|
|
sybperl-l Archive
Up Prev Next
From: "Klein, Shoshana R" <Shoshana dot Klein at gs dot com>
Subject: FW: using sort, map and multiple splits
Date: Oct 30 2000 5:01PM
I dont' think this got sent the first time, my apologies if it's a dupe.
-----Original Message-----
From: Klein, Shoshana R
Sent: Sunday, October 29, 2000 9:23 PM
To: 'SYBPERL-L@list.cren.net'
Subject: using sort, map and multiple splits
I have an advanced perl question.
I'm trying to read in a colon delimited file and sort the 4th column, but
that column has multiple values delimited by commas, I'd like to append the
first 3 columns to each value and then sort the file. Is there a way to do
it in with the one
statement.
in coming data
1:abc:tag1:Employee
2:acd:tag3:Employee
3:alb:tag0:Employee
4:klkl:tag9:Employee,Manager
5:alnm:tag7:Employee
6:all:tag18:Employee,Manager,Analyst
8:altt:tag2:Employee
desired output
6:all:tag18:Analyst
1:abc:tag1:Employee
2:acd:tag3:Employee
3:alb:tag0:Employee
5:alnm:tag7:Employee
4:klkl:tag9:Employee
6:all:tag18:Employee
8:altt:tag2:Employee
4:klkl:tag9:Manager
6:all:tag18:Manager
Can I expand this code that sorts the just the last column, to first split
on colon, then split [3] on comma and join the first 3 columns to each value
in in column 4 and then sort column 4.
@in_data =
map { $_->[0]}
#sort { $a->[1] cmp $b->[1]}
sort { $b->[1] cmp $a->[1]}
map { [$_, (split /:/)[3]] }
;
This is what i've been trying but it's not working
@in_data =
map { $_->[0]}
#sort { $a->[1] cmp $b->[1]}
sort { $b->[1] cmp $a->[1]}
#map { [$_, (split /:/)[3]] }
#map { $_, (split /:/)[3];(split /,/)[3]}
map {[ $_, (split/,/) @temp[3]]; @temp=(split /:/)}
;
|