Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
No such thing as a small change
 
PerlMonks  

Re: Album Information Database

by jwkrahn (Abbot)
on Jan 05, 2007 at 08:42 UTC ( [id://593110]=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 Album Information Database

add.pl

$dbentry = "BPM-$info.txt"; #add DB prefix if (-e $dbentry) { #check if file already exists (it should't) open(DBENTRY, ">>$dbentry") || die "cannot open file $dbentry\n"; +#open w/ error handling print DBENTRY "$info\n "; #append Album info (shouldn't have to ap +pend) close(DBENTRY); #make sure we're all neat } else { #we should be creating a new file open(DBENTRY, ">$dbentry") || die "cannot create file $dbentry\n"; + #open w/ error handling print DBENTRY "$info\n "; #add the Album info close(DBENTRY); #make sure we're all neat }
You do realize that append mode will create the file if it does not already exist? So that should simply be:
$dbentry = "BPM-$info.txt"; #add DB prefix open(DBENTRY, ">>$dbentry") || die "cannot open file $dbentry: $!"; #o +pen w/ error handling print DBENTRY "$info\n "; #append Album info close(DBENTRY); #make sure we're all neat

bpm.pl

@files = (@files, $name); #add it!
Using push would be more efficient (and idiomatic.)
push @files, $name; #add it!

You should at least test your code with warnings enabled!

$ perl -Wc bpm.pl Found = in conditional, should be == at bpm.pl line 33.
That line should be:
if ($flag eq "yes") { #if the flag is on

But you could simplify that a lot and there is no need to store all of the files lines in an array, just store the ones that match /$bpm/:

foreach my $filename ( @files ) { #for each filename in the array open(PHILE, '<', $filename) || die "cannot open $filename: $!"; #o +pen file w/ error handling my @lines = scalar <PHILE>; #get the Artist/Album info while ( <PHILE> ) { push @lines, $_ if /$bpm/; } if ( @lines > 1 ) { print @lines; } else { print "sorry, no matching BPMs found."; #deliver the bad news } close PHILE; #finish up }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593110]
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.