in reply to Re: PERL $/variable
in thread PERL $/variable

Well it worked for me until I realized suspicious solution with $/ = value. Still it does what I want for file 1 :)

Replies are listed 'Best First'.
Re^3: PERL $/variable
by kennethk (Abbot) on Mar 11, 2010 at 18:45 UTC
    It works for file 1 because records are separated by multiple new lines. The regular expression returned "" and, as per the provided link ($/):

    Setting to "" will treat two or more consecutive empty lines as a single empty line.
      If I do now:$/==""; it doesn't work for file1. I have to write $/=""; to make it work. So to conclude the best solution for me is to set different $/ for file1 ($/="";) and file2 (default $/). Am I not right ?
        You could, or you could skip blank lines
        while (<$fh>) { chomp; next if !length; ... }
        As I said below, $/==""; is a meaningless statement - a logical test where you do not use the return value. What is wrong with the solution I provided? As far as I can tell, it works on both your file formats. Using $/ in this context would require you to know the format of the file ahead of time - you would have to read the file twice.