Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

%20 results from reading info from a .dat file

by DAVEFLINDERS (Initiate)
on Jan 13, 2002 at 22:39 UTC ( #138445=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://138445]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2021-07-29 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?