in reply to Problem with reading the total file into variable

Your code is highly confused. There only is one instance of the MYFILE filehandle and the flow is as follows:

  1. while(<MYFILE>)... reads one line from the file into $_
  2. print <MYFILE> reads all remaining lines from MYFILE and prints them
  3. $data = join "", <MYFILE> assigns the empty string to $data because MYFILE is at the end of the file now.

Maybe you can take a step back and explain why you are sprinkling various attempts to read from MYFILE over your code and what your real goal is?

Replies are listed 'Best First'.
Re^2: Problem with reading the total file into variable
by ravi45722 (Pilgrim) on Aug 25, 2015 at 07:18 UTC

    Thanks for reply. I want to do exactly what Athanasius did. From this I learn How  while<MYDATA> &  print <MYDATA> works.