Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Just another Perl shrine
 
PerlMonks  

Re: grep problems and file copying issues

by chromatic (Archbishop)
on Jul 10, 2000 at 17:36 UTC ( [id://21827]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to grep problems and file copying issues

grep'll do what you want, in this case, but I would rather use a hash. (As your list of CDs grows, the grep operation will take longer, while a hash lookup will always take the same amount of time.)
my %dbfile = (); open DBFILE , "$dbFileName" or die $!; foreach (<DBFILE>) { $dbfile{$_} = 1; } close DBFILE; if (defined $dbfile{$cdLabel}) print "This CD ($cdLabel) is already in the database\n"; exit; }
Better way to do it.

Replies are listed 'Best First'.
RE: Re: grep problems and file copying issues
by ambiguous (Novice) on Jul 10, 2000 at 23:01 UTC
    Good answer. I'd just like to add don't forget that hash keys are case sensitive so be to lc() or uc() they keys when you populate and reference the hash. Also, depending on how/where the $cdLabel is populated, you should probably strip all leading and trailing white space, $cdLabel =~ s/^\s+//; $cdLabel =~ s/\s+$//; Hope that helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://21827]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.