problem with simple pattern matching
- From: jim_n@xxxxxxxxxx (Jim)
- Date: Wed, 29 Aug 2007 21:39:12 +1000
Hi,
I hope this is simple, as i am very new to perl.
I am trying to use pattern matchinig to create many srcipts from
a template file which i have read into a list then print out to files.
the problem is the patter match only matches on the first 2 successful matches
after that it keeps the valuse found in those first 2 successes and writes them out
after that
the sub below is called in a for loop which pulls out some new data to fill the args
Thanks
Jim
the lines im trying to match are
#! DATASET="C:\jim\MinePlan\StratMinePlan\Data_In\2007\2 year detailed stage plan\DGN_IN.dgn"
DEFAULT_MACRO SourceDataset_IGDS_1 C:\jim\MinePlan\StratMinePlan\Data_In\2007\2 year detailed stage plan\DGN_IN.dgn
#! DATASET="C:\jim\MinePlan\StratMinePlan\Data_In\2007\2 year detailed stage plan\CSVOUT"
DEFAULT_MACRO DestDataset_CSV_1 C:\jim\MinePlan\StratMinePlan\Data_In\2007\2 year detailed stage plan\CSVOUT
#! DATASET="C:\jim\MinePlan\StratMinePlan\Data_In\2007\2 year detailed stage plan\DESTDIR"
DEFAULT_MACRO DestDataset_MAPINFO_1 C:\jim\MinePlan\StratMinePlan\Data_In\2007\2 year detailed stage plan\DESTDIR
as i said the first file out is written with the bits filled in correctly ... but only the first :(
sub mk_fme_from_template
{
my $data_class = shift;
my $dgn_fname = shift;
my $prediction_year = shift;
my $dgn_src_dir = shift;
my $mapinfo_dest_dir = shift;
my $mapinfo_text_dir = shift;
my $i = 0;
# search patterns
my $search_dgn_in = "DGN_IN";
my $search_dest_dir = "DESTDIR";
my $search_csv_out = "CSVOUT";
my $prepend;
my $curr_yr_pred = $current_year . "_" . $data_class . "_" . $prediction_year;
foreach my $line (@fme_template_file)
{
if ($line =~ m/$search_dgn_in/g)
{
if ($line =~ m/DEFAULT_MACRO/g)
{
$prepend = "DEFAULT_MACRO SourceDataset_IGDS_1 ";
} else {
$prepend = "#! DATASET=\"";
}
$line = "$prepend$dgn_src_dir\\$dgn_fname\n";
$dgn_in = 1;
}
if ($line =~ m/$search_dest_dir/)
{
if ($line =~ m/DATASET/)
{
$prepend = "#! DATASET=\"";
} else {
$prepend = "DEFAULT_MACRO DestDataset_MAPINFO ";
}
$line = $prepend . $mapinfo_dest_dir . "\"\n";
}
if ($line =~ m/$search_csv_out/)
{
if ($line =~ m/DATASET/)
{
$prepend = "#! DATASET=\"";
} else {
$prepend = "DEFAULT_MACRO DestDataset_CSV_1 ";
}
$line = $prepend . $mapinfo_text_dir . "\\" . $prediction_year . ".csv\"\n";
}
$fme_output_script[$i++] = $line;
}
write_fme_file($data_class, $prediction_year);
}
.
- Follow-Ups:
- Re: problem with simple pattern matching
- From: Chas Owens
- Re: problem with simple pattern matching
- References:
- Re: Problem in opening the file using Tail Module
- From: Rob Dixon
- Re: Problem in opening the file using Tail Module
- Prev by Date: More Perl and AJAX
- Next by Date: AW: More Perl and AJAX
- Previous by thread: AW: Problem in opening the file using Tail Module
- Next by thread: Re: problem with simple pattern matching
- Index(es):
Relevant Pages
|
|