Use the Perl script on the terminal to automatically complete the input content

Source: Internet
Author: User
Tags perl script
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.