Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

split slice question

0 views
Skip to first unread message

Richard Lee

unread,
May 10, 2008, 10:14:54 AM5/10/08
to Perl Beginners
I use this before (split slice ) but it's working bit funny now..

can someone tell me why??

it looks like it's splitting on '' instead of /|/ as I have specified
below... ??

use strict;
use warnings;


my $array = q/hi|how|are|you|fine/;

my ($moe,$hae,$now) = (split(/|/,$array))[0,1,2];
print "$moe $hae $now\n";

[root@RLEE ~]# ./!$
././split_practice.pl
h i |

Gunnar Hjalmarsson

unread,
May 10, 2008, 10:42:05 AM5/10/08
to begi...@perl.org
Richard Lee wrote:
>
> my ($moe,$hae,$now) = (split(/|/,$array))[0,1,2];

'|' is special in a regular expression and needs to be escaped.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Dr.Ruud

unread,
May 11, 2008, 6:50:08 AM5/11/08
to begi...@perl.org
Richard Lee schreef:

> I use this before (split slice ) but it's working bit funny now..

> it looks like it's splitting on '' instead of /|/ as I have specified
> below... ??

Look for quotemeta in perlre.

--
Affijn, Ruud

"Gewoon is een tijger."

0 new messages