I want to read a file line by line and for each line split the string and print it. But the script only prints the even lines.
File:
line1:item1
line2:item2
line3:item3
line4:item4
line5:item5
line6:item6
and the script:
$FILE = "file";
open($FILE, "<", "file") or die("Could not open file.");
while (<$FILE>) {
my $number = (split ":", <$FILE>)[1];
print $number;
}
output:
item2
item4
item6
This is because you read two lines per loop round
use this instead