- 论坛徽章:
- 1
|
使用引用创建的多维数组,在传递给子程序,或者从子程序传递出来,是重新赋值过还是直接传递引用。
貌似直接传递引用的。
- #!/usr/bin/perl
- use warnings;
- use strict;
- use Text::CSV_XS;
- sub csv{
- open (CSV,"<$_[0]");
- my @columns;
- my $col;
- my $csv = Text::CSV_XS->new({
- 'binary' => 1,
- 'quote_char' => '"',
- 'sep_char' => ','
- });
- foreach my $line (<CSV>) {
- chomp $line;
- if ($csv->parse($line)) {
- $col=[];
- @{$col} = $csv->fields();
- push @columns,$col;
- } else {
- print "[error line : ", $csv->error_input, "]\n";
- }
- }
- close (CSV);
- return @columns;
- }
- sub check{
- foreach (@_){
- foreach (@{$_}){
- s/ //g;
- s/,//g;
- }
- }
- }
- my @tmp=csv($ARGV[0]);
- &check(@tmp);
- foreach (@tmp){
- foreach (@{$_}){
- print $_."\n";
- }
- }
复制代码 |
|