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: Beginner:
endless loop


New User

Oct 24, 2012, 10:37 AM

Post #1 of 5 (2008 views)
endless loop Can't Post

I want to extract the content except http header from tcp flow files
the content is like the following
the http header ends when two ^M are met

HTTP/1.1 200 OK^M 
Last-Modified: Sat, 20 Mar 2010 09:43:12 GMT^M
Content-Type: video/x-flv^M
Date: Wed, 24 Oct 2012 14:34:13 GMT^M
Expires: Wed, 24 Oct 2012 14:34:13 GMT^M
Cache-Control: private, max-age=22124^M
Accept-Ranges: bytes^M
Content-Length: 29833281^M
Connection: close^M
X-Content-Type-Options: nosniff^M
Server: gvs 1.0^M
FLV^A^E^@^@^@ ^@^@^@^@^R^@^CK^@^@^@^@^@^@^@^B^@
=p£×^@ starttime^@^@^@^@^@^@^@^@^@^@^Mtotalduration^@@i<97>

my code for extraction is as follows,
and I run : < tcp.flow
but it seems the loop is endless,
what is wrong with the codes? thanks!

if ( $start eq 0 && $_ =~ /^\r\n/) { $start = 1; }
elsif ( $start eq 1 ) { $data = $data . $_; }
open(FH, ">sample.flv");
print FH $data;

(This post was edited by esolve on Oct 24, 2012, 10:38 AM)

Veteran / Moderator

Oct 24, 2012, 2:14 PM

Post #2 of 5 (1997 views)
Re: [esolve] endless loop [In reply to] Can't Post


$start eq 0

This should probably be:

$start == 0

Otherwise, from what you describe, why detecting a ^M at the beginning of the line should not be sufficient?

Something like this might do the job:

while (<STDIN>) { 
next unless /^\r\n/;
print FH $_;
print FH $_ while (<STDIN>);
close ...


Oct 25, 2012, 5:00 AM

Post #3 of 5 (1988 views)
Re: [Laurent_R] endless loop [In reply to] Can't Post

While doing a numeric equality test is certainly more logical, a textual comparision would do as well in this case, so this can't be the problem.

Assuming that the posted program is complete, the only way it could go into a endless loop would be if STDIN is feeded endlessly (via a pipe, for example). This is unlikly of course. Therefore I don't think we have a looping problem here.

Maybe the input redirection is not set up correctly, and the program is just blocking at <STDIN>.

It would be interesting to know what got printed on FH ...

Veteran / Moderator

Oct 25, 2012, 3:27 PM

Post #4 of 5 (1980 views)
Re: [rovf] endless loop [In reply to] Can't Post

I certainly agree with Rovf that a program like this one should not go into an endless loop, at least not if it is given a (presumably non infinite) file as input.

But the use of <STDIN> leads me to a question: how do you launch your program (i.e. can you give the exact command line that you use to run your program?).

In other words, I suspect that the program could simply be hanging because it is waiting for user input, if given no file as a parameter to work with.

Veteran / Moderator

Oct 25, 2012, 4:35 PM

Post #5 of 5 (1976 views)
Re: [Laurent_R] endless loop [In reply to] Can't Post

FYI, the OP cross posted this Q on stackoverflow and like here, hasn't responded to anyone's response to this question.

(This post was edited by FishMonger on Oct 25, 2012, 4:35 PM)


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

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