in reply to Skip a line
By the way, I'd write your code (above) as follows:
One thing needs to be stressed: you must explicitly close the file when you're done reading or writing it. Just releasing the lock (calling flock 8) is not enough. In fact, closing the file also releases the lock, so you don't need to call flock 8 at all, normally.my $now = time; my $expire_after_seconds = $expire_after_days * 24 * 60 * 60; open DATAFILEIN, "< $catagory.dat" or die "Your listing is the fir +st in this category!<br>"; flock DATAFILEIN, 2; my @temp = grep { ($now - (split /\|/)[6]) < $expire_after_seconds + } <DATAFILEIN>; close DATAFILEIN; unshift @temp, join( '|', $company_name, $time, $email, $member1, $member1phone, $data, $expiretime, $pictureurl, $password, $website, $member2, $member2phone, $address, $citystatezip, $fax, $catlisting )."\n"; if ( open DATAFILEOUT, "> $catagory.dat" ) { flock DATAFILEOUT, 2; print DATAFILEOUT @temp; close DATAFILEOUT; }
A couple other comments:
1. You probably will find it more convenient, in the long term, to use a hash variable, rather than that long slew of separate variables. I.e. instead of print DATAFILEOUT "$company_name|$time|$email|$member1|$member1phone|$data|$expiretime|$pictureurl|$password|$website|$member2|$member2phone|$address|$citystatezip|$fax|$catlisting\n"; you could have
for example.print DATAFILEOUT join( '|', @userinfo{qw( company_name time email member1 member1phone data expiretime pictureurl password website member2 member2phone address citystatezip fax catlisting )}, "\n";
2. Your emailme() subroutine should probably take arguments, rather than using global variables ($toemail, $fromemail). Then you could it as
Hope this helps,$emailme eq 'yes' and emailme( $myemail, $userinfo{'email'} ); $emailuser eq 'yes' and emailme( $userinfo{'email'}, $myemail );
jdporter
...porque es dificil estar guapo y blanco.
|
|---|