in reply to Edit a New file in place after reading it in

Not relevant to your original question, but:

Perl's open will create a file if it does not exist. There would normally be no need to shell out to create it before you open it.

my $New_Part_Date = system "date"; assigns $New_Part_Date the exit status of the date command (probably 0). The actual date goes to the terminal that runs the Perl script. In general if you want to capture the output of a command you use something like my $New_Part_Date = `date`;. But in this specific case I would do my $New_Part_Date = localtime;, which does not involve shelling out.

Replies are listed 'Best First'.
Re^2: Edit a New file in place after reading it in
by perlynewby (Scribe) on Dec 22, 2021 at 16:04 UTC

    Yes, I was expecting Perl to create the file but it wasn't. I Googled for the answer for this but I couldn't make it work so I added that system "touch" to create it for me. I'd like to know why Perl was having a hard time creating the file on my Linux shell; it is still a mystery to me. Yes, I will use your suggestion to have the file time stamped. Grazie mille!

      Your code checks for errors from open (good) but it just calls die on failure (not so good). Better would be to include what you were trying to open as well as the contents of the $! variable which will tell you what the problem was (showing just creating your output handle but similar message are useful for opening files for input as well):

      open my $outfh, '>', $New_part_report or die "Problem opening '$New_part_report' for writing: $!\n";

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.