in reply to How do I pass values entered in the textfield into a hash?

You might also want to add a little data filtration on the keys and values to at least strip leading and trailing whitespace otherwise "a=>4" will generate a different key to say " a =>4". Something like:

foreach (split /,\s*/, param('hashdata')) { my ($k, $v) = split(/=>/); whitespace(\$k,\$v); $hash{$k} = $v; } sub whitespace { while (my $ref = shift){ $$ref =~ s/^\s+|\s+$//g } }

We pass the sub references to the variables so we can change them in the sub and not bother having to return the changed values and assign them.

cheers

tachyon

Replies are listed 'Best First'.
Re: Answer: how do i pass values entered in the textfield into a hash ?
by tachyon (Chancellor) on Jul 09, 2001 at 04:10 UTC

    chromatic points out that split(/\s*=>\s*/) is is a shorter and more efficient solution to the whitespace problem:

    foreach (split /,\s*/, param('hashdata')) { my ($k, $v) = split(/\s*=>\s*/); $hash{$k} = $v; }

    I have to agree :-(

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print