[TriLUG] Perl substitution problem

Wes Garrison via TriLUG trilug at trilug.org
Fri Jun 16 13:28:41 EDT 2017


As William says, you don't need strict, but you do need a #!/usr/bin/perl
at the top.

I was just trying to type out a pseudo-code example to show how the comma
is a problem, but yes the \n has to be inside quotes for it to work.

So this whole thing was a red herring, as usual.

The problem was at the bottom of my code I was doing this:
$output =~ s/\\",/",/gi;

...so replacing \", with just ",  so that a " at the end of a comment
doesn't break the JSON.

Looks like I just need to use a JSON library instead of trying to build it
by hand.

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

On Fri, Jun 16, 2017 at 1:18 PM, William Sutton via TriLUG <
trilug at trilug.org> wrote:

> use strict not required for my/our.  he did something else when he pasted
> his code.
>
> Also, HTH does
>
> print $string1 \n;
>
>
> work in Perl?  It needs to be
>
> print "$string1 \n";
>
> otherwise, I'm looking at your question
>
> William Sutton (Perl expert)
>
>
> On Fri, 16 Jun 2017, Brian via TriLUG wrote:
>
> You need a
>>
>> use strict;
>>
>> for "my" to work, which Wes omitted probably for the sake of brevity.
>>
>> -B
>>
>>
>> On 06/16/2017 01:07 PM, karl flores via TriLUG wrote:
>>
>>> 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
>>>>
>>>
>>>
>>>
>>>
>>>
>> --
>> This message was sent to: William <william at trilug.org>
>> 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/william%40trilug.org
>> Welcome to TriLUG: http://trilug.org/welcome
>>
> --
> This message was sent to: Wes <wes at xitechusa.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/wes%40xitechusa.com
> Welcome to TriLUG: http://trilug.org/welcome
>


More information about the TriLUG mailing list