Recently, when running in a local environment using Perl, I need to enter a device name to determine the next step. Every time I run it here, I enter a long device name manually, for example, ciscocontenteng. Every time I input such a name, it is not only exhausting, but also prone to errors.
In this case, you can use the term: complete module to implement automatic completion with the tab key. Easy to use. CodeIt is almost understandable:
Use warnings; use strict;
Use term: complete;
My @ completion_list = ("atest", "btest", "cdtest", "efgtest ");
My $ input = complete ('Please input the start character and use tab to complete: ', \ @ completion_list); # $ input = complete ('prop _ string ', @ completion_list );
Print "the input word is:". $ input;
In the above Code, we set an array @ completion_list, which contains the name to be supplemented. Perl is based on this list to complete your input characters. The complete function is the core of this work. Its first parameter is the description of the prompt input output on the terminal, and the second parameter is the list of phrases that can be used for completion.
When running this script, you press the tab key. Perl will automatically use the words in the list to complete the task. You can press enter to confirm the completion. After the completion, perl stores your input content in the variable $ input.
In this way, you no longer need to break a long string of characters.