DAVEFLINDERS has asked for the wisdom of the Perl Monks concerning the following question:

how do i stop %20 results from reading a .dat file when i need spaces??
  • Comment on %20 results from reading info from a .dat file

Replies are listed 'Best First'.
Re: %20 results from reading info from a .dat file
by wog (Curate) on Jan 13, 2002 at 23:12 UTC

    It looks like you are dealing with URL-encoded data. The URI::Escape module can deal with this:

    use URI::Escape; # ... $data = uri_unescape($data);

    This should change %20 (in the $data variable) into spaces (assuming you are running on an ASCII-compatible platform), and other %XX sequences into the appropriate character. If you really don't want to use a module you can use the substitution: $data =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg which should be equivilent.

Re: %20 results from reading info from a .dat file
by screamingeagle (Curate) on Jan 13, 2002 at 23:44 UTC
    How about :
    $data =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
      Cargo-cult programming at work here! How about shortening this to more simply ...

      $data =~ s/%([\da-fA-F]{2})/chr(hex($1))/eg;

       

      perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Re: %20 results from reading info from a .dat file
by n3dst4 (Scribe) on Jan 13, 2002 at 22:54 UTC
    Well Dave, how about:
    s/%20/ /g;
    Cheerio.