[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] How files are read in (was: for loops)



At 09.01 -0000 98-12-30, G. Ann Campbell wrote:
>Yes, that was it exactly, as I finally figured out about an hour after posting
>my question.... But I don't understand why.

<FILEHANDLE> returns the next line if called in scalar context, and a list
of all remaining lines if called in list context.

This means that

>   @obits = <OBITS>;

will make @obits an array of all lines in OBITS, while

>     $txt = <TXT>;'

will put the first line of TXT into $txt. If $txt contains the whole file,
then MacPerl thinks the file is just one line. That can happen if the file
isn't a text file, if it is a text file from another OS (Unix) and if
you've fiddled with $/.

>Also, does anyone have a snippet handy to sort a list of names (i.e. John B.
>Doe, Mrs. Mary Smith, Harold Icks) by last name?

#!perl

@array = ('John Doe',
'Alan M. Smith',
'Mrs. Josephina K. Anderson',
'Chandler Bing',
'Carl Johan Berglund');

@array = map {
    $_->[1]
} sort {
    $a->[0] cmp $b->[0]
} map {
    my @name = split;
    [$name[-1], $_]
} @array;

print join "\n", @array;

__END__

Carl Johan Berglund

___Carl_Johan_Berglund_________________________
   Adverb Information
   carl.johan.berglund@adverb.se
   http://www.adverb.se/



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch