Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
I cannot trace why all my captured vars come back undef because the debugger steps not finegrained enough. Where do I need to fix my code?
Also, how can I express it in regex that the captured var for e.g. $vr stays undef if there is no video bitrate, yet X/Y resolution and FPS are populated (because they are always on the line)?
Is that a job for regex anyway or is it more elegant with other tools? If yes, what do you recommend?
#!perl use strict; use diagnostics; use Data::Dump::Streamer; while (<DATA>) { my ($ar, $x, $y, $vr, $fps); ($ar) = (m|(\d+) kb/s|) if /Stream.*Audio/; ($x, $y, $vr, $fps) = (m|(\d+)x(\d+).*(\d+) kb/s.*(\d+\.\d+) fps|) + if /Stream.*Video/; Dump [$ar, $x, $y, $vr, $fps] if /^$/; }; __DATA__ E:\jyb.avi Stream #0.1: Audio: mp3, 44100 Hz, mono, 80 kb/s Stream #0.0: Video: mpeg4, yuv420p, 464x240, 25.00 fps(r) E:\weit.m4v Stream #0.0(eng): Audio: aac, 44100 Hz, stereo Stream #0.1(eng): Video: h264, yuv420p, 320x240, 15.00 fps(r) E:\otm.mov Stream #0.1(eng): Audio: qdm2, 44100 Hz, stereo Stream #0.0(eng): Video: svq3, yuv420p, 320x240, 24.00 fps(r) E:\bo.mp4 Stream #0.1(eng): Audio: aac, 44100 Hz, stereo Stream #0.0(eng): Video: mpeg4, yuv420p, 320x240, 25.00 fps(r) E:\tom.mpeg Stream #0.1[0x1c0]: Audio: mp2, 44100 Hz, stereo, 256 kb/s Stream #0.0[0x1e0]: Video: mpeg1video, yuv420p, 352x240, 1180 kb/s, +29.97 fps(r) E:\gb.rmvb Stream #0.1: Audio: cook, 44100 Hz, stereo, 44 kb/s Stream #0.0: Video: RV40 / 0x30345652, 352x288, 180 kb/s, 12.00 fps( +r) E:\xt.wmv Stream #0.0: Audio: wmav2, 32000 Hz, stereo, 32 kb/s Stream #0.1: Video: wmv1, yuv420p, 320x240, 15.00 fps(r)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: conditional regex
by ikegami (Patriarch) on Feb 05, 2007 at 17:27 UTC | |
|
Re: conditional regex
by Util (Priest) on Feb 05, 2007 at 18:51 UTC |