On Wed, 10 Jul 2002 11:52:55 -0400, [EMAIL PROTECTED] wrote:

>This is what I have now.
>.......
>The only problem seems to be the 
>use strict;  directive
>if I take this out it works fine
>
>So I guess I need to know if the use strict; directive is really
>necessary and if so how do I get around it?
>
>Thanks

In addition to what the others have said about declaring your variables
and using strict; there is one other thing you must do to work
with strict. You must return the value of your get_date subroutine.
Without strict, the $date is global, so it works.
With strict, $date must be returned to a value.
############################################################
#!/usr/bin/perl
use warnings;
use strict;
# Here we define the variables
my $htpasswd = 'c:\apache\htdocs\members\.htpasswd';
my $database = 'c:\apache\members.db';
print "Content-type: text/html\n\n";
print 'Please write this down as it will not be emaild ', "\n";
print 'for your own security ', "\n";
# Here is the random gereration string.
my ( $username, $password ) = ( random_string(), random_string() );
print "Username: $username\n";
print "Password: $password\n";
sub random_string {

    my ($string) = '';
    my ($length) = 8;
    my (@chars)  = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9 );
    while ( length($string) != $length ) {
        $string .= $chars[ rand @chars ];
    }
    return ($string);
}

# get the date now!
my $date = &get_date;
print "$date\n";

# everything ok, let's write to database.

open( DATABASE, ">>$database" );
flock( DATABASE, 2 );
print DATABASE "$username|$password|$date\n";
flock( DATABASE, 8 );
close(DATABASE);

# everything ok, now we write to the password file.

my $uselog = 1;

if ( $uselog eq '1' ) {
    open( LOG, ">>$htpasswd" );
    print LOG "$username:$password\n";
    close(LOG);
}

sub get_date {
    my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
      localtime(time);
    my @months =
      ( "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
"11",
        "12" );
    my @digits = split ( //, $sec );
    my $size = @digits;
    if ( $size == 1 ) {
        $sec = "0$sec";
    }
    @digits = split ( //, $min );
    $size = @digits;
    if ( $size == 1 ) {
        $min = "0$min";
    }
    $year = $year + 1900;
    my $date1 = "$months[$mon]/$mday/$year";
    return $date1;
}




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

Reply via email to