Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Dereference string in foreach

by 7stud (Deacon)
on Feb 13, 2013 at 23:23 UTC ( #1018657=note: print w/ replies, xml ) Need Help??


in reply to Dereference string in foreach

By the way, in "Perl Best Practices" Damian Conway advises that you should always write 'my' before your for-loop variable because if you don't :

[The resulting] behaviour is contrary to all reasonable expectation.  Everywhere else in Perl, when you declare a lexical variable, it's visible throughout the remainder of its scope, unless another explicit my declaration hides it.  So it's natural to expect that the [variable] used in the for loop is the same lexical [variable] that was declared before the loop.

But it isn't.
("Perl Best Practices", p. 108)

My code makes it neccessary to loop through an array and to output all elements using a reference.

That doesn't seem to make a lot of sense:

use strict; use warnings; use 5.010; my @arr = (10, 20, 30); for my $num (@arr) { say ${\$num}; } --output:-- 10 20 30


Comment on Re: Dereference string in foreach
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-07-04 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls