[TriLUG] Perl substitution problem

Ken M via TriLUG trilug at trilug.org
Fri Jun 16 16:50:07 EDT 2017


That would be my suggestion, cpan is your friend.  But if not don't try
to handle the json elements directly as a string.  Build a hash and then
write a routine to export your hash as json.  Or I am pretty sure that
is how one of the json libraries works anyway.  Taking a page from
python's json stdlib the json load and dump routines basically work with
dictionaries.

On Fri, Jun 16, 2017 at 01:28:41PM -0400, Wes Garrison via TriLUG wrote:
> 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
> 


More information about the TriLUG mailing list