Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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?
[Corion]: usemodperl: Well, if the world changes and makes your "wonderful" approach not work anymore, you can either change your approach, or change the world. You seem to want to change others instead.
[usemodperl]: no dude i'm just asking how to access meta via http and you are getting defensive for some reason (did you turn off http at meta? :-)
[choroba]: why do you need to access metacpan via http?
[usemodperl]: stop asking why, just say how
usemodperl pulls teeth...
[usemodperl]: change the world? you mean BREAK THE WEB? we will regret this once google starts pulling certs for cursing or something...
Veltro Sees open mouth and feeds troll
[Corion]: usemodperl: Naah, you're just being unreasonable. It's not hard to download https URLs, and we've shown you ways to avoid downloading at all, and ways to keep downloading via http possible. You reject both.
[choroba]: Also, try asking at IRC
[usemodperl]: corion baby you have done nothing of the sort

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2018-06-24 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?