Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I populate a scrolling list on a web page with values taken from a text file.

Replies are listed 'Best First'.
Re: Lists
by davorg (Chancellor) on Apr 17, 2001 at 19:54 UTC

    Of course, you'll be using CGI.pm for this task...

    #!/usr/bin/perl -w use strict; use CGI qw(:standard); open(FILE, '/path/to/file') or die "$!\n"; my @text = <FILE>; chomp @text; print header, start_html, start_form(-action=>'/cgi-bin/myscript.pl'), scrolling_list(-name=>'list', -values=>\@text, -size=>5), submit, end_html;

    You might need to add a bit more HTML :)

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: Lists
by suaveant (Parson) on Apr 17, 2001 at 19:46 UTC
    open(DATA,'file') or die $!; print "<SELECT NAME=foo>"; while(<DATA>) { chomp; print "<OPTION>$_</OPTION>\n"; } print "</SELECT>"; close DATA;
    that'll read the file, strip the newline, and put each line as an option in the select box.
                    - Ant

      Or, using the handy function in CGI.pm,

      use CGI qw(:standard); # stuff open FILE, $filename or die "Can't open $filename: $!\n"; my @lines = <FILE>; chomp @lines; close FILE; # more stuff print scrolling_list(-name=>'foo', -values=>\@lines);

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor