<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>


            ??????? Perl???????????

            ????????
            ????Perl?§Ö???
            ??????????
            ?????????
          1. ???????

          2. ?‰]????
            ?????????????
            ????????????
            ???????
            ???????????
            ??????
            ??????????????
            ?????Perl????????§»???

                ?????????????Perl???????????(OOP)???????¦É???????????????§³???????????????????????
            ????????
                ???(module)????Perl??(pachage)??Perl?§Ö?????????????????????¨¢??????¨¹???x?????????
            ???http://www.metronet.com??perlmod??perlobj??
                ??????????????????????????????????????????????????????????????????§Ø????????????????????????????????????????????????????????????????????????????????????????????????????Perl??????????????????????Perl5?§µ??????§Ò??????œZ??????????¨¢?
                ???????????????????????????Perl????¦É????????????
                .???????Perl???????§Ü?????????????
                .?????????Perl???????????????????????
                .?????????????????????¨¢?
            ????Perl?§Ö???
                ???????¡ê????Perl???????????????????????Perl???????????????????????????????????Perl5???????????????????????C++?????????????????????????Perl4?????????????e??(::)??????????????????????
                ?????????????????????§³?Perl?§Ö??????????????????????????????????????§Ù???????????????????????????????§³?
                ???????????????????????????????????¹À?????????????????ð‹?????x?1??????ï‚???????????????????????????????????????????y??????????????(')??????????¦Ë???§Ö?????????§Ô?????¦Ë????»Ç$class'$member????Perl5?§µ??????e??????????????????????»Ç$class'$member??$class::$member?????
            ??????????
                ???????????????????????ÒÂ???????????????????????Cocoa????????•ø??????????????Java???????????????????????????????????Java??????????????????Java???????????????????????þŸ
                ???????????????Cocoa.pm??????(?????pm?????????????????Perl Module)???????????????????????????????????????????????????1;????????§µ??????????????????????????1;????????§³?????Perl?????????????????e??????Perl????????????????????????
            package Cocoa;

            #
            # Put "require" statements in for all required,imported packages
            #

            #
            # Just add code here
            #

            1; # terminate the package with the required 1;
                ??????????????????????????????????????????????????new()????????????????????????new()?????????????????
            ?????????
                ??????????????????????????????????????¨¢?????????????????????????????????????????y?????????bless()?????????
                bless YeReference [,classname]
                YeReference??????????????????????classname?????????????????????????????????????????
                ????????????????????????????????????????????????»Ç
            sub new {
              my $this = {}; # Create an anonymous hash, and #self points to it.
              bless $this; # Connect the hash to the package Cocoa.
              return $this; # Return the reference to the hash.
            }

            1;
                {}??????????????/??????????????????ï‚?????????????????????????$this??????bless()??????????????????????????Cocoa???????????¨¢???????????????????????????????
                ??new()?????????$this???????????????¨²??????????¨´?????????????¨´??????????????????????Perl??????§Ò???¨´?????????????????¦Ì????
                $cup = new Cocoa;
                ???????????e???????????????
            1 #!/usr/bin/perl
            2 push (@INC,'pwd');
            3 use Cocoa;
            4 $cup = new Cocoa;
                ????????Perl????????¦Ë?????????§µ???????????¡¤??????§Ò?@INC?§Û????????¨¢?????????????????§Õ????????ö–????t???¡¤???????íà?????/home/test/scripts/????????????§à???????¡ê?
                push (@INC , "/home/test/scripts");
                ????????§µ????????Cocoa.pm????????????±Ä???use??????Perl??@INC¡¤????????Cocoa.pm???????????????????????§³?use????????????????????§Ö???new????????????????Perl???????????????????????????????????????????????§Ø????????????§Õ??
                $cup = cocoa->new();
                ???????C??????????????e????????Cocoa???§Ö?new()???????»Ç
                $cup = Cocoa::new();
                ????????????§Þ??????????????Cocoa.pm?§µ??????????????????????????????????????¨´????????????????????????????
            ???
            1??????????????§Ô??????????
            2????????my??????????§Õ?????????
            3??????????????????local?????????????????????????????
            4????????????????????????????
                ??????????Cocoa?????????¡ê?
            sub new {
              my $this = {};
              print "\n /* \n ** Created by Cocoa.pm \n ** Use at own risk";
              print "\n ** Did this code even get pass the javac compiler? ";
              print "\n **/ \n";
              bless $this;
              return $this;
            }
                ??????????e????????????????????????????????????»Ç
            sub new {
              my $this = {}
              bless $this;
              $this->doInitialization();
              return $this;
            }
                ???????????????????????§µ??????????????????????????????new?????????new????????????????
            sub new {
              my $class = shift; # Get the request class name
              my $this = {};
              bless $this, $class # Use class name to bless() reference
              $this->doInitialization(); return $this;
            }
                ??????????????????????????????§Ö????
          3. Cocoa::new()
          4. Cocoa->new()
          5. new Cocoa
          6.     ??????bless????????????????¦Ì????bless??????????????bless????????????C??Pascal??????????????????????????????????—¨???????????????????????????????™n????????Perl?????????????????????
                ?????????????????????????Perl????bless??????????????????????????bless??????????????????????????????????????????????????????¦Ê???

          7. ???????


          8.     ???????????new()?????????????????????????????????????????????????????????????????new()????????????????????????
                ???????????????????????????????????????
                ?¨´???????????¡ê?
            sub new {
            my $type = shift;
            my %parm = @_;
            my $this = {};
            $this->{'Name'} = $parm{'Name'};
            $this->{'x'} = $parm{'x'};
            $this->{'y'} = $parm{'y'};
            bless $this, $type;
            }
                ?????÷g?????????¡ê?
            sub new {
            my $type = shift;
            my %parm = @_;
            my $this = [];
            $this->[0] = $parm{'Name'};
            $this->[1] = $parm{'x'};
            $this->[2] = $parm{'y'};
            bless $this, $type;
            }
                ?????????????????¡ä????????
                $mug = Cocoa::new( 'Name' => 'top','x' => 10,'y' => 20 );
                ??????=>????????????????????=>?????¨¢???????????¡ê?
                print "Name=$mug->{'Name'}\n";
                print "x=$mug->{'x'}\n";
                print "y=$mug->{'y'}\n";
            ?‰]????
                Perl????????????????Perl????????????????????????????Perl????????�I???¦Ê????????????�q??????????????????????????????Perl?????????????????????ú›????
                ????????????????????????ú›????????????????????¨¢??????????????????????????????????????????????????????????????????????????????????????????????????????????????ú›??????????????????shift??????self??this?§µ????????????????????¨¢??»Ç
            1. sub nameLister {
            2.     my $this = shift;
            3.     my ($keys ,$value );
            4.     while (($key, $value) = each (%$this)) {
            5.         print "\t$key is $value.\n";
            6.     }
            7. }
            ?????????????
                ???????????????Cocoa.pm??????????????????¦Ä????????????????Cocoa.pm?????????????????????????Exporter??ï…?????????????????????§µ?
                require Exporter;
                @ISA = qw (Exporter);
                ?????§Ñ?????Exporter.pm??ï…????Exporter????????@ISA???????????????????????????????????@EXPORT?????§à????????????????????closeMain??declareMain????????¡ê?
                @EXPORT = qw (declareMain , closeMain);
                Perl??????????@ISA?????????@ISA???õ™??????¦Ê???§Ø??ÈÉ???????????????ÈÉPerl??????????????????????î•????@INC?????????@INC?????????????¡¤????@ISA???üA????(??)?????????????????????¦Ä???????@ISA?§Ö???????@ISA?§Ý????§Ö?????§Ö????????
                ???§Ö???????§Ù??????????????????@ISA???úE??????????????????@ISA??????¦Ä?????Perl???AUTOLOAD()??????????????????????????????????sub???‰^?????AUTOLOAD???????????use Autoload;??????autoload.pm????AUTOLOAD??????????????Perl???????????????????AUTOLOAD???????Perl???UNIVERSAL?????????¦Ã?????????????Perl??????????????????????????
            ????????????
                ????????????????????????????????????????????ú›????????????????????????????????????¡Â????????????????????Cocoa???????§»?????????????¡ê?
            package Cocoa;
            require Exporter;
            @ISA = qw(Exporter);
            @EXPORT = qw(setImports, declareMain, closeMain);
            #
            # This routine creates the references for imports in Java functions
            #
            sub setImports{
              my $class = shift @_;
              my @names = @_;
              foreach (@names) {
                print "import " . $_ . ";\n";
              }
            }
            #
            # This routine declares the main function in a Java script
            #
            sub declareMain{
              my $class = shift @_;
              my ( $name, $extends, $implements) = @_;
              print "\n public class $name";
              if ($extends) {
                print " extends " . $extends;
              }
              if ($implements) {
                print " implements " . $implements;
              }
              print " { \n";
            }
            #
            # This routine declares the main function in a Java script
            #
            sub closeMain{
              print "} \n";
            }
            #
            # This subroutine creates the header for the file.
            #
            sub new {
              my $this = {};
              print "\n /* \n ** Created by Cocoa.pm \n ** Use at own risk \n */ \n";
              bless $this;
              return $this;
            }

            1;
                ?????????§Õ???????Perl?????????????????????????????Java applet??????????????
            #!/usr/bin/perl
            use Cocoa;
            $cup = new Cocoa;
            $cup->setImports( 'java.io.InputStream', 'java.net.*');
            $cup->declareMain( "Msg" , "java.applet.Applet", "Runnable");
            $cup->closeMain();
                ??¦Í???????????????Msg??Java applet???????(extend)??java.applet.Applet§³??¨®???????????(runnable)??????????????????§Õ?????¡ê?
            Cocoa::setImports($cup, 'java.io.InputStream', 'java.net.*');
            Cocoa::declareMain($cup, "Msg" , "java.applet.Applet", "Runnable");
            Cocoa::closeMain($cup);
                ?????§ß?????¡ê?
            /*
            ** Created by Cocoa.pm
            ** Use at own risk
            */
            import java.io.InputStream;
            import java.net.*;

            public class Msg extends java.applet.Applet implements Runnable {
            }
                ????????->?????????¡Â???????§Þ???????????????????????????????»Ç$cup->setImports( 'java.io.InputStream', 'java.net.*');???e??????»ÇCocoa::setImports($cup, 'java.io.InputStream', 'java.net.*');??????????§Õ???Cocoa::setImports $cup, 'java.io.InputStream', 'java.net.*' ;
            ???????
                ????????????????????????????????????????????????????????Espresso??Qava???????????grind????????::????????????Qava???????
                $mess = Qava::grind("whole","lotta","bags");
                Qava::grind($mess, "whole","lotta","bags");
                ???????????????????????????????????????????????¡Â??????????????????
                $method = $local ? "Qava::" : "Espresso::";
                $cup->{$method}grind(@args);
            ???????????
                Perl????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????§Õ??????????
                ??????????????????????????????????DESTROY()??????DESTROY()?????????????????????????§»?????????DESTROY()?????????????????DESTROY()??????Perl???????????????????????????????????bless??DESTROY()??????????????????DESTROY()???????????????????????????????§Ø???????????????????
                ?????????????????DESTROY()??????????????????????¡ê?
            sub DESTROY {
            #
            # Add code here.
            #
            }
                ???????????Perl???????????????????????????????¦Ê¦Æ??????????????????????????????????????????????????Perl???????????????????????????????????????§Ö???§Ò????????????UNIX??????§µ???????????????????????????????????????????
            ??????
                ???????@ISA?????§µ????????§Ò???????Ú…????????????????Bean.pm??Coffee.pm??????Coffee.pm???Bean.pm???§»??????????????¦Ä?????????????????????????????????????????????????????????????????§³?
                Bean.pm???????¡ê?
            package Bean;
            require Exporter;
            @ISA = qw(Exporter);
            @EXPORT = qw(setBeanType);

            sub new {
              my $type = shift;
              my $this = {};
              $this->{'Bean'} = 'Colombian';
              bless $this, $type;
              return $this;
            }

            #
            # This subroutine sets the class name
            sub setBeanType{
              my ($class, $name) = @_;
              $class->{'Bean'} = $name;
              print "Set bean to $name \n";
            }
            1;
                ?????§µ???$this???????????????????????'Bean'???????'Colombian'??????setBeanType()??????'Bean'??????????$class???????????????????
                Coffee.pm???????¡ê?
            1  #
            2  # The Coffee.pm file to illustrate inheritance.
            3  #
            4  package Coffee;
            5  require Exporter;
            6  require Bean;
            7  @ISA = qw(Exporter, Bean);
            8  @EXPORT = qw(setImports, declareMain, closeMain);
            9  #
            10 # set item
            11 #
            12 sub setCoffeeType{
            13   my ($class,$name) = @_;
            14   $class->{'Coffee'} = $name;
            15   print "Set coffee type to $name \n";
            16   }
            17 #
            18 # constructor
            19 #
            20 sub new {
            21   my $type = shift;
            22   my $this = Bean->new(); ##### <- LOOK HERE!!! ####
            23   $this->{'Coffee'} = 'Instant'; # unless told otherwise
            24   bless $this, $type;
            25   return $this;
            26   }
            27 1;
                ??6?§Ö?require Bean;????????Bean.pm?????????????????????setCoffeeType()???????t??????$class->{'Coffee'}????????????new()?§µ?$this???Bean.pm????????????????????????????????????????????????????????????????????Bean.pm??????????????????????????§Ö??????
                my $this = {}; #????
                my $this = $theSuperClass->new(); #???
                ????????????¦Å??¨¹?§Ö??????
            1  #!/usr/bin/perl
            2  push (@INC,'pwd');
            3  use Coffee;
            4  $cup = new Coffee;
            5  print "\n -------------------- Initial values ------------ \n";
            6  print "Coffee: $cup->{'Coffee'} \n";
            7  print "Bean: $cup->{'Bean'} \n";
            8  print "\n -------------------- Change Bean Type ---------- \n";
            9  $cup->setBeanType('Mixed');
            10 print "Bean Type is now $cup->{'Bean'} \n";
            11 print "\n ------------------ Change Coffee Type ---------- \n";
            12 $cup->setCoffeeType('Instant');
            13 print "Type of coffee: $cup->{'Coffee'} \n";
                ??????????????¡ê?
            -------------------- Initial values ------------
            Coffee: Instant
            Bean: Colombian
            -------------------- Change Bean Type ----------
            Set bean to Mixed
            Bean Type is now Mixed
            ------------------ Change Coffee Type ----------
            Set coffee type to Instant
            Type of coffee: Instant
                ?????????§µ?????????????????????????'Bean'??'Coffee'????????????????????????????????
                ?????????§Ø??????????????Coffee.pm??????????makeCup()?????????¡ê?
            sub makeCup {
              my ($class, $cream, $sugar, $dope) = @_;
              print "\n================================== \n";
              print "Making a cup \n";
              print "Add cream \n" if ($cream);
              print "Add $sugar sugar cubes\n" if ($sugar);
              print "Making some really addictive coffee ;-) \n" if ($dope);
              print "================================== \n";
            }
                ?????????????????????????????????????????????????»Ç
            1  #!/usr/bin/perl
            2  push (@INC,'pwd');
            3  use Coffee;
            4  $cup = new Coffee;
            5  #
            6  # With no parameters
            7  #
            8  print "\n Calling with no parameters: \n";
            9  $cup->makeCup;
            10 #
            11 # With one parameter
            12 #
            13 print "\n Calling with one parameter: \n";
            14 $cup->makeCup('1');
            15 #
            16 # With two parameters
            17 #
            18 print "\n Calling with two parameters: \n";
            19 $cup->makeCup(1,'2');
            20 #
            21 # With all three parameters
            22 #
            23 print "\n Calling with three parameters: \n";
            24 $cup->makeCup('1',3,'1');
                ??????????¡ê?
            Calling with no parameters:
            ==================================
            Making a cup
            ==================================
            Calling with one parameter:
            ==================================
            Making a cup
            Add cream
            ==================================
            Calling with two parameters:
            ==================================
            Making a cup
            Add cream
            Add 2 sugar cubes
            ==================================
            Calling with three parameters:
            ==================================
            Making a cup
            Add cream
            Add 3 sugar cubes
            Making some really addictive coffee ;-)
            ==================================
                ??????§µ?????makeCup()????????????????????????????????????????????????????????????????????????????????§µ???????????????????????????????????????????ÙM??????
            ????????????????
                ??§Ö?????????????????????????????????????????????????????????????????????????Bean.pm???§Þ?????printType()?????????¡ê?
            sub printType {
              my $class = shift @_;
              print "The type of Bean is $class->{'Bean'} \n";
            }
                ????????@EXPORT???????????
                @EXPORT = qw ( setBeanType , printType );
                ?????????¨²???printType()??????????¡Â?????
            $cup->Coffee::printType();
            $cup->printType();
            $cup->Bean::printType();
                ?????????¡ê?
            The type of Bean is Mixed
            The type of Bean is Mixed
            The type of Bean is Mixed
                ????????????????????????§Ø??Žï??printType()????????????????????§Ö?????????????????????????printType()????????????Coffee.pm???§Þ?????‰Ø
            #
            # This routine prints the type of $class->{'Coffee'}
            #
            sub printType {
              my $class = shift @_;
              print "The type of Coffee is $class->{'Coffee'} \n";
            }
                ????????@EXPORT???ï“
                @EXPORT = qw(setImports, declareMain, closeMain, printType);
                ????????????????
            The type of Coffee is Instant
            The type of Coffee is Instant
            The type of Bean is Mixed
                ??????§Ö???????Bean::???????????????????????????????????
                ?????????????????????¦Å????????????????????¦Á??????SUPER::????????????????»Ç$this->SUPER::function(...argument list...); ????????@ISA?§Ò????????????????SUPER::?�IBean::????§Õ?$cup->SUPER::printType(); ?????????????????
            The type of Bean is Mixed
            ?????Perl????????§»???
                OOP?????????????????¨¢?OOP???????????????§»????????Perl???????????my?????????????????????Perl????????????????????????????????????????????????????????????????????????????????????????????
            ???
            1??????????????????????????
            2????????????????????????????
                ????§Õ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????local()?????ÈÉ??????????????????????????????????????????????????????????????????????????¦Ì?????????????????????????????????????????????????????????
                ????????????¡¤?????????????
                use coffee::Bean;
                ???????????????@INC????????????Coffee?????????Bean.pm?????????Bean.pm???./Coffee???????????????????use????????????????????????????????????????íà????????
                use Another::Sub::Menu;
                ??¦Æ??????????????
                ./Another/Sub/Menu.pm

            ????? ????? ??


            paper | appdir | ssv
            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      ÑÇÖÞÅ·ÃÀÔÚÏß