in reply to What is the difference?

I'm not sure if this is the root of the problem, but you're attempting to "add" a string numerically. That just isn't going to work. The offending code in the second example is:

$line += split /[ \t]*/; # Notice '+=' operator

Which should be:

$line .= split /[ \t]*/; # Notice '.=' operator

As I said, this may or may not fix your stated problem.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: What is the difference?
by jasonk (Parson) on Apr 08, 2003 at 14:30 UTC

    Split doesn't return a string, it returns a list, the scalar value of which is the number of elements, and since the split is splitting into individual characters, $line (although a poorly chosen variable name) contains the count of all the characters so far. Your 'fixed' example would end up giving you a list of numbers, if the text file contained two lines of 8 characters each, your example would return '88'.


    We're not surrounded, we're in a target-rich environment!