Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > why does Perl choke here?

Reply
Thread Tools

why does Perl choke here?

 
 
Z. M. Wu
Guest
Posts: n/a
 
      11-24-2003
Perl does not like if $other contains special characters
like * ] in the following

my @a=split/$other/,$req;


My current workaround is

$other=~ s/[\)\(\*]/_/g;
$req=~ s/[\)\(\*]/_/g;

before the split.

Any insight or better solution would be helpful

Thanks

Mr Wu Zong Ming

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-24-2003
Z. M. Wu wrote:
> Perl does not like if $other contains special characters
> like * ] in the following
>
> my @a=split/$other/,$req;


No, they are special characters in regular expressions, and need to be
escaped.

> My current workaround is
>
> $other=~ s/[\)\(\*]/_/g;
> $req=~ s/[\)\(\*]/_/g;
>
> before the split.
>
> Any insight or better solution would be helpful


Better solution:

my @a = split /\Q$other/, $req;

See "perldoc perlre".

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why doesn't std::cin choke on this? William Payne C++ 10 01-06-2004 08:12 AM
Why does this choke? S Kemplay Python 4 11-09-2003 11:37 PM
Random dates (was RE: Why does this choke?) Tim Peters Python 0 11-08-2003 06:19 PM
Why does this choke? S Kemplay Python 2 11-07-2003 12:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57