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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |