Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

unknown syntax

by TourneyOfPerl (Initiate)
on May 01, 2012 at 19:36 UTC ( #968321=perlquestion: print w/ replies, xml ) Need Help??
TourneyOfPerl has asked for the wisdom of the Perl Monks concerning the following question:

I have what appears to be a perl script. The file is a .bat, but appears to use a lot of perl.

What would the line

local *MY_VAR

mean? Especially if I don't see MY_VAR defined anywhere?

Comment on unknown syntax
Download Code
Re: unknown syntax
by JavaFan (Canon) on May 01, 2012 at 19:58 UTC
    If you had seen my $MY_VAR would you be baffled because you had not seen $MY_VAR defined anywhere? ;-)

    Anyway, it localizes the type glob MY_VAR. Before we had autovivifying refs to filehandles, "everyone" used plain filehandles instead of references to handles. This was (and is) a way to localize handles.

Re: unknown syntax
by furry_marmot (Pilgrim) on May 01, 2012 at 20:38 UTC

    If it's a .bat file, it's a Windows batch file. Before Windows XP, you might or might not have been able to successfully run a Perl script on windows just by running it. One solution was to convert a perl script to a batch file (the Activestate distribution still includes a script to accomplish this).

    The script makes a copy of the perl script (replacing the extension with .bat) and puts a bunch of lines at the top so that if Perl is not installed, the batch file will exit gracefully. When you run the batch file, it calls perl.exe with the batch file as the argument, including the -x switch, which tells perl to skip everything until it finds a shebang line (which is #!perl).

    And as JavaFan pointed out, local *MY_VAR is defining it.

    Consider reading Learning Perl. It's a good read, and may be helpful to you.

    --marmot

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://968321]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2014-07-25 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls