--- Matthew Mangione <[EMAIL PROTECTED]> wrote:
> 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
>
Matt,
$success is never initialized in this code. Try the following:
#!perl -w
use strict;
open DATA, "> mydata.dat" or die "Cannot open mydata.dat for writing: $!";
print DATA "Hi Matt";
close DATA;
In the code above, the $! variable is a special variable that, when used in string
context,
returns the operating system error, if any, that is reported when trying to do things
like "open".
For code a bit closer to your format:
#!perl -w
use strict;
my $success = 1;
my $file = 'mydata.dat';
open DATA, "> $file" or $success = 0;
unless ($success) {
print "Could not open $file for writing: $!";
die;
}
print DATA "Hi Matt";
Cheers,
Curtis "Ovid" Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]