in reply to Save form data with decoded URL chars

The problem is that file is saved with URL encoded Swedish letters, even if client is set to ISO 8859-1 and header from server is set to same

How is that a problem ?

save is a CGI.pm serialization method, if you want to read the file again, use CGI.pm's new, and then use param as usual, and decode / encode as usual ( perlunitut: Unicode in Perl#I/O flow (the actual 5 minute tutorial) )

Besides that, you should start writing functions that take arguments, functions that do not operate on global variables, like I already showed you

  • Comment on Re: Save form data with decoded URL chars

Replies are listed 'Best First'.
Re^2: Save form data with decoded URL chars
by SerZKO (Beadle) on Aug 08, 2012 at 12:59 UTC

    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.

      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 ?