Re: suggestion for print format string based on configuration

2017-01-03 Thread Luca Ferrari
On Wed, Jan 4, 2017 at 12:22 AM, Chris Fedde wrote: > my ($condition, @fields) = parse_data($source_item); > print sprintf $formats[ $condition ], @fields; > > Or something. Well, I've simplified the example and effectively, in my code, the formats is an hash instrumented by the condition

Re: suggestion for print format string based on configuration

2017-01-03 Thread Luca Ferrari
On Tue, Jan 3, 2017 at 5:58 PM, Shlomi Fish wrote: > Perhaps try looking at this page about generating text in Perl - > http://perl-begin.org/uses/text-generation/ (note that Perl-Begin is a site > which I maintain). This page on my personal website, which is not > Perl-specific, but which may hav

Re: suggestion for print format string based on configuration

2017-01-03 Thread Chris Fedde
Luca, I think you have a reasonable solution to the problem as you present it. Adding a couple strategic comments might help the clarity. A concern for me is how the $condition variable gets set. If the source data dictates the $condition then deriving them both in the same parser might help:

Re: suggestion for print format string based on configuration

2017-01-03 Thread Shlomi Fish
Hi Luca, On Tue, 3 Jan 2017 10:35:46 +0100 Luca Ferrari wrote: > Hi all, > I've a program that needs to print some fields formatted in different > ways according to some conditions. > The solution I come up is working, but I'm looking for a suggestion > for something more elegant. > What I do is

suggestion for print format string based on configuration

2017-01-03 Thread Luca Ferrari
Hi all, I've a program that needs to print some fields formatted in different ways according to some conditions. The solution I come up is working, but I'm looking for a suggestion for something more elegant. What I do is something like the following: print sprintf $formats[ $condition ], @fields;