Link to home
Start Free TrialLog in
Avatar of mfischer2
mfischer2

asked on

Open()

  $fileloc = "/billy/bob";
        if (-e "/billy/bob")
          {
          open(DATA, ">>$fileloc");
          }
        else
          {
          open(DATA, ">$fileloc");
          }

      Does anyone know why this doesn't work?  Or can anyone suggest another way that will? I want to append or create the file...
Avatar of ozo
ozo
Flag of United States of America image

Maybe perl can tell you
Maybe perl can tell you why if you ask it:
#!/bin/perl -w
$fileloc = "/billy/bob";
if( -e "/billy/bob" ){
     open(DATA, ">>$fileloc") || die "can't append $fileloc $!";
}else{
     open(DATA, ">$fileloc") || die "can't write $fileloc $!";
}
Avatar of mfischer2
mfischer2

ASKER

Thats not the problem.  I know it won't work at all, well actually it will append the file, but it won't create it!  I have tried about 50 permutations of the scenario, and no luck.
Either
  open(DATA, ">>$fileloc")
or
  open(DATA, ">$fileloc")
can create a file.
If it failed for you, what did $! tell you about the reason?
If it was "No such file or directory", you may want to do a
  mkdir "/billy",0766 or die $!;
If it was "Permission denied" you may want to do a
  umask 0;
first.
Okay, It cant create the file, and I assume its because I dont have permissions.  This is a web based application, and it runs on an AFS file system, so perhaps I dont have the permissions set correctly.  I will look into it, but thanks for your help.  (BTW  - it didnt really say permission denied, just said the error message and gave the line number.)
ASKER CERTIFIED SOLUTION
Avatar of gabsi
gabsi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Its AFS, problem solved.