Regex - find chars between ()

2005-09-11 Thread Keenan, Greg John (Greg)** CTR **
Hi, Have a file like: meteor(L, 4) (G,24) rocket(J,19) (D,35) aulan (E,28) (E, 2) aupbx (B,32) (O,10) And I need to work with the chars between the brackets after I've found the string on the left e.g. if my $host variable matches rocket then I need to get J and 19 and D and 3

RE: Regex - find chars between ()

2005-09-11 Thread Thomas Bätzler
Hi, Keenan, Greg John (Greg)** CTR ** <[EMAIL PROTECTED]> asked: > Have a file like: > > meteor(L, 4) (G,24) > rocket(J,19) (D,35) > aulan (E,28) (E, 2) > aupbx (B,32) (O,10) > > And I need to work with the chars between the brackets after > I've found the string on the left

Re: Regex - find chars between ()

2005-09-11 Thread Jeff Pan
Is this feasible? while(<>) { next unless /$host/; $_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/; my @array=("$1","$2","$3","$4"); } On Mon, 12 Sep 2005 16:14:14 +1000, "Keenan, Greg John (Greg)** CTR **" <[EMAIL PROTECTED]> said: > Hi, > > Have a file like: > > meteor(L, 4) (G,

Re: Regex - find chars between ()

2005-09-11 Thread Xavier Noria
On Sep 12, 2005, at 8:14, Keenan, Greg John (Greg)** CTR ** wrote: meteor(L, 4) (G,24) rocket(J,19) (D,35) aulan (E,28) (E, 2) aupbx (B,32) (O,10) And I need to work with the chars between the brackets after I've found the string on the left e.g. if my $host variable matches r

Re: Regex - find chars between ()

2005-09-12 Thread Jeff Pan
Sorry,it should be: $_=~/\((\w+)\,\s*(\d+)\)\s+\((\w+)\,\s*(\d+)\)/; Didn't consider the blank space before. On Mon, 12 Sep 2005 14:54:56 +0800, "Jeff Pan" <[EMAIL PROTECTED]> said: > Is this feasible? > > while(<>) > { > next unless /$host/; > $_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/

Re: Regex - find chars between ()

2005-09-12 Thread John W. Krahn
Keenan, Greg John (Greg)** CTR ** wrote: > Hi, Hello, > Have a file like: > > meteor(L, 4) (G,24) > rocket(J,19) (D,35) > aulan (E,28) (E, 2) > aupbx (B,32) (O,10) > > And I need to work with the chars between the brackets after I've found the > string on the left e.g. if my $

RE: Regex - find chars between ()

2005-09-12 Thread Thomas Bätzler
Jeff Pan <[EMAIL PROTECTED]> asked: > Is this feasible? > > while(<>) > { > next unless /$host/; > $_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/; > my @array=("$1","$2","$3","$4"); The quotes around the variables are in fact slowing your code down - you're forcing a string interpolation w

RE: Regex - find chars between ()

2005-09-12 Thread Charles K. Clarkson
Jeff Pan wrote: : Is this feasible? Yes, but ... : while(<>) : { : next unless /$host/; : $_=~/\((\w+)\,(\d+)\)\s+\((\w+)\,(\d+)\)/; What happens if this doesn't match? Then $1, $2, $3, and $4 will be unitialized in the next statement. Better to check

RE: Regex - find chars between ()

2005-09-12 Thread Jeff Pan
> Why are $1, $2, $3, and $4 in quotes? What's > wrong with this: > > my @array = ( $1, $2, $3, $4 ); > > Or this: > > my @array = //; Sorry, when I use the second way u mentioned,it can't work. the code: while(<>) { next unless /$host/; $_=~/\((\w+)\,\s*(\d+)\)\s+\((\

RE: Regex - find chars between ()

2005-09-12 Thread Charles K. Clarkson
Jeff Pan wrote: : Charles wrote: : : : : my @array = ( $1, $2, $3, $4 ); : : : : Or this: : : : : my @array = //; : : : Sorry, when I use the second way u mentioned,it can't work. Works for me. use strict; use warnings; use Data::Dumper 'Dumper'; my $h