diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2021-05-03 05:03:41 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2021-05-03 05:03:41 +0800 |
| commit | eb72326ab9a5f1f7b2ae2f9facc0a4bb12ffbe66 (patch) | |
| tree | 14afdf6a9bbfe95236ad2ec9efafed07429b8589 | |
| parent | 2d2f56894d29cf5dfa7d4dcdda2ff56131793aae (diff) | |
| download | perlweeklychallenge-club-eb72326ab9a5f1f7b2ae2f9facc0a4bb12ffbe66.tar.gz perlweeklychallenge-club-eb72326ab9a5f1f7b2ae2f9facc0a4bb12ffbe66.tar.bz2 perlweeklychallenge-club-eb72326ab9a5f1f7b2ae2f9facc0a4bb12ffbe66.zip | |
edit ch-2.pl and blog
| -rw-r--r-- | challenge-110/cheok-yin-fung/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-110/cheok-yin-fung/perl/ch-2.pl | 17 |
2 files changed, 11 insertions, 7 deletions
diff --git a/challenge-110/cheok-yin-fung/blog.txt b/challenge-110/cheok-yin-fung/blog.txt new file mode 100644 index 0000000000..f7a4b58e75 --- /dev/null +++ b/challenge-110/cheok-yin-fung/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/c_y_fung/2021/05/cys-take-on-pwc110.html diff --git a/challenge-110/cheok-yin-fung/perl/ch-2.pl b/challenge-110/cheok-yin-fung/perl/ch-2.pl index f5b7a432bb..89cbd1e4e8 100644 --- a/challenge-110/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-110/cheok-yin-fung/perl/ch-2.pl @@ -17,16 +17,19 @@ for my $field (@{$csv_file}) { } for my $i (0..$old_max_num_col-1) { - print $csv_file->[0]->[$i]; + print_item($csv_file->[0]->[$i]); for my $k (1..$old_num_row-1) { print ","; - my $item = $csv_file->[$k]->[$i]; - if (defined($item)) { - print "\"" if $item =~ /,/; - print $item; - print "\"" if $item =~ /,/; - } + print_item($csv_file->[$k]->[$i]); } print "\n"; } +sub print_item { + my $item = $_[0]; + if (defined($item)) { + print "\"" if $item =~ /,/; + print $item; + print "\"" if $item =~ /,/; + } +} |
