perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew O'Brien" <>
Subject RE: Help: Migrating from embperl 1.3 to Embperl 2
Date Thu, 29 Apr 2010 22:46:17 GMT

Hi Mario,

> How can do a perl regular expresion for search and replace blocks like
>         [+ command1 ; command2; command3 +]
> with
>        [+ do { command1 ; command2; command3 } +]
> We try with some like this :
> cat file.epl |perl -na -e'if ($_ =~ m/\[\+( *.+? *)\+\]/g ){ print "
> do {$1}\n"} ;'
> But code like [+ $output +]  is replaced with [+ do {$output} 
> +] too ...

The mail archives don't seem to be available but below is an email I
sent to the list with a script to do exactly this in August 2007. It
will probably get you 95% of the way there :)

Hi all,

As part of migrating a large embperl site from HTML::Embperl I ended up
whipping up a quick script to convert plus blocks and foreach loops to
the format required by Embperl 2.x.

There are still other issues as I work through things but these relate
to either the current working directory not being the basename of the
file being executed or html construct nesting issues which should be
cleaned up anyway.

(I'm not claiming this is perfect but it does 99% which is good enough
for me :) )

Hopefully someone might find this useful.

This does the following:

1) removes trailing semicolons from plus blocks

[+ $something; +] -> [+ $something +]
[+ do { blah; foo; bar; }; +] -> [+ do { blah; foo; bar; } +]

2) wraps multistatement plus blocks in do{} constructs

[+ $a=1; $a +] -> [+ do { $a=1; $a } +]

3) makes sure all [$ foreach $] argument lists are contained in round

[$ foreach $a @list $] -> [$ foreach $a (@list) $]
[$ foreach $a 'foo', 'bar' $] -> [$ foreach $a ('foo', 'bar') $]

Usage: --dir directory [--dir directory2]
          --match filematch [--match filematch2]
          [--potent] [--verbose] [--exclude path]

 -d, --dir      A base directory to recurse from. May be given
                more than once.
 -m, --match    A file glob or regex to match filename. May be
                given more than once
 -b, --backup   Back up each matched file with a .bak extension
 -e, --exclude  A full directory name to exclude. It is anchored
                at the beginning of the file path when tested.
 -l, --limit    Change at most this many files
 -p, --potent   Actually perform file content substitutions.
 -v, --verbose  Increase verbosity. May be given more than

Eg: -d /var/www/mysite -m '*.epl' \
  -m '*.html' -e /var/www/mysite/not_embperl -v -v

View raw message