I think this is what you are trying to achieve. I've commented each line so that you can understand exactly what's going on there.

#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp 'fatalsToBrowser'; my $query = CGI->new; print $query->header; my $usedpw = "logfile.txt" ; my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & *) ); # opening for reading open(USEDPW, "<", $usedpw) or die $!; # shared lock flock USEDPW, 1; # read entire file into array, one line per element my @usedpw = <USEDPW>; # close the file close(USEDPW); # remove new line chars from passwords chomp @usedpw; my $pw; my $used; # loop generating passwords until we create one that's unique do { # generate a password $pw = join @chars[map{rand @chars} (1..17)]; # assume it's not used $used = 0; # compare generated password to each existing password for (@usedpw) { # if the generated password has been used before, # set the used flag and abort the for loop $used=1,last if $_ eq $pw; } } while ($used); # display the password print "Your unique password is: $pw\n"; # open for append (>>) and save the new password open(USEDPW, ">>", $usedpw) or die $!; # exclusive lock flock USEDPW, 2; # write new password to end of file print USEDPW "$pw\n"; # close the file close(USEDPW);
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

In reply to Re: Losing or overwritting values by pfaut
in thread Losing or overwritting values by sulfericacid

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.