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

Re: problem with loop

by McA (Priest)
on Oct 27, 2014 at 11:50 UTC ( [id://1105134]=note: print w/replies, xml ) Need Help??


in reply to problem with loop

Hi,

probably something like this:

#!/usr/bin/perl use strict; use warnings; use 5.010; my @list = qw(PA5098 PA5100 PA5092 PA3175); for (my $i = 0; $i < @list - 1; $i++) { for (my $j = $i + 1; $j < @list; $j++) { my $diff = $j - $i; print "$list[$i] $list[$j] $diff\n"; } }

Be aware: You need a special case when list has less than two elements.

Regards
McA

Replies are listed 'Best First'.
Re^2: problem with loop
by AnomalousMonk (Archbishop) on Oct 27, 2014 at 13:51 UTC
    You need a special case when list has less than two elements.

    No special case seems needed: inner loop just executes 0 times. (Update: Also works with 5.8.9.)

Re^2: problem with loop
by Anonymous Monk on Oct 27, 2014 at 11:53 UTC
    thanks - simple

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2024-04-25 01:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found