fork download
  1. #!/usr/bin/env perl
  2. # -*- mode: cperl; indent-tabs-mode: nil; tab-width: 3; cperl-indent-level: 3; -*-
  3. BEGIN { $|=1; }
  4. use strict;
  5. use warnings;
  6. use utf8;
  7. use Data::Dumper;
  8. use JSON::SL;
  9.  
  10. my $p = JSON::SL->new;
  11. $p->utf8(1);
  12. $p->noqstr(1);
  13. $p->nopath(1);
  14. $p->set_jsonpointer(['/^']);
  15.  
  16. my $buf = <<JSON;
  17. [{"id": "hello"}]
  18. JSON
  19.  
  20. $p->feed($buf);
  21. while (my $obj = $p->fetch) {
  22. my %val = %{$obj->{Value}};
  23.  
  24. foreach my $k (sort keys %val) {
  25. # This prints: id => hello
  26. print "$k => $val{$k}\n";
  27. # This prints: $VAR1 = 'id';
  28. print Dumper($k);
  29. if ($k eq 'id') {
  30. # This triggers: Use of uninitialized value $val{"id"}
  31. # So, id != id ?
  32. print "id => $val{id}\n";
  33. }
  34. }
  35. print "\n";
  36.  
  37. # Now for the fun bit: This causes 2 rows of key id
  38. $val{'id'} = 5;
  39. foreach my $k (sort keys %val) {
  40. print "$k => $val{$k}\n";
  41. print Dumper($k);
  42. }
  43. }
  44.  
  45. =pod
  46. id => hello
  47. $VAR1 = 'id';
  48. Use of uninitialized value $val{"id"} in concatenation (.) or string at /home/tino/parsers/bin/json_sl.pl line 32.
  49. id =>
  50.  
  51. id => hello
  52. $VAR1 = 'id';
  53. id => 5
  54. $VAR1 = 'id';
  55. =cut
Runtime error #stdin #stdout #stderr 0.02s 5088KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Can't locate JSON/SL.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.16.2/i686-linux /usr/lib/perl5/site_perl/5.16.2 /usr/lib/perl5/5.16.2/i686-linux /usr/lib/perl5/5.16.2 .) at prog.pl line 8.
BEGIN failed--compilation aborted at prog.pl line 8.