Re: can you pass an array in a form in Perl




John wrote:

Is the following possible in Perl?

print "<form>";
print "<input type='hidden' name='cities' value='@industries'>";
print </form>";

I want to pass an array as a hidden value.

The values of HTML fields are plain text (this as nothing to do with
Perl). A Perl array has structure (this as nothing to do with HTML).
To store something with structure in a plain text string you need to
serialize it in some way (this as nothing to do with Perl or HTML).

If you have a Perl array the elements of which are plain text and which
you know won't contain a given character you can simply use join() and
split().

If you want to store aribtrary Perl structures in plain text fields the
usual approach is to use Storeable and MIME::Base64. (And optionally
some sort or compression and encryption).

use Storable qw( freeze thaw );
use MIME::Base64;
use Compress::Zlib qw( compress uncompress );
require Crypt::CBC;

my $cipher = Crypt::CBC->new($ENV{CRYPTO_KEY},'Blowfish');

sub encode {
encode_base64(compress($cipher->encrypt(freeze(shift))),'');

}

sub decode {
my $state = shift;
return unless $state;
thaw($cipher->decrypt(uncompress(decode_base64($state))));
}

.



Relevant Pages

  • Re: not receiving emails expected
    ... $send_toarray. ... Is it because values have not been added to $dest ... And don't try to fool with html to start. ... And when you do send html email, you should always have a plain text ...
    (comp.lang.php)
  • Re: can you pass an array in a form in Perl
    ... A Perl array has structure (this as nothing to do with HTML). ... To store something with structure in a plain text string you need to ... If you want to store aribtrary Perl structures in plain text fields the ...
    (perl.beginners)
  • Error: RCPT TO: error (550 relay not permitted)
    ... PERL. ... subject => 'Test HTML mail', ... $plain = encode_qp $text; ...
    (comp.lang.perl.modules)
  • Re: Learning Perl
    ... it should be an array, ... Then they'd be completely inaccessible to beginners. ... that should be my $var. ... so why is it redundant to point out that Perl is different from C here? ...
    (comp.lang.perl.misc)
  • Re: Walking a tree and extracting info... Problems
    ... Learn to use the Perl debugger and to use the ... foreach $file (@thefiles) { ... push @lines, $_; # push the data line onto the array ... Perl has allocated "@lines" once for the whole program; when you process the next file in the directory you push the lines on the bottom; the match for the HTML title then fires every time. ...
    (comp.lang.perl.misc)