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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
split or splice string on char count?


New User

Nov 26, 2010, 4:50 AM

Post #1 of 3 (889 views)
split or splice string on char count? Can't Post


I will try to explain my problem as simple as possible.

my $region1_Start = 5; #5th element in string
my $region1_End = 10; #10th element etc...
my $region2_Start = 21;
my $region2_End = 28;

I would like to cut both regions from the string and have the leftover 3 parts.
so part 1-4, 11-20 and 29-30, seperated from eachother.
The length of the $string is variable, the number of regions that has to be cut from the $string is also variable.

I tried a few different combinations of things like split, splice, substr, RE subs, or just RE matching, but i really dont see the solution.

Can someone help me?!


while !sleep {$sheep++};



Nov 26, 2010, 8:35 PM

Post #2 of 3 (870 views)
Re: [Linda] split or splice string on char count? [In reply to] Can't Post

Use substr!


Positions are numbered from 0 to 29 (not 1 to 30).

Replacing text with an empty string is the same as a 'cut'.

The third argument is the length of the field, not the end position.

Cut the fields in the order from last to first so required positions do not get renumbered.
Good Luck,

New User

Nov 28, 2010, 7:56 AM

Post #3 of 3 (861 views)
Re: [BillKSmith] split or splice string on char count? [In reply to] Can't Post


I think i have been staring at it for too long..i went back to subtr as you suggested en started at the end (why didnt i think of that Crazy), replacing the known regions with a *, i can then split the new string on * and get my left over parts. thanks for your help.



while !sleep {$sheep++};



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

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