Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 ( [id://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".

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 (Archbishop) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11100898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found