Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Declaring a Variable [for BEGINNERS]

by gaal (Parson)
on Dec 27, 2006 at 19:44 UTC ( #591924=note: print w/replies, xml ) Need Help??

in reply to Declaring a Variable [for BEGINNERS]

This example does not declare variables in the beginning of the script: that is, these variables are only visible inside the scope of the sub CheckAllPairs. This is called "lexical" scoping, and extends from a "my" declaration to the end of the scope of the my. Perl also has global variables, which you usually use the "our" declarator to introduce, but as a rule of thumb lexicals are better for most purposes.

Using strict is almost always a good idea, yes. Having so many variables like in that example looks like a lot, but maybe it's warranted by what the code is doing. If you want to declare several lexicals all at once rather than on separate lines, you can do it the following way, but it's mostly a stylistic thing:

my ($subj_num, $region, $region1, $region2, $time); # put as many as y +ou like here my ($abs_time, $max_peak_time) = (50, 2050) # you can initiali +ze multiple vars like this.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://591924]
[erix]: choroba I believe you ;)
[1nickt]: Corion I assume you are talking about Retry? Attempt doesn;t offer callbacks and has a much simpler interface. (Also written by someone I trust...)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-05-24 12:56 GMT
Find Nodes?
    Voting Booth?