in reply to How to save the output result in file

See the documentation for open and print, and How do I write to a file?.

  • Comment on Re: How to save the output result in file

Replies are listed 'Best First'.
Re^2: How to save the output result in file
by rammohan (Acolyte) on Jan 17, 2014 at 06:41 UTC
    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

      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";