On May 14, 2005, at 19:47, Aditi Gupta wrote:
there are actuaaly no fields specified.. i have strings in each row (with intermittent hyphens) and i've to find which alphabet occurs how many times in each column and then perform reg exp operations.. but i've never dealt with such columnwise analysis before and haven't seen in books also so far.. which documentationshould i refer for such problem..
From that description my guess is that we have:
my @cols = split /\s*-\s*/, $row;
If an "alphabet" can have a stringfied representation, a code for example, and if given a $col we imagine for the sake of this followup a function that guesses $col's alphabet code:
my $code = guess_alphabet($col);
then a possible approach would be:
my @counters = (); while (my $row = <$fh>) { my @cols = split /\s*-\s*/, $row; for (my $i = 0; $i < @cols; ++$i) { my $code = guess_alphabet($cols[$i]); ++$counters[$i]{$code}; } }
That's to be taken as pseudocode (I wrote it just inline), and needing adjusts taking into account details of the actual problem to solve.
The main idea is that we have an array of counters called @counters. The ith element of @counters contains counters per alphabet corresponding to the ith column in the input file.
To distinguish counters per alphabet at column $i, we store a hashref at $counters[$i], whose keys are alphabet codes, and whose values are counters per alphabet. That is, $counters[$i]{$code} gives how many times alphabet with code $code has been seen in the $ith column. Alphabets not seen at column $i have no entry, but $counters[$i] {$code} would evaluate to undef without problem.
Does that help? Can you apply regexps as you need with that structure?
-- fxn
PS: Notice that we don't explicity create the hashref to be stored at $counters[$i], we directly write $counters[$i]{$code}. That's thanks to a nice feature of Perl called "autovivification" that creates structures on the fly for you.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>