If you only have one file, yes, $0 will refer to the same file as __FILE__.

If your program has more than one file (for example, if your code is a perl module), __FILE__ is more useful; $0 will tell you the name of the file that perl started running, but __FILE__ will tell you the file where you code is currently running. If you use the commands "require", "do", "use", __FILE__ will keep track of where the code came from: it's very handy.

Also, notice that it's __FILE__ (with two underscores before and after the word), not _FILE_ (with one underscore).

You might want to look at the module called "Carp": if you say "use Carp"; and then use the function "carp" where you would use the function "warn", you'll get messages that include the current line number, all the functions called to reach the current function, with file names and line numbers.

Good Luck! :-)
--
Ytrew


In reply to Re^3: How Do I Get the Line Number In My Error Message? by Anonymous Monk
in thread How Do I Get the Line Number In My Error Message? by azaria

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.