use Modern::Perl; my $filename = $ARGV[0]; die "Usage: modulenamechanger.pl filename newmodulename oldmodulename\ +n" unless @ARGV == 3; open my $INFILE, "<", $filename or die "Failed to read file $filename +: $!"; say "Now parsing $filename"; my @file = <$INFILE>; close $INFILE; open my $OUTFILE, '>', $filename or die "Failed to create $filename"; my $match = qr "module\s*($ARGV[2])"; say "Matching: $match"; for my $line (@file) { if ( $line =~ m(^//) ) { print $OUTFILE $line; next; } $line =~ s/$match/module $ARGV[1]/; print $OUTFILE $line; }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re^2: Bug in script, regex help req extreme urgent
by CountZero
in thread Bug in script, regex help req extreme urgent
by sid.verycool
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |