For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > Facing problem with perl one-liner for single quote









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Facing problem with perl one-liner for single quote
Krishnan Hariharan

2007-08-31, 4:29 am

Hi all,

I am trying a one-liner substitution for a content in
a file.

original file content
---------
signal TCLK_IN : std_logic;
signal TPOS_IN : std_logic;
---------

I want to change it as:
---------
signal TCLK_IN : std_logic;
signal TPOS_IN : std_logic := '0';
-------

I wrote this one liner,

perl -pi -e 's/signal TPOS_IN \: std_logic;/signal
TPOS_IN \: std_logic \:= '0';/' <file_name>

But here i get an error saying, "Unmatched single
quote".

Can you please give me an idea what is wrong and how
to overcome this?

Thanks in advance.

Regards,
HK.




________________________________________
________________________________________
____
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
John W. Krahn

2007-08-31, 4:29 am

Krishnan Hariharan wrote:
> Hi all,


Hello,

> I am trying a one-liner substitution for a content in
> a file.
>
> original file content
> ---------
> signal TCLK_IN : std_logic;
> signal TPOS_IN : std_logic;
> ---------
>
> I want to change it as:
> ---------
> signal TCLK_IN : std_logic;
> signal TPOS_IN : std_logic := '0';
> -------
>
> I wrote this one liner,
>
> perl -pi -e 's/signal TPOS_IN \: std_logic;/signal
> TPOS_IN \: std_logic \:= '0';/' <file_name>
>
> But here i get an error saying, "Unmatched single
> quote".
>
> Can you please give me an idea what is wrong and how
> to overcome this?


You are using the (') single quote character to delimit the perl code so you
can't very easily use one inside the perl code.

One way to do it (it may not work depending on your shell.):

$ perl -le'print "one '''two''' three"'
one 'two' three


A better way, we find from an ASCII table (man ascii) that the single quote is
character number 39 (047 octal or 27 hexidecimal):

$ perl -le'print "one \047two\047 three"'
one 'two' three


So that gives you:

perl -i -pe's/^(signal\s+TPOS_IN\s+:\s+std_logic)(?=;)/$1 := \0470\047/'



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Gunnar Hjalmarsson

2007-08-31, 4:29 am

Krishnan Hariharan wrote:
> I am trying a one-liner substitution for a content in
> a file.
>
> original file content
> ---------
> signal TCLK_IN : std_logic;
> signal TPOS_IN : std_logic;
> ---------
>
> I want to change it as:
> ---------
> signal TCLK_IN : std_logic;
> signal TPOS_IN : std_logic := '0';
> -------
>
> I wrote this one liner,
>
> perl -pi -e 's/signal TPOS_IN \: std_logic;/signal
> TPOS_IN \: std_logic \:= '0';/' <file_name>
>
> But here i get an error saying, "Unmatched single
> quote".


Use double-quotes instead, at least if you are on Windows.

perl -pi"orig_*" -e "s/(TPOS_IN[^;]+)/$1 := '0'/" <file_name>

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
John W. Krahn

2007-08-31, 4:29 am

Gunnar Hjalmarsson wrote:
> Krishnan Hariharan wrote:
>
> Use double-quotes instead, at least if you are on Windows.
>
> perl -pi"orig_*" -e "s/(TPOS_IN[^;]+)/$1 := '0'/" <file_name>


If you do that the shell will interpret $1 as one of its variables.

If the OP were on windows then he won't have been able to use single quotes
for the original.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Gunnar Hjalmarsson

2007-08-31, 4:29 am

John W. Krahn wrote:
> Gunnar Hjalmarsson wrote:
>
> If you do that the shell will interpret $1 as one of its variables.


Yes, a *nix shell will, so on *nix you need \$1

> If the OP were on windows then he won't have been able to use single
> quotes for the original.


If I understood it correctly, he wasn't...

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
John W. Krahn

2007-08-31, 4:29 am

Gunnar Hjalmarsson wrote:
> John W. Krahn wrote:
>
> Yes, a *nix shell will, so on *nix you need \$1
>
>
> If I understood it correctly, he wasn't...



Krishnan Hariharan wrote:
>
> I wrote this one liner,
>
> perl -pi -e 's/signal TPOS_IN \: std_logic;/signal
> TPOS_IN \: std_logic \:= '0';/' <file_name>



It looks like he was?




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Krishnan Hariharan

2007-08-31, 4:29 am

Hello all,

Thanks for your help.

I tried using "\047" ASCII for the single quote in the
substitution and it worked.

The OS am using is Sun Solaris.

Regards,
HK.


--- "John W. Krahn" <krahnj@telus.net> wrote:

> Gunnar Hjalmarsson wrote:
> on Windows.
> '0'/" <file_name>
> of its variables.
> able to use single
>
>
> Krishnan Hariharan wrote:
> std_logic;/signal
>
>
> It looks like he was?
>
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where
> you
> can special-order certain sorts of tools at low cost
> and
> in short order. -- Larry
> Wall
>
> --
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
> http://learn.perl.org/
>
>
>




________________________________________
________________________________________
____
Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/ya..._invite.asp?a=7


Gunnar Hjalmarsson

2007-08-31, 7:27 pm

John W. Krahn wrote:
> Gunnar Hjalmarsson wrote:
>
>
> Krishnan Hariharan wrote:
>
>
> It looks like he was?


Well, he also let us know that he got an error that complained about
single quotes, which made me suspect he might be on Windows. Anyway, now
we know that I was wrong.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com