jaffinito34 has asked for the wisdom of the Perl Monks concerning the following question:
I just started a script where I take in a text file (words.txt) where there is a new word each line. I used a while loop to read each line and a split to assign the words to a variable. My problem is that the output is not the word, it is the number of characters plus one. For example, the first word is 'tutor' and the print statements prints '6'. I'm thinking its because of the newline that it is adding one but even so, I don't know why its not printing the string. Ive used this type of statement before and never had issues.
#! /usr/bin/perl open (WORD, '<', 'words.txt'); while ($lines = <WORD>){ @word = split "", $lines; print @word."\n"; } print "\n\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: while loop returning numbers not strings
by blue_cowdawg (Monsignor) on Dec 05, 2012 at 18:19 UTC | |
Re: while loop returning numbers not strings
by ww (Archbishop) on Dec 05, 2012 at 18:21 UTC | |
Re: while loop returning numbers not strings
by SuicideJunkie (Vicar) on Dec 05, 2012 at 18:11 UTC | |
by Lotus1 (Vicar) on Dec 05, 2012 at 20:01 UTC | |
by jaffinito34 (Acolyte) on Dec 05, 2012 at 18:20 UTC | |
by Kenosis (Priest) on Dec 05, 2012 at 19:49 UTC | |
Re: while loop returning numbers not strings
by Rudolf (Pilgrim) on Dec 05, 2012 at 18:27 UTC |
Back to
Seekers of Perl Wisdom