aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-11 22:49:38 +0100
committerGitHub <noreply@github.com>2021-04-11 22:49:38 +0100
commita594ef6416183710766ca873128949f08e18927a (patch)
tree47f7d06fb1258b7a4526c0ad4635edeb8016eb1b
parent9521ad166f11e64ae3edd3c5bd5833e0ba557b45 (diff)
parent92b1db1ea2aa726d870c8975427cf74e430f5d05 (diff)
downloadperlweeklychallenge-club-a594ef6416183710766ca873128949f08e18927a.tar.gz
perlweeklychallenge-club-a594ef6416183710766ca873128949f08e18927a.tar.bz2
perlweeklychallenge-club-a594ef6416183710766ca873128949f08e18927a.zip
Merge pull request #3870 from E7-87-83/newt
submission for week 107
-rw-r--r--challenge-107/cheok-yin-fung/perl/ch-2.pl10
1 files changed, 7 insertions, 3 deletions
diff --git a/challenge-107/cheok-yin-fung/perl/ch-2.pl b/challenge-107/cheok-yin-fung/perl/ch-2.pl
index da92d07e33..188059fcf2 100644
--- a/challenge-107/cheok-yin-fung/perl/ch-2.pl
+++ b/challenge-107/cheok-yin-fung/perl/ch-2.pl
@@ -8,15 +8,19 @@
# ---
# Usage: ch-2.pl [complete name of the script]
+
die "Please input Perl scripts you want to check.\n" if !defined($ARGV[0]);
my $program = $ARGV[0];
open(SCRIPT, $program) or die "Fail to read $program\n";
-while (<SCRIPT>) {
- if ( /sub(\s+)(\&|\w)(\w*)/ ) {
- print $2.$3 . "\n";
+my %hash;
+
+while (my $line = <SCRIPT>) {
+ while ( $line =~ /sub(\s+)(\&|\w)(\w*)/g ) {
+ print $2.$3."\n";
}
}
+#ref: https://stackoverflow.com/questions/9156149/perl-match-one-pattern-multiple-times-in-the-same-line-delimited-by-unknown-cha