D
Dave Saville
I am processing records, one field of which is a "book number" this is
the "book" that the item belongs to. However it can belong to
multiple books. So the field can either be "1" or a semi colon
separated list "1;5;7" for example.
I want a simple test to see if an item belongs to a given book. Pseudo
code: "next if list does not contain book #".
Assuming $req holds the requested book number and $books holds the
string of books, two ways I have come up with that work are:
next if $books !~ m/^$req$|^$req;|;$req;|;$req$/;
or
next if ! grep { $req == $_ } split /;/, $books;
Neither of which I am that pleased with. Is there a better way?
TIA
the "book" that the item belongs to. However it can belong to
multiple books. So the field can either be "1" or a semi colon
separated list "1;5;7" for example.
I want a simple test to see if an item belongs to a given book. Pseudo
code: "next if list does not contain book #".
Assuming $req holds the requested book number and $books holds the
string of books, two ways I have come up with that work are:
next if $books !~ m/^$req$|^$req;|;$req;|;$req$/;
or
next if ! grep { $req == $_ } split /;/, $books;
Neither of which I am that pleased with. Is there a better way?
TIA