Jeff 'Japhy' Pinyan wrote:
>
> On Oct 8, Rob Dixon said:
> >
> >Jeff 'Japhy' Pinyan wrote:
> >>
> >> open BLAH, "< c:/Inetpub/wwwroot/dg/menu.txt"
> >> or die "can't read c:/Inetpub/wwwroot/dg/menu.txt: $!";
> >
> > my $fd;
> > open $fd, '< c:/Inetpub/wwwroot/dg/menu.txt';
> >
> >might be a better match? With $fd in place of 'BLAH' in the
> >rest of the code.
>
> Only if he's got a version of Perl that supports that syntax.
True. I think it's been around since 5.0. Do you know?
> >> >$line = fread($fd,filesize("C:\Inetpub\wwwroot\dg\menu.txt"));
> >>
> >> my $content = join "", <BLAH>;
> >> # or
> >> my $content; { local $/; $content = <BLAH>; }
> >> # or
> >> read(BLAH, my $content, -s BLAH);
> >> # etc.
> >
> >I'm staying faithful to:
> >
> > my $content = do {local $/; <$fd>};
>
> Last I checked, that makes TWO copies of the string from <$fd>: one in
> the do BLOCK, and then it gets copied and returned to $content. I could
> be wrong, but I think I heard about it on p5p.
That's interesting. You mean there's a temporary internal
scalar in the copy process? It's almost certainly the same
as:
sub readall {
my $fh = shift;
local $/;
<$fh>;
}
my $content = readall \*FH;
when the return value would have to be stacked.
Certainly worth thinking about for Gb files, but
it's ripe for in-line optimisation.
I might check. One day :)
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]