in reply to Problem in extracting alphanumeric string from file
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem in extracting alphanumeric string from file
by rahulme81 (Sexton) on Aug 19, 2015 at 08:45 UTC | |
by stevieb (Canon) on Aug 19, 2015 at 13:41 UTC | |
by rahulme81 (Sexton) on Aug 19, 2015 at 09:09 UTC | |
by rahulme81 (Sexton) on Aug 19, 2015 at 10:20 UTC |