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

I am new to perl. I have to write a script that will:
1. get the filesize of an mp3 file in bytes (ls -l -R)
2. multiply the field in bytes by 8 to get bits
3. divide the results by 128000 (128kbs/sec) to get playtime in seconds
4. get the playtime in seconds and convert is to minutes (/60)
5. convert the decimal minutes to MM:SS
6. will produce an output of: "songname sizeinM time in MM:SS" recursively 
possibly to a file.
This is what I have done using awk. (I'm new to this too)
ls -l | awk '{print $5,(($5*8)/128000)/60}' | awk -F\. '{print $1, $2* +(60/100)}'
You help is truly appreciated. Thank you.

Replies are listed 'Best First'.
Re: playtime calculation
by japhy (Canon) on Jan 28, 2000 at 18:51 UTC
    Here is a simple program. Do not just use it, though. If you want to write a Perl program, it's best to learn Perl.
    #!/usr/bin/perl $filename = $ARGV[0]; # filename passed on commandline $size = (-s $filename) * 8 / 128000 / 60; ($min,$sec) = (int($size/60), $size % 60); printf "$filename is %d:%02d long\n", $min, $sec;
    How does it work? Look in 'perlfunc' for the -s file test. Look at 'perlop' if you need help with the math operators. Look at 'perldoc -f printf' and 'perldoc -f sprintf' to see how printf works in formatting your time output. japhy
Re: playtime calculation
by da w00t (Sexton) on Jan 31, 2000 at 02:13 UTC