473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2566
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,509 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
KevinADC
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
KevinADC
4,059 Expert 2GB
Are you talking about me again?

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

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: xtian | last post by:
Hi - I'm doing some data conversion with minidom (turning a csv file into a specific xml format), and I've hit a couple of small problems. 1: The output format has a header with some xml that...
8
by: jamesfin | last post by:
Dear XMLers, Please guide me... I have a simple xml file... <URLTest>
7
by: Rob Meade | last post by:
Hi all, Been a long time since I've been here... /me waves to all.. Ok - my conundrum.. I have a form where a user can enter text and BB codes...for example:
6
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an...
14
by: shamirza | last post by:
Question Do ActiveX DLLs made in VB still need the VB runtimes on the machine? ________________________________________ Answer In a word, Yes. Visual Basic does not support what is known...
6
by: Dic4000 | last post by:
ÏÂÃæ³ÌÐò½¨Á¢²»ÁËÎļþ,²»ÖªµÀÄÄÀï³ö´íÁË? Ö»Ï붨ÒåÒ»¸öfstreamÀàÐÍÀ´Íê³ÉÊäÈëÊä³öµÄ¹¤×÷. #include<iostream> #include<conio.h> #include<fstream> using namespace std; int main()
6
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME>...
7
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME>...
6
by: Bartholomew Simpson | last post by:
I'm trying to avoid (or at least, minimize) duplicity of effort. I have the following function: void Permissions::Exists(const unsigned int id, std::vector<Permission>::const_iterator& iter) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.