kindly help me to get out the error of " Use of uninitialized Value $_ in substitution.

my code is.....

#!/usr/bin/perl
use warnings;
use strict;

open (TEXT_FILE1,'C:\Documents and Settings\rnjenga\Muguga.embl'); # open file for reading

my ($line1, $nextline1 ,$line2,$newline );
my ($find1, $find2);

#Get required line from file
while ($line1 = <TEXT_FILE1>) {


          if ($line1 =~ /FT\s*\Wnote.+\w+:/){
          $nextline1 = <TEXT_FILE1> ;
           print " $line1 $nextline1 \n" ;
}          $find1 = ( '$line1 $nextline1' );
}

 open (TEXT_FILE2,'C:\Documents and Settings\rnjenga\Marikebuni.embl');# open file for reading

#Get required line from file2
  while ($line2 = <TEXT_FILE2>) {

        if ($line2 =~ /FT\s*\Wnote.+none/){
         # $nextline2 = <TEXT_FILE2> ;
           print " $line2 \n" ;
         $find2 = ('$line2' );


   }

   }
  $_ =~ s/$find2/$find1/; # substitute line from File1 with the one from file 2

close (TEXT_FILE2);
close (TEXT_FILE1);

Thanks in advance.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

well from what i can see is that $_ is a default set variable, but in your case its not being set by perl anywhere b/c you set all your variables up.

you'll might need to rethink your code layout if you want to access the $_ variable.

while (<SOME_FILE_HANDLE>){

{

uses the $_ variable for each line of the files data.

This article has been dead for over six months. Start a new discussion instead.