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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Parsing Delimited String

 



keith73
Novice

Nov 14, 2000, 9:09 AM

Post #1 of 3 (218 views)
Parsing Delimited String Can't Post

Have a string that I need to separate but only on the first delimit character.
The string is delimited using | and I only need to separate it using the first word and then everything after becomes the value.

product|name|type|price

I could do a split, splice and join but I want to try to do it with one command.

I've been trying to do this.

($item,$value) = /([^\|]*)/;

this only gets me $item. I want name|type|price to become $value.

I've tried adding to that match to account for everything after the first | including all remaing |'s and just can't get it to work.

Any help is appreciated.


japhy
Enthusiast

Nov 14, 2000, 9:31 AM

Post #2 of 3 (218 views)
Re: Parsing Delimited String [In reply to] Can't Post

If you read the documentation for split(), you'll see that you can tell it to split it into a specific number of parts:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$str = "john jacob jingleheimer schmidt";

($first,$mid1,$mid2,$last) = split ' ', $str;
print "$first, $mid1, $mid2, $last\n";
# john, jacob, jingleheimer, schmidt

($first,$rest) = split ' ', $str, 2;
print "$first, $rest\n";
# john, jacob jingleheimer schmidt
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



keith73
Novice

Nov 14, 2000, 9:54 AM

Post #3 of 3 (218 views)
Re: Parsing Delimited String [In reply to] Can't Post

Well smack me silly and call me slappy, I totally forgot about that.

Thanks for refreshing my memory. Of course, now I have that song stuck in my head.
"... his name is my name too..."

-Keith

 
 


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

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