Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Why am I getting wrong result in counting the number and kind of 2-letter in 3-letter words in a string?

by JavaFan (Canon)
on May 01, 2012 at 13:35 UTC ( #968246=note: print w/ replies, xml ) Need Help??


in reply to Why am I getting wrong result in counting the number and kind of 2-letter in 3-letter words in a string?

You seem to misunderstand substr. The second argument is the start index to take the sub string from, the third argument the length.

If you have to take the first and third character of a string, you cannot do that with a single sub string, as you are not interested in the second character. Perhaps you want to do something along the lines of:

foreach my $tri (@trilet) { my ($f, $s, $t) = $tri =~ /(.)(.)(.)/; $first{"$f$s"}++; $second{"$s$t"}++; $third{"$f$t"}++; }


Comment on Re: Why am I getting wrong result in counting the number and kind of 2-letter in 3-letter words in a string?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-09-17 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (72 votes), past polls