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

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

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

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


            ??????  ?????

            ??????????/???????
              1??????I/O????
                1)open????
                2)??open?????????
                3)????????
                4)?????д???
                5)close????
                6)print, printf??write????
                7)select????
                8)eof????
                9)??????????
              2???????????????
              3??????д????
              4????getc??????
              5????binmode????????????
            ?????????????
              1??mkdir
              2??chdir
              3??opendir
              4??closedir
              5??readdir
              6??telldir
              7??seekdir
              8??rewinddir
              9??rmdir
            ??????????????
              1????????λ????
              2?????????????????
              3?????????????
              4?????????????
            ??????DBM???

                ??????????????????????UNIX????????????????UNIX???У??Щ??????????ж?????в???????????????????Perl?????????
            ??????????/???????
                ?????????????ж????????????д????????????????
            1??????I/O????
                ?ЩI/O??????????????????н???????
          1. open???????????????
          2. close????????????
          3. print?????д???????
          4. write???????д?????????
          5. printf??????????????????????
          6.     ??????????£?????Щ???δ?????????
            1)open????
                open?????????????????????????????????????????????磺open(MYVAR, "/u/file"); ????????????????????????????????????open????????????????????????????д??????????????????????????open(MYVAR, ">/u/file"); ?????е?????β???????????????????open(MYVAR, ">>/u/file"); ????????????????????????????????????????(|)??open(MAIL, "|mail dave");
            2)??open?????????
                ??????????????????????????????????????????????????????(|)???磺
                open(CAT, "cat file*|");
                ??open?????????????cat file* ?????????????????????????????????????????file???????????????????????????????????????????????????CAT??????磺
                $input = ;
                ????????????????w????????г????????????????????
            1 : #!/usr/local/bin/perl
            2 :
            3 : open (WOUT, "w|");
            4 : $time = <WOUT>;
            5 : $time =~ s/^ *//;
            6 : $time =~ s/ .*//;
            7 : ; # skip headings line
            8 : @users = ;
            9 : close (WOUT);
            10: foreach $user (@users) {
            11:   $user =~ s/ .*//;
            12: }
            13: print ("Current time: $time");
            14: print ("Users logged on:\n");
            15: $prevuser = "";
            16: foreach $user (sort @users) {
            17:   if ($user ne $prevuser) {
            18:     print ("\t$user");
            19:     $prevuser = $user;
            20:   }
            21: }
                ?????????£?
            Current time: 4:25pm
            Users logged on:
              dave
              kilroy
              root
              zarquon
                w?????г??????????????????????????????????????????????е??????磺
              4:25pm  up 1 day,  6:37,  6 users,  load average: 0.79, 0.36, 0.28
            User     tty       login@  idle   JCPU   PCPU what
            dave     ttyp0     2:26pm           27      3 w
            kilroy   ttyp1     9:01am  2:27   1:04     11 -csh
            kilroy   ttyp2     9:02am    43   1:46     27 rn
            root     ttyp3     4:22pm     2               -csh
            zarquon  ttyp4     1:26pm     4     43     16 cc myprog.c
            kilroy   ttyp5     9:03am         2:14     48 /usr/games/hack
            
                ?????д?w???????????????????????????????????????????3??????w?????????open????????w???????????????????????????WOUT?????????????4?ж????????????????
                4:25pm up 1 day, 6:37, 6 users, load average: 0.79, 0.36, 0.28
                ???????????д??????г??????????????5????????????????6???????????β???з?????????????????????$time??
                ??7?д?WOUT???????У??????????????????????????????8?а???μ??и???????@users??????9?й??WOUT?????????w?????????
                @users?е????????????????????????????????????е?????????????????????10~12?????????з?????????????????????????@users??????????????б??
                ??13???????????$time?е??????????print???????????з??????$time???С?16~21?ж?@users?е??????????????????????????????ε??????????$preuser???????????????????????′???????????$user??????????$preser???????????
            3)????????
                ???UNIX shell?????????????(STDOUT)???????????(STDERR)??????????????????????Bourne Shell??sh???У?????
                $ foo > file1 2>&1
                ????????foo???????????????????????????????????????????file1?С?????????Perl????????????????
            1: #!/usr/local/bin/perl
            2:
            3: open (STDOUT, ">file1") || die ("open STDOUT failed");
            4: open (STDERR, ">&STDOUT") || die ("open STDERR failed");
            5: print STDOUT ("line 1\n");
            6: print STDERR ("line 2\n");
            7: close (STDOUT);
            8: close (STDERR);
                ???к????file1?е????????
                 line 2
                 line 1
                ??????????????в?δ????????????????????????????????????????γ???
                ??3???????????????????????????file1?????????????STDOUT??????????????????????????4??????????????????????>&STDOUT????Perl????????????????STDOUT????????????????????STDERR?????STDOUT????????????5??6?з????STDOUT??STDERRд????????????????????????????????????????????????д?????file1?У????????????????????????
                ????????UNIX??????????????????print??????????????д??STDOUT????????UNIX?????????????????????????????????????漴???????У????????????????????д?????????д???????????????????????????????????????????д????????????????????????????????ζ?????????????????????????????????I/O?????????????
                ???????????κη?????????????????????????STDOUT??STDERR?????????????????????????STDERR???????????????STDERR????????е?????line 2???????????STDOUT????????е?????line 1????
                ???????????????????Perl??????????????????壬???????
                 1????select??????????
                 2?????1??????????$|
                ??????$|???????????л?????????????????????塣???$|?????????????塣$|????????$~??$^Э?????????δ????select???????$|????????????????????????????
            1 : #!/usr/local/bin/perl
            2 :
            3 : open (STDOUT, ">file1") || die ("open STDOUT failed");
            4 : open (STDERR, ">&STDOUT") || die ("open STDERR failed");
            5 : $| = 1;
            6 : select (STDERR);
            7 : $| = 1;
            8 : print STDOUT ("line 1\n");
            9 : print STDERR ("line 2\n");
            10: close (STDOUT);
            11: close (STDERR);
                ???????к????file1?????????
                 line 1
                 line 2
                ??5?н?$|????1??????Perl???????????????????л??壬???δ????select?????????????????????file1??STDOUT????6?н????????????STDERR????7????????$|?1????????????file1???????????????塣????STDOUT??STDERR?????????????????????????д??????У????line 1?????????С?
            4)?????д???
                ????????????д???????????????????????"+>"?????£?
                 open (READWRITE, "+>file1");
                ?????????????д?????file1??????????д???е???????????д????????????seek??tell???????????????????????κ????
                ??????????"+<"??????д????
            5)close????
                ??????????????????close????????????????????????????????????????????磺
                 open (MYPIPE, "cat file*|");
                 close (MYPIPE);
                ??????????????????????????У????????cat file*????????
            6)print, printf??write????
                print????????????????????????????????????????δ?????????????????????У??磺
                 print ("Hello, there!\n");
                 print OUTFILE ("Hello, there!\n");
                ???????????????????У???δ????select?????STDOUT?????????????????????OUTFILE?????????С?
                printf?????????????????????????????????????У??磺
                 printf OUTFILE (??You owe me %8.2f", $owing);
                ????????????$owing??????滻????е?%8.2f??%8.2f???????????????$owing???????????????
                write???????????????????????????У??磺
                 select (OUTFILE);
                 $~ = "MYFORMAT";
                 write;
                ????printf??write?????????x?? ????????????
            7)select????
                select??????????????????????????????μ???????????磺
                 select (MYFILE);
                ??????MYFILE??????????????????print??write??printf?????δ????????????????MYFILE?С?
            8)eof????
                eof???????????ζ???????????????????????????????????????????????????????????????
                ???????£???eof????ò???????????eof??eof()???Ч???????<>???????????????eof??eof()????????????????????????????????????file1??file2??file1?????????
                 This is a line from the first file.
                 Here is the last line of the first file.
                file2?????????
                 This is a line from the second and last file.
                 Here is the last line of the last file.
                ????????????eof??eof()??????????????????
            1: #!/usr/local/bin/perl
            2:
            3: while ($line = <>) {
            4:   print ($line);
            5:   if (eof) {
            6:     print ("-- end of current file --\n");
            7:   }
            8: }
                ???н?????£?
            $ program file1 file2
            This is a line from the first file.
            Here is the last line of the first file.
            -- end of current file --
            This is a line from the second and last file.
            Here is the last line of the last file.
            -- end of current file --
            $
                ?????eof???eof()??????????????
            1: #!/usr/local/bin/perl
            2:
            3: while ($line = <>) {
            4:   print ($line);
            5:   if (eof()) {
            6:     print ("-- end of output --\n");
            7:   }
            8: }
                ???н?????£?
            $ program file1 file2
            This is a line from the first file.
            Here is the last line of the first file.
            This is a line from the second and last file.
            Here is the last line of the last file.
            -- end of output --$
                ????????????????????????eof()??????棬?????????????????????β????????????????????????????
            9)??????????
                ??????????????open, close, print, printf, write, select??eof?????????ü?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????open, close, write, select??eof??????????????????????????????????????????????????????????????
            1: #!/usr/local/bin/perl
            2:
            3: &open_file("INFILE", "", "file1");
            4: &open_file("OUTFILE", ">", "file2");
            5: while ($line = &read_from_file("INFILE")) {
            6:   &print_to_file("OUTFILE", $line);
            7: }
            8:
            9: sub open_file {
            10:   local ($filevar, $filemode, $filename) = @_;
            11:
            12:   open ($filevar, $filemode . $filename) ||
            13:     die ("Can't open $filename");
            14: }
            15: sub read_from_file {
            16:   local ($filevar) = @_;
            17:
            18:   <$filevar>;
            19: }
            20: sub print_to_file {
            21:   local ($filevar, $line) = @_;
            22:
            23:   print $filevar ($line);
            24: }
            2???????????????

            ?????? seek
            ?????? seek (filevar, distance, relative_to);
            ??? ??????????/???????????????????
            1??filevar?????????
            2??distance?????????????????????????????????????
            3??reletive_to??????0??1??2???0??????????????????1??????????λ??????????????У???????2????????????β?????
            ???г???????棨??????????????????????tell???????á?

            ?????? tell
            ?????? tell (filevar);
            ??? ??????????????λ??????
            ???
            1??seek??tell????????????????????????
            2??seek??tell???????????????????????

            3??????д????

            ?????? read
            ?????? read (filevar, result, length, skipval);
            ??? read??????????UNIX??fread??????Ч???????????????????????????????????????????????????
            1??filevar?????????
            2??result????????????????????????????
            3??length????????????
            4??skipval??????????????????????????????
            ????????????????????????????????β????????????????????????

            ?????? sysread
            ?????? sysread (filevar, result, length, skipval);
            ??? ??????????????UNIX????read??Ч????????read?????

            ?????? syswrite
            ?????? syswrite (filevar, data, length, skipval);
            ??? ?????д?????????UNIX????write??Ч????????
            1??filevar?????д??????
            2??data???????д??????????
            3??length???д????????
            4??skipvalд???????????????????

            4????getc??????

            ?????? getc
            ?????? $char = getc (infile);
            ??? ??????ж???????????

            5????binmode????????????

            ?????? binmode
            ?????? binmode (filevar);
            ??? ?????????????DOS?????????????????????????????????á??????????????????????á?

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

            ?????? mkdir
            ?????? mkdir (dirname, permissions);
            ??? ?????????????????
            1??dirname????????????????????????????????
            2??permissions??8?????????????????????????????????±?????????????????????????

            ? ???
            4000   ????????????ID  
            2000 ???????????ID
            1000 ???λ
            0400 ?????????
            0200 ?????д???
            0100 ???????????
            0040 ??????
            0020 ??д???
            0010 ????????
            0004 ??????????
            0002 ??????д???
            0001 ????????????

            ?????? chdir
            ?????? chdir (dirname);
            ??? ????????????????dirname????????????????????????

            ?????? opendir
            ?????? opendir (dirvar, dirname);
            ??? ???????????漸???????????????????????б?????????
            1??dirvar???????????????????????
            2??dirname?????????????????????
            ????????????????????
            ????????п????????????????????????????????????????

            ?????? closedir
            ?????? closedir (mydir);
            ??? ??????????

            ?????? readdir
            ?????? readdir (mydir);
            ??? ???????????????θ?????????????????????????????????????????????

            ?????? telldir
            ?????? location = telldir (mydir);
            ??? ????????????????????telldir???????seekdir?????????б???????????

            ?????? seekdir
            ?????? seekdir(mydir, location);
            ??? location?????telldir????????

            ?????? rewinddir
            ?????? rewinddir (mydir);
            ??? ?????????λ????????????????????????б??

            ?????? rmdir
            ?????? rmdir (dirname);
            ??? ?????????????????棨????????????????????????

            ??????????????
            1????????λ????

            ?????? rename
            ?????? rename (oldname, newname);
            ??? ???????????????????????У????????????????????

            ?????? unlink
            ?????? num = unlink (filelist);
            ??? ???????????????????б????????????????????????
            ???????????unlink??????delete???????????????????????????????

            2?????????????????

            ?????? link
            ?????? link (newlink, file);
            ??? ?????????????????--??????file?????????????newlink??????????????
            ????????棬????????
            ????????????????е????????????????????????????????

            ?????? symlink
            ?????? symlink (newlink, file);
            ??? ????????????????????????????????????????????????????????????????
            ??????????????磺??unlinke??????????????????????????????????????????????????????????????

            ?????? readlink
            ?????? filename = readlink (linkname);
            ??? ???linkname??????????????????????????????????????????

            3?????????????

            ?????? chmod
            ?????? chmod (permissions, filelist);
            ??? ??????????????????????
            1??permissions??????????????京???????mkdir??????
            2??filelist??????????????б?

            ?????? chown
            ?????? chown (userid, groupid, filelist);
            ??? ??????????????????????????
            1??userid??????????(????)ID??
            2??groupid???μ???(????)ID???-1????????
            3??filelist?????????????????б?

            ?????? umask
            ?????? oldmaskval = umask (maskval);
            ??? ???????????????????????????????

            4?????????????

            ?????? truncate
            ?????? truncate (filename, length);
            ??? ??????????????length?????????????????С??length???????κ????????filename?????????????????????????

            ?????? stat
            ?????? stat (file);
            ??? ??????????????file??????????????????????????б???????????
          7. ????????豸
          8. ????ο???(inode)
          9. ???????
          10. ???????
          11. ??????(????)ID
          12. ???????(????)ID
          13. ?豸????????file???豸?????
          14. ?????С?????????
          15. ?????????
          16. ?????????
          17. ??????????
          18. I/O?????????С
          19. ???????????????
          20. ?????? lstat
            ?????? lstat (file);
            ??? ??stat????????????file??????????????

            ?????? time
            ?????? currtime = time();
            ??? ?????1970??1??1?????????????

            ?????? gmtime
            ?????? timelist = gmtime (timeval);
            ??? ????time, stat ?? -A ?? -M ????????????????????????????????????????б???????????
          21. ??
          22. ????
          23. С???0~23
          24. ????
          25. ?·??0~11(???~?????)
          26. ???
          27. ?????0~6(????~????)
          28. ????е??????0~364
          29. ????????????

          30. ???UNIX??gmtime??????

            ?????? localtime
            ?????? timelist = localtime (timeval);
            ??? ??gmtime???????????????????????????

            ?????? utime
            ?????? utime (acctime, modtime, filelist);
            ??? ??????????????????????????????磺
            $acctime = -A "file1";
            $modtime = -M "file1";
            @filelist = ("file2", "file3");
            utime ($acctime, $modtime, @filelist);

            ?????? fileno
            ?????? filedesc = fileno (filevar);
            ??? ????????????UNIX?????????????filevar??????????

            ?????? fcntl
            flock
            ?????? fcntl (filevar, fcntlrtn, value);
            flock (filevar, flockop);
            ??? ??????UNIX??????????

            ??????DBM???
               Perl?п??ù?????????????DBM????????ú????dbmopen??dbmclose????Perl5?У?????tie??untie???檔

            ?????? dbmopen
            ?????? dbmopen (array, dbmfilename, permissions);
            ??? ????????????DBM?????????????????
            1??array?????ù???????
            2??dbmfilename????????DBM?????
            3?????????????mkdir

            ?????? dbmclose
            ?????? dbmclose (array);
            ??? ???DBM?????????????????????????



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

            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>

                      亚洲欧美在线