Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: my $x or my ($x)

by rinceWind (Monsignor)
on Apr 04, 2006 at 14:26 UTC ( #541151=note: print w/replies, xml ) Need Help??


in reply to my $x or my ($x)

Another useful use of list context is with regular expression captures. Consider:

my $x = /(\w+)/;

and

my ($x) = /(\w+)/;

The first example will set $x to 1 if $_ contains any alphanumerics. The second example sets $x to the first word.

The second, list context, example is such a common, natural idiom to me that I never make the mistake of using captures in scalar context. I also almost never need to use $1, $2 etc. explicitly.

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://541151]
help
Chatterbox?
[karlgoethebier]: thao4: Si tout le reste échoue demande en francais ;-) There are some French speaking monks in the monastry...
[erix]: weird: a dev version perl (perl-5.27.9) is released, but git doesn't contain a perl-5.27.10 yet
[karlgoethebier]: ...not me ;-)
[thao4]: I posted my question, Could you help me , Please ?
[thao4]: posted with the title :Replace a patern_2 in 30 lines from the line with the patern_1 founded
[Eily]: karlgoethebier but we're trying to stay hidden!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2018-02-21 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (277 votes). Check out past polls.

    Notices?