[32323] in Perl-Users-Digest
Perl-Users Digest, Issue: 3590 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 15 16:09:24 2012
Date: Sun, 15 Jan 2012 13:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 15 Jan 2012 Volume: 11 Number: 3590
Today's topics:
Merging Multiple Array elements <smilesonisamal@gmail.com>
Re: Merging Multiple Array elements <jurgenex@hotmail.com>
Re: Merging Multiple Array elements <tadmc@seesig.invalid>
Re: Merging Multiple Array elements <news@lawshouse.org>
Re: Merging Multiple Array elements <NoSpamPleaseButThisIsValid3@gmx.net>
Re: Merging Multiple Array elements <news@lawshouse.org>
Re: Merging Multiple Array elements <smilesonisamal@gmail.com>
Re: Merging Multiple Array elements <news@lawshouse.org>
Re: Merging Multiple Array elements <smilesonisamal@gmail.com>
Re: Merging Multiple Array elements <NoSpamPleaseButThisIsValid3@gmx.net>
Re: Merging Multiple Array elements <smilesonisamal@gmail.com>
Re: Merging Multiple Array elements <willem@toad.stack.nl>
Re: Merging Multiple Array elements <smilesonisamal@gmail.com>
Re: Merging Multiple Array elements <willem@toad.stack.nl>
Re: Merging Multiple Array elements <jurgenex@hotmail.com>
Re: Merging Multiple Array elements <jurgenex@hotmail.com>
Re: problem reading html stream SOLVED <hjp-usenet2@hjp.at>
Re: problem reading html stream SOLVED <dave@invalid.invalid>
Re: problem reading html stream SOLVED (Jens Thoms Toerring)
Re: problem reading html stream SOLVED <dave@invalid.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 15 Jan 2012 09:20:44 -0800 (PST)
From: Pradeep Patra <smilesonisamal@gmail.com>
Subject: Merging Multiple Array elements
Message-Id: <8444298f-b23e-4613-88c6-b853b97e6b51@m11g2000yqe.googlegroups.com>
Hi all,
I want to merge more than 2 arrays.
For example:
@array1 = (1,2,3);
@array2 = (4,5,6);
@array3 = (7,8,9);
@array4 = (10,11,12);
my @array;
@array = (@array1,@array2,@array3,@array4);
print "Array elements:@array";
It works and displays 1-12. But I need something different because i
dont know the value of "n" beforehand. So I decided to use a for loop.
I tried push but it did not work. I would appreciate any help to merge
multiple array elements preferably not using any library function like
push etc.
for (my $i = 1; $i < 3; $i++)
{
@array =(@array1,@array."$i+1"); ---> To add array1 to array 4 and
return final array
}
Regards
Pradeep
------------------------------
Date: Sun, 15 Jan 2012 09:53:20 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <sb46h71qrmrforhgo5lsp9n2tvtb6nfvgi@4ax.com>
Pradeep Patra <smilesonisamal@gmail.com> wrote:
>Hi all,
> I want to merge more than 2 arrays.
>
>For example:
>
>@array1 = (1,2,3);
>@array2 = (4,5,6);
>@array3 = (7,8,9);
>@array4 = (10,11,12);
>my @array;
>
>
> @array = (@array1,@array2,@array3,@array4);
>
>print "Array elements:@array";
>
>It works and displays 1-12. But I need something different because i
>dont know the value of "n" beforehand.
Yes, you do know. Or how did you declare and define all those arrays
without knowing how many there are?
However, that is not the real the issue here. Whenever you find yourself
numbering your variables like above and on top of it you don't even know
how many variables you need, then you should seriously look into a
different data structure. In this case use an array, Luke! Or what do
you think those numbers are for?
>So I decided to use a for loop.
And then the for loop will work perfectly fine.
jue
------------------------------
Date: Sun, 15 Jan 2012 11:54:13 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Merging Multiple Array elements
Message-Id: <slrnjh6533.jj9.tadmc@tadbox.sbcglobal.net>
Pradeep Patra <smilesonisamal@gmail.com> wrote:
> multiple array elements preferably not using any library function like
> push etc.
push() is not a library function.
push() is a built-in.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Sun, 15 Jan 2012 18:10:20 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Merging Multiple Array elements
Message-Id: <RvKdnVmOPcwRi47SnZ2dnUVZ8oWdnZ2d@giganews.com>
On 15/01/12 17:20, Pradeep Patra wrote:
> Hi all,
> I want to merge more than 2 arrays.
>
> For example:
>
> @array1 = (1,2,3);
> @array2 = (4,5,6);
> @array3 = (7,8,9);
> @array4 = (10,11,12);
> my @array;
>
> for (my $i = 1; $i< 3; $i++)
> {
> @array =(@array1,@array."$i+1"); ---> To add array1 to array 4 and
> return final array
> }
The code you posted doesn't even come near to doing what you want: had
you actually tried it?
#!/usr/bin/perl
use strict;
use warnings;
my @array1 = (1,2,3);
my @array2 = (4,5,6);
my @array3 = (7,8,9);
my @array4 = (10,11,12);
my @array;
for (my $i = 1; $i < 3; $i++)
{
@array =(@array1,@array."$i+1");
}
print "result is: ", (join ',',@array), "\n";
./tryout
result is: 1,2,3,42+1
While you call your arrays by fixed names (array1, array2, arrayfoo)
you're not going to be able to do this easily. I suggest you use an
array of arrays, over which you can then iterate, merging the contents
of each sub-array as you go. This code does what you want but I make no
assertions as to its elegance.
#!/usr/bin/perl
use strict;
use warnings;
my @arrays = ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
my @merged;
for ( @arrays ) {
@merged = ( @merged, @$_ );
}
print "Result is ", (join ',', @merged), "\n";
./tryout
Result is 1,2,3,4,5,6,7,8,9,10,11,12
--
Henry Law Manchester, England
------------------------------
Date: Sun, 15 Jan 2012 19:48:31 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Merging Multiple Array elements
Message-Id: <4f131f7f$0$6561$9b4e6d93@newsspool4.arcor-online.net>
Am 15.01.2012 18:20, schrieb Pradeep Patra:
> It works and displays 1-12. But I need something different because i
> dont know the value of "n" beforehand. So I decided to use a for loop.
> I tried push but it did not work. I would appreciate any help to merge
> multiple array elements preferably not using any library function like
> push etc.
>
>
> for (my $i = 1; $i < 3; $i++)
> {
> @array =(@array1,@array."$i+1"); ---> To add array1 to array 4 and
> return final array
> }
This looks like you want to construct the name of a variable in your
program which is usually a bad idea: read perldoc -q "variable name"
The misconception here is that you have 4 separate arrays which belong
together in some way. So you could put (references to) all the arrays
into another array (or into a hash).
So:
my @x = ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
my @merged = map @$_, @x;
- Wolf
------------------------------
Date: Sun, 15 Jan 2012 18:56:11 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Merging Multiple Array elements
Message-Id: <loOdndCOQM7WvI7SnZ2dnUVZ8j6dnZ2d@giganews.com>
On 15/01/12 18:48, Wolf Behrenhoff wrote:
> my @merged = map @$_, @x;
... that's the kind of proper Perlish construction that I knew was there
somewhere!
--
Henry Law Manchester, England
------------------------------
Date: Sun, 15 Jan 2012 10:58:19 -0800 (PST)
From: Pradeep Patra <smilesonisamal@gmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <36c24676-0d35-4d9a-9079-03dd0fe5c110@f1g2000yqi.googlegroups.com>
On Jan 15, 11:48=A0pm, Wolf Behrenhoff
<NoSpamPleaseButThisIsVal...@gmx.net> wrote:
> Am 15.01.2012 18:20, schrieb Pradeep Patra:
>
> > It works and displays 1-12. But I need something different because i
> > dont know the value of "n" beforehand. So I decided to use a for loop.
> > I tried push but it did not work. I would appreciate any help to merge
> > multiple array elements preferably not using any library function like
> > push etc.
>
> > for (my $i =3D 1; $i < 3; $i++)
> > {
> > =A0 @array =3D(@array1,@array."$i+1"); =A0---> To add array1 to array 4=
and
> > return final array
> > }
>
> This looks like you want to construct the name of a variable in your
> program which is usually a bad idea: read perldoc -q "variable name"
>
> The misconception here is that you have 4 separate arrays which belong
> together in some way. So you could put (references to) all the arrays
> into another array (or into a hash).
>
> So:
> my @x =3D ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
> my @merged =3D map @$_, @x;
>
> - Wolf
Thanks all for the replies.
My 4 separate arrays are returned from a method iterating as follows:
@array1=3D fun(i=3D1);
@array2=3D fun(i=3D2); and so on. I cannot change the func. So I need to
sum array elements merging the 4 arrays.
Any ideas/Suggestions? Sample code will help.
------------------------------
Date: Sun, 15 Jan 2012 19:07:51 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: Merging Multiple Array elements
Message-Id: <k5Gdnewdq96auY7SnZ2dnUVZ7sadnZ2d@giganews.com>
On 15/01/12 18:58, Pradeep Patra wrote:
>
> Any ideas/Suggestions? Sample code will help.
>
No, _you_ write the code this time. Your turn.
--
Henry Law Manchester, England
------------------------------
Date: Sun, 15 Jan 2012 11:17:29 -0800 (PST)
From: Pradeep Patra <smilesonisamal@gmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <f122f006-fe4e-4e98-b3ab-75c18c436388@e8g2000yqd.googlegroups.com>
Thanks Henry.I am trying to write code as per your suggestion. But how
will I get the below(my @arrays) initially from the func(). If you
could give some clue i will try to write code.
my @arrays =3D ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
On Jan 16, 12:07=A0am, Henry Law <n...@lawshouse.org> wrote:
> On 15/01/12 18:58, Pradeep Patra wrote:
>
>
>
> > Any ideas/Suggestions? Sample code will help.
>
> No, _you_ write the code this time. =A0Your turn.
>
> --
>
> Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England
------------------------------
Date: Sun, 15 Jan 2012 20:32:52 +0100
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: Merging Multiple Array elements
Message-Id: <4f1329e5$0$6555$9b4e6d93@newsspool4.arcor-online.net>
Am 15.01.2012 20:17, schrieb Pradeep Patra:
> Thanks Henry.I am trying to write code as per your suggestion. But how
> will I get the below(my @arrays) initially from the func(). If you
> could give some clue i will try to write code.
>
> my @arrays = ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
Maybe you could read
perldoc perllol
section "Growing Your Own"
- Wolf
------------------------------
Date: Sun, 15 Jan 2012 10:47:57 -0800 (PST)
From: Pradeep Patra <smilesonisamal@gmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <23f8fe01-f5e6-4827-9ab1-823a9b28ec19@k8g2000yqk.googlegroups.com>
The reason I need this requirement because I have something as
follows:
@array1 =3D returned by func1(i=3D0); [NOTE: this is just for illustration
not actual code]
@array2 =3D returned by func1(i=3D1);
I cannot change the func1(i); So I have to summing all the sub arrays
returned by func1(i) itself.
Any suggestions how to go about this?
On Jan 15, 11:10=A0pm, Henry Law <n...@lawshouse.org> wrote:
> On 15/01/12 17:20, Pradeep Patra wrote:
>
>
>
> > Hi all,
> > =A0 =A0 I want to merge more than 2 arrays.
>
> > For example:
>
> > @array1 =3D (1,2,3);
> > @array2 =3D (4,5,6);
> > @array3 =3D (7,8,9);
> > @array4 =3D (10,11,12);
> > my @array;
>
> > for (my $i =3D 1; $i< =A03; $i++)
> > {
> > =A0 =A0@array =3D(@array1,@array."$i+1"); =A0---> =A0To add array1 to a=
rray 4 and
> > return final array
> > }
>
> The code you posted doesn't even come near to doing what you want: had
> you actually tried it?
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my @array1 =3D (1,2,3);
> my @array2 =3D (4,5,6);
> my @array3 =3D (7,8,9);
> my @array4 =3D (10,11,12);
> my @array;
>
> for (my $i =3D 1; $i < 3; $i++)
> {
> =A0 =A0@array =3D(@array1,@array."$i+1");
>
> }
>
> print "result is: ", (join ',',@array), "\n";
>
> ./tryout
> result is: 1,2,3,42+1
>
> While you call your arrays by fixed names (array1, array2, arrayfoo)
> you're not going to be able to do this easily. =A0I suggest you use an
> array of arrays, over which you can then iterate, merging the contents
> of each sub-array as you go. =A0This code does what you want but I make n=
o
> assertions as to its elegance.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my @arrays =3D ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
> my @merged;
> for ( @arrays ) {
> =A0 =A0@merged =3D ( @merged, @$_ );}
>
> print "Result is ", (join ',', @merged), "\n";
>
> ./tryout
> Result is 1,2,3,4,5,6,7,8,9,10,11,12
>
> --
>
> Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England
------------------------------
Date: Sun, 15 Jan 2012 19:49:08 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: Merging Multiple Array elements
Message-Id: <slrnjh6bdk.27d2.willem@toad.stack.nl>
Pradeep Patra wrote:
) Thanks all for the replies.
) My 4 separate arrays are returned from a method iterating as follows:
)
) @array1= fun(i=1);
) @array2= fun(i=2); and so on. I cannot change the func. So I need to
) sum array elements merging the 4 arrays.
)
) Any ideas/Suggestions? Sample code will help.
How about you give a clearer description of what exactly this func that you
cannot change does? What you wrote above is really awful. That either
means that that function is really awful, or that you dodn't describe it
properly.
Are you calling the method multiple times, once for each array?
Or does the function 'return' multiple arrays? (If so, how?)
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Sun, 15 Jan 2012 11:49:42 -0800 (PST)
From: Pradeep Patra <smilesonisamal@gmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <376a4c19-f8c6-4410-a973-c56be6ba9cbc@k28g2000yqc.googlegroups.com>
On Jan 16, 12:32=A0am, Wolf Behrenhoff
<NoSpamPleaseButThisIsVal...@gmx.net> wrote:
> Am 15.01.2012 20:17, schrieb Pradeep Patra:
>
> > Thanks Henry.I am trying to write code as per your suggestion. But how
> > will I get the below(my @arrays) initially from the func(). If you
> > could give some clue i will try to write code.
>
> > my @arrays =3D ( [1,2,3], [4,5,6], [7,8,9], [10,11,12] );
>
> Maybe you could read
> perldoc perllol
> section "Growing Your Own"
>
> - Wolf
Thanks Wolf... Its awesome... Let me try if that works.
------------------------------
Date: Sun, 15 Jan 2012 19:52:01 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: Merging Multiple Array elements
Message-Id: <slrnjh6bj1.27d2.willem@toad.stack.nl>
Pradeep Patra wrote:
)
) The reason I need this requirement because I have something as
) follows:
)
) @array1 = returned by func1(i=0); [NOTE: this is just for illustration
) not actual code]
) @array2 = returned by func1(i=1);
)
) I cannot change the func1(i); So I have to summing all the sub arrays
) returned by func1(i) itself.
)
) Any suggestions how to go about this?
Yes. Append the result of each function call directly to the whole array:
my @array;
for ( ... ) {
push @array, func1( ... );
}
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Sun, 15 Jan 2012 12:45:54 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <vge6h7ptkki97880p07qraid4rbkqvdvof@4ax.com>
Pradeep Patra <smilesonisamal@gmail.com> wrote:
>
>The reason I need this requirement because I have something as
>follows:
>
>@array1 = returned by func1(i=0); [NOTE: this is just for illustration
>not actual code]
>@array2 = returned by func1(i=1);
>
>I cannot change the func1(i); So I have to summing all the sub arrays
>returned by func1(i) itself.
>
>Any suggestions how to go about this?
Yes, several:
- If you really want to collect the individual return results before
summing them up then use an array of (references to) arrays as explained
before.
- with each iteration (i=0, i=1, ...) don't store the return result, but
add it to your grand total right away
- and last but not least: please post actual Perl code, not some
pseudo-code
jue
------------------------------
Date: Sun, 15 Jan 2012 12:56:47 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Merging Multiple Array elements
Message-Id: <fqe6h7d67390ct40st1lhp3k0qdbkb4jfi@4ax.com>
Pradeep Patra <smilesonisamal@gmail.com> wrote:
>Thanks all for the replies.
>My 4 separate arrays are returned from a method iterating as follows:
>
>@array1= fun(i=1);
>@array2= fun(i=2); and so on. I cannot change the func. So I need to
>sum array elements merging the 4 arrays.
Somehow you are not telling the true story. Do you have 4 distinct
function calls and 4 distinct arrays? Or don't you know how many
function calls there are therefore how many arrays there are?
It is either the one or the other, it can't be both.
If it is the second, then don't use mockup code for the first case in
your examples.
If it is the first case then you also do know the names of the arrays
and you can use your own old awkward method.
If it is the second case then either add the return array of each call
of fun immediately to the grand total as several people already sugested
in this thread or create an AoA to store the results from all fun calls
and then loop through that array at the end to sum up the results.
>Any ideas/Suggestions?
You got pleanty of those already.
>Sample code will help.
Tit for tat! You provide good sample code instead of mockup pseudo-code
and we may be able to help with more than general information.
jue
------------------------------
Date: Sun, 15 Jan 2012 16:09:39 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: problem reading html stream SOLVED
Message-Id: <slrnjh5r1j.90i.hjp-usenet2@hrunkner.hjp.at>
On 2012-01-15 14:01, Dave Saville <dave@invalid.invalid> wrote:
> On Sun, 15 Jan 2012 12:16:08 UTC, "Peter J. Holzer"
><hjp-usenet2@hjp.at> wrote:
>
><snip>
>
>> Do you use HTTP to get the data or some custom protocol?
>
> HTTP - But it would appear to be a problem with perl sockets - Someone
> suggested LWP::Simple but that was no good as I needed to process the
> files which are large and the server does not have much RAM. So I used
> LWP::UserAgent to dump straight to a file which I can then post
> process and it works fine. Odd as I would have thought that LWP* would
> use sockets at the bottom layer. Ho hum.
It does. You probably made an error in writing your own HTTP
implementation.
hp
--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Bill Code on asrg@irtf.org
------------------------------
Date: Sun, 15 Jan 2012 16:19:10 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: problem reading html stream SOLVED
Message-Id: <fV45K0OBJxbE-pn2-WbIcjRiw6NIH@localhost>
On Sun, 15 Jan 2012 15:09:39 UTC, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:
> On 2012-01-15 14:01, Dave Saville <dave@invalid.invalid> wrote:
> > On Sun, 15 Jan 2012 12:16:08 UTC, "Peter J. Holzer"
> ><hjp-usenet2@hjp.at> wrote:
> >
> ><snip>
> >
> >> Do you use HTTP to get the data or some custom protocol?
> >
> > HTTP - But it would appear to be a problem with perl sockets - Someone
> > suggested LWP::Simple but that was no good as I needed to process the
> > files which are large and the server does not have much RAM. So I used
> > LWP::UserAgent to dump straight to a file which I can then post
> > process and it works fine. Odd as I would have thought that LWP* would
> > use sockets at the bottom layer. Ho hum.
>
> It does. You probably made an error in writing your own HTTP
> implementation.
That I am willing to believe. Perhaps you would be so kind as to point
out the error in my code?
#!/usr/local/bin/perl
use warnings;
use strict;
use Socket;
open RAW, ">RAW" or die $!;
my $iaddr = inet_aton('xmltv.radiotimes.com') or die $!;
socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp')) or die $!;
my $paddr = sockaddr_in(80, $iaddr);
connect(SOCK, $paddr) or die $!;
send SOCK, "GET /xmltv/94.dat HTTP\/1.1\r\n", 0;
send SOCK, "Host: xmltv.radiotimes.com\r\n\r\n", 0;
while ( <SOCK> )
{
print RAW $_;
}
close SOCK;
close RAW;
This hangs for minutes and then completes. I have run the above on two
different operating systems and they both do exactly the same.
--
Regards
Dave Saville
------------------------------
Date: 15 Jan 2012 17:32:34 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: problem reading html stream SOLVED
Message-Id: <9nggtiFj33U1@mid.uni-berlin.de>
Dave Saville <dave@invalid.invalid> wrote:
> On Sun, 15 Jan 2012 15:09:39 UTC, "Peter J. Holzer"
> <hjp-usenet2@hjp.at> wrote:
> > On 2012-01-15 14:01, Dave Saville <dave@invalid.invalid> wrote:
> > > On Sun, 15 Jan 2012 12:16:08 UTC, "Peter J. Holzer"
> > ><hjp-usenet2@hjp.at> wrote:
> > >
> > ><snip>
> > >
> > >> Do you use HTTP to get the data or some custom protocol?
> > >
> > > HTTP - But it would appear to be a problem with perl sockets - Someone
> > > suggested LWP::Simple but that was no good as I needed to process the
> > > files which are large and the server does not have much RAM. So I used
> > > LWP::UserAgent to dump straight to a file which I can then post
> > > process and it works fine. Odd as I would have thought that LWP* would
> > > use sockets at the bottom layer. Ho hum.
> >
> > It does. You probably made an error in writing your own HTTP
> > implementation.
> That I am willing to believe. Perhaps you would be so kind as to point
> out the error in my code?
> #!/usr/local/bin/perl
> use warnings;
> use strict;
> use Socket;
> open RAW, ">RAW" or die $!;
> my $iaddr = inet_aton('xmltv.radiotimes.com') or die $!;
> socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp')) or die $!;
> my $paddr = sockaddr_in(80, $iaddr);
> connect(SOCK, $paddr) or die $!;
> send SOCK, "GET /xmltv/94.dat HTTP\/1.1\r\n", 0;
> send SOCK, "Host: xmltv.radiotimes.com\r\n\r\n", 0;
> while ( <SOCK> )
> {
> print RAW $_;
> }
> close SOCK;
> close RAW;
>
> This hangs for minutes and then completes. I have run the above on two
> different operating systems and they both do exactly the same.
This 180 kB look suspicously like the length of the file the
server sends. And you're using HTTP 1.1, which allows the sender
to keep the connection open after it has send a file, waiting
for the next request unless told otherwise ("persistent connec-
tion" is actually the defalt with HTTP 1.1). So my guess is that
the server sends the complete file just fine and waits for the
the next request. But since your loop only ends when the connec-
tion is closed by the other side it hangs until the server gets
bored and closes the connection after a few minutes. So either
use HTTP 1.0 or send an additional HTTP header with (IIRC)
"Connection: close\r\n". See also e.g.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Sun, 15 Jan 2012 18:43:40 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: problem reading html stream SOLVED
Message-Id: <fV45K0OBJxbE-pn2-ftxhhpWrf3fL@localhost>
On Sun, 15 Jan 2012 17:32:34 UTC, jt@toerring.de (Jens Thoms Toerring)
wrote:
> This 180 kB look suspicously like the length of the file the
> server sends. And you're using HTTP 1.1, which allows the sender
> to keep the connection open after it has send a file, waiting
> for the next request unless told otherwise ("persistent connec-
> tion" is actually the defalt with HTTP 1.1). So my guess is that
> the server sends the complete file just fine and waits for the
> the next request. But since your loop only ends when the connec-
> tion is closed by the other side it hangs until the server gets
> bored and closes the connection after a few minutes. So either
> use HTTP 1.0 or send an additional HTTP header with (IIRC)
> "Connection: close\r\n". See also e.g.
>
Thank you so much Jens, reverting to 1.0 or adding the header both
work.
--
Regards
Dave Saville
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3590
***************************************