Good Morning Monks,

This is a question about error tracking.. Say I'm reading in various variables from various files, and passing them to various different subs in various different modules I wrote. Then say that some of my input data (in the input files) is messed up in some way. So I pass it to one of my subs, and the sub throws an error (lets have an example because I'm confusing myself here :P)

(main.pl) use strict; use warnings; use mySubs; my @array; while (my $temp=<INPUT>){ my $number=&mySub(\$temp); @array=(@array,$number); } --------------------------- (mySubs.pm) use strict; use warnings; package mySubs; #...Exporter.. etc.. sub mySub { my $variable = ${$_[0]}; .... #some stuff .... if (some condition){ print "data $variable not valid in mySub\n"; return -1; } .... #rest of sub .... }

So what I want to be able to do is instead of just printing 'data $variable not valid in mySub' I'd like to be able to print 'data $variable not valid in mySub from line xx in 'main.pl'; line yy in <INPUT>'

Is this possible? I thought I could pass $. around but that wouldn't (I don't think) tell me it came from 'main.pl' (And it would be a pain to change all of my subs if there's a simpler way!)

I don't even really know where to start on this one, so any monk-ish wisdom would be appreciated!
Cheers, why bird.

p.s. I wasn't sure what an appropriate title would be so feel free to change it/suggest what it should be changed to

........
Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......

In reply to Tracking down errors in data from input files. by why_bird

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.