[Omaha.pm] Could you take a look

Jay Hannah jay at jays.net
Fri Jan 19 05:56:33 PST 2007


On Jan 19, 2007, at 7:18 AM, kiran bina wrote:
> Could you please take a look at this.
> <test.zip>

Hi again Kiran.  :)


Your code (as viewed in the debugger):


   DB<6> l 9-15
9:      while (my $line=<IN1>)
10      {
11:         if ($line=~ m/\>\s+/)
12          {
13:             $line=~ m/^(\S+)\>\s(\S+)$/;
14==>           my $read = $1;
15:             my $value= $2;


Your first problem is that $line has carriage returns and/or newlines  
at the end, so your regex demand that the line end with \S+ fails.

I'll step past the regex and show you the newlines:

                                                                         
                                                  main::(test.pl: 
13):             $line=~ m/^(\S+)\>\s(\S+)$/;

DB<1> n
main::(test.pl:14):             my $read = $1;
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
      DB<3> p "[$line]"
[a> APPLE
]


Now normally you could just 'chomp $line;', but that didn't work for  
me on your data. Perhaps because my Mac defines newlines differently  
than wherever you made your file? Even after I added chomp it still  
wasn't working, so I x'd it in the debugger to see why not:


   DB<3> x $line
0  "a> APPLE\cM"


Bummer. I believe "\r\n" (carriage return, linefeed) is interpreted  
as Control-M, So I added a regex to remove all carriage returns and  
linefeeds


     $line =~ s/[\r\n]//g;


(chomp might work fine for you.)

The next annoyance was all these warnings:


Use of uninitialized value in string eq at test.pl line 43, <IN1>  
line 5.


Which you can avoid by NOT running look_up_order() if there is no  
$value. I don't know if that's what you wanted to do or not, but you  
can do that with this line


         next unless ($value);  #  No value in file...


So your code now reads like this:


while (my $line=<IN1>)
{
     $line =~ s/[\r\n]//g;
     if ($line=~ m/\>\s+/)
     {
         $line=~ m/^(\S+)\>\s(\S+)$/;
         my $read = $1;
         my $value= $2;
         next unless ($value);  #  No value in file...


which seems to work?


$ perl test.pl
a
APPLE
b
BOY
d
DOG


?

Lower, your look_up_order() doesn't seem to do anything at all. Were  
you wanting it to pull values out of File2 if File1 didn't have a  
$value or something?

HTH,

j




More information about the Omaha-pm mailing list