First, we should make sure that we can recognize the beginning and the end
of section within CRONDMP file itself.
For example, let's define
my $SEC_START = '## SECTION START',
my $SEC_END = '## SECTION END';
When the source file contains both of these, and so the section we need is
clearly marked, we have two ways of doing the partial processing:
1) either we can redefine an input separator to "$SEC_START\n", skip the
first part of file, then cut the resulting string up to $SEC_END, like that:
...
local $/ = $SEC_START . $/;
<DATA>;
while (<DATA>) {
$_ = substr $_, 0, (index $_, $SEC_END);
my @lines = split /^/;
## processing @lines here...
last;
}
...
2) ...or we can use $in_section flag and control what we do with it:
...
my $in_section;
while (<DATA>) {
if ($in_section) {
last if /$SEC_END/;
### insert original code here
}
else {
$in_section++ if /$SEC_START/;
}
}
...
Each way has its advantages and disadvantages, as usual. )
-- iD
2012/2/9 Clay Lovett <[email protected]>
> I have inherited a script that processes the cron and comments stuff out
> for month end processing. We have added some store that do not run the same
> monthly calendar as the rest of the stores. What I need to know is how to
> add a start and a finish section to the code so that it only processes the
> section I want it to. I have included the code below:
>
> while(<CRONDMP>){
> s/\n|\r//g;
>
> $PoutputFile5pm=
> (/icpw/ && /start_pricingfeed.sh/) ||
> (/icpw/ && /start_inventoryfeed.sh/) ||
> (/icpw/ && /start_customerfeed.sh/) ||
> (/DwInventoryFeed/ && /dw_inventory_feed.pl/) ||
> (/CustFeed/ && /XplCust.sh/) ||
> (/CustFeed/ && /accUpd.sh/) ||
> (/RebateFileExtract/ && /rebate_file_extract.pl/)
> ;
>
> $PoutputFile915pm=
> (/icpw/ && /start_pricingfeed.sh/) ||
> (/icpw/ && /start_inventoryfeed.sh/) ||
> (/icpw/ && /start_customerfeed.sh/) ||
> (/DwInventoryFeed/ && /dw_inventory_feed.pl/) ||
> (/CustFeed/ && /XplCust.sh/) ||
> (/CustFeed/ && /accUpd.sh/) ||
> (/RebateFileExtract/ && /rebate_file_extract.pl/)
> ;
>
> if($PoutputFile5pm){
> print CRON5PM "###cmt###$_\n";
> }else{
> print CRON5PM "$_\n";
> }
>
> if($PoutputFile915pm){
> print CRON915PM "###cmt###$_\n";
> }else{
> print CRON915PM "$_\n";
> }
>
>
> print CRONORIG "$_\n";
> }
>
> Thanks in advance
>
> Clay Lovett, MBA/TM
> UNIX Systems Administrator
> GPI Technologies, LLC
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>