Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Getting Perl to print out error messages

Reply
Thread Tools

Getting Perl to print out error messages

 
 
laredotornado
Guest
Posts: n/a
 
      09-21-2011
Hi,

I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
out run time error messages? I have this at the top of my script ...

use warnings;
use strict;

but making a call like this ...

$baseTestDir = File::Spec->catfile($data{'myco.checkout.dir'},
$data{'selenium.myco.test.root'});

causes script execution to exit without printing out why (I was able
to pinpoint the failure point by putting in a bunch of print
statements). If I add "use File::Spec" at the top, execution occurs
past that line, but it would be great if Perl just told me why things
failed.

Any help is appreciated, - Dave
 
Reply With Quote
 
 
 
 
Rainer Weikusat
Guest
Posts: n/a
 
      09-21-2011
laredotornado <(E-Mail Removed)> writes:
> I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
> out run time error messages? I have this at the top of my script ...
>
> use warnings;
> use strict;
>
> but making a call like this ...
>
> $baseTestDir = File::Spec->catfile($data{'myco.checkout.dir'},
> $data{'selenium.myco.test.root'});
>
> causes script execution to exit without printing out why (I was able
> to pinpoint the failure point by putting in a bunch of print
> statements). If I add "use File::Spec" at the top, execution occurs
> past that line, but it would be great if Perl just told me why things
> failed.


NB: I don't Windows.

How where you running the script? When I try the same here, I get

[rw@sapphire]/tmp $perl a.pl
Can't locate object method "catfile" via package "File::Spec" (perhaps you forgot to load "File::Spec"?) at a.pl line 3.
 
Reply With Quote
 
 
 
 
Ilya Zakharevich
Guest
Posts: n/a
 
      09-21-2011
On 2011-09-21, laredotornado <(E-Mail Removed)> wrote:
> Hi,
>
> I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
> out run time error messages? I have this at the top of my script ...
>
> use warnings;
> use strict;


Do not. `use warnings' should be better restricted to coding
packages. Use the "standard" boilerplate

#!/usr/bin/perl -w
use strict;

(but this was discussed many times here...).

Hope this helps,
Ilya
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-22-2011
laredotornado <(E-Mail Removed)> wrote:
>I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
>out run time error messages? I have this at the top of my script ...
>
>use warnings;
>use strict;
>
>but making a call like this ...
>
> $baseTestDir = File::Spec->catfile($data{'myco.checkout.dir'},
>$data{'selenium.myco.test.root'});
>
>causes script execution to exit without printing out why (I was able
>to pinpoint the failure point by putting in a bunch of print
>statements). If I add "use File::Spec" at the top, execution occurs
>past that line, but it would be great if Perl just told me why things
>failed.
>
>Any help is appreciated, - Dave


I cannot reproduce your problem. After declaring the obvious variables I
am getting

Can't locate object method "catfile" via package "File::Spec" (perhaps
you forgot to load "File::Spec"?) at C:\tmp\t.pl line 6.

That message seems to be self-explanatory to me.

jue
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      09-22-2011
On Wed, 21 Sep 2011 09:20:13 -0700 (PDT), laredotornado <(E-Mail Removed)> wrote:

>Hi,
>
>I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
>out run time error messages? I have this at the top of my script ...
>
>use warnings;
>use strict;
>
>but making a call like this ...
>
> $baseTestDir = File::Spec->catfile($data{'myco.checkout.dir'},
>$data{'selenium.myco.test.root'});
>
>causes script execution to exit without printing out why (I was able
>to pinpoint the failure point by putting in a bunch of print
>statements). If I add "use File::Spec" at the top, execution occurs
>past that line, but it would be great if Perl just told me why things
>failed.
>
>Any help is appreciated, - Dave


Its possible your STDERR output is not going to the console.
I can reproduce your dificulty by redirecting STDERR to a file then
calling the File::Spec->catfile() function.

I'm not the greatest I/O expert and don't know windows 7 that well,
is it possible a shell can redirect STDERR, or maybe in your program or
some module your program loads?

Try this. I redirected STDERR to a file then trapped the system error.

-sln


###############
# test.pl
###############
use strict;
use warnings;

my ($baseTestDir, %data);

# Close stderr, reopen it to a text file:

close STDERR;
open STDERR, '>', 'stderr.txt' or die "$!";

# Trap runtime exceptions in eval {} block:

eval {
# This should cause system to die();

$baseTestDir = File::Spec->catfile($data{'myco.checkout.dir'},
$data{'selenium.myco.test.root'});
};

# See if eval trapped an error,
# if so, print it out to STDERR (really to file 'stderr.txt')

$@ && print STDERR "$@\n";

# Print a message to STDOUT

print "All!\n";


# Test that die() sends a message to STDERR (really to file 'stderr.txt')

die "Done!";


__END__

--------------------------------
From the command line:


c:\temp>perl test.pl
All!

c:\temp>type stderr.txt
Can't locate object method "catfile" via package "File::Spec" (perhaps you forgo
t to load "File::Spec"?) at uu.pl line 16.

Done! at uu.pl line 32.

c:\temp>
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      09-23-2011
On 2011-09-21, Henry Law <(E-Mail Removed)> wrote:
>> Do not. `use warnings' should be better restricted to coding
>> packages. Use the "standard" boilerplate
>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> (but this was discussed many times here...).

>
> So would it be a good idea, therefore, to have the documentation changed
> to reflect this "good practice"? Currently it says
>
>> The use warnings pragma [is]... a more flexible alternative for both the command line flag -w ...


> I confess that I am confused.


No wonder. This piece of documentation is plain wrong (alas, the same as
most of Perl docs nowadays). AFAIK, one cannot reconstruct the
effects of -w by `use warnings'.

BTW, (I expect that) the majority of bugs caught by -w won't be caught
by `use warnings'. I did not test the OP's problem, but it might be
in this category.

Hope this helps,
Ilya
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      09-25-2011
On 2011-09-21 22:00, Ilya Zakharevich <(E-Mail Removed)> wrote:
> On 2011-09-21, laredotornado <(E-Mail Removed)> wrote:
>> I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
>> out run time error messages? I have this at the top of my script ...
>>
>> use warnings;
>> use strict;

>
> Do not. `use warnings' should be better restricted to coding
> packages. Use the "standard" boilerplate
>
> #!/usr/bin/perl -w
> use strict;
>
> (but this was discussed many times here...).


Yes. And almost everyone here disagrees with you.

hp

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      09-25-2011
On 2011-09-25 10:27, Peter J. Holzer wrote:
> On 2011-09-21 22:00, Ilya Zakharevich<(E-Mail Removed)> wrote:
>> On 2011-09-21, laredotornado<(E-Mail Removed)> wrote:


>>> I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
>>> out run time error messages? I have this at the top of my script ...
>>>
>>> use warnings;
>>> use strict;

>>
>> Do not. `use warnings' should be better restricted to coding
>> packages. Use the "standard" boilerplate
>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> (but this was discussed many times here...).

>
> Yes. And almost everyone here disagrees with you.


I advise to always use '-w' in the shebang line of your .pl files.
It helps me a lot.

The 'use warnings' is best for modules.

During development and testing you can further use '-W',
and a $SIG{__WARN__} = sub { die @_ }.

--
Ruud
 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      09-25-2011
"Peter J. Holzer" <(E-Mail Removed)> writes:
> On 2011-09-21 22:00, Ilya Zakharevich <(E-Mail Removed)> wrote:
>> On 2011-09-21, laredotornado <(E-Mail Removed)> wrote:
>>> I'm using ACtivePerl 5.12.4 on Windows 7. How do I get Perl to print
>>> out run time error messages? I have this at the top of my script ...
>>>
>>> use warnings;
>>> use strict;

>>
>> Do not. `use warnings' should be better restricted to coding
>> packages. Use the "standard" boilerplate
>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> (but this was discussed many times here...).

>
> Yes. And almost everyone here disagrees with you.


Which means essentially nothing in absence of arguments supporting
this disagreement. "-w has big problems" doesn't count.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
Orcon news... getting messages out quicker The Other Guy NZ Computing 1 04-16-2005 12:21 AM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM
how to print email without print out today's date? vddiee Computer Support 2 07-16-2004 03:56 PM



Advertisments