Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Using grep in a scalar context

by choroba (Canon)
on Feb 06, 2013 at 13:47 UTC ( #1017436=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Using grep in a scalar context
in thread Using grep in a scalar context

I am still not sure what your input is, but I hope you might find one of the following two solutions helpful:

use Data::Dumper; my $string = 'MHDLKNDHASDRWT'; my %count_string; $count_string{$_}++ for $string =~ /(?=(..))/g; # Uses look-ahead to o +nly progress by one character. my @array = split //, $string; my %count_array; $count_array{ join q(), @array[$_, $_ + 1] }++ for 0 .. $#array - 1; print Dumper \%count_string, \%count_array;
Note: /AA/ matches the capital letter A followed by the capital letter A. It does not stand for "anything" in regular expressions.

Updated: Added the hashes.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^3: Using grep in a scalar context
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017436]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2015-07-03 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (52 votes), past polls