Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Lady_Aleena's scratchpad

by Lady_Aleena (Chaplain)
on Sep 07, 2007 at 20:54 UTC ( #637756=scratchpad: print w/ replies, xml ) Need Help??

package Base::HTML::Inline; use strict; use warnings; use Exporter qw(import); our @EXPORT_OK = qw(inline); # Written by an Anonymous Monk on PerlMonks ( +?node_id=1028699) use Regexp::Common qw/ balanced /; use vars qw/ $re_balanced_angles /; our $re_balanced_angles = qr{(?^:(?^:(?:\<(?:(?>[^\<\>]+)|(??{ $re_bal +anced_angles }))*\>)))}; our $allowed = join '|', qw[ A ABBR ACRONYM B BIG CITE CODE DFN EM I KBD Q SAMP SMALL SPAN STRONG SUB SUP TT VAR ]; sub inline { local $_ = $_[0]; my $dent = $_[1] || 0; pos = 0; my $ret = ""; inlineLOOP: while( length > pos ){ m{\G(\s+)}gcsx and do { $ret .= $1; next inlineLOOP; }; m{\G( $allowed )( $re_balanced_angles )}gcsx and do { $ret .= inline_allowed( "$1" , "$2" , $dent ); next inlineLOOP; }; m{\G([^<]+\s)}gcmx and do { $ret .= inline_text( "$1" ); next inlineLOOP; }; m{\G([\<\>])}gcmx and do { last inlineLOOP; }; m{\G(\S)}gcmx and do { $ret .= inline_text( "$1" ); next inlineLOOP; }; } $ret; } sub inline_allowed { my( $tag , $stuff, $dent ) = @_; $stuff = $1 if $stuff =~ m{^<(.*)>$}gs; my $ret = ""; $ret .= "<\L$tag\E" if $tag; $stuff =~ s{\|([^<>]+)$}{$ret .= " $1"; "";}gsex if defined $stuff; ## inline_allowed_atts($tag,$1) $ret .= ">" if $tag; if( defined $stuff and length $stuff and $stuff =~ m{[<>]}g ){ $ret .= inline( $stuff , $dent+1) ; ## recurse } else { $ret .= $stuff; } $ret .= "</\L$tag\E>" if $tag; $ret; } sub inline_text { join'',@_ } 1;

Notes to self

  • Do not print Dumper when trying to display a script in a browser without using <pre> tags.
  • Do print Dumper when something goes wrong. The data structure is usually the problem.
  • If one changes a variable, check the whole script for that variable to make sure that the results will be as expected.
  • rename will not create directories, be sure to use mkdir in conjunction with rename if the files are also being moved to a new directory.

Notes from others

  • bart: LA it's often considered good practice to increment the variable in a continue block, to prevent running out of sync when using next.
  • Intrepid: btw, i wish i could explain to a lot of people i know, how efficacious Lady_Aleena's explained strategy can be (to use coding and thinking about coding to master a disquieted state of mind)
  • ambrus: In general, use magic only when normal solutions aren't enough.
  • GrandFather: each time through its loop while asks itself "Can I loop this time? Can I? Can I Can I? Please?" and if the answer is no (false statement) while gets grumpy and stops

Things I should get a grip on

  • objects
  • testing
  • SQL
  • version control
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-07-29 18:50 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (226 votes), past polls