On Sat, Mar 7, 2009 at 13:44, Octavian Râşniţă <orasn...@gmail.com> wrote:
> From: "Rick" <rich.j...@gmail.com>
>>
>>    my ($data) = $test_s =~ /(\[(.+)\]/;
>
> I think it contains a "(" that shouldn't be there (after =~ /).
>
>>> The code above assumes you want what is between the first and last
>>> brackets in $test_s.  If the string contains more than one set of
>>> brackets you may want to say this instead:
>>>
>>>    my ($data) = $test_s =~ /(\[(.+?)\]/;
>
> That ( is till there but it was surely copied by mistake, however in this
> case the regexp should also use a /g modifier:
snip

The first ( is indeed a mistake, but there is no need for the /g
modifier.  We are not trying to get multiple matches, just the first.
If we wanted every substring that matched we would need to say

my @matches = $test_s =~ /\[(.+?)\]/g;


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to