hi
thema moose bzw Role ist fuer mich erstmal tabu da kein core modul.
bitte das readfile nicht so ernst nehmen es mehr beispiel.
ich habe nach dem lesen von
http://perldoc.perl.org/perlobj.html
und
http://perldoc.perl.org/Exporter.html
das ganze noch mal ueberarbeit.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package Hgltools;
use strict;
use warnings;
use English '-no_match_vars';
use Carp;
use feature qw/switch/;
use Readonly;
our $VERSION = '0.01';
our @ISA = qw(Exporter);
our @EXPORT_OK = ();
if ( eval 'use Hglreadfile; 1;' ) { push @EXPORT_OK,'_readfile'; }
require Exporter;
use base qw(Exporter);
sub new {
my ($class,$args) = @_;
my $shelf = {};
$class = ref($class) || $class;
bless $shelf,$class;
return $shelf;
} # end sub new
sowie
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
package Hglreadfile;
# $Revision: 00001 $
# $Source: /home/glaess/perl/hgltools/Hglreadfile.pm $
# $Id: Holger Glaess $
use strict;
use warnings;
use English '-no_match_vars';
use Carp;
our $VERSION = '0.01';
our @ISA = qw(Exporter);
our @EXPORT = qw (_readfile);
our @EXPORT_OK = qw (_readfile);
sub new {
my @opt = @_;
my $shelf = {};
my $class = $opt[0];
my $args = $opt[1];
$class = ref($class) || $class;
bless $shelf, $class;
return $shelf;
} # end sub new
sub _readfile {
my ($shelf,$args) = @_;
my $file = \$args->{'file'};
my @content = ();
if ( not ( -e ${$file} ) ) { return ('filenotexist'); }
open my $FH , '<', ${$file} or croak "can't open ${$file} for _readfile $ERRNO";
while (<$FH>) {
chomp;
push @content,$_;
}
close $FH or croak $ERRNO;
return (@content);
}
1;
holger
Last edited: 2011-06-01 11:18:57 +0200 (CEST)