Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Open()

Posted on 1997-10-16
7
Medium Priority
?
166 Views
Last Modified: 2006-11-17
  $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...
0
Comment
Question by:mfischer2
  • 3
  • 3
7 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 1207785
Maybe perl can tell you
0
 
LVL 85

Expert Comment

by:ozo
ID: 1207786
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 $!";
}
0
 

Author Comment

by:mfischer2
ID: 1207787
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Expert Comment

by:ozo
ID: 1207788
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.
0
 

Author Comment

by:mfischer2
ID: 1207789
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.)
0
 
LVL 1

Accepted Solution

by:
gabsi earned 80 total points
ID: 1207790
I don't see why it does not works, I tried it whith several perl versions, no problem.

But

open(DATA, ">>$fileloc") || die "can't append $fileloc $!";

will create the file if it does not exist and open it in append mode if it exists.
0
 

Author Comment

by:mfischer2
ID: 1207791
Its AFS, problem solved.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question