<?xml version="1.0" encoding="windows-1252"?>
<node id="535366" title="shmem's scratchpad" created="2006-03-09 05:35:21" updated="2006-03-09 00:35:21">
<type id="182711">
scratchpad</type>
<author id="510280">
shmem</author>
<data>
<field name="doctext">
For [Lady_Aleena] - well, didn't know about [pad://choroba] which contains the same stuff with minimal style changes
&lt;c&gt;
use strict;
use warnings;

my $element = pop; # 'something';

my @attributes;

my %eq = (
    script   =&gt; ['defer'],
    label    =&gt; ['for'],
    area     =&gt; ['nohref'],
    head     =&gt; ['profile'],
    option   =&gt; ['selected'],
    param    =&gt; ['valuetype'],
    table    =&gt; ['border','cellpadding','cellspacing','frame','rules','summary'],
    object   =&gt; ['archive','classid','codebase','codetype','data','declare','standby'],
    select   =&gt; ['multiple'],
    input    =&gt; ['checked','maxlength'],
    frame    =&gt; ['noresize'],
    a        =&gt; [qw(onblur onfocus )],
    label    =&gt; [qw(onblur onfocus )],
    area     =&gt; [qw(onblur onfocus )],
    button   =&gt; [qw(onblur onfocus )],
    select   =&gt; [qw(onblur onfocus onchange multiple size                                     )],
    input    =&gt; [qw(onblur onfocus onchange          size onselect readonly checked maxlength )],
    textarea =&gt; [qw(onblur onfocus onchange               onselect readonly                   )],
    iframe   =&gt; ['frameborder','longdesc','marginheight','marginwidth','scrolling'],
    frame    =&gt; ['frameborder','longdesc','marginheight','marginwidth','scrolling','noresize'],
);

my %matches = (
    '(?:meta)'                                           =&gt; ['content','http-equiv','scheme'],
    '^(?:body|frameset)$'                                =&gt; ['onload','onunload'],
    '^(?:a|area)$'                                       =&gt; ['coords','shape'],
    '^(?:a|link)$'                                       =&gt; ['hreflang','rel','rev'],
    '(?:a|area|base|link)'                               =&gt; ['href'],
    '(?:a|area|base|link|form)'                          =&gt; ['target'],
    '(?:a|area|button|input|label|legend|textarea)'      =&gt; ['accesskey'],
    '(?:a|area|button|input|object|select|textarea)'     =&gt; ['tabindex'],
    '(?:a|link|script)'                                  =&gt; ['charset'],
    '(?:a|link|button|input|object|param|script|style)'  =&gt; ['type'],
    '^(?:del|ins)$'                                      =&gt; ['cite','datetime'],
    '^(?:col|colgroup|tbody|td|tfoot|th|thead|tr)$'      =&gt; ['align','char','charoff','valign'],
    '^(?:td|th)$'                                        =&gt; ['abbr','axis','colspan','headers','rowspan','scope'],
    '(?:col|colgroup)'                                   =&gt; ['span'],
    '^(?:input|select)$'                                 =&gt; ['size'],
    '^(?:form|input)$'                                   =&gt; ['accept'],
    '^(?:image|area|input)$'                             =&gt; ['alt'],
    '^(?:button|input|optgroup|option|select|textarea)$' =&gt; ['disabled'],
    '^(?:iframe|img|object)$'                            =&gt; ['height'],
    '^(?:img|input)$'                                    =&gt; ['ismap'],
    '^(?:option|optgroup:)$'                             =&gt; ['label'],
    '^(?:style|link|form)$'                              =&gt; ['media'],
    '^(?:a|button|form|frame|iframe|img|input|object|map|param|meta|select|textarea)$' =&gt; ['name'],
    '^(?:input|frame|iframe|img|script)$'                =&gt; ['src'],
    '^(?:img|input|object)$'                             =&gt; ['usemap'],
    '^(?:input|option|param|button|li)$'                 =&gt; ['value'],
    '^(?:iframe|img|object|table|col|colgroup)$'         =&gt; ['width'],
);

my %non_matches = (
    '^(?:base|basefont|head|html|meta|param|script|title|style)$'          =&gt; ['class','style'],
    '^(?:applet|base|basefont|bdo|br|frame|iframe|frameset|param|script)$' =&gt; ['dir'],
    '^(?:base|head|html|meta|script|style|title)$'                         =&gt; ['id'],
    '^(?:applet|base|basefont|br|frame|frameset|iframe|param|script)$'     =&gt; ['lang'],
    '^(?:base|basefont|head|html|meta|param|script|title)$'                =&gt; ['title'],
    '^(?:applet|base|basefont|bdo|br|font|frame|frameset|head|html|iframe|isindex|meta|param|script|style|title)$'
        =&gt; ['onclick','ondblclick','onkeydown','onkeypress','onkeyup','onmousedown',
            'onmousemove','onmouseout','onmouseover','onmouseup'
           ],
);

push @attributes, @{$eq{$element}} if exists $eq{$element};
$element =~ qr{$_} and push @attributes, @{$matches{$_}} for keys %matches;
$element !~ qr{$_} and push @attributes, @{$non_matches{$_}} for keys %non_matches;

print join("\n",sort @attributes);

&lt;/c&gt;
&lt;hr&gt;
&lt;p&gt;&lt;c&gt;foo.pl&lt;/c&gt;&lt;/p&gt;
&lt;c&gt;
#!/usr/bin/perl
use strict;
my $pat = shift;
my $p;
{
  my (%s, %i);
  my $d = my $c = 1; # our regexp will be inside parens, so first backref is 2
  $p = join (
    "",
    map {
      if($s{$_}++){
        "\\".$i{$_}
      }
      else{
        $i{$_}=++$c;
        $c&gt;$d+1 ? '(?!'.join('|',map{"\\".abs}-$c+1..-$d-1).")(\\w)" : "(\\w)";
      }
    } split//,$pat
  );
}
print '(',$p,")\n";


open my $fh, '&lt;', shift;
my %s;
while (&lt;$fh&gt;) {
    my @l = ();
    while (/\b($p)\b/g) {
      push @l, $1 unless $s{$1}++;
    }
    print join (", ",@l), $/ if @l;
}
&lt;/c&gt;
&lt;p&gt;try: &lt;c&gt;perl foo.pl fusselkerl /usr/share/dict/words&lt;/c&gt;&lt;/p&gt;</field>
</data>
</node>
