hello everyone
i have a question about a program i have tried to write, i am a beginner to programming overall, and i am having much trouble with everything,including syntax errors and the like, but in this case,none are reported, even when using -w , it is a basic random password generator i tried to create for myself,as you can see,i am using the urandom file that is included with linux, the matching does not work, no matter what i put inbetween the m// function,it will push every character into the array, while i only want it to push 0-9 and a-z,i tried manually specifying /55-90/ also with a backslash /\55-90/ (can't use the [] parenthesis since it creates links,but in my program i have it) and just to try,i tried using the defined \w switch ,and nothing works.. thank you in advance for you reply
#!/usr/bin/perl -w
$DEBUG=1;
#this is my random password generator project
open(FILE ,"/dev/urandom") or die "could not open the file: $!";
$index=0;
print "how many characters in length should the password be?\n";
$input=<STDIN>;
chomp($input);
while($index < $input)
{
$character=getc FILE;
chomp($character);
print "### DEBUG: \$character is $character\n" if $DEBUG;
if(chr $character =~ m/[55-90]/)
{
push(@array ,$character);
$index++;
}
}
print reverse(@array);
close FILE;
UPDATE:I was making quite the bad mistakes i see.. i did check the documentation, but unfortunately i didnt grasp it too well, its just that i'm only about 2 weeks into programming and all of this still hurts my head a little.. i will learn, thank you all very much for your replies
20050209 Edit by castaway: Changed title from 'Why won't this program work?'
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.