Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Following Aiden Bell's hint, I tried Readline in Perl. Solution 1 using Term::Complete (also used by CPAN, I think):</p> <pre><code>use Term::Complete; my $F; open($F,"&lt;","bin/phonebook.csv"); my @terms = &lt;$F&gt;; chomp(@terms); close($F); my $input; while (!defined $input) { $input = Complete("Enter a name or number: ",@terms); my ($name,$number) = split(/\t/,$input); print("Sending SMS to $name ($number).\n"); system("sudo gammu --sendsms TEXT $number"); } </code></pre> <p>Press \ to complete, press Ctrl-D to see all possibilities. </p> <p>Solution 2: Ctrl-D is one keystroke to much, so using standard Term::Readline allows completion and the display off possible completions using only \.</p> <pre><code>use Term::ReadLine; my $F; open($F,"&lt;","bin/phonebook.csv"); my @terms = &lt;$F&gt;; chomp(@terms); close($F); my $term = new Term::ReadLine; $term-&gt;Attribs-&gt;{completion_function} = sub { return @terms; }; my $prompt = "Enter name or number &gt;&gt; "; my $OUT = $term-&gt;OUT || \*STDOUT; while ( defined (my $input = $term-&gt;readline($prompt)) ) { my ($name,$number) = split(/\t/,$input); print("Sending SMS to $name ($number).\n"); system("sudo gammu --sendsms TEXT $number"); } </code></pre> <p>This solution still needs a for completion.</p> <p><strong>Edit: Final Solution</strong> Modifying Term::Complete (<a href="http://search.cpan.org/~jesse/perl-5.12.0/lib/Term/Complete.pm" rel="nofollow noreferrer">http://search.cpan.org/~jesse/perl-5.12.0/lib/Term/Complete.pm</a>) does give me on the fly completion.</p> <p>Source code: <a href="http://search.cpan.org/CPAN/authors/id/J/JE/JESSE/perl-5.12.0.tar.gz" rel="nofollow noreferrer">http://search.cpan.org/CPAN/authors/id/J/JE/JESSE/perl-5.12.0.tar.gz</a> Solution number 1 works with this modification. I will put the whole sample online somewhere else if this can be used by somebody</p> <p>Modifications of Completion.pm (just reusing it's code for Control-D and \ for each character):</p> <p><code> 170c172,189</p> <blockquote> <pre><code> my $redo=0; @match = grep(/^\Q$return/, @cmp_lst); unless ($#match &lt; 0) { $l = length($test = shift(@match)); foreach $cmp (@match) { until (substr($cmp, 0, $l) eq substr($test, 0, $l)) { $l--; } } print("\a"); print($test = substr($test, $r, $l - $r)); $redo = $l - $r == 0; if ($redo) { print(join("\r\n", '', grep(/^\Q$return/, @cmp_lst)), "\r\n"); } $r = length($return .= $test); } if ($redo) { redo LOOP; } else { last CASE; } </code></pre> <p></code></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload