Good day bros. I almost feel stupid asking about this. I've been coding PERL for a long time, and this is a simple script, but I am getting a result I can't understand. Maybe it's too early in the morning and I've made one of those stupid mistakes you just can see for some reason. Anyway here is the code:
#!/usr/bin/perl use strict; my $targetdir = 'bmd/production'; my @coders = qw(fleischer); foreach my $c (@coders) { print "$c\n"; open(IN,"$c-assignments.dat") or die "Can't open input: $!\n"; my @coderfiles; while (<IN>) { chop; if ($_ =~ /\w/) { push(@coderfiles,$_); } } close IN; foreach my $f (@coderfiles) { print "$f\n"; my ($countrydir) = split(/\-/,$f); my $ofn = "$countrydir/$f"; print "$ofn\n"; my $nfn = "/usr/local/brat/data/$targetdir/$c/$countrydir/$f"; print "$nfn\n"; open(IN,$ofn.'.txt') or die "Can't open input: $!\n"; open(OUT,">$nfn".'.txt') or die "Can't open output: $!\n"; while (<IN>) { print OUT $_; } close IN; close OUT; open(OUT,">$nfn\.ann") or die "Can't open output: $!"; print OUT ''; close OUT; } }
There is only one person in the @coders array because I am testing. Here is what I get when I run this:
fleischer uk-07-m-01 uk/uk-07-m-01 /usr/local/brat/data/bmd/production/fleischer/uk/uk-07-m-01 Can't open input: No such file or directory
But the script is in the directory above uk and...
bash-3.2$ ls uk/uk-07-m-01.txt uk/uk-07-m-01.txt
It appears the .txt filetype is not getting appended to the filename. I have tried expressing the filename every way I can think of, for example "$ofn\.txt" which I normally do and have done a thousand times before, and I get the same result. Just for laughs, I commented out everything below the first open in the foreach loop, and added
print "$ofn\.txt\n"; print $ofn.'.txt'."\n"; print "$nfn\.txt\n"; print $nfn.'.txt'."\n";
And I get
fleischer uk-07-m-01 uk/uk-07-m-01 /usr/local/brat/data/bmd/production/fleischer/uk/uk-07-m-01 .txtk-07-m-01 .txtk-07-m-01 .txt/local/brat/data/bmd/production/fleischer/uk/uk-07-m-01 .txt/local/brat/data/bmd/production/fleischer/uk/uk-07-m-01
WTF?!?

What am I doing wrong?


In reply to File that exists won't open by cormanaz

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.