Click here to get back home

better design of spreadsheet generation

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
better design of spreadsheet generation Ela 03-20-2008
Posted by Ela on March 20, 2008, 7:58 am
Please log in for more thread options
A spreadsheet of *n* fields is to be generated. For debugging purpose,
confidentiality and so on reasons, sometimes some of the fields are not to
be generated.

Using a series of "if" or "?" can solve the problem, but it makes the codes
very clumsy and not generic. Is perl capable of handling this situation?

e.g.

print a header by:

field1 f2 f3 .... fn-1 fn
r11 r12 r13 ... r1n-1 r1n
...

or

field1 f3 .... fn-1
r11 r13 ... r1n-1
...




Posted by Ben Morrow on March 20, 2008, 11:37 am
Please log in for more thread options

> A spreadsheet of *n* fields is to be generated. For debugging purpose,
> confidentiality and so on reasons, sometimes some of the fields are not to
> be generated.
>
> Using a series of "if" or "?" can solve the problem, but it makes the codes
> very clumsy and not generic. Is perl capable of handling this situation?
>
> e.g.
>
> print a header by:
>
> field1 f2 f3 .... fn-1 fn
> r11 r12 r13 ... r1n-1 r1n
> ...
>
> or
>
> field1 f3 .... fn-1
> r11 r13 ... r1n-1
> ...

While it's not the least bit clear what you want (an actual example
would be helpful), is something like this useful?

my %skipped;
$skipped = 1 for 2, 4, 6;

for my $r (qw/field r/) {
for my $i (1..10) {
$skipped and next;
printf '%8s ', "$r$i";
}
print "\n";
}

Posted by Ela on March 20, 2008, 6:58 pm
Please log in for more thread options

> my %skipped;
> $skipped = 1 for 2, 4, 6;
>
> for my $r (qw/field r/) {
> for my $i (1..10) {
> $skipped and next;
> printf '%8s ', "$r$i";
> }
> print "\n";
> }

Oh! It seems you and ccc31807 are providing the exact solution! In my case
then I would place something like name, age, ... in the qw. But I guess I'll
modify your for my $i ... into a several "if" in order to differentiate the
categories to display, e.g. personal info, diagnosis results, ...

Nevertheless, I also thank Jim's suggestion on using OO.



Similar ThreadsPosted
Array generation January 14, 2005, 5:23 pm
String generation September 21, 2005, 12:02 am
CGI.pm Button Generation February 6, 2007, 8:21 pm
[OT] ISO book on CGI design January 11, 2005, 11:32 pm
Perl web design February 27, 2005, 5:25 am
tutorial on dynamic SID generation May 30, 2006, 10:17 pm
Data Pattern generation November 7, 2006, 4:52 pm
Automatic document generation November 14, 2007, 9:41 pm
CGI scripts and modular design? September 28, 2004, 9:41 am
Opinions on the Design of Perl December 13, 2004, 1:19 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap