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

Re: Not sure how to handle this scope

by BillKSmith (Monsignor)
on Aug 19, 2021 at 01:34 UTC ( #11135948=note: print w/replies, xml ) Need Help??


in reply to Not sure how to handle this scope

In this respect, lexical variables are much like local. The new variable is not initialized.
use strict; use warnings; use feature 'say'; package OO; sub new {my $animal = $_[1]; return bless \$animal;} sub species { return ${$_[0]} } package main; my $cat = 'cat'; my $dog = 'dog'; my $self = new OO( $cat ); { my $self = $self; $self = new OO( $dog ) if $ARGV[0] eq 'Fido'; say $self->species(); } say $self->species();

OUTPUT (with argument 'Fido')

dog cat

OUTPUT (without argument 'Fido')

cat cat
Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-12-04 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (30 votes). Check out past polls.

    Notices?