note
blue_cowdawg
<ul><ul><i>
</i></ul></ul>
<p>
OK took your code at face value and made some fundamental changes:
<code>
#!/usr/bin/perl
use strict;
while ($lines = <DATA>){
$word = split "", $lines;
print $word."\n";
}
print "\n\n";
exit 0;
__END__
tutor
teacher
tinker
sailor
</code>
and when I ran it got:
<code>
$ ./fix.pl
Global symbol "$lines" requires explicit package name at ./fix.pl line 5.
Global symbol "$word" requires explicit package name at ./fix.pl line 6.
Global symbol "$lines" requires explicit package name at ./fix.pl line 6.
Global symbol "$word" requires explicit package name at ./fix.pl line 8.
Execution of ./fix.pl aborted due to compilation errors.
</code>
which is not too surprising. So the next set of changes:
<code>
#!/usr/bin/perl
use strict;
while (my $lines = <DATA>){
my $word = split "", $lines;
print $word."\n";
}
print "\n\n";
exit 0;
__END__
tutor
teacher
tinker
sailor
</code>
and now when we run it we get:
<code>
$ ./fix.pl
6
8
7
8
</code>
pretty much as you describe. So let's make another change:
<code>
#!/usr/bin/perl
use strict;
while (my $lines = <DATA>){
my ($word) = split "", $lines;
print $word."\n";
}
print "\n\n";
exit 0;
__END__
tutor
teacher
tinker
sailor
</code>
which gives us:
<code>
$ ./fix.pl
t
t
t
s
</code>
At this point I have a couple of comments to make:
<ol>
<li> <b>Remember:</b> the function <code>split()</code> returns an array based on the regex designating where to split the string. In this case you pass in an empty string which causes your <code>$lines</code> variable to be split on every character. (was that your intention?)
</li>
<li> Without the enclosing parenthesis around <code>$word</code> you are using an array in a scalar context which means you are going to get the length of that array as a scalar not the value of the array itself.</li>
</ol>
</p>
<p>
Hope this helps you on your way....
</p>
<div class="pmsig"><div class="pmsig-72516">
<hr>
<font size="-2">
Peter L. Berghold -- Unix Professional<br>
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg<br>
</font>
</div></div>
1007352
1007352