Perl log 0906

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:
如果去除注释后,一个完整的.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 

原文地址:https://www.cnblogs.com/chenrui/p/2674866.html