Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

File::Spec::Win32; catpath

by smturner1 (Sexton)
on Jan 14, 2014 at 21:41 UTC ( [id://1070612]=perlquestion: print w/replies, xml ) Need Help??

smturner1 has asked for the wisdom of the Perl Monks concerning the following question:

Me again. I am really starting to curse the day I said I would take the time to learn Perl. I am debugging a program that keeps bombing out on my lexical variables. The error I am getting "Can't locate object method "Desktop" via package "Source_dir" (perhaps you forgot to load "Source_dir"?) at deploy line 50 (#1) Uncaught exception from user code: Can't locate object method "Desktop" via package "Source_dir" (perhaps y ou forgot to load "Source_dir"?) at deploy line 50. at deploy line 50". Any direction or help (...again!) would be greatly appreciated.
use File::Spec::Win32; my $SourceDir = File::Spec->catpath($volume, (Users st2641 Deskto +p Source_dir,));

Replies are listed 'Best First'.
Re: File::Spec::Win32; catpath
by choroba (Cardinal) on Jan 14, 2014 at 21:53 UTC
    You probably forgot to put qw before one of the parentheses:
    my $SourceDir = 'File::Spec'->catpath($volume, qw(Users st2641 Desktop + Source_dir));

    When seeing barewords separated by whitespace, Perl thinks "indirect object notation".

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: File::Spec::Win32; catpath
by Preceptor (Deacon) on Jan 14, 2014 at 21:57 UTC

    Add 'use strict' and 'use warnings'. You'll see you're treating 'Users' 'st2641' and 'Desktop' as bareword values, which means Perl doesn't really know, whether they're variables, procedure calls or strings.

    I would assume you're aiming to get e.g. "C:\Users\st2641\Desktop\Source_dir". If that's so, you need instead to do:

    use strict; use warnings; my $volume = "C:"; use File::Spec::Win32; my $SourceDir = File::Spec::Win32::catfile( $volume, qw ( Users s +t2641 Desktop Source_dir ) ); print $SourceDir,"\n";

    Is that more or less what you were after?

Re: File::Spec::Win32; catpath (perlintro, diagnostics, perlintro)
by Anonymous Monk on Jan 14, 2014 at 21:51 UTC
      You are correct about me forgetting to use 'qw', and not reading perlintro - which I will. I did use diagnostics, which I omitted in my post (my fault). So, the error I provided is verbose. I do realize I need to do a lot of reading to get where I need to be. I appreciate your help and direction.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-25 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found