设为首页 收藏本站
查看: 480|回复: 0

[经验分享] Perl log 0906

[复制链接]

尚未签到

发表于 2015-12-27 08:28:21 | 显示全部楼层 |阅读模式
1. comment and uncomment
this page is very comprehensive about commenting in vim.
After trial and error, the plugin alternative is chosen.
http://www.straw-dogs.co.uk/01/05/comment-multiple-lines-in-vim/

Below is how-to use the plugin, multiple-line comment and uncomment(not applicable)
description
Global Plugin to comment and un-comment lines in different source files in both normal and visual <Shift-V> mode
usage:
ctrl-c to comment a single line
ctrl-x to un-comment a single line
shift-v and select multiple lines, then ctrl-c to comment the selected multiple lines
shift-v and select multiple lines, then ctrl-x to un-comment the selected multiple lines
supports: c, c++, java, php[2345], proc, css, html, htm, xml, xhtml, vim, vimrc, sql, sh, ksh, csh, perl, tex, fortran, ml, caml, ocaml, vhdl, haskel and normal files

Only ctrl-c and ctrl-x are used, but also powerful enough.

2. chop()
if no chop on the file line input, no futher file tests can be conducted.
The purpose is choping away the return cursor.

3. system()
http://perldoc.perl.org/functions/system.html
Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).


A friend at work said that in his experience, the return code from "system" isn't reliable when used that way. He said I should capture the actual return code from the system call and evaluate it. If it's not zero, there's an error and to print $! at that point. I followed his recommendation and the problem went away. Here's the code I used.
use strict;
&doSystemCommand(  "cp /analysis/fasta1.fa /analysis2/fasta1.fa"  );

sub doSystemCommand
{
    my $systemCommand = $_[0];

    print LOG "$0: Executing [$systemCommand] \n";
    my $returnCode = system( $systemCommand );

    if ( $returnCode != 0 )
    {
        die "Failed executing [$systemCommand]\n";
    }
}
~~~~~
The return code from "system" is not unreliable, you're just interpreting it backwards. It's a really easy mistake to make - the shell interprets 0 as success and nonzero as failure. So a zero return code from a system call means it succeeded. The actual return code, if nonzero, is returned in the high-order byte of the return code, so if the shell returns 1 you'll get 256. That is usually not what you care about, you just want to know did it succeed or fail. So - change "or" to "and" and you're all set. It is clearer to say: if(system(...) != 0) { die(" ... "); }

4. file manipulation
after the script, the great issue is the files goes to the same directory.
So I have to sort them out with the stored info in the file.

~~~split fcn
whitespace (not just a single space character) is used as a separator. However, this special treatment can be avoided by specifying the pattern / / instead of the string " " , thereby allowing only a single space character to be a separator.

~~~

~~~ this is for something after split the directory into array
If you're doing a global match (/g) then the regex in list context will return all of the captured matches. Simply do:

my @matches = ( $str =~ /pa(tt)ern/g )
This command for example:

perl -le '@m = ( "foo12gfd2bgbg654" =~ /(\d+)/g ); print for @m'
Gives the output:

12
2
654
~~~~~~
~~~~~~myScript
#! /usr/bin/perl

#filename: sort.pl
use strict;

my $dir= "./mmsim_docs/doc/UltraSim_UWI/UltraSim_UWI.pdf";
if($dir =~ /mmsim_docs/)
        {
          my @dir = split(/\//,$dir);
         foreach my $str(@dir)
                {print "$str","\n";
                if ($str =~/pdf/) {print "here is the match for .pdf: $str, \n";}
                }
         print "here is the match: \n";

        }

~~~~join function
$name="Tom";
$birth="01/02/86";
$addr="chengdu.sichuan";
$info=join(":",$name,$birth,$addr);
print "1.$info"."\n";

@list=("Tom","Joe","Tonny","chris");
@array=join("\n",@list);
$str=join("-",@list);
print "2.$str\n";
print "3.@array";
~~~~~

5. vim change-line alignment
This is about add some settings in the user_directory/.vimrc.
Recommended settings from the website:
http://hi.baidu.com/mnb998866/item/8db11d0cdb689b20a0312d91如果去除注释后,一个完整的.vimrc配置信息如下所示:
set nocompatible
set number
filetype on
set history=1000
set background=dark
syntax on
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set guioptions-=T
set vb t_vb=
set ruler
set nohls
set incsearch
if has("vms")
set nobackup
else
set backup
  endif

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-156793-1-1.html 上篇帖子: Why the framework uses ruby instead of perl?[转] 下篇帖子: Perl notes | Perl语言入门(第四版)笔记
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表