What is wrong in the following script

Discussion in 'Perl Misc' started by Arun, Sep 8, 2008.

  1. Arun

    Arun Guest

    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);
    }
    }
     
    Arun, Sep 8, 2008
    #1
    1. Advertising

  2. 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
     
    Josef Moellers, Sep 8, 2008
    #2
    1. Advertising

  3. Arun

    Dr.Ruud Guest

    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."
     
    Dr.Ruud, Sep 8, 2008
    #3
  4. Arun <> 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
     
    Eric Pozharski, Sep 8, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. willem oosthuizen

    What is wrong with the following code?

    willem oosthuizen, Oct 10, 2003, in forum: VHDL
    Replies:
    9
    Views:
    1,331
  2. Razvan
    Replies:
    3
    Views:
    391
    Xiangliang Meng
    Jun 22, 2004
  3. Chris
    Replies:
    7
    Views:
    479
    BigBrian
    Feb 9, 2005
  4. Replies:
    5
    Views:
    325
    John Carson
    Apr 16, 2005
  5. Replies:
    4
    Views:
    348
    Kristo
    May 9, 2005
Loading...

Share This Page