I'd appreciate some enlightenment. ($0 .. !$0) is truly bizarre looking!
update: How does the scalar value of the weird looking range wind up being one less when the "if statement" is satisfied as opposed to what it is before the if statement? Of course $0 is normally the file name of the executing Perl script (C:/...baha/../../this.pl) I don't understand the meaning of ($0 .. !$0).
use strict; use warnings; $|=1; # turn of stdout buffering sub get_max_index { my $imax = 0; foreach (@_) { print "b4 if: default var = $_ imax=$imax\n"; print "b4 if: Value of weird range=".($0 .. !$0),"\n"; $imax = ($0 .. !$0), print "If triggered, new imax=$imax\n" if + $_ > $_[$imax]; print "\n"; } return $imax; } my @arr = (1,2,13,4,5); my $ans = get_max_index(@arr); print"$ans\n"; #2 __END__ b4 if: default var = 1 imax=0 b4 if: Value of weird range=1 b4 if: default var = 2 imax=0 b4 if: Value of weird range=2 If triggered, new imax=1 b4 if: default var = 13 imax=1 b4 if: Value of weird range=3 If triggered, new imax=2 b4 if: default var = 4 imax=2 b4 if: Value of weird range=4 b4 if: default var = 5 imax=2 b4 if: Value of weird range=5 2
In reply to Re^7: Why does my get_max_index function return zero? (High Water Mark Algorithm)
by Marshall
in thread Why does my get_max_index function return zero? (High Water Mark Algorithm)
by hghosh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |