search and replace a pattern in a line in perl -



search and replace a pattern in a line in perl -

i need help regular expression:

i have file has line this:

label 9 { v { some_text ; } w { some_text;} } #12345.

now status is, if line has label 9, have replace nop (everything else on line should remain same) , can't seem figure out why

this did (only releveant portion of code):

my $cur_line = $_; if($cur_line =~ s/label\s+9/) { $cur_line =~ s/label\s+9/nop/; print "$cur_line"; }

thanks!

your code did not compile me untill changed:

if($cur_line =~ s/label\s+9/)

to:

if($cur_line =~ /label\s+9/)

note s/. then, performed substitution desire.

you can simplify as:

my $cur_line = $_; if ($cur_line =~ s/label\s+9/nop/) { print $cur_line; }

perl

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -