I've run into a problem with a script I'm developing that among other things changes a delimited files delimiter, 1st checking that the new delimiter does not exist in the data.
Everything works fine unless the delimiter is a regex metacharacter. So if the delimiter is ":" no problem, but if the delimiter is a "|" big problem as the expresion /$n_delim/ is always true when $n_delim =~ /|/
I've tried several approaches but they've all failed as I won't know what the delimiter may be. Most often though the delimiter would be "," or "|" or "\t". I been banging my head against the wall for days with this and I just can't figure it out. The snippet below is from the offending script. For those of you wondering; I do have use strict; and use warnings; at the top.
open(FI, "<", $i_file) or die "Unable to open $i_file: $!";
while (sysread(FI, $_, 2 ** 16)){
if (/$n_delim/){
print "Delimiter: $n_delim already in $i_file\n";
exit 2;
}
}
Thanks in advance!