in reply to Need regex to filter out unwanted rows

Hello ps2931,

In the spirit of TMTOWTDI, here’s a variation on AnomalousMonk’s solution, using tr/// instead of m//:

#! perl use strict; use warnings; while (<DATA>) { chomp; my $invalid = tr{- _,:./"0-9a-zA-Z}{}c; print "Found $invalid invalid characters in:\n$_\n" if $invalid; } __DATA__ This line is OK. 2749 "CQWERC20F+XZIAQAAAQjLiDI9sNc=", "1","ds_uid","CWER1Y1mHZIAQAA8di +wRHfuwrM=","2012-10-14 18:41:44.429","2012-10-14 18:41:44.572","1975- +10-10 00:00:00.000","7307 mg rd","","naasik","NK","44026","IN","44063 +59999","","","","DEFAULT","","","AABBCCXX","","Qqwwee<feff>","","qqww +ee@yahoo.com","0","YOPANEL","","false","en","","","","","","","",""," +","","","","","","","","" This line is OK too: abc123-_,:./"

Output:

22:35 >perl 1012_SoPW.pl Found 6 invalid characters in: 2749 "CQWERC20F+XZIAQAAAQjLiDI9sNc=", "1","ds_uid","CWER1Y1mHZIAQAA8di +wRHfuwrM=","2012-10-14 18:41:44.429","2012-10-14 18:41:44.572","1975- +10-10 00:00:00.000","7307 mg rd","","naasik","NK","44026","IN","44063 +59999","","","","DEFAULT","","","AABBCCXX","","Qqwwee<feff>","","qqww +ee@yahoo.com","0","YOPANEL","","false","en","","","","","","","",""," +","","","","","","","","" 22:35 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Need regex to filter out unwanted rows
by AnomalousMonk (Archbishop) on Sep 15, 2014 at 12:59 UTC

    tr/// will be faster than  m// for large masses of input, hence IMHO preferable.