sanket vaidya wrote:
Hi all,
Hello,
As a part of one program I need to get the current working directory. So I get this using cwd(). I want to replace forward slash (/) by backslash (\) in the path which I get because I work on windows.
You shouldn't need to do that.
Kindly look at the code below: use warnings; use strict; use Cwd; my $current_path = cwd(); print "$current_path"; $current_path =~ s|/|\|;
That should be: $current_path =~ s|/|\\|g; Or: $current_path =~ tr|/|\\|;
print "$current_path";
perldoc -q quoting Found in /usr/share/perl/5.8/pod/perlfaq4.pod What’s wrong with always quoting "$vars"? The problem is that those double-quotes force stringification-- coercing numbers and references into strings--even when you don’t want them to be strings. Think of it this way: double-quote expansion is used to produce new strings. If you already have a string, why do you need more? If you get used to writing odd things like these: print "$var"; # BAD
When I run this I get the below error: Substitution replacement not terminated at line 8.
That is because a single backslash escapes the terminating delimiter.
However if I replace 's|/|\|' with 's////\/' it works.
$ perl -e's////\/' Search pattern not terminated at -e line 1. It doesn't appear to work.
Can anyone tell me why this happens & how to overcome it?
John -- Those people who think they know everything are a great annoyance to those of us who do. -- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/