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

Re: Puzzled over 'my'

by tadman (Prior)
on Oct 23, 2003 at 20:47 UTC ( #301713=note: print w/ replies, xml ) Need Help??


in reply to Puzzled over 'my'

You must've not only removed the my, but the brackets as well. It was the brackets, mind you, that are the key here.

Including brackets means that you're assigning a list to a list, in this case, the result of the grep operation into a list containing the variable $ok. Thus, the first thing grepped goes into the first variable, and you get "Some String".

If you want to know how many things you got, you need to force a list to scalar conversion. That might sound fancy, but it's just a way of saying you want to assign the list directly to the variable instead of to a list of variables. No brackets. If you're a bit fuzzy, here's some examples;

my @list = ("A","B","C"); my ($var) = @list; # $var becomes "A" my $var = @list; # $var becomes 3 my ($var) = scalar(@list); # $var becomes 3 my $var = scalar(@list); # $var becomes 3 (same idea)


Comment on Re: Puzzled over 'my'
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-08-01 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls