You can also write it as a one-line command:
perl -00ne 'BEGIN { $filename = "MyFileName0000" } { open my $IFILE, "
+>", $filename++; print $IFILE $_ }' table1.txt table2.txt tableN.txt
- -00 means separate on empty lines (paragraph mode) -- see cdarke's reply
- -n means implicit while (<ARGV>) { .. }
- -e uses an expression as the program instead of a full-fledge script
- The BEGIN { .. } block sets $filename at the beginning, outside of the implicit while loop
- Creating an explicit scope { open my $IFILE, .. } means we do not have to explicitly close($IFILE) since $IFILE is only effective within the curly braces -- once out-of-scope, $IFILE is auto-closed
To get a feel of the code, you can run this on its own:
perl -MO=Deparse -00ne 'BEGIN { $filename = "MyFileName0000" } { open
+my $IFILE, ">", $filename++; print $IFILE $_ }'