in reply to Perl Expect : Get the complete matched string

Hi cryptonite1,

I haven't used Expect much, but the documentation says

If called in an array context expect() will return ($matched_pattern_position, $error, $successfully_matching_string, $before_match, and $after_match).

So that would mean something like

my ($match_pos, $error, $match_string, $before_match, $after_match) = +$exp->expect( $timeout, ... );

(Untested) Update: Fixed a copy/paste mistake, and I tried it out and in your case you'll probably be interested in the string $after_match, since that will contain the rest of the line after the regex "Backup file location:". It'll still have whitespace and newlines on the ends of the string, so you'll have to do something like $after_match =~ s/^\s+|\s+$//g; to get rid of it.

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Perl Expect : Get the complete matched string (updated)
by cryptonite1 (Initiate) on Aug 02, 2016 at 10:42 UTC
    Hi Hauke, thanks for the updates. Yes , i did try $after_match but the problem is it will pull all the output after the match is found , all i need is to extact only the specific line "Backup file location: /var/log/CPbackup/backups/x.x/x.x.x.x_01_1_Aug_2016_11_05.tgz"

      Hi cryptonite1,

      What does the string you want to get the filename from look like exactly? Use this to print it:

      use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper($after_match);

      Regards,
      -- Hauke D