- 論壇徽章:
- 1
|
使用引用創(chuàng)建的多維數(shù)組,在傳遞給子程序,或者從子程序傳遞出來,是重新賦值過還是直接傳遞引用。
貌似直接傳遞引用的。
- #!/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";
- }
- }
復制代碼 |
|