in reply to need to remove the extra line in regular expression

By the way, use IO::Interface::Simple. It's more reliable than screenscraping ifconfig output.

Also, use warnings and strict. This will help you to prevent many stupid errors which can otherwise occur easily.

Edit: removed somewhat offensive part of the message caused by misunderstanding
Sorry if my advice was wrong.
  • Comment on Re: need to remove the extra line in regular expression

Replies are listed 'Best First'.
Re^2: need to remove the extra line in regular expression
by ulaksh (Acolyte) on Aug 22, 2012 at 14:27 UTC
    Thanks for the suggestion. but can I get the expected out put without using IO module because I am extracting the output from config file. currentlty this is important for me.please suggest.
      Try something like this:
      my $interface; # declare the variable while (<>) { # if there are non-space symbols on the start of the line, # consider it interface name $interface = $1 if /^([\S]+)/; # $1 means first matched () group of s +ymbols # a group of numeric symbols or dots after "inet addr:" # is considered an IP-address print "$interface => $1\n" if /inet addr:([0-9.]+)/; # use /inet6? addr: ?([0-9a-f.]+)/ if you want to match IPv6-addresse +s }
      Sorry if my advice was wrong.
        Thanks for the help
        I have added small code which will check the condition first, if the l +ine contain Link encap and if it found then get the ethernet address +and ip address other wise skip the test. and here is my changes. open FILE,"config.txt" or die "cannot open file : $!"; my $interface; # declare the variable while(<FILE>) { if (/Link encap/){ print "yes"; # if there are non-space symbols on the start of the line, # consider it interface name $interface = $1 if /^([\S]+)/; # $1 means first matched () group of s +ymbols # a group of numeric symbols or dots after "inet addr:" # is considered an IP-address print "$interface => $1\n" if /inet addr:([0-9.]+)/; # use /inet6? addr: ?([0-9a-f.]+)/ if you want to match IPv6-addresse +s } }
        But when I run the script it gives me the below output but not giving +the expected out. "Yes"