Hi to all,
I want to create a script which can substitute a more-than-one-word substitution with more than other one from command line in a large amount of files.


My idea:
$ perl command words to be substitute -f words with which substitute -f2 file file file...


(-f marks the end (the italian word for end is "fine") for the first group of words and -f2 the end of second group).

The script can see and print al my variables (in particular $pattern and $replacement) but doesn't use them, and I'm sure it's something of simple but (for my eyes) invisible.

Thanks a lot,

alladr



===========================THE SCRIPT========================

#!/usr/bin/perl -w

use strict;
my ($var, $mark1, $mark2, $pattern, $replacement);
foreach $ARGV (@ARGV)
{
        $mark1 = $var if ($ARGV eq "-f");
        $mark2 = $var if ($ARGV eq "-f2");
        $var++;
}
$var = 0;
for($var = 0; $var < $mark1; $var++)
{
        $pattern .= "$ARGV[$var] ";
}
$mark1++;
for($var = $mark1; $var < $mark2; $var++)
{
        $replacement .= "$ARGV[$var] ";
}
$var -= $mark2;
$mark2++;
chomp $pattern;
chomp $replacement;

################
# here my problem: the script see my $pattern and my $replacement but doesn't use them
#
# someone can help me?
################


$^I = '';
splice @ARGV, 0, $mark2;

while(<>){
        tr/\015\012/\n/s;
        s/$pattern/$replacement/g;
        print;
        print STDOUT ++$var, " - I cleaned $ARGV\n" if (eof);
    }


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to