Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

pairwise() doesn't seem to work...

by 7stud (Deacon)
on Oct 06, 2010 at 09:06 UTC ( #863738=perlquestion: print w/ replies, xml ) Need Help??
7stud has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

This is what I get when I try to use pairwise() in List::MoreUtils,

use strict; use warnings; use 5.010; use List::MoreUtils; my @arr1 = (1, 2, 3); my @arr2 = (10, 20, 30); my %hash = pairwise { ($a, $b) } @arr1, @arr2; use Data::Dumper; say Dumper(\%hash); --output:-- Name "main::b" used only once: possible typo at 1perl.pl line 10. Name "main::a" used only once: possible typo at 1perl.pl line 10. Can't call method "pairwise" on an undefined value at 1perl.pl line 10 +.

Comment on pairwise() doesn't seem to work...
Download Code
Re: pairwise() doesn't seem to work...
by Corion (Pope) on Oct 06, 2010 at 09:19 UTC

    You need to import pairwise from List::MoreUtils. It seems that Perl interprets pairwise { ($a, $b) } as indirect object notation otherwise:

    use List::MoreUtils qw( pairwise );
Re: pairwise() doesn't seem to work...
by eyepopslikeamosquito (Canon) on Oct 06, 2010 at 09:20 UTC

    You need to explicitly import pairwise like so:

    use List::MoreUtils qw(pairwise);

      Thanks.
Re: pairwise() doesn't seem to work...
by AnomalousMonk (Monsignor) on Oct 06, 2010 at 10:02 UTC

    And get rid of the  Name "main::whatever" used only once ... warnings with a  use vars qw($a $b); (or similar) statement.

    >perl -wMstrict -le "use 5.010; use List::MoreUtils qw(pairwise); my @arr1 = (1, 2, 3); my @arr2 = (10, 20, 30); use vars qw($a $b); my %hash = pairwise { ($a, $b) } @arr1, @arr2; use Data::Dumper; say Dumper(\%hash); " $VAR1 = { '1' => 10, '3' => 30, '2' => 20 };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-08-02 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (54 votes), past polls