in reply to How 'bout an argv pragma?
The problem I see with your second domkfile is when it encounters whatever open <> there might be already. Consider this:
while (<>) { chomp; print collect( $_ ); } sub collect { local @ARGV = @_; join '', <>; }
I ran it this way:
ls | perl ../perlmonks.pl
In the directory where I ran it, there are two files, 'file1' and 'file2'. Each has two lines. Run this way, I get:
file2 line1file1 line2file1
Try unrolling the loop instead:
print collect( 'file1' ); print collect( 'file2' );
Then the I get the correct output:
line1file1 line2file1 line1file2 line2file2
As an aside, I don't find this much more readable either. Any altering of @ARGV beyond the usual shift has a code smell to me, even if you politely use local. Adding a pragma on top of it to give it even more special behavior not found in other variables strikes me as asking for trouble.
But perhaps I'm just a grumpy old monk. If your argv pragma is well-documented, and its behavior is clear and unambiguous, then so much the better. You're light on details, and so my reaction may be mostly knee-jerk.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How 'bout an argv pragma?
by blazar (Canon) on May 27, 2008 at 19:34 UTC | |
by ysth (Canon) on May 27, 2008 at 21:47 UTC | |
by blazar (Canon) on May 28, 2008 at 10:01 UTC | |
by ysth (Canon) on May 29, 2008 at 01:53 UTC | |
by blazar (Canon) on May 29, 2008 at 16:57 UTC | |
|