Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by trizen (Hermit)
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 making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-07-07 06:32 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 (87 votes), past polls