|
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";
}
|