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: Beginner:
regex to add pipe delimiter?

 



vallely
Novice

Jul 9, 2001, 1:09 PM

Post #1 of 3 (753 views)
regex to add pipe delimiter? Can't Post

I want add a pipe delimiter to the following lines.


January 01 1883 Firm named Emery Brothers established
February 28 1876 Delaware Grove Post Office re-established

I want a pipe after the first, second and third word. I would also like one at the end of each line.


I'm sure there is a very simple way to do this but Ive given it much time and finally gave up.
I'm a beginner (((snicker...snicker... no kidding???)))


Thanks for your time!





mhx
Enthusiast / Moderator

Jul 9, 2001, 1:20 PM

Post #2 of 3 (752 views)
Re: regex to add pipe delimiter? [In reply to] Can't Post

Hi,

if you put the line into $line, you can use the following code:

Code
$line = join('|', split ' ', $line, 4) . '|';

This will split $line into four parts at spaces, join the four parts with a pipe and finally append a pipe to the end. So

Code
"January 01 1883 Firm named Emery Brothers established"

will turn to

Code
"January|01|1883|Firm named Emery Brothers established|"

Hope this helps.

-- Marcus



vallely
Novice

Jul 9, 2001, 7:11 PM

Post #3 of 3 (746 views)
Re: regex to add pipe delimiter? [In reply to] Can't Post

Works perfectly.. Thanks!


 
 


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

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