Thread JSON Regex ausgeben (35 answers)
Opened by bianca at 2013-10-30 08:46

bianca
 2013-10-30 08:46
#171641 #171641
User since
2009-09-13
6975 Artikel
BenutzerIn

user image
Wie kann man einen Regex in ein JSON Format ausgeben, sodass das browserseitig mit JSON.parse() wieder sauber entfaltet und funktionsfähig ist?
Ich scheitere im Moment an einer CPAN:JSON Fehlermeldung:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use JSON 2.59;

my %var = (
        regex => qr{[^a-z]}i,
);
print 'Test '.('FOO1' =~ $var{regex} ? 'erfolgreich' : 'fehlgeschlagen')."\n";
my $json_obj = JSON->new->latin1;
$json_obj->convert_blessed(0);
my $json = $json_obj->encode(\%var);

Quote
Test erfolgreich
Uncaught exception from user code:
encountered object '(?^i:[^a-z])', but neither allow_blessed nor convert_blessed settings are enabled at test.pl line 13.
JSON::PP::encode_error('encountered object \'(?^i:[^a-z])\', but neither allow_blesse...') called at C:/strawberry/perl/lib/JSON/PP.pm line 340
JSON::PP::object_to_json('JSON=HASH(0x12de4dc)', 'Regexp=REGEXP(0x52a8ac)') called at C:/strawberry/perl/lib/JSON/PP.pm line 368
JSON::PP::hash_to_json('JSON=HASH(0x12de4dc)', 'HASH(0x12deb4c)') called at C:/strawberry/perl/lib/JSON/PP.pm line 312
JSON::PP::object_to_json('JSON=HASH(0x12de4dc)', 'HASH(0x12deb4c)') called at C:/strawberry/perl/lib/JSON/PP.pm line 292
JSON::PP::PP_encode_json('JSON=HASH(0x12de4dc)', 'HASH(0x12deb4c)') called at C:/strawberry/perl/lib/JSON/PP.pm line 143
JSON::PP::encode('JSON=HASH(0x12de4dc)', 'HASH(0x12deb4c)') called at test.pl line 13

Mit diesem convert_blessed() habe ich schon herumgespielt aber das hat nichts geändert. Ich verstehe auch den Zusammenhang nicht.
Wie kann man das richtig machen?
10 print "Hallo"
20 goto 10

View full thread JSON Regex ausgeben