Re: Any suggestions?
From: David Warren (davidw_spam_at_spam_gto.net)
Date: 10/20/04
- Next message: Tim Hammerquist: "Re: perl to english"
- Previous message: David Warren: "Re: Any suggestions?"
- In reply to: Jim Gibson: "Re: Any suggestions?"
- Next in thread: Jon Ericson: "Re: Any suggestions?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 20 Oct 2004 02:58:25 -0400
Jim Gibson wrote:
> In article <weCdnYecxoKj_ejcRVn-gw@golden.net>, David Warren
> <davidw_spam@spam_gto.net> wrote:
>
>
>> Frame# 8575/8575 192 kbps L R "
>>
> I am assuming you have 'use strict' and 'use warnings' at the
> beginning of your program.
Yes I'm using 'use strict' and 'use warnings'
>
>> my ( @nums , $num ); local $/ = "\r"; open PIPE, "lame $args
>> \"$song_source\" \"$song_destin\" 2>&1 |"; my $y =
>> $e->gauge_start( text => "Converting: $song_source", percentage =>
>> 1 ); my $line_count = 1;
>>
>> then I'm using a while loop:
>>
>> while ( <PIPE> ) { if ( /Frame/ && /kbps/ && /$line_count/ ) {
>
>
> Here you are trying to match the input line against the current value
> of $line_count. Why are you doing that? The line you show above
> doesn't have a line count value in it. This test will succeed
> randomly based on whether or not the actual line has the current
> value of $line_count in it as a substring somewhere.
>
Perhaps $line_count would be better defined as $frame_count. There is
no real reason other than trying to ensure the output is filtered.
On the 2 and 3rd lines of output from LAME it outputs a
filename and I was just trying to ensure it would be filtered out. (given
that there is some wierd filenames out there). Perhaps, not neccessary or
maybe there would be a better way, to make sure I just got the last line
of output ( which is updated/buffered ) from LAME.
The portion that updates is:
Frame# --->8575<---/8575 192 kbps L R "
That could range anywhere from 1105 -> 8575 (lame skips the first 1105
frames). In this examples, depends on size of mp3.
> You can test and extract the number you want from the input line in
> one operation:
>
> if( |Frame#\s*\d+/(\d+)| ) { my $num = $1; # do something with $num }
>
>
>
>> $line_count++; unless ( defined($num) ) {
>
>
> Why are you testing to see if $num is defined? This will result in
> only performing the extraction one time, since you are assigning a
> value to $num below.
>
Here I'm after only:
Frame# 8575/-->8575<-- 192 kbps L R
This never updates, and I don't need to try to match against it anymore
once I defined $num. Thought it would be unneccessary and pointless to
try and continue to try and match against it. Is there any differences in
efficency between checking if a variables is defined or using pattern
matching?
> Then you should clean it up before asking hundreds of people for
> help. If you need more help, please post a complete, working, minimal
> program that shows the problem you are having.
>
> Thanks.
I should rephrase, I am trying to clean it up. Partially that is what I
was looking for here. Next time I will include a small working
example and being a little clearer. Trying to learn how to use regex
(yes I've read docs) (NOTE - my version was working, I was looking for a
cleaner/more efficent way of doing the while loop.)
Thanks for the help.
David
- Next message: Tim Hammerquist: "Re: perl to english"
- Previous message: David Warren: "Re: Any suggestions?"
- In reply to: Jim Gibson: "Re: Any suggestions?"
- Next in thread: Jon Ericson: "Re: Any suggestions?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|