tabs between fields

Discussion in 'Perl Misc' started by beartiger@gmail.com, Oct 8, 2005.

  1. Guest

    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;
     
    , Oct 8, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > I would like a tab between the values of $foo and $bar in the output.


    Then why are you using the format? Why not just "$foo\t$bar"
     
    , Oct 8, 2005
    #2
    1. Advertising

  3. Guest

    wrote:
    > wrote:
    > > I would like a tab between the values of $foo and $bar in the output.

    >
    > Then why are you using the format? Why not just "$foo\t$bar"


    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.

    Thanks. ;-)


    J
     
    , Oct 8, 2005
    #3
  4. Guest

    wrote:
    > 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.
     
    , Oct 8, 2005
    #4
  5. Guest

    wrote:
    > wrote:
    > > 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.


    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
     
    , Oct 8, 2005
    #5
  6. Guest

    wrote:
    > wrote:
    > > 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;


    This looks redundant, and print is repeated too.

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

    >
    > I've never liked formats. They seem very old-fashioned to me.
     
    , Oct 8, 2005
    #6
  7. Guest

    wrote:
    > 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).
     
    , Oct 8, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TomTom
    Replies:
    1
    Views:
    395
    PeterOo
    Aug 26, 2003
  2. qwweeeit
    Replies:
    2
    Views:
    649
    qwweeeit
    Dec 14, 2005
  3. rantingrick

    Tabs -vs- Spaces: Tabs should have won.

    rantingrick, Jul 16, 2011, in forum: Python
    Replies:
    95
    Views:
    1,836
    Roy Smith
    Jul 19, 2011
  4. John Kopanas
    Replies:
    2
    Views:
    293
    Gregory Brown
    Jan 29, 2007
  5. Marek
    Replies:
    10
    Views:
    229
    Tim Greer
    Sep 19, 2008
Loading...

Share This Page