jcrush has asked for the wisdom of the Perl Monks concerning the following question:
Hello Wise Monks,
I'm trying to find a more efficient solution, to correct interpolated data coming into my script.
Since I cannot control the data coming in - only how its stored in the database.
I'm storing data into a SQL database that is interpolating domain accounts into whitespace.
Incoming data, 3 types of samples interpolated:
"AD\thomas" -> "AD homas" # tab "MAIN\nancy" -> "MAIN ancy" # newline "nancy" -> "nancy" # no domain, no problem
Here is what I came up with, but its a kludge, and not efficient when working with lots of database inserts.
$domainID =~ (s/(AD|MAIN)\n/n/); # should not be $domainID =~ (s/(AD|MAIN)\r/r/); # checked 3 times $domainID =~ (s/(AD|MAIN)\t/t/); # before exiting
- - - SOLUTION - - -
Thanks to everyone's suggestions, I solved this domain interpolation issue:
our %whitespace = ( "\f" => "f","\n" => "n","\r" => "r","\t" => "t" ); $netid =~ (s/(\s)/$whitespace{$1}/g); $netid =~ (s/(AD|MAIN)//);
Results:
"AD\thomas" -> "thomas" "MAIN\floyd" -> "floyd" "AD\manny" -> "manny" # perl escapes normal char, no harm
Thank you for all the help,
jcrush
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficiently create an IF/ELSE regex
by hdb (Monsignor) on May 01, 2015 at 16:22 UTC | |
by jcrush (Acolyte) on May 01, 2015 at 19:51 UTC | |
by Anonymous Monk on May 01, 2015 at 20:16 UTC | |
|
Re: Efficiently create an IF/ELSE regex
by jeffa (Bishop) on May 01, 2015 at 15:51 UTC | |
|
Re: Efficiently create an IF/ELSE regex
by AnomalousMonk (Archbishop) on May 01, 2015 at 15:52 UTC |