I have this kind of data in JSON format
{
"stream 8": {
"stream_name": "xyz",
"field1": "xe-0/0/1",
"field2": "at-0/0/0"
},
"stream 12": {
"stream_name": "abc",
"field1": "br-0/1/1",
"field2": "at-1/0/1"
}
}
I sent this JSON object to a Perl CGI script where I converted it to a hash of hashes.
Now I want to send this hash reference to another Perl script using a command-line argument. I don't know why it's not working.
Here is my CGI script
#!c:/perl/bin/perl.exe
use CGI;
use strict;
use warnings;
use JSON;
use JSON::PP;
use Data::Dumper;
use Storable;
# read the CGI params
my $q = CGI->new;
my $json = $q->param("r");
print "Content-type:text/html\n\n";
my $href = decode_json($json);
my %arr = %{$href};
my %hash;
foreach my $key (keys %arr) {
my %a = %{$arr{$key}};
foreach my $value (keys %a) {
$hash{$key}{'streamname'} = $a{'stream_name'};
$hash{$key}{'f1'} = $a{'field1'};
$hash{$key}{'f2'} = $a{'field2'};
}
}
my @h = %hash;
#print ref(@h);
print Dumper(@h);
my $out;
$out = `perl te.pl @h hashval`;
Te.pl
use strict;
use warnings;
use Data::Dumper;
use Storable;
print("\nIn sample\n");
if ( $ARGV[-1] eq 'hashval' ) {
#print("\nIts hash\n");
delete($ARGV[-1]);
my %h1 = @ARGV;
print Dumper(%h1);
}
When I print %h1
I don't get the desired output.
Please let me know how to exactly fix this as I am new to Perl and CGI.