Solved

Open()

Posted on 1997-10-16
7
158 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
ID: 1207785
Maybe perl can tell you
0
 
LVL 84

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 84

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 40 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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