Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl substitution working on some machines but not others?

Reply
Thread Tools

Perl substitution working on some machines but not others?

 
 
therocket79@yahoo.co.uk
Guest
Posts: n/a
 
      11-21-2006
Hi,

I have a question about the following line of code:

$new_file =~ s/^$from_dir/$to_dir/;

I have 2 variables $from_dir and $to_dir which are different directory
path names. I also have the $new_file variable which is the full path
of a file. I am trying to substitute the first part of the file path
($from_dir) with a new file path ($to_dir), following on from this I
copy the original file to the new location.

An example:

$new_file = C:/directory1/file.txt
$from_dir = C:/directory1
$to_dir = C:/directory2

I would like the result of the substitution to be $new_file =
C:/directory2/file.txt, so I can then copy C:/directory1/file.txt to
C:/directory2/file.txt

However, this seems to work on some machines but fail on others. The
reason being the substitution doesn't seem to take place correctly and
I end up trying to copy something to the same location. Can anyone
help with why this is happening?

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      11-21-2006
<(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Hi,
>
> I have a question about the following line of code:
>
> $new_file =~ s/^$from_dir/$to_dir/;
>
> I have 2 variables $from_dir and $to_dir which are different directory
> path names. I also have the $new_file variable which is the full path
> of a file. I am trying to substitute the first part of the file path
> ($from_dir) with a new file path ($to_dir), following on from this I
> copy the original file to the new location.
>
> An example:
>
> $new_file = C:/directory1/file.txt
> $from_dir = C:/directory1
> $to_dir = C:/directory2
>
> I would like the result of the substitution to be $new_file =
> C:/directory2/file.txt, so I can then copy C:/directory1/file.txt to
> C:/directory2/file.txt
>
> However, this seems to work on some machines but fail on others. The
> reason being the substitution doesn't seem to take place correctly and
> I end up trying to copy something to the same location. Can anyone
> help with why this is happening?


Too little info. What is the exact code that does (or doesn't do) the
substitution? What is the content of $from_dir, $to_dir and $new_file
in a case where it works and in a case where it doesn't? Also name the
OS and its version for a working case and one that doesn't work.

Anno
 
Reply With Quote
 
 
 
 
therocket79@yahoo.co.uk
Guest
Posts: n/a
 
      11-21-2006
Hi,

Thanks for your response. I've managed to get it wokring now, it was
actually to do with forward and backslashes being included in file
paths inconsistently.

Thanks again.

http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de wrote:

> <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> > Hi,
> >
> > I have a question about the following line of code:
> >
> > $new_file =~ s/^$from_dir/$to_dir/;
> >
> > I have 2 variables $from_dir and $to_dir which are different directory
> > path names. I also have the $new_file variable which is the full path
> > of a file. I am trying to substitute the first part of the file path
> > ($from_dir) with a new file path ($to_dir), following on from this I
> > copy the original file to the new location.
> >
> > An example:
> >
> > $new_file = C:/directory1/file.txt
> > $from_dir = C:/directory1
> > $to_dir = C:/directory2
> >
> > I would like the result of the substitution to be $new_file =
> > C:/directory2/file.txt, so I can then copy C:/directory1/file.txt to
> > C:/directory2/file.txt
> >
> > However, this seems to work on some machines but fail on others. The
> > reason being the substitution doesn't seem to take place correctly and
> > I end up trying to copy something to the same location. Can anyone
> > help with why this is happening?

>
> Too little info. What is the exact code that does (or doesn't do) the
> substitution? What is the content of $from_dir, $to_dir and $new_file
> in a case where it works and in a case where it doesn't? Also name the
> OS and its version for a working case and one that doesn't work.
>
> Anno


 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      11-22-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) schreef:

> $new_file =~ s/^$from_dir/$to_dir/;


$new_file =~ s/^\Q$from_dir/$to_dir/;

See perldoc -f quotemeta.

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Images do not show in IE browser on some client machines =?Utf-8?B?ZGF2aWQ=?= ASP .Net 5 09-13-2007 06:58 PM
WebRequest works on two machines, but not on a third. clockemail@alltel.net ASP .Net 0 07-18-2007 08:57 PM
Substitution Operator Not Working on Directory Path Strings Hike Mike Perl Misc 10 08-03-2005 04:52 PM
Getting "The Page cannot be displayed" on some machines but not others with ASP.NET pages R. G. ASP .Net Security 2 07-08-2004 08:37 PM
IE produces 404 Error when calling ASP page, but only on some machines... Andreas.Bretl ASP General 0 05-18-2004 01:55 PM



Advertisments