Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: simplifying a CGI param request

by Anonymous Monk
on Apr 07, 2006 at 17:13 UTC ( #541927=note: print w/replies, xml ) Need Help??


in reply to Re: simplifying a CGI param request
in thread simplifying a CGI param request

hashes don't keep them in the order I need. How would I sort them to print out q1, q2, q3 etc in order in a foreach loop?

Replies are listed 'Best First'.
Re^3: simplifying a CGI param request
by japhy (Canon) on Apr 07, 2006 at 17:21 UTC
    You'd take his for loop and instead of putting the stuff in a hash you'd just do something with the number right then and there!
    for (1 .. 25) { my $value = param("q$_"); print "Value #$_ = $value\n"; }

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
      This could work or you could drop the "q" from the hash key and then just do a numeric sort on the hash and add it back in at the end.


      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid

        Or you could sort it thusly:

        foreach $key( map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { m/q(\d+)/; [ $1, $_ ] } keys %hash ){ print "$key : $hash{$key}\n"; }

        (untested)



        --chargrill
        $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-02-03 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (24 votes). Check out past polls.

    Notices?