For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > BitVector in GET/POST Params









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author BitVector in GET/POST Params
Richard Heintze

2004-05-22, 11:31 am

I have a bit array I need to store in GET/POST
parameters and <input type=hidden> fields. Presently
I'm storing one bit per hidden field.

I would like to optimize this and use a little less
space. If I know I need less than 32 elements in my
boolean (bit) array, I can just use an integer in a
single hidden field.

What if I need more than 32 elements in my bit array?
I suppose I could use the first hidden field for the
first 32 elements of my array and the next 32 elements
are stored in the next hidden field. Uggghhh... Is
there an easier way?

Sieg

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/
Wc -Sx- Jones

2004-05-22, 11:31 am

Richard Heintze wrote:

> What if I need more than 32 elements in my bit array?
> I suppose I could use the first hidden field for the
> first 32 elements of my array and the next 32 elements
> are stored in the next hidden field. Uggghhh... Is
> there an easier way?


You must not read the regular beginners list?

Lucky you :) Store it in as many 32 bit numbers
as required and use pack/unpack -

#! /usr/bin/perl
use strict;
use warnings;

my $count;
my $index;
my $str;

while (++$index) {
$count = $index;

while(1) {
(++$count) ? $count += $count--
: $count += $count++;

$str = unpack("B32", pack("N", $count));
print "$count \tis binary $str\n";
last if $count > 60_000;
sleep 1;
}

exit if $index > 255;
}

__END__
-Sx-

PS - Incase you missed the joke -
the ONLY relevant part of this
answer is -

$str = unpack("B32", pack("N", $count));
Richard Heintze

2004-05-22, 11:31 am

Let me rephrase that question:
Is there a way I can store large integers (> 2**32) as
character strings in radix 10 or radix 16 and covert
these strings to and from bitvectors from which I can
insert and extract individual bits?

I think bitvector is the name of the module. I did a
search on CPAN and looked thru my perldoc but could
not find it. What is the name of feature for storing
large boolean arrays?

Thanks,
Siegfried


--- WC -Sx- Jones <sx@insecurity.org> wrote:
> Richard Heintze wrote:
>
> array?
> the
> elements
>
> You must not read the regular beginners list?
>
> Lucky you :) Store it in as many 32 bit numbers
> as required and use pack/unpack -
>
> #! /usr/bin/perl
> use strict;
> use warnings;
>
> my $count;
> my $index;
> my $str;
>
> while (++$index) {
> $count = $index;
>
> while(1) {
> (++$count) ? $count += $count--
> : $count += $count++;
>
> $str = unpack("B32", pack("N", $count));
> print "$count \tis binary $str\n";
> last if $count > 60_000;
> sleep 1;
> }
>
> exit if $index > 255;
> }
>
> __END__
> -Sx-
>
> PS - Incase you missed the joke -
> the ONLY relevant part of this
> answer is -
>
> $str = unpack("B32", pack("N", $count));
>
> --
> To unsubscribe, e-mail:
> beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-cgi-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>



__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/
Randy W. Sims

2004-05-22, 11:31 am

On 4/2/2004 12:45 AM, Richard Heintze wrote:

> Let me rephrase that question:
> Is there a way I can store large integers (> 2**32) as
> character strings in radix 10 or radix 16 and covert
> these strings to and from bitvectors from which I can
> insert and extract individual bits?
>
> I think bitvector is the name of the module. I did a
> search on CPAN and looked thru my perldoc but could
> not find it. What is the name of feature for storing
> large boolean arrays?


maybe 'perldoc -f vec', 'perldoc -f pack',
also <http://search.cpan.org/search?query=bit>


Wc -Sx- Jones

2004-05-22, 11:31 am

Randy W. Sims wrote:
> maybe 'perldoc -f vec', 'perldoc -f pack',
> also <http://search.cpan.org/search?query=bit>


I was only suggesting:

man perlpacktut
-Sx-
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com