in reply to Newbie question, advice appreciated
That will even keep them in the order found in file.nameopen FH, 'file.name' or die "Cannot open 'file.name' for reading: $!\n"; my @items; while (<FH>) { chomp; my @line = split; # Remove "#" and "STANDARD" shift @line; shift @line; # I assume the function name is the last item in the list and has +no spaces in it my $function = pop @line; push @items, { function => $function, description => join( ' ', @line ), }; } close FH; foreach my $item (@items) { # $item->{description} is the description # $item->{function} is the function name }
Now, if you need to sort them, do so as such:
# If sorting ascending asciibetically. my @sorted_items = sort { $a->{description} cmp $b->{description} } @i +tems;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Newbie question, advice appreciated
by sauoq (Abbot) on Sep 27, 2005 at 20:15 UTC |