in reply to Re: ref, no, maybe?
in thread ref, no, maybe?
That's fed to the routine that creates the query string and everybody's happy. What you're suggesting seems to imply that I should break the hash in two and feed them in separately, or send them to different functions. That seems less efficient. Is there a benefit to approaching it that way, or did I misunderstand your response?my %hash = ( name => 'Ovid', color => [ 'red', 'blue' ], COBOL => 'sucks' );
Cheers,
Ovid
Update: Hmm... it occurs to me that I could have made *all* values into array refs. The code would be smaller and easier to follow. The while{} loops becomes this:
Saved about six lines of code and made it cleaner, to boot. Damn. merlyn strikes again!while (($key, $value) = each %data) { $key = uri_escape( $key, $cgi_chars ); foreach ( @$value ) { my $array_value = uri_escape( $_, $cgi_chars ); $query_string .= "$key=$array_value&"; } }
So here's the interesting question: is it coincidence that I was able to improve this subroutine and eliminate the ref, or is seeing a ref in code generally indicative of a poor algorithm that bears further investigation? Here's another question: is that last sentence pompous enough for you?
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid) Re(2): ref, no, maybe?
by Fastolfe (Vicar) on Jan 11, 2001 at 04:40 UTC | |
|
Re: (Ovid) Re(2): ref, no, maybe?
by merlyn (Sage) on Jan 11, 2001 at 05:22 UTC | |
by tilly (Archbishop) on Jan 11, 2001 at 05:54 UTC | |
|
Re (tilly) 3: ref, no, maybe?
by tilly (Archbishop) on Jan 11, 2001 at 06:01 UTC | |
by tye (Sage) on Jan 12, 2001 at 03:06 UTC |