T
toomanyjoes
Hi,
I'm trying to loop through a .txt file and grab a number at the
beginning of the line. I want to save this number in a variable and
then compare it with the number at the beginning of the next line. For
instance my text would look like this:
1sampletextsampletextsamplet22tsampletextsampletextsampletext
2sampletextsampletextsamplet22tsampletextsampletextsampletext
3sampletextsampletextsamplet22tsampletextsampletextsampletext
The lines are distinct from one other, each one ends with a newline
character. How do I loop through a text file line by line?
#Heres my code so far
$myvar = "1sampletextsampletextsamplet22tsampletext"; #easy way out of
opening the text file (I'm not sure how)
if ($myvar =~ /^(\d+)/){
$curNum = "$1"; #curNum should equal 1
}
print "$curNum";
This only works for an individual line. I need to move to the next line
and do the same thing, then compare $curNum with $newNum.
I'm trying to loop through a .txt file and grab a number at the
beginning of the line. I want to save this number in a variable and
then compare it with the number at the beginning of the next line. For
instance my text would look like this:
1sampletextsampletextsamplet22tsampletextsampletextsampletext
2sampletextsampletextsamplet22tsampletextsampletextsampletext
3sampletextsampletextsamplet22tsampletextsampletextsampletext
The lines are distinct from one other, each one ends with a newline
character. How do I loop through a text file line by line?
#Heres my code so far
$myvar = "1sampletextsampletextsamplet22tsampletext"; #easy way out of
opening the text file (I'm not sure how)
if ($myvar =~ /^(\d+)/){
$curNum = "$1"; #curNum should equal 1
}
print "$curNum";
This only works for an individual line. I need to move to the next line
and do the same thing, then compare $curNum with $newNum.