How To Count Strings Inside Another In Perl
1 2 3 4 5 |
my $needle = 'foo'; my $haystack = 'foo foo foo'; my @count = $haystack =~ /$needle/g; my $count = scalar @count; print "$count\n"; |
Should result in 3
1 2 3 4 5 |
my $needle = 'foo'; my $haystack = 'foo foo foo'; my @count = $haystack =~ /$needle/g; my $count = scalar @count; print "$count\n"; |
Should result in 3
CPAN Error: Undefined subroutine &IO::Uncompress::Base::readonly called at /usr/lib/perl5/site_perl/5.8.8/IO/Uncompress/Base.pm Looks like CentOS update installs an older version of the Scalar::Util so that Perl could not load the module. Download the Scalar::Util module and manually install it:
1 2 3 4 5 6 7 |
wget http://search.cpan.org/CPAN/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.35.tar.gz tar xvzf Scalar-List-Utils-*.tar.gz cd Scalar-List-Utils-* perl Makefile.PL gmake gmake test gmake install |
To test: perl -MCPAN -e ‘shell’ For more information, visit the CPAN Util.pm page. Original Post: http://www.perlmonks.org/?displaytype=print;node_id=965635;replies=1