in reply to Re: How 'bout and argv pragma?
in thread How 'bout an argv pragma?
I personally believe that you're right. More precisely, it was so "obvious" to me that nested <>'s would behave "correctly" in connection with local, that I was sure your test was flawed. So, to be sure, I reproduced it... only to find it miserably failing, albeit in a completely different manner:
picard:~/tmp [21:23:31]$ ls file1 file2 picard:~/tmp [21:23:37]$ cat file1 line1 line2 picard:~/tmp [21:23:42]$ cat file2 line1 line2 picard:~/tmp [21:23:44]$ cat ../domk.pl #!/usr/bin/perl use strict; use warnings; while (<>) { chomp; print collect( $_ ); } sub collect { local @ARGV = @_; join '', <>; } __END__ picard:~/tmp [21:23:53]$ ls file? | perl ../domk.pl Can't open file1: No such file or directory at ../domk.pl line 13, <> +line 3. file2
This is perl 5.10.0, and 2-arg or 3-args openedness of ARGV apart, I would definitely consider both the above behaviour and "yours" buggy. That such constructs are rare enough for me to only have discovered it now, after many years of Perl programming, does not make it less so.
I was about to send this post already, when I though that perhaps I should have localised the whole of *ARGV, which would have made things even more clumsy and counter-intuitive, but at least working: let me tell you that I tried and this appears not to be the case.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How 'bout an argv pragma?
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 | |
by ysth (Canon) on May 29, 2008 at 20:07 UTC | |
|