>
> I am a learner in Perl and this is my first post in this group. I need to
> search a word "Test 1.2.1" in my file. I am using "$_ =~m/Test \d+", but it
> searched only "Test 1" not the full content. I need to check whether it is
> "Test 1" or "Test 1.2" or "Test 1.2.1". Kindly help me in this regard
>

Hello MadYuv,

I'm sure there is a much cleaner way of writing the regular
expression. I am in the process of learning regular expression Perl
flavour myself.

Below is sample program I came up with below:

HTH,

Chris

#!/usr/bin/perl
use warnings;
use strict;

while(<DATA>) {
  chomp;
  if($_ =~ m/(Test\s+\d\.\d\.\d)/){
    print "$1\n";
  }
}

__DATA__
Test 1.2.1
Test 1.2.1
Test 1.2.1
Test 1.2.1
Test 1
Test 1.2

***OUTPUT***
Test 1.2.1
Test 1.2.1
Test 1.2.1
Test 1.2.1

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to