I wrote this script in order to change multiple instances of text, for instance to change the location of images in a HTML doc. However, when the file is being read in and assigned to the array, it is removing the first line in the file? I'm sure it's a simple solution, I'm just not experienced enough to see it.
Any help is appreciated, the source is listed below.
Thanks, Jim
Any help is appreciated, the source is listed below.
Thanks, Jim
Code:
#!/usr/local/bin/perl -w
$counter = 1;
while (<*.inc>) { # < -- Enter the file name here.
$page = "$_";
#Opening file to save contents
open (PAGE, "$page") || die "Can't open $page $!\n";
#saving contents
while(<PAGE>)
{
@contents = (<PAGE>);
}
close PAGE;
print "Content-type: text/html\n\n";
print <pre>;
#processing file contents
foreach $item (@contents)
{
$item =~ s!<!<!g; # < -- change regex as needed
$item =~ s!>!>!g;
@converted =(@converted, $item);
print "$item";
$counter ++;
}
print "</pre>";
#opening page to save changes
open (PAGE, ">$page") || die "Can't open $page $!\n";
foreach $line (@contents)
{
print PAGE "$line";
}
close PAGE;
@contents = (); #removing array
@converted = (); #contents
print "\"$page\":\nProcessed Successfully...\n\n";
}