How to re-direct the contents to a file instead of printing it to terminal

Simply use the 3 argument open method.

use strict;
use warnings;

my $line = "Hello Again!";
open (my $fh, ">", "/home/vibes/text") || die "Failed to open /home/vibes/text $!";
print $fh "$line\n";
close($fh); # Always close opened files.

Leave a Comment