trouble writting to file

A

Alexandre Jaquet

Hi I could not find why, I can't write data
to my file :

open (FILE, ">$interfacePath/$interfaceFile") or die "cannot open
chmod (0775, "$interfacePath/$interfaceFile");
$interfacePath/$interfaceFile\n" ;

print FILE "test,test,test";

In my file : FILE :
/web/floor.ch/cms/interface/disquesoffice/Library/category/interface/test-save.icf

ls -al :


-rwxrwxr-x 1 www web 0 Apr 15 14:21 test-save.icf


thx in advance
 
T

Tad McClellan

Alexandre Jaquet said:
Hi I could not find why,


Because you have a syntax error.

I can't write data
to my file :


Because the program never executes.

open (FILE, ">$interfacePath/$interfaceFile") or die "cannot open
chmod (0775, "$interfacePath/$interfaceFile");
^
^

There is the end of the argument to die()...
 
I

Ian Wilson

Alexandre said:
Hi I could not find why, I can't write data
to my file :

You should read the posting guideleines before posting a question.
open (FILE, ">$interfacePath/$interfaceFile") or die "cannot open
chmod (0775, "$interfacePath/$interfaceFile");
$interfacePath/$interfaceFile\n" ;

print FILE "test,test,test";

The above isn't valid Perl, looks like the chmod has been inserted in
the middle of the "open ... die ..." statement.

A perl program should start
#!perl
use strict;
use warnings;

You shoulc close the file you opened.
In my file : FILE :
/web/floor.ch/cms/interface/disquesoffice/Library/category/interface/test-save.icf


ls -al :
-rwxrwxr-x 1 www web 0 Apr 15 14:21 test-save.icf

Your "die" should take care to print the error details: include $! in
the output.

e.g.
#!perl
use strict;
use warnings;
open (FILE, ">$interfacePath/$interfaceFile")
or die "cannot open $interfacePath/$interfaceFile because $!" ;
chmod (0775, "$interfacePath/$interfaceFile");
print FILE 'test,test,test';
close FILE;


You should read about lexical filehandles and 3-way opens:
open my $fh, '>', $filename or die ...

Understand the difference between "test,test,test" and 'test,test,test'.

If you do all the above at least you'll have an informative error message.
 
J

Joe Smith

Ian said:
Understand the difference between "test,test,test" and 'test,test,test'.

There is none.

The example you have given does not use $ or \, so what point are you
trying to make?
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top