Perl

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • format to scalar better solution?

    1 answers - 669 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello all,
    I like format function, but I miss output to scalars.
    write always print to STDUT, or filehandle, but I need access
    contents to scalar. I found in docs one solution, but it is not much
    nice:
    use Carp;
    sub swrite {
    croak "usage: swrite PICTURE ARGS" unless @_;
    my $format = shift;
    $^A = "";
    formline($format,@_);
    return $^A;
    }
    $string = swrite(<<'END', 1, 2, 3);
    Check me out
    @<<< @||| @
    END
    print $string;
    but when I have in formating template lets say 40 variables
    I'm just curious, if there are some other possibilities.
    Thanks
    /brano
  • No.1 | | 181 bytes | |

    Brano Gerzo:
    I like format function, but I miss output to scalars.
    I think you mean 'to text strings' and are looking for sprintf.
    perldoc -f sprintf

Re: format to scalar better solution?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "Perl"

EMSDN.COM