Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Name "main::a" used only once: possible typo

by davido (Archbishop)
on Mar 05, 2013 at 20:10 UTC ( #1021896=note: print w/ replies, xml ) Need Help??


in reply to Name "main::a" used only once: possible typo

This is a common problem with no known great solution (if there is a great solution I hope someone will show it so that we can submit patches). It also annoys anyone using List::MoreUtils pairwise, for about the same reason. Several ideas were tossed around in the List::MoreUtils RT as to how to fix the problem, but none were ideal, and none fixed it in 100% of use cases (including my attempt).

The easiest solution is still annoying, and looks like this:

reduce { no warnings 'once'; $a * $b } 1 .. 6;

Update: I see that the List::Util RT suggests something like this:

reduce { our ( $a, $b ); $a * $b } 1 .. 6;

Dave


Comment on Re: Name "main::a" used only once: possible typo
Select or Download Code
Replies are listed 'Best First'.
Re^2: Name "main::a" used only once: possible typo
by ikegami (Pope) on Mar 06, 2013 at 04:48 UTC
      I'd probably put the our ($a,$b) outside of that block, but this is what I had in mind. I was just interested in more options. - Thanks
      out ($a, $b); reduce { $a * $b } 1 .. 6;
        I was just interested in more options.

        This is kind of old-school and amounts to the same thing as sticking an  our ($a, $b); statement somewhere, but it's another option:

        >perl -wMstrict -le "use List::Util qw/reduce/; use vars qw($a $b); ;; print reduce { $a * $b } 1..6; " 720

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2015-07-31 08:35 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 (276 votes), past polls