[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CLIENT/SERVER in Perl/UNIX

Posted on 2005-04-21
5
Medium Priority
?
364 Views
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?


CLIENT.PL
----------------------
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
            ----       -----      ------------      -------------------          ------------
            .
            
            write;
      }
      close CLIENT;
}
close CLIENT;


Can anybody see any errors?

Nothing works?

Ellandrd

0
Comment
Question by:ellandrd
  • 4
5 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 13838362
I think you want
print SERVER $messageNumber,"\n";
not
print <SERVER> $messageNumber,"\n";
0
 
LVL 16

Author Comment

by:ellandrd
ID: 13840678
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
----      -----     ------------     -------------------         ------------
20

Ellandrd
0
 
LVL 85

Expert Comment

by:ozo
ID: 13840756
$display =~ /#/g
will only be true when $display contains a "#" character
"20\n" does not contain a "#" character
0
 
LVL 85

Expert Comment

by:ozo
ID: 13840773
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.
0
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 13841402
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?"
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans
Suggested Courses

834 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