in reply to Re^2: Statistics from a txtfile
in thread Statistics from a txtfile

Hi mbdc566021,

Your code looks like it has just been cobbled together with snippets from various sources. This is OK, but don't be afraid to make changes and experiment with the code to see what happens. Here are a few points:

# this matches each character once $filecontents =~ m/./g; # this version also puts a copy of each match into @characters my @characters = $filecontents =~ m/./g; # this counts the number of elements in @characters my $CharCount = scalar @characters; # to verify your regex is matching correctly # this will print a list of each item counted: for (@characters){ print "$_ \n"; }

Good luck with your assignment.

Replies are listed 'Best First'.
Re^4: Statistics from a txtfile
by blazar (Canon) on Jan 02, 2008 at 21:17 UTC
    Your code looks like it has just been cobbled together with snippets from various sources. This is OK, but don't be afraid to make changes and experiment with the code to see what happens.

    I personally believe it's far from being OK unless one

    • understands what that those snippets do, or tries to and upon failure asks for clarification, or
    • can safely take a black-box approach: e.g. I can't understand a given sub's algorithm, but I have a clear idea of what input it takes and what output does it spit out. (Or try to understand that and upon failure...)
    --
    If you can't understand the incipit, then please check the IPB Campaign.

      I see your point blazar, and maybe I gave away a little too much. But since the OP is obviously a student, I was trying to encourage him (her?) to experiment so he will understand what the code does.