in reply to Access given folder to parse a file

Hi ArifS,

There are a number of problems with your code that would have been shown to you had you started your program off using strict and warnings. There is a function provided by File::Spec::Functions named catfile, which will put the proper separator between your directory and file. I'd also suggest using the 3 argument version of open along with a lexical variable instead of a bareword "INPUT". Example changes shown below along with use of Win32 GetFolderPath to use the Desktop as the target directory:

use strict; use warnings; use File::Spec::Functions; use Win32 qw(CSIDL_DESKTOP); my $directory = Win32::GetFolderPath(CSIDL_DESKTOP); my $file = "my log file.log"; my $path = catfile($directory,$file); open my $input, '<', $path or die "Can't open INPUT: $!"; my @lines = <$input>; print "I have access to the folder\n"; close $input;

Replies are listed 'Best First'.
Re^2: Access given folder to parse a file
by ArifS (Beadle) on Nov 03, 2014 at 15:02 UTC
    I tried your script replacing with the following and getting an error-
    use Win32 qw(folder(1)); my $directory = Win32::GetFolderPath(folder(1));
    Error: "folder(1)" is not exported by the Win32 module Can't continue after import errors at c:\temp\dir5B6B.tmp\AccessFolder +.pl line 8. BEGIN failed--compilation aborted at c:\temp\dir5B6B.tmp\AccessFolder +line 8.
    Please let me know.

      Please explain what the following line is supposed to do:

      use Win32 qw(folder(1));

      Where did you find this syntax documented in the documentation of Win32?