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 }


In reply to Re: Album Information Database by jwkrahn
in thread Album Information Database by bitsmart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.