Perl Best Practices [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Best Practices [Electronic resources] - نسخه متنی

Damian Conway

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







10.13. Simple Prompting


Always prompt for interactive input .


There are few things more frustrating than firing up a program and then sitting there waiting for it to complete its task, only to realize after a few minutes that it's actually been just sitting there too, silently waiting for you to start interacting with it:



# The quit command is case-insensitive and may be abbreviated...

Readonly my $QUIT => qr/\A q(?:uit)? \z/ixms;
# No command entered yet...
my $cmd = $EMPTY_STR;
# Until the q[uit] command is entered...
CMD:
while ($cmd !~ $QUIT) {
# Get the next command...
$cmd = <>;
last CMD if not defined $cmd;

# Clean it up and run it...

chomp $cmd;
execute($cmd)
or carp "Unknown command: $cmd";
}

Interactive programs should

always prompt for interaction whenever they're being run interactively:



# Until the q[uit] command is entered...

CMD:
while ($cmd !~ $QUIT) {

# Prompt if we're running interactively...

if (is_interactive( )) {
print get_prompt_str( );
}
# Get the next command...

$cmd = <>;
last CMD if not defined $cmd;
# Clean it up and run it...

chomp $cmd;
execute($cmd)
or carp "Unknown command: $cmd";
}


/ 317