I'm a programmer, new to perl.
My first project is making a new extension module for a perl based wiki.
It uses
\G to create a chain of text replacement patterns.
My new rule is for a new text pattern like so:
[[*.mov x y options_list #bg_color]]
or more structurally
[[*.mov int int (play loop ctrl) #int]]
Using:
if (/\G\[\[(.*?)\.mov (\d+) (\d+) (.*?) #(.*?)\]\]/cgi)
I am gathering up all the params.
My primary question is all about the (play loop control) options list in now in $4. This should be 'play ctrl loop' or some lesser unordered variant of this list. (I want to pass in these optional params as words, not booleans. Setting them true if they are present. )
So how do I process $4 and set local boolean variables
(my $play, my $loop, my $ctrl) based on the absence/presence of these keywords?Essentially false unless the keyword is present.
My humble code, that should set
$loop to be true or false, now returns empty regardless:
my $loop = ($4 eq 'loop');
How do I do this correctly? I feel so close to insight.
My second question has to do with also wanting the color parameter to be optional, now I even ignore the fact it's a number, and just look after the # sign. And how to set it by default to #000000 if the value isn't present. I just can't see it yet.
Here's the working module. Everything is good but my booleans.
# Copyright (C) 2004 Phillip Reay
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
$ModulesDescription .= '<p>$Id: mov.pl,v 1.14 2005/10/09 11:57:52 as E
+xp $</p>';
push(@MyRules, \&movRule);
$RuleOrder{\&movRule} = -10; # run before default rules!
sub movRule { # [[src.mov x:320 y:240 play:true ctrl:true loop:tru
+e bg:#000000]]
if (/\G\[\[(.*?)\.mov (\d+) (\d+) (.*?) #(.*?)\]\]/cgi) {
# [[src.mov x y play ctrl loop bg:#000]]
my $src = $1;
my $x = $2;
my $y = $3;
my $auto = ($4 eq 'play');
my $ctrl = ($4 eq 'ctrl');
my $loop = ($4 eq 'loop');
my $bg = $5;
if ($1 eq 'http://') {
return qq {
<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6
+B' width="$x" height="$y"
codebase='http://www.apple.com/qtactivex/qtplugin.cab'
+>
<param name='src' value="$src.mov">
<param name='autoplay' value="$auto">
<param name='controller' value="$ctrl">
<param name='loop' value="$loop">
<EMBED src="$src.mov" width="$x" height="$y" autoplay=
+"$auto"
controller="$ctrl" loop="$loop" bgcolor="#$bg"
pluginspage='http://www.apple.com/quicktime/download/'
+></EMBED></OBJECT>
}
}
return qq {
<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' w
+idth="$x" height="$y"
codebase='http://www.apple.com/qtactivex/qtplugin.cab'>
<param name='src' value="../movies/$src.mov">
<param name='autoplay' value="$auto">
<param name='controller' value="$ctrl">
<param name='loop' value="$loop">
<EMBED src="../movies/$src.mov" width="$x" height="$y" aut
+oplay="$auto"
controller="$ctrl" loop="$loop" bgcolor="#$bg"
pluginspage='http://www.apple.com/quicktime/download/'></E
+MBED></OBJECT>
}
}
return undef;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.