Perl读取文本格式化后写入文本

Perl读取文本格式化后写入文本,第1张

概述demo: #!/usr/bin/perl -w#Perl pragma to restrict unsafe constructsuse strict;use utf8;#main functionsub main { #get params # @_ # Within a subroutine the array @_ contains the para


demo:

#!/usr/bin/perl -w#Perl pragma to restrict unsafe constructsuse strict;use utf8;#main functionsub main {    #get params    # @_      # Within a subroutine the array @_ contains the parameters passed to that subroutine.     # InsIDe a subroutine,@_ is the default array for the array operators push,pop,shift,and unshift.	# set source file location    my $s_file = "example_file.txt";	# set destinate file location    my $d_file = "file_1.txt";	# notice and exit if $s_file or $d_file is null    dIE "must have source file and destination file!\n" unless $s_file && $d_file;    #open file for read,FO file handler    if ( open(FO,$s_file) ) {        if ( open(FOO,">$d_file") ) {            #do while loop             while(<FO>) {                # $_ general variables                 my $line = $_;                # remove head and tail blank                $line =~ s{^\s|\s$}{}g;                # use,split line                # split /PATTERN/,EXPR. use what split depend on your file delimiter                my @items = split/,/,$line;                # write some item to new file                print FOO  $items[1] . "|" . $items[0] . "  ";            }            # close file handler            close(FOO);        } else {			# open file fail            print "open destination file $d_file error\n";        }		# close file handler        close(FO);    } else {		# open file fail        print "open source file $s_file error\n";    }}# pass params to main function,# @ARGV# The array @ARGV contains the command-line arguments intended for the script.main(@ARGV);
总结

以上是内存溢出为你收集整理的Perl读取文本格式化写入文本全部内容,希望文章能够帮你解决Perl读取文本格式化后写入文本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1279130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存