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.

In reply to Whats Wrong Here?!?! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.