Using printf to modify scalars

J

jussi

Hi Gurus

I try to make an timecode generator and my problem is that using printf
I can get right format. But I can't use printf to modify scalars
format:

Here is what get so far:

------------- START ---------------

#!/usr/bin/perl -w
$time_seconds = 0;
$time_minutes = 0;
$time_hours = 10;




while (</tmp/*.jpg>)
{


$time_frames = $time_frames + 1 ;
if ($time_frames < 10 ) {
$time_frames = "0".$time_frames;
}
if ($time_frames == 25) {
$time_frames = 0;
$time_seconds = $time_seconds + 1;
}
if ($time_seconds == 60) {
$time_seconds = 0;
$time_minutes = $time_minutes + 1;
}
if ($time_seconds < 10 ) {
$time_seconds = "0".$time_seconds ;
}

if ($time_minutes == 60 ){
$time_minutes = 0 ;
$time_hours = $time_hours + 1;
}
if ($time_minutes < 10 ){
$time_minutes = "0".$time_minutes;
}

$timecode = (printf
"%02d:%02d:%02d:%02d\n",$time_hours,$time_minutes,$time_seconds,$time_frames);
print "Time Code is: $timecode\n";

--------------------------- END ------------------------------

Printf gives me right format, but $timecode is constant 1 (=succesfull
??):

10:00:00:01
Time Code is: 1
10:00:00:02
Time Code is: 1
10:00:00:03
Time Code is: 1
10:00:00:04
Time Code is: 1
10:00:00:05
Time Code is: 1
10:00:00:06
Time Code is: 1
10:00:00:07
Time Code is: 1
10:00:00:08
Time Code is: 1
10:00:00:09
Time Code is: 1
10:00:00:10
Time Code is: 1
10:00:00:11
Time Code is: 1
10:00:00:12
Time Code is: 1
10:00:00:13
Time Code is: 1
10:00:00:14
Time Code is: 1
10:00:00:15
Time Code is: 1
10:00:00:16
Time Code is: 1
10:00:00:17
Time Code is: 1
10:00:00:18
Time Code is: 1
10:00:00:19
Time Code is: 1
10:00:00:20
Time Code is: 1
10:00:00:21
Time Code is: 1
10:00:00:22


So I would like to get time code in 10:00:00:22 format so I can pas it
to bash script

Any help would be very appreciate
-Jussi
 
B

Brian McCauley

jussi said:
[ question about printf() ]

Please read the documentation of the printf() function. Make sure that
you read at least as far as halfway through the first sentence before
you give up and ask for help.

Note: in general if you have question about a specific
function/module/error message whatever it's more efficient for all
concerned to try looking it up in the manual before asking for help.
 
J

jdamon

jussi said:
$timecode = (printf
"%02d:%02d:%02d:%02d\n",$time_hours,$time_minutes,$time_seconds,$time_frames);
print "Time Code is: $timecode\n";


I don't know what your script is attempting to do ( as your times have
nothing to do with times of the files ) , but

a quick fix would be



$timecode = print sprintf
"%02d:%02d:%02d:%02d\n",$time_hours,$time_minutes,$time_seconds,$time_frames);

print "Time Code is: $timecode\n";


the sprintf will do your formatting...

-Jimi
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top