Hi all, I was wondering if you could find the reason for this issue in the code posted below?

I am trying to automate the way I use a program (Gromacs) and edit its outputs. So first I loop through my molecules and issue the Gromacs command (g_angle) which works fine. Then I commented the g_angle command out to test the rest of the script. What I want to do now is open (for reading) the output of the previously used command, to manipulate it and write another file.

However the line open $input, '<', '/Users/athina/check-ma/$ID${l}/F${j}\/gangle-dihedrals-${i}${id}${k}.xvg' or die $!; fails as "no such file or directory" but the file exists.

The line print  `ls /Users/athina/check-ma/$ID${l}/F${j}\/gangle-dihedrals-${i}${id}${k}.xvg`; that I've used as a test works fine and returns the file.

What is happening? :( Thank you so much for your time!

#!/usr/bin/perl use warnings; use strict; my $id = "ac"; my $ID = "AC"; my $g_angle = "/usr/local/gromacs/bin/g_angle"; my $i; my $k; my $input; my $output; #disable Gromacs backups because otherwise it fails after writing 99x +copies if(!defined $ENV{GMX_MAXBACKUP}) { $ENV{GMX_MAXBACKUP}=-1 } for ($i=2; $i<=2; $i++) { my $j = sprintf ("%05d", $i); for ($k=15; $k<=15; $k++) { my $l = sprintf ("%04d", $k); my $path = "/Users/athina/check-ma/$ID${l}/F${j}"; my $dashFolder = "/media/data/athina/dash-test/$ID${l}"; #`$g_angle -f $path\/${i}${id}${k}.mdsol.centered.xtc -n /Users/ath +ina/check-ma/$ID${l}/F00001/dihedrals-1${id}${k}.ndx -type dihedral - +all -ov $path\/gangle-dihedrals-${i}${id}${k}.xvg -od $path\/out.xvg` +; print `ls /Users/athina/check-ma/$ID${l}/F${j}\/gangle-dihedrals-${i} +${id}${k}.xvg`; open $input, '<', '/Users/athina/check-ma/$ID${l}/F${j}\/gangle-dih +edrals-${i}${id}${k}.xvg' or die $!; open $output, '>', '/Users/athina/check-ma/$ID${l}/F${j}\/in-dihedr +als-${i}${id}${k}.txt' or die $!; while (my $line = <$input>) { chomp $line; # remove end-of-line character $line =~ s/^\s+//; # strip leading whitespace next unless $line; # skip blank lines # skip first 12 lines next unless $. > 12; # $. contains current line number my @columns = split(/\s+/, $line); # split columns on whitespac +e my $col1 = shift @columns; # column 1 (throw away) my $col2 = shift @columns; # column 2 (throw away) my $col3 = shift @columns; # column 3 (special - keep this one) my $result = sprintf("%8.3f", $col3); # special format for col 3 # loop over remaining columns, appending to result string for my $c (@columns) { my $data = sprintf("%9.3f", $c); $result .= " $data"; } print $output "$result\n"; } ### } ### for k loop } ### for i loop

In reply to 'open for read' fails as "no such file or directory" but file is there by fasoli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.