Thread Werte in Subroutine und zurück mit Modulen (36 answers)
Opened by Brenner at 2009-01-13 17:30

Gast Gast
 2009-01-15 17:57
#118031 #118031
Versuch es mal so:

Code (perl): (dl )
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
47
48
49
50
51
52
53
54
#! /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";

View full thread Werte in Subroutine und zurück mit Modulen