http://qs321.pair.com?node_id=1105905


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;