473,406 Members | 2,847 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.

split function usage

Hi,
in order to split a path i used split m!/!, $Dir_name.
when i print the path, it gives \, so i tried different combinations but none are working,
please let me know.
i tried -
split m!\!, $_
split /\/, $_
etc

thanks in advance
Jul 7 '08 #1
4 1111
I'm not sure if you specifically need the split function or not. I usually use the index() and rindex() function to seperate the directory paths from each other. For example: if you want to split c:\program files\software\specific. And you wanted to split "specific" from the the rest of the directory path. I would do the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #you want to add 1 because you want to skip "\"
  3. $index_num = rindex($_, "\") + 1;
  4.  
  5. #specific would be saved in $filename
  6. $filename = substr($_, $index_num); 
  7.  
  8. #the directory would be saved into $directory path
  9. $dir_path = substr($_, 0, $index_num);
  10.  
  11.  
Jul 8 '08 #2
numberwhun
3,509 Expert Mod 2GB
To split up a path, the best thing to use is the File::Basename module. It is a much more efficient way to accomplish this task.

Regards,

Jeff
Jul 8 '08 #3
KevinADC
4,059 Expert 2GB
The backslash needs to be escaped, you need two of them, the first escapes the second one:

split /\\/, $_

But I also reccomend you use File::Basename
Jul 8 '08 #4
Thank you so much for the responses.
Jul 8 '08 #5

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

Similar topics

7
by: brianshields | last post by:
array("a", "b", "c", "d", "e"); I want to now be able to load "b" into a variable ($var) then print it out print $var thanks!
12
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
2
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces,...
15
by: zealotcat | last post by:
Hi, all: I want to implement a function (using std::string and std::vector) split a string contain special token into vector. eg: string = "alex delia john" ==> vector = "alex"; vector =...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
1
by: mdefoor | last post by:
I've written the following sample to split a string into chunks. Is this the right approach or is there perhaps a better way to accomplish getting chunks of a string? #include <stdio.h>...
1
Atli
by: Atli | last post by:
The following small HowTo is a compilation of an original problem in getting some cookie-values through different methods of string-handling. The original Problem was posted as follows: As...
1
by: John | last post by:
Hi I have written a Split function which in turn calls the standard string split function. Code is below; Function Split1(ByVal Expression As String, Optional ByVal Delimiter As String = " ",...
5
by: nagmvs | last post by:
Can anyone tell me about the usage of split function in Asp with Example ? i done one project using split function.and i have some problems regarding storing data in data base.I use there...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.