Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map/sort help 1

Status
Not open for further replies.

travs69

MIS
Joined
Dec 21, 2006
Messages
1,431
Location
US
I have an array like
@new ("1.1.1.1 stlmo #Web Server",
"1.1.1.2 atlga #Web Server",
"1.1.1.3 houtx #"1.1.1.4 stlmo #FTP Server",
"1.1.1.5 stlga #FTP Server",
"1.1.1.6 houtx #FTP Server");

I am trying to sort by the comments first then on the hostname. The code I was trying was
Code:
@new = map { $_->[0] } 
sort { $a->[3] cmp $b->[3] || $a->[2] cmp $b->[2]} 
map { [$_, (split /s+/),$_,3] } @new;

for (@new) { print "$_\n"; }

but (as I'm sure you know cause I'm posting here) it isn't working as expected.
 
the split argument is wrong: [red]s+[/red]
if you want to split on multiple "s" thats fine, but I think you wanted to split on spaces: [red]\s+[/red]

that should do it. [wink]



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks Kevin.. I'll put my dunce hat on now :)
 
hehehe.... I'll lend you mine, it's pretty well worn out from me using it so much but your welcome to have it (keep it too, I need a new one). [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top