Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Anonymous Monk
on Jun 15, 2005 at 09:35 UTC ( #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; }


Comment on Re: Extracting non-consecutive but related items from an array.
Download Code
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
Node Status?
node history
Node Type: note [id://466845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-09-02 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (32 votes), past polls