"Chas. Owens" <[EMAIL PROTECTED]> writes: > On Dec 10, 2007 2:31 PM, <[EMAIL PROTECTED]> wrote: > snip >> But I did stick an undef in at if (!$OutputFile) so >> if (undef $OutputFile) >> >> Then the warning moved on to line 66 where the code attempts to use >> OutputFile. Seems to indicate OutputFile was gettiong a varlue in the >> if clause. > snip > > That does not do what you think it does. The undef function makes its > argument variable undefined. You are looking for the defined function > like this > > if (not defined $OutputFile) { > > or this > > unless (defined $OutputFile) {
Ok, but hold it a minute... I think I must have been unclear in that post because I wasn't saying I thought using undef there was the way to go, I did that to try to trip the same warning output. But it didn't (it caused a similar warning further along as expected) so I was saying that showed that $OutputFile being undefined was NOT the reason for the warning this thread was about. (thats probably as clear as mud too). > my $OutputFile = shift || "/home/reader/projects/perl/work/myfile"; > die "<$OutputFile> cannot be found .. exiting\n" unless -f $OutputFile; Now there is something I've been kind of put out about. Maybe because of being only a sometimes coder or maybe because I arrived at perl from shell scripting and at one time a sort of heavey (not necessarily skilled) awk user. It seems perl coders like to jumble lots of actions into one line. And think of that as a better way. I don't doubt it is... and certainly not advocating against advice from a skilled and experienced user, but can you tell me how it is better? Is it faster for the interpreter to read or something else? To me its much harder to read later... mnths later when the script does something unexpected.. when used in a different way I hadn't tested it in. to me: my $var; if ($ARGV[0]){ $var = shift; } if (!$var){ $var = "someDefaultfile"; } It is a good bit more drawn out but it tells me more about intent at a glance than what you used. If my kind of extra baloney is slowing down the excecution when taken as a whole .... that is many times more baloney when seen over 300 lines or so than the shorter ways like you posted, then its probably time for me to give up the long hand and start trying to go the shorter more concise route. Can you expound on that a bit? > The shift function defaults ..... [...] thanks for that nifty info > ............ The new // operator that will be available in > Perl 5.10 returns the first defined item (if any). This makes it a > much better choice for defaulting logic like this. I just compiled that new version. Paul J. mentioned it has code to give better warnings and it really does. It actually gives the subject variable by name in cases like the subject of this thread. Can you show an example of how that new `//' operator works? I've got that version built and installed in a test area and all set to be shocked and amazed at new features... : ) Since all of what I do is either home use or on a webpage of mine. and won't really cause anyone else (except maybe this list,,) a problem I think I'll turn the new version loose on my scripts and see what turns up. Over the yrs I've accumlated over 100 homeboy perl scripts (most probably very poorly written and some haven't seen that much use). It will be interesting to see if they all still work. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/