Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: how do i pass values entered in the textfield into a hash ?

by tachyon (Chancellor)
on Jul 03, 2001 at 21:12 UTC ( [id://93586]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://93586]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found