Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Puzzled over 'my'

by tadman (Prior)
on Oct 23, 2003 at 20:47 UTC ( [id://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)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-18 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found