Hello,
----- Original Message -----
From: "Xavier Noria" <[EMAIL PROTECTED]>
To: "Perl List" <beginners@perl.org>
Sent: Tuesday, May 15, 2007 11:49 AM
Subject: Re: Assign a delimiter variable
On May 15, 2007, at 6:42 PM, Mike Blezien wrote:
Hello,
this one has been driving me nuts and I'm sure it's something very simple I
maybe overlooking. I need to assign a delimiter variable IE: Pipe or Comma
delimiter:
my $del = '|'; # use either a '|' or ','
my $dataline = "0|1|2|3|4|5|6|7|8|9";
my @data = split(/$del/, $dataline);
This does not work, it won't split the file line with the '|' delimiter, and
get no errors. But if I do this:
my $dataline = "0|1|2|3|4|5|6|7|8|9";
my @data = split(/\|/, $dataline);
Then it works prefectly, it splits the line as expected. What am I missing
??
The actual regexp is what you get _after_ interpolation.
Since the pipe is a metacharacter it is being interpreted as such, as if you
directly wrote
split /|/, ...
To prevent this there's quotemeta(), which is available in literals as \E:
my @data = split(/\E$del/, $dataline);
-- fxn
Actually it was the /\Q that worked. Your suggestion got me looking back at the
books and found it, thanks :)
Mike
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/