in reply to (tye)Re: Cheap idioms
in thread Cheap idioms
A more robust method is...
Redundancy :) I don't like typing ARGV twice, but realise localizing *ARGV is necessary. Thanks for the pointer - I think I'm very fortunate to not have been bitten by this yet.
Since you can assign a reference to a typeglob to set only one data type associated with it, simply adding brackets solves my problem of having to type the four uppercase letters twice. *foo = [ 1, 2, 3 ]; is like @foo = (1, 2, 3);, but with rather different semantics.
my $contents = do { local (*ARGV, $/) = [$filename]; <> };
Note that prior to Perl v5.6.0 (I think) this idiom didn't work correctly.
A quick, possibly broken test (perl5.005 -e'print do { local (@ARGV, $/) = "/etc/passwd"; <> }') shows that the unaltered version works with perl 5.005. But that one is broken. Any version of this idiom localizing *ARGV doesn't work with perl5.005, so your version doesn't play nice with it.
That is not at all a problem, though. I don't use perls older than 5.6.0 anymore, except when explicitly asked. It's time we moved on to newer versions. There's perl 5.8.0 already, and people are still using 5.005. The _03 release is over three years old now.
I put use 5.006; in my code to make sure things break as soon as possible. I even use use v5.6; sometimes, just to nag :)
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: (tye)Re: Cheap idioms
by Anonymous Monk on Oct 13, 2002 at 21:59 UTC | |
by Juerd (Abbot) on Oct 14, 2002 at 05:54 UTC | |
Re: Re: (tye)Re: Cheap idioms
by Sihal (Pilgrim) on Oct 17, 2002 at 11:31 UTC | |
by Aristotle (Chancellor) on Oct 17, 2002 at 13:24 UTC | |
by Sihal (Pilgrim) on Oct 17, 2002 at 13:48 UTC | |
by Aristotle (Chancellor) on Oct 17, 2002 at 14:06 UTC | |
by rir (Vicar) on Oct 17, 2002 at 15:53 UTC | |
| |
Re^3: Cheap idioms
by ysth (Canon) on May 29, 2008 at 20:09 UTC |