That's not really a module ... first, even if you do consider that a module, it really is two modules. Second, modules are not meant to be executed, so no need for the 'she-bang' line. Third, if you are going to make a module, i really recommend you stick with the Object Oriented paradigm, but that's just me. Here is a shell that uses OO as well as allows the client to chose whether to use mpgtx or ffmpeg. (This is untested.)

package Info::Video; use strict; use warnings; my %value_types = ( mpginfo => '/usr/bin/mpgtx -i', ffmpeg => '/usr/bin/ffmpeg', ); sub new { my $class = shift; my $type = shift || 'mpginfo'; die "invalid type:$type\n" unless $valid_type{$type}; my $self = { type => $type, duration => '00:00:00.0', bitrate => 0, vcodec => '', vformat => '', framerate => '0.00', acodec => '', samplerate => 0, stereo => 0, audiorate => 0, }; return bless $self, $class; } sub video_info { my $self = shift; my $file = shift; # note: use $valid_types{ $self->{type} } for executable if ($self->{type} eq 'mpginfo') { # handle mpginfo } elsif ($self->{type} eq 'ffmpg') { # handle ffmpg } return $self; } 1;
And a simple client:
#!/usr/bin/perl use strict; use warnings; use Info::Video; my $info = Info::Video->new('ffmpeg'); $info->video_info(); # now $info contains the video information

That's a decent "first stab" at the problem. It is far from optimal, but it should illustrate a better way of getting things done. I don't like having to use an if-elsif inside the video_info() sub ... i would consider using a Factory Pattern instead (or Class::Factory). I would also consider using Class::MethodMaker so that you can automatically add accessor methods to your object, instead of mucking directly with the attributes. Finally ... use POD! Don't use simple # comments for documentation, save those for simple comments.

And finally finally, don't stick use warnings; in the middle of a for loop. Cheers! :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: Video information by jeffa
in thread Video information by wazoox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.