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 $host variable matches rocket then I need to
> get J and 19 and D and 35 into an array or their own seperate variables.
>  
> I have been going around in circles with the regex.  I have tried escaping
> the round brackets with \, anchoring the string to the end with \z and a
> multitude of other combos of \D \d \w . \s etc.
>  
> Note that some coordinates have two digits and others single digit with
> whitespace before it.
>  
> #StartCode
> use strict;
> use warnings;
> use diagnostics;
>  
> my $host = $ARGV[0];
> my $dirRoot = "/gjkeenan/G7";
> my $fileG7 = "$dirRoot/G7";
> my $filePW = "$dirRoot/PW";
>  
> open(PWFILE, "$filePW")
>   || die "Can't open $filePW: $!";
> while (<PWFILE>) {
>   if (/$host/) {

The $host regular expression should be anchored or it may not match correctly
and if it contains any regular expression meta-characters they should be 
escaped.

  if ( /^\Q$host\E\s/ ) {


>     my @c = /(\D,\d\d)\s(\D,\d\d)/;

You have to declare the array @c outside of the while loop or you can't use it
at the end of the while loop.

This may work better for you:

@c = / \( ( \D ) , \s* ( \d+ ) \) \s+ \( ( \D ) , \s* ( \d+ ) \) /x;


>   }
> }
> close(PWFILE);
> ...do something with $c[0] $c[1] $c[2] $c[3]...
> #EndCode


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to