problems reading a file

I am working on a live content-update tool which uses text files to store data for publication.

In several places, I generate these files by using the contents of a variable as part of the generated file's name.

When I try to use the same method to read the file, I receive no error message, but it appears that no information is passed (the contents of the file are not read in, or the file is not found).

More than likely this is something very obvious, but I'm fairly new to Perl, so I'm missing it completely.

I create the files with:

    open (INFO, ">c:/mydir/01$Config{'nmonth'}$Config{'nyear'}_1e.txt");
    print INFO "(content not available in english)\n";    

nmonth and nyear are variables passed by a previous form.

I then try to read it with:

  open (READINFO, "c:/mydir/$Config{'numero'}_1e.txt");
  $content1e = <READINFO>;
  close (READINFO);

where numero is the appropriate value (ex:01012003) - I have confirmed that this value is passed properly, but it simply isn't working.
TIA for any help

Who is Participating?
ventolinConnect With a Mentor Commented:
$content1e = <READINFO>;

will only read in one line of the file.

you'll need to do this:

# undef input record seperator so we can get whole file
undef $/;

# slurp template into $template
$content1e = <READINFO>;

# set input record seperator back to default newline character
$/ = "\n";

Could you post your code example here? The places where you write and read the file...
yes... please post your code.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

AaarghAuthor Commented:
Edited text of question.
#also, check the success of the open:
open (READINFO, "c:/mydir/$Config{'numero'}_1e.txt") or die "can't open c:/mydir/$Config{'numero'}_1e.txt because $!";
AaarghAuthor Commented:
Well this wasn't really the solution to my original problem, which was a bug on my part (newline char. being included in the value, and passed on to the filename).

However, I would have run into it immediately after solving the bug, so it definitely helped.

ozo, I had noticed that bit of code in other posts, and was going to try it out - you comfirmed it for me, and that's how I discovered the bug.

Many thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.