Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Use perl to do direction matching

by hujunsimon (Sexton)
on Oct 09, 2009 at 15:18 UTC ( [id://800309]=note: print w/replies, xml ) Need Help??


in reply to Re: Use perl to do direction matching
in thread Use perl to do direction matching

After i declare the variable as you suggested, it comes out another error, said 'use of uninitialized value $A in concatenation <.>.....'

#Main body while (my $line = <TEMP>) { my $A; my $B; my @column = split (/,/,$line); if ($column[4] < $column[7]) { $A = $direction[0]; }else {$A = $direction[1]; } if ($column[5] < $column[8]) { $B = $direction[2]; }else {$B = $direction[3]; } my $dir = $A.$B; print OUTPUT $column[4],$comma,$column[5],$comma,$column[7],$comm +a,$column[8],$comma,$dir,$comma,$nline; }

Replies are listed 'Best First'.
Re^3: Use perl to do direction matching
by moritz (Cardinal) on Oct 09, 2009 at 15:36 UTC

    It's not an error, it's a warning. So you have to find out why it's undef. Check the code where you assign to it, find out which branch it took, why the value you assign to it is undef etc.

    You know that $A is either $direction[0] or $direction[1], so try to print those:

    use 5.010; # enable say(), which is shorter than print ..., "\n"; ... say "Direction 0: '$direction[0]'"; say "Direction 1: '$direction[1]'";

    That should give you some clue of what's wrong. You can also use Data::Dumper for debugging.

    Oh, and you still haven't chosen a better name for $A - you really should. Since Perl doesn't know what your code means (at least not in the way you think it should), you should help us understand what it should mean - by using a good names, for example.

    For fixing it, I recommend reading the section List value constructors in perldata, or at perlintro.

    Perl 6 - links to (nearly) everything that is Perl 6.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://800309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found