At 4:30 pm -0800 19/11/02, Heather Madrone wrote:
Is perl on the Mac going to care whether source files are Mac-style or Unix-style? Is it going to have difficulty reading and operating on either kind of file? What kind of text files will it write?You can do a routine like the one below to discover what line endings are used in the file and set $/ accordingly. This script establishes, by reading 1000 bytes, that a Eudora mailbox file uses carriage returns only, changes $/ to cr and loops through the file printing all the From: lines terminated with line feeds.
#!/usr/bin/perl
$f = "$ENV{HOME}/Documents/Eudora Folder/Mail Folder/Manningham" ;
sysopen F, $f, O_RDONLY ;
sysread F, $_, 1000 ;
if (/\015\012/) {
$/ = "\015\012" ;
} elsif (/\015/) {
$/ = "\015" ;
} else {
$/ = "\012" ;
}
open F, $f ;
for (<F>) {
/^From: / and chomp and print "$_\n"
}
-- JD