Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Efficient way to verify scalar contents

by tybalt89 (Monsignor)
on Jun 23, 2020 at 22:27 UTC ( [id://11118395]=note: print w/replies, xml ) Need Help??


in reply to Efficient way to verify scalar contents

Just for some TMTOWTDI fun :)

sub validate { local $_ = shift; length >= 20 ? 1 : !/[a-z]/ || !/[A-Z]/ ? 0 : length >= 16 ? 1 : !/\d/ ? 0 : length >= 12 ? 1 : !/[^_\w]/ ? 0 : length >= 8 ? 1 : 0; }

Besides, I think it's cute.

Replies are listed 'Best First'.
Re^2: Efficient way to verify scalar contents
by haukex (Archbishop) on Jun 24, 2020 at 09:46 UTC

    Nice, so far the only other solution that beats the original :-)

    Rate BillKSmith2 choroba2 LanX2 choroba1 LanX1 haukex1 + BillKSmith1 orig tybalt89 haukex2 BillKSmith2 38227/s -- -55% -60% -72% -72% -83% + -85% -85% -87% -88% choroba2 85658/s 124% -- -10% -38% -38% -62% + -66% -67% -70% -74% LanX2 95639/s 150% 12% -- -31% -31% -57% + -62% -63% -67% -71% choroba1 138099/s 261% 61% 44% -- -1% -38% + -44% -47% -52% -58% LanX1 138866/s 263% 62% 45% 1% -- -38% + -44% -47% -52% -58% haukex1 223763/s 485% 161% 134% 62% 61% -- + -10% -14% -22% -33% BillKSmith1 248507/s 550% 190% 160% 80% 79% 11% + -- -5% -13% -25% orig 260650/s 582% 204% 173% 89% 88% 16% + 5% -- -9% -21% tybalt89 287084/s 651% 235% 200% 108% 107% 28% + 16% 10% -- -13% haukex2 331543/s 767% 287% 247% 140% 139% 48% + 33% 27% 15% --

      Out of curiosity, I tried tr/// instead of regex, much faster :)

      sub validatetr { local $_ = shift; length >= 20 ? 1 : !tr/a-z// || !tr/A-Z// ? 0 : length >= 16 ? 1 : !tr/0-9// ? 0 : length >= 12 ? 1 : !tr/a-zA-Z0-9//c ? 0 : length >= 8 ? 1 : 0; }
        Out of curiosity, I tried tr/// instead of regex, much faster :)

        Looks like it's a winner :-)

        Rate BillKSmith2 choroba2 LanX2 choroba1 LanX1 haukex1 + BillKSmith1 orig tybalt89 haukex2 tybalt89_2 BillKSmith2 40957/s -- -53% -58% -71% -71% -82% + -84% -85% -85% -88% -91% choroba2 88071/s 115% -- -10% -38% -38% -61% + -65% -67% -69% -73% -82% LanX2 97356/s 138% 11% -- -31% -31% -57% + -61% -63% -65% -71% -80% choroba1 141499/s 245% 61% 45% -- 0% -37% + -44% -47% -50% -57% -70% LanX1 141499/s 245% 61% 45% 0% -- -37% + -44% -47% -50% -57% -70% haukex1 225463/s 450% 156% 132% 59% 59% -- + -11% -15% -20% -32% -53% BillKSmith1 252057/s 515% 186% 159% 78% 78% 12% + -- -5% -11% -24% -47% orig 265476/s 548% 201% 173% 88% 88% 18% + 5% -- -6% -20% -44% tybalt89 281788/s 588% 220% 189% 99% 99% 25% + 12% 6% -- -15% -41% haukex2 331918/s 710% 277% 241% 135% 135% 47% + 32% 25% 18% -- -30% tybalt89_2 476665/s 1064% 441% 390% 237% 237% 111% + 89% 80% 69% 44% --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found