Don't understand how the slashes work on a Win32 machine @INC PATH Substitution current directory

Please look at the following error: (ActivePerl, Windows)

Can't coerce UNKNOWN to string in entersub at c:/Perl/lib/ line 184.
Use of uninitialized value in scalar chomp at c:\xxx\rte\Modules/ line 526.
Modification of a read-only value attempted at c:\xxx\rte\Modules/ line 527.

what's with the slashes? Why are they inconsistent?

Furthermore, How come I cannot get the following to work:

  use Cwd;
  my $PATH = cwd();
  $PATH =~ s/\//\\\\/g;   # substitute the slashes to be DOS compliant
  push(@INC, "$PATH");

# when I print $PATH; I get:
current path: C:\xxx_Projects\RTE\Modules

# when I print @INC; I get:

but if I use:
push(@INC, "C:\\xxx_Projects\\RTE\\Modules");

it works just fine!!!

How come I can't use cwd() to define a @INC include string? It barfs on me!

This question has probably been asked 100 times before - please don't ignore it!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just use
  my $PATH = cwd();
  push(@INC, $PATH);

"\\Modules" is the same as '\Modules', since "" interpolates, and '' does not.
DOS accepts / as a directory separator as long as it's not being parsed by the command shell

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sapbucketAuthor Commented:
  use Cwd;
  my $PATH = cwd();
  push(@INC, $PATH);
  #push(@INC, "c:\\xxx_projects\\rte\\Modules");

I still get an error
sapbucketAuthor Commented:
"insecure dependecy in require while running -T switch. BEGIN failed, compilation aborted"

could it be that because i am using BEGIN {} it is conflicting with some other BEGIN {} block somewhere?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

sapbucketAuthor Commented:
hmmm this is strange, within Komodo it won't compile, but from the command line it does!

This must be an issue with the IDE instead of PERL...

Your suggestion was the first thing I tried. It made my brain go "urkhgkkkk" when it didn't work - I thought I was in the twilight zone.

sapbucketAuthor Commented:

in Komodo, click Edit->Preferences->Languages->Perl-> and unselect Taint mode.

I'll award ozo with the points - his solution is afterall correct.

But why it doesn't work with taint enabled is beyond me.
'taint mode' is independent of which IDE you are using, it is built within the Perl compiler itself. Under taint mode, the compiler enforces certain data integrity checks on your variables, which prevent security issues. The data obtained through insecure means is labelled as 'tainted' and any derived from tainted data is itself tainted.

I really dont have much experience with tainted data but my guess would be that $PATH is tainted because cwd() returns tainted data(it returns `pwd` in most cases, especially other cases also, it searches in the %ENV which is again tainted) . This leads to @INC being tainted and hence require will fail as it uses @INC.
Taintedness can be subverted using pattern-matching backreferences...because Perl assumes you know what you are doing.
perldoc perlsec
for details on this.
sapbucketAuthor Commented:
It seems to me that there should be an easy way of getting the current path on Win32 box.

 I mean, just about everyone using modules has to add things to @INC, so why not a standard (untainted) way of doing this? Or is this a Win32 related thing?

Is there a way to turn of taint mode for a couple of lines? like 'no taint;' or something?
Couldn't you just use
push(@INC, "./Modules");
sapbucketAuthor Commented:
that works the best!

Thanks, and it works with -T turned on

and it fits in one line...

perfect solution!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.