in reply to Split a database

Sorry for messing up the code...I was able to figure it out about 5 minutes after posting my question. Here's my solution:
sub BuildMMList { $list = $FORM{'list'}; open(FILE, "$MM_FILE") || &error_message("Can't find data file - $dat +adir/lists.txt."); @list = <FILE>; close(FILE); $numlist = @list; for ($a = 0; $a < $numlist; $a ++) { ($one, $nochop) = split(/``/, $list[$a]); print "<option value='$one'>$one</option>\n"; } close(FILE); }
This seems to be working great but if anyone has any other methods please send them my way. Thanks

Replies are listed 'Best First'.
Re^2: Split a database
by particle (Vicar) on Oct 24, 2002 at 00:15 UTC

    it seems you've fixed your immediate problem, although i see you've left yourself open to more problems in the future. i have a few suggestions:

    sub BuildMMList { ## enforce strict programming methods (see strict) ## if you can't do this for the whole script, do it in each ## subroutine until the whole script has been refactored ## while you're at it, use warnings, too (see warnings) use strict; use warnings; ## pass parameters to the subroutine -- global variables are trouble ## assign the passed parameters to variables local to the scope of t +he sub my( $list, $mm_file ) = @_; ## use the three parameter form of open (see perlfunc) ## localize your filehandles to avoid namespace pollution ## don't quote variables unneccessarially (see perlvar) ## don't use the '&' sigil when calling subs (see perlsub) ## make your error messages verbose open( local *FILE, '<', $mm_file ) or error_message( "$0: Can't open data file: $mm_file: $!"); ## use a while loop to process the file in memory ## this avoids temp variables, and avoids c-like for loops while( <*FILE> ) { ## use the 3-arg form of split to limit fields ## throw away other fields by assigning to 'undef' my( $opt, undef ) = split /``/, $_, 2; ## use quote operators, so quote characters don't need to be escap +ed print qq{<option value="$opt">$opt</option>\n}; } }

    i haven't tested this code, so there may be a bug or two lurking. anywhere i have a parenthesised note, you should use perldoc to find more info, or supersearch perlmonks for more.

    i'm sorry i can't offer you more help (like using taint mode to safely process cgi params), but i hope this will get you started, and you'll go looking for more as you need it.

    ~Particle *accelerates*