in reply to Newbie question, advice appreciated

You will actually want to use an array of hashes. Parallel arrays are notoriously error-prone, so avoid them whenever possible.
open 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 }
That will even keep them in the order found in file.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;

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Newbie question, advice appreciated
by sauoq (Abbot) on Sep 27, 2005 at 20:15 UTC

    This is all good, but I'd use a regex to dice up the line rather than split and all that shifting, popping, and joining.

    my ($description, $function) = /^#\s?STANDARD\s+(.*?)\s+(\S+)\s*$/;
    -sauoq
    "My two cents aren't worth a dime.";