Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Access given folder to parse a file

by Loops (Curate)
on Nov 03, 2014 at 14:46 UTC ( [id://1105905]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105905]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found