468,321 Members | 1,679 Online

# Questions relating replacing a variable and file parse.

Hi,

I'm trying to replace a character in a string. was facing problem in it.

$string = "D:\Folder\TEST\abc.txt" i wanted to transform this string to "D:/Folder/TEST/abc.txt" this is wot i tried, but doesn't work$string = ~ s/\\/\//;

Another Q is related to fileparse.

Expand|Select|Wrap|Line Numbers
1. $value = D:/Folder/TEST/abc.txt 2. my ($name, $path,$extension ) = fileparse ( $value, '\..*' ); 3.$filename = $name .$extension;
4.
I am getting the values as follows:

$name = abc$path = /
$extension = Where am I going wrong. Do i need to install anything thing for this. I have included File::Basename in the file. Any help is appreciated. Ravi Sep 24 '08 #1 6 2492 KevinADC 4,059 Expert 2GB Look at this: Expand|Select|Wrap|Line Numbers 1.$string = "D:\Folder\TEST\abc.txt";
2. print $string; the output is: D:FolderTEST.bc.txt notice there are no backslashes to substitute with forward slashes. The backslash in a double-quoted string is an escape character, not a literal backslash. You ned to use single-quotes: Expand|Select|Wrap|Line Numbers 1.$string = 'D:\Folder\TEST\abc.txt';

Are you trying to parse Windows filepaths on a Linux/Unix box?

From File::Basname:

<start quote>
fileparse_set_fstype

my $type = fileparse_set_fstype(); my$previous_type = fileparse_set_fstype($type); Normally File::Basename will assume a file path type native to your current operating system (ie. /foo/bar style on Unix, \foo\bar on Windows, etc...). With this function you can override that assumption. Valid$types are "MacOS", "VMS", "AmigaOS", "OS2", "RISCOS", "MSWin32", "DOS" (also "MSDOS" for backwards bug compatibility), "Epoc" and "Unix" (all case-insensitive). If an unrecognized $type is given "Unix" will be assumed. <end quote> Sep 24 '08 #2 numberwhun 3,503 Expert Mod 2GB Ravi, The slash in the closing code tag goes the other way. It is a forward slash and not a back slash. Please follow the example in the Reply Guidelines box as it shows the correct format. Regards, Jeff Sep 24 '08 #3 Icecrack 174 Expert 100+ just another note when using Single quotes ' ' variables, arrays, etc. do not get printed/parsed eg. Expand|Select|Wrap|Line Numbers 1.$echo = "hello";
2.
3. print ' $echo world'; this will print$echo world
Sep 24 '08 #4
4,059 Expert 2GB
just another note

when using Single quotes ' ' variables, arrays, etc. do not get printed/parsed eg.

Expand|Select|Wrap|Line Numbers
1. $echo = "hello"; 2. 3. print '$echo world';

this will print \$echo world

True but thats not the case here. This is a lack of knowing the basics of perl beforing trying to write programs.
Sep 25 '08 #5
eWish
971 Expert 512MB
This is a lack of knowing the basics of perl beforing trying to write programs.
Are you talking about me again?

--Kevin
Sep 25 '08 #6
4,059 Expert 2GB
Are you talking about me again?

--Kevin
hehehe... were your ears buring?
Sep 25 '08 #7