Hi all ! I can't figure out what is the problem here. I'm trying to do 'sed' like regex replace to files, but, at the same time ask a question if I want it run for the file in question. The problem is that the second time I call the ja_nei() it seems to hang. My guess is that there is some buffer issues that I can't seem to figure out. I've used to run the same code but by calling sed from doSystemCommand - but, I hate having to use sed for something that I should be able to do in perl only. I was hoping to write this without any use of modules.
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; }

In reply to inline replace and stdin problem by Thalamus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.