Re: special chars as scalar inside regex
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 28 Mar 2008 01:55:15 -0700
Rob Benton wrote:
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.
perldoc -f quotemeta
my @fields = split /\Q$delimiter\E/, $line;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- special chars as scalar inside regex
- From: Rob Benton
- special chars as scalar inside regex
- Prev by Date: Re: special chars as scalar inside regex
- Next by Date: Geting the Host from URL in cgi script
- Previous by thread: Re: special chars as scalar inside regex
- Next by thread: Geting the Host from URL in cgi script
- Index(es):
Relevant Pages
|
|