Thalamus has asked for the wisdom of the Perl Monks concerning the following question:
print "Process \"$change_me\" ? (j/n) : "; $svar = ja_nei(<>); if ($svar) { fixer( 'anonymous_enable=YES','anonymous_enable=NO',"$change_me" ); fixer( '#nopriv_user=ftpsecure','nopriv_user=ftpsecure',"$change_me" + ); doSystemCommand("useradd -m ftpsecure -s /bin/bash"); } ## # Subs ## sub ja_nei { #chomp( my $input = (<STDIN>) ); my $input = (<STDIN>); if ( $input =~ /^j|^y/i ) { return 1; } else { return 0; } } sub fixer { my $pat = shift; my $to = shift; my $file = shift; my $count = 0; local $^I = ''; undef @ARGV; push @ARGV, $file; while (<>) { if (s/$pat/$to/g) { $count++; } print; } if ( $count == 0 ) { say "WARNING : No changes made to file \"$file\""; } elsif ( ($g_debug) && ($count) ) { say "\"$pat\" changed to \"$to\" in \"$file\""; } } sub doSystemCommand { my ($systemCommand) = @_; my $returnCode = system($systemCommand ); if ( $returnCode != 0 ) { die "Failed executing [$systemCommand] : $!\n"; } return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inline replace and stdin problem
by choroba (Cardinal) on May 21, 2014 at 12:02 UTC | |
|
Re: inline replace and stdin problem
by Anonymous Monk on May 21, 2014 at 12:00 UTC | |
|
Re: inline replace and stdin problem
by Thalamus (Acolyte) on May 21, 2014 at 12:21 UTC |