Hello,
I'm new to Perl and I'm stepping through an online tutorial. I'm trying to count the lines in a file that have strings with double letters in them. This is my code -
[CODE=perl]$file = 'c:\Perl\Beth\f 7.txt';
open(INFO, $file);
$i = 1;
while ($line = <INFO>)
{
$_ = $line;
if (/.+/)
{
print "00$i $line";
$i++;
}
}
close(INFO);[/CODE]
"f7.txt" contains:
orannges
lemon lemon
pickles hammburger
bagel
This compiles and I get:
001 orannges
002 lemon lemon
003 pickles hammburger
004 bagel
I thought the ".+" would only match strings with one or more repeating characters. I expected:
001 orannges
What did I do wrong?
Thanks!
Beth
I'm new to Perl and I'm stepping through an online tutorial. I'm trying to count the lines in a file that have strings with double letters in them. This is my code -
[CODE=perl]$file = 'c:\Perl\Beth\f 7.txt';
open(INFO, $file);
$i = 1;
while ($line = <INFO>)
{
$_ = $line;
if (/.+/)
{
print "00$i $line";
$i++;
}
}
close(INFO);[/CODE]
"f7.txt" contains:
orannges
lemon lemon
pickles hammburger
bagel
This compiles and I get:
001 orannges
002 lemon lemon
003 pickles hammburger
004 bagel
I thought the ".+" would only match strings with one or more repeating characters. I expected:
001 orannges
What did I do wrong?
Thanks!
Beth
Comment