Subject: RE: backslashes and perl
From: Neil Lunn <[email-masked]>
To: "'Peter Buckley'" <[email-masked]>, Neil Lunn <[email-masked]>
Cc: "[email-masked]'" <[email-masked]>
Date: Wed, 9 May 2001 14:09:33 +1000

> -----Original Message-----
> From: Peter Buckley [mailto:[email-masked]]
> Sent: Wednesday, May 09, 2001 8:06 AM
> To: 'Neil Lunn'
> Cc: [email-masked]'
> Subject: RE: backslashes and perl
> 
> 
> The correct syntax on *all* versions of perl? 
> I don't think I am using "active" perl, 
> or you must mean all versions except 5.001, 
> since my script accepted backslashes as paths 
> and worked fine in an NT command shell. 
> 
> It seems that /path/to/myfile is not 
> the only correct path syntax on all versions of perl. 

It actually is though. What you are reffering to is a porter issue. Perl was
unified for Win32 platforms at version 5.004, so I cannot be sure what
source your perl is based on. Besides, there is a wealth of perl modules out
there that will not work with a version less than 5.003 so you are best off
moving forward.

At any rate this is *not* a perl problem. (see below)

> 
> NT command shell uses C:\path\executable.exe, 
> and so do perl 5.001 and cygwin B20, 
> without any problems, 
> flags, 
> or variables that need to be set. 
> 
> I don't have the line "C:\path\executable.exe" in my perl script, 
> I just have a variable that accepts the parameter from the shell. 

Aha. You should have said this in the first place.

> 
> The NT command shell passes "C:\path\executable.exe" to the script. 
> 
> So I am not interested in rewriting the perl script to be portable, 
> it's portable already.

I doubt it. The question here is how are you setting the parameter and how
are you reading it.

For example (under bash)

export FOO=c:\foo.exe
perl -e 'print $ENV{FOO}' # Will produce c:foo.exe
for that matter so will echo $FOO as '\' as a shell escape char

Under NT Command shell
set FOO=c:\foo.exe
echo %FOO% of course prints c:\foo.exe # not an escape char in MS-DOS like
stuff.

therefore
perl -e 'print $ENV{FOO}' # Will also produce c:\foo

and guess what happens if FOO was set in the NT environment.
perl -e 'print $ENV{FOO}' # Will also produce c:\foo

As you can see, people *have* gone out of their way to accept NT shell
syntax. The same semantics are taken on for arguments taken in by perl.
Where you are running into a problem is with your call to system() or
whatever.

Internally perl *will* treat '\' as an escape character in any string. What
you need to do is something like this:

my $command = $ARGV[0];
$command =~ s/\\/\//g;	# Swap '\' for '/'
system($command);

Now that will work.

Neil

> 
> I want cygwin and perl to be portable, 
> i.e. to work with an NT command shell
> and its default syntax.
> 
> I can't believe that programs written to emulate unix on NT 
> can't accept NT
> command shell syntax. 
> 
> Does this clarify my question?
> -Peter
> 
> -----Original Message-----
> From: Neil Lunn [mailto:[email-masked]]
> Sent: Tuesday, May 08, 2001 12:23 AM
> To: 'Peter Buckley'; [email-masked]'
> Subject: RE: backslashes and perl
> 
> 
> Replied to your earlier message. "\" is an escape character. 
> The correct
> path syntax on *all* versions of perl is /path/to/myfile.
> 
> Actually you should be using C:/path/executable.exe. This is 
> compatible with
> cygwin and Activestate perl.
> 
> Better Still, even the "C:" should be pulled in by a variable 
> or config to
> make your script really portable.
> 
> Neil
> > -----Original Message-----
> > From: Peter Buckley [mailto:[email-masked]]
> > Sent: Tuesday, May 08, 2001 4:35 AM
> > To: [email-masked]'
> > Subject: backslashes and perl
> > 
> > 
> > I don't think I am asking the question right- 
> > 
> > What I really need is for the new perl to work with an NT 
> > command shell.
> > It used to- when I was using Cygwin B20 and Perl 5.001. 
> > 
> > Just like I can set MAKE_MODE=win32, 
> > I need a PERL_MODE=win32. 
> > 
> > I want my new cygwin and new perl to accept paths 
> > that contain backslashes, and still treat them as paths.
> > 
> > The NT command shell is going to pass perl a path that
> > contains backslashes, and I need to switch on the flag that
> > will make perl treat the path like a win32 path.
> > 
> > Thanks,
> > Peter
> > 
> > 
> > Sounds like what you really need is to make sure that your script
> > runs in a POSIX environment.  Then you can use the /, and
> > everything would be okey-dokey....  There is a cygpath function
> > for coders, so why couldn't you create a Perl function/package
> > that does this, and always call it before you actually reference
> > your object.  This function would mangle the POSIX style name
> > into a system specific style name based upon the runtime environment
> > it finds.
> > 
> > 
> > On Fri, 4 May 2001 16:09:06 -0400, Peter Buckley wrote:
> > 
> > >The thing is, this perl script used to work with perl 5.001 
> > unofficial
> > >pathlevel 1m. It is just since I upgraded to perl 5.6.1 with 
> > 1 registered
> > >patch that I started having this problem. The 
> > script/makefile in question
> > >has to work on UNIX, NT, and Win2k. And backslashes are a 
> > necessity with a
> > >Win2k command shell. I am testing the new cygwin stuff 
> > before we start
> > using
> > >it company wide, and eventually recommend it to our 
> > customers. I would like
> > >to find the flag or option to perl so I can use backslashes, 
> > instead of
> > more
> > >ifdef-ing for all my variables in NT. 
> > >
> > >Thanks,
> > >Peter
> > >
> > >-----Original Message-----
> > >From: Mark Paulus [mailto:[email-masked]]
> > >Sent: Friday, May 04, 2001 3:57 PM
> > >To: [email-masked]; Peter Buckley
> > >Subject: Re: backslashes stripped in perl
> > >
> > >
> > >have you tried using \\ where you are using \?  Perl is 
> > probably seeing
> > >the \ as an escape character, so you need to escape the \ 
> to preserve
> > >it.  You may need to play with varying levels of \ to get it right
> > >depending on how many downstream filters are looking at the string
> > >(Check out some of Don Libes discussions about backslashes in his
> > >Exploring Expect book)
> > >
> > >
> > >On Fri, 4 May 2001 15:44:28 -0400, Peter Buckley wrote:
> > >
> > >>I am passing a parameter that contains backslashes in the 
> > path to a perl
> > >>script. 
> > >>I am calling the perl script from a makefile macro. The 
> line in the
> > >makefile
> > >>is
> > >>
> > >>target :
> > >>	$(PERL) myscript.pl $(ARG0) $(ARG1)
> > >>
> > >>And in the perl script I have the lines 
> > >>
> > >>$VARIABLE = @ARGV[0];
> > >>cmd "$VARIABLE -o $OPTION -c $PATH/path/config1 -batch";
> > >>
> > >>When $(ARG0) is C:\path\executable.exe, I get the error 
> > >>
> > >>C:pathexecutable.exe: not found
> > >>
> > >>It is stripping the backslashes out. 
> > >>I know that it works with forward slashes, 
> > >>and I had similar problems with make before this 
> > >>(I found out how to set MAKE_MODE = win32).
> > >>
> > >>I have to use backslashes in the path.
> > >>I didn't find anything when I searched for 
> > >>backslash perl
> > >>in the archives, and I didn't see an entry for perl
> > >>in the FSF online manuals.
> > >>
> > >>I am using the NT4.0 SP5 cmd.exe as my shell. I get this failure
> > >>whether I explicitly set the SHELL environment variable or
> > >>not.
> > >>
> > >>Thanks in advance for any help,  
> > >>
> > >>Peter Buckley
> > Peter Buckley
> > C-Port Corporation, a Motorola Company
> > One High Street
> > No. Andover, MA 01845
> > 978-773-2490
> > 
> > 
> > --
> > Want to unsubscribe from this list?
> > Check out: http://cygwin.com/ml/#unsubscribe-simple
> > 
> 
> ______________________________________________________________
> ____________
> Please Note :
> Only  the intended recipient is authorised to access or use 
> this e-mail.  If
> you are not the intended recipient,
> please delete this e-mail and notify the sender immediately.  
>  The contents
> of this e-mail are the writer's 
> opinion and are not necessarily endorsed by the Gunz Companies unless
> expressly stated.
> 
> We use virus scanning software but exclude all liability for 
> viruses or
> similar in any attachment.
> 
> 
> 
> --
> Want to unsubscribe from this list?
> Check out: http://cygwin.com/ml/#unsubscribe-simple
> 
> --
> Want to unsubscribe from this list?
> Check out: http://cygwin.com/ml/#unsubscribe-simple
> 

__________________________________________________________________________
Please Note :
Only  the intended recipient is authorised to access or use this e-mail.  If
you are not the intended recipient,
please delete this e-mail and notify the sender immediately.   The contents
of this e-mail are the writer's 
opinion and are not necessarily endorsed by the Gunz Companies unless
expressly stated.

We use virus scanning software but exclude all liability for viruses or
similar in any attachment.

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple