in reply to Re: Filling a hash
in thread Filling a hash

how I can add an element to a hash using the push function in an intuitive way

One could push the key value pairs onto an array and then construct a hash from that array (but that's just wonky, even for homework).

Replies are listed 'Best First'.
Re^3: Filling a hash
by polettix (Vicar) on Oct 26, 2005 at 14:19 UTC
    Something like:
    { my @ary = %hash; push @ary, $k => $v; %hash = @ary; }
    I suppose. But it doesn't seem much natural :) I only wondered why the teacher had to specify this strange requirement.

    Update: corrected bug in snippet, thanks to QM

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.