全て、
次のコードを検討してください。
our $classwork = 0;
while( <INFILE> )
{
chomp;
next if $. == 1;
if( $year >= 1992 && $year <= 1995 )
{
$classwork = (split( /,/ ))[6];
print "Classwork is: ", $classwork, "\n";
}
if( $year >= 1996 && $year <= 2001 )
{
$classwork = (split( /,/ ))[-1];
}
print "Classwork is: ", $classwork, "\n";
if( $year == 2002 )
{
$classwork = (split( /,/ ))[-2];
}
if( $year == 2003 || $year == 2004 )
{
$classwork = (split( /,/ ))[23];
}
if( $year >= 2005 && $year <= 2009 )
{
$classwork = (split( /,/ ))[22];
}
if( $year >= 2010 && $year <= 2012 )
{
$classwork = (split( /,/ ))[20];
}
print "Classwork is: ", $classwork, "\n";
$line = <STDIN>;
}
最後の print ステートメントは、変数を出力したくありません。「our」と宣言したり、宣言をコメントアウトしたりしても。さらに奇妙なのは、最初の反復でのみ発生することです。ファイルには数千のレコードがあり、最初の反復では変数のみが未定義です。後続のすべての呼び出しは良好です。
何が起こっているのですか?
ありがとうございました。