1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package List_subjects;
use strict;
use warnings "all";
sub subject {
my ( $class, $file ) = @_;
my $self = {};
bless( $self, $class );
open( my ($list_subjects), '<', $file )
or die "\nCannot open the subjects file $file : $!\n";
while ( my $line = <$list_subjects> ) {
if (
$line =~ m/("[a-z]{2,30}) \s
([a-z]{2,30})" \s
(\w{4,6}) \s
([0-9]{6}) \s
([0-9]{1,2}) \s
([0-9]{1,2})/x
)
{
$self->{LIST_ID}[ $. - 1 ] = $4;
}
}
close(LISTSUBJ);
return $self;
}
sub tour {
my ( $self, $code ) = @_;
foreach my $elt ( @{ $self->{LIST_ID} } ) { $code->( $self, $elt ); }
}
sub get_size {
my $self = shift;
return scalar @{ $self->{LIST_ID} };
}
sub get_id {
my ($self, $idx ) = @_;
return $self->{LIST_ID}[$idx];
}
1;
__DATA__ |