Re: help regex and substitutions



On Aug 31, 7:15 pm, john swilting <john.swilt...@xxxxxxxxxx> wrote:
how to make to improve my code...

#!/usr/bin/perl -w

use strict;
use diagnostics;

If you can afford, get rid of the "use diagnostics" to improve
execution speed.

use warnings;

my @conf = ('XferMethod',
'rsync',
'XferLogLevel',
'1',
'RSyncShare',
'___1___',
'ClientNameAlias',
'___2___');

print @conf,"\n";
my @substitution = @conf;
my $motif =qr/(___[1-9][0-9]?___)/is;
my @regexes = ();

##my @motif = ();
##foreach $motif ( @motif ) {
## push (@regexes,qr/$motif/);
## }

You could remove the commented out code altogether from your program,
it is confusing.

push (@regexes,$motif);
foreach my $elem ( @substitution ) {
foreach my $re ( @regexes ) {
if ( $elem =~ /$re/) {
print "$elem egal $re\nentrer la valeur\n";
chop ($elem =<STDIN>);

You could use chomp instead of chomp.
perldoc -f chomp
This safer version of chop removes any trailing string that
corresponds to the current value of $/

print "nouvelle valeur de",$elem,"\n";
}
}
}

.



Relevant Pages