develooper Front page | perl.beginners | Postings from May 2007

Re: Assign a delimiter variable

Thread Previous | Thread Next
From:
Jeff Pang
Date:
May 15, 2007 19:14
Subject:
Re: Assign a delimiter variable
Message ID:
464A6793.3010200@gmx.net
Mike Blezien 写道:
> 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 ??
> 

Hello,

Change one of the lines to:
my @data     = split(/\Q$del/, $dataline);

This would work.

from perldoc perlre,
\Q          quote (disable) pattern metacharacters till \E


-- 
Jeff Pang
http://home.arcor.de/jeffpang/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About