From eb72326ab9a5f1f7b2ae2f9facc0a4bb12ffbe66 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 3 May 2021 05:03:41 +0800 Subject: edit ch-2.pl and blog --- challenge-110/cheok-yin-fung/blog.txt | 1 + challenge-110/cheok-yin-fung/perl/ch-2.pl | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 challenge-110/cheok-yin-fung/blog.txt 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 =~ /,/; + } +} -- cgit