seattlejohn has asked for the wisdom of the Perl Monks concerning the following question:
The output from this is:use strict; my @items = ('file1', 'file2', 'file3'); open INPUT_FILE,"/no/such/directory/$items[2]" or print eval 'qq{unabl +e to open file $items[2]: $!\n}'; open INPUT_FILE,"/no/such/directory/$items[1]" or print eval 'qq{unabl +e to open file $items[1]: $!\n}'; open INPUT_FILE,"/no/such/directory/$items[0]" or print eval 'qq{unabl +e to open file $items[0]: $!\n}';
Before you ask why I'm using eval in such a goofy way: This is just an artificial test case I've created to demonstrate the behavior in distilled way, not how I'm actually writing the code. Anyway, the thing that you can see here is that if the string being evaluated includes an array element with an index other than zero, the value of $! seems to get squashed. I would've expected all three lines of output above to be identical except for filename, since the only difference in the three lines is which array element is included in the string being evaled. I'm using ActivePerl 5.6.0 on Linux and Win2K. Any insight would be appreciated!unable to open file file3: unable to open file file2: unable to open file file1: No such file or directory
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: eval and variable scope
by jeffa (Bishop) on Dec 17, 2001 at 06:47 UTC | |
by seattlejohn (Deacon) on Dec 17, 2001 at 07:16 UTC | |
by blakem (Monsignor) on Dec 17, 2001 at 07:22 UTC | |
by seattlejohn (Deacon) on Dec 17, 2001 at 14:16 UTC | |
|
Re: eval and variable scope
by Zaxo (Archbishop) on Dec 17, 2001 at 06:57 UTC |