Re: How to process just part of a file
On Feb 9, 8:08 am, clay.lov...@carquest.com (Clay Lovett) wrote: 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. ... snip ... while (CRONDMP) { if ( /pattern1/ ... /pattern2/ ) { # do something here, like print matched: $_; } else { # do something different print; } } You can also match on line number: if ( $. == 100 ... $. == 150 ) { ... } or a combination: if ( $. == 200 ... /^your reg[ex]/ ) { ... } HTH. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to process just part of a file
Eric Pement wrote: You can also match on line number: if ( $. == 100 ... $. == 150 ) { ... } That is the verbose way to write: if ( 100 .. 150 ) { ... } or a combination: if ( $. == 200 ... /^your reg[ex]/ ) { ... } If you are going to be verbose then: if ( $. == 200 ... $_ =~ /^your reg[ex]/ ) { ... } Or just: if ( 200 ... /^your reg[ex]/ ) { ... } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
How to process just part of a file
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: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to process just part of a file
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 clay.lov...@carquest.com 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: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/