Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Generate list of possibilities from incomplete input

by BillKSmith (Monsignor)
on Jan 21, 2018 at 04:09 UTC ( [id://1207615]=note: print w/replies, xml ) Need Help??


in reply to Generate list of possibilities from incomplete input

Sometimes brute force is best. Here two foreach loops iterate the parameters of substr. The function uniq in the module List::Util removes the duplicates.
use strict; use warnings; use List::Util qw(uniq); my $given_string = '0ae4bb830'; my @results; foreach my $pos ( 0 .. 9 ) { foreach my $chr ( '0' .. '9', 'a' .. 'f' ) { my $out = $given_string; substr( $out, $pos, 0 ) = $chr; push @results, $out; } } { local $, = "\n"; print uniq(@results); }
Bill

Log In?
Username:
Password:

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

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

    No recent polls found