For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > line number on error condition









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author line number on error condition
tewilk@gmail.com

2006-09-21, 6:58 pm

can someone give me an example of how I can print the line number of
the current place in my perl script when creating an error condition?
For example, lets say I'm reading a configuration file and a setting
I'm expecting to be in the file is not there so I want to end the
execution of the script. How do I print the line number of the current
or last executed line of code?

Thanks!
Terry

usenet@DavidFilmer.com

2006-09-21, 6:58 pm

tewilk@gmail.com wrote:
> can someone give me an example of how I can print the line number of
> the current place in my perl script when creating an error condition?


print "Oops - big booboo on line " . __LINE__ . "\n";
or
print "Oops - big booboo on line @{[__LINE__]}\n";


--
David Filmer (http://DavidFilmer.com)

Uri Guttman

2006-09-21, 6:58 pm

>>>>> "u" == usenet <usenet@DavidFilmer.com> writes:

u> tewilk@gmail.com wrote:[color=darkred]

u> print "Oops - big booboo on line " . __LINE__ . "\n";
u> or
u> print "Oops - big booboo on line @{[__LINE__]}\n";

warn will do that if its arg list doesn't end with a \n (just like die
will). so warn 'oops - big booboo' is all you need.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
tewilk@gmail.com

2006-09-22, 7:57 am

Thanks for all replies... worked great!

Uri Guttman wrote:
>
> u> tewilk@gmail.com wrote:
>
> u> print "Oops - big booboo on line " . __LINE__ . "\n";
> u> or
> u> print "Oops - big booboo on line @{[__LINE__]}\n";
>
> warn will do that if its arg list doesn't end with a \n (just like die
> will). so warn 'oops - big booboo' is all you need.
>
> uri
>
> --
> Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com