in reply to Re: Save form data with decoded URL chars
in thread Save form data with decoded URL chars

Hej Anonimous monk and thanks for your reply,

The problem is that my original csv file is ISO-8859-1 encoded and that all clients that will use this script will use ISO-8859-1 on their browsers. I did this (exactly that you showed me before :-D ) :

sub URLDekod { my $URLkodad = $_[0]; $URLkodad =~ tr/+/ /; $URLkodad =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg; return $URLkodad; }
but that means I have to open a file again, run through subroutine, save it to another file and then close and unlink and rename and so on.

I was just looking for TMTOWTDI from more experienced people that probably is much shorter then my solution (having in mind simple fact that I have som problems by taking C out of my head).

This is what I did after saving file

open (TEMP, "<$tempfil") or die "Kan inte \xF6ppna filen $kontorfil"; open (NYF, "+>$nyfil") or die "Kan inte \xF6ppna filen $nyfil"; flock (NYF,2) or die $!; while (<TEMP>) { print NYF URLDekod($_); close TEMP; close NYF; }

Any better TMTOWTDI is highly appreciated.

Replies are listed 'Best First'.
Re^3: Save form data with decoded URL chars
by Anonymous Monk on Aug 08, 2012 at 13:16 UTC

    but that means I have to open a file again, run through subroutine, save it to another file and then close and unlink and rename and so on.

    No you don't, why do you think you need to do that?

    Any better TMTOWTDI is highly appreciated.

    Its simple, don't use save, use param

      Any chance you could post a little snippet to point me to right direction ?

        Any chance you could post a little snippet to point me to right direction ?

        No, the CGI documentation is full of snippets, and the distribution comes with samples

        perl -MCGI -e " $q= CGI->new({ ro => qq{=sh\nam=bo\n}, }); print qq{\ +n\n\n# first save()d and new()able\n}; $q->save( \*STDOUT ); print qq +{# and now not save()d and not new()able\n}; for my $key( $q->param ) +{ for my $val( $q->param($key) ){ print qq{$key=$val\n}; } } " # first save()d and new()able ro=%3Dsh%0Aam%3Dbo%0A = # and now not save()d and not new()able ro==sh am=bo