if ( $file_no1 gt $file_no2 )
You are using text comparison on numbers which will not work correctly:
$ perl -le'print "$ARGV[0] is ", $ARGV[0] gt $ARGV[1] ? "" : "NOT ", " +greater than $ARGV[1]"' 12 18 12 is NOT greater than 18 $ perl -le'print "$ARGV[0] is ", $ARGV[0] gt $ARGV[1] ? "" : "NOT ", " +greater than $ARGV[1]"' 12 10 12 is greater than 10 $ perl -le'print "$ARGV[0] is ", $ARGV[0] gt $ARGV[1] ? "" : "NOT ", " +greater than $ARGV[1]"' 7 10 7 is greater than 10
Also wrong on these lines:
if ( $file_no1 eq 0 ) if ( $mkey eq $k ) if ($k eq $file_no1-1 ) if ( $count1 eq $count2 ) if ( $flag eq 1 )
$indexed= "\("; foreach my $index (@array) { $temp=$index+0; $indexed="$indexed $temp"; $indexed="$indexed,"; } $indexed ="$indexed \)";
Or just:
$indexed = "(" . join ", ", @array, ")";
$hashref2 = @$VAR2[$k];
That is correctly written as:
$hashref2 = $VAR2->[$k];
my $srt; for (my $s=0;$s<@array; $s++) { for (my $r=0;$r<@array;$r++) { if ($s ne $r) { if($array[$s]<$array[$r]) { $srt=$array[$s]; $array[$s]=$array[$r]; $array[$r]=$srt; } } } }
That is usually written as:
for my $s ( 0 .. $#array ) { for my $r ( 0 .. $#array ) { if ( $s != $r && $array[ $s ] < $array[ $r ] ) { @array[ $r, $s ] = @array[ $s, $r ]; } } }
Or as:
@array = sort { $a <=> $b } @array;
In reply to Re: Unexpected output for given program with write function
by jwkrahn
in thread Unexpected output for given program with write function
by dipesh777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |