in reply to Matching on a specific line of text
Hi kingdom, If I understood your question correctly then workout this,
use strict; use warnings; use Switch; open (FILE, shift)||die $!; while(<FILE>){ switch ($.) { case 1 { (m/^12345.67890$/) ? (print "Line $. \"$&\" Matched\n") +: (print "Line $. Not Matched\n"); } case 2 { (m/^13456.12345$/) ? (print "Line $. \"$&\" Matched\n") +: (print "Line $. Not Matched\n"); } case [3..5]{ (m/^\d+$/) ? (print "Line $. \"$&\" Matched\n") : (p +rint "Line $. Not Matched\n"); } } } close(FILE);
Input is: (test.txt) 12345.67890 13456.12345 12A345.67890 13E456.12345 12B345.67890 Output is: Line 1 "12345.67890" Matched Line 2 "13456.12345" Matched Line 3 Not Matched Line 4 Not Matched Line 5 Not Matched
Regards,
Velusamy R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching on a specific line of text
by davidrw (Prior) on May 07, 2006 at 18:59 UTC |