in reply to scalar number with preceding 0.

PerlingTheUK,
Nothing in your code indicates why a string '0' would show up as unprintable/space. You however have way over complicated things:
#!/usr/bin/perl use strict; use warnings; while ( <DATA> ) { chomp; print format_time( split " " , $_ ), "\n"; } sub format_time { return sprintf("%.2d:%.2d:%.2d", @_) } __DATA__ 9 12 54 23 8 7

Cheers - L~R

Replies are listed 'Best First'.
Re^2: scalar number with preceding 0.
by PerlingTheUK (Hermit) on Jul 26, 2004 at 16:54 UTC
    In this case I perfectly see that sprintf does the job very well. Only the problem is, that at some other places I will soon have to concatenate strings that cann be only digits, letters, ... a lot of them start with leading 0 that I will need to print out later. I have no clear formatting, at least there are about 12 formats I have seen yet. I do not want to create a regexp for each.
      PerlingTheUK,
      I do not understand what you are asking. If you would like to parse date/time strings that come in different formats, you should have a look at Date::Manip. If you are asking how to do some sort of templating then please try to rephrase your question. Break the problem into small pieces, put them in a logical order, and then present them to us in a digestible manner.

      Cheers - L~R

        L~R,
        This is one date time string, with a very simple formatting, but as I have some other problems coming up soon, where I have to concatenate some values that might be only numbers with leading zeros, the behaviour I experience from concatenation which basically replaces 0 with space, surprises me a bit. So I am asking for someplace or explanation why this happens.

        Cheers, PerlingTheUK