in reply to Re: reg ex help
in thread reg ex help

tachyon's solution would include the space on the end of the number unless you chomp:
local $/ = " "; while(<DATA>) { next unless $. == 15; # 14th number is 15th element with 0000: f +irst chomp; print; last; } __DATA__ 0000: 30 44 02 01 01 04 06 70 75 62 6C 69 63 A7 37 02 0D.....public.7
I suppose it depends on what you're using it for later.

Replies are listed 'Best First'.
Re: Re: Re: reg ex help
by markd (Acolyte) on Apr 15, 2004 at 11:26 UTC
    This is what I used and it worked.
    $session1->expect(30, '-re', qr'^0000:.*\r\n'); my $tmpvar = $session1->match(); my $tmpvar1 = (split (/ +/, $tmpvar))[14]; unless($tmpvar1 eq 'A6') { &snmp_conf_cleanup(); &clean_up_and_exit($session,"FAIL",$mesg,"did not receive any +v2 notifications"); }
    My original question to try and match it in one reg exp was to have the code in one expect perl line:
    $session1->expect(30, '-re', qr'REGEX HERE');
    I would still like to do that but at least now I have it working. Thanks for everyone's help here.
Re: Re: Re: reg ex help
by tachyon (Chancellor) on Apr 15, 2004 at 11:27 UTC

    In my defense ;-) that is only if the A7 was followed by a newline of course which it was not in the sample. $/ is probably not the best solution to this problem but it is a very useful widget.

    cheers

    tachyon

      In your . . . offen[cs]e (?) ;)

      Once you changed $/, chomp isn't looking for newlines anymore - it'll be removing spaces, which are still attached to the end of each number.

        Fair enough.

        cheers

        tachyon