New Member - Array of Hashes between perl scripts via commandline argument
Discuss Array of Hashes between perl scripts via commandline argument in the Perl Programming forum on Dev Shed. Array of Hashes between perl scripts via commandline argument Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
Posts: 2
Time spent in forums: 36 m 23 sec
Reputation Power: 0
New Member - Array of Hashes between perl scripts via commandline argument
Hello @,
I am trying to pass "Array of Hash" as command line argument from one perl file to another perl file using reference. But the address becomes invalid once it reached another file . Is it because of different process address space between the perl files ? How to pass parameters like array, hashes and array of hashes from one perl file to another perl file using system("perl abc.pl <Array of Hashes>) command.
Code which call another perl command is:
#!/usr/bin/perl
use strict;
my (@AoH, $myRef, $CMD, $NewProcess );
@AoH = (
{
Instance => "orcl",
Metric => "6",
Filter => "Tablespace_name NOT LIKE 'TEMP'",
},
{
Instance => "orcl",
Metric => "16",
Filter => "Segment_name NOT LIKE 'TEMP'",
},
My Code which will be called is :
#!/usr/bin/perl
use strict;
use Getopt::Long;
my (@AoH, $href, $role, $myRef, $input,$ret) ;
print "Inside TCAOH.pl file \n";
$ret = GetOptions ( "f" => \$input);
print "Ret value : $ret \n";
print "Address : $input \n";
for (my $i=0; $i < @$input; $i++) {
print $input->[$i]{Instance}."\n";
print $input->[$i]{Metric}."\n";
print $input->[$i]{Filter}."\n";
}
1;
Output Error is:
Callee Address ARRAY(0x32e6fc)
To execute : perl TCAOH.pl -f ARRAY(0x32e6fc)Can't use string ("1") as an ARRAY
ref while "strict refs" in use at TCAOH.pl line 38.
Here line 38 is:
for (my $i=0; $i < @$input; $i++) {
Please suggest.
End of the day, I want to store set of data into memory and pass to different perl scripts as and when required to avoid I/O activities by each set of perl scripts.
What would be the best way to achieve this objective ?
Posts: 2
Time spent in forums: 36 m 23 sec
Reputation Power: 0
Thanks a lot for your reply.
Yes, it worked. But again its writing into a flat file and reading from the flat file which means I/O activity.
Is there any way, we can avoid such I/O overheads ?
Posts: 1,652
Time spent in forums: 1 Month 2 Weeks 2 Days 6 h 21 sec
Reputation Power: 1170
How big of a data structure are you taking about? The example you've given would only take a few milliseconds of I/O overhead.
You haven't provided enough info on what the real goal is, but my first suggestion would be to redesign/refactor your scripts and turn one of then into a module.
Another option would be to use a database instead of a flat file.