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

Re: [MacPerl] Read entire file?



>Thanks all for the various replies.  I had forgotten about -s.
>
>I wanted to avoid reading into an array of lines and joining them
>because since I only wanted a scalar anyway, it seemd like unnecessary
>overhead.  And if I process a file with line endings other than the
>platform line ending, I'd only get one "line" anyway.
>
>Jim
>
>--
>Jim Correia                                Bare Bones Software, Inc.
>correia@barebones.com                     <http://web.barebones.com>
>

Hi Jim,

on the Mac, Perl's -s file test gives the size of a file's *data 
fork* only. To get the full size of a file,
including the resource fork, you will have to use the Mac::Files 
module as shown below:

#!perl -w
use Mac::Files;
my($file, $fileCat , $fileSize);

$file = 'MacintoshHD:MacPerl Ÿ:MacPerl';
$fileCat = FSpGetCatInfo($file) or die($^E); # get the CatInfo object 
for the file
print $fileCat->ioNamePtr(), "\n"; # print file name

# the size is

$fileSize = $fileCat->ioFlLgLen() + $fileCat->ioFlRLgLen();

print "MacPerl's file size is $fileSize bytes.\n";

__END__

Dirty FileManager stuff, isn't it? Read more about it in "MacPerl 
Power and Ease" by Vicki Brown and Chris Nandor, Chapter 13, The 
Toolbox Modules. [1]

HTH.

Best regards,
--Thomas

[1] http://macperl.com/macperl/ptf_book/HTML


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org