in reply to Re: How to save the output result in file
in thread How to save the output result in file

i tried like my
$filename = "/home/Ram/Desktop/Perl_file.txt"; open(my@array_a = @array[0..5], '>', $filename) or die "Could not open + file '$filename' $!"; print @array_a ; close @array_a; print "done\n";
but it showing error like

first five string:abcdef ghi ijklmnop q rstu vwxy Can't use string ("6") as a symbol ref while "strict refs" in use at array.pl line 22 (#1) (F) Only hard references are allowed by "strict refs". Symbolic references are disallowed. See perlref. Uncaught exception from user code: Can't use string ("6") as a symbol ref while "strict refs" in use at array.pl line 22. at array.pl line 22

. Why it showing error? Please let me know

Replies are listed 'Best First'.
Re^3: How to save the output result in file
by hdb (Monsignor) on Jan 17, 2014 at 06:52 UTC

    You need to add a variable for the filehandle:

    my $filename = "/home/Ram/Desktop/Perl_file.txt"; open(my $filehandle, '>', $filename) or die "Could not open file $file +name\n"; print $filehandle @array_a ; close $filehandle; print "done\n";