Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I'm all for computer dating, but I wouldn't want one to marry my sister.


devel / comp.lang.perl.misc / printf with trailing dots ?

SubjectAuthor
* printf with trailing dots ?hymie!
+- Re: printf with trailing dots ?Grant Taylor
+* Re: printf with trailing dots ?HASM
|`* Re: printf with trailing dots ?Grant Taylor
| `* Re: printf with trailing dots ?hymie!
|  +- Re: printf with trailing dots ?Grant Taylor
|  `* Re: printf with trailing dots ?HASM
|   `- Re: printf with trailing dots ?Ben Bacarisse
+- Re: printf with trailing dots ?Keith Thompson
`* Re: printf with trailing dots ?Rainer Weikusat
 `- Re: printf with trailing dots ?Rainer Weikusat

1
printf with trailing dots ?

<slrnuls0ir.nep.hymie@nasalinux.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9993&group=comp.lang.perl.misc#9993

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.swapon.de!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.iad.POSTED!not-for-mail
Newsgroups: comp.lang.perl.misc
From: hym...@nasalinux.net (hymie!)
Subject: printf with trailing dots ?
Organization: Eric Conspiracy Secret Labs
User-Agent: slrn/pre1.0.4-6 (Linux)
Message-ID: <slrnuls0ir.nep.hymie@nasalinux.net>
Lines: 30
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Wed, 22 Nov 2023 13:30:03 UTC
Date: Wed, 22 Nov 2023 13:30:03 GMT
X-Received-Bytes: 1451
 by: hymie! - Wed, 22 Nov 2023 13:30 UTC

Greetings. I'm sure this is probably an FAQ, but I can't find it.

I have a script that basically does this:

printf "%-38s%s\n",left_column_info,right_column_info;

The problem is that when the left_column_info is too short, there's a big
gap.

I'd like to use what I think are called "leaders" ... where the output
would something like this: (monospace text ahead)

left_column_info . . . . . . . . . right_column_info
long_left_column_info . . . . . . right_column_info

Is there an easy way to do this, where there is
* at least one space after left_column_info
* the dots are aligned in columns
?

The only thing I can think of is
* get the length(left_column_info)
* add 1 space if the number is (let's say) even
* add " ." until the length is (in this case) 37

But I wonder if printf will do it for me.

Thanks.

--hymie! http://nasalinux.net/~hymie hymie@nasalinux.net

Re: printf with trailing dots ?

<ujl3dk$330$2@tncsrv09.home.tnetconsulting.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9994&group=comp.lang.perl.misc#9994

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.198.18.1.140!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Wed, 22 Nov 2023 08:32:20 -0600
Organization: TNet Consulting
Message-ID: <ujl3dk$330$2@tncsrv09.home.tnetconsulting.net>
References: <slrnuls0ir.nep.hymie@nasalinux.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Nov 2023 14:32:20 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="198.18.1.140";
logging-data="3168"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <slrnuls0ir.nep.hymie@nasalinux.net>
 by: Grant Taylor - Wed, 22 Nov 2023 14:32 UTC

On 11/22/23 07:30, hymie! wrote:
> But I wonder if printf will do it for me.

It's been too long since I've done anything like this so I don't know.

I do think that printf had an option where you could specify the
character that was used to pad with. I don't know if that had to be a
singular character or if it could e a multi-character pattern. --
though I don't know what the alignment would be like.

One trick I would wonder about if you were printing to a terminal would
be to print the entire line with the dot pattern space and then over
print it with the left_column and a space. But that might not work for
your application.

Grant. . . .

Re: printf with trailing dots ?

<87cyw1olsx.fsf@127.0.0.1>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9995&group=comp.lang.perl.misc#9995

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!nntp.comgw.net!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: has...@example.invalid (HASM)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Wed, 22 Nov 2023 07:22:06 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <87cyw1olsx.fsf@127.0.0.1>
References: <slrnuls0ir.nep.hymie@nasalinux.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="d730866e03ff832bbefb1f8ad83593e5";
logging-data="1461925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HVnLa0yIn+iOQV7bSDYHhK3DbtgRvJ5Y="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:bxhIOG7MA3n72uhUmIXZOR3p4mc=
sha1:ugBErnhVmrPDq8Mtj+BRUWNQc1s=
 by: HASM - Wed, 22 Nov 2023 15:22 UTC

hymie! <hymie@nasalinux.net> writes:

> I'd like to use what I think are called "leaders" ... where the output
> would something like this: (monospace text ahead)

> left_column_info . . . . . . . . . right_column_info
> long_left_column_info . . . . . . right_column_info

The code below ought to do it.
Maybe add some error checking for the proper arguments to print subroutine.

-- HASM

#! /usr/bin/perl

use Modern::Perl;
use List::Util qw(max);

sub dot_printf {
my $width = shift;
my $left_string = shift;
my $right_string = shift;

my $len_left = length($left_string);
my $len_dots = max(0, $width-$len_left);
printf ("%-*s %s %s\n", $len_left, $left_string, '.'x$len_dots, $right_string);
}

my $widht = 38;
dot_printf $widht, 'left string', 'right_string';
dot_printf $widht, 'larger string', 'right_string';

Re: printf with trailing dots ?

<ujlavv$hu6$1@tncsrv09.home.tnetconsulting.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9996&group=comp.lang.perl.misc#9996

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.198.18.1.140!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Wed, 22 Nov 2023 10:41:35 -0600
Organization: TNet Consulting
Message-ID: <ujlavv$hu6$1@tncsrv09.home.tnetconsulting.net>
References: <slrnuls0ir.nep.hymie@nasalinux.net> <87cyw1olsx.fsf@127.0.0.1>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Nov 2023 16:41:35 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="198.18.1.140";
logging-data="18374"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <87cyw1olsx.fsf@127.0.0.1>
 by: Grant Taylor - Wed, 22 Nov 2023 16:41 UTC

On 11/22/23 09:22, HASM wrote:
> printf ("%-*s %s %s\n", $len_left, $left_string, '.'x$len_dots, $right_string);

Wouldn't that end up with:

left_column_info...................right_column_info
long_left_column_info..............right_column_info

Or am I misunderstanding the '.'x$len_dots part?

Though I do wonder if you might be able to tweak that to be something
akin to:

'. 'x$len_dots/2

Type thing.

Grant. . . .

Re: printf with trailing dots ?

<87wmu9d96p.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9997&group=comp.lang.perl.misc#9997

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.samoylyk.net!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Wed, 22 Nov 2023 08:50:06 -0800
Organization: None to speak of
Lines: 41
Message-ID: <87wmu9d96p.fsf@nosuchdomain.example.com>
References: <slrnuls0ir.nep.hymie@nasalinux.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="923e91cce60caefb746fc5a8835e9251";
logging-data="1488271"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kOi4wFi2MzDCKXrf6076b"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:vFxoPW134DcIO4tC8uMAKbpjD34=
sha1:M8zXS30WAXoxRK/wzZTXccOJMhk=
 by: Keith Thompson - Wed, 22 Nov 2023 16:50 UTC

hymie! <hymie@nasalinux.net> writes:
> Greetings. I'm sure this is probably an FAQ, but I can't find it.
>
> I have a script that basically does this:
>
> printf "%-38s%s\n",left_column_info,right_column_info;
>
> The problem is that when the left_column_info is too short, there's a big
> gap.
>
> I'd like to use what I think are called "leaders" ... where the output
> would something like this: (monospace text ahead)
>
> left_column_info . . . . . . . . . right_column_info
> long_left_column_info . . . . . . right_column_info
>
> Is there an easy way to do this, where there is
> * at least one space after left_column_info
> * the dots are aligned in columns
> ?
>
> The only thing I can think of is
> * get the length(left_column_info)
> * add 1 space if the number is (let's say) even
> * add " ." until the length is (in this case) 37
>
> But I wonder if printf will do it for me.

I don't think printf will do this directly. You can certainly do it
with string manipulation, but I think that `format` might be the best
solution. `perldoc perlform` for details. (Disclaimer: I haven't
thought about Perl's format feature in years, so I'm not at all sure
that it's suitable.)

Other than that, initializing a string with ". . . . . ."... and then
overwriting parts of it may be the best solution.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: printf with trailing dots ?

<slrnulsfag.otu.hymie@nasalinux.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9998&group=comp.lang.perl.misc#9998

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
Newsgroups: comp.lang.perl.misc
From: hym...@nasalinux.net (hymie!)
Subject: Re: printf with trailing dots ?
References: <slrnuls0ir.nep.hymie@nasalinux.net> <87cyw1olsx.fsf@127.0.0.1>
<ujlavv$hu6$1@tncsrv09.home.tnetconsulting.net>
Organization: Eric Conspiracy Secret Labs
User-Agent: slrn/pre1.0.4-6 (Linux)
Message-ID: <slrnulsfag.otu.hymie@nasalinux.net>
Lines: 37
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Wed, 22 Nov 2023 17:41:36 UTC
Date: Wed, 22 Nov 2023 17:41:36 GMT
X-Received-Bytes: 1702
 by: hymie! - Wed, 22 Nov 2023 17:41 UTC

In our last episode, the evil Dr. Lacto had captured our hero,
Grant Taylor <gtaylor@tnetconsulting.net>, who said:
> On 11/22/23 09:22, HASM wrote:
>> Awesome program that I'm now playing with.
>> printf ("%-*s %s %s\n", $len_left, $left_string, '.'x$len_dots, $right_string);
>
> Wouldn't that end up with:
>
> left_column_info...................right_column_info
> long_left_column_info..............right_column_info

Yes it does.

> Though I do wonder if you might be able to tweak that to be something
> akin to:

I've got this:

use List::Util qw(max);

sub dot_printf {
my $width = shift;
my $left_string = shift;
my $right_string = shift;

my $len_left = length($left_string);
$len_left++ if ($len_left % 2);
my $len_dots = max(0, $width-$len_left);
printf ("%-*s %s%s\n", $len_left, $left_string, '. 'x ($len_dots/2),
$right_string);
}

And I think it does exactly what I want.

Thank you very much HASM

--hymie! http://nasalinux.net/~hymie hymie@nasalinux.net

Re: printf with trailing dots ?

<ujlk47$9qa$1@tncsrv09.home.tnetconsulting.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9999&group=comp.lang.perl.misc#9999

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!tncsrv06.tnetconsulting.net!tncsrv09.home.tnetconsulting.net!.POSTED.198.18.1.140!not-for-mail
From: gtay...@tnetconsulting.net (Grant Taylor)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Wed, 22 Nov 2023 13:17:27 -0600
Organization: TNet Consulting
Message-ID: <ujlk47$9qa$1@tncsrv09.home.tnetconsulting.net>
References: <slrnuls0ir.nep.hymie@nasalinux.net> <87cyw1olsx.fsf@127.0.0.1>
<ujlavv$hu6$1@tncsrv09.home.tnetconsulting.net>
<slrnulsfag.otu.hymie@nasalinux.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 22 Nov 2023 19:17:27 -0000 (UTC)
Injection-Info: tncsrv09.home.tnetconsulting.net; posting-host="198.18.1.140";
logging-data="10058"; mail-complaints-to="newsmaster@tnetconsulting.net"
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <slrnulsfag.otu.hymie@nasalinux.net>
 by: Grant Taylor - Wed, 22 Nov 2023 19:17 UTC

On 11/22/23 11:41, hymie! wrote:
> And I think it does exactly what I want.

Cool.

My concern would be ending up with lines of output not having dots line
up, depending on the length of the left column. Even vs odd length type
thing.

If that does happen, you could probably add a space for the remainder
(modulus) of the length of the left column divided by two.

Grant. . . .

Re: printf with trailing dots ?

<878r6oo4xv.fsf@127.0.0.1>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10000&group=comp.lang.perl.misc#10000

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: has...@example.invalid (HASM)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 07:38:36 -0800
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <878r6oo4xv.fsf@127.0.0.1>
References: <slrnuls0ir.nep.hymie@nasalinux.net> <87cyw1olsx.fsf@127.0.0.1>
<ujlavv$hu6$1@tncsrv09.home.tnetconsulting.net>
<slrnulsfag.otu.hymie@nasalinux.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="08523a6b570dda421cc382e33b1544da";
logging-data="1994243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hmj+19I+v5ZkO2IZ6y9Qc3WKTXEap2OU="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:QJTPQEShBQNkzhwtzlL83OYvAMo=
sha1:HtGiq26C2TegdO35dOd1l8H+AmM=
 by: HASM - Thu, 23 Nov 2023 15:38 UTC

>>> printf ("%-*s %s %s\n", $len_left, $left_string, '.'x$len_dots,
>>> $right_string);
>> Wouldn't that end up with:
>> left_column_info...................right_column_info
>> long_left_column_info..............right_column_info

Not quite, I misread the initial requirement, but did bracket the dot
sequence with spaces, i,e., one would get

left column info ...................... right_column_info
long_left column info ................. right_column_info

> Thank you very much HASM

You're welcome.

I think I've only used printf's * field width once (and also $
positional ordering) more than 20 years ago on a C program, but your
post triggered my memory and I was almost certain Perl would have it.

-- HASM

Re: printf with trailing dots ?

<87msv4gtrl.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10001&group=comp.lang.perl.misc#10001

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 19:21:50 +0000
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <87msv4gtrl.fsf@bsb.me.uk>
References: <slrnuls0ir.nep.hymie@nasalinux.net> <87cyw1olsx.fsf@127.0.0.1>
<ujlavv$hu6$1@tncsrv09.home.tnetconsulting.net>
<slrnulsfag.otu.hymie@nasalinux.net> <878r6oo4xv.fsf@127.0.0.1>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="a3bbe519c861d2d3f0f848d13d8516a3";
logging-data="2060719"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/toaZbyWUBZ57D9siuA5bFix7zRolBObY="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:INF3lv7O6KEUgIpMRYotkbuLAlw=
sha1:SHeAxzCc6hIPRqUgD8SKnGA/ZNk=
X-BSB-Auth: 1.3f6d7c5d2253abc5ff68.20231123192150GMT.87msv4gtrl.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 23 Nov 2023 19:21 UTC

HASM <hasm@example.invalid> writes:

>>>> printf ("%-*s %s %s\n", $len_left, $left_string, '.'x$len_dots,
>>>> $right_string);
>>> Wouldn't that end up with:
>>> left_column_info...................right_column_info
>>> long_left_column_info..............right_column_info
>
> Not quite, I misread the initial requirement, but did bracket the dot
> sequence with spaces, i,e., one would get
>
> left column info ...................... right_column_info
> long_left column info ................. right_column_info
>
>> Thank you very much HASM
>
> You're welcome.
>
> I think I've only used printf's * field width once (and also $
> positional ordering) more than 20 years ago on a C program, but your
> post triggered my memory and I was almost certain Perl would have it.

But why? printf("%-*s", length($s), $s) is just printf("%s", $s).

--
Ben.

Re: printf with trailing dots ?

<87v89sl0uc.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10002&group=comp.lang.perl.misc#10002

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 19:35:23 +0000
Lines: 42
Message-ID: <87v89sl0uc.fsf@doppelsaurus.mobileactivedefense.com>
References: <slrnuls0ir.nep.hymie@nasalinux.net>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net BlaMCYDK9EYRuFyPEgmqmwS2OojjU455OZuVpbW0eJYVDYWSs=
Cancel-Lock: sha1:zX9m3rdd5zjvy2/PvSTcy1WEW6c= sha1:Y2I/M27LExUyOSuuPwoNk0CDjoM= sha256:CXIVIsxslk7qlkQ+55/v7sxCUKf9zZ+/PdVlKfhhvnM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Thu, 23 Nov 2023 19:35 UTC

hymie! <hymie@nasalinux.net> writes:
> Greetings. I'm sure this is probably an FAQ, but I can't find it.
>
> I have a script that basically does this:
>
> printf "%-38s%s\n",left_column_info,right_column_info;
>
> The problem is that when the left_column_info is too short, there's a big
> gap.
>
> I'd like to use what I think are called "leaders" ... where the output
> would something like this: (monospace text ahead)
>
> left_column_info . . . . . . . . . right_column_info
> long_left_column_info . . . . . . right_column_info

[...]

> The only thing I can think of is
> * get the length(left_column_info)
> * add 1 space if the number is (let's say) even
> * add " ." until the length is (in this case) 37
>
> But I wonder if printf will do it for me.

Why not just translate your algorithm into Perl?

-----
sub dot_print {
my ($w, $l, $r) = @_;

$l .= ' ' unless length($l) & 1;
$l .= ' .' while length($l) < $w;
print($l, ' ', $r, "\n");
}

dot_print(38, 'left_column_info', 'right_column_info');
dot_print(38, 'long_left_column_info', 'right_column_info');
-----

IMHO, doing anything more fancy just makes the code needlessly
complicated.

Re: printf with trailing dots ?

<87r0kgkuh2.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10003&group=comp.lang.perl.misc#10003

  copy link   Newsgroups: comp.lang.perl.misc
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.lang.perl.misc
Subject: Re: printf with trailing dots ?
Date: Thu, 23 Nov 2023 21:52:57 +0000
Lines: 37
Message-ID: <87r0kgkuh2.fsf@doppelsaurus.mobileactivedefense.com>
References: <slrnuls0ir.nep.hymie@nasalinux.net>
<87v89sl0uc.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net qARg4AjBSDMrGy32eK/rUwOgy9ubNrSqiMVhn0rcrMvDYJKlw=
Cancel-Lock: sha1:N6O/RHEdAc0li3TzQx6EuO0x1ek= sha1:0McqJbbXsbGzgw4U7BnW2Ygzv1g= sha256:6Jk0x+1H+rDfVSIAS3oUvKqIYAkW3dnDJpp0rzGA9LQ=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Thu, 23 Nov 2023 21:52 UTC

Rainer Weikusat <rweikusat@talktalk.net> writes:
> hymie! <hymie@nasalinux.net> writes:

[...]

>> The only thing I can think of is
>> * get the length(left_column_info)
>> * add 1 space if the number is (let's say) even
>> * add " ." until the length is (in this case) 37
>>
>> But I wonder if printf will do it for me.
>
> Why not just translate your algorithm into Perl?
>
> -----
> sub dot_print {
> my ($w, $l, $r) = @_;
>
> $l .= ' ' unless length($l) & 1;
> $l .= ' .' while length($l) < $w;
> print($l, ' ', $r, "\n");
> }
>
> dot_print(38, 'left_column_info', 'right_column_info');
> dot_print(38, 'long_left_column_info', 'right_column_info');
> -----

Slight correction: The lines produced by the code above are too long.

----
sub dot_print {
my ($w, $l, $r) = @_;

$l .= ' ' unless length($l) & 1;
$l .= ' .' while $w - length($l) > 1;
print($l, ' ', $r, "\n");
}

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor