Click to See Complete Forum and Search --> : Perl: open(file) close(file) problems


noshankus
06-03-2003, 05:39 AM
Hi,


I have some code, and I can't figure out why the hell it won't work.


open (LIST, "$list");
my @list=<LIST>;

open (TEMP, ">$temp");

foreach $line(@list) {

open(USER, "/home/data/intranet/testies/$build/users/$line/current.usr");
my @user=<USER>;
close(USER);

print TEMP "$line";
print TEMP "$build";
print TEMP "@user";
}
close(TEMP);
close(LIST);


The $var's are declared correctly, and using this, I actually get an output of every user's name and the build number (cos of $line and $build) - but I don't get the @user array in the TEMP file.

Each file is chmod 777, so it's not a rights issue.

Any help is very much appreciated.
Best regards,

dchidelf
06-03-2003, 08:53 AM
in your foreach $line loop, $line will contain newlines, so the path to open will be weird.
Add a chomp($line) before the open.
You'll have to print "$line\n" if you need a newline in the temp file.

noshankus
06-03-2003, 09:38 AM
Yep! That did it. :D

Thanks very much!

Best regards,