Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Whats Wrong Here?!?!

by Anonymous Monk
on Sep 12, 2002 at 10:21 UTC ( [id://197185]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I Have wrote the script below but cannot find out what it is complaining about when i try to run it. I try to fix it and then make it worse!! Help much appreciated.
#! /usr/bin/perl -wT use strict; # where grab account details from file goes my $username = 'bob'; my $realname = 'Bob The Great'; my $emailadd = 'a@b.com'; my $service = 'Yes'; my $ipaddr = '1.2.3.4'; my $file = 'nothing'; # Sanitise Passed Variables if ($realname !~ /^[-.\w\s]{3,30}$/) { # unlink $file; print "Realname Invalid\n"; exit; } if ($username !~ /^[A-Za-z][-.\w]{2,29}) { # unlink $file; print "Username Invalid\n"; exit; } # Generate Random Password And Encrypt It my @chars = ('a'..'z', 'A'..'Z', 0..9); my $password = do {{ local $_ = join "" => map {$chars [rand @chars]} 1..8; redo unless /[a-z]/ && /[A-Z]/ && /\d/; $_; }}; my $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; my $encrpass = crypt($password, $salt); #Take Current System Date And Add Two Weeks On For Trial use constant WEEK => 60 * 60 * 24 * 7; my $expires = sprintf '%04d-%02d-%02d', sub { $_[5]+1900, $_[4]+1, $_[3] }->(localtime(time + 2 * WEEK)); # Create Unix User Account # Do Stuff Here
Judging by the errors, my code is in a complete mess:
In string, @chars now must be written as \@chars at ./adduser.pl line +22, near "$file; print "Username Invalid\n"; exit; } # Generate Random Password And Encrypt It my @chars" Global symbol "@chars" requires explicit package name at ./adduser.pl +line 22. Global symbol "$password" requires explicit package name at ./adduser. +pl line 22. Global symbol "$chars" requires explicit package name at ./adduser.pl +line 22. In string, @chars now must be written as \@chars at ./adduser.pl line +22, near "$chars [rand @chars" Global symbol "@chars" requires explicit package name at ./adduser.pl +line 22. syntax error at ./adduser.pl line 33, near "redo unless /[" (Might be a runaway multi-line // string starting on line 22) Unmatched right curly bracket at ./adduser.pl line 35, at end of line syntax error at ./adduser.pl line 35, near "}" Execution of ./adduser.pl aborted due to compilation errors.

Replies are listed 'Best First'.
Re: Whats Wrong Here?!?!
by jmcnamara (Monsignor) on Sep 12, 2002 at 10:26 UTC

    You are missing a trailing slash in this m//:
    if ($username !~ /^[A-Za-z][-.\w]{2,29}) {

    --
    John.

      Cheers. I noticed that just after posting. *goes bright red*. ohh, what difference a / can make!
      Which is exactly why a syntax highilghting editor is so handy.

      -- Dave
Re: Whats Wrong Here?!?!
by Anonymous Monk on Apr 22, 2016 at 17:26 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://197185]
Approved by krisahoch
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-26 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found