Fork me on GitHub

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

shell、perl开发示例

shell部分
perl部分

Shell

shell创建空文件

> filename / >> filename
touch filename
echo "" > filename (替换) / echo "" >> filename (补充)

perl

perl IO文件示例
#!/usr/bin/env perl

$infile = shift;  # 获取数组的第一个元素,若未提供则获取 @ARGV 的值
$outfile = shift;
$num_per = shift;
print "参数" , $infile , $outfile , $num_per;   # 打印语句
open IN ,"<:encoding(utf8)" , $infile or die $!;   # < 读取模式,以utf8解码
$cc = 0;  # 定义变量
$file_num = 1;
$line = "";
open OUT , ">:encoding(utf8)", $outfile."/$infile-$file_num" or die $!; # > 写模式

while( $line = <IN> ) # 遍历读取对象内容
{
        $cc++;
        if ($cc%$num_per==1 ) {
                if($cc > $num_per){
                        close OUT;
                        $file_num++;
                        open OUT , ">:encoding(utf8)", $outfile."/$infile-$file_num" or die $!;
                }
        }
        # if ($file_num > 100){
        #       last;     #  last跳出循环,next跳过当前次循环
        # }
        print OUT $line;     # 将读取内容写进新文件中
}

close OUT;  # 关闭文件对象
close IN;
$waves_dir = $ARGV[0];
$in_list = $ARGV[1];
open IL, $in_list;
while ($l = <IL>)
{
        # 去除尾部的换行符
	chomp($l);  
	$full_path = $waves_dir . "\/" . $l;
	$l =~ s/\.wav//; # ~s模式匹配  string=~s/匹配项/替换项/ 这里将 .wav 替换成 nothing
	print "$l $full_path\n";
}

shift文档详解(Perl)

shift ARRAY
shift   Shifts the first value of the array off and returns it,
        shortening the array by 1 and moving everything down. If there
        are no elements in the array, returns the undefined value. If
        ARRAY is omitted, shifts the @_ array within the lexical scope
        of subroutines and formats, and the @ARGV array outside a
        subroutine and also within the lexical scopes established by the
        "eval STRING", "BEGIN {}", "INIT {}", "CHECK {}", "UNITCHECK {}"
        and "END {}" constructs.

        See also "unshift", "push", and "pop". "shift" and "unshift" do
        the same thing to the left end of an array that "pop" and "push"
        do to the right end.
posted @ 2022-01-13 00:15  365/24/60  阅读(127)  评论(0编辑  收藏  举报