What is wrong in the following script

This is a discussion on What is wrong in the following script within the Perl forums in Programming Languages category; problem: excecutes only DATA string but nor IO1 and IO0. script: #!\usr\bin\perl -w use IO::Socket; use diagnostics; use strict; use POSIX qw(strftime); my $remote_host = ""; my $remote_port = ""; my ($handle, $send_data,$send_i1,$send_i0,$count); $count=0; $handle= IO::Socket::INET->new( PeerAddr => $remote_host, PeerPort => $remote_port, Proto => "tcp", Type => SOCK_STREAM ) || die "Couldn't connect to $remote_host:$remote_port: \n"; print STDERR "[Connected to $remote_host:$remote_port]\n"; DATA: while(<$handle=1>) { for($count=0;$count<180;$count++) { $send_data = self define string; $handle-> send($send_data); $count=0; sleep(180); } } IO1: while(<$handle=1>) { for($count=0;$count<240;$count++) { $send_i1 = self defined string $handle-> send($send_i1); $count=0; sleep(240); } } IO0: while(<$handle=1>) { for($count=0;$count<360;$count++) { $send_i0 = ...

Go Back   Application Development Forum > Programming Languages > Perl

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-08-2008, 08:00 AM
Arun
Guest
 
Default What is wrong in the following script

problem: excecutes only DATA string but nor IO1 and IO0.

script:

#!\usr\bin\perl -w

use IO::Socket;
use diagnostics;
use strict;
use POSIX qw(strftime);

my $remote_host = "";
my $remote_port = "";
my ($handle, $send_data,$send_i1,$send_i0,$count);

$count=0;
$handle= IO::Socket::INET->new( PeerAddr => $remote_host,
PeerPort => $remote_port,
Proto => "tcp",
Type => SOCK_STREAM
)
|| die "Couldn't connect to $remote_host:$remote_port: \n";

print STDERR "[Connected to $remote_host:$remote_port]\n";

DATA: while(<$handle=1>)
{
for($count=0;$count<180;$count++)
{
$send_data = self define string;
$handle-> send($send_data);
$count=0;
sleep(180);
}
}

IO1: while(<$handle=1>)
{
for($count=0;$count<240;$count++)
{
$send_i1 = self defined string
$handle-> send($send_i1);
$count=0;
sleep(240);
}
}

IO0: while(<$handle=1>)
{
for($count=0;$count<360;$count++)
{
$send_i0 = self defined string;
$handle-> send($send_i0);
$count=0;
sleep(360);
}
}
Reply With Quote
  #2  
Old 09-08-2008, 08:56 AM
Josef Moellers
Guest
 
Default Re: What is wrong in the following script

Arun wrote:

Perhaps you try to explain to us and to yourself, what this line is
supposed to do:

> DATA: while(<$handle=1>)


Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
Reply With Quote
  #3  
Old 09-08-2008, 02:43 PM
Dr.Ruud
Guest
 
Default Re: What is wrong in the following script

Arun schreef:

> #!\usr\bin\perl -w
> [...]
> use strict;


It won't solve your real problem, but it sure looks better:

#!/usr/bin/perl
use strict;
use warnings;

--
Affijn, Ruud

"Gewoon is een tijger."
Reply With Quote
  #4  
Old 09-08-2008, 05:03 PM
Eric Pozharski
Guest
 
Default Re: What is wrong in the following script

Arun <sajapuram.arun.prakash@gmail.com> wrote:
> problem: excecutes only DATA string but nor IO1 and IO0.


I would like to hear any answert to Josef Moellers's question too.

Meanwhile:

> #!\usr\bin\perl -w


Use C<use warnings;> instead.

> use IO::Socket;
> use diagnostics;


Use C<perldoc perldiag> instead.

> use strict;
> use POSIX qw(strftime);


> my $remote_host = "";
> my $remote_port = "";
> my ($handle, $send_data,$send_i1,$send_i0,$count);


> $count=0;
> $handle= IO::Socket::INET->new( PeerAddr => $remote_host,
> PeerPort => $remote_port,


I'm not an B<IO::Socket::INET> expert, but I suppose you are going to
connect to empty port at empty address.

> Proto => "tcp",
> Type => SOCK_STREAM
> )
> || die "Couldn't connect to $remote_host:$remote_port: \n";


> print STDERR "[Connected to $remote_host:$remote_port]\n";


> DATA: while(<$handle=1>)

*SKIP*
> $send_data = self define string;


BTW, copy-paste your code. Don't retype.

*SKIP*
> IO1: while(<$handle=1>)

*SKIP*
> IO0: while(<$handle=1>)

*SKIP*

I would like to know your intentions too. What you really achieved is:

23:38:09 69 [0:0]$ perl -mIO::Handle -wle '
$x = new IO::Handle; print <$x=1>'
IO::Handle=GLOB(0x814ed90)=1

I believe, that since filehandles aren't supposed to be assigned while
reading from them, Perl treats your construct as globbing (instead of
reading). Surprise? C<perldoc -f glob> has more.

--
Torvalds' goal for Linux is very simple: World Domination

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:28 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.