Thanks John. It works Regards, Sanket Vaidya
-----Original Message----- From: John W. Krahn [mailto:jwkr...@shaw.ca] Sent: Wednesday, July 01, 2009 11:17 AM To: Perl Beginners Subject: Re: Substitution question 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/ _____________________________________________________________________ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _____________________________________________________________________ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/