top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Suggestion for print format string based on configuration in perl?

+1 vote
192 views

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;

where $condition is the condition used to select a sprintf format string out of an array (@formats) that contains something like:

my @formats = (
 qw( %09d %-1s %03d ... )
, qw(%-4s %1s %09d %1s %-150s %-4s %011d)
, ...
);

Now, while this approach is working really fine, it is a little hard to decode, especially considering that I've got some formats with 50+ fields. I don't believe that using Perl formats is a solution, it will provide a quite longer configuration (consider I've got even fields specified as "-100%s"!).

Any suggestion to get a more readable code?

posted Jan 3, 2017 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes

I routinely generate rows of tab-separated data like this;

my @array = ( "boris", "natasha", "rocky", "bullwinkle"); print join "t", @array, "n";

However this code inserts an extra tab between bullwinkle and the newline character. So when it is important I do this instead:print join "t", @array;print "n";
I suppose you could put both statements on a single line. Is there a simpler/faster way to generate this output: boristnatashatrockytbullwinklen?

+1 vote

I am running a script under perl -d and want to break execution at line 243 in this case. perl -d scriptname loads the script in to the debugger and b 243 sets the break point. c then Enter starts the program which runs until it reaches the desired line at which point it stops. All I want to do is get it to loop multiple times through this point and then stop.

This is similar to the behavior of gdb where you could tell it to stop after, say, 250 passes through the break point.

+1 vote

I have a Linux machine and windows machine, I need to run a GUI of Linux machine on the windows machine.
I don't want to use putty or any other software. I have to use any Perl modules to achieve this please help.

+1 vote

I need to access ClearQuest programatically using Perl. I just found ClearQuest OSLC REST API. Client is planning to use ClearQuest web 7.1.1. I read that it comes with OSLC REST API out the box.
Can someone please provide me some examples on how I can access the CQ through Perl using this API.

...