
freddo
User
Mar 2, 2002, 4:28 AM
Post #3 of 13
(1275 views)
|
Re: [RandyL712] Best way to separate string?
[In reply to]
|
|
|
Hello Randy, Here it is my try at it:[perl]$verify = '<h2>Values Follow</h2>LOGIN=testgate<BR>AMOUNT=147.95<BR>TYPE=<BR>CARDTYPE=VISA<BR>CARDNUM=41XXXXXXXXXX1111<BR>'; @retval = qw/login amount type cardtype cardnum/; $regex = ".*?"; map { $regex .= "$_=(.*?)<BR>" } @retval; print "Regex is $regex\n"; print "Array:\n"; @values = $verify =~ /$regex/i; # get result in an array print join "\n", @values; print "\nHash:\n"; @value{@retval} = $verify =~ /$regex/i; # get result in a hash print "CardNum = ", $value{cardnum}, "\n"; # print cardnum[/perl] Now, keep in mind that: 1) the regex is case insensitive (dunno how this could be BAD) 2) Everything is accepted as a value (.*?) and you should better set valid ranges like [:alnum:] or [\.0-9]... Anyway, i hope you get what you want, if the hash thing seems a little strange, see Jasmine comments here (btw, thanks jasmine, i didnt knew that really nice feature of perl, i guess i'll get smaller .pl files now then ). Freddo ;---
|