in reply to Re^2: Structure number
in thread Structure number

Will you please kindly tell me what will be the modification if another column is added to the input file? but the output should be the same as the previous one omitting the alphabets? If the input file is

536 ENERGY = -176.2 gag
1 G 0 2 0
2 G 1 3 533
3 G 2 4 532
536 ENERGY = -175.9 gag
1 G 0 2 0
2 G 1 3 533
3 G 2 4 532

I have tried the following but its not working

open(MYFILE, $data_file) || die("Could not open file!"); my $energy; while ( <MYFILE> ) { if ( /\bENERGY\b/ ) { ++$energy; next; } my ( $key, @fields ) = grep $_, split; for my $field ( @fields ) { if (@fields[2] ne G || A || C || G) { print "$key $field $energy\n"; } } }

Replies are listed 'Best First'.
Re^4: Structure number
by jwkrahn (Abbot) on Dec 02, 2010 at 08:30 UTC
    if (@fields[2] ne G || A || C || G)

    The syntax and logic are wrong there.    The letter would be in  $fields[0] and that has to be explicitly compared for each letter and you want to use  && instead of  || for a negative comparison.    For example:

    if ( $fields[0] ne 'G' && $fields[0] ne 'A' && $fields[0] ne 'C' & +& $fields[0] ne 'G' )

      its still not working. The code is not omitting pairs/lines with these alphabets :(

        its done thank you so much for your help. I was making a mistake in array index :)