Solved

Open()

Posted on 1997-10-16
7
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

623 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