Re: inserting what was matched in regex without going through if statement

2009-03-07 Thread Chas. Owens
On Sat, Mar 7, 2009 at 13:44, Octavian Râşniţă wrote: > From: "Rick" >> >>    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 c

Re: inserting what was matched in regex without going through if statement

2009-03-07 Thread Octavian Râşniţă
From: "Rick" 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

Re: inserting what was matched in regex without going through if statement

2009-03-07 Thread Rick
Chas. Owens wrote: On Sat, Mar 7, 2009 at 11:53, Rick wrote: __test-code__ use warnings; use strict; my $test_s = 'hi [how are you]'; my $data; if ( $test_s =~ m/\[.+\]/ ) { $data = $1; } __END__ is there easier way to do this I was hoping something like this would work $data = ($test_

Re: inserting what was matched in regex without going through if statement

2009-03-07 Thread Chas. Owens
On Sat, Mar 7, 2009 at 11:53, Rick wrote: > __test-code__ > use warnings; > use strict; > my $test_s = 'hi [how are you]'; > > my $data; > if ( $test_s =~ m/\[.+\]/ ) { >    $data = $1; > } > __END__ > > is there easier way to do this > I was hoping something like this would work > > $data = ($tes

inserting what was matched in regex without going through if statement

2009-03-07 Thread Rick
__test-code__ use warnings; use strict; my $test_s = 'hi [how are you]'; my $data; if ( $test_s =~ m/\[.+\]/ ) { $data = $1; } __END__ is there easier way to do this I was hoping something like this would work $data = ($test_s =~ m/\[.+\]/); but does not work.. I tried @data too but stil