I am new to Perl as I was trying to create a text file in a sub-directory named as data inside a directory named as a test, I have tried to write the following code, the code is as follows:-
#!/usr/bin/perl
use strict;
use warnings;
use Cwd qw(abs_path);
use File::Path qw(make_path remove_tree);
my $path = abs_path();
my @file = open(my $fh, '>>', '$path/test/data') or die "unable to create text file $!";
print $fh;
close $fh or die "unable to close file $fh $!\n";
It gave me the following error:-
unable to close file GLOB(0x1d5ea68) Bad file descriptor
Please it would be really helpful and appreciated if you can explain what is happening here? and how can it be solved? Thanks in advance.