Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: RFC (possible new tutorial) Guide to references; The Basics

by raybies (Chaplain)
on May 25, 2012 at 14:03 UTC ( #972432=note: print w/replies, xml ) Need Help??


in reply to RFC (possible new tutorial) Guide to references; The Basics

I think these two examples in your cheat sheet ending might be seen as confusing in that the values are assigned to scalars and force scalar context, which ultimately is not what the comment is claiming above the program statements.

# access the entire array through its reference my $elem_count = scalar @{ $aref }; # access the entire hash through its reference my $keys_count = keys %{ $href };

I get the point that the %{} and @{} make the hash reference into regular hash context, and the array reference into array context, but the final result in the examples in both are actually scalars, so the end result is the number of array elements, and the number of keys of the hash that's referred to by the variable. Perhaps that's a bit complex for a simple cheat example. Dunno, or you might want to clarify the comment to reflect the end result.

Of course the names of the variables is a good choice, but I don't know if that's sufficient.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://972432]
help
Chatterbox?
choroba misses the context
[Corion]: choroba: Optimizing how Perl reads source code on startup (and then processes it line-by-line)
[Corion]: But in general, it seems to be an interesting approach I should think about - whenever I'm searching for something, to consider if I could search for the end of the token instead of the start of the token

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2016-12-06 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (108 votes). Check out past polls.