in reply to File modification

$argact = $ARGV[0] or die "No number given\n"; open INPUT, 'one.txt' or die $!; open NEWFILE, '>', 'output' or die $!; while (<INPUT>){ if(/^Authentication\s+number\s+is/) { my ($old_num) = /(\d+)/; if ($argact != $oldnum) { $changeflag = 1; s/\d+/$argact/; } } print NEWFILE; }

Note: I've included $changeflag only because it was in the original code. I've no idea what it's there for. Maybe its value is checked later on in the program.

Update: Typo fixed.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: File modification
by Hofmator (Curate) on Jul 07, 2006 at 12:33 UTC

    Update: too slow ...

    Minor nit ...

    s/\d+/$argact;
    is missing a closing /.

    -- Hofmator

Re^2: File modification
by qsl (Scribe) on Jul 07, 2006 at 12:28 UTC
    Hi davorg
    I am running your code and getting the following compilation error,
    [ristee:croco]perl -c filemod.pl Substitution replacement not terminated at filemod.pl line 11.
    thanks

      Yes, there was a typo in my code. Pretty simple to fix tho' I would have thought.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg