First of all I want to thank everyone for helping with the first error I was having. I was able to get the code cycling through the files, however now I'm running into an error doing a regex substitutions.
#Find the CHAN pair if( $UNID[1] eq $UNID[$x] ) { #Temporary variable to store the CHAN $channel2 = $CHAN[$x]; #Creates a loop counter $y = 1; #Tracks if the changes have been complete $complete = 0; #Search the files for the instancs of the CHAN while( ( $y < scalar( @FILES ) ) && ( $complete == 0 ) + ) { #Open the file for replacement open $fd, '<', $FILES[ $y ]; #Creates a backup of the original file $^I = '.bac'; @file = <$fd>; seek $fd, 0, 0; print "$channel1 and $channel2\n"; foreach $file ( @file ) { $file =~ s/$channel2/$channel1/ or die $!; } #Close the file that was searched close $fd; $y++; }#End replacing while #Remove the used entries from the array delete $CHAN[1]; delete $UNID[1]; delete $CHAN[$x]; delete $UNID[$x]; #Force the loop to end $found = 1; }#End pair find if
For some reason the line containing the studstitution errors out saying the variables are uninitialized. But I can put a print statement directly before them and that will print the values just fine. If I a use an or die statement I recieve an error just saying that the program died. Any help would be greatly appreciated. Thank you.

In reply to Re: replacing text in multiple files by brayk1990
in thread replacing text in multiple files by brayk1990

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.