in reply to cool regular expression needed for matching in columns
When dealing with fixed length records, it was recommended to use pack / unpack pair. See "Perl Best Practices" by Damian Conway for more. With this, here is another solution that reflects this recommendation:
use strict; use warnings; my $spat = qr/(?:abc|xyz)/; while(<DATA>) { chomp; my $r = $_; my @flds = unpack "(A3)*", $r; print "$r => "; do { print "$_ " if /$spat/ } for @flds; print "\n"; } __DATA__ abcmmmnnn mmmxyznnn xyzfooabc mabcmxyzm
-BR
|
|---|