Hi

I am trying to figure out how can we compare two index values of two
strings in the same array, so that if the 1st argument index value is
less than second argument index value, I want to swap the input
arguments.Please help me with that.
I successfully got the index values for the given input ( 2 cities
separated by space). But couldnt compare the indexes .

My code is


#!/usr/local/bin/perl

use strict;
use warnings;

my @cities = qw/Atlanta Boston Chicago Denver Detroit Houston LA Miami
NY Philly SanFrancisco Seattle/;

my ($i, $j);

for ( $i = 0; $i < @cities; $i++) {
    next unless $cities[$i] =~ /\b$ARGV[0]\b/i;

    print "$i: $cities[$i] \n";

}
for ( $j = 0; $j < @cities; $j++) {
    next unless $cities[$j] =~ /\b$ARGV[1]\b/i;

    print "$j: $cities[$j] \n";

}


if ($i > $j) {

print" $ARGV[0] $ARGV[1] \n";

} else {

print" $ARGV[1] $ARGV[0] \n";

}


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to