in reply to why is my regex not right?
I think this regular expression pattern is probably more suitable.
(\$\d{1,3}(?:,\d\d\d)*\.\d\d\b)
use strict; use warnings; use English qw( -no_match_vars ); ... while (my $record = <$input_fh>) { my @prices = $record =~ m/(\$\d{1,3}(?:,\d\d\d)*\.\d\d\b)/g; $number_of_prices = scalar @prices; $number_of_prices == 3 or warn "Incorrect number of prices ($number_of_prices) at" . " line $INPUT_LINE_NUMBER of file $input_file\n"; ... } exit 0;
But you should probably use Text::CSV_XS instead of a regular expression pattern to parse the semicolon-separated-value records properly and to extract the prices from them that way.
Jim
|
|---|