Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Processing pairs of values from even-sized array

by ciderpunx (Vicar)
on Jun 03, 2011 at 15:56 UTC ( [id://908012]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @arr = qw/1 2 3 4 5 6 7 8/;
    while(my ($x,$y) = splice @arr,0,2) {
      say "$x => $y";
    }
    
  2. or download this
    my @arr = qw/1 2 3 4 5 6 7 8/;
    
    ...
    for(keys %hash) {
      say "$_ => $hash{$_}"
    }
    
  3. or download this
    1 => 2
    3 => 4
    7 => 8
    5 => 6
    
  4. or download this
    my @arr = qw/1 2 3 4 5 6 7 8/;
    push @arr, undef;
    ...
    for(@{$x}){
      say $_ ." => " . $y->[$i++] if($_);
    }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-07-23 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.