in reply to How to count substitutions on an array
A foreach loop over each array element is fine.#!/usr/bin/perl use warnings; use strict; my $x = "xyzzyblahxyzzymoreBLahxyzzyasdfouyXYZZY"; print "Input = $x\n"; my $count = $x =~ s/xyzzy//gi; print "count = $count\n"; print "result = $x\n\n"; $x = "blahxyzzy"; print "Input = $x\n"; $count = $x =~ s/xyZzy//gi; print "count = $count\n"; print "result = $x\n"; __END__ PRINTS: Input = xyzzyblahxyzzymoreBLahxyzzyasdfouyXYZZY count = 4 result = blahmoreBLahasdfouy Input = blahxyzzy count = 1 result = blah
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to count substitutions on an array
by Anonymous Monk on Aug 13, 2016 at 05:09 UTC | |
by AnomalousMonk (Archbishop) on Aug 13, 2016 at 14:29 UTC | |
by AnomalousMonk (Archbishop) on Aug 13, 2016 at 18:23 UTC | |
by Anonymous Monk on Aug 13, 2016 at 19:11 UTC | |
by Marshall (Canon) on Aug 14, 2016 at 14:55 UTC |