Beat: Anhang

Beitrag lesen

Hallo Struppi
Das Script ist wohl doch nicht sehr nützlich.
Der untenstehende Test verdeutlicht es.

  
#!usr/bin/perl -w  
#  
use strict;  
use CGI::Carp qw(fatalsToBrowser);  
  
BEGIN {  
 use CGI::Carp qw(carpout);  
 open(LOG, ">>error.txt")  or  die "Unable to append to error.txt: $!\n";  
 carpout(*LOG);  
}  
  
  
  
use constant NL => "\n";  
  
package Accessor;  
  
  
sub new {  
  my $proto = shift;  
  my $p = shift || 'x_';  
  my %dummy;  
  no strict 'refs';  
  foreach my $func (qw(a b c)) {  
         *{"${proto}::$p$func"}   = sub {  
       my $self = shift;                  ## sic!  
       $dummy{$func} = $_[0] if @_;  
       return $dummy{$func};  
     };  
   }  
  my $self = bless \%dummy, $proto;  
  return $self;  
}  
  
  
  
  
package main;  
  
# TEST  
  
print NL;  
my $y = new Accessor('y_');  
$y->y_a('$y, y_');  
print '$y->y_a() : ', $y->y_a(), NL;  
  
print NL;  
my $x = new Accessor('x_');  
$x->x_a('$x, x_');  
print '$y->x_a() : ', $y->x_a(), NL;  
print '$y->y_a() : ', $y->y_a(), NL;  
print '$x->x_a() : ', $x->x_a(), NL;  
print '$x->y_a() : ', $x->y_a(), NL;  
  
print NL;  
my $z = new Accessor('z_');  
$z->z_a('$z, z_');  
print '$z->x_a() : ', $z->x_a(), NL;  
print '$z->y_a() : ', $z->y_a(), NL;  
print '$z->z_a() : ', $z->z_a(), NL;  
  
sleep(20);  
  
exit;  
__END__  

Die Instanz $z hat vollen Zugriff auf die Eigenschaften von Instanzen $x und $y.

mfg Beat

--
Selber klauen ist schöner!
0 69

Mein erstes kleines Modülchen...

Patrick Andrieu
  • perl
  1. 0
    Cheatah
    1. 0
      Patrick Andrieu
      1. 0
        Cheatah
        1. 0
          Patrick Andrieu
    2. 0
      Patrick Andrieu
      1. 0
        Patrick Andrieu
  2. 0
    hotti
  3. 0
    hotti
    1. 0
      Patrick Andrieu
  4. 0
    Adolf
    1. 0
      Patrick Andrieu
      1. 0
        Adolf
        1. 0
          Patrick Andrieu
  5. 0
    Beat
    1. 0
      Patrick Andrieu
  6. 0
    Struppi
    1. 0
      Patrick Andrieu
      1. 0
        Struppi
        1. 0

          Mein erstes kleines Modülchen... und Grundsatzfragen!

          Patrick Andrieu
          1. 0
            Struppi
            1. 0
              Patrick Andrieu
  7. 0

    Mein erstes (nicht mehr so kleines) Modülchen...

    Patrick Andrieu
    1. 0
      Beat
      1. 0

        Anhang

        Beat
        1. 0
          Skrilax
          1. 0
            Beat
            1. 0
              Struppi
              1. 0
                Struppi
              2. 0
                Beat
                1. 0
                  Struppi
                  1. 0
                    Beat
                    1. 0
                      Struppi
                      1. 0
                        Beat
                        1. 0
                          Struppi
                          1. 0
                            Siechfred
                            1. 0
                              Struppi
                              1. 0
                                Siechfred
                          2. 0
                            Beat
                            1. 0
                              Struppi
      2. 0
        Patrick Andrieu
    2. 0
      Christoph
      1. 0
        Patrick Andrieu
        1. 0
          Christoph
          1. 0
            Patrick Andrieu
    3. 0
      Siechfred
      1. 0
        Patrick Andrieu
        1. 0
          Patrick Andrieu
          1. 0
            Tim Tepaße
        2. 0
          Harlequin
        3. 0
          Tim Tepaße
          1. 0
            Patrick Andrieu
            1. 0
              at
              1. 0
                Patrick Andrieu
                1. 0
                  at
            2. 0
              Tim Tepaße
              1. 0
                Patrick Andrieu
              2. 0

                Date::Today released and with POD

                Patrick Andrieu
                1. 0
                  Christoph
                  1. 0
                    Patrick Andrieu
  8. 0

    Kritik und Regel für Wochenzählung

    Patrick Andrieu
    1. 0
      Patrick Andrieu
      1. 0
        at
        1. 0
          Patrick Andrieu
    2. 0
      Patrick Andrieu
      1. 0
        Beat
        1. 0
          Patrick Andrieu
          1. 0
            Beat
            1. 0
              Patrick Andrieu