Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: how to declare a local *subname=sub{}?

by haukex (Archbishop)
on Oct 31, 2016 at 09:39 UTC ( [id://1175003]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    our $foo = "foo";
    {
    ...
        }
    }
    quz();  # prints "$foo = foo"
    
  2. or download this
    our $foo = "foo";
    {
    ...
        $foo = "foo";
    }
    quz();  # prints "$foo = foo"
    
  3. or download this
    #!/usr/bin/env perl
    use warnings;
    ...
    Subroutine main::bar redefined at local_ex.pl line 15.
    orig foo
    local bar
    
  4. or download this
    our $bar = "BBB";
    sub foo { print "orig foo (bar=$bar)\n" }
    ...
        baz();  # first call to baz
        quz();  # second call to quz (OOPS, $bar is still undef!)
    }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-24 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found