in reply to Re: Extract and read different columns from the file
in thread Extract and read different columns from the file

The entire text file looks something similar like this

3 9606 34 ACADM 187960098 NP_001120800.1

5 9606 37 ACADVL 4557235 NP_000009.1

6 9615 489421 ACAT1 73955189 XP_546539.2

I know how to read get each line as the input. After this, i should store all the desired columns in a hash table with the line number as the hash table index and to perform some string matching operations....
  • Comment on Re^2: Extract and read different columns from the file

Replies are listed 'Best First'.
Re^3: Extract and read different columns from the file
by ikegami (Patriarch) on Oct 27, 2010 at 04:15 UTC

    with the line number as the hash table index

    huh, why not just use an array?

    my @a; while (<>) { chomp; my @rec = split; push @a, [ @rec[???, ???, ???] ]; }

    i should store all the desired columns

    You keep saying you only want certain columns, yet you don't say which. Again, just use the index of the columns you want for the question marks.

Re^3: Extract and read different columns from the file
by aquarium (Curate) on Oct 27, 2010 at 04:38 UTC
    while($line=<>) { ($key,$num1,$num2,$string,$num3,$stringnum) = split(/\s/,$line); $somehash{"$key"}{"$num1"}{"$num2"}{"$string"}{"$num3"}= $stringnum; }
    that puts the data into a "hash", but probably not what you want.
    whether you use a hash or array structure largely depends on the data available and the logic/processing required. sequential processing and lack of a random access key lends itself to an array structure. when you have a good logical random access key (not a record sequence number) and need to access the records non-sequentially, use a hash. a hash structure, or even a mix of hash and array structure may be suitable. but exactly what structure do you want? both approaches could be out the window if you have millions of records in the file, whereby some much smarter arrangement would be required to achieve the logic/processing required.
    speaking of which..what is the required logic/processing for these records?
    the hardest line to type correctly is: stty erase ^H