lunix has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my @words = ("anyone", "cancel", "declare", "perlmonks"); my $count = 0; foreach (@words) { if ($words[$count] =~ m/a/i) { my $number = () = $words[$count] =~ /e/gi; print "$words[$count]: $number\n"; } $count ++; }
anyone: 1 cancel: 1 declare: 2
perl -e 'for('anyone','cancel','declare','perlmonks'){$i=()=/e/g;print +"$_: $i\n"if(/a/);}'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Shorten this one-liner!
by LanX (Saint) on Aug 25, 2018 at 21:56 UTC | |
by lunix (Novice) on Aug 26, 2018 at 10:03 UTC | |
Re: Shorten this one-liner!
by eyepopslikeamosquito (Archbishop) on Aug 26, 2018 at 07:00 UTC | |
by lunix (Novice) on Aug 26, 2018 at 10:19 UTC | |
Re: Shorten this one-liner!
by eyepopslikeamosquito (Archbishop) on Aug 26, 2018 at 12:22 UTC | |
by lunix (Novice) on Aug 26, 2018 at 15:22 UTC | |
by Marshall (Canon) on Aug 28, 2018 at 00:51 UTC | |
Re: Shorten this one-liner!
by Marshall (Canon) on Aug 25, 2018 at 23:28 UTC |