[31222] in Perl-Users-Digest
Perl-Users Digest, Issue: 2467 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 10 00:09:47 2009
Date: Tue, 9 Jun 2009 21:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 9 Jun 2009 Volume: 11 Number: 2467
Today's topics:
Re: perl and CGI <mvdwege@mail.com>
Re: perl and CGI <someone@somewhere.nb.ca>
Re: perl and CGI <tadmc@seesig.invalid>
Re: perl and CGI <tadmc@seesig.invalid>
Re: perl and CGI <ben@morrow.me.uk>
understanding \Q \E <someone@somewhere.nb.ca>
Re: understanding \Q \E <ben@morrow.me.uk>
Re: understanding \Q \E <derykus@gmail.com>
Re: understanding \Q \E <someone@somewhere.nb.ca>
Re: understanding \Q \E <tadmc@seesig.invalid>
Re: understanding \Q \E <someone@somewhere.nb.ca>
Re: understanding \Q \E <tadmc@seesig.invalid>
Re: understanding \Q \E <tadmc@seesig.invalid>
Re: understanding \Q \E <jurgenex@hotmail.com>
Re: understanding \Q \E <jurgenex@hotmail.com>
Re: understanding \Q \E <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Jun 2009 00:35:19 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: perl and CGI
Message-Id: <86ws7lm3x4.fsf@gareth.avalon.lan>
JXrgen Exner <jurgenex@hotmail.com> writes:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
>>Vit <FiNaR76@gmail.com> wrote in news:c735cb19-fe19-4379-8598-
> [...]
>>> in the cgi-bin directori the "my_email.cgi" file:
>>> #!/usr/bin/perl
>>> print "Content-type: text/html\n\n";
>>> print "Hello, world!\n";
>>
>>The content you send and the content type you specify conflict:
>
> Sorry for asking stupid and even off-topic, but: while true that
> shouldn't cause a server error, should it?
>
Indeed not. The server does not do HTML validation, that's the work of
the HTML parser on the client.
Possible causes for the error seen by the OP:
- Permissions on the CGI script are wrong.
- Webserver is looking in another directory for CGI scripts.
- I saw the OP using backslashes to specify the path in the URL. I don't
know if that's going to work with Apache (the server output mentions
it's Ubuntu, so I assume Apache as httpd).
- Perl is not in /usr/bin on the webserver.
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Tue, 9 Jun 2009 21:22:22 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: perl and CGI
Message-Id: <4a2efcab$0$23753$9a566e8b@news.aliant.net>
"Vit" <FiNaR76@gmail.com> wrote:
Hi All,
I'm new to the perl language....
I'm trying to understand how this language work and I hav develop the
following code:
in the webpage:
<form action="\cgi-bin\my_email.cgi" method="post">
<input type="submit" name="Submit" value="Submit" style="width:
93px" />
in the cgi-bin directori the "my_email.cgi" file:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, world!\n";
I'm using this file just to test.... and the result is that is not
working....
when I click to the "submit" button, I get the following message:
Server error!
The server encountered an internal error and was unable to complete
your request.
Error message:
Premature end of script headers: my_email.cgi
If you think this is a server error, please contact the webmaster.
Error 500
Tue Jun 9 14:11:00 2009
Apache/2.0.55 (Ubuntu) mod_ldap_userdir/1.1.11 PHP/4.4.2-1.1
mod_vhost_ldap/1.0.0
what can I do?? do you know what can I cahe to find out the issue???
thanks
Vit
-----------------------------
Did you solve your problem?
1. Make sure you upload your Perl script to the correct folder on your web
server, which I think would be something like /cgi-bin. Otherwise you may
get a 404 error, saying it can't find the file.
2. Once on the server, ensure that you change the file's properties to
executable, otherwise, I think you'll get error 403, something about
refusing to display web page.
3. I get the 500 Internal Server Error when I have an error in my code. The
following script for example works fine:
#!/usr/bin/perl
$command= $];
$title = "Perl Version";
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head><body>";
print "<h1>$title</h1>\n";
print "Perl version : ".$command;
print "<HR> \n";
system 'perl -v';
It displays the following -- yes I know it would be great if I had Perl 10
:(
Perl Version
Perl version : 5.006001
-----------------------
This is perl, v5.6.1 built for i686-linux Copyright 1987-2001, Larry Wall
Perl may be copied only under the terms of either the Artistic License or
the GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
If however, I forget a semi colon like:
#!/usr/bin/perl
$command= $] # <--- Forgot Semicolon
$title = "Perl Version";
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head><body>";
print "<h1>$title</h1>\n";
print "Perl version : ".$command;
print "<HR> \n";
system 'perl -v';
I get the following:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, or webmaster and inform them of the
time the error occurred, and anything you might have done that may have
caused the error.
More information about this error may be available in the server error log.
4. You can also access your perl scripts directly instead of submitting a
form, for example, type the following in your address bar, and also use
/cgi-bin/my_email.cgi instead of \cgi-bin\my_email.cgi like Sinan said.
http://yourserver/cgi-bin/my_email.cgi
5. On a side note, I use the .pl extension instead of .cgi, but I may be a
minority? I think I even read that it was better to not use any extension
claiming that people don't have to know that the script is Perl or whatever?
6. Your print code looks ok, so perhaps the trouble is in your (pound bang)
line? Like you, mine is:
#!/usr/bin/perl
But perhaps you require it like this: (user) instead of (usr)???
#!/user/bin/perl
7. Are you sure your system supports Perl? If so, check if there are some
default Perl scripts in the /cgi-bin folder and check if they work, and if
they do, start with them.
Finally, I'm quite new to this group and Perl so I expect to be corrected
here!
PS. I recently learned that instead of uploading my scripts to test them, I
could install Strawberry Perl on my Windows XP and test my scripts locally.
I upload them to the server only once the bugs are out.
Cheers,
Guy D.
------------------------------
Date: Tue, 9 Jun 2009 20:39:55 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: perl and CGI
Message-Id: <slrnh2u3nb.llm.tadmc@tadmc30.sbcglobal.net>
Guy <someone@somewhere.nb.ca> wrote:
>
> "Vit" <FiNaR76@gmail.com> wrote:
> Hi All,
>
> I'm new to the perl language....
[ snip quoted text with no quote marks ]
> -----------------------------
> Did you solve your problem?
[ snip original text, but how can anybody tell that it is not quoted? ]
Please learn the proper way of composing a followup.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 9 Jun 2009 20:43:42 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: perl and CGI
Message-Id: <slrnh2u3ue.llm.tadmc@tadmc30.sbcglobal.net>
Guy <someone@somewhere.nb.ca> wrote:
> it would be great if I had Perl 10
There is no Perl 10.
There isn't even a Perl 6 (just yet).
It would be great if you had Perl 5.10.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 10 Jun 2009 03:28:07 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl and CGI
Message-Id: <nai3g6-4ag1.ln1@osiris.mauzo.dyndns.org>
Quoth "Guy" <someone@somewhere.nb.ca>:
>
> It displays the following -- yes I know it would be great if I had Perl 10
> :(
[damn, Tad's already pointed out the error... :)]
> Perl Version
> Perl version : 5.006001
Never mind about 5.10: that's merely good-to-have at this point. You
*need* to be using at least 5.8.5, and preferably 5.8.8 or .9.
5.6.1 was released over eight years ago. There have been twelve stable
releases of perl since then (5.6.2, 5.8.0-9, 5.10.0). If your webhost
only provides 5.6.1, you need to get a new webhost.
> But perhaps you require it like this: (user) instead of (usr)???
> #!/user/bin/perl
Are you just making things up at this point?
> Finally, I'm quite new to this group and Perl so I expect to be corrected
> here!
If you expect your answers to be wrong, it's best to keep quiet until
you know enough to be sure you are right. There's more than enough bad
Perl advice on the Intarwebs already, we don't need more of it in here.
Ben
------------------------------
Date: Tue, 9 Jun 2009 20:12:18 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: understanding \Q \E
Message-Id: <4a2eec40$0$23750$9a566e8b@news.aliant.net>
I bought the 3 books: Learning Perl, Intermediate Perl, Mastering Perl, and
what I've read is great. But the only info I've found so far on \Q \E is on
page 24 of Learning Perl which says "Quote non-word characters by adding a
backslash until \E." Does this mean metacharacters?
And I read on http://www.informit.com/articles/article.aspx?p=24468
that the full list of metacharacters is \, |, ^, $, *, +, ?, ., (, ), [, {
So I wrote the following lines to see the results, but I don't seem to grasp
what is happening and what makes \Q \E useful. You may want to ignore the
<BR> as in my case I am printing to HTML.
my $str1 = "\a|a^a$a*a+a?a.a(a)a[a{a";
my $str2 = "\Q\a|a^a$a*a+a?a.a(a)a[a{a\E";
my $str3 = "\\Q\a|a^a$a*a+a?a.a(a)a[a{a\\E";
print "</CENTER>";
print '\a|a^a$a*a+a?a.a(a)a[a{a<BR>'; # the original string
print "$str1 <BR>";
print "$str2 <BR>";
print "$str3 <BR>";
This is the results.
\a|a^a$a*a+a?a.a(a)a[a{a
|a^a*a+a?a.a(a)a[a{a
\\|a\^a\*a\+a\?a\.a\(a\)a\[a\{a
\Q|a^a*a+a?a.a(a)a[a{a\E
Can someone show me a useful example of \Q \E ? All info is appreciated.
Guy D
------------------------------
Date: Wed, 10 Jun 2009 00:55:03 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: understanding \Q \E
Message-Id: <nb93g6-9df1.ln1@osiris.mauzo.dyndns.org>
Quoth "Guy" <someone@somewhere.nb.ca>:
> I bought the 3 books: Learning Perl, Intermediate Perl, Mastering Perl, and
> what I've read is great. But the only info I've found so far on \Q \E is on
> page 24 of Learning Perl which says "Quote non-word characters by adding a
> backslash until \E." Does this mean metacharacters?
Specifically, it means everything except letters and numbers.
> And I read on http://www.informit.com/articles/article.aspx?p=24468
> that the full list of metacharacters is \, |, ^, $, *, +, ?, ., (, ), [, {
Assuming you mean regex metacharacters, a better place to look would be
perldoc perlreref. Relying on random web pages rather than the real
documentation is a bad idea for any programming language, but
particularly so for Perl. There's an awful lot of rubbish out there
about Perl, unfortunately.
> So I wrote the following lines to see the results, but I don't seem to grasp
> what is happening and what makes \Q \E useful. You may want to ignore the
> <BR> as in my case I am printing to HTML.
Does this mean you are running programs as CGI scripts? This is a bad
idea while you are just learning the language. Get a copy of perl for
your machine and do your experimenting locally: for Windows, you can get
perl from strawberryperl.com, and other systems (including Mac OS) will
usually have perl installed already.
> my $str1 = "\a|a^a$a*a+a?a.a(a)a[a{a";
> my $str2 = "\Q\a|a^a$a*a+a?a.a(a)a[a{a\E";
> my $str3 = "\\Q\a|a^a$a*a+a?a.a(a)a[a{a\\E";
> print "</CENTER>";
> print '\a|a^a$a*a+a?a.a(a)a[a{a<BR>'; # the original string
> print "$str1 <BR>";
> print "$str2 <BR>";
> print "$str3 <BR>";
>
> This is the results.
> \a|a^a$a*a+a?a.a(a)a[a{a
> |a^a*a+a?a.a(a)a[a{a
> \\|a\^a\*a\+a\?a\.a\(a\)a\[a\{a
> \Q|a^a*a+a?a.a(a)a[a{a\E
Is there anything specific you don't understand here? Note that "\a"
will give a literal ASCII BEL character (character number 7, sometimes
represented as control-G), which Perl considers to be non-alphanumeric,
so "\Q\a\E" gives a backslash followed by a BEL. If you wanted a literal
backslash in your string, you would have to write "\\a".
See "Quote and Quote-like Operators" in perldoc perlop for the full list
of escapes in double-quoted strings (if you haven't already).
> Can someone show me a useful example of \Q \E ? All info is appreciated.
It's useful for situations like this:
my $str = "a+b";
if ($str =~ /$str/) {
print "matched";
}
else {
print "no match";
}
As written this doesn't match, since the '+' is treated as a
metacharacter and the pattern will match strings like 'ab', 'aab', etc.
If you change the pattern to
/\Q$str\E/
though, it *will* match, since the '+' gets quoted. In general, whenever
you are interpolating variables into regexes that should be treated as
literal strings, you need to use \Q. This is *particularly* important
when interpolating strings that came from user input.
It is guaranteed, in all versions of Perl past, present and future, that
any non-backslashed alphanumeric and any backslashed non-alphanumeric
will always literally match itself (also, that '_' and '\_' both match a
literal '_', to avoid confusion about whether it's alphanumeric or not).
This means, if you are unsure about whether a given character needs
escaping or not, there is a very simple rule to follow: if it's
alphanumeric, leave it alone; if it's not, give it a backslash. It also
means you can see immediately that sequences like '\s' and '\Q' are
magic, and sequences like '\{' and '\<' are not. (That last doesn't
actually need the backslash, but it does no harm.)
Ben
------------------------------
Date: Tue, 9 Jun 2009 17:26:45 -0700 (PDT)
From: Anonymous <derykus@gmail.com>
Subject: Re: understanding \Q \E
Message-Id: <b36ac9ce-2ad2-4cd1-ab05-0eadb4f0c2e0@l28g2000vba.googlegroups.com>
On Jun 9, 4:12=A0pm, "Guy" <some...@somewhere.nb.ca> wrote:
> I bought the 3 books: Learning Perl, Intermediate Perl, Mastering Perl, a=
nd
> what I've read is great. But the only info I've found so far on \Q \E is =
on
> page 24 of Learning Perl which says "Quote non-word characters by adding =
a
> backslash until \E." =A0Does this mean metacharacters?
>
> And I read onhttp://www.informit.com/articles/article.aspx?p=3D24468
> that the full list of metacharacters is \, |, ^, $, *, +, ?, ., (, ), [, =
{
>
> So I wrote the following lines to see the results, but I don't seem to gr=
asp
> what is happening and what makes \Q \E useful. You may want to ignore the
> <BR> as in my case I am printing to HTML.
> =A0 =A0 my $str1 =3D "\a|a^a$a*a+a?a.a(a)a[a{a";
> =A0 =A0 my $str2 =3D "\Q\a|a^a$a*a+a?a.a(a)a[a{a\E";
> =A0 =A0 my $str3 =3D "\\Q\a|a^a$a*a+a?a.a(a)a[a{a\\E";
> =A0 =A0 print "</CENTER>";
> =A0 =A0 print '\a|a^a$a*a+a?a.a(a)a[a{a<BR>'; =A0 =A0# the original strin=
g
> =A0 =A0 print "$str1 <BR>";
> =A0 =A0 print "$str2 <BR>";
> =A0 =A0 print "$str3 <BR>";
>
> This is the results.
> =A0 =A0 \a|a^a$a*a+a?a.a(a)a[a{a
> =A0 =A0 =A0|a^a*a+a?a.a(a)a[a{a
> =A0 =A0 \ \|a\^a\*a\+a\?a\.a\(a\)a\[a\{a
> =A0 =A0 \Q |a^a*a+a?a.a(a)a[a{a\E
>
> Can someone show me a useful example of \Q \E ? All info is appreciated.
>
One scenario: a search function that scans a document with a regex
and incorporates user inputs. If the user wants to see
if there's a '$foo' in section 2, then any regex metacharacters (such
as '$') in the user's input will need to be escaped.
$user_input =3D '$foo';
$regex =3D qr/^section 2.*?\Q$user_input\E.*?^section 3/ms;
if ($doc =3D~ $regex) {
...
--
Charles DeRykus
------------------------------
Date: Tue, 9 Jun 2009 21:43:50 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: understanding \Q \E
Message-Id: <4a2f01b3$0$23755$9a566e8b@news.aliant.net>
"Ben Morrow" <ben@morrow.me.uk> wrote:
>
> Quoth "Guy" <someone@somewhere.nb.ca>:
[SNIP]
> Does this mean you are running programs as CGI scripts? This is a bad
> idea while you are just learning the language. Get a copy of perl for
> your machine and do your experimenting locally: for Windows, you can get
> perl from strawberryperl.com, and other systems (including Mac OS) will
> usually have perl installed already.
I do have Strawberry Perl, and yes it would have made more sense to test it
locally, and no I don't know why I was uploading to the server to test, and
yes I feel stupid now :O
[SNIP]
> See "Quote and Quote-like Operators" in perldoc perlop for the full list
> of escapes in double-quoted strings (if you haven't already).
> Ben
A lot of people refer to perldoc but I don't know how to access this. Is
this a website or did it install with Strawberry Perl, or is it on the
server?
I can access the version of perl by doing system 'perl -v'; This also says
"Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'." I've tried system
'perldoc'; but that didn't show anything.
Thanks,
Guy
------------------------------
Date: Tue, 9 Jun 2009 20:01:19 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: understanding \Q \E
Message-Id: <slrnh2u1ev.kpr.tadmc@tadmc30.sbcglobal.net>
Guy <someone@somewhere.nb.ca> wrote:
> page 24 of Learning Perl which says "Quote non-word characters by adding a
> backslash until \E." Does this mean metacharacters?
No, it means non-word characters.
> And I read on http://www.informit.com/articles/article.aspx?p=24468
> that the full list of metacharacters is \, |, ^, $, *, +, ?, ., (, ), [, {
That is not a list of metacharacters in a string, that is a list
of metacharacters in a regular expression.
Hyphen is not a regex metacharacter (it _is_ a Perl metacharacter,
it is also meta in character classes) but it is a non-word character.
Space is not a regex metacharacter but it is a non-word character.
And they are both "quoted" (backslashed) by \Q
my $str1 = "a hyphenated-string";
print "$str1\n";
print "\Q$str1", "\n";
There is a named function that does what \Q does in strings:
perldoc -f quotemeta
This code makes the 2 more lines of output that are the same
as the last line of code above:
print quotemeta($str1), "\n";
$str1 =~ s/(\W)/\\$1/g;
print "$str1\n";
> So I wrote the following lines to see the results, but I don't seem to grasp
> what is happening and what makes \Q \E useful.
It is most useful when using regular expressions rather than
simple quoted strings.
>You may want to ignore the
><BR> as in my case I am printing to HTML.
You may want to convert your <BR> to \n before posting,
as nobody but you will be printing to HTML.
(because it a is foolish approach to figuring out what is going on.
eg: Why does my HTML look like this "a sentence" when my code is
print "a sentence";
?
Why did Perl delete all those spaces?
A: Perl did not delete any spaces.
)
You are once again demonstrating a lack of regard for us.
Should one person change the <BR> to \n or should that one person
just leave it, and let the dozens of other people that are being
asked to do you a favor convert them?
Is your time more valuable than the time of dozens/hundreds of us?
> my $str1 = "\a|a^a$a*a+a?a.a(a)a[a{a";
^^
^^
You should always enable warnings when developing Perl code!
> my $str2 = "\Q\a|a^a$a*a+a?a.a(a)a[a{a\E";
> my $str3 = "\\Q\a|a^a$a*a+a?a.a(a)a[a{a\\E";
> print "</CENTER>";
> print '\a|a^a$a*a+a?a.a(a)a[a{a<BR>'; # the original string
> print "$str1 <BR>";
> print "$str2 <BR>";
> print "$str3 <BR>";
>
> This is the results.
No it isn't.
This is the results:
</CENTER>\a|a^a$a*a+a?a.a(a)a[a{a<BR>|a^a*a+a?a.a(a)a[a{a <BR>\\|a\^a\*a\+a\?a\.a\(a\)a\[a\{a <BR>\Q|a^a*a+a?a.a(a)a[a{a\E <BR>
> \a|a^a$a*a+a?a.a(a)a[a{a
> |a^a*a+a?a.a(a)a[a{a
> \\|a\^a\*a\+a\?a\.a\(a\)a\[a\{a
> \Q|a^a*a+a?a.a(a)a[a{a\E
Your code has
print "</CENTER>";
in it. Did that print statement fail?
> Can someone show me a useful example of \Q \E ?
It is useful when your pattern contains a regex metacharacter
that you want to match literally:
------------------
#!/usr/bin/perl
use warnings;
use strict;
my $str = 'fooxhtml';
print "matched\n" if $str =~ /foo.html/; # Oops!
print "matched again\n" if $str =~ /\Qfoo.html/;
my $url = 'http://www.informit.com/articles/article.aspx?p=24468';
print "matched url\n" if $url =~ /aspx?p/; # Oops!
print "matched url again\n" if $url =~ /\Qaspx?p/;
------------------
It saves you from having to do the backslashing yourself.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 9 Jun 2009 22:38:57 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: understanding \Q \E
Message-Id: <4a2f0e9e$0$23753$9a566e8b@news.aliant.net>
"Tad J McClellan" <tadmc@seesig.invalid> wrote:
> Guy <someone@somewhere.nb.ca> wrote:
>
>
>> page 24 of Learning Perl which says "Quote non-word characters by adding
>> a
>> backslash until \E." Does this mean metacharacters?
>
>
> No, it means non-word characters.
>
>
>> And I read on http://www.informit.com/articles/article.aspx?p=24468
>> that the full list of metacharacters is \, |, ^, $, *, +, ?, ., (, ), [,
>> {
>
>
> That is not a list of metacharacters in a string, that is a list
> of metacharacters in a regular expression.
>
> Hyphen is not a regex metacharacter (it _is_ a Perl metacharacter,
> it is also meta in character classes) but it is a non-word character.
>
> Space is not a regex metacharacter but it is a non-word character.
>
> And they are both "quoted" (backslashed) by \Q
>
> my $str1 = "a hyphenated-string";
> print "$str1\n";
> print "\Q$str1", "\n";
>
> There is a named function that does what \Q does in strings:
>
> perldoc -f quotemeta
>
> This code makes the 2 more lines of output that are the same
> as the last line of code above:
>
> print quotemeta($str1), "\n";
>
> $str1 =~ s/(\W)/\\$1/g;
> print "$str1\n";
>
>
>> So I wrote the following lines to see the results, but I don't seem to
>> grasp
>> what is happening and what makes \Q \E useful.
>
>
> It is most useful when using regular expressions rather than
> simple quoted strings.
>
>
>>You may want to ignore the
>><BR> as in my case I am printing to HTML.
>
>
> You may want to convert your <BR> to \n before posting,
> as nobody but you will be printing to HTML.
>
> (because it a is foolish approach to figuring out what is going on.
> eg: Why does my HTML look like this "a sentence" when my code is
> print "a sentence";
> ?
>
> Why did Perl delete all those spaces?
>
> A: Perl did not delete any spaces.
> )
>
> You are once again demonstrating a lack of regard for us.
>
> Should one person change the <BR> to \n or should that one person
> just leave it, and let the dozens of other people that are being
> asked to do you a favor convert them?
>
> Is your time more valuable than the time of dozens/hundreds of us?
I understand exactly and totally agree with that but honestly didn't realize
it as I was cutting and pasting. I'm sincerely sorry... again.
>> my $str1 = "\a|a^a$a*a+a?a.a(a)a[a{a";
> ^^
> ^^
>
> You should always enable warnings when developing Perl code!
>
>
>> my $str2 = "\Q\a|a^a$a*a+a?a.a(a)a[a{a\E";
>> my $str3 = "\\Q\a|a^a$a*a+a?a.a(a)a[a{a\\E";
>> print "</CENTER>";
>> print '\a|a^a$a*a+a?a.a(a)a[a{a<BR>'; # the original string
>> print "$str1 <BR>";
>> print "$str2 <BR>";
>> print "$str3 <BR>";
>>
>> This is the results.
>
> No it isn't.
>
> This is the results:
>
> </CENTER>\a|a^a$a*a+a?a.a(a)a[a{a<BR>|a^a*a+a?a.a(a)a[a{a
> <BR>\\|a\^a\*a\+a\?a\.a\(a\)a\[a\{a <BR>\Q|a^a*a+a?a.a(a)a[a{a\E <BR>
Again, I see what you mean by including HTML stuff here.
>> \a|a^a$a*a+a?a.a(a)a[a{a
>> |a^a*a+a?a.a(a)a[a{a
>> \\|a\^a\*a\+a\?a\.a\(a\)a\[a\{a
>> \Q|a^a*a+a?a.a(a)a[a{a\E
>
>
> Your code has
>
> print "</CENTER>";
>
> in it. Did that print statement fail?
Just in case this wasn't a retorical question, it didn't appear to fail, not
from the server and not from my local Strawberry perl.
>> Can someone show me a useful example of \Q \E ?
>
>
> It is useful when your pattern contains a regex metacharacter
> that you want to match literally:
>
> ------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $str = 'fooxhtml';
> print "matched\n" if $str =~ /foo.html/; # Oops!
> print "matched again\n" if $str =~ /\Qfoo.html/;
>
> my $url = 'http://www.informit.com/articles/article.aspx?p=24468';
> print "matched url\n" if $url =~ /aspx?p/; # Oops!
> print "matched url again\n" if $url =~ /\Qaspx?p/;
> ------------------
>
> It saves you from having to do the backslashing yourself.
Thanks for all Tad,
Guy D.
------------------------------
Date: Tue, 9 Jun 2009 20:34:49 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: understanding \Q \E
Message-Id: <slrnh2u3dp.llm.tadmc@tadmc30.sbcglobal.net>
Guy <someone@somewhere.nb.ca> wrote:
> A lot of people refer to perldoc but I don't know how to access this.
A lot (most, in fact) of Perl programmers use Perl on *nix, so they
are used to accessing it by typing into the command line exactly what
you usually see posted (which is why it is posted that way).
eg. Most folks see Perl's std docs by typing:
perldoc -f quotemeta
at a shell prompt.
The important part to get here, is that when they say
perldoc -f quotemeta
it is a short-hand for:
you should read the description of the quotemeta function
in Perl's standard documentation.
How you do that on your system is system-specific.
> Is
> this a website
No, the standard Perl docs are part of a normal perl distribution.
That is, they are normally installed along with perl itself.
> or did it install with Strawberry Perl,
I do not use Strawberry Perl, so I can't help you with that part.
> or is it on the
> server?
If it is a *nix server and it is configured properly, then yes,
the standard Perl docs should be on your server.
Do you have command line access to your (web, I assume) server?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 9 Jun 2009 20:23:49 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: understanding \Q \E
Message-Id: <slrnh2u2p5.llm.tadmc@tadmc30.sbcglobal.net>
Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth "Guy" <someone@somewhere.nb.ca>:
>> And I read on http://www.informit.com/articles/article.aspx?p=24468
>> that the full list of metacharacters is \, |, ^, $, *, +, ?, ., (, ), [, {
>
> Assuming you mean regex metacharacters, a better place to look would be
> perldoc perlreref. Relying on random web pages rather than the real
> documentation is a bad idea for any programming language, but
> particularly so for Perl. There's an awful lot of rubbish out there
> about Perl, unfortunately.
I was going to say something similar...
... until I looked at the byline on that page.
Clinton is a Real Perl Programmer, so in this case it isn't the
usual "random" web page we usually see referred to here...
It is so important, let me say it yet again, since repetition is
the key to learning.
The standard Perl docs are better than web pages.
The standard Perl docs are better than books.
In this case, most especially when what you need is of a "reference"
nature rather than a "tutorial" nature.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 09 Jun 2009 18:48:46 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: understanding \Q \E
Message-Id: <ip3u25tiqb8pr18prsjb2oc8jvvbplm4rk@4ax.com>
"Guy" <someone@somewhere.nb.ca> wrote:
>A lot of people refer to perldoc but I don't know how to access this. Is
>this a website or did it install with Strawberry Perl, or is it on the
>server?
perldoc is a standard part of any perl installation and you can access
it by simply typing the command
perldoc
plus the appropriate arguments on the command line. Try
perldoc perldoc
for an overview of what options are available.
If your installation of perl is missing perldoc then either the
installation is broken (you may want to fix it) or it is a stripped-down
special use version for e.g. a server where documentation would be of no
use because nobody would be using it to develop programs on it..
jue
------------------------------
Date: Tue, 09 Jun 2009 18:52:51 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: understanding \Q \E
Message-Id: <kd4u255tdlu6vq69utilsmd2s5ob5ht8i8@4ax.com>
Tad J McClellan <tadmc@seesig.invalid> wrote:
>Guy <someone@somewhere.nb.ca> wrote:
>
>> A lot of people refer to perldoc but I don't know how to access this.
>
>A lot (most, in fact) of Perl programmers use Perl on *nix, so they
>are used to accessing it by typing into the command line exactly what
>you usually see posted (which is why it is posted that way).
>
>eg. Most folks see Perl's std docs by typing:
>
> perldoc -f quotemeta
>
>at a shell prompt.
Just for reference: it works exactly the same way from a MS Windows
command line, too.
jue
------------------------------
Date: Wed, 10 Jun 2009 03:14:16 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: understanding \Q \E
Message-Id: <ogh3g6-4ag1.ln1@osiris.mauzo.dyndns.org>
Quoth "Guy" <someone@somewhere.nb.ca>:
>
> I do have Strawberry Perl, and yes it would have made more sense to test it
<snip>
>
> A lot of people refer to perldoc but I don't know how to access this. Is
> this a website or did it install with Strawberry Perl, or is it on the
> server?
It's installed with Perl (any non-broken install of perl will include
the docs).
> I can access the version of perl by doing system 'perl -v'; This also says
> "Complete documentation for Perl, including FAQ lists, should be found on
> this system using `man perl' or `perldoc perl'." I've tried system
> 'perldoc'; but that didn't show anything.
Um... how on earth are you running your Perl scripts, if you think you
need to use system (from within Perl) to run perl -v?
Open a Command Prompt window. Run
perl -V
to make sure perl is in your PATH. If it isn't, run
set PATH=c:\strawberry\perl\bin;c:\strawberry\c\bin;c:\windows\system32
and/or fix your default PATH environment variable. Then run
perldoc perlop
The default pager (more.com) is pretty limited (you can't go backwards,
for instance, and I don't think you can search), but I leave finding and
installing a better one up to you.
There is also perldoc.perl.org, but it only covers perl core
documentation (not installed modules) and you need to be careful to
choose the correct version of perl.
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2467
***************************************