Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: list of four digit lock combinations without repeated digits

by tybalt89 (Parson)
on Jun 20, 2018 at 20:18 UTC ( #1217052=note: print w/replies, xml ) Need Help??


in reply to list of four digit lock combinations without repeated digits

#!/usr/bin/perl # https://perlmonks.org/?node_id=1217042 use strict; use warnings; (1 x 10) =~ /.+?(.).*?(.).*?(.)(?{print @-, "\n"})(*FAIL)/;

Replies are listed 'Best First'.
Re^2: list of four digit lock combinations without repeated digits
by Lotus1 (Priest) on Jun 22, 2018 at 14:44 UTC

    I did ask for interesting solutions. It's going to take me a while to understand how this works. I found in perlvar a description of @- as being an array of the indexes of the matches. Thanks for posting.

    @- $-[0] is the offset of the start of the last successful match. $-[n] i +s the offset of the start of the substring matched by n-th subpattern +, or undef if the subpattern did not match. Thus, after a match against $_ , $& coincides with substr $_, $-[0], $ ++[0] - $-[0] . Similarly, $n coincides with substr $_, $-[n], $+[n] - + $-[n] if $-[n] is defined, and $+ coincides with substr $_, $-[$#-], + $+[$#-] - $-[$#-] . One can use $#- to find the last matched subgrou +p in the last successful match. Contrast with $#+ , the number of sub +groups in the regular expression. Compare with @+ . This array holds the offsets of the beginnings of the last successful +submatches in the currently active dynamic scope. $-[0] is the offset + into the string of the beginning of the entire match. The nth elemen +t of this array holds the offset of the nth submatch, so $-[1] is the + offset where $1 begins, $-[2] the offset where $2 begins, and so on.

      Here's another version without the @-

      Just match any four of the digits (from an ordered string).

      #!/usr/bin/perl # https://perlmonks.org/?node_id=1217042 use strict; use warnings; '0123456789' =~ /(.).*?(.).*?(.).*?(.)(?{print "$1$2$3$4\n"})(*FAIL)/;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2019-05-25 22:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (152 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!