Hi all, I would really appreicate it if people would offer their expertise to help me with my programming, by letting me know what I'm doing wrong etc. In the last hour or so I have written a very quick script to choose lottery numbers (I have used it for tonight's draw, so I'll let you know if I win :) ) It is basically a command line program that will generate the random numbers and then you can email them to yourself, nothing fancy, just something I hope will help people give me some advice on where I am going wrong.

Thank you very much for any advice, code below.

#!/usr/bin/perl print "-------------------------------------------------------\n"; print "National Lottery Number Picker \n"; print "-------------------------------------------------------\n\n"; print "How many lines do you want to play?\n"; print "Lines.....:"; $lines = <STDIN>; @numbers = (1..49); srand; print "\n"; &chooseline(); $i = 1; sub chooseline { while ($i < $lines) { &genline(); push @lines, @line; $i++; if ($i eq $lines) { print "\n\n"; last; } } print "\n\n"; } sub genline { @line = ''; $e = 1; while ($e ne "7") { $index = rand @numbers; $element = $numbers[$index]; print " $element"; if ($e eq "6") { print "\n"; push @line, $element; $newline = "\n"; push @line, $newline; last; } else { push @line, $element; } $e++; } } print "(E)mail Results / (Q)uit\n\n"; print "Action....:"; $action = <STDIN>; exit if $action =~ /^Q/i; if ($action =~ /^E/i) { print "\nEmail address...:"; $email = <STDIN>; open (MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $email\n"; print MAIL "From: Lottery Generator\n"; print MAIL "Subject: Your Lottery Numbers\n"; foreach $lin (@lines) { print MAIL "$lin "; } close (MAIL); }

Edit kudra, 2001-11-04 Changed title


In reply to Some help with a lottery picking program 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.