#! /usr/bin/perl use strict; use warnings; package ERRORCODEOBJ; sub new { my $class=shift; my $file = shift or 'errormap.txt'; my $self={}; $self->{file_name}=$file; $self->{ERRORS}=[]; bless($self,$class); $self->load(); return $self; } sub load { my $self=shift; my $filename=$self->{filename}; open( my $errormaplist, '<', $filename ) or die "error open $filename : $!"; my @lines = <$errormaplist>; close $errormaplist; chomp(@lines); $self->{ERRORS}=\@lines; } sub errormap { my $self = shift; my $line =shift; if($line < @{$self->{ERRORS}} and $line >= 0) { return $self->{ERRORS}->[$line]; } return undef; } package main; my $objekt=ERRORCODEOBJ->new(); print $objekt->errormap(1)."\n";