#!/usr/bin/perl use strict; use warnings; while (<DATA>) { next if ! /^\w{4}(\.\d+){3}/; print; } __DATA__ MONDAY MD21.2.7.8 TUESDAY # Driver Code = TD20.2.7.8 TD20.2.7.8 WEDNESDAY # Driver Code = WD20.2.7.8 WD30.2.7.8 FRIDAY # Driver Code = FD20.2.7.8 FD40.2.7.8
Prints:
MD21.2.7.8 TD20.2.7.8 WD30.2.7.8 FD40.2.7.8
I presume the scalar @t in your code is in response to the warning:
Applying pattern match (m//) to @t will act on scalar(@t) at ...
The real problem is @t =~ /.../ doesn't make sense. The =~ operator does not work with arrays or hashes. Actually, the real problem is that you need to match against the entire line so you don't need the split and don't need the array. See the regex match in my sample code to see how you ought to do the match.
In reply to Re: Problem in extracting alphanumeric string from file
by GrandFather
in thread Problem in extracting alphanumeric string from file
by rahulme81
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |