package String; use strict; use warnings; sub new { my $class = shift; my %arg = @_; my $ddl = { a => { start => 0, length => 5, }, b => { start => 5, length => 5, }, n => { start => 10, length => 1, }, }; my $self = { ddl => $ddl, line => undef, }; bless $self, $class; } sub line : lvalue { my $self = shift; my $line = shift; $self->{'line'}; } sub field_start { my $self = shift; my $field = shift; return $self->{'ddl'}{$field}{'start'}; } sub field_length { my $self = shift; my $field = shift; return $self->{'ddl'}{$field}{'length'}; } sub field_int : lvalue { my $self = shift; my $field = shift; print "SUBSTR: ", substr($self->{'line'}, $self->field_start($field), $self->field_length($field)), "\n"; substr($self->{'line'}, $self->field_start($field), $self->field_length($field) ); } 1;