faqts : Computers : Programming : Languages : Perl

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 16 people (44%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How to create name/value from string based on equal sign?

Dec 1st, 2004 09:12
Nat Tuck, Guest,


If you have the $string
"this=that monkeys=red stuff=purple bob=tuna"
you can say
@pairs = split /\s+/, $string;
foreach $p (@pairs) {
   ($k, $v) = split /=/, $p;
   $hash{$k} = $v;
}