in reply to Re: Structure number
in thread Structure number

Thank you so much for help. It worked.

Replies are listed 'Best First'.
Re^3: Structure number
by AG87 (Acolyte) on Dec 02, 2010 at 07:23 UTC

    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"; } } }
      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 :(