?
Solved

\n error! ahhh!

Posted on 1998-12-23
5
Medium Priority
?
182 Views
Last Modified: 2010-03-05
#!/usr/bin/perl

use Barecgi;
%formdata = Barecgi::parse_form();

$formdata{lname} = "Aratsu";
$requested_doctor_lname = $formdata{lname};

if($formdata{lname})
{

      $do_doctor_lname = 1;
      $found = 0;

      open(file, "data/tx/alias.doctors.ref");
      @alias_doctor_ref_fdata = <file>;
      chop(@alias_doctor_ref_fdata);
      close(file);

      for($f = 0; $alias_doctor_ref_fdata[$f]; $f = $f + 1)
      {

            open(file, "data/tx/usr/$alias_doctor_ref_fdata[$f]") or print "Error";
            @doctor_fdata = <file>;
            chop(@doctor_fdata);
            close(file);
            
            print "$doctor_fdata[0]\n";

            ($doctor_info_fname, $doctor_info_lname) = split(/!~~~!/, $doctor_fdata[0]);

            print "$doctor_info_fname - $doctor_info_lname\n";

            print "[matching] $requested_doctor_lname $doctor_info_lname";

            if($requested_doctor_lname eq $doctor_info_lname)
            {                                    
                  $found_doctor_lname[$found] = $alias_doctor_ref_fdata[$f];
                  $found = $found + 1;

            }                        

      }

}

When I run this, the output I get is (among other things):

[matching] aratsu
aratsu

Why is there a line break there?  There isn't one in the print statement.  

print "[matching] $requested_doctor_lname $doctor_info_lname";

$requested_doctor_lname is "Aratsu", so is $doctor_info_lname.  Chop either one of them and you get Arats.

What's up with this?

Tribal
0
Comment
Question by:tribal9
5 Comments
 

Expert Comment

by:bkearns
ID: 1207148
You should try using chomp it is a safer version of chop, it only removes \n if it is there. Perhaps this will solve your problem.  
0
 

Author Comment

by:tribal9
ID: 1207149
There is no '\n' character anywhere in the string..the output is still produced this way.
0
 
LVL 85

Expert Comment

by:ozo
ID: 1207150
Where is the output going?
Is that really the output you get?  lower case "A" and no space after the line break?  Is there a space before the line break?
0
 
LVL 1

Accepted Solution

by:
sdjjm earned 0 total points
ID: 1207151
Is an ASCII 13 the leading character on your second string?
Open a file and output your print statement into it.  Send both strings there individually and together.  View the file in binary mode and find out exactly where the bad character you don't want is located so you can deal with it accordingly.
0
 

Author Comment

by:tribal9
ID: 1207152
Dunno if this will work but hell I just want closure.

One tough bug.

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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

850 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