Debug plain text input

Posted on 2007-08-03
Last Modified: 2010-03-05
My script's purpose is to perform .NET functions on a PC client, and it talks back and forth using plain text:
a) The script prints plain text, which is intercepted by the client and tells the client which .NET operations to perform (this part is working great).

b) The Windows client (basically a glorified telnet client) sends responses in plain text back to the perl script (with perhaps a CR/LF after each line of text - maybe this is the problem)

The only line that is giving me trouble is the one exiting the loop:

       last if $text eq '3Click,MyForm.button1';

The script exits correctly if i manually run it from the # prompt and type:


followed by pressing the ENTER key.

The problem is the script does not end when my client sends this text.  Are there alternatives to chomp that I should be using?  To debug, is there a way I can dump the value of $text into a file during each pass through the loop, so I can see what text the script is receiving?  Or is my syntax just inappropriate for the application?

The script:

   # Enter TrueGUI mode:                                    
   print "\$\$EnterTrueGuiMode\$\$\n";                      
   # Load the set of Windows Forms we created with Visual Studio:        
   print "{ TrueGui.LoadAssembly(`WindowsApplication1`) }\n";
   # Create an instance of Form1 calling it "MyForm"        
   print "{ MyForm = New WindowsApplication1.Form1() }\n";  
   # Show MyForm                                            
   print "{ MyForm.Show() }\n";                              
   while(1) {                                                
      last if $text eq '3Click,MyForm.button1';              
   # end of script                                          

Question by:silentreproach
    LVL 39

    Accepted Solution

    open(LOG, ">>TrueGUI.log") or die "Could not open log: $!\n";
    print LOG "Program running at " . localtime() . "\n";
    while(1) {                                                
        print LOG "Text received='$text'\n";
        last if $text eq '3Click,MyForm.button1';
    LVL 18

    Assisted Solution

    Alternatively, instead of chomp(), you could use

         # remove all trailing whitespace
         # \x0a = LineFeed (ASCII 10)
         # \x0d = Carriage Return (ASCII 13)
         # \s = all whitespace (space, tab, newlines)
         $text =~ s/[\s\x0a\x0d]+$//;

    If you only want the newlines trimmed, then remove the \s in the range.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    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…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    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…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now