Re: passing array reference from one perl script to another perl scirpt

2008-01-28 Thread praveen mall
I am just putting the code here that might be helpful to others.  Thank you
very much.

Praveen Mall

Program1: (sending hash reference)

use strict;

use warnings;

use Storable;

 my %h = (a = 1, b = 2, c = 3);

 store(\%h, c:\\perlipc.$$)

   or die could not store hash in /tmp/perlipc.$$: $!;

 system(perl, 2.pl, $$) == 0

   or die could not run second.pl;



Program2: (receiving hash reference)

use strict;

use warnings;

use Storable;
my $parentpid = shift;

my $href = retrieve(c:\\perlipc.$parentpid)

   or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;



my %hash = %$href;



foreach my $key(keys %hash){



print $key=$hash{$key}\n;


On Jan 28, 2008 3:00 PM, praveen mall [EMAIL PROTECTED] wrote:

 Thanks a lot for helping me. :)



 On Jan 25, 2008 6:50 PM, Nagrale, Ajay [EMAIL PROTECTED] wrote:

  Passing hashes between the scripts would be useful using GDBM
  files..Hashes would be stored internally. You can directly load and change
  the contents.
 
  It's easy to handle. But, gdbm files have their own disadvantages when
  you keep on adding and deleting the data.
 
  Try this out. This might help.
 
  ~Ajay
 
  -Original Message-
  From: Chas. Owens [mailto:[EMAIL PROTECTED]
  Sent: Friday, January 25, 2008 6:32 PM
  To: praveen mall
  Cc: beginners@perl.org
  Subject: Re: passing array reference from one perl script to another
  perl scirpt
 
 
  On Jan 25, 2008 4:45 AM, praveen mall [EMAIL PROTECTED] wrote:
  snip
   There are two script. From first script I need to call the second
  program
   and in second program I want to receive the hash. I have complete hash
  in
   first program and calling second program by system call by passing
  hash
   reference as a parameter.
  snip
 
  I believe you are placing constraints on yourself that do not actually
  exist, but we will work with them for now.  You need some form of
  IPC*.  The easiest to understand is the simple file method: script one
  writes a file to disk and script two reads that file.  Now that we
  know how to get the two scripts talking, we need to know how to
  transfer a hash along that conduit.  We need to serialize it (turn it
  into a string that contains all of the information we need).  There
  are many functions in Perl that can do this for us and which one is
  best depends on the data structure to be serialized and your other
  needs.  For now, let's us one that is in Core Perl: Storable**.
 
  Here is the first script
  #!/usr/bin/perl
 
  use strict;
  use warnings;
  use Storable;
 
  my %h = (a = 1, b = 2, c = 3);
 
  store(\%h, /tmp/perlipc.$$)
 or die could not store hash in /tmp/perlipc.$$: $!;
 
  system(perl, second.pl, $$) == 0
 or die could not run second.pl;
 
  Here is the second script
  #!/usr/bin/perl
 
  use strict;
  use warnings;
  use Storable;
  use Data::Dumper;
 
  my $parentpid = shift;
  my $href = retrieve(/tmp/perlipc.$parentpid)
 or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;
 
  print Dumper($href);
 
 
  * inter process communication
  ** http://perldoc.perl.org/Storable.html
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/
 
 
 


 --
 Thanks and Regards,
 Praveen Kumar Mall
 Jr. SQA Engineer
 Pune
 Mo. No. 09850982204




-- 
Thanks and Regards,
Praveen Kumar Mall
Jr. SQA Engineer
Pune
Mo. No. 09850982204


Re: passing array reference from one perl script to another perl scirpt

2008-01-28 Thread praveen mall
Thanks a lot for helping me. :)


On Jan 25, 2008 6:50 PM, Nagrale, Ajay [EMAIL PROTECTED] wrote:

 Passing hashes between the scripts would be useful using GDBM
 files..Hashes would be stored internally. You can directly load and change
 the contents.

 It's easy to handle. But, gdbm files have their own disadvantages when you
 keep on adding and deleting the data.

 Try this out. This might help.

 ~Ajay

 -Original Message-
 From: Chas. Owens [mailto:[EMAIL PROTECTED]
 Sent: Friday, January 25, 2008 6:32 PM
 To: praveen mall
 Cc: beginners@perl.org
 Subject: Re: passing array reference from one perl script to another
 perl scirpt


 On Jan 25, 2008 4:45 AM, praveen mall [EMAIL PROTECTED] wrote:
 snip
  There are two script. From first script I need to call the second
 program
  and in second program I want to receive the hash. I have complete hash
 in
  first program and calling second program by system call by passing hash
  reference as a parameter.
 snip

 I believe you are placing constraints on yourself that do not actually
 exist, but we will work with them for now.  You need some form of
 IPC*.  The easiest to understand is the simple file method: script one
 writes a file to disk and script two reads that file.  Now that we
 know how to get the two scripts talking, we need to know how to
 transfer a hash along that conduit.  We need to serialize it (turn it
 into a string that contains all of the information we need).  There
 are many functions in Perl that can do this for us and which one is
 best depends on the data structure to be serialized and your other
 needs.  For now, let's us one that is in Core Perl: Storable**.

 Here is the first script
 #!/usr/bin/perl

 use strict;
 use warnings;
 use Storable;

 my %h = (a = 1, b = 2, c = 3);

 store(\%h, /tmp/perlipc.$$)
or die could not store hash in /tmp/perlipc.$$: $!;

 system(perl, second.pl, $$) == 0
or die could not run second.pl;

 Here is the second script
 #!/usr/bin/perl

 use strict;
 use warnings;
 use Storable;
 use Data::Dumper;

 my $parentpid = shift;
 my $href = retrieve(/tmp/perlipc.$parentpid)
or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;

 print Dumper($href);


 * inter process communication
 ** http://perldoc.perl.org/Storable.html

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/





-- 
Thanks and Regards,
Praveen Kumar Mall
Jr. SQA Engineer
Pune
Mo. No. 09850982204


Re: passing array reference from one perl script to another perl scirpt

2008-01-25 Thread praveen mall
Idea is good to turn one script as a module. But I can not do anyhow.

What I want to achieve is:

There are two script. From first script I need to call the second program
and in second program I want to receive the hash. I have complete hash in
first program and calling second program by system call by passing hash
reference as a parameter.

If anyone has solution of this then please let me know.

Thanks,
Praveen Mall

On Jan 25, 2008 12:11 AM, Chas. Owens [EMAIL PROTECTED] wrote:

 On Jan 24, 2008 6:06 AM,  [EMAIL PROTECTED] wrote:
 snip
   What you are trying to do there won't work and even if it did it would
   be a bad idea.  It appears as if you are trying to modularize your
   code.  There are better ways of doing it than that.  If you describe
   what effect you are trying to achieve, we may be able to point you in
   the right direction.
 
 
  What I see is that , reference is received in next program but I am
  not able to access the hash after dereferencing it. I was passing the
  hash reference.
 snip

 No, what you are seeing is the result of turning a reference into a
 string.  You cannot turn a string back into a reference, even in the
 same Perl program.  Please describe what you want to do (not how you
 want to do it) and someone on this list will be able to point you in
 the right direction.  The proper answer is to probably turn that
 second script into a module that the first script can use.




-- 
Thanks and Regards,
Praveen Kumar Mall
Jr. SQA Engineer
Pune
Mo. No. 09850982204


Re: passing array reference from one perl script to another perl scirpt

2008-01-25 Thread Rob Dixon

praveen mall wrote:


Idea is good to turn one script as a module. But I can not do anyhow.

What I want to achieve is:

There are two script. From first script I need to call the second program
and in second program I want to receive the hash. I have complete hash in
first program and calling second program by system call by passing hash
reference as a parameter.

If anyone has solution of this then please let me know.


That looks more like /how/ you want to achieve a solution rather than
/what/ you want to achieve. Presumably you haven't yet written either of 
these programs? Is there any real reason why you have to implement

things this way?

If you are genuinely constrained to a solution that works like this then
please let us know. Otherwise we can help you to explore alternative
solutions to the actual problem, which I would like you to describe.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: passing array reference from one perl script to another perl scirpt

2008-01-25 Thread Nagrale, Ajay
Passing hashes between the scripts would be useful using GDBM files..Hashes 
would be stored internally. You can directly load and change the contents.

It's easy to handle. But, gdbm files have their own disadvantages when you keep 
on adding and deleting the data.

Try this out. This might help.

~Ajay

-Original Message-
From: Chas. Owens [mailto:[EMAIL PROTECTED]
Sent: Friday, January 25, 2008 6:32 PM
To: praveen mall
Cc: beginners@perl.org
Subject: Re: passing array reference from one perl script to another
perl scirpt


On Jan 25, 2008 4:45 AM, praveen mall [EMAIL PROTECTED] wrote:
snip
 There are two script. From first script I need to call the second program
 and in second program I want to receive the hash. I have complete hash in
 first program and calling second program by system call by passing hash
 reference as a parameter.
snip

I believe you are placing constraints on yourself that do not actually
exist, but we will work with them for now.  You need some form of
IPC*.  The easiest to understand is the simple file method: script one
writes a file to disk and script two reads that file.  Now that we
know how to get the two scripts talking, we need to know how to
transfer a hash along that conduit.  We need to serialize it (turn it
into a string that contains all of the information we need).  There
are many functions in Perl that can do this for us and which one is
best depends on the data structure to be serialized and your other
needs.  For now, let's us one that is in Core Perl: Storable**.

Here is the first script
#!/usr/bin/perl

use strict;
use warnings;
use Storable;

my %h = (a = 1, b = 2, c = 3);

store(\%h, /tmp/perlipc.$$)
or die could not store hash in /tmp/perlipc.$$: $!;

system(perl, second.pl, $$) == 0
or die could not run second.pl;

Here is the second script
#!/usr/bin/perl

use strict;
use warnings;
use Storable;
use Data::Dumper;

my $parentpid = shift;
my $href = retrieve(/tmp/perlipc.$parentpid)
or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;

print Dumper($href);


* inter process communication
** http://perldoc.perl.org/Storable.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: passing array reference from one perl script to another perl scirpt

2008-01-25 Thread Chas. Owens
On Jan 25, 2008 4:45 AM, praveen mall [EMAIL PROTECTED] wrote:
snip
 There are two script. From first script I need to call the second program
 and in second program I want to receive the hash. I have complete hash in
 first program and calling second program by system call by passing hash
 reference as a parameter.
snip

I believe you are placing constraints on yourself that do not actually
exist, but we will work with them for now.  You need some form of
IPC*.  The easiest to understand is the simple file method: script one
writes a file to disk and script two reads that file.  Now that we
know how to get the two scripts talking, we need to know how to
transfer a hash along that conduit.  We need to serialize it (turn it
into a string that contains all of the information we need).  There
are many functions in Perl that can do this for us and which one is
best depends on the data structure to be serialized and your other
needs.  For now, let's us one that is in Core Perl: Storable**.

Here is the first script
#!/usr/bin/perl

use strict;
use warnings;
use Storable;

my %h = (a = 1, b = 2, c = 3);

store(\%h, /tmp/perlipc.$$)
or die could not store hash in /tmp/perlipc.$$: $!;

system(perl, second.pl, $$) == 0
or die could not run second.pl;

Here is the second script
#!/usr/bin/perl

use strict;
use warnings;
use Storable;
use Data::Dumper;

my $parentpid = shift;
my $href = retrieve(/tmp/perlipc.$parentpid)
or die could not retrieve hash from /tmp/perlipc.$parentpid: $!;

print Dumper($href);


* inter process communication
** http://perldoc.perl.org/Storable.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: passing array reference from one perl script to another perl scirpt

2008-01-24 Thread mallu . it
On Jan 8, 7:05 pm, [EMAIL PROTECTED] (Chas. Owens) wrote:
 On Jan 8, 2008 4:32 AM, Siva Prasad [EMAIL PROTECTED] wrote:



  Hi Gurus,

  Iam getting problem in accessing the array reference which is passed as
  command line argument to a perl script from another perl script

  I have a main perl script I have declared an array as our
  @arr=(1,2,3,4);

  And I have passed this array reference to another Perl script (system(perl
  subscriplt1.pl  [EMAIL PROTECTED]);)

  I can get the reference value in subscript but I am not able to get the
  values in the array.

  Can anybody give some solution for this?

  Thanks in Advance,
  Siva

 What you are trying to do there won't work and even if it did it would
 be a bad idea.  It appears as if you are trying to modularize your
 code.  There are better ways of doing it than that.  If you describe
 what effect you are trying to achieve, we may be able to point you in
 the right direction.


What I see is that , reference is received in next program but I am
not able to access the hash after dereferencing it. I was passing the
hash reference.

Praveen Mall


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: passing array reference from one perl script to another perl scirpt

2008-01-24 Thread Thomas Bätzler
[EMAIL PROTECTED] wrote:e solution for this?
 What I see is that , reference is received in next program 
 but I am not able to access the hash after dereferencing it. 
 I was passing the hash reference.

Ever since memory management units (MMU) became all the rage,
processes (or program if you like) have had their own separate
and isolated address spaces. If program b needs to access
variables form program a then it has to run in a's context and
virtual machine. You could look at eval() but the best solution
would probably be to make program b into a module that is called
from program a.

HTH,
Thomas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: passing array reference from one perl script to another perl scirpt

2008-01-24 Thread Tom Phoenix
On Jan 24, 2008 3:06 AM,  [EMAIL PROTECTED] wrote:

 What I see is that , reference is received in next program but I am
 not able to access the hash after dereferencing it. I was passing the
 hash reference.

No; it's not possible to pass a hash by reference from one program to
another. You are mistaken.

See the perlipc manpage for good information on inter-process
communication methods that actually work.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: passing array reference from one perl script to another perl scirpt

2008-01-24 Thread Chas. Owens
On Jan 24, 2008 6:06 AM,  [EMAIL PROTECTED] wrote:
snip
  What you are trying to do there won't work and even if it did it would
  be a bad idea.  It appears as if you are trying to modularize your
  code.  There are better ways of doing it than that.  If you describe
  what effect you are trying to achieve, we may be able to point you in
  the right direction.


 What I see is that , reference is received in next program but I am
 not able to access the hash after dereferencing it. I was passing the
 hash reference.
snip

No, what you are seeing is the result of turning a reference into a
string.  You cannot turn a string back into a reference, even in the
same Perl program.  Please describe what you want to do (not how you
want to do it) and someone on this list will be able to point you in
the right direction.  The proper answer is to probably turn that
second script into a module that the first script can use.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: passing array reference from one perl script to another perl scirpt

2008-01-08 Thread John W. Krahn

Siva Prasad wrote:


Hi Gurus,


Hello,


Iam getting problem in accessing the array reference which is passed as
command line argument to a perl script from another perl script


It won't work.  You can't do that.



I have a main perl script I have declared an array as our
@arr=(1,2,3,4);

And I have passed this array reference to another Perl script (system(perl
subscriplt1.pl  [EMAIL PROTECTED]);) 


That is not an array reference, it is just the string '@arr'.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: passing array reference from one perl script to another perl scirpt

2008-01-08 Thread Chas. Owens
On Jan 8, 2008 4:32 AM, Siva Prasad [EMAIL PROTECTED] wrote:
 Hi Gurus,

 Iam getting problem in accessing the array reference which is passed as
 command line argument to a perl script from another perl script

 I have a main perl script I have declared an array as our
 @arr=(1,2,3,4);

 And I have passed this array reference to another Perl script (system(perl
 subscriplt1.pl  [EMAIL PROTECTED]);)

 I can get the reference value in subscript but I am not able to get the
 values in the array.

 Can anybody give some solution for this?

 Thanks in Advance,
 Siva

What you are trying to do there won't work and even if it did it would
be a bad idea.  It appears as if you are trying to modularize your
code.  There are better ways of doing it than that.  If you describe
what effect you are trying to achieve, we may be able to point you in
the right direction.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/