problem with slash and backslash : strange behaviour with different PC 
Author Message
 problem with slash and backslash : strange behaviour with different PC

hello,

I have different behaviour between 2 PC with this code :
      if ($vpf !~ /^$winpath/)
with :
  winpath = C:\ccs\psapp\Build\Dest\.LOCK
  vpf = C:/ccs/psapp/Build/Dest

The problem seems to come from the value of $winpath because "\p" from
"\psapp" is interpreted by perl as a regex option.

When I write my code as follow :
      if ($vpf !~ /^\Q$winpath/)
it works fine.

But why this code works on a PC and not on another ?
======================================================
  On a PC : I need the \Q option
  On another : the first code works directly

??? Why ???

The PC have the same configuration and the perl comes from
the package of "MKS Toolkit for developer 8.0" (it is perl 5.6.0 :
perl -v)

Thank you very much
Pascal



Fri, 27 May 2005 10:24:31 GMT  
 problem with slash and backslash : strange behaviour with different PC
Also sprach Pascal:

Quote:
> I have different behaviour between 2 PC with this code :
>       if ($vpf !~ /^$winpath/)
> with :
>   winpath = C:\ccs\psapp\Build\Dest\.LOCK
>   vpf = C:/ccs/psapp/Build/Dest

> The problem seems to come from the value of $winpath because "\p" from
> "\psapp" is interpreted by perl as a regex option.

> When I write my code as follow :
>       if ($vpf !~ /^\Q$winpath/)
> it works fine.

That's the expected behaviour.

Quote:
> But why this code works on a PC and not on another ?
>======================================================
>   On a PC : I need the \Q option
>   On another : the first code works directly

> ??? Why ???

> The PC have the same configuration and the perl comes from
> the package of "MKS Toolkit for developer 8.0" (it is perl 5.6.0 :
> perl -v)

And it's in both cases 5.6.0? I just browsed perldelta according to
which the \p assertion has been introduced in Perl 5.6.1. That means, a
plain '\p' will fail under 5.6.1 while it works under more previous
releases.

Whatever it is, you should conclude from this behaviour that putting a
string with possibly arbitrary content should not be used as input for a
regular expression, simply because of all those meta-characters that
could be in it. That's where \Q is useful as you have already found out.

Tassilo
--

pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;



Fri, 27 May 2005 11:02:52 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Strange behaviour with variables in different namespaces

2. Slash vs backslash in nt vs 95?

3. Filename seperators - slash or backslash!

4. NT Perl 5 and slash vs. backslash

5. Substituting backslash for 2 forward slashes

6. Changing back slashes to forward slashes

7. Different behaviour between perl4/perl5

8. localtime() behaviour different on UNIX and Win32

9. different behaviour when running from web and command line

10. CGI.pm - strange behaviour

11. regexp: strange behaviour (it works but it doesn't)

12. Strange behaviour, Part 2

 

 
Powered by phpBB® Forum Software