Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't get command line perl to work right

Reply
Thread Tools

Can't get command line perl to work right

 
 
Dave
Guest
Posts: n/a
 
      02-24-2011
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
 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      02-24-2011
On Thu, 24 Feb 2011 09:41:54 -0800 (PST), Dave <> wrote:

>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
 
Reply With Quote
 
 
 
 
Charlie Harvey
Guest
Posts: n/a
 
      02-24-2011
On 24/02/11 17:41, Dave wrote:
> 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
 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      02-24-2011
Dave wrote:
> 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
 
Reply With Quote
 
pleier
Guest
Posts: n/a
 
      02-24-2011
On 24.02.2011 18:41, Dave wrote:
> 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
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      02-24-2011
>>>>> "p" == pleier <> writes:

>> 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

--
Uri Guttman ------ -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      02-24-2011
On Feb 24, 12:50*pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "p" == pleier *<n...@pleier.org> writes:

>
> * >> 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
>
> --
> Uri Guttman *------ *u...@stemsystems.com *-------- *http://www.sysarch.com--
> ----- *Perl Code Review , Architecture, Development, Training, Support ------
> --------- *Gourmet Hot Cocoa Mix *---- *http://bestfriendscocoa.com---------


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
 
Reply With Quote
 
Justin C
Guest
Posts: n/a
 
      02-25-2011
On 2011-02-24, Charlie Harvey <charlie+> wrote:
> On 24/02/11 17:41, Dave wrote:
>> 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


This is for 5.10, the OP doesn't have 5.10.

Justin.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSpec command line run command doesn't work P. A. Ruby 0 09-04-2009 02:30 AM
Right-Click With Mouse and Toolba Buttonsr Don't Work Right Bigfoot It Is Computer Support 0 10-30-2006 06:08 PM
use one line Perl command to add a line at the begin of a file Ting Wang Perl Misc 3 12-13-2005 06:07 PM
Pull out only first field of ps command ( in Perl ) PERL RUN COMMAND tweetiebirds@gmail.com Perl Misc 2 03-26-2005 06:03 AM
A question about Perl: using perl command line to replace strings... lucy Perl Misc 7 09-03-2004 07:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57