On Mon, Apr 16, 2007 at 05:25:41AM +0900, Brian Candler wrote:
>
> while contents = gets(nil)
> # do stuff with contents
> end
>
> Doing that in Perl seems quite hard.
Thanks for the information. As for this last example, the functionality
you achieved isn't exactly "hard" in Perl, but it's a touch less
intuitive. Slurping a file via the diamond operator should end up
looking something like this, generally:
my $foo;
{ local $/; $foo = <>; }
The "my $foo" part, for those not familiar with Perl, is just the way
the $foo variable can be declared with lexical scope. If you're writing
code without strict and warnings pragmas (indispensable debugging aids
in Perl), you could dispense with the "my $foo" line altogether.
In fact, you could dispense with the braces and use "undef $/" instead
of "local $/" if you prefer, as long as you don't care about getting the
original value of $/ back (or want to put it back in manually for some
reason).
TIMTOWTDI.
--
CCD CopyWrite Chad Perrin [
http://ccd.apotheon.org ]
print substr("Just another Perl hacker", 0, -2);