Date: 9/2/2010 10:31 am
Rating: 0
Anyway, the problem I'm having is that I'd like to escape quotes from a string and spit it out onto the page. I can do it outside of the expression tags using a simple substitution, but it requires two statements to do it.
my $str = $ARGS{'search'}; #copy to local variableThen I'm able to use the expression <% $str %> to get the value I need. Unfortunately, Mason doesn't allow multiple statements between the expression tags, so I'm wondering if there's some way to reduce this all to an inline expression. I know that in Javascript, I would just do str.replace(); PHP would use str_replace(), too. Is there a simple expression in Perl that would allow me to do this all inline?
$str=~s/"/\"/g; #Make the substitution
Thanks,
Karl
Date: 9/2/2010 11:05 am
Rating: 0
use URI::Encode qw(uri_encode);
<% uri_encode($ARGS{'search'}) %>
On Thu, Sep 2, 2010 at 10:31 AM, wrote:
> Spizzat2 wrote:
>
> I'm working with HTML::Mason, which allows you to build web pages in a
> fashion very similar to PHP in that it lets you intersperse Perl code into
> the HTML page as it's being built by wrapping expressions in Mason tags (
> which look like this <% %> ). Obviously, Perl could do this alone, but Mason
> provides other features.
> Anyway, the problem I'm having is that I'd like to escape quotes from a
> string and spit it out onto the page. I can do it outside of the expression
> tags using a simple substitution, but it requires two statements to do it.
>>
>> my $str = $ARGS{'search'}; #copy to local variable
>> $str=~s/"/\"/g; #Make the substitution
>
> Then I'm able to use the expression <% $str %> to get the value I need.
> Unfortunately, Mason doesn't allow multiple statements between the
> expression tags, so I'm wondering if there's some way to reduce this all to
> an inline expression. I know that in Javascript, I would just do
> str.replace(); PHP would use str_replace(), too. Is there a simple
> expression in Perl that would allow me to do this all inline?
> Thanks,
> Karl
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
Date: 9/2/2010 11:18 am
Rating: 0
----- Original Message -----From: madtalk@madmongers.orgTo: admin@wisbin.comSent: Thursday, September 02, 2010 11:05 AMSubject: [MadTalk] Re: Substitution expressionmcholste wrote:
What about all the other unsafe chars? I'd go canonical:
use URI::Encode qw(uri_encode);
<% uri_encode($ARGS{'search'}) %>
On Thu, Sep 2, 2010 at 10:31 AM, wrote:
> Spizzat2 wrote:
>
> I'm working with HTML::Mason, which allows you to build web pages in a
> fashion very similar to PHP in that it lets you intersperse Perl code into
> the HTML page as it's being built by wrapping expressions in Mason tags (
> which look like this <% %> ). Obviously, Perl could do this alone, but Mason
> provides other features.
> Anyway, the problem I'm having is that I'd like to escape quotes from a
> string and spit it out onto the page. I can do it outside of the expression
> tags using a simple substitution, but it requires two statements to do it.
>>
>> my $str = $ARGS{'search'}; #copy to local variable
>> $str=~s/"/\"/g; #Make the substitution
>
> Then I'm able to use the expression <% $str %> to get the value I need.
> Unfortunately, Mason doesn't allow multiple statements between the
> expression tags, so I'm wondering if there's some way to reduce this all to
> an inline expression. I know that in Javascript, I would just do
> str.replace(); PHP would use str_replace(), too. Is there a simple
> expression in Perl that would allow me to do this all inline?
> Thanks,
> Karl
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
Date: 9/2/2010 11:32 am
Rating: 0
Date: 9/2/2010 11:47 am
Rating: 0
It's in an HTML attribute. Those functions should provide me what I need. I already had an alternative solution, though. This was more to see if it could be done theoretically.
On Sep 2, 2010 11:46 AM, <doug@plainblack.com> wrote:
preaction wrote:
Why are you escaping the quotes?Is it for inside an HTML tag? use HTML::Entities.<% encode_entities( $string ) %>For a URL? URI::Escape.<% uri_encode( $string ) %>For inside Perl code? quotemeta().<% quotemeta( $string ) %>
View Online
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
Date: 9/2/2010 11:55 am
Rating: 0
Thanks to everyone else for pointing me to some good packages that solve the problem.
Spizzat2 wrote:
It's in an HTML attribute. Those functions should provide me what I need. I already had an alternative solution, though. This was more to see if it could be done theoretically.
On Sep 2, 2010 11:46 AM, <doug@plainblack.com> wrote:
preaction wrote:
Why are you escaping the quotes?Is it for inside an HTML tag? use HTML::Entities.<% encode_entities( $string ) %>For a URL? URI::Escape.<% uri_encode( $string ) %>For inside Perl code? quotemeta().<% quotemeta( $string ) %>
View Online
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
Date: 9/2/2010 12:37 pm
Rating: 0
jon
On 9/2/10 11:32 AM, doug@plainblack.com wrote:
preaction wrote:
Why are you escaping the quotes?
Is it for inside an HTML tag? use HTML::Entities.<% encode_entities( $string ) %>
For a URL? URI::Escape.<% uri_encode( $string ) %>
For inside Perl code? quotemeta().<% quotemeta( $string ) %>
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
-- .Jonathan J. Miner----------------------------------------------------. | jon@jjminer.org | photos - http://photos.jjminer.org/ | | | R.A.W. #1629 - http://www.reggaeambassadors.org | | | LOCS Webmaster - http://www.locs-buffett.org | | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper | `---------------------------------------------------------------------' "We don't have a town drunk... We all take turns!" -- James Slater, "Key West Address"
Date: 9/2/2010 1:05 pm
Rating: 0
$insert_sth->execute($value1, $value2) or die $DBI::errstr;
----- Original Message -----From: jon@jjminer.orgTo: admin@wisbin.comSent: Thursday, September 02, 2010 12:37 PMSubject: [MadTalk] Re: Substitution expressionminer wrote:
And, of course, if it's something to do with a database, $dbh->quote( $string ).
jon
On 9/2/10 11:32 AM, doug@plainblack.com wrote:preaction wrote:
Why are you escaping the quotes?Is it for inside an HTML tag? use HTML::Entities.<% encode_entities( $string ) %>For a URL? URI::Escape.<% uri_encode( $string ) %>For inside Perl code? quotemeta().<% quotemeta( $string ) %>
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org-- .Jonathan J. Miner----------------------------------------------------. | jon@jjminer.org | photos - http://photos.jjminer.org/ | | | R.A.W. #1629 - http://www.reggaeambassadors.org | | | LOCS Webmaster - http://www.locs-buffett.org | | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper | `---------------------------------------------------------------------' "We don't have a town drunk... We all take turns!" -- James Slater, "Key West Address"
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
Date: 9/2/2010 11:46 am
Rating: 0
>> my $str = $ARGS{'search'}; #copy to local variable
>> $str=~s/"/\"/g; #Make the substitution
I think those are all good points - quote is only one of your worries,
rigth? But just to take a stab at your orig. question:
(my $str = $ARGS{'search'} ) =~ s/"/\"/g;
I imagine you could skip the local str too and operate/use on %ARGS -
I doubt it'd break anything 'upstream', though it is a bit ugly for a
lot of use.
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk
Date: 9/2/2010 12:12 pm
Rating: 0
> Unfortunately, Mason doesn't allow multiple statements between the
> expression tags
maybe not *those* tags, but you can use other tags
from:
http://search.cpan.org/~drolsky/HTML-Mason-1.45/lib/HTML/Mason/Devel.pod
% lines
Most useful for conditional and loop structures - if, while, foreach, ,
etc. - as well as side-effect commands like assignments. To improve
readability, always put a space after the '%'. Examples:
o Conditional code
% my $ua = $r->header_in('User-Agent');
% if ($ua =~ /msie/i) {
Welcome, Internet Explorer users
...
% } elsif ($ua =~ /mozilla/i) {
Welcome, Netscape users
...
% }
o HTML list formed from array
% foreach $item (@list) {
<% $item %>
% }
o HTML list formed from hash
% while (my ($key,$value) = each(%ENV)) {
<% $key %>: <% $value %>
% }
o HTML table formed from list of hashes
% foreach my $h (@loh) {
<% $h->{foo} %>
<% $h->{bar} %>
<% $h->{baz} %>
% }
<% xxx %>
Most useful for printing out variables, as well as more complex
expressions. To improve readability, always separate the tag and
expression with spaces. Examples:
Dear <% $name %>: We will come to your house at <% $address %> in the
fair city of <% $city %> to deliver your $<% $amount %> dollar prize!
The answer is <% ($y+8) % 2 %>.
You are <% $age < 18 ? 'not' : '' %> permitted to enter this site.
<%perl> xxx
Useful for Perl blocks of more than a few lines.
Date: 9/2/2010 12:28 pm
Rating: 0
Right, and I was hoping to get it all done in one expression like I can in many other languages. My initial solution was to do it in multiple lines, but Andy's code and the packages gave me a way to do it in one expression, so I could use the <% %> tags.
On Sep 2, 2010 12:27 PM, <jesse.thompson@doit.wisc.edu> wrote:
zjt wrote:
maybe not *those* tags, but you can use other tags
On 09/02/2010 10:31 AM, madtalk@madmongers.org wrote:
> Unfortunately, Mason doesn't allow multipl...
from:
http://search.cpan.org/~drolsky/HTML-Mason-1.45/lib/HTML/Mason/Devel.pod
% lines
Most useful for conditional and loop structures - if, while, foreach, ,
etc. - as well as side-effect commands like assignments. To improve
readability, always put a space after the '%'. Examples:
o Conditional code
% my $ua = $r->header_in('User-Agent');
% if ($ua =~ /msie/i) {
Welcome, Internet Explorer users
...
% } elsif ($ua =~ /mozilla/i) {
Welcome, Netscape users
...
% }
o HTML list formed from array
% foreach $item (@list) {
<% $item %>
% }
o HTML list formed from hash
% while (my ($key,$value) = each(%ENV)) {
<% $key %>: <% $value %>
% }
o HTML table formed from list of hashes
% foreach my $h (@loh) {
<% $h->{foo} %>
<% $h->{bar} %>
<% $h->{baz} %>
% }
<% xxx %>
Most useful for printing out variables, as well as more complex
expressions. To improve readability, always separate the tag and
expression with spaces. Examples:
Dear <% $name %>: We will come to your house at <% $address %> in the
fair city of <% $city %> to deliver your $<% $amount %> dollar prize!
The answer is <% ($y+8) % 2 %>.
You are <% $age < 18 ? 'not' : '' %> permitted to enter this site.
<%perl> xxx
Useful for Perl blocks of more than a few lines.
View Online
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org