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

Re: How can I get the results in a text file from counting in a string?

by trizen (Friar)
on Aug 07, 2012 at 17:55 UTC ( #986042=note: print w/ replies, xml ) Need Help??


in reply to How can I get the results in a text file from counting in a string?

#!/usr/bin/perl use strict; use warnings; my $str = "BATCATDATEFEAT"; my %hash; while ($str =~ /([AT])/ig) { $hash{$1}{cnt}++; $hash{$1}{pos} = pos($str); printf "Position of $1 at: %d\n", $hash{$1}{pos}; } my $output = "Results.txt"; open(my $results_fh, '>', $output) or do { die "[!] Cannot open file '$output'.\n"; }; foreach my $key (sort keys %hash) { print $results_fh <<"EOL"; $key=$hash{$key}{cnt} ends at $hash{$key}{pos} EOL } close $results_fh;


Comment on Re: How can I get the results in a text file from counting in a string?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-10-31 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (215 votes), past polls