Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 romping around the Monastery: (7)
As of 2014-09-20 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (160 votes), past polls