Hi all, how do i get the complete string which has matched via regex when using Perl Expect.

#!/usr/bin/perl use Expect; use Getopt::Long; my $exp = Expect->spawn("/usr/bin/ssh $username\@$ip") or die "Cannot spawn ssh: $!\n";; /* removed the ssh handling code */ $exp->send("show backup status\n"); $result=$exp->expect( $timeout, ['-re',qr'Backup file location:',sub {my $exp = shift; $exp->print_log_file($backup_Complete); $i=0; } ], ['-re',qr'>'] );

Out put of the above command is :

=== local backup succeeded. Backup file location: /var/log/CPbackup/backups/x.x/x.x.x.x_01_1_Aug_2 +016_11_05.tgz Backup process finished in 00:48 seconds ===
How do we extract "location: /var/log/CPbackup/backups/x.x/x.x.x.x_01_1_Aug_2016_11_05.tgz" line from the output with perl expect ? Do note that i have tried to use $exp->match() but just displayes "Backup file location:" which is the regex


In reply to Perl Expect : Get the complete matched string by cryptonite1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.