You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Andy Lim <an...@caltan.com> on 2001/05/11 20:00:59 UTC
sorting a hash for checkbox list..
Hello.
I want to sort a hash which contaning key-value pair for a list checkbox
(like below) so that it print in the specific order.
Anyone know how to do this?
------------------------------------
[-
@application_k = keys %GSIS::PROD_APPLICATION;
@application_v = values %GSIS::PROD_APPLICATION;
-]
<input type="checkbox" name="app_type" value="[+ $application_k[$row] +]">
[+ $application_v[$row] +]
Andrew
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: sorting a hash for checkbox list..
Posted by ___cliff rayman___ <cl...@genwax.com>.
you're right.
in the original example i stole this from, there were
some function calls and data tests. without them,
this is overly complex .
Angus Lees wrote:
> On Mon, May 14, 2001 at 05:14:31PM -0700, ___cliff rayman___ wrote:
> > if by value order by key order then:
> > @application_k =
> > map {$_->[0]}
> > sort {$a->[1] <=> $b->[1] || $a->[0] cmp $b->[0]}
> > map {[$_ , $GSIS::PROD_APPLICATION{$_}]}
> > keys %GSIS::PROD_APPLICATION;
> >
> > the second one is called a schwartzian transform. u should be
> > able to find an explanation of it on the web.
>
> i don't get it. why not just do:
>
> *h = \%GSIS::PROD_APPLICATION; # just to make the example shorter..
>
> @k = sort {$h{$a} <=> $h{$b} || $a cmp $b} keys %h;
>
> --
> - Gus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: sorting a hash for checkbox list..
Posted by Angus Lees <gu...@switchonline.com.au>.
On Mon, May 14, 2001 at 05:14:31PM -0700, ___cliff rayman___ wrote:
> if by value order by key order then:
> @application_k =
> map {$_->[0]}
> sort {$a->[1] <=> $b->[1] || $a->[0] cmp $b->[0]}
> map {[$_ , $GSIS::PROD_APPLICATION{$_}]}
> keys %GSIS::PROD_APPLICATION;
>
> the second one is called a schwartzian transform. u should be
> able to find an explanation of it on the web.
i don't get it. why not just do:
*h = \%GSIS::PROD_APPLICATION; # just to make the example shorter..
@k = sort {$h{$a} <=> $h{$b} || $a cmp $b} keys %h;
--
- Gus
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: sorting a hash for checkbox list..
Posted by ___cliff rayman___ <cl...@genwax.com>.
if by key order then"
@application_k = sort keys %GSIS::PROD_APPLICATION;
if by value order by key order then:
@application_k =
map {$_->[0]}
sort {$a->[1] <=> $b->[1] || $a->[0] cmp $b->[0]}
map {[$_ , $GSIS::PROD_APPLICATION{$_}]}
keys %GSIS::PROD_APPLICATION;
the second one is called a schwartzian transform. u should be
able to find an explanation of it on the web.
Andy Lim wrote:
> Hello.
> I want to sort a hash which contaning key-value pair for a list checkbox
> (like below) so that it print in the specific order.
> Anyone know how to do this?
> ------------------------------------
> [-
> @application_k = keys %GSIS::PROD_APPLICATION;
> @application_v = values %GSIS::PROD_APPLICATION;
> -]
>
> <input type="checkbox" name="app_type" value="[+ $application_k[$row] +]">
> [+ $application_v[$row] +]
>
--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: sorting a hash for checkbox list..
Posted by Kee Hinckley <na...@somewhere.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 11:00 AM -0700 5/11/01, Andy Lim wrote:
>Hello.
>I want to sort a hash which contaning key-value pair for a list checkbox
>(like below) so that it print in the specific order.
>Anyone know how to do this?
>------------------------------------
>[-
> @application_k = keys %GSIS::PROD_APPLICATION;
> @application_v = values %GSIS::PROD_APPLICATION;
>-]
>
><input type="checkbox" name="app_type" value="[+ $application_k[$row] +]">
>[+ $application_v[$row] +]
[- @application_k = sort keys %GSIS::PROD_APPLICATION; -]
<input type="checkbox" name="app_type" value="[+ $application_k[$row] +]">
[+ $GSIS::PROD_APPLICATION{$application_k[$row]} +]
- --
Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBOvxBwyZsPfdw+r2CEQIgowCeNdNXFkPOkVST+zcgR+/gl9LeyQ8AoLkV
mMi+QDrWNdPa2rWAh525ILmB
=LnX8
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: sorting a hash for checkbox list..
Posted by Brooklyn Linux Solutions CEO <ru...@mrbrklyn.com>.
perldoc -f sort
On 2001.05.11 14:00:59 -0400 Andy Lim wrote:
Hello.
I want to sort a hash which contaning key-value pair for a list checkbox
(like below) so that it print in the specific order.
Anyone know how to do this?
------------------------------------
[-
@application_k = keys %GSIS::PROD_APPLICATION;
@application_v = values %GSIS::PROD_APPLICATION;
-]
<input type="checkbox" name="app_type" value="[+ $application_k[$row] +]">
[+ $application_v[$row] +]
Andrew
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
--
Brooklyn Linux Solutions
http://www.mrbrklyn.com
http://www.brooklynonline.com
1-718-382-5752
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org