Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: my $1

by grinder (Bishop)
on Apr 23, 2009 at 20:33 UTC ( #759655=note: print w/replies, xml ) Need Help??


in reply to my $1

$1 and $2 are package variables, not lexicals. You can nest their contents with local. Lexical $_ is a new addition from 5.10.0 onwards.

Best practice is simply to copy out $1 and ilk to lexicals, the way you're doing it (but within a conditional, checking that the match succeeded).

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: my $1
by mltucker (Initiate) on Apr 23, 2009 at 21:26 UTC

    Thanks for the reply.

    Ok, so could I use local for $1 and $2 in the same way that I use my for $_? This isn't working how I expected it to.

    I'm not sure if this is relevant, but the one that I'm having trouble with is the multiplication, where I use both the originals and the recursive call results:

    return "($1)*(".diff($2).")+($2)*(".diff($1).") if m/(.+?)\*(.+)/;

    This works fine using $capt1 = $1, but I'm curious as to whether it can be done using local or with the double quotes...

    -Mark

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759655]
help
Chatterbox?
[LanX]: Eily don't be sad ... you are the Bishop of our hearts.
[marto]: 1nickt, I just said that in a Sean Connery accent
[LanX]: Discipulus++ # Bi-Shop
[Eily]: is the Bishop of hearts higher or lower ranked than the Jack?
[ambrus]: Higher.
[Eily]: Discipulus what's the merchandise? Other bi-people?
[1nickt]: marto would like to hear that. Of course he speaks very deliberately and dramatically, allowing pauses between words, so if anybody could pull it off it would be him, or someone impersonating him ...
[Eily]: Discipulus that's a chess joke BTW right? Because bishops don't walk straight :D
[choroba]: stop making chessy jokes about bishops!
[choroba]: I mean cheesy

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (15)
As of 2017-09-26 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (294 votes). Check out past polls.

    Notices?