in reply to printing array values

Please note that you are not having a problem with "printing array values". What you're having to do with is not an array, but an associative array aka "hash" (because they're internally implemented by means of hash tables).
print $fvalues{$_}, "\n" for keys %fvalues;

Update: incidentally, while there may be some corner cases in which C-style for loops would result to be convenient, most often perl-style ones cover the vast majority of cases and are most advantageous.

Update2: oh, and now that I think of it, while the above is more similar to what you were doing in that it iterates over the keys,

print $_, "\n" for values %fvalues;
is conceptually simpler. But then it may be more convenient to (locally) set ($\,$,) suitably and directly write
print values %fvalues;
Of course if you want to have output sorted according to the keys (as per holli's suggestion at Re^2: printing array values) or something similar, then you have to use keys.

Replies are listed 'Best First'.
Re^2: printing array values
by holli (Abbot) on May 19, 2005 at 09:44 UTC
    <nitpick>

    I would prefer the output to be numerically sorted.
    print $fvalues{$_}, "\n" for sort { $a<=>$b } keys %fvalues;
    </nitpick>


    holli, /regexed monk/
Re^2: printing array values
by texuser74 (Monk) on May 19, 2005 at 08:54 UTC
    thanks for your reply

    then could you please let me know how i can retreive a particular value from that hash, say for e.g fvalues{3}

      The problem is that there may not be a such a thing as $fvalue{3}. More precisely, hashes are not indexed by numbers, but by keys (strings).

      You may want to store your values in a real array. But then you should discard the keys. Or else you may want an array of arrays (AoA), each of which containing the key and the value. Or a HoA or an AoH. Who knows?!?

      You may also want to push your keys into an array for "sequential" retrieving. But then again, who knows?!? All this smells byzantine and suggests you may have an "XY problem": you are asking X, but you really want to do Y.

      I ask you to trust me when I tell you that this is "very" x 10 basic perl. I recommend reading some basic {introduction,tutorial}...