perl script to print file information - newbie


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script to print file information - newbie
# 1  
Old 04-15-2011
perl script to print file information - newbie

Hi
I have a perl script that prints all the video and audio file information(playing duration).

It works fine in one of my friends linux laptop.

But it doesn't work in my both windows and linux.

My friend told me I have to do install some module ( ppm instal ...... )

but I have no idea what module to install in windows.
in the code I have used
Code:
use IPC::Open3;

Also I have used some file handlers.

Please suggest me which module to install . I tried ppm install IPC::Open3 in command prompt, but it did not work.
It gave me this error "No missing packages to install"

Help me please to execute this code.

---------- Post updated at 12:23 PM ---------- Previous update was at 10:58 AM ----------

Ok , I understand this is not the module problem. Because I feel that the module is already installed .

Here is the code that works fine in linux, but I am not able to make it work in windows.
Code:
#!c:\perl\bin\perl.exe

use strict;
use warnings;
#require "./xxx.pl";
use IPC::Open3;

my @list = glob('*.mp3 *.mp4 *.mpg *.aac *.midi *m3u *.mpa *.dat *.avi');

open(FILEHANDLE, ">vinform.txt") or die "cannot open file";

print FILEHANDLE "NAME \t\t\t DURATION \t DURATION IN SECONDS \n\n";

close(FILEHANDLE);
foreach my $song (@list){

  print "$song \n";

my $filename = $song;

my %videoInfo = videoInfo($filename);

  print "duration: " . $videoInfo{'duration'}. "\n";

  print "durationsecs: " . $videoInfo{'durationsecs'}. "\n\n";

open(FILEHANDLE, ">>vinform.txt") or die "cannot open file";

print FILEHANDLE "$song \t\t";

print FILEHANDLE "". $videoInfo{'duration'}. "\t\t";

print FILEHANDLE "". $videoInfo{'durationsecs'}. "\n \n";

}

close(FILEHANDLE);

sub videoInfo {

    # ffmpeg command

    my $ffmpeg = 'C:\ffmpeg.exe';



    my %finfo = (

                  'duration'     => "00:00:00.00",
                  'durationsecs'  => "0"
);


    my $file = shift;



    # escaping characters

    $file =~ s/(\W)/\\$1/g;



    open3( "</dev/null", ">/dev/null", \*ERPH, "$ffmpeg -i $file" ) or die "can't run $ffmpeg\n";

    my @res = <ERPH>;

 foreach (@res) {



        # duration

        if (m!Duration: ([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])!) {

            $finfo{'duration'} = $1;

        }

  }

    my $tenths  = substr( $finfo{'duration'}, 9, 2 );

    my $seconds = substr( $finfo{'duration'}, 6, 2 );

    my $minutes = substr( $finfo{'duration'}, 3, 2 );

    my $hours   = substr( $finfo{'duration'}, 0, 2 );

    $finfo{'durationsecs'} = ( $tenths * .01 ) + $seconds + ( $minutes * 60 ) + ( $hours * 360 );

    return %finfo;
}

Its just displaying 00:00:00:00 as the output.

Please help me with this assignment.

---------- Post updated at 05:09 PM ---------- Previous update was at 12:23 PM ----------

ok, you need to install ffmpeg.exe and give path in the code.

But I am trying to extract the output from ffmpeg and display it,
I also have to insert the values to my sql database once I get this time and file name.
# 2  
Old 04-20-2011
sed runs on all platforms, can transform the output to valid input or report.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl script print the lines between two pattern

i have a file as below sample.pl parameter1 argument1 argument2 parameter2 I want out as below argument1 argument2 that is , i want to print all the lines between parameter1 & parameter 2. i tried with the following if($mystring =~ m/parameter1(.*?)parameter2/) (2 Replies)
Discussion started by: roopa
2 Replies

2. Programming

Adding information to c file using perl

Hi, I have c file which contains more number of tests. two or more tests in one c file. I have the XMl data regarding tests. i need to add this xml data to c file at before the test. I know which file having which test and i created hash table for that. so the problem is i have to add information... (13 Replies)
Discussion started by: veerubiji
13 Replies

3. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

4. Shell Programming and Scripting

Print file information using ffmpeg in perl

I am trying to print file information using ffmpeg tool in perl Here is my code use strict; use warnings; use IPC::Open3; # example my $filename = $ARGV; my %videoInfo = videoInfo($filename); print "duration: " . $videoInfo{'duration'} . "\n"; print "durationsecs: " .... (0 Replies)
Discussion started by: srijith
0 Replies

5. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

6. Shell Programming and Scripting

Perl Print Problems in script

Hi Perl Gurus, perl -e 'print "http://www.site@domain.com"' The output of the above is : http://www.site.com" I want to print http://www.site@domain.com without using escape sequence before '@' like '\@'. Is there any way to do this in perl? Thanks, Som (1 Reply)
Discussion started by: som.nitk
1 Replies

7. Shell Programming and Scripting

Perl script issue: print

Can someone tell me what I'm doing wrong with my perl script? I am new to Perl. This isn't even the final script, I'm just testing to see if it will print the directories with the files in it. For some reason my output is only printing the 1st, 6th, and last entries of the @sub_dir array. Each... (3 Replies)
Discussion started by: man
3 Replies

8. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

9. Shell Programming and Scripting

Newbie to perl - Help with stats script

Hi, this is my first post so here goes..... I need help... I am trying to write a script to produce some stats based on a number of searches in a log file. Now i know how to do this using multiple variables which are really just greps, but I want a more efficent way of doing this as my poor... (1 Reply)
Discussion started by: ARwebble
1 Replies

10. Shell Programming and Scripting

Perl: adding columns in CSV file with information in each

Hi Wise UNIX Crew, I want to add 3 different columns to the file in which: 1. The first new column pulls in today's date and time 2. Second column one has a '0' 3. Third column has the word 'ANY' going down the column If my file content is as follows: "7","a","abc",123"... (1 Reply)
Discussion started by: dolo21taf
1 Replies
Login or Register to Ask a Question