Can't get command line perl to work right

D

Dave

Hi,

I'm using Perl 5.8.9 on Mac 10.6.3. I have a file and I want to have
a new file where the uri_escape function is applied to each line of
the file. However, this call

perl -pi -e 'use URI::Escape; print uri_escape($_)' link_names.txt

only partially works. The result is a line that contains the escaped
string, and then the original string. How do I modify the code above
to print out only the escaped string?

Thanks, - Dave
 
S

sln

Hi,

I'm using Perl 5.8.9 on Mac 10.6.3. I have a file and I want to have
a new file where the uri_escape function is applied to each line of
the file. However, this call

perl -pi -e 'use URI::Escape; print uri_escape($_)' link_names.txt

only partially works. The result is a line that contains the escaped
string, and then the original string. How do I modify the code above
to print out only the escaped string?
perl -ni -mURI::Escape -e 'print uri_escape($_)' link_names.txt

maybe

-sln
 
C

Charlie Harvey

Hi,

I'm using Perl 5.8.9 on Mac 10.6.3. I have a file and I want to have
a new file where the uri_escape function is applied to each line of
the file. However, this call

perl -pi -e 'use URI::Escape; print uri_escape($_)' link_names.txt

only partially works. The result is a line that contains the escaped
string, and then the original string. How do I modify the code above
to print out only the escaped string?

Thanks, - Dave

Hi Dave,

perl -n -E 'use URI::Escape; say uri_escape($_)' link_names.txt

Cheers,
Charlie
 
J

J. Gleixner

Dave said:
Hi,

I'm using Perl 5.8.9 on Mac 10.6.3. I have a file and I want to have
a new file where the uri_escape function is applied to each line of
the file. However, this call

perl -pi -e 'use URI::Escape; print uri_escape($_)' link_names.txt

only partially works. The result is a line that contains the escaped
string, and then the original string. How do I modify the code above
to print out only the escaped string?


Check the documentation to see what those flags actually do:

perldoc perlrun

Hint: using -p along with print might be redundant.

If you want a new file, then you need to specify it. Hint: -i
 
P

pleier

Hi,

I'm using Perl 5.8.9 on Mac 10.6.3. I have a file and I want to have
a new file where the uri_escape function is applied to each line of
the file. However, this call

perl -pi -e 'use URI::Escape; print uri_escape($_)' link_names.txt

only partially works. The result is a line that contains the escaped
string, and then the original string. How do I modify the code above
to print out only the escaped string?

Thanks, - Dave

The -p already prints the original line, just leave it and it should work.

gerhard
 
U

Uri Guttman

p> The -p already prints the original line, just leave it and it should work.

leave what? uri_escape returns a value so it needs to either be printed
explicitly or assigned to $_.

these should be equivilent:

perl -pi -e 'use URI::Escape; $_ = uri_escape($_)' link_names.txt
perl -ni -e 'use URI::Escape; print uri_escape($_)' link_names.txt

and using -M is a little cleaner too:

perl -pi -MURI::Escape -e '$_ = uri_escape($_)' link_names.txt

uri
 
D

Dave

  >> perl -pi -e 'use URI::Escape; print uri_escape($_)' link_names.txt

  p> The -p already prints the original line, just leave it and it should work.

leave what? uri_escape returns a value so it needs to either be printed
explicitly or assigned to $_.

these should be equivilent:

perl -pi -e 'use URI::Escape; $_ = uri_escape($_)' link_names.txt
perl -ni -e 'use URI::Escape; print uri_escape($_)' link_names.txt

and using -M is a little cleaner too:

perl -pi -MURI::Escape -e '$_ = uri_escape($_)' link_names.txt

uri

Thanks for everyone's suggestions. Unfortunately, I got different
errors from all of them except Uri's. Uri, you're solution did not
result in any errors, but everything appeared on one long line (I
noticed the carriage returns got escaped as "%0A"). Is there a way to
make each line appear separately? - Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top