Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Well, that will never issue that warning :) anyway this is what I imagine you're after, you can add lots of print/warn debugging statements to figure out how it works

#!/usr/bin/perl -- #~ 2012-11-25-06:19:07PDT by Anonymous Monk #~ perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END" -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" use strict; use warnings; use autodie; # dies if open/close... fail Main( @ARGV ); exit( 0 ); sub Main { if( @_ == 3 ) { NotDemoMeaningfulName( @_ ); } else { Demo(); print '#' x 33, "\n", Usage(); } } sub NotDemoMeaningfulName { my( $inputFile, $outputFile, $dataFile ) = @_; my $DataRegex = MakeRegex( $dataFile ); open my( $inFh ), '<', $inputFile; open my( $outFh ), '>', $outputFile; my $this_line = ""; my $do_next = 0; while( <$inFh> ) { my $last_line = $this_line; $this_line = $_; if( $this_line =~ m{$DataRegex} ) { print $outFh $last_line unless $do_next; print $outFh $this_line; $do_next = 1; } else { print $outFh $this_line if $do_next; $last_line = ""; $do_next = 0; } } close $inFh; close $outFh; } ## end sub NotDemoMeaningfulName sub Usage { <<"__USAGE__"; $0 $0 infile outfile datafile perl ${\__FILE__} perl ${\__FILE__} infile outfile datafile __USAGE__ } ## end sub Usage sub MakeRegex { my( $inputFile ) = @_; open my( $data ), '<', $inputFile; my @dForRex; while( <$data> ) { chomp; push @dForRex, quotemeta $_; } my $rex = join '|', @dForRex; qr{$rex}; } ## end sub MakeRegex sub Demo { my( $Input, $WantedOutput, $Data ) = DemoData(); NotDemoMeaningfulName( \$Input, \my $Output, \$Data ); require Test::More; Test::More::is( $Output, $WantedOutput, ' NotDemoMeaningfulName Works Aas Designed' ); Test::More::done_testing(); } sub DemoData { #~ http://perlmonks... my $One = <<'__One__'; 0 yes I am 1a Faking it :) 2b with a 4386_7#8 3c then a 4386_7#11 4 cause I go to 12 5a and thirteen too 6b shabba 4350_7#6 7c shabba shooby dooby doo 8 ha cha cha cha 9 hi hi hi __One__ #~ http://perlmonks... my $Two = <<'__Two__'; __Two__ #~ http://perlmonks... my $Three = <<'__Three__'; 4386_7#8 4350_7#6 4414_1#6 __Three__ return $One, $Two, $Three; } ## end sub DemoData __END__

In reply to Re^7: How to print the lines immediately above and below a matching line? by Anonymous Monk
in thread How to print the lines immediately above and below a matching line? by Bio90

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2014-08-21 02:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (127 votes), past polls