pccode has asked for the wisdom of the Perl Monks concerning the following question:
$original = &promptUser("Enter original filename"); $modified = &promptUser("Enter modified filename"); open($ORIG, "$original"); binmode($ORIG); open($MOD, ">$modified"); binmode($MOD); $/ = "\x00"; while (<$ORIG>) { $count = (($change = $_) =~ s/(\x33\x33\x39\x39.*?\x00)/"\x00" x lengt +h($1)/e); if ($count == null) { print $MOD $_; } else { $answer = &promptUser("Modify $1?"); if ($answer == "y") { print $MOD $change; } else { print $MOD $_; } } } close $MOD; close $ORIG; sub promptUser { local($promptString,$defaultValue) = @_; if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; } else { print $promptString, ": "; } $| = 1; # force a flush after print $_ = <STDIN>; # get the input from STDIN chomp; if ("$defaultValue") { return $_ ? $_ : $defaultValue; # return $_ if it has a value } else { return $_; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl command line prompts
by Forsaken (Friar) on May 16, 2005 at 07:52 UTC | |
|
Re: perl command line prompts
by northwind (Hermit) on May 16, 2005 at 05:52 UTC | |
by pccode (Novice) on May 16, 2005 at 06:35 UTC | |
|
Re: perl command line prompts
by tlm (Prior) on May 16, 2005 at 09:35 UTC | |
by pccode (Novice) on May 16, 2005 at 20:08 UTC | |
by holli (Abbot) on May 16, 2005 at 20:23 UTC | |
by Transient (Hermit) on May 16, 2005 at 20:28 UTC | |
by tlm (Prior) on May 16, 2005 at 21:17 UTC | |
by pccode (Novice) on May 16, 2005 at 21:22 UTC |