[JaxPM] counting a string

Steve Lane sml at zfx.com
Fri Feb 25 13:10:54 CST 2000


On the jacksonville-pm-list; Jax.PM'er Steve Lane <sml at zfx.com> wrote -

just use the length() function.  

  print "whatever" if length($pass) > 14;

Nate wrote:
> 
> On the jacksonville-pm-list; Jax.PM'er Nate <nate at netimages.com> wrote -
> 
> The other day I wanted to count a string to make sure that it wasn't too
> long (it was to check the length of a username/password pair for an
> account generation script).
> 
> I figured I could do something like this:
> 
> print "Password too long, try again\n" if $pass > 14;
> 
> ..but it didn't work.
> I ended up having to do this:
> 
> while($pass =~ /./g) {
>         $count++;
> }
> if($count > 14) {
>         print "Password too long, try again";
> } elsif ($count < 4) {
>         print "Password too short, try again";
> }
> 
> It works great, but it's just not what I thought needed to be done (I
> think I found the latter in the Cookbook). Plus, I like the first form, as
> it reads like english, and is easy to maintain.
> 
> It's all done now, but next time could I use the first form? Did I just
> get the sytax wrong (BTW, I forget the exact syntax I tried the first
> time, I just made it up again ;)
> 
> Thanks in advance,
> Nate
>  -----------------------------------------------------------
> | Nate Campi         | Net Images Support                   |
> | nate at netimages.com | Internet Presence: www.netimages.com |
> | nate at campin.net    | Infosec docs: www.campin.net         |
>  -----------------------------------------------------------
> 
> Jax.PM Moderator's Note:
> This message was posted to the Jacksonville Perl Monger's Group listserv.
> The group manager can be reached at -- owner-jacksonville-pm-list at pm.org
> to whom send all praises, complaints, or comments...

--
Steve Lane <sml at zfx.com>

Jax.PM Moderator's Note:
This message was posted to the Jacksonville Perl Monger's Group listserv.
The group manager can be reached at -- owner-jacksonville-pm-list at pm.org
to whom send all praises, complaints, or comments...




More information about the Jacksonville-pm mailing list