Page 2 of 2

Re: Turning an integer into an array of its digits

Posted: 2019-10-02 05:57:20
by phspaelti

Code: Select all

$my1997keys = Array.new()
foreach $key, value in $myhash
    if $value.find('1997')
        $my1997keys.push $key
    end
end
Pulling these keys into an Array may be useful, if you want to process them further, perhaps repeatedly. But since you will most likely need to loop through them again to do anything, you could really just do the comparison on the fly.

Also I am using .find to do the comparison. Nisus actually has a .containsString command which could be used instead. Not sure if there is any real advantage to one method or the other.

[PS: Sorry. Earlier I just wrote "foreach $key in $hash". But of course with hashes you have to do "foreach $key, $value in $hash".]