You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Mario Toro <mt...@movilgate.com> on 2010/04/29 23:04:28 UTC

Help: Migrating from embperl 1.3 to Embperl 2

Hello,

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 ...

Thanks and regards,
-- 
Mario F. Toro
--

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: Help: Migrating from embperl 1.3 to Embperl 2

Posted by Andrew O'Brien <an...@oriel.com.au>.
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
brackets

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


Usage: convert_embperl_files.pl --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
                once

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