Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: I'm trying to consolidate my functions into subroutines

by haukex (Archbishop)
on May 13, 2017 at 17:38 UTC ( [id://1190214]=note: print w/replies, xml ) Need Help??


in reply to Re: I'm trying to consolidate my functions into subroutines
in thread I'm trying to consolidate my functions into subroutines

Parameter passing is kind of weird in Perl. When you say SpecifySeqLengths(my $id, my %seq); it's actually creating global variables $id and %seq.

While I agree with the rest of the post and the code example is good, this part is not quite accurate. Those two variables are still lexically scoped to whatever block they're declared in. If that happens to be the scope of the file, one might tend to call them "global", but typically in Perl that term is used for package variables, which are "global" in the sense that they cross the file boundary. There are actually only a limited number of "truly global" variables (i.e. they cross even package boundaries), such as $_ and other special variables (although strangely, that list only seems to be in the Camel's reference section, not in the Perl docs).

Replies are listed 'Best First'.
Re^3: I'm trying to consolidate my functions into subroutines
by Anonymous Monk on May 13, 2017 at 17:44 UTC
    Good point. What would be a better term for top-level lexical variables?

      File-scope lexicals.


      Give a man a fish:  <%-{-{-{-<

      File scoped (contrary to block scoped)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found