tabs between fields

B

beartiger

How do I insert a tab between fields in a format?

use strict;
use warnings;

my $foo=123;
my $bar=456;

format TABLE=
@### @###
$foo, $bar;
 
U

usenet

Because I'm a fricking idiot. It's one format in a long list of
formats and I never thought I could just get rid of the format.

Maybe you wanted to preserve the space padding characteristics of the
format statement. You could do that instead with sprintf:
print sprintf "%3s\t%3s\n", $foo, $bar;

I've never liked formats. They seem very old-fashioned to me.
 
B

beartiger

Maybe you wanted to preserve the space padding characteristics of the
format statement. You could do that instead with sprintf:
print sprintf "%3s\t%3s\n", $foo, $bar;

I've never liked formats. They seem very old-fashioned to me.

Thanks. This is the first time I've tried formatting. I don't know
about old fashioned, but I find the way a format is done kind of
clunky.

I've never done sprintf either. That will come in handy.


J
 
M

michaelpgee

Maybe you wanted to preserve the space padding characteristics of the
format statement. You could do that instead with sprintf:
print sprintf "%3s\t%3s\n", $foo, $bar;

This looks redundant, and print is repeated too.

Why not just: printf "%3s\t%3s\n", $foo, $bar;
 
U

usenet

This looks redundant, and print is repeated too.

True, but since the OP (properly) posted trivial code, I wasn't sure if
he actually intended to assign or print in his "real" application. So I
covered both bases (at the expense of redundancy).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top