in reply to modifying a file with regex!

easy.
#!/usr/bin/perl -w -i.bak $regexfile = shift @argv; open (FH, $regexfile); @regexen = <FH>; close FH; while (<>) { foreach $regex (@regexen) { ($a, $b) = split /\t/, $regex; s/$a/$b/og; } }
this should work, but it may not.

Original code restored below by GrandFather

#!/usr/bin/perl -w $regexfile = shift @argv; open (FH, $regexfile); @regexen = <FH>; close FH; while (<>) { foreach $regex (@regexen) { $regex; } }

--linuxkid


imrunningoutofideas.co.cc

Replies are listed 'Best First'.
Re^2: modifying a file with regex!
by aaron_baugher (Curate) on Mar 17, 2012 at 19:32 UTC

    I don't have three whole years of Perl experience, but I think this is broken. What are you expecting it to do? $regex will contain a line (at least a newline) from the first file given on the command line. What's Perl supposed to do with that when you give it as an expression by itself?

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.

      a s/// regex left without being bound to a variable with ~= just acts upon $_

      --linuxkid


      imrunningoutofideas.co.cc
        But in your code, there is no s/// regex, there is a variable. And even if there had been any change in $_, there is no output going on.

        But a variable that contains a string that looks like a regex isn't a regex, and Perl won't know to automatically treat it like one. Have you tried running your own script yet? Aren't you curious what it does?

        Aaron B.
        My Woefully Neglected Blog, where I occasionally mention Perl.

        A reply falls below the community's threshold of quality. You may see it by logging in.