Hello Monks,

In my most recent script I'm working on I've began deploying Signal handlers and BEGIN and END blocks for the 1st time.

I added SIGNAL handlers to my script, along with BEGIN and END blocks, so I could create and remove a PID file for my
daemon/script I'm writing, as well as dealing with a few other loose ends... Everything seems to be working great with
this. I tried everyway I can think of to end/kill my running script, and everytime it properly creates and subsequently
removes the file containing the PID ($$) of my running script.

The error I'm wondering about is the error message below. I get the first part, but I'm confused about why there is an error
at all...?
Died at ./myScriptname line 58, <$fh> line 119.

Line 58 in my script is this below, which is what makes my END{} block execute when the script is killed/Terminated/etc...
$SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub { die; };

And this is my END code block.
END { ### This will get the Duration from the starting Execution time # till the time the process was stopped... $DURATION = duration(time() - $^T); my $duration_str = "*The myScriptname Daemon ran for $DURATION\n"; push @data, $duration_str; ### Close the LOG_FILE by untie'ing the array @data from the file: untie @data; ### PID File: Name and Location... my $PID_FILE = "/var/run/myScriptname.pid"; ### If the PID file exists, then we will remove it: if (-e $PID_FILE) { unlink $PID_FILE; #-->Deletes files from the given list... } }

Could that error have anything to do with a file being left open, or something like that, when the END block begins
getting executed? Or, is it that I'm using the untie function in that block?

I believe at the time that error is displayed, the file tied to the array "@data", had 119 lines in it...
So what can I do to get rid of that error/warning?

Any thoughts or suggestions would be much appreciated!

UPDATE:
After I just posted I did a few more tests. Lets say the file 'tied' to @data has exactly 82 lines in it before running
my script. I then start my script and immediately I print/push about 10-12 lines onto the end of the file. So at this
point my file has 94 lines. I then click Ctrl+C and kill my script. I then get the error:
Died at ./myScriptname line 58, <$fh> line 82.
I'm confused why it would give an error at line 82, when at the point the script "dies" there are 94 lines in the file...?

Thanks in Advance,
Matt


In reply to Meaning of this Filehandle Error? by mmartin

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.