Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: can we pass two variable to foreach loop

by ambrus (Abbot)
on Mar 28, 2007 at 18:26 UTC ( #607078=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @name = qw(fred wilma barney betty);
    @color = qw(black red blonde black);
    ...
    # wilma - red
    # barney - blonde
    # betty - black
    
  2. or download this
    @name = qw(fred wilma barney betty);
    for $k (0 .. @name - 2) { print $name[$k] . " - " . $name[$k + 1] . "\
    +n" }
    # fred - wilma
    # wilma - barney
    # barney - betty
    
  3. or download this
    @name = qw(fred wilma barney betty);
    for $k (0 .. @name/2 - 1) { print $name[2 * $k] . " - " . $name[2 * $k
    + + 1] . "\n" }
    # fred - wilma
    # barney - betty
    
  4. or download this
    @data = (["fred", "black"], ["wilma", "red"], ["barney", "blonde"], ["
    +betty", "black"]); 
    @color = qw(black red blonde black); for $rec (@data) { my($name, $col
    +or) = @$rec; print $name . " - " . $color . "\n" }
    ...
    # wilma - red
    # barney - blonde
    # betty - black
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2014-07-14 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (259 votes), past polls