r1571@llin: dpavlin | 2007-11-08 18:19:49 +0100
[webpac2] / lib / WebPAC / Normalize.pm
index ea4c49e..305d3be 100644 (file)
@@ -16,7 +16,7 @@ our @EXPORT = qw/
        marc_template
 
        rec1 rec2 rec
-       frec
+       frec frec_eq frec_ne
        regex prefix suffix surround
        first lookup join_with
        save_into_lookup
@@ -48,7 +48,7 @@ WebPAC::Normalize - describe normalisaton rules using sets
 
 =cut
 
-our $VERSION = '0.33';
+our $VERSION = '0.34';
 
 =head1 SYNOPSIS
 
@@ -1168,6 +1168,39 @@ sub frec {
        return shift @out;
 }
 
+=head2 frec_eq
+
+=head2 frec_ne
+
+Check if first values from two fields are same or different
+
+  if ( frec_eq( 900 => 'a', 910 => 'c' ) ) {
+       # values are same
+  } else {
+    # values are different
+  }
+
+Strictly speaking C<frec_eq> and C<frec_ne> wouldn't be needed if you
+could write something like:
+
+  if ( frec( '900','a' ) eq frec( '910','c' ) ) {
+       # yada tada
+  }
+
+but you can't since our parser L<WebPAC::Parser> will remove all whitespaces
+in order to parse text and create invalid function C<eqfrec>.
+
+=cut
+
+sub frec_eq {
+       my ( $f1,$sf1, $f2, $sf2 ) = @_;
+       return (rec( $f1, $sf1 ))[0] eq (rec( $f2, $sf2 ))[0];
+}
+
+sub frec_ne {
+       return ! frec_eq( @_ );
+}
+
 =head2 regex
 
 Apply regex to some or all values