Robert Day wrote:
> I am using a very basic Perl script to parse a file and extract
> just the elements I need ...
<snip>
> I don't know how to get rid of "Enter bookmobile session location
> code (or NONE) : NONE" when it appears (as it does on a few
> entries). i have tried various patterns and I am sure the solution
> is simple but it eludes me at present. Can anyone help?
As regards the approach I have to ask: If you want to extract
something, why do you not write code that does just that rather than
deleting everything that you do not want to keep?
$library =~ s/^\s+\d{2}\s\w{3}\s\d{4}\s+//;
----------------------^
What's your considerations behind beginning the pattern with the ^
metacharacter?
perldoc perlvar points out that the $` variable "anywhere in a program
imposes a considerable performance penalty on all regular expression
matches". There appears not to be any reason to use it here.
> $library = $`;
> $library =~ s/^\s+\d{2}\s\w{3}\s\d{4}\s+//;
> $library =~ s/- CAMBOOK//g;
You may want to replace those three lines with:
my ($library) = /\d{2} \w{3} \d{4}\s+(.+?)(?:- CAMBOOK)?\s+UV/;
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl