Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Not sure how to handle this scope

by BillKSmith (Monsignor)
on Aug 19, 2021 at 01:34 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found