Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

perl need to do until on qx{tracert $ip}

by diamondsandperls (Beadle)
on Sep 14, 2012 at 16:23 UTC ( #993753=perlquestion: print w/replies, xml ) Need Help??
diamondsandperls has asked for the wisdom of the Perl Monks concerning the following question:

I am having problems i need to do a traceroute until my regex match is met i understand how qx works but my research indicates that there is a way i can use open maybe to accomplish what i need to accomplish.

#!perl use strict; use warnings; my $trace; my $ipaddy = ""; #example do { $trace = qx{tracert $ipaddy}; until ($trace =~ /myhost/) }

Replies are listed 'Best First'.
Re: perl need to do until on qx{tracert $ip}
by NetWallah (Canon) on Sep 14, 2012 at 17:04 UTC
    Do you really want to run 'tracert' multiple (possibily infinite) times ?

    I'm guessing this is what you are want:

    my $found = 0; for (qx<tracert $ipaddy>){ next unless /myhost/; found = 1; last; }
    or, simpler,
    if (grep {/myhost/}, qx<tracert $ipaddy>){ #Do something }else{ #Addr was not found in trace }

                 I hope life isn't a big joke, because I don't get it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://993753]
Approved by herveus
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-06-18 00:32 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.