mmontemuro has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $ref=''; my $entry=''; my @records=(); my @sorted=(); sub getmydata { my($name,$project,$hours) = @_; my ($tester) = { name => $name, project => $project, hours => $hours }; return $tester; } while(<DATA>) { $ref = getmydata(split); #Space delimited by default push(@records, $ref); #We then sort this array } #This is where I need help #Sort into sorted array by name. Array should contain list in sorted o +rder by name # #print out data structure in sorted order by Name foreach $entry (@sorted) #Returns ref, must deref it, { print "NAME:$entry->{name}\n"; print "JOB:$entry->{project}\n"; print "HOURS:$entry->{hours}\n"; print "--------------\n"; } __END__ Mike Plumber 80 Laura Programmer 60 Mark Sales 70 Jeremy Cook 65
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sort lists/Data Structures
by McDarren (Abbot) on Dec 05, 2008 at 20:25 UTC | |
by mmontemuro (Initiate) on Dec 05, 2008 at 21:19 UTC | |
Re: Sort lists/Data Structures
by kennethk (Abbot) on Dec 05, 2008 at 20:22 UTC | |
by mmontemuro (Initiate) on Dec 05, 2008 at 20:38 UTC | |
Re: Sort lists/Data Structures
by lightoverhead (Pilgrim) on Dec 05, 2008 at 20:56 UTC |