in reply to Re^3: Wx Server reform
in thread Wx Server reform

Use Strict gives me BareWord "AHCMD" line 55.
AHCMD is needed.

Use Warnings gives me Useless use of 1's complement (~) in void context line 53.
If I comment out line 53, the command to the system does not work. Line 53 is needed. Somehow it filters out the text "Get", "HTTP", etc

Updated code:
#!/usr/bin/perl package main; use IO::Socket; use Sys::Hostname; use Socket; use strict; use warnings; use Wx; use wxPerl::Constructors; use base 'Wx::App'; use Wx qw(wxTE_MULTILINE wxVERTICAL wxID_DEFAULT); my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]); my $local; my $addr; my $path; my $app = Demo::App->new; $app->MainLoop; package Demo::App; use base 'Wx::App'; sub OnInit { my $frame = Demo::App::Frame->new; $frame->Show(1); } package Demo::App::Frame; use Wx qw(:everything); use base 'Wx::Frame'; sub new { my ($class) = @_; my $self = $class->SUPER::new( undef, -1, "X10 Voice Commander", wxDefaultPosition, wxDefaultSize, );$local = IO::Socket::INET->new( Proto => 'tcp', # protocol LocalAddr => "$ipaddr:8086", ) or die "$!"; $local->listen(); $local->autoflush(1); while($addr = $local->accept() ) { while (<$addr>) { $path = "C:/Program Files (x86)/Common Files/X10/Common"; chdir($path) or die "Cant chdir to $path $!"; ~s/GET//,~s/~/ /g,~s/%20/ /g,~s/%22/ /g,~s/x10command=DEVICE/ +/,~s/\//\ /g,~s/[?]//g ,~s/'/ /g,~s/HTTP/ /,~s/1.1/ /g,~s/sh://; system(AHCMD. "$_"); $self->{text} = Wx::TextCtrl->new($self, -1, "", [-1,-1], [500, 50 +0], wxTE_MULTILINE); $self->{text}->WriteText("Use Your IP $ipaddr:8086 on your device. +\n"); $self->{text}->WriteText("Connection From: "); $self->{text}->WriteText($addr->peerhost()); $self->{text}->WriteText("\n"); $self->{text}->WriteText("Received: $_"); print "Received: $_"; close $addr; } return $self; #This has something to do with it? Return where??? } }

Replies are listed 'Best First'.
Re^5: Wx Server reform
by afoken (Chancellor) on Jun 03, 2012 at 15:35 UTC
    Use Strict gives me BareWord "AHCMD" line 55. AHCMD is needed.

    For what? Do you (not perl) think it is a constant? Perl does not think so. Maybe you need to import that constant explicitly. Do you (not perl) think it is a function without arguments? Then add explicit braces, and make sure perl knows that function (again, import it explicitly if it is not automatically exported). Do you (not perl) think it is an old-style file handle? Replace it with a lexical handle. Do you (not perl) think it is a string that does not strictly have to be quoted? Then add quotes.

    Use Warnings gives me Useless use of 1's complement (~) in void context line 53. If I comment out line 53, the command to the system does not work. Line 53 is needed.

    Looks like a typo. Do you want a string match (=~) or a smart match (~~)?

    Line 53 is

    ~s/GET//,~s/~/ /g,~s/%20/ /g,~s/%22/ /g,~s/x10command=DEVICE//,~s/\//\ + /g,~s/[?]//g ,~s/'/ /g,~s/HTTP/ /,~s/1.1/ /g,~s/sh://;

    And that ~ in front of every substitution operator is plain nonsense. Read perlsyn.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^5: Wx Server reform
by ww (Archbishop) on Jun 03, 2012 at 16:03 UTC
    "AHCMD is needed.
    ...
    Line 53 is needed.</i?"

    "(N)eeded," maybe. Need to be corrected; definitely!

    When the pragmas provide the kind of information you've now observed, they're not telling you that something is "un-needed." They're telling you that you haven't written the Perl (the code) correctly; that you need to fix the errors before you can move on.

      Thanks to you, I removed all the ~ on line 53 and it still works and the warning went away.

      Next is Making Perl know AHCMD has to be used.

      system(AHCMD. "$_")
      is sent to the path that contains AHCMD.exe. The arguments are what the client sent. A1 On or A1 Off, etc.
        Unless AHCMD runs really really fast, you will need to put it into it's own thread, or it will block your network code and GUI. Also you should be using Wx::Socket for your sockets. But after all the responses I gave you in Server with GUI, I'm giving up trying to correct your code. Please go to jobs.perl.org to get someone to write your code for you.

        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh