Perl

How to write into a file?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

# We can use:
# '>' Write (it clears a previous content if exists).
# '>>' Append.
open(my $fh, '>>', 'file_name.ext') or die "Error: file can't be opened";
print $fh "writing text...\n";
close($fh);