#!/usr/bin/perl -- #~ 2011-09-21-11:45:38PDT by Anonymous Monk #~ perltidy -csc -otr -opr -ce -nibc -i=4 use strict; use warnings; use autodie; # dies if open/close... fail Main( @ARGV ); exit( 0 ); sub Main { if ( @_ == 1 ) { NotDemoMeaningfulName( @_, 'temp', \&DiddleSomeTemp ); } else { Demo(); print '#' x 33, "\n", Usage(); } } ## end sub Main sub NotDemoMeaningfulName { my ( $inputFile, $outputFile, $callBack ) = @_; my $flag = 0; my $outMode = '+>'; open my ($inFh), '<', $inputFile; open my ($outFh), $outMode, $outputFile; while (<$inFh>) { if (/^#/) { if ( not $flag ) { $flag++; close $outFh; open $outFh, $outMode, $outputFile; } else { seek $outFh, 0, 0; $callBack->($outFh); close $outFh; open $outFh, $outMode, $outputFile; } ## end else [ if ( not $flag ) ] } else { print $outFh $_; } } ## end while (<$inFh>) close $inFh; close $outFh; } ## end sub NotDemoMeaningfulName sub Usage { <<"__USAGE__"; $0 $0 dataFile perl ${\__FILE__} perl ${\__FILE__} dataFile __USAGE__ } ## end sub Usage sub DiddleSomeTemp { warn "Hey diddle diddle @_\n"; my $f = shift; warn "#$_" while <$f>; } sub Demo { my ( $Input, $WantedOutput ) = DemoData(); my $Output; require Test::More; NotDemoMeaningfulName( $Input, \$Output, sub { Test::More::is( $Output, $WantedOutput->[0], ' NotDemoMeaningfulName Works Aas Designed' ); shift @$WantedOutput; }, ); Test::More::done_testing(); } ## end sub Demo sub DemoData { #~ http://perlmonks.com/?abspart=1;displaytype=displaycode;node_id=927193;part=1 my $One = <<'__One__'; # A B C # D E F # __One__ my @Two = ( #~ http://perlmonks.com/?abspart=1;displaytype=displaycode;node_id=927193;part=2 <<'__Two__', A B C blah __Two__ #~ http://perlmonks.com/?abspart=1;displaytype=displaycode;node_id=927193;part=3 <<'__Two__', D E F blah __Two__ ); return \$One, \@Two; } ## end sub DemoData __END__ $ perl pm.927193.pl not ok 1 - NotDemoMeaningfulName Works Aas Designed # Failed test ' NotDemoMeaningfulName Works Aas Designed' # at pm.927193.pl line 76. # got: 'A # B # C # ' # expected: 'A # B # C blah # ' not ok 2 - NotDemoMeaningfulName Works Aas Designed # Failed test ' NotDemoMeaningfulName Works Aas Designed' # at pm.927193.pl line 76. # got: 'D # E # F # ' # expected: 'D # E # F blah # ' 1..2 ################################# pm.927193.pl pm.927193.pl dataFile perl pm.927193.pl perl pm.927193.pl dataFile # Looks like you failed 2 tests of 2.