Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: JSON saving regex?

by thargas (Deacon)
on Jan 27, 2012 at 13:16 UTC ( #950357=note: print w/replies, xml ) Need Help??

in reply to JSON saving regex?

The problem is that qr/.../ produces a Regexp object (try ref(qr/.../)).

If you know where all the regexes are in your structure, you could convert them all to strings before calling to_json() on them.

Or you can do:
{ package Regexp; sub TO_JSON { my $regex = shift; $regex = "$regex"; return $regex; } my $json = JSON->new->convert_blessed; print $json->encode(qr/.../);
as documented in JSON

Replies are listed 'Best First'.
Re^2: JSON saving regex?
by The Perlman (Beadle) on Jan 27, 2012 at 21:09 UTC

    Thanks for showing that this solution exists.

    (I hoped it would, but was too lazy to look it up :)

    Just one remark: I hope the OP doesn't expect that those RegExes always work in other languages than Perl.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950357]
[james28909]: everything past the first two things you piked from my posts are irrelevant to me and my beliefs. they are side effects.
[james28909]: two or three. if it has to do with how humans are handling said situations, then that is after they were able to evolve into those problems. agnostic means only believe with evidence. i took that from a tyson video
[james28909]: and it seems that racism suggest that there is indeed a better race, but that is for evolution to decide
[1nickt]: "right now, humans are smarter than in any of those times": define "smart"
[erix]: ah, now you're appraoch downvote-territory ;)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2017-12-15 14:57 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (433 votes). Check out past polls.