in reply to deleting special lines from files

If you're merely trying to delete lines beginning with ';', then the following should work.

perl -ni.bak -e 'print unless /^;/' file
It also creates a backup file file.bak by using the -i flag. See perlrun for more options.

Hope that helped,
-v
"Perl. There is no substitute."

Replies are listed 'Best First'.
Re^2: deleting special lines from files
by theroninwins (Friar) on Sep 02, 2004 at 08:58 UTC
    Thanks but i want to run it from within the program. I program does other things too. It is only part of the program, so i can't call the program like that. But thank it is still a very usefull hint you gave me.
      my @data = grep { /^\S+;/ } <FILEHANDLE>;

      Then the lines you want are in @data.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        Perfect it works. Thanks so much.
        Just to understand better (it's the only way to learn :-) ) what do those symblos mean with grep?? What would you have to do if for examples the lines would be test;;understand and you want to delete those with the ;; in them??
      If the "other things" in your program are all happening inside a while loop like this:
      while (<>) { # or maybe using a file handle, like <IN> # do stuff... }
      and you just want to skip lines that start with a semi-colon, then just add one line at the top of the loop like this:
      while (<>) { next if ( /^\s*;/ ); # skip if first non-space char is ";" # now do stuff... }
      If you also want to delete lines with double semi-colons (because these represent empty fields), adjust that first line within the loop as follows:
      while (<>) { next if ( /^\s*;/ or /;;/ ); # now do stuff... }
      The "next" statement simply causes the script to skip everything that follows in the loop, and go right to the next iteration. The regular expressions in the "if" statement are saying:
      ^ -- line begins with... \s* -- zero or more white-space characters ; -- followed by a semi-colon or ;; -- there are two semi-colons together anywhere in the line