CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Forward slash to backward slash and strip off y:

 



triveni1125
New User

Dec 23, 2009, 5:22 PM

Post #1 of 3 (4100 views)
Forward slash to backward slash and strip off y: Can't Post

can someone please help me in writing the regular expression for the following..
actually fileVapth we have "Y:\default\main\safari\Airline\WORKAREA\Workarea01/html/jetnet/china.html";

But I need to change it to /default/main/safari/Airline/WORKAREA/Workarea01/html/jetnet/china.html ---All fwd slashes and stripoff y:
For this i tried to write the regex as following...But did not workout can u please help...

1.I tried to replace backwd slashes with fwd slashes using $fileVpath=~ s# \ # / #ig;
2.To strip off y:$fileVpath=~ s# ^y:(.*) # $1 #i;

Following is the program...
#!c:/perl/bin
my $fileVpath="Y:\default\main\safari\Airline\WORKAREA\Workarea01/html/jetnet/china.html";
$$fileVpath~ s# \ # / #ig; #to replace backwd slashes with fwd slashes#
print "string3 is now $string3";
$string3=~ s# ^y:(.*) # $1 #i; #To strip off y:the string3 values should be /default/main/safari/Airline/WORKAREA/Workarea01/html/jetnet/china.html#
print "string3 is now $string3";

Thanku,
Triveni


toolic
User

Dec 24, 2009, 10:16 AM

Post #2 of 3 (4082 views)
Re: [triveni1125] Forward slash to backward slash and strip off y: [In reply to] Can't Post

\ is special, and it needs to be escaped: \\


Code
use strict; 
use warnings;

my $str = 'Y:\default\main\safari\Airline\WORKAREA\Workarea01/html/jetnet/china.html';
$str =~ s/^Y://;
$str =~ s{\\}{/}g;
print "$str\n";



(This post was edited by toolic on Dec 24, 2009, 10:18 AM)


shawnhcorey
Enthusiast


Dec 24, 2009, 11:21 AM

Post #3 of 3 (4078 views)
Re: [triveni1125] Forward slash to backward slash and strip off y: [In reply to] Can't Post

If you're going to be playing with file paths, I suggest you use File::Spec. It is a standard module, and like all standard modules, it's installed along with Perl.

See `perldoc File::Spec` or http://perldoc.perl.org/File/Spec.html

For a list of standard modules, see `peldoc perlmodlib` or http://perldoc.perl.org/perlmodlib.html

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives