First of all, Yes, even you can use CPAN, and you can always copy the code from within modules into your program.

Second, are you sure that it works? Because after adding some print statements to your code to monitor its progress it seem to me that it's not doing anything sensible:

#!/usr/bin/perl use strict; #open DATA, "</home/file.conf"; my $DESIRED_LINE_NUMBER; my $LINE; while (<DATA>) { if(m/END/) { print "END line is on line >$.\n"; print "END line is >$_\n"; my $pos = $.; $pos--; chomp $pos; $DESIRED_LINE_NUMBER = $pos; } } print "Moving to line number $DESIRED_LINE_NUMBER\n"; $. = 0; do { $LINE = <DATA>; print "Discarding: $LINE\n" } until $. == $DESIRE +D_LINE_NUMBER || eof; print "Found desired line $DESIRED_LINE_NUMBER as '$LINE'\n"; __DATA__ foo bar baz END bloob blargh blubb blubb2

But then again, if you're confident that it does what you want, most likely you're also able to modify it yourself to do more of what you want.

The modified program outputs:

C:\Projekte>perl -w tmp.pl >4 >END Moving to line number 3 Use of uninitialized value $LINE in concatenation (.) or string at tmp +.pl line 2 6. Discarding: Use of uninitialized value $LINE in concatenation (.) or string at tmp +.pl line 2 7. Found desired line 3 as ''

... which doesn't look like the line above the END line to me.


In reply to Re^13: Help editing a file based off seach criteria by Corion
in thread Help editing a file based off seach criteria by perlnewb123

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.