cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
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:
There is only one person in the @coders array because I am testing. Here is what I get when I run this:#!/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; } }
But the script is in the directory above uk and...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
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 addedbash-3.2$ ls uk/uk-07-m-01.txt uk/uk-07-m-01.txt
And I getprint "$ofn\.txt\n"; print $ofn.'.txt'."\n"; print "$nfn\.txt\n"; print $nfn.'.txt'."\n";
WTF?!?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
What am I doing wrong?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File that exists won't open
by Corion (Patriarch) on Mar 07, 2014 at 13:29 UTC | |
by cormanaz (Deacon) on Mar 07, 2014 at 13:40 UTC | |
by McA (Priest) on Mar 07, 2014 at 13:46 UTC | |
Re: File that exists won't open
by marinersk (Priest) on Mar 07, 2014 at 13:43 UTC | |
by jellisii2 (Hermit) on Mar 07, 2014 at 13:56 UTC | |
Re: File that exists won't open
by ww (Archbishop) on Mar 07, 2014 at 13:58 UTC |
Back to
Seekers of Perl Wisdom