Try using double quotes around the $filename part when you open it to write.

Dan

-----Original Message-----
From: Colin Johnstone [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 14, 2003 8:32 AM
To: [EMAIL PROTECTED]
Subject: File Handling


Gidday all,

Im having trouble reading and writing to this file, It's probably just something 
silly. Heres my code. I have set the permissions on the file to 775.

<code>
my ($filename);

$filename = "/home/bdweb8083m/johnstonefamily.com/cgi-bin/hp_data/participants.txt";

if( -e $filename ){
  print "Yeah - File exists<br>";
}

my @participants;

open IN, "<$filename" || die( "Cannot Open: $!" );
while( my $line = <IN> ){
  chomp $line;
  push( @participants, $line );
}
close IN;

print "Num elements array participants = ".scalar( @participants )."<br>";

my $outString;
$outString  = "";
$outString .= $fields{'SelectCity'} . ",";
$outString .= $fields{'Workshop1'} . ",";
$outString .= $fields{'Workshop2'} . ",";
$outString .= $fields{'Salutation'} . ",";
$outString .= $fields{'FirstName'} . ",";
$outString .= $fields{'LastName'} . ",";
$outString .= $fields{'Title'} . ",";
$outString .= $fields{'CompanyName'} . ",";
$outString .= $fields{'CompanyAddress'} . ",";
$outString .= $fields{'Suburb'} . ",";
$outString .= $fields{'State'} . ",";
$outString .= $fields{'PostCode'} . ",";
$outString .= $fields{'PhoneNumber'} . ",";
$outString .= $fields{'Mobile'} . ",";
$outString .= $fields{'EmailAddress'};

print "Out string =$outString<br>";

push( @participants, $outString );

print "Num elements array participants = ".scalar( @participants )."<br>";

print "@participants\n\n";

open( OUTFILE, '>$filename') or die( "Cannot open file: $!"); while( @participants ){
  my $val = shift( @participants );
  print( OUTFILE "$val\n" );
}
close( OUTFILE ) or die( "Cannot close file: $!");
</code>

Here is a sample of the output I get on the screen

<output>
Yeah - File exists
Num elements array participants = 2
Out string =Melbourne,Next Generation Alpha Servers - Simplifying Cluster Management 
with Single System Image,HP Single Server Strategy - Itanium is 
real,vcxzvcxzv,vcxzvcxz,vxzcvcxz,zxcvcxzvxc,vzcxvzcx,xczvcxzv,vzxcvzcxv,vcxv
zcxv,vzxcvzcxv,vzcxvxzcv,vzxcvzxcvz,[EMAIL PROTECTED]
Num elements array participants = 3
Melbourne,Next Generation Alpha Servers - Simplifying Cluster Management with Single 
System Image,HP Single Server Strategy - Itanium is 
real,vcxzvcxzv,vcxzvcxz,vxzcvcxz,zxcvcxzvxc,vzcxvzcx,xczvcxzv,vzxcvzcxv,vcxv
zcxv,vzxcvzcxv,vzcxvxzcv,vzxcvzxcvz,[EMAIL PROTECTED]
</output>

Im pulling my hair out, maybe I've been at it too long today, Im going to bed, 
hopefully the morning will bring a solution.

Any help appreciated.

Colin



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