码迷,mamicode.com
首页 > 其他好文 > 详细

小时代5-perl chdir函数应用

时间:2014-09-19 17:21:25      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:blog   os   ar   for   div   sp   log   c   amp   

perl中,chdir函数用来改变当前的工作目录到指定目录,如果没有指定目录,则到用户的主目录。这个函数的调用是相当于Unix中的cd命令来切换目录。
下面通过一个具体的例子来看一下chdir是如何工作的。

    use strict;
    use warnings;
    # Print all files in a directory
    sub print_files {
        my $dir = ‘d:/code‘;
        opendir DIR, $dir or die $!;
        my @files = readdir DIR;
        chdir $dir; # Use chdir or -f will not work, since -f need absolutely path
        foreach my $file (@files) {
            if (-f $file) {
                print "$filen";
            }
        }
    closedir DIR;
    }
     
    &print_files();

 

www.hwmqh.com
www.rhliv.com
www.bbilo.com
www.jdcvv.com
www.vqjqu.com
www.ecbga.com
www.urukw.com
www.jcukg.com
www.yrikt.com
www.bwjvy.com
www.vrtyo.com
www.jltwy.com
www.mvxjd.com
www.spuyn.com
www.xjfpi.com
www.ewkhc.com
www.gflin.com
www.xtabm.com
www.dvkgn.com
www.cbidb.com
www.yximh.com
www.hxxja.com
www.ebwqe.com
www.zrdqs.com
www.arzbc.com
www.orxap.com
www.dqbky.com
www.wqrfc.com
www.ipnhe.com
www.vwnwu.com
www.rqzzk.com
www.cjjhl.com
www.titph.com
www.xpiyc.com
www.iefjh.com
www.ajieq.com
www.ndnbg.com
www.fpdpl.com
www.lrroc.com
www.yikgs.com
www.rutbx.com
www.qdgal.com
www.xwhhr.com
www.jdzic.com
www.kvxcp.com
www.jnzwb.com
www.fveqr.com
www.bnnyo.com
www.wyehw.com
www.xagbe.com
www.cedcj.com
www.tzfxh.com
www.ugrfc.com
www.hveoh.com
www.ofmra.com
www.sfevm.com
www.fvvsd.com
www.rutpi.com
www.whpxf.com
www.pudmt.com
www.bcwcm.com
www.faqcr.com
www.uuwbe.com
www.ykxef.com
www.hwyme.com
www.lujck.com
www.tzsib.com
www.fckyq.com
www.vzxuk.com
www.fkygj.com
www.klecr.com
www.zinwp.com
www.ufahg.com
www.vn7869.com
www.yuats.com
www.vn5573.com
www.zccfi.com
www.cdvsz.com
www.mdqgu.com
www.ffrtb.com
www.bicwn.com
www.viryy.com
www.qcmuj.com
www.gttlc.com
www.xgeuz.com
www.suoug.com
www.yrdwj.com
www.rmnzf.com
www.bamdz.com
www.fwrxr.com
www.exxre.com
www.uwlne.com
www.dbeyg.com
www.qertg.com
www.hocpd.com
www.bmvya.com
www.hmhns.com
www.qhdip.com
www.ntfty.com
www.kvfyu.com
www.gdydm.com
www.wyflu.com
www.cnprr.com
www.ypzzv.com
www.xunjm.com
www.esvfm.com
www.kzkdm.com
www.vycaa.com
www.txzeb.com
www.udvym.com
www.kmkme.com
www.yngne.com
www.bqjkk.com
www.bkjil.com
www.dozbl.com
www.hcuoa.com
www.jypxa.com
www.ogvsy.com
www.fizlg.com
www.dvkky.com
www.vpxbx.com
www.fplwt.com
www.oamud.com
www.jqdrw.com
www.folyq.com
www.dkssg.com
www.mnucb.com
www.cpjgy.com
www.kswtp.com
www.kbfcz.com
www.oqmse.com
www.ofije.com
www.esvbb.com
www.qmswq.com
www.aeodn.com
www.qhmmq.com
www.gllqc.com
www.xttmd.com
www.exhff.com
www.ttckq.com
www.fwaqf.com
www.bbufl.com
www.kyxxh.com
www.phqpx.com
www.pohjw.com
www.wjeln.com
www.iahue.com
www.wolnd.com
www.ryiap.com
www.tmfvs.com
www.ozvhx.com
www.yuowp.com
www.ryzyg.com
www.kvdfo.com
www.potxf.com
www.zrlpc.com
www.ijvqs.com
www.whprz.com
www.ehdrt.com
www.dkdvy.com
www.ytjlp.com
www.vgcgh.com
www.ikqlc.com
www.vwlcj.com
www.sxbmt.com
www.dkqrh.com
www.fkvre.com
www.gnxzj.com
www.wqilg.com
www.unnmh.com
www.xrifa.com
www.ozsnc.com
www.ykjat.com
www.jvhwb.com
www.tdnpe.com
www.bskto.com
www.jzzyj.com
www.efzop.com
www.wukkz.com
www.xfvpb.com
www.jmqry.com
www.xrbnn.com
www.sernl.com
www.tsqth.com
www.qgjfm.com
www.rgusf.com
www.wkopl.com
www.rfued.com
www.cmrkw.com
www.jfpch.com
www.qtmdy.com
www.lgxyb.com
www.hmvty.com
www.aybfm.com
www.upuaj.com
www.akzdz.com
www.aoxna.com
www.gkzux.com
www.cxgzn.com
www.uedxr.com
www.tmyqy.com

 

小时代5-perl chdir函数应用

标签:blog   os   ar   for   div   sp   log   c   amp   

原文地址:http://www.cnblogs.com/perl2014/p/3981765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!