singhabsk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Extraction n Airthmatic operation Fun on TEXTFILE

Replies are listed 'Best First'.
Re: Extraction n Airthmatic operation Fun on TEXTFILE
by Ratazong (Monsignor) on Jan 28, 2011 at 08:37 UTC

    You don't need to be a Guru to do such kind of work!

    I propose the following approach

    • open the file
    • read the file line by line
      • if the line contains one of your keywords, just increase a counter related to it
      • (you can identify the keyword with a simple regex (e.g. if ($line =~ /RequestREGISTER/) { $regcnt++; }) - simple, isn't it?)
    To process the number or unique TIDs, remember the wise words of brother brian_d_foy in perlfaq4:
    Use a hash. When you think the words "unique" or "duplicated", think "hash keys".
    So extract the TID from your line (again using a regex), add them to a hash, and process the hash as you wish once you finished reading the file.

    HTH, Rata

      See the below code,

      open(INP, "Test.txt") || die "can't open input file"; my %occuranceCounter; my %tidOccurance; while (<INP>) { if (/\-\-(TID\d+-\d+\@[\d\.]+ \d+)\-\-([^\n]+)\n/) { $tidOccurance{$1}=1; $occuranceCounter{$2}=$occuranceCounter{$2}+1; } } #print outputs foreach my $occurance (keys %occuranceCounter) { print "$occurance: ".$occuranceCounter{$occurance}."\n"; } print "Tid unique occurances is ".scalar(keys(%tidOccurance));