Tox has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys This is my first post, just joined this website really like it ! looking forward to learn Perl. Am currently writing a bash script and need to uncomment a line in a configuration file with the word "sql" line is like this: #sql The problem is that in this configuration file there are more than one: #sql So was thinking on a command that could specify to uncomment the #sql between line numbers, this way can be very precise on what #sql is exactly the one I want to uncomment. Any one can share a good perl command to accomplish this ? Thank you in advance

Replies are listed 'Best First'.
Re: Perl Command Help
by toolic (Bishop) on Dec 19, 2013 at 19:55 UTC
    perintro is a good place to learn. This might give you some ideas:
    use warnings; use strict; while (<DATA>) { s/#sql/sql/ if $. > 2 and $. < 5; print; } __DATA__ #sql #sql #sql #sql #sql #sql #sql
      Or even
      s/#sql/sql/ if 3 .. 4;
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Perl Command Help
by aitap (Curate) on Dec 20, 2013 at 20:02 UTC

    In addition to the previous comments, Perl can be used like sed to edit files on the fly if ran with the -i switch (often used with -p) in the command line or the hashbang line.

    If you write your program for -i and -p switches, all your code needs to do is to change the $_ variable which equals to the current line of the file being edited (the code is re-ran on each line sequentially). Read perlrun for more information on this topic.