Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 23rd, 2012, 11:32 AM
arsh25 arsh25 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 2 arsh25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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'",
},

{
Instance => "orcl",
Metric => "10",
Filter => "Any filter statement",
},
{
Instance => "orcl",
Metric => "100",
Filter => "Any filter statement 1",
},
);
$NewProcess = "TCAOH.pl";
$myRef = \@AoH;
print "Callee Address $myRef \n";
$CMD = "perl $NewProcess -f $myRef" ;
print "To execute : $CMD";
system("$CMD > Mytestoutput.txt");


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 ?

Reply With Quote
  #2  
Old April 23rd, 2012, 01:29 PM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,652 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 6 h 21 sec
Reputation Power: 1170
Use the Storable module to exchange the data structure between the scripts.

http://search.cpan.org/~ams/Storable-2.30/Storable.pm

Reply With Quote
  #3  
Old April 24th, 2012, 03:05 AM
arsh25 arsh25 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 2 arsh25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 ?

Reply With Quote
  #4  
Old April 24th, 2012, 08:19 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,652 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
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.
Comments on this post
OmegaZero agrees: Measure before you worry is always good advice.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > New Member - Array of Hashes between perl scripts via commandline argument

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap