[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-beginners
Subject:    Re: expect module $expect->log_file(\&captureexpectout $arg2 $arg3);
From:       Jim Gibson <jimsgibson () gmail ! com>
Date:       2013-02-06 0:19:45
Message-ID: 39B7598A-4E1D-474A-AD67-6CD205B00C5D () gmail ! com
[Download RAW message or body]


On Feb 5, 2013, at 2:39 PM, Rajeev Prasad wrote:

> Hello,
> 
> I have a working sub like this:
> 
> sub captureexpectout {
> my $data_coming_in_from_expect_call = shift;
> ...do something with data..
> ...
> ...
> }
> 
> which i am calling like this:
> 
> $expect->log_file(\&captureexpectout);
> 
> 
> Now I want to call this subroutine with arguments. I tried below but I got error...
> 
> $expect->log_file(\&captureexpectout($_,$myarg));

You are passing a code reference to the $expect->log_file() subroutine. You cannot \
include arguments with that code reference, as it is just a scalar value that will be \
saved by the Expect object and used later,

Like this:

sub log_file
{
   ...
   $code_ref = shift;


and then later used like this:

   $code_ref->(@args);


> I was assuming that the data from expect call is contained in $_
> 
> but i get nothing. (seems like it passes blank to subroutine...)
> 

Normal data passed to subroutines is contained in @_ (not $_). Your shift command \
will pop off the first element of @_, however, so you should see something if it is \
being passed. Unfortunately, the documentation does not specify what, if anything, is \
passed to your subroutine. Make sure you are calling $expect->log_file() early in \
your program.



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic