Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Where does <GEN1> come from?

by mnooning (Beadle)
on May 24, 2007 at 18:07 UTC ( [id://617297]=perlquestion: print w/replies, xml ) Need Help??

mnooning has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am attempting to diagnose a problem in code I am unfamiliar with. I get lines that look like the two below.

Error while ... edited out ... at t/ithreadm.t line 47, <GEN1> line 1.
Error while ... edited out ... at t/ithreadm.t line 47, <GEN1> line 835.

The "line 47" refers to the file t/ithreadm.t. I cannot find where the GEN lines are coming from. I grepped for GEN in all seemingly relevant files.

A search on the web indicates that the GEN numbers in error messages pop up quite a bit. What generates it? If I knew, I would have a better shot at diagnosing the problem.

Thanks

Replies are listed 'Best First'.
Re: Where does <GEN1> come from?
by liverpole (Monsignor) on May 24, 2007 at 18:28 UTC
    Hi mnooning,

    As BrowserUK says, it's the line number of the most recently opened filehandle.

    Here's a (slightly contrived) example:

    #!/usr/bin/perl use strict; use warnings; use FileHandle; my $iam = $0; my $fh = new FileHandle; open($fh, "<", $iam) or die "Can't open myself: '$iam' ($!)\n"; my $cnt = 15; while (my $line = <$fh>) { chomp $line; printf "%2d: %s\n", (10 / $cnt--), $line; }

    When saved as the file "mytest", and run, it errors out on the 15th line, where a division by zero error occurs:

    Illegal division by zero at mytest line 15, <GEN0> line 16.

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      Now that is what I call an esoteric nuance!

      Thank you all very much for the comments and the code.

      And yes, it is Net::Daemon code I am looking at.

      Thanks
Re: Where does <GEN1> come from?
by BrowserUk (Patriarch) on May 24, 2007 at 18:16 UTC

    The bit on the end indicates the most recent line of the most recent file read. In the case shown, the main script probably has lines that looks something like:

    open GEN1, ... while( <GEN1> ) { ... }

    From perlfunc for die:

    If the last element of LIST does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied. Note that the ``input line number'' (also known as ``chunk'') is subject to whatever notion of ``line'' happens to be currently in effect, and is also available as the special variable $..

    It's a barely documented and somewhat dubious feature.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      It's a barely documented and somewhat dubious feature.

      Personally I find it an useful feature. However I hardly ever remember having used it: more precisely most of my warnings and errors are meant for the users of some script. Thus I end them with "\n". In the rare case I have some that are meant for people working on the script itself, I don't append it. A tiny example was posted here.

        The default of appending the line number at which a message is generated is a fine and useful feature.

        The default of also appending the filehandle and linenumber of the last line of the last "file" read by the script, or any of the modules it uses, is at best dubious, at worst, confusing.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Where does <GEN1> come from?
by Fletch (Bishop) on May 24, 2007 at 18:26 UTC

    Judging by the filename (and a quick trip to google code search) it's a test file from Net::Daemon which uses IO::Socket so I'd bet it's just read from the second anonymous glob generated for a socket (the first would have been named GEN0). You can get the same handle names yourself with gensym from the core Symbol module.

Re: Where does <GEN1> come from?
by jettero (Monsignor) on May 24, 2007 at 18:17 UTC
    Feels like it might have something to do with sockets... The error is at line 47 of threadm.t. The file handle GEN1 just happens to be open and at line 1 or 835...

    It's most likely in one of the modules that are used or required. Try to grep some of those.

    -Paul

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://617297]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found