in reply to Generating sequence nos. for data

If I understand you, you want to enumerate each occurrance of the first column of your data (the alphabetic letter). Maybe something like:
my %sequence; while (<>) { my @line = split; my $sequence = ++$sequence{$line[0]}; print "@line $sequence\n"; }

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Generating sequence nos. for data
by icg (Acolyte) on Jun 07, 2005 at 12:58 UTC
    Thank you for the reply. If the tags are in continuous order generating sequence number would be easy. For e.g. A 100 A 200 A 300. Each time A is encountered sequence number can be incremented. However if a series of tags are repeating, for e.g. A 100 B 100 A 200 B 300, then for the first occurance of A and B, the sequence number should be 1 and for the next it should be incremented. In other words whenever a tag is repeated in the input file, the sequence number should be incremented. The repeatition of the tags is not guarenteed. They may occur. Thank you, Gowtham
      Yes, that's exactly what my code does, presuming "A 100" is on one line, and "B 100" is on the next. You aren't formatting it more clearly than that, so I'm not sure what you mean unless you say more.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        The input file consists of more than 2000 lines with multiple records. A $$ indicates the start of the record. The record is split on the tag. A hash is populated with key being the tag and value being the data. Some fields within a record repeat in a well defined manner. For e.g. A 100, A 200, A 300, etc. But some fields repeat in a sequence. For e.g. C 100 D 200 E 500 C 400 D 500 E 1000, etc. The sequence number for such fields should be incremented for each such sequence. For e.g. C 100 seqno=1 D 200 seqno=1 E 500 seqno=1 C 400 seqno=2 D 500 seqno=2 E 1000 seqno=2 etc. Thank you, Gowtham