Solved

\n error! ahhh!

Posted on 1998-12-23
5
171 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 84

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

830 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