blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:
That didn't work for me, but when I changed the CORE::open line to the following, it did work:use subs 'open'; sub open { print "opening file: @_\n"; CORE::open(@_); }
Any idea why that makes a difference?CORE::open($_[0], $_[1]);
Given just an argument of "test.txt", it works. But if I run it with args of "test.txt bad", it fails. $! is empty even when it fails.
use subs 'open'; $file = $ARGV[0]; $method = $ARGV[1] eq 'bad' ? 0 : 1; sub open { my $count = scalar @_; print "opening file: @_ ($count)\n"; # Prints "opening file: TEST + [filename] (2)" for either method my $return; if ($method == 0) { $return = CORE::open(@_); # doesn't work } else { $return = CORE::open($_[0], $_[1]); # works } return $return; } if ($result = open (TEST, $file)) { my $lineCount; for my $line (<TEST>) { last if $lineCount++ > 5; print "$line\n"; } close TEST; } else { print "couldn't open test.pl\n"; print "error info: $!\n" if $!; print "more error info: $^E\n" if $^E; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use subs
by chromatic (Archbishop) on Jan 24, 2003 at 05:52 UTC | |
|
Re: use subs
by Gilimanjaro (Hermit) on Jan 24, 2003 at 15:14 UTC | |
by Mr. Muskrat (Canon) on Jan 24, 2003 at 15:48 UTC | |
by Aristotle (Chancellor) on Jan 24, 2003 at 17:02 UTC | |
by Mr. Muskrat (Canon) on Jan 24, 2003 at 17:17 UTC | |
by blahblahblah (Priest) on Apr 08, 2005 at 15:13 UTC |