Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: difference between ($scalar) and $scalar

by elbie (Curate)
on Jul 21, 2001 at 15:48 UTC ( #98655=note: print w/replies, xml ) Need Help??


in reply to difference between ($scalar) and $scalar

It is a difference between the list and scalar contexts. Your pattern matching operation will return a list, but if the assignment is to a scalar (as it is in the second case) then you only get the scalar value of the list. i.e. The number of elements in the list. In this case, that's the number of matches made.

If the assignment is made to a list, which you can explicity do by putting the brackets around the variable as in your first case, then you will get the elements of the left hand side's list (in this case, the one variable $rcs) matched up with the elements of the right hand side (the matches from the regexp) on a one-for-one basis until one side reaches the end of the list.

  • Comment on Re: difference between ($scalar) and $scalar

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2021-10-22 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?