Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

linuxer's scratchpad

by linuxer (Deacon)
on Apr 24, 2008 at 19:05 UTC ( #682694=scratchpad: print w/ replies, xml ) Need Help??

Maybe useful:


CGI's Vars returns multi-valued parameters as a packed string, separated by the "\0" (null) character.

If you know of a reason why one should not use Vars(), it would be great, if you could send me some info about that reason...

#!/usr/bin/perl use strict; use warnings; use CGI; use Data::Dumper; my $cgi = CGI->new(); my %p = $cgi->Vars; # if you don't like the \0 delimiter, replace it by your own one; e.g. +: s/\0/[whatever I want]/g for values %p; print Dumper \%p; __END__ $ perl T.pl a=1 b=1 b=2 b=3 $VAR1 = { 'a' => '1', 'b' => '1[whatever I want]2[whatever I want]3' };

Example how to count the number of "\n" in a string; see #How can I count the number of occurrences of a substring within a string?

#!/usr/bin/perl -l use strict; use warnings; my $text = qq(I have multiple lines ); print $text =~ s/\n/\n/g; # substitute print $text =~ tr/\n//; # transliterate __END__

Example how to use Text::CSV with a CSV file containing fields with multi-lined fields:

#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $csv_file = 'test.csv'; # binary => 1 : makes Text::CSV work on multi-lined fields my $csv = Text::CSV->new( { binary => 1 } ); #open my $fh, '<', $csv_file or die "$csv_file: $!\n"; # *DATA; instead of opening a separate file; using the data section at + the end of file my $fh = *DATA; # read rows and store them in an array reference while ( my $ref = $csv->getline( $fh ) ) { # dereference the reference and simply print the elements print "@$ref\n"; } #close $fh or die "$csv_file: close failed: $!\n"; __DATA__ "column1","column2","column3" "single1","single2","single3" "single4","multiA multiB",single5
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-09-02 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (31 votes), past polls