[TriLUG] Perl substitution problem

karl flores via TriLUG trilug at trilug.org
Fri Jun 16 13:07:36 EDT 2017


Error: Parse error on line 1:
my $string2 = 'this
^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'


On Fri, Jun 16, 2017 at 12:57 PM, Wes Garrison via TriLUG <trilug at trilug.org
> wrote:

> My Google-fu is not good enough to solve this simple problem.
>
> I am building some simple JSON structures by hand in Perl, and I need to
> escape double-quotes.
>
> my $string1 = 'this "should" work';
> $string1 =~ s/"/\\"/g;
> print $string1 \n;
> this \"should\" work
>
> ^ Yay!  it substituted correctly for both double-quotes!
>
> my $string2 = 'this "should"*,* work';
> $string2 =~ s/"/\\"/g;
> print $string2 \n;
> this \"should" work
>
> ^ the comma after the second double-quote broke the substitution. (and it
> breaks my JSON)
>
> Why?  What the heck am I missing?
>
> -Wes
> _________________________________
> Wesley S. Garrison
> Network Engineer
> Xitech Communications, Inc.
> phone:  (919) 260-0803
> fax:       (919) 932-5051
> __________________________________
> "Lead us not into temptation, but deliver us from email."
> --
> This message was sent to: karl flores <karl.americorp at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  : https://www.trilug.org/
> mailman/options/trilug/karl.americorp%40gmail.com
> Welcome to TriLUG: http://trilug.org/welcome




-- 
Karl Flores
IT Specialist
Directl: 619-796-1329
Fax:  858-605-4265


"There are those who look at opportunities and contemplate limitations.
There are those who seek opportunities and discover limitations. And there
are those who find opportunities and challenge their own limitations."



"My children are footprints that prove I existed"

 "My life is based on a true story. The characters, incidents, and
dialogues are products of my imagination and are not to be construed as
real. Any resemblance to actual events or persons, living or dead, is
entirely accidental."

"What I now know is that I never knew that I knew what I know"

 "Finish Happy"


More information about the TriLUG mailing list