ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: PERL create file
by Bill Luebkert other posts by this author
Jul 3 2009 4:27AM messages near this date
RE: PERL create file | Re: PERL create file
Brian Raven wrote:
>  
>                                                                   To
>  improve your I would advise using the 3 argument form of open, localise
>  the file handle, 

Neither of those suggestions 'should' change a thing.

                    and include the reason for the failure in your error
>  message. 

That's what would be useful, change the or die to :

	open OUT, "+> >$output" or die "open for read/append $output: $! ($^E)";

or (if read not needed):

	open OUT, "> >$output" or die "open for append $output: $! ($^E)";

and maybe you'll get something useful (assuming it's dieing on the open).
The $^E should give additional helpful text since $! is often cryptic.

 >            So, to open a file for appending, creating it if it doesn't
>  exist, I might have the following.
>  
>  my $output = "/home/saqib/performance_debug_20090703.txt";
>  open my $fd, ">>", $output or die "Failed to open $output: $!\n";

I'm guessing he may want to read as well as write or he doesn't
understand what +> > means.  There's nothing wrong with the code
per se - the only probable error might be one of permissions on
the output dir, but seeing as it's apparently to his home dir,
theat would seem unlikely unless it's like in a CGI script running
as a different user or some such.

>  As it is an output file you should also check that the close was
>  successful, as this is where any disk dull errors will, usually, be
>  discovered.
_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Saqib Rafique
Brian Raven
Bill Luebkert
Ingo Schwarze
Bill Luebkert
Serguei Trouchelle
Bill Luebkert
Jan Dubois
Ingo Schwarze
Mohammed Mustafa
Stanislaw Romanski

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved