Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Extracting non-consecutive but related items from an array.

by Anonymous Monk
on Jun 15, 2005 at 09:35 UTC ( [id://466845]=note: print w/replies, xml ) Need Help??


in reply to Extracting non-consecutive but related items from an array.

my %servers; while (<>) { chomp; next unless 3 == my ($server, $loc, $country) = split /,\s*/; push @{$servers{$server}}, [$loc, $country]; } local $" = " "; while (my ($server, $info) = each %servers) { print "$server\n"; print "\t@$_\n" foreach @$info; }

Replies are listed 'Best First'.
Re^2: Extracting non-consecutive but related items from an array.
by sapnac (Beadle) on Jun 15, 2005 at 14:11 UTC
    #use strict; use FileHandle; # Global Declaration my($spool,%serverdet); open (spooler ,"data.dat") or die "Error opening the file\n"; while($spool=<spooler>) { chomp($spool); ($server,$dat1,$dat2)=split(/,/,$spool); if($serverdet{$server}) { $serverdet{$server} .= ";".$dat1.",".$dat2; }else{ $serverdet{$server} = $dat1.",".$dat2; } } foreach $key (sort keys %serverdet) { print "Server $key\n"; @val = split(/;/,$serverdet{$key}); foreach $val (sort @val) { print $val."\n"; } }
    Hope this helps!

    code tags added by holli

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://466845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-23 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found