I don't know much about PHP, but here is a straightforward idea that might make some sense or I hope at least give you something to work from. The general idea is to break this down into smaller "chunks". I assume that the code that your Perl program "re-writes" does compile and that parens match up, etc. Compressing the spaces is also a simplifying assumption.
#!/usr/bin/perl -w
use strict;
my $line = q{ split( '/', $string ) };
$line =~ s/ //g; #compress spaces
#now just "split('/',$string)"
if ($line =~ m/^split/) # check for the split keyword
{
# get (parm1, parm2) of the split, ie the two
# things separated by commas within the parens
my ($parm1,$parm2) = ($line =~ m/\((.*?),(.*?)\)/)[0,1];
# now get stuff between quotes in parm 1
my $inside_quote = ($parm1 =~ m|'(.*?)'|)[0];
# change any / to \/
$inside_quote =~ s|/|\\/|g;
#now just print back out
print "preg_split('/$inside_quote/',$parm2)\n";
}
__END__
Prints:
preg_split('/\//',$string)
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.