Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Scrolling list and data

by nasa (Beadle)
on Dec 13, 2006 at 06:13 UTC ( [id://589495]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings wonderfull people.

I have a DIR with several .data files in it.
I hoped to extract the data files to a scrolling list like so
opendir(HOMEDIR, "\interest") || die ("Unable to open directory"); while ($filename = readdir(HOMEDIR)) { print scrolling_list('name',[$filename]); } closedir(HOMEDIR);
This resulted in creating a separate scrolling list for each file in the DIR.
Very untidy
I have seen arrays printed in textboxes before
So I then tried this.
opendir(HOMEDIR, "\interest") || die ("Unable to open directory"); while ($filename = readdir(HOMEDIR)) { @array = $filename; print scrolling_list('name',[@array]); } closedir(HOMEDIR);
However this resulted in exactly the same thing
A separate scrolling box for each file .
Whats the trick here guys.
How do we lock the little critters in one scrolling box.

Replies are listed 'Best First'.
Re: Scrolling list and data
by ikegami (Patriarch) on Dec 13, 2006 at 06:57 UTC

    "\interest" doesn't mean what you think it means.

    $\ = "\n"; print "interest"; # interest print "\interest"; # interest print "\\interest"; # \interest print 'interest'; # interest print '\interest'; # \interest print '\\interest'; # \interest print "test"; # test print "\test"; # A tab followed by est print "\\test"; # \test print 'test'; # test print '\test'; # \test print '\\test'; # \test

    See "Quote and Quote-like Operators" in perlop.

    And please please please use use strict;.

Re: Scrolling list and data
by McDarren (Abbot) on Dec 13, 2006 at 06:32 UTC
    Two things:

    Firstly, from perldoc CGI:

    1. The first and second arguments are the list name (-name) and value +s (-values). As in the popup menu, the second argument should be an +array reference.

    So you need to pass your array as a reference. Something like the following should do the trick:

    print scrolling_list('name', \@array);

    Secondly, you need to remove that line of code from your while loop, because as it stands at the moment you are printing a new list for every file. In fact, you don't even need the while loop. You could simply do something like the following (untested)...

    my $data_dir = '/foo'; opendir(DIR, $data_dir) or die "Cannot opendir $data_dir:$!"; my @files = grep { /data$/ && -f "$data_dir/$_" } readdir DIR; closedir DIR; print scrolling_list('name', \@files);

    Cheers,
    Darren :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://589495]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found