438,834 Members | 2,265 Online
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

# Questions relating replacing a variable and file parse.

 P: 68 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 $value = D:/Folder/TEST/abc.txt my ($name, $path,$extension ) = fileparse ( $value, '\..*' );$filename = $name .$extension;   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 Share this Question 6 Replies  Expert 2.5K+ P: 4,059 Look at this: Expand|Select|Wrap|Line Numbers$string = "D:\Folder\TEST\abc.txt"; 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$string = 'D:\Folder\TEST\abc.txt'; Are you trying to parse Windows filepaths on a Linux/Unix box? From File::Basname: 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. Sep 24 '08 #2  Expert Mod 2.5K+ P: 3,503 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  Expert 100+ P: 174 just another note when using Single quotes ' ' variables, arrays, etc. do not get printed/parsed eg. Expand|Select|Wrap|Line Numbers$echo = "hello";   print ' $echo world'; this will print$echo world Sep 24 '08 #4

 Expert 2.5K+ P: 4,059 just another note when using Single quotes ' ' variables, arrays, etc. do not get printed/parsed eg. Expand|Select|Wrap|Line Numbers $echo = "hello"; 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

 Expert 100+ P: 971 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

 Expert 2.5K+ P: 4,059 Are you talking about me again? --Kevin hehehe... were your ears buring? Sep 25 '08 #7