Posted on 2005-04-21
Last Modified: 2010-05-18
What I want to achieve:
Send message from Server to Client using PERL on a UNIX OS

Whats happens in both scripts:
All the Server is doing is either sending a number back to Client or a string back to the Client, depending on my choice.

// variables set up with values
$messageNumber = 20;
$messageString = "12345,12345,abcd,asdf,12345";

//send message to client
print <SERVER> $messageNumber,"\n";  <<<<<<<<<< here i can choose what to send back to client like i said above!

I want to check if its a number of a string?

but cant get it to work?

use Socket;
use FileHandle;
autoflush CLIENT 1;

$filename = "###";

socket(CLIENT, PF_UNIX, SOCK_STREAM, 0) or die "Socket: $!";
connect(CLIENT, sockaddr_un($filename)) or die "Connect: $!";

while ($display = <CLIENT>)
      if ($display =~ /#/g)
            print "The number from the server was: $display\n\n";
            close CLIENT;
      elsif ($display > " ")      
            chomp ($display);
            ($uid, $pid, $state, $fname, $size) = split(",", $display);
            format =
            @<<<<<< @<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<
            $uid, $pid, $state, $fname, $size

            format STDOUT_TOP =
            Page No: @<
            UID      PID       State             Filename                Virtual Size
            ----       -----      ------------      -------------------          ------------
      close CLIENT;
close CLIENT;

Can anybody see any errors?

Nothing works?


Question by:ellandrd
    LVL 84

    Expert Comment

    I think you want
    print SERVER $messageNumber,"\n";
    print <SERVER> $messageNumber,"\n";
    LVL 16

    Author Comment

    OK that fixed that part, but how come it keeps printing out my the formating in the second IF statement if i passed a number to the client? it should just print:

    The number from the server was: 20

    but it prints out:

    UID     PID      State           Filename              Virtual Size
    ----      -----     ------------     -------------------         ------------

    LVL 84

    Expert Comment

    $display =~ /#/g
    will only be true when $display contains a "#" character
    "20\n" does not contain a "#" character
    LVL 84

    Expert Comment

    perl -Mdiagnostics -we '$display=20;if( $display > " " ){}'
    Argument " " isn't numeric in numeric gt (>) at -e line 1 (#1)
        (W numeric) The indicated string was fed as an argument to an operator
        that expected a numeric value instead.  If you're fortunate the message
        will identify which operator was so unfortunate.
    LVL 84

    Accepted Solution

    If you want to check if $display contains any digits, you can use
     $display =~ /\d/

    You may also want to see
    perldoc -q "How do I determine whether a scalar is a number/whole/integer/float?"

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now