
Kanji
User
Jul 2, 2000, 7:32 PM
Post #3 of 4
(701 views)
|
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> ($variable1, $variable2) = split(/&/,$ENV{'QUERY_STRING'});</pre><HR></BLOCKQUOTE> ... should suffice, as what you're doing is resetting the two variables after already setting them. ie, <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> foreach( @DATA ) { ... } # is the same as foreach ( "fo", "fum" ) { ... } # is (functionally) the same as foreach ( 1, 2 ) { ... } # is the same as ... ...</pre><HR></BLOCKQUOTE> For scalability, tho', I'd stick with the array assignment because you could then access variables as $DATA[0] (fo), $array[1] (fum), etc. but not have to hardcode any more variables if you decided to pass more arguments. It's odd to see arguments like that passed to a script though. Usually they take a key/value form like ?colour=blue&indent=yes. I suspect that's where you got your redundant loop from as there's lots of code out there like ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> @pairs = split(/&/,$ENV{'QUERY_STRING'}); foreach $pair (@pair) { ($key,$value) = split(/=/,$pair); $inpput{$key} = $value; }</pre><HR></BLOCKQUOTE> (Note the second split on = not &). However, is this is what you were really after, I'd advise you to use CGI.pm or one of the other CGI modules instead. Makes life a lot easier and saves you reinventing the wheel. If that's what you had in mind, then you should take [This message has been edited by Kanji (edited 07-02-2000).]
|