[EMAIL PROTECTED] wrote on 04/09/2006 02:25:18 
PM:
> Today's Topics:
>    2. messy regex (Gerald Preston)
> ----------------------------------------------------------------------
> ------------------------------
> 
> Message: 2
> Date: Sun, 9 Apr 2006 09:32:36 -0500
> From: "Gerald Preston" <[EMAIL PROTECTED]>
> Subject: messy regex
> To: <[email protected]>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hi!
> 
> 
> 
> I am not sure how to start to use regex in the following. 
> 
> 
> 
<example stuff snipped> 
> 
> 
> I have started with the following:
> 
> 
> 
> #!/perl
> 
> 
> 
>   use strict;
> 
> 
> 
>   local( *FI, *FO );
> 
> 
> 
>   my $DEBUG           = 00;
> 
>   my $DEBUG1          = 01;
> 
> 
> 
>   open( FI, "RH.lst" ) || die "RH.lst $!\n";
> 
>   while(<FI>) {
> 
> 
> 
>     chomp;
> 
> 
> 
>     print $_;
> 
>     my $money =~ /\$(\d+)\/mo/;
> 
> 
> 
>     print "\nmoney $1\n";
> 
> 
> 
>     my $phone =~ /(\d{3})-(\d+)-(\d+)-/;
> 
> 
> 
>     print "\nphone $1 * $2 * $3 *\n";
> 
> exit;
> 
>   }
> 
>   close FI;
> 
> 
> 
> Thanks,
> 
> 
> 
> Jerry
> 
I cant give you everything but the prices seem to follow q $##### format

also you are creating and testing varirables, not the string.

untested code follows. i even buffed your money test to hamdle numbers 
like $234,456.90

-josh

#!/perl
use strict;

# get the argument that is a file
my $file=shift;

# make an array for the info
my @apts;

open IN, "<$file" or die "cound not open $file: $! $^E";

while(<>){
  # create part variables
  my ($price, $loc);

  # faux switch used in a new way
  for($_){
    /(\$[\d\.\,]+)/ && do { $price=$1; };
#    /<pattern here>/ && do { <set variable here>; };
  }

  # add to apt list and report
  print "found: $money\n";
  push @apts, "$money";
}

close IN;

open OUT, ">>$apts";
foreach $apt (@apts){
  print out "$apt\n";
}
close OUT;
__END__

-----------------------------------------
PLEASE NOTE: 
SeaChange International headquarters in Maynard, MA is moving!
Effective March 1, 2006, our new headquarters address will be:

SeaChange International 
50 Nagog Park 
Acton, MA 01720 USA 

All telephone numbers remain the same: 
Main Corporate Telephone: 978-897-0100 
Customer Service Telephone: 978-897-7300

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to