Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

linuxer's scratchpad

by linuxer (Curate)
on Apr 24, 2008 at 19:05 UTC ( [id://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 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