Solved

Open()

Posted on 1997-10-16
7
154 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 84

Expert Comment

by:ozo
Comment Utility
Maybe perl can tell you
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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 40 total points
Comment Utility
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
Comment Utility
Its AFS, problem solved.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now