Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://591924]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-12-09 06:47 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (36 votes). Check out past polls.