zoukankan      html  css  js  c++  java
  • perl 里面如何写出阅读友好的代码提示

    在我们使用别人写好的程序时,经常会使用-h 之类的东西查看一下简单的帮助手册或者说明信息;

    对于perl 语言而言,写起来简单,经常随手一写,解决了当时的问题,但是过几天去看,你都不知道这个脚本该怎么调用,是用来做什么的;

    为了避免这样的情况,对于常用的脚本,有必要提供较为清晰的帮助文档。

    在perl 里面,官方提供了这样的注释手段,看下面的代码示例

    =pod
    
    =head1 NAME
    
    L<Transdecoder.LongOrfs|http://transdecoder.github.io> - Transcriptome Protein Prediction
    
    =head1 USAGE
    
    Required:
    
     -t <string>                            transcripts.fasta
    
    Optional:
    
     --gene_trans_map <string>              gene-to-transcript identifier mapping file (tab-delimited, gene_id<tab>trans_id<return> ) 
    
     -m <int>                               minimum protein length (default: 100)
     
     -G <string>                            genetic code (default: universal; see PerlDoc; options: Euplotes, Tetrahymena, Candida, Acetabularia)
    
     -S                                     strand-specific (only analyzes top strand)
    
    =head1 Genetic Codes
    
    See L<http://golgi.harvard.edu/biolinks/gencode.html>. These are currently supported:
    
     universal (default)
     Euplotes
     Tetrahymena
     Candida
     Acetabularia
     Mitochondrial-Canonical
     Mitochondrial-Vertebrates
     Mitochondrial-Arthropods
     Mitochondrial-Echinoderms
     Mitochondrial-Molluscs
     Mitochondrial-Ascidians
     Mitochondrial-Nematodes
     Mitochondrial-Platyhelminths
     Mitochondrial-Yeasts
     Mitochondrial-Euascomycetes
     Mitochondrial-Protozoans
    
    =cut

    =pod 到 =cut 之间的内容是帮助信息,这些信息显示到屏幕上时是这样的

    NAME
        <Transdecoder.LongOrfs> - Transcriptome Protein Prediction
    
    USAGE
        Required:
    
         -t <string>                            transcripts.fasta
    
        Optional:
    
         --gene_trans_map <string>              gene-to-transcript identifier mapping file (tab-delimited, gene_id<tab>trans_id<return> ) 
    
         -m <int>                               minimum protein length (default: 100)
     
         -G <string>                            genetic code (default: universal; see PerlDoc; options: Euplotes, Tetrahymena, Candida, Acetabularia)
    
         -S                                     strand-specific (only analyzes top strand)
    
    Genetic Codes
        See <http://golgi.harvard.edu/biolinks/gencode.html>. These are
        currently supported:
    
         universal (default)
         Euplotes
         Tetrahymena
         Candida
         Acetabularia
         Mitochondrial-Canonical
         Mitochondrial-Vertebrates
         Mitochondrial-Arthropods
         Mitochondrial-Echinoderms
         Mitochondrial-Molluscs
         Mitochondrial-Ascidians
         Mitochondrial-Nematodes
         Mitochondrial-Platyhelminths
         Mitochondrial-Yeasts
         Mitochondrial-Euascomycetes
         Mitochondrial-Protozoans

    有表头部分,格式上也很整齐,通过=head1 , =pod , =cut 这几个小标签,我们只需要关注内容,就可以写出格式整齐,阅读良好的帮助信息

    use Pod::Usage;
    
    pod2usage(-verbose => 2, -output => *STDERR) if ($help);

    通过使用Pod::Usage 模块,加可以将写好的上述格式的注释,方便的显示在屏幕上,结合if 等判断语句,自定义触发条件;

  • 相关阅读:
    flask 源码专题(七):threading.local和高级
    flask 源码专题(六):session处理机制
    flask 源码专题(五):SqlAlchemy 中操作数据库时session和scoped_session的区别
    flask 源码专题(四):wtforms Form实例化流程以及csrf验证
    flask 源码专题(三):请求上下文和应用上下文入栈与出栈
    python 追踪函数调用
    flask 源码专题(一):app.run()的背后
    flask 源码专题(二):请求上下文与全文上下文
    边框间距 | border-spacing (Miscellaneous Level 2)
    边框样式属性 | border-top-style (Backgrounds & Borders)
  • 原文地址:https://www.cnblogs.com/xudongliang/p/8431626.html
Copyright © 2011-2022 走看看