Here's some example code snippets. Hopefully it will help narrow down what you need to focus on for this project.

# start your program with these. trust me use strict; use warnings; # hash table of search strings and insertion code my %insertions = ( 'search string' => 'code insertion', foo => 'bar', alpha => 'beta', ); # read in array of filenames from a directory opendir (my $DH, $directory); my @files = $readdir $DH; closedir $DH; # iterate over array of filenames for my $filename (@files){ # process your file here # or use a subroutine subName($filename); } # basic subroutine sub subName{ # get first arg passed my $filename = shift; # if you need a return value return $foo; } # opening files. $TFH = target filehandle open (my $TFH, ">", $targetfile); open (my $SFH, "<", $sourcefile); # read source file line by line while (my $line = <$SFH>){ print $TFH, $line; # use regular expression to find matching string if ($line =~ /$matchString/){ print $TFH, $snippet; } } close $TFH; close $SFH;

In reply to Re: Manipulating File Contents Interactively by hangon
in thread Manipulating File Contents Interactively by TheWorldPeace

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.