📄 ch10.066_prob
字号:
################################################################################ Code fragment (NOT RECOMMENDED) from Chapter 10 of "Perl Best Practices" #### Copyright (c) O'Reilly & Associates, 2005. All Rights Reserved. #### See: http://www.oreilly.com/pub/a/oreilly/ask_tim/2001/codepolicy.html ################################################################################# Standard modules...use strict;use warnings;use IO::Prompt;use Carp;use English qw( -no_match_vars );use Data::Alias;use Readonly;Readonly my @CONFIG_PATHS => qw( dev/config dev/config/alt ~/config /usr/config );Readonly my $REMOTE_SERVER => 'foobar@foo.bar';Readonly my $MAX_TRIES => 100;Readonly my $QUIT => qr/\A q(?:uit)? \z/ixms;sub init_from { return sleep 2;}sub connect_to { my ($server, $opt_ref) = @_; sleep $opt_ref->{timeout}; return rand 0 > 0.7 ? 'pipe' : undef;}my @fibonacci;sub fibonacci { my ($n) = @_; return 1 if $n < 2; return $fibonacci[$n] ||= fibonacci($n-1) + fibonacci($n-2);}my $prompt_str = '> ';# Initialize from any config files...for my $possible_config ( @CONFIG_PATHS ) { init_from($possible_config);} # Connect to remote server...my $connection;TRY:for my $try (1..$MAX_TRIES) { # Retry connection with increasingly tolerant timeout intervals... $connection = connect_to($REMOTE_SERVER, { timeout => fibonacci($try) }); last TRY if $connection;}croak "Can't contact server ($REMOTE_SERVER)" if !$connection; # Interactive portion of the program starts here...while (my $cmd = prompt($prompt_str, -fail_if=>$QUIT)) { remote_execute($connection, $cmd) or carp "Unknown command: $cmd";}sub remote_execute { my ($connection, $cmd) = @_; print "remotely executing via $connection: $cmd\n"; return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -