Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018657]
help
Chatterbox?
[Your Mother]: Stick with what you know. Or post a SOPW and if it's not complicated I guarantee someone will answer; me if it's straightforward and no one else gets it better first.
[1nickt]: ++YourMother (Grammar Vigilante of Bristol)
[Lady_Aleena]: Um, how does grep do multiline? print "$file:$_" if grep { /get_(array|hash| data)\(.+\)/ } $_; only returns the same 18 lines the command line grep does.
[Lady_Aleena]: my scratchpad has what I have so far.
[choroba]: what do you mean by multiline?
[Discipulus]: thanks 1nickt!
[choroba]: grep is a filter, it selects elements from a list based on a boolean condition
[moritz]: you need to read the file in one go to do a multiline regex match
[erix]: ha ha, I like the Vigilante
[Lady_Aleena]: Forget it. I'm getting angry with it.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-05-23 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?