Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Why does my get_max_index function return zero? (High Water Mark Algorithm)

by hghosh (Acolyte)
on Jun 03, 2019 at 17:45 UTC ( #11100898=note: print w/replies, xml ) Need Help??


in reply to Re: Why does my get_max_index function return zero? (High Water Mark Algorithm)
in thread Why does my get_max_index function return zero? (High Water Mark Algorithm)

Sorry, I copy-pasted the original script's code (which didn't use warnings or strict). Please see my edited code above because my script is still returning zero, even when I run the function as its own perl script (I just run the above code in a file called test_max.pl). Also, I don't use $imax anywhere else in the original script that uses the function "get_max_index".
  • Comment on Re^2: Why does my get_max_index function return zero? (High Water Mark Algorithm)

Replies are listed 'Best First'.
Re^3: Why does my get_max_index function return zero? (High Water Mark Algorithm)
by Paladin (Vicar) on Jun 03, 2019 at 17:53 UTC
    The $imax inside your for loop is different from the $imax outside it (as you've declared it with my inside the for loop). Remove that my.
Re^3: Why does my get_max_index function return zero? (High Water Mark Algorithm)
by haukex (Chancellor) on Jun 03, 2019 at 18:04 UTC
    Please see my edited code above

    Please have a look at How do I change/delete my post?, in particular, "It is uncool to update a node in a way that renders replies confusing or meaningless". But luckily I still had your original code sitting around:

    Other than that, Paladin has already pointed out the issue with the second my declaration inside the loop in your updated code. I just wanted to add that in general, one should not combine my with an if statement modifier, as its behavior is undefined (see Statement Modifiers).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2019-11-20 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (96 votes). Check out past polls.

    Notices?