Doh! Mistake in my grep line.... Corrected line is:
# BTW> opendir(SMD, $startloc) || die....
# BTW> $val = join(",", grep {$_ !~ m/^\.{1,2}$/} readdir(SMD))
# BTW> closedir(SMD);
Brian
[EMAIL PROTECTED] on 01/14/2002 09:53:13 AM
To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED]
bcc:
Subject: Re: [cgiapp] Need help with CGI::Application
Might I make a couple of suggestions on your style and effeciency?
Obviously "there is more than one way to do it", but you have reimplemented
the grep and join commands in a way that may not give consistant results.
See embedded comments (# BTW>). I would also heavily recommend that you
read the Camel book from O'Reilly.
Brian
[EMAIL PROTECTED] on 01/14/2002 08:17:58 AM
To: [EMAIL PROTECTED]
cc:
bcc:
Subject: [cgiapp] Need help with CGI::Application
I have a cgi script as below
-------------------------------------------------------------------------
#!/usr/bin/perl -w
push(@INC,'c:\program files/apache group/apache/cgi-bin');
# BTW> If your perl is recent enough, you can "use lib 'c:\program....'"
use testapi;
my $webapp = testapi->new();
$webapp->run();
--------------------------------------------------------------------------
The testapi.pm is as below:
--------------------------------------------------------------------------
package testapi;
use base 'CGI::Application';
use strict;
sub setup {
my $self = shift;
$self->start_mode('mode1');
$self->run_modes(
'mode1' => 'showapps',
'mode2' => 'showyear',
'mode3' => 'showdates',
'mode4' => 'showdetails'
);
}
sub teardown {
my $self = shift;
}
sub showapps {
my $self = shift;
# Get CGI query object
my $q = $self->query();
my $val = "";
my $startloc="e:/it support services/db
architecture/sybase/sysmon-webdb";
# BTW> Start of section I am commenting on...
opendir(SMD,"$startloc") || die "Failed to open Sysmon DB";
# BTW> There is no need to quote a variable. In fact, this
stringifys (term
# BTW> from the perl community, not mine :) the variable needlessly,
possibly
# BTW> burning cycles.
my $c=0;
my @apps;
while (my $dir = readdir(SMD))
{
$apps[$c] = $dir;
$c++;
}
closedir(SMD);
for (my $i = 2; $i < $c; $i++ ) {
$val .= $apps[$i];
if($i < $c-1)
{
$val .= ",";
}
}
# BTW> End of section I am commenting on...
# BTW> I am assuming that this block of code is loading $val with a
comma
# BTW> seperated list of all files in the $startloc directory except
for
# BTW> "." and "..". That can be accomplished more quickly (and
more Perlish)
# BTW> with the following snippet of code...
# BTW> opendir(SMD, $startloc) || die....
# BTW> $val = join(",", grep {m/^\.{1,2}/} readdir(SMD))
# BTW> closedir(SMD);
# BTW> This will open the directory,
# BTW> read the directory, remove "." and "..", join them with ",",
and store
# BTW> the result in $val. Much shorter and easier to maintain. It
also does
# BTW> not assume that "." and ".." are in the first two directory
slots.
my $output = '';
$output .= $q->start_html(-title => 'Sysmon Database');
$output .= $q->start_form();
# BTW> Read Chapter 2 from the Camel book, and in the section on
Scalar Variables
# BTW> there is a subsection about the various quotes (search for
"Interpolate").
# BTW> That should explain your problem with the next line.
$output .= $q->scrolling_list(-name=> '@apps', -values=>'$val');
$output .= $q->hidden(-name => 'rm', -value => 'mode2');
$output .= $q->submit();
$output .= $q->end_form();
$output .= $q->end_html();
return $output;
}
sub showlist {
my $self = shift;
# Get CGI query object
my $q = $self->query();
my $testcode = $q->param("testcode");
my $output = '';
$output .= $q->start_html(-title => 'List of Matching tests');
$output .= $q->end_html();
return $output;
}
sub showdetail {
my $self = shift;
# Get CGI query object
my $q = $self->query();
my $testid = $q->param("testid");
my $output = '';
$output .= $q->start_html(-title => 'test Detail');
$output .= $q->end_html();
return $output;
}
1;
-----------------------------------------------------------------------
When the script is executed it sends the actual variables in the HTML as
opposed to the values in the variable as in the output below. How do I get
the alctual values from the variables passed in the HTML??
** <select name="@apps" size="1">
** <option value="$val">$val</option>
** <input type="hidden" name=".cgifields" value="@apps" />
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]