Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by mithaldu (Monk)
on Mar 11, 2013 at 13:23 UTC ( [id://1022794]=note: print w/replies, xml ) Need Help??


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

I am confused that nobody suggested:

print reduce { $_[0] * $_[1] } 1..6;

Replies are listed 'Best First'.
Re^2: Name "main::a" used only once: possible typo
by toolic (Bishop) on Mar 11, 2013 at 13:38 UTC
    Perhaps because it produces the incorrect result and 8 more warning messages:
    #!/usr/bin/env perl use warnings; use strict; use List::Util qw/reduce/; print reduce { $_[0] * $_[1] } 1..6; __END__ Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. Use of uninitialized value in multiplication (*) at x.pl line 7. 0
Re^2: Name "main::a" used only once: possible typo
by LanX (Saint) on Mar 11, 2013 at 13:40 UTC
    cause it doesn't work?

    use List::Util qw/reduce/; print reduce { $_[0] * $_[1] } 1..6; __END__ Use of uninitialized value in multiplication (*) at /home/lanx/B/PL/PM +/ScopeListUtils.pl line 23. ...

    Cheers Rolf

      Well damn. I was sure i had used that on List::Util stuff to get around $a/b warnings. Guess i misremembered.
Re^2: Name "main::a" used only once: possible typo
by subogero (Initiate) on Sep 13, 2017 at 10:42 UTC
    I guess List::Util::reduce does not pass the parameter pair at all to your function, it just localizes $a and $b with them.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-19 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found