0

I'm using the null character (\0) as a separator to keep the strings leading white-spaces after the sprintf. But the strings with the null character don't work (in this case) with the Curses addstr function.
Is there some suitable character to replace the \0 for this purpose?

#!/usr/bin/env perl
use warnings;
use 5.12.0;


sub routine {
    my @list = @_;
    @list = map{ "\0".$_."\0"; } @list;
    # ...
    # ...
    @list = map{ sprintf "%35.35s", $_ } @list;
    # ...
    # ...
    my $result = $list[5];

    $result =~ s/\A\s+\0//;
    $result =~ s/\0\s+\z//;
    return $result;
}
sid_com
  • 24,137
  • 26
  • 96
  • 187
  • 4
    What exactly are you doing that is stripping whitespace? `sprintf`? – TLP Mar 20 '12 at 15:26
  • I think you should be using [substr](http://perldoc.perl.org/functions/substr.html) instead of `sprintf`. – cjm Mar 20 '12 at 15:44
  • 1
    This is an [XY Problem](http://www.perlmonks.org/?node=XY%20Problem). What is `routine` actually trying to do? – ikegami Mar 20 '12 at 20:11
  • There was an error in the example. I map the list through `sprintf`, so all items have the same length (longest item). (to get a nice output). But now I am considering to use `printf` at the end when printing to the screen, so I don't need a separation character. I didn't do that until now, because I thought `printf` would be slower than `print` but maybe there is no big difference. – sid_com Mar 20 '12 at 22:11

1 Answers1

0

What about using some pretty print module from CPAN?

http://metacpan.org/pod/Data::Format::Pretty::Console

http://metacpan.org/pod/Text::Tabulate

szabgab
  • 6,202
  • 11
  • 50
  • 64
user1126070
  • 5,059
  • 1
  • 16
  • 15
  • I need to move around on the screen (similar to the `choose` function from [Term::Clui](http://search.cpan.org/perldoc?Term::Clui)). – sid_com Mar 24 '12 at 17:20