in reply to Re^3: new to perl : how to match ?
in thread new to perl : how to match ?

hi david
data to L650-F01 is ip address sdf sdf sdf sdf sdf sdfs Thu Oct 27 11:16:55 GMT 2005 data to L650-F01 is sdf..1 . . . sdf sdf sdf sdf sdf sdfs Thu Oct 27 11:16:55 GMT 2005 data to . . . #(no is here ) sdf gdfg dfgdf dfgdf dfgdf dfg Thu Oct 27 10:58:46 GMT 2005 data to MAP050-DFyutv01 is sdf gdfg dfgdf dfgdf dfgdf dfg Thu Oct 27 10:58:46 GMT 2005 data to . . . (same as above) sdf gdfg dfgdf dfgdf dfgdf dfg Thu Oct 27 10:58:46 GMT 2005 data to gbsdfghfif7 is ip address fgd dfgdf dfg dfg dfgd fdfgdf dfg ddfg fd dgfd Thu Oct 27 10:59:23 GMT 2005
this the data file and i am checking for characters after "to".
while (! eof inFile) { $line .= ' ' . <inFile>; chomp $line; next if ! ($line =~ /logging\sto\s+\s+(.*?)\s+/i) and ! eof inFile;
is not checking for "data to . . . #(no is here ), data to gbsdfghfif7 is ip address" types.... i m confused on this. any clairifiactions pls let me know and i m working in it meanwhile

Replies are listed 'Best First'.
Re^5: new to perl : how to match ?
by McDarren (Abbot) on Oct 28, 2005 at 08:53 UTC
    Okay, based on CB conversation - I think you want something like the following:
    #!/usr/bin/perl -w use strict; while (<DATA>) { next unless /data to/; chomp; my $server = (split)[2]; print "Server is $server\n"; if ($server eq "L650-F01") { # Do somthing } elsif ($server eq "MAP050-DFyutv01") { # Do something else } elsif ($server eq "gbsdfghfif7") { # Do something else else } } __DATA__ data to L650-F01 is ip address sdf sdf sdf sdf sdf sdfs Thu Oct 27 11:16:55 GMT 2005 data to L650-F01 is sdf..1 . . . sdf sdf sdf sdf sdf sdfs Thu Oct 27 11:16:55 GMT 2005 data to . . . #(no is here ) sdf gdfg dfgdf dfgdf dfgdf dfg Thu Oct 27 10:58:46 GMT 2005 data to MAP050-DFyutv01 is sdf gdfg dfgdf dfgdf dfgdf dfg Thu Oct 27 10:58:46 GMT 2005 data to . . . (same as above) sdf gdfg dfgdf dfgdf dfgdf dfg Thu Oct 27 10:58:46 GMT 2005 data to gbsdfghfif7 is ip address fgd dfgdf dfg dfg dfgd fdfgdf dfg ddfg fd dgfd Thu Oct 27 10:59:23 GMT 2005


    Note that there are much better ways to do this, such as using a hash to store all your server names in - but this is probably easier for you to understand.

    Hope this helps,
    --Darren :)
      hi What to do if i have some 100 servers' ?
        Hi Sun,

        Welcome to the Monestary. It's nice that you've obviously taken some time to figure out how to post with code tags and whatever else was needed to make your posts easy to read. Thank you.

        Now you need to spend some time figuring out how to communicate your questions effectively. I cannot fathom how a difference of 1 server vs 100 servers is related to your original question; it seems that no one else can either.

        If you need help figuring out how to post clear questions, here are a few good references that may help you:


        -Scott