Gossamer Forum
Home : General : Perl Programming :

Newbie - line boundary when reading text files

Quote Reply
Newbie - line boundary when reading text files
New to PERL - i.e. five days! Hope the following is appropriate for this forum.

I have a simple task, but after a few hours of searching, cannot spot the answer, which I am sure is obvious.

I have PERL running on WinXP and I have text files like that shown at the bottom stored in MS Word.

I would like to read each line into a variable and then use regex to search for a string and extract the info. contained - it's a list of poker hands, so I want to know which hands I played, what was the result etc.

Question is what marks the line boundary - my little script seems to read about 20lines as one string, instead of each. In word, the end of each line seems to have a paragraph mark, but I can't search and replace for the ^p so, the only real paragraph mark is the one at the end of the document. NB. In word the following are displayed on consecutive lines, not with a double-line space as marked-up here.

What do I need to do to make PERL recognise the end of a line? In my little PERL book all the examples talk about manually inputted text, and not text read from a .txt file or something similar.

Thanks in advance for your help!

P.

------HAND 1------

Game #871100404: Texas Hold'em No Limit (15/30) - 2005/09/11 - 21:14:01 (UK)

Table "Tourney 1066310 - 21" Seat 9 is the button.

Seat 1: jaynos (1500 in chips)

Seat 2: Stev04055 (1480 in chips)

Seat 3: StevieD. (1360 in chips)

Seat 4: Lanc02061 (4870 in chips)

Seat 5: dutchsam (910 in chips)

Seat 6: Kreskin (1570 in chips)

Seat 8: richie200 (730 in chips)

Seat 9: carbonstu (1290 in chips)

Seat 10: TEXAN2000 (1290 in chips)

TEXAN2000: posts small blind 15

jaynos: posts big blind 30

----- HOLE CARDS -----

dealt to Stev04055 [Qs 8s]

Stev04055: folds

StevieD.: folds

Lanc02061: calls 30

dutchsam: calls 30

Kreskin: calls 30

richie200: raises to 730 and is all-in

carbonstu: folds

Quote Reply
Re: [Pincher] Newbie - line boundary when reading text files In reply to
Hi,

Should be \n Smile

I'm not really sure exactly what you're trying to do, or else I would have given you a bit more example code <G>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Newbie - line boundary when reading text files In reply to
In Reply To:
Hi,

Should be \n Smile

I'm not really sure exactly what you're trying to do, or else I would have given you a bit more example code <G>

Hope that helps.

Cheers

It could be either "\n\r|\n" depending on the text editor... Some editors format the text file in UNIX ASCII (UltraEdit32, Notepad++) format instead of M$ ASCII (Notepad, Word(pad)). Or something like that...

An alternative is to use while (<DATA>) { chomp; ... } which will strip off new line characters. ;)
Quote Reply
Re: [xtremenw] Newbie - line boundary when reading text files In reply to
Is it not normally \r\n instead of \n\r?

s/\r?\n//sg;
Quote Reply
Re: [xtremenw] Newbie - line boundary when reading text files In reply to
FWIW, recently I had get rid of the \r even after chomp - not sure why...

chomp($Line);
$Line =~ s/\r//g; #strips off hard returns