DaWolf has asked for the wisdom of the Perl Monks concerning the following question:

Hello there.

I'm generating a scalar variable based in time(), so:

$foo = time();

I want to limit the length of this variable in six characters, so I did this:

$foo = time(); truncate $foo, 6;


But it doesn't works at all... The variable still have the same length that it had before. Any thoughts?

Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper

Replies are listed 'Best First'.
Re: Using truncate
by btrott (Parson) on Jan 17, 2001 at 03:00 UTC
Re: Using truncate
by Beatnik (Parson) on Jan 17, 2001 at 03:04 UTC
    truncate is a file thing, you can use substr to limit the length of a scalar.

    $string = substr($string,0,6);

    ofcourse there are many ways to handle time/date stuff, besides cutting of the number of seconds since the Epoch (which is what time returns). You'll probably find localtime much handier.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.