After some tinkering:
use strict; use warnings; my $original = &promptUser("Enter original filename"); my $modified = &promptUser("Enter modified filename"); open(my $ORIG, "$original") or die "could not open $original"; binmode($ORIG); open(my $MOD, ">$modified") or die "could not open $modified"; binmode($MOD); # commented out $/ = "\x00"; while (<$ORIG>) { my $count = ((my $change = $_) =~ s/(\x33\x33\x39\x39.*?\x00)/"\x00" + x length($1)/e); if ($count == 0) { print $MOD $_; } else { my $answer = &promptUser("Modify $1?"); if ($answer eq "y") # <-- eq for test, == is for numerical compari +sons { print $MOD $change; } else { print $MOD $_; } } } close $MOD; close $ORIG; sub promptUser { my($promptString, $defaultValue) = @_; if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; } else { print $promptString, ": "; } $| = 1; # force a flush after print my $line = <STDIN>; # get the input from STDIN chomp($line); if ($defaultValue) { return $line ? $line : $defaultValue; } # return $line if it ha +s a value else { return $line; } }
Turns out it was your $/ that caused it. Btw, is there supposed to be only 1 change in the entire file?

Oh, and please, in the future, for the sake of your own sanity as well as ours:
- use strict;
- use warnings;
- indent
- just like in english(or other languages), a space after a comma please
- (personal opinion) assign $_ to a named variable if you're going to use that value for more than the most basic of functions.

Remember rule one...


In reply to Re: perl command line prompts by Forsaken
in thread perl command line prompts by pccode

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.