V
Vito Corleone
Hi,
How can I do progressive progressive matching and replace? For example I
want to change this text:
##--- before ---##
adfdf <photo src=12> dasfd Fdfdsfdf <photo
src=14> adsfdf dsf dsf dsf asdfdsa ds <phot
o> dsafd adsf
to:
##--- after ---##
adfdf <img src=12.gif> dasfd Fdfdsfdf <img
src=14.gif> adsfdf dsf dsf dsf asdfdsa ds <phot
o> dsafd adsf
And also I want to check if each user has access to the image they are
trying to link to. Here is what I tried:
##----- start sample.pl -----##
my $test =<< "BLOCK"; ## User input this from web interface, textarea
adfdf <photo src=12> dasfd Fdfdsfdf <photo
src=14> adsfdf dsf dsf dsf asdfdsa ds <phot
o> dsafd adsf
BLOCK
;
$test =~ s/\n//g;
while ($test =~ /<photo src=(\d+)>/g) {
if (!check_access($1)) { ## See if user have access to this photo
die "Use your own photo";
}
## Here I don't know how to change
## from <photo src=XX> to <img src=XX.gif>
}
##----- end sample.pl -----##
But I have some problems here:
1. I can do progressive matching, but I don't know how to replace it.
2. Even if I can, I don't know how can I restore the newline that I
deleted.
Any better way to do this? Thank you very much.
--Vito
How can I do progressive progressive matching and replace? For example I
want to change this text:
##--- before ---##
adfdf <photo src=12> dasfd Fdfdsfdf <photo
src=14> adsfdf dsf dsf dsf asdfdsa ds <phot
o> dsafd adsf
to:
##--- after ---##
adfdf <img src=12.gif> dasfd Fdfdsfdf <img
src=14.gif> adsfdf dsf dsf dsf asdfdsa ds <phot
o> dsafd adsf
And also I want to check if each user has access to the image they are
trying to link to. Here is what I tried:
##----- start sample.pl -----##
my $test =<< "BLOCK"; ## User input this from web interface, textarea
adfdf <photo src=12> dasfd Fdfdsfdf <photo
src=14> adsfdf dsf dsf dsf asdfdsa ds <phot
o> dsafd adsf
BLOCK
;
$test =~ s/\n//g;
while ($test =~ /<photo src=(\d+)>/g) {
if (!check_access($1)) { ## See if user have access to this photo
die "Use your own photo";
}
## Here I don't know how to change
## from <photo src=XX> to <img src=XX.gif>
}
##----- end sample.pl -----##
But I have some problems here:
1. I can do progressive matching, but I don't know how to replace it.
2. Even if I can, I don't know how can I restore the newline that I
deleted.
Any better way to do this? Thank you very much.
--Vito