Sorry to reply to my own reply but you should also consider "use strict" which
will catch certain things like the $success bug in your script ..

On Thu, Oct 25, 2001 at 06:12:22PM +0100, [EMAIL PROTECTED] shaped the electrons 
to read:
> I am assuming that the script you showed is complete ... there are a few
> problems with it.
> 
> First the showstopper ... what is the value of $success?  Did you mean
> $success = open(DATA,">mydata.dat");
> 
> Next are the "probably a better idea to di it this way" (IMHO) stuff ...
> 
> die takes parameters and behaves almost like the print function in terms of
> parameters.  So instead of a separate print and then a die you could just as
> well do this
>       die "Problem encountered\n";
> 
> It is also probably a good idea to put $! in the die statement as well to show
> the errors (unnless u r doing a CGI app or have reasons not to show the error
> generated by perl)
> 
> you also opened the handle but failed to close it.  Perl cleans up after you
> so you did not see problems but if htis script was run as a daemon process or
> mod_perl you might run into problems. all you need to do is
> 
>       close DATA;
> 
> Typically the code to do what you set out below is something like
> 
> open(DATA,">mydata.dat") or die "Problem encountered:$!\n";
> print DATA "Hi Matt\n";
> close DATA;
> 
> On Thu, Oct 25, 2001 at 12:35:02PM -0400, Matthew Mangione shaped the electrons to 
>read:
> > hey im trying to write to a file with just like 6 lines of code and it doesnt work 
>so I need some help. here is the code:
> > 
> > #!perl
> > 
> > open DATA, "> mydata.dat";
> > 
> > unless ($success) {
> >  print "Problem Encountered";
> >  die;
> > }
> > 
> > print DATA "Hi Matt";
> > 
> > 
> > 
> > thanx        matt
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to