Problem executing perl script on remote server

Hello,

I am running in to a problem running a perl script on a remote server.

I can run a simple script test.pl which contains just a print statment without issue by running

ssh root@1.2.3.4 perl test.pl

However, I have a more complex script that does not execute as expected. I think I have it narrowed down to a problem with the lines that open files for writing. The script works fine if I run it on the server.

The following does not create a file and write to it if executed remotely

open FILE, ">file.txt" or die $!;
print FILE "Testing123\n";
close FILE;

Does anyone know of a way I can achieve this?

Regards,
Colin

Colin,
Give the full path to the file you wish to write to also it is recommended you add perl interpreter with the shebang on the first line.
See below:

#!/usr/bin/perl
open FILE, ">/tmp/file.txt" or die $!;
print FILE "Testing123\n";
close FILE;

Cheers
SRG

Does it print any error messages?

Hello,

Thats great lads. Worked a charm. Had the she bang in already but never thought about putting in the full path.

Thanks for yer help
Colin