fireartist has asked for the wisdom of the Perl Monks concerning the following question:
Following is a very stripped down copy of the code from the script, the module it calls, and the conf files which the module calls.if ($var{tablename}) { for (@range_columns) { my $value = shift @db_row; my $column_num = $dbs->column_num(@table_num, $_); $value = $dbs->format_column_range(@table_num, $column_num, $value +); $value =~ s/ / /g; push @product_cells, $value; } }
__________ script.cgi __________ #!/usr/bin/perl -wT use strict; use lib '/home/www.domain.net/lib'; use DBStruct; use vars qw/ $dbs %param %var @range_columns @table_num /; $dbs = new DBStruct; $var{tablename} = 'monitors'; @range_columns = qw/ size visible_size recommended_resolution dot_pitch /; @table_num = qw/ 04 01 01 /; while (my @db_row = $sth->fetchrow_array) { my @product_cells; if ($var{tablename}) { for (@range_columns) { my $value = shift @db_row; my $column_num = $dbs->column_num(@table_num, $_); $value = $dbs->format_column_range(@table_num, $column_num, $val +ue); $value =~ s/ / /g; push @product_cells, $value; } } } ___________ DBStruct.pm ___________ package DBStruct; use strict; use Exporter; use vars qw / $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS /; use vars qw / $dbstruct $dbtables /; $VERSION = 1.00; @ISA = qw/ Exporter /; @EXPORT_OK = qw / new column_num /; BEGIN { unless ($dbtables = do('/home/www.domain.net/conf/DBTables.pl')) { die("Could not 'do' /home/www.domain.net/conf/DBTables.pl"); } } sub new { my $self = {}; bless($self); return $self } =head4 column_num() This requires a list of dep numbers (1, 2, or 3) and a column name, and returns the column number. $column = $dbs->column_num($dep_1, $dep_2, $dep_3, $name); or $column = $dbs->column_num(@deps, $name); =cut sub column_num { my $self; if (ref $_[0]) { $self = shift; } my $name = pop; my @dep = @_; my ($dep_1, $dep_2, $dep_3); $dep_1 = shift @dep; if ($dep_2 = shift @dep) { if ($dep_3 = shift @dep) { ### there's 3 dep for ( keys %{$dbtables->{$dep_1}->{dep_2}->{$dep_2}->{dep_3}->{$ +dep_3}->{columns}} ) { if ( $name eq $dbtables->{$dep_1}->{dep_2}->{$dep_2}->{dep_3}- +>{$dep_3}->{columns}->{$_}->{name} ) { return $_ } } return undef } else { ### there's only 2 dep for ( keys %{$dbtables->{$dep_1}->{dep_2}->{$dep_2}->{columns}} +) { if ( $name eq $dbtables->{$dep_1}->{dep_2}->{$dep_2}->{columns +}->{$_}->{name} ) { return $_ } } return undef } } else { ### there's only 1 dep for ( keys %{$dbtables->{$dep_1}->{columns}} ) { if ( $name eq $dbtables->{$dep_1}->{columns}->{$_}->{name} ) { return $_ } } return undef } } =back =cut 1; ___________ DBTables.pl ___________ { '04' => { dep_2 => { '01' => { table => 'monitors', columns => { '01' => { name => 'pr +od_code', }, '02' => { name => 'si +ze', }, '03' => { name => 'vi +sible_size',, }, '04' => { name => 're +commended_resolution', }, '05' => { name => 'do +t_pitch', }, }, }, }, }, },
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 'for' array being altered - scope
by Sidhekin (Priest) on Sep 26, 2002 at 10:36 UTC | |
by diotalevi (Canon) on Sep 26, 2002 at 12:18 UTC | |
by Sidhekin (Priest) on Sep 26, 2002 at 12:38 UTC | |
by diotalevi (Canon) on Sep 26, 2002 at 12:49 UTC |