develooper Front page | perl.beginners | Postings from March 2008

special chars as scalar inside regex

Thread Next
From:
Rob Benton
Date:
March 28, 2008 01:22
Subject:
special chars as scalar inside regex

I've got a problem I think there may be a straight-forward solution to  
that I just don't know.  I have a program that reads a variable-length  
input file. And the field delimiter of that file is given as an  
argument.  The problem is something like pipe "|" might show up as the  
delimiter.  So is there a way to quote/protect that in the split()  
function without it being interpreted as a regex special character?

Something like:

./myprog.pl "|"

myprog.pl:
---------
my $delimiter = $ARGV[0];
my @fields = split(/$delimiter/, $line);


This is a very simplified example.  Hope that makes sense.

Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About