Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^7: replicating the command 'unset LIBPATH' in perl

by viffer (Beadle)
on May 19, 2010 at 02:07 UTC ( #840601=note: print w/replies, xml ) Need Help??


in reply to Re^6: replicating the command 'unset LIBPATH' in perl
in thread replicating the command 'unset LIBPATH' in perl

Thanks gents - I now feel like the beginner I am!

But....what is __FILE__?

  • Comment on Re^7: replicating the command 'unset LIBPATH' in perl

Replies are listed 'Best First'.
Re^8: replicating the command 'unset LIBPATH' in perl
by Anonymous Monk on May 19, 2010 at 03:06 UTC
    Its not a secret :) __FILE__ site:perldoc.perl.org The special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that point in your program.
    $ perl -e"die __FILE__" -e at -e line 1. $ echo die __FILE__ > thefileis $ perl -e"die __FILE__" -e at -e line 1. $ echo die __FILE__ > thefileis $ perl thefileis thefileis at thefileis line 1. $ perl D:\thefileis D:\thefileis at D:\thefileis line 1. $
      OK - so __FILE__ is the name of my script, but I will admit to not understanding what you're trying to do with it.

      When I run your version of the BEGIN code, I get

      Use of uninitialized value in string eq at /apps/bin/blah/reconcile_wi +thdotsh.pl line 68. main::BEGIN() called at /apps/bin/blah/reconcile_withdotsh.pl +line 73 eval {...} called at /apps/bin/blah/reconcile_withdotsh.pl lin +e 73
      where lines 68 and 73 are:
      67 BEGIN { 68 unless( $ENV{ +__FILE__ } eq __FILE__ ){ 69 delete $ENV{LIBPATH}; 70 $ENV{ +__FILE__ } = __FILE__; 71 exec $^X, __FILE__, @ARGV; # relaunch without LIBPATH 72 } 73}
      It isn't __FILE__ that is the uninitialized value (as I put a print command in), so presumably its the "$ENV{ +__FILE__ }" but I can't manage to print that to check - and being in a BEGIN statement I can't step through it in debug.

      Also, in both versions the script just ends (as opposed to terminating with an error).

      Maybe I should be a heretic and go back to using COBOL on a mainframe! Do any still exist?

      Cheers

      Kev

        When I run your version of the BEGIN code

        Where'd you see that?

        I get Use of uninitialized value in string eq

        That's what happens when you use a variable to which you never assigned a value.

        Also, in both versions the script just ends (as opposed to terminating with an error).

        How did you determine that (as oppose to running successfully with no output)? If it's true, maybe whatever is messing with your Perl to cause it to give a stack trace for warnings — where's that eval come from? — is also messing with the process replacing itself.

        The whole point of placing the code in BEGIN is to get it to execute as early as possible, yet the code is at line 67 of the script. Move that to line 1! There's no point in doing work before this check since it restarts the process from scratch.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-05-28 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (98 votes). Check out past polls.

    Notices?