$line = <FH> returns incomplete lines

T

Tad McClellan

I personally find Tad Mclelan the most insulting individual


You reap what you sow.


[
You should post comments as followups to the post you are
commenting on.

If Tad said something you want to say something about, say something
about it in a followup to where Tad said it, and quote what was
said.
]


Everybody else posts by trimming and quoting. Have you looked at
several followups and noticed that they are all in that style?

I'd seen
here.


Ahhh, shucks.

You mean, I'm the meanest in all of your vast experience here?

How many years have you been around here anyway?

You sure seem to know a lot about the newsgroup...

He is totally out of context,


I only have 10 years experience in the context of this newsgroup,
I bow to your obvious superiority in these matters.

I am wondering what Google is
going to do


Pardon me, but your ignorance is showing (yet again).

Consider talking only about things that you know something about.

Obvious lurkers


That is an oxymoron.

Lurkers are not obvious by definition.

If they were obvious, they would not be "lurking".

Keep this rude behaviour up and


Sorry Mom.

this group will dissolve
I assure you.


It has been here for over 10 years so far (which is before
Google was even started BTW).

How many years have you been observing here again?
 
J

Jeff Stampes

I personally find Tad Mclelan the most insulting individual I'd seen
here.

Aw shucks...Tad doesn't even *try*. It's unfortunate you consider
someone who tries to help you avoid looking like a complete idiot to be
"insulting". Frankly, Tad's helped you way too much already, and his
help isn't....um...helping.
He is totally out of context,
rarely can see the forest for the trees.

*Gasp* a perl programmer on a perl newsgroup! Tad, you out-of-context
guy. Go join the cops at the local police station, the drunk at the
local bar, and the other out-of-context people in your town.
I am wondering what Google is
going to do when they get
another complaint about this group and some of these individuals
professing to be ... uh, I don't
know... have the power of GOD to be so insulting and personally
demeaning on here.

I'm not sure what [G]eorge [O]rwell's [D]aughter has to do with any of
this, but I'm sure she's pleased to be held in high esteem. I'm not so
sure what Google has to do with it either. But if you want to talk
"insulting", can you imagine this bonehead who barged in here recently,
demanding help, resisting constructive criticism, insulting the
long-time contributors, and being a general jerk?
Obvious lurkers who have power trips. Keep this rude behaviour up and
this group will dissolve
I assure you.

We'll take the risk.
Regards,
RFC

Same to you Robin.

Sorry all, I had to feed the Troll just once.
 
R

robic0

This folks, I'm afraid, is what your in for if you post a simple perl
question here.
Twisted people who parse every line and word you write must have
psychological
problems. Obviously they can't write algorythms, and are the rudest
people on usenet.
Folks welcome to nazi *lang* land which mostly originates from 3rd
world countries
by people who steal American jobs. I will cut and past my concerns to
Google as well
as to my congressman and President Bush as I really do believe you
undermime
American culture and should be banned from the US. I know people in
congress and I
will cc them too. I think that you foreigners should not be allowed to
belittle Americans
and behave so rudely. I really wish this server would be dissolved and
re-built without
the extremely rude people involved with its maintanence.

RFC
 
S

Sherm Pendley

I am wondering what Google is going to do when they get
another complaint about this group

I know I shouldn't feed the trolls, but I can't help asking... What exactly
do you imagine Google *can* do? They don't own this group, they didn't
create it, and they don't manage it.
Obvious lurkers who have power trips. Keep this rude behaviour up and
this group will dissolve

You have no idea how usenet actually works, do you?

sherm--
 
A

A. Sinan Unur

Obviously they can't write algorythms, and are the rudest
people on usenet.

Since you seem to place a high value on being able to write algorithms,
you might be interested in learning about the origin of the word:

http://en.wikipedia.org/wiki/Algorithm#History
Folks welcome to nazi *lang* land
http://www.faqs.org/faqs/usenet/legends/godwin/

which mostly originates from 3rd world countries
:)

by people who steal American jobs. I will cut and past my concerns to
Google as well as to my congressman and President Bush as I really do
believe you undermime

How do you undermime something?
American culture and should be banned from the US. I know people in
congress and I will cc them too. I think that you foreigners should
not be allowed to belittle Americans and behave so rudely.

No one belittled Americans. We tried to show an ignorant fool the error
of his ways, but he was not listening. The fact that he is from the
U.S.A. is of no relevance to the issues that were brought up.
I really wish this server would be dissolved and re-built without
the extremely rude people involved with its maintanence.

You really do not understand how the newsgroups work, do you?

Incidentally, Adelphia High Speed Internet and Google Groups will be
more concerned about your abusive behavior than anything else that was
said in these threads.

Sinan

PS: I know, I broke my promise.
 
C

Chris Barts

What does GPL, character class, Tail or personal insults have to do
with anything
this gentleman posted a question about?

What does this rant have to do with my comment, to which it is
apparently a follow-up?
Obvious lurkers who have power trips.

As opposed to moronic whackadoos who have power trips?
Keep this rude behaviour up and this group will dissolve
I assure you.

Imminent Death of The Net Predicted!

Begone, loser. You are but a flyspeck on the long history of Usenet.

:plonk:
 
T

Tad McClellan

Folks welcome to nazi *lang* land


Godwin has finally signalled an end to this thread. It's about time.

which mostly originates from 3rd
world countries
by people who steal American jobs.


Sounds like sour grapes to me.

Did your job get outsourced or something?

I will cut and past my concerns to
Google as well


Google has no responsibility for Usenet.

as to my congressman and President Bush as I really do believe you
undermime
American culture and should be banned from the US. I know people in
congress and I
will cc them too.


Golly, we won't be able to sleep at night anymore for fear
of your formidable power being directed against us.



I have not seen much evidence of that thus far.

that you foreigners should not be allowed to
belittle Americans


Nearly all Americans are foreigners, unless you are
defending Native Americans.

I really wish this server


There is no "this" server.

This newsgroup is on *thousands* of servers around the world.

would be dissolved and
re-built without
the extremely rude people involved with its maintanence.


Nobody who has posted here is involved with its maintanence (sic).

You confuse "participation" with "maintenance".
 
R

robic0

Since you seem to place a high value on being able to write algorithms,
you might be interested in learning about the origin of the word:

Oh, haven't read any of your crap, but u already knew that b4
u posted it because it wasen't intended to educate me in the
professional sense, it was meant to degrade and humiliate.
Well obviously u don't know the origin of you. You came
from a woman I fucked the shit out of 20 years ago !!!
HEHE, take it to the bank!
You get on your knees and under*mine* their assholes.... jeesh
No one belittled Americans. We tried to show an ignorant fool the error
of his ways, but he was not listening. The fact that he is from the
U.S.A. is of no relevance to the issues that were brought up.
So all us U.S.A. assholes are an ignorant lot of jackoffs... huh?
You really do not understand how the newsgroups work, do you?
Yes, you use news papers to wipe your asshole when you shit
because no one would give you a job... fuuu christ sakes!!!
Incidentally, Adelphia High Speed Internet and Google Groups will be
more concerned about your abusive behavior than anything else that was
said in these threads.
Again, with this statement your neck should be alleviated of its
limited weight. Should you feel that Google or Adelphia allow this
abuse upon yourself you should not hesitate to complain to the
World Bank. . . . what an asshole!
 
R

robic0

What does this rant have to do with my comment, to which it is
apparently a follow-up?


As opposed to moronic whackadoos who have power trips?


Imminent Death of The Net Predicted!

Begone, loser. You are but a flyspeck on the long history of Usenet.

:plonk:

Hey thanks Chris.
I don't know of the GPL cut/paste thing you referr too (but i'm gonna
find out).

All I know is that some really strange people here and have done
nothing but attacked me what ever I post (right or wrong).
Could be I (and like any other human being) make mistakes.
Jeez, whats the test for that? Don't everybody take a shit in the
morning/night and don't it stink?

Well, after your post, I offered the real solution to OP's problem.
It didn't relate to GPL. Here it is:

Thanks!
-rfc


=============================
$line = '';
while(1) {
while ( ($line .= <MYLOG> ) )
{
if ($line =~ /[\n]+/) {
print ("GOT THIS: ",$line);
$line = '';
}
}
seek (MYLOG,0, 1);
sleep (1);
}

Quote from somewhere: "each call reads and returns the next line,
until
end-of-file is reached".
'seek (MYLOG,0, 1)' is resetting the eof condition on the FH which you
get everytime.
It just so happends there was no "\n" in the last chars flushed from
the buffer but it does go to an eof.
<MYLOG> will return on $/ or eof otherwise it would not return at the
end.
 
A

Anno Siegel

Tad McClellan said:
[...]

Your code that I quoted is equivalent to:

if ($line =~ /\n+/) {

The 2 underlined characters served no purpose, so I'm wondering
why you included them. Maybe you (mis)think that they _do_ serve
some purpose, in which case you will learn something.

The '+' doesn't make sense either, unless someone messed with $/.
This guy's code is sloppy and imprecise, matching his English.

Anno
 
B

Brian McCauley

$line = '';
while(1) {
while ( ($line .= <MYLOG> ) )
{
if ($line =~ /[\n]+/) {
print ("GOT THIS: ",$line);
$line = '';
}
}
seek (MYLOG,0, 1);
sleep (1);
}

That code will hang busy if a partial line is read.

It is worse than the OP's solution.
 
A

axel

Brian McCauley said:
$line = '';
while(1) {
while ( ($line .= <MYLOG> ) )
{
if ($line =~ /[\n]+/) {
print ("GOT THIS: ",$line);
$line = '';
}
}
seek (MYLOG,0, 1);
sleep (1);
}
That code will hang busy if a partial line is read.

The following seems to work.

#!/usr/bin/perl

open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
$|++;

print "GOT THIS: ";
while ( 1 ) {
while (<MYLOG>) {
print;
print ("GOT THIS: ") if /\n/;
}
sleep (1);
}
__END__


Axel
 
B

Brian McCauley

The following seems to work.

#!/usr/bin/perl

open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
$|++;

print "GOT THIS: ";
while ( 1 ) {
while (<MYLOG>) {
print;
print ("GOT THIS: ") if /\n/;
}
sleep (1);
}
__END__

That is missing the seek() that is needed to reset the EOF flag on MYLOG.

If you insert the seek() it will work, sort of, but only because you are
simply printing the output. If you wanted to do someting else - like
selectively print lines by pattern match (as per OP) then it wouldn't work.
 
A

axel

That is missing the seek() that is needed to reset the EOF flag on MYLOG.
If you insert the seek() it will work, sort of, but only because you are
simply printing the output.

It works without the seek. Each time some characters are picked up
they are printed. A new 'GOT THIS' message is only printed once a
new line is seen in the input (actually it should not be printed
until at least something has actually been received).
If you wanted to do someting else - like
selectively print lines by pattern match (as per OP) then it wouldn't work.

I find that it does... a slightly altered version with a couple of
pattern matching examples...

1) An specific error message is printed once a full line (i.e.
terminated by \n) is found to contain 'error'.
2) A critical message is printed immediately the incoming line is
found to contain 'critical' - there is no wait for the end of
line (the message is repeated as the line is built up until
terminated by \n).

#!/usr/bin/perl

use warnings;
use strict;

open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
$|++;

my $line;
my $prefix = "GOT THIS: ";
print "Listening\n";
while ( 1 ) {
while (<MYLOG>) {
print $prefix, $_;
$prefix = '';
$line .= $_;

print "\nCritical *************\n" if $line =~ 'critical';
print "Error =============\n" if /\n/ && $line =~ 'error';

if (/\n/) {
$prefix = 'GOT THIS: ';
$line = '';
} else {
$prefix = '';
}
}
sleep (1);
}
__END__


Axel
 
B

Brian McCauley

It works without the seek.

I think you were right the first time. It _seems_ to work. My
understanding is that it is undefined if Perl's readline() will or will
not reset the EOF condition when more data appears in a file.

Right now I can't find a platform on which your code fails but so long
as it is officially undefined if it will work without the seek() I'd be
inclined not to omit it.
Each time some characters are picked up they are printed.

Yes, that was my point. You rely on the behaviour of the output device
to give the false impression that split lines are being reassembled.
(Note reassembly of the split lines is the subject of this thread).
I find that it does... a slightly altered version
$line .= $_;
if (/\n/) {
$line = '';
}

Well, yes, of course, if you add the code that reassembles split lines
then of course your solution is the same as all the others offered in
this thread. (Remember, it is the reassembly of the split lines that is
the subject of this thread).
 
A

axel

Brian McCauley said:
(e-mail address removed) wrote:
I think you were right the first time. It _seems_ to work. My
understanding is that it is undefined if Perl's readline() will or will
not reset the EOF condition when more data appears in a file.
Right now I can't find a platform on which your code fails but so long
as it is officially undefined if it will work without the seek() I'd be
inclined not to omit it.

Point taken.
Yes, that was my point. You rely on the behaviour of the output device
to give the false impression that split lines are being reassembled.
(Note reassembly of the split lines is the subject of this thread).
Well, yes, of course, if you add the code that reassembles split lines
then of course your solution is the same as all the others offered in
this thread. (Remember, it is the reassembly of the split lines that is
the subject of this thread).

I seem to have gone off at a tangent... puzzling as to where the
problem lay and why seek was considered necessary.

Axel
 
R

robic0

$line = '';
while(1) {
while ( ($line .= <MYLOG> ) )
{
if ($line =~ /[\n]+/) {
print ("GOT THIS: ",$line);
$line = '';
}
}
seek (MYLOG,0, 1);
sleep (1);
}

That code will hang busy if a partial line is read.
The "while( wait_for_level2_io )" condition is the "<>" mode default.
Perl submits a default Level 2 io read request, then waits for the io
device to deliver a complete entry, which could include more than
one "\n" depending on if the callers process was slowed down.
Perl would return on the last EOL char it gets (there could be
several) OR the EOF condition. Thats why /\n+/ is relavent.
Printing a string with several \n I guess you wouldn't be able
to tell. Might have to run an assembly program that pumps
multiple \n at high priority to tell for sure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top