See?  I knew someone else would know a better way.

Jolinar

"Beau E. Cox" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi - you suggested:
>
> > foreach $lastname (sort { $a cmp $b } keys %names) {
> >  print "$lastname, $names{$lastname}\n";
> > }
>
> That works well. I'm lazy, so I usually do something like:
>
> print "$_, $names{$_}\n" for (sort keys %names);
>
> 1) for == foreach so save 4 keystrokes.
> 2) I use the .... for ....; structure because the
>    processing within the "for" is just one line.
> 3) the sort default is {$a cmp $b}, so no need to specify.
> 4) $_ is automatically the loop variable, so
>    skip declaring the temp variable $lastname.
>
> Now if you want a case-insensitive sort:
>
> print "$_, $names{$_}\n" for (sort { lc $a cmp lc $b } keys %names);
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to