Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Need help with a variable

by cal (Beadle)
on Oct 30, 2002 at 23:30 UTC ( [id://209274]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks, I am trying to concantenate the value of variable $gallery with the $SAVE_DIRECTORY path variable inside BEGIN{}. The variable is always empty. Any ideas.. Thanks Cal
$gallery = param('galleries'); # Configurable Options Follow: # BEGIN { $SAVE_DIRECTORY = "/u/web/abcdefg/photogal/$gallery"; # # --> Variable: # $gallery # --> Variable: # $SAVE_DIRECTORY # --> Function: # Defines the path to the directory # on the server that should be used # as the folder to save files into. # --> Directory Permissions: # a+rwx # --> Additional Notes: # This path should not have a # trailing forward slash. Also # remember that this is a path, not # a URL. Use something similar to: # # /home/myself/www/uploads # $MAXIMUM_UPLOAD = 0; # # --> Variable: # $MAXIMUM_UPLOAD # --> Function: # Defines the number of bytes that # can be uploaded. Files that exceed # this limit will not be saved on the # server. # --> Additional Notes: # Set this to zero in order to # disable size checking. # $ALLOW_INDEX = 0; # # --> Variable: # $ALLOW_INDEX # --> Function: # If set to zero, files whose # names begin with the word # index will not be saved. # # Set to one to allow files # named index* to be uploaded. # --> Additional Notes: # $SUCCESS_LOCATION = "" # # --> Variable: # $SUCCESS_LOCATION # --> Function: # Defines the URL that users # should be redirected to if # the script works properly. If # this is left blank, a default # page will be returned to the # user. # --> Additional Notes: # This is a COMPLETE URL, not # a path. } # # End of Configurable Options.

Replies are listed 'Best First'.
Re: Need help with a variable
by hiseldl (Priest) on Oct 30, 2002 at 23:38 UTC
    Everything in the BEGIN scope is always compiled executed before everything else even if in your script BEGIN {} is at the end.

    $var = "VARIABLE"; END {print "this is at the end:$var\n";} BEGIN {print "this is in the beginning:$var\n";} ##OUTPUT: $ perl script.pl this is the beginning: this is at the end:VARIABLE

    Try running your script without the BEGIN.

    --
    hiseldl
    What time is it? It's Camel Time!

      No it's NOT compiled before the code above. It's EXECUTED before the code above.

      perl starts from the top, compiles the code as it goes and whenever it encounters the end of a BEGIN{} block it executes the code within that block, whenever it sees a use statement it stops compiling the script, compiles the module (executing the BEGIN{} blocks and processing the uses), executes the code in the module (if there is any outside subroutines) and executes the module's import() function). Then it continues with the script. When it gets to the end of the file it starts executing the COMPILED code outside the BEGIN{} blocks.

      I hope I'm making sense.

      Jenda

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found