James Edward Gray II wrote: > On Mar 27, 2004, at 12:10 AM, R. Joseph Newton wrote: > > > Not exactly. It is not the newline "\n" that would give the full > > output of the > > warn function, but the $! variable, which contains the most recent > > warning or > > error message. > > I believe you are confusing two often paired, but not otherwise related > features of Perl.
Actually, I was starting to think that I had misstated the above, by saying "output of the warn function, but I think I was closer to the mark. You can print $! and get the error message, but the line information is the product of warn or die: open IN, 'some_nonexistent_filename' or print $!; ^Z Name "main::IN" used only once: possible typo at - line 1. # built-in compiler warning No such file or directory # simply printing $! open IN, 'some_nonexistent_filename' or warn $!; ^Z .. No such file or directory at - line 1. > > warn() is a tool for delivering non-fatal error messages. It behaves > differently depending if the provided message does or doesn't end in a > newline character, as has been discussed in this thread. > > $! is a Perl interface to C's "errno" variable. It is set by failed > system/library calls. > > While it may often be useful to issue a warn()ing including $!, it is > by no means required. In this case, James, it is what the OP was looking for. He specifically saw a problem with having the warning message come out as a simple print statement. I'm not terribly concerned about the internal mplementation. I am speaking of the effect. Unless I am missing something about what the OP wnated here. > It may be useful to issue warn()ings including > many variables. $@ is a common example, in fact, it's the default > message warn() will display if not provided one. You may want to use > your own variables, so simply print a message in your own words about > what happened. That's what warn() is for. I agree, which is why I tend to recommend the darn-near canonical form I showed. Interestingly enough, it is almost the same generalized warning produced by $@: Greetings! E:\d_drive\perlStuff\hdr>perl -w open IN, 'some_nonexistent_filename' or warn $@; ^Z Name "main::IN" used only once: possible typo at - line 1. Warning: something's wrong at - line 1. except that the $@ adds the Warning: prefix. It seems pretty clear to me, that although modular in their function, these Perl built-in variables were precisely designed to work with the warn and die functions. I'll hold with my essential point--that you get a lot more useful information out of your warning by havng the $! at the end of your custom message. I would recommend always using such custom messages also, and putting design thought into them. That is why I suggested having them include the name of the function containing them, and why I generally specify the operation being attempted. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>