in reply to Hey Monks, I need help understanding how to write to a text file

Don't you get perldoc open ? in google search ?

If FILEHANDLE, in your case its DIN is an undefined scalar variable, a new filehandle is autovivified, meaning that the variable is assigned a reference to a newly allocated anonymous filehandle. Otherwise if FILEHANDLE(DIN) is an expression, its value is the real filehandle.

Why should I use three-argument open ?

You should use the three-argument version because it protects against files with crazy names. Consider the following example

my $filename = "<file.txt"; open( INPUTFILE, "< $filename" ) or die "$!";

This will interpolate as: open( INPUTFILE, "< <file.txt" ) or die "$!"; So its actually open a file named file.txt instead of one named <file.txt.


All is well