in reply to Re: extracting dissimilar lines
in thread extracting dissimilar lines

A bit shorter, using no split, no additional variables and only one regex:
$/ = ""; while (<>) { /=\s*([^\n]+).*=\s*([^\n]+)/s; print unless $1 eq $2; }

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 Deltronics

Replies are listed 'Best First'.
Re^3: extracting dissimilar lines
by JavaFan (Canon) on Mar 26, 2012 at 21:16 UTC
    That would fail if the second line contains more than one '='. But, if you think there's value in replacing trivial regexes (which can be dealt with by the optimizer) with complicated ones, why not:
    $/ = ""; /=(\N+)\n[^=]+=\1\n/ or print while <>;
    Or, as a one-liner:
    perl -00ne'/=(\N+)\n[^=]+=\1\n/ or print' data-file
      Even better!

      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 Deltronics