Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Generate list of possibilities from incomplete input

by johngg (Canon)
on Jan 21, 2018 at 01:03 UTC ( [id://1207610]=note: print w/replies, xml ) Need Help??


in reply to Generate list of possibilities from incomplete input

You could use glob with substr although it gives a warning.

johngg@shiraz ~/perl/Monks $ perl -Mstrict -Mwarnings -E ' my $str = q{0ae}; my $globStr = q/{/ . join( q{,}, 0 .. 9, q{a} .. q{f} ) . q/}/; for my $off ( 0 .. length( $str ) + 1 ) { my $new = $str; substr $new, $off, 0, $globStr; say for glob $new; }' 00ae 10ae 20ae 30ae 40ae 50ae 60ae 70ae 80ae 90ae a0ae b0ae c0ae d0ae e0ae f0ae 00ae 01ae 02ae 03ae 04ae 05ae 06ae 07ae 08ae 09ae 0aae 0bae 0cae 0dae 0eae 0fae 0a0e 0a1e 0a2e 0a3e 0a4e 0a5e 0a6e 0a7e 0a8e 0a9e 0aae 0abe 0ace 0ade 0aee 0afe 0ae0 0ae1 0ae2 0ae3 0ae4 0ae5 0ae6 0ae7 0ae8 0ae9 0aea 0aeb 0aec 0aed 0aee 0aef substr outside of string at -e line 7.

I hope this is useful.

Update: This gets rid of the warning.

johngg@shiraz ~/perl/Monks $ perl -Mstrict -Mwarnings -E ' my $str = q{0ae}; my $globStr = q/{/ . join( q{,}, 0 .. 9, q{a} .. q{f} ) . q/}/; for my $off ( 0 .. length $str ) { my $new = $str; substr $new, $off, 0, $globStr; say for glob $new; } $str .= $globStr; say for glob $str;' 00ae 10ae 20ae 30ae 40ae 50ae 60ae 70ae 80ae 90ae a0ae b0ae c0ae d0ae e0ae f0ae 00ae 01ae 02ae 03ae 04ae 05ae 06ae 07ae 08ae 09ae 0aae 0bae 0cae 0dae 0eae 0fae 0a0e 0a1e 0a2e 0a3e 0a4e 0a5e 0a6e 0a7e 0a8e 0a9e 0aae 0abe 0ace 0ade 0aee 0afe 0ae0 0ae1 0ae2 0ae3 0ae4 0ae5 0ae6 0ae7 0ae8 0ae9 0aea 0aeb 0aec 0aed 0aee 0aef 0ae0 0ae1 0ae2 0ae3 0ae4 0ae5 0ae6 0ae7 0ae8 0ae9 0aea 0aeb 0aec 0aed 0aee 0aef

Update 2: Shouldn't post late at night when brain already half asleep! The warning was because I was being an idiot, length( $str ) + 1 should be length $str of course :-/

johngg@shiraz ~/perl/Monks $ perl -Mstrict -Mwarnings -E ' my $str = q{0ae}; my $globStr = q/{/ . join( q{,}, 0 .. 9, q{a} .. q{f} ) . q/}/; for my $off ( 0 .. length $str ) { my $new = $str; substr $new, $off, 0, $globStr; say for glob $new; }' 00ae 10ae 20ae 30ae 40ae 50ae 60ae 70ae 80ae 90ae a0ae b0ae c0ae d0ae e0ae f0ae 00ae 01ae 02ae 03ae 04ae 05ae 06ae 07ae 08ae 09ae 0aae 0bae 0cae 0dae 0eae 0fae 0a0e 0a1e 0a2e 0a3e 0a4e 0a5e 0a6e 0a7e 0a8e 0a9e 0aae 0abe 0ace 0ade 0aee 0afe 0ae0 0ae1 0ae2 0ae3 0ae4 0ae5 0ae6 0ae7 0ae8 0ae9 0aea 0aeb 0aec 0aed 0aee 0aef

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-23 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found