[30638] in Perl-Users-Digest
Perl-Users Digest, Issue: 1883 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 27 16:09:53 2008
Date: Sat, 27 Sep 2008 13:09:19 -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 Sat, 27 Sep 2008 Volume: 11 Number: 1883
Today's topics:
$current_path=`echo $cwd` does not work <chen_zhitao@yahoo.com>
Re: $current_path=`echo $cwd` does not work <jurgenex@hotmail.com>
Re: $current_path=`echo $cwd` does not work <rkb@i.frys.com>
Re: $current_path=`echo $cwd` does not work <john@castleamber.com>
Any thoughts on catalyst? <walterbyrd@iname.com>
Re: How to unable the use of tainted mode in a CGI scri <tim@burlyhost.com>
Newlines on Windows <void.no.spam.com@gmail.com>
Re: Newlines on Windows <chaff@t-online.de>
Re: Newlines on Windows <jurgenex@hotmail.com>
Re: Newlines on Windows <void.no.spam.com@gmail.com>
Re: Newlines on Windows <tim@burlyhost.com>
Re: Newlines on Windows <bjoern@hoehrmann.de>
sprintf doesn't round correctly? <void.no.spam.com@gmail.com>
Re: sprintf doesn't round correctly? <chaff@t-online.de>
Re: sprintf doesn't round correctly? <void.no.spam.com@gmail.com>
Re: sprintf doesn't round correctly? <jurgenex@hotmail.com>
Re: sprintf doesn't round correctly? <joost@zeekat.nl>
Re: sprintf doesn't round correctly? <void.no.spam.com@gmail.com>
Re: sprintf doesn't round correctly? <jurgenex@hotmail.com>
Re: Terminate the entire Perl script when control_C in <chen_zhitao@yahoo.com>
What does m@ stand for in the following regular express <cdalten@gmail.com>
Re: What does m@ stand for in the following regular exp <bjoern@hoehrmann.de>
Re: What does m@ stand for in the following regular exp <jurgenex@hotmail.com>
Re: What does m@ stand for in the following regular exp <tim@burlyhost.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Sep 2008 07:10:15 -0700 (PDT)
From: Kuhl <chen_zhitao@yahoo.com>
Subject: $current_path=`echo $cwd` does not work
Message-Id: <f1390fcb-c833-4019-a813-19a4ab719704@l33g2000pri.googlegroups.com>
Hi, all:
Backticks `` are supposed to be able to transfer the result of shell
commands to Perl variable.
But it's very confusing that it does not behave in the way that I
think it should do.
$current_path=`pwd`; This works.
$current_path=`echo $cwd`; This does not work.
But in fact, pwd is aliased to echo $cwd. Details see below.
What's the issue? How to fix it?
Thanks.
# which pwd
pwd: aliased to echo $cwd
# pwd
/home/user/shell
# echo $cwd
/home/user/shell
#!/usr/bin/perl
$current_path=`pwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`echo $cwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`echo \$cwd`;
print "\nCurrent path is $current_path .\n";
$current_path=`"echo $cwd"`;
print "\nCurrent path is $current_path .\n";
exit 0;
But the result of this script is:
Current path is /home/user/shell
.
Current path is
.
Current path is
.
sh: line 1: echo : command not found
Current path is .
#
------------------------------
Date: Sat, 27 Sep 2008 07:56:38 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: $current_path=`echo $cwd` does not work
Message-Id: <p6hsd4tf5vqarlilkairpqsdac5cvsr1t3@4ax.com>
Kuhl <chen_zhitao@yahoo.com> wrote:
>Hi, all:
>
>Backticks `` are supposed to be able to transfer the result of shell
>commands to Perl variable.
>But it's very confusing that it does not behave in the way that I
>think it should do.
>
>$current_path=`pwd`; This works.
>$current_path=`echo $cwd`; This does not work.
>
>But in fact, pwd is aliased to echo $cwd. Details see below.
A guess: those aliases are not valid in your _system_ shell but only in
the shell that you are using as your standard shell from the command
line?
Try calling print `alias` to find out, if those aliases are even
defined.
jue
------------------------------
Date: Sat, 27 Sep 2008 08:29:40 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: $current_path=`echo $cwd` does not work
Message-Id: <89d66844-a7d8-4b4a-b570-cad8feef6b31@a3g2000prm.googlegroups.com>
On Sep 27, 7:10 am, Kuhl <chen_zhi...@yahoo.com> wrote:
> Hi, all:
>
> Backticks `` are supposed to be able to transfer the result of shell
> commands to Perl variable.
> But it's very confusing that it does not behave in the way that I
> think it should do.
>
> $current_path=`pwd`; This works.
> $current_path=`echo $cwd`; This does not work.
>
$cwd is being seen as a Perl scalar that is interpolated by Perl
before passing it to the shell...you need to escape it.
$current_path=`echo \$cwd`;
------------------------------
Date: 27 Sep 2008 16:34:34 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: $current_path=`echo $cwd` does not work
Message-Id: <Xns9B2675C3323E9castleamber@130.133.1.4>
Kuhl <chen_zhitao@yahoo.com> wrote:
> Hi, all:
>
> Backticks `` are supposed to be able to transfer the result of shell
> commands to Perl variable.
> But it's very confusing that it does not behave in the way that I
> think it should do.
>
> $current_path=`pwd`; This works.
> $current_path=`echo $cwd`; This does not work.
[..]
> #!/usr/bin/perl
use strict;
use warnings;
and all becomes clear. It does work, you only misunderstand ``.
There is a very good reason why those two lines are recommended daily in
this group.
--
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
------------------------------
Date: Sat, 27 Sep 2008 08:38:15 -0700 (PDT)
From: walterbyrd <walterbyrd@iname.com>
Subject: Any thoughts on catalyst?
Message-Id: <46918cde-17d1-4c49-8c57-64a6a43dfdd2@b2g2000prf.googlegroups.com>
When I google catalyst vs whatever, I keep getting pages of hits about
some benchmark test.
IMO: execution speed is important, but it is not the only thing in the
world. I am also interested in speed of development, ease of learning,
availability of hosting, documentation, community and so on.
I barely use perl, and I have never used catalyst. But one thing that
concerns me is that CPAN seems overwhelming. There are so many modules
that seem to do the same thing, or nearly the same thing, and I
understand it, some modules work much better than others.
Any thoughts appreciated, thanks.
------------------------------
Date: Sat, 27 Sep 2008 11:45:27 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: How to unable the use of tainted mode in a CGI script ?
Message-Id: <ebvDk.28$Ra2.19@newsfe06.iad>
Azol wrote:
> In article <r59Dk.75755$PK.65320@newsfe04.iad>, tim@burlyhost.com
> says...
>> Where is your log directory? Are you looking for the error log in
>> the
>> log directory for the web server? A lot of hosts have individual
>> directories for user's domain logs, or one central location, while
>> the actual error logs are usually still located in the standard log
>> location for the web service (wherever that might be, depending on
>> their configuration and type of service). Ask your host if you're
>> unsure.
>
> OK, not any error.log in my account... I ask the support about this.
> Thanks for your advice, Tim.
>
>>
>> By the way, that access log alone showed a 200 response, rather than
>> a 500 response, so it made it appear as though, from the access log
>> standpoint anyway, that it's working (this is why you need to locate
>> and show the associated log entry from the error log, when you test
>> the
>> script and have it fail). Did you ask your host to clarify how/why
>> Taint isn't working?
>>
>
> Here is the reply from the hoster's support (in French) :
>
> "Nous vous informons qu'il ne sera pas possible d'utiliser cette
> fonction sur de l'hébergement mutualisé. Vous devez pour cela vous
> tourner vers les offres de serveurs privés, ou l'accès Root vous
> permettra d'installer ce type de script."
>
> In English, it's something like :
>
> "We inform you that it will be not possible to use this function in a
> mutualised hosting. You must go to the private or dedicated servers
> offers, where the root access will alow you this kind of script"
>
> oops :(
That is unfortunate, and wrong. I suggest you start looking for a
hosting provider that has a better idea of how this works. After all,
it's only to their advantage (and yours), to offer features that catch
a lot of potential mistakes in user's codes (that can ultimately save
their clients (and them) a lot of headaches about abuse reports). For
example, if some client has their script exploited, because the host
didn't allow their users to add some common and simple checks to
alert/warn or error when there's a significant goof in the code is
seen. Strange. I'd convey those concerns to them, if nothing else.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Sat, 27 Sep 2008 11:52:30 -0700 (PDT)
From: "void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com>
Subject: Newlines on Windows
Message-Id: <c10c92c6-a9c1-450e-a137-3ecdb03a9605@m45g2000hsb.googlegroups.com>
I thought that on Windows, if you want to output a carriage return,
you have to use \r\n instead of just \n. So in my perl script that
generates a file, I put a \r\n after every line, but when I open the
file in an editor, I see a ^M after each line. This is with
ActivePerl 5.8.8.
------------------------------
Date: Sat, 27 Sep 2008 21:33:29 +0200
From: Chris Haffenstedt <chaff@t-online.de>
Subject: Re: Newlines on Windows
Message-Id: <gbm1q6$hq$1@newsreader2.netcologne.de>
void.no.spam.com@gmail.com schrieb:
> I thought that on Windows, if you want to output a carriage return,
> you have to use \r\n instead of just \n.
So it's like in PHP. In Perl you haven't to do so. Just use \n and Perl
takes care for the rest, on Windows, Linux, Macintosh and all the rest.
------------------------------
Date: Sat, 27 Sep 2008 12:34:58 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Newlines on Windows
Message-Id: <v22td4ter0sj1cih43k3muiej6a4569kv7@4ax.com>
"void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com> wrote:
>I thought that on Windows, if you want to output a carriage return,
>you have to use \r\n instead of just \n.
Neither nor. You are confusing two different layers.
To output a carriage return you have to print the ASCII controll
character 13 (DEZ) or 0x0D (HEX) or short "\r". That is by definition
the CR character for ASCII which in turn is a subset of Windows-1252,
ISO-Latin-1, and many other encodings.
"\n" on the other hand in Perl is a logical line end, which will be
translated automatically into the correct line end sequence for the
current OS, be it 0x0A for unixoide OSes, 0x0A 0x0D for Windows, or 0x0D
for Mac.
So your combination \r\n on Windows will result in 0x0D 0X0A 0x0D.
Probably not what you want.
> So in my perl script that
>generates a file, I put a \r\n after every line, but when I open the
>file in an editor, I see a ^M after each line. This is with
Well, you got what you added.
jue
------------------------------
Date: Sat, 27 Sep 2008 12:47:06 -0700 (PDT)
From: "void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com>
Subject: Re: Newlines on Windows
Message-Id: <474c610f-26c2-4e10-ae48-0da0fbc7aef7@26g2000hsk.googlegroups.com>
On Sep 27, 3:34=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> "void.no.spam....@gmail.com" <void.no.spam....@gmail.com> wrote:
> >I thought that on Windows, if you want to output a carriage return,
> >you have to use \r\n instead of just \n.
>
> Neither nor. You are confusing two different layers.
>
> To output a carriage return you have to print the ASCII controll
> character 13 (DEZ) or 0x0D (HEX) or short "\r". That is by definition
> the CR character for ASCII which in turn is a subset of Windows-1252,
> ISO-Latin-1, and many other encodings.
>
> "\n" on the other hand in Perl is a logical line end, which will be
> translated automatically into the correct line end sequence for the
> current OS, be it 0x0A for unixoide OSes, 0x0A 0x0D for Windows, or 0x0D
> for Mac.
>
> So your combination \r\n on Windows will result in 0x0D 0X0A 0x0D.
> Probably not what you want.
>
> > So in my perl script that
> >generates a file, I put a \r\n after every line, but when I open the
> >file in an editor, I see a ^M after each line. =A0This is with
>
> Well, you got what you added.
>
> jue
Thanks for the explanation.
------------------------------
Date: Sat, 27 Sep 2008 12:59:03 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Newlines on Windows
Message-Id: <bgwDk.6053$M_7.3185@newsfe03.iad>
void.no.spam.com@gmail.com wrote:
> I thought that on Windows, if you want to output a carriage return,
> you have to use \r\n instead of just \n. So in my perl script that
> generates a file, I put a \r\n after every line, but when I open the
> file in an editor, I see a ^M after each line. This is with
> ActivePerl 5.8.8.
This is an issue with what you use to edit the file. It's inserting
hidden line feed characters (junk) in the script.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Sat, 27 Sep 2008 22:06:40 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Newlines on Windows
Message-Id: <gg4td4tmvrg631hoiviggibvd0upimtujk@hive.bjoern.hoehrmann.de>
* void.no.spam.com@gmail.com wrote in comp.lang.perl.misc:
>I thought that on Windows, if you want to output a carriage return,
>you have to use \r\n instead of just \n. So in my perl script that
>generates a file, I put a \r\n after every line, but when I open the
>file in an editor, I see a ^M after each line. This is with
>ActivePerl 5.8.8.
See `perldoc perlport` for an in-depth discussion of line endings.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
------------------------------
Date: Sat, 27 Sep 2008 12:30:13 -0700 (PDT)
From: "void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com>
Subject: sprintf doesn't round correctly?
Message-Id: <f0ed21ad-046c-4ea6-b7c2-e0ecc33e19df@a1g2000hsb.googlegroups.com>
Hi, I have the following code, where the multiplication results in a
dollar amount which needs to be rounded to the nearest cent.
$a = sprintf("%.2f", 1900*18.12895);
print $a;
The multiplication yields the value 34445.005, which should be rounded
up to 34445.01, but perl says that $a has the value 34445.00. Why is
it exhibiting this behavior?
------------------------------
Date: Sat, 27 Sep 2008 21:38:26 +0200
From: Chris Haffenstedt <chaff@t-online.de>
Subject: Re: sprintf doesn't round correctly?
Message-Id: <gbm23f$hq$2@newsreader2.netcologne.de>
void.no.spam.com@gmail.com schrieb:
> Hi, I have the following code, where the multiplication results in a
> dollar amount which needs to be rounded to the nearest cent.
>
> $a = sprintf("%.2f", 1900*18.12895);
> print $a;
>
> The multiplication yields the value 34445.005, which should be rounded
> up to 34445.01, but perl says that $a has the value 34445.00. Why is
> it exhibiting this behavior?
sprintf doesn't round at all. In your example, you get the result of
your multiplication, and after that, sprintf gives you the result with
the two digits after the ".".
More about rounding in Perl:
http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
------------------------------
Date: Sat, 27 Sep 2008 12:43:30 -0700 (PDT)
From: "void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com>
Subject: Re: sprintf doesn't round correctly?
Message-Id: <8da0ede1-c397-44c4-af0b-e7db653df83b@k7g2000hsd.googlegroups.com>
On Sep 27, 3:38=A0pm, Chris Haffenstedt <ch...@t-online.de> wrote:
> void.no.spam....@gmail.com schrieb:
>
> > Hi, I have the following code, where the multiplication results in a
> > dollar amount which needs to be rounded to the nearest cent.
>
> > $a =3D sprintf("%.2f", 1900*18.12895);
> > print $a;
>
> > The multiplication yields the value 34445.005, which should be rounded
> > up to 34445.01, but perl says that $a has the value 34445.00. =A0Why is
> > it exhibiting this behavior?
>
> sprintf doesn't round at all. In your example, you get the result of
> your multiplication, and after that, sprintf gives you the result with
> the two digits after the ".".
> More about rounding in Perl:http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/=
Q4.13.html
That is not true, because I tried this code:
$a =3D sprintf("%.2f", 3.0051);
print $a;
And it printed out 3.01
------------------------------
Date: Sat, 27 Sep 2008 12:46:06 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: sprintf doesn't round correctly?
Message-Id: <s23td4h82ulcbg7ehiobn9rhcnd8qiruhl@4ax.com>
"void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com> wrote:
>Hi, I have the following code, where the multiplication results in a
>dollar amount which needs to be rounded to the nearest cent.
>
>$a = sprintf("%.2f", 1900*18.12895);
>print $a;
>
>The multiplication yields the value 34445.005,
No, it doesn't. At least not on a typical computer.
>which should be rounded
>up to 34445.01, but perl says that $a has the value 34445.00. Why is
>it exhibiting this behavior?
You must have missed the introductory lesson in the Introduction into
Computer Numerics class.
Try
$a = sprintf("%.20f", 1900*18.12895);
print $a;
and the reason will become obvious (note: 2 replaced with 20 digits).
For a more detailed explanation please see 'perldoc -q 9999'.
jue
------------------------------
Date: Sat, 27 Sep 2008 21:51:47 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: sprintf doesn't round correctly?
Message-Id: <87myhtgyek.fsf@zeekat.nl>
"void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com> writes:
> Hi, I have the following code, where the multiplication results in a
> dollar amount which needs to be rounded to the nearest cent.
>
> $a = sprintf("%.2f", 1900*18.12895);
> print $a;
>
> The multiplication yields the value 34445.005, which should be rounded
> up to 34445.01, but perl says that $a has the value 34445.00. Why is
> it exhibiting this behavior?
The direction of rounding at exactly x.yx5 is debatable. Perl uses
banker's rounding, which rounds towards even:
printf("%1.0f",0.5) => "0"
printf("%1.0f",1.5) => "2"
There are good reasons why it does this for general rounding: the last
time we had this question it turned into a rediculously long discussion.
Just see http://en.wikipedia.org/wiki/Rounding
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Sat, 27 Sep 2008 12:57:07 -0700 (PDT)
From: "void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com>
Subject: Re: sprintf doesn't round correctly?
Message-Id: <a4042a81-6455-49fa-93e5-7cf4091ea818@m36g2000hse.googlegroups.com>
On Sep 27, 3:46=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> "void.no.spam....@gmail.com" <void.no.spam....@gmail.com> wrote:
> >Hi, I have the following code, where the multiplication results in a
> >dollar amount which needs to be rounded to the nearest cent.
>
> >$a =3D sprintf("%.2f", 1900*18.12895);
> >print $a;
>
> >The multiplication yields the value 34445.005,
>
> No, it doesn't. At least not on a typical computer.
>
> >which should be rounded
> >up to 34445.01, but perl says that $a has the value 34445.00. =A0Why is
> >it exhibiting this behavior?
>
> You must have missed the introductory lesson in the Introduction into
> Computer Numerics class.
>
> Try
> =A0 =A0 =A0 =A0 $a =3D sprintf("%.20f", 1900*18.12895);
> =A0 =A0 =A0 =A0 print $a;
> and the reason will become obvious (note: 2 replaced with 20 digits).
>
> For a more detailed explanation please see 'perldoc -q 9999'.
>
> jue
Ah, that explains it. Thanks.
------------------------------
Date: Sat, 27 Sep 2008 13:05:33 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: sprintf doesn't round correctly?
Message-Id: <7d4td4lbs8isq00d73f1naftuvkonfmt0e@4ax.com>
Joost Diepenmaat <joost@zeekat.nl> wrote:
>"void.no.spam.com@gmail.com" <void.no.spam.com@gmail.com> writes:
>
>> Hi, I have the following code, where the multiplication results in a
>> dollar amount which needs to be rounded to the nearest cent.
>>
>> $a = sprintf("%.2f", 1900*18.12895);
>> print $a;
>>
>> The multiplication yields the value 34445.005, which should be rounded
>> up to 34445.01, but perl says that $a has the value 34445.00. Why is
>> it exhibiting this behavior?
>
>The direction of rounding at exactly x.yx5 is debatable. Perl uses
>banker's rounding, which rounds towards even:
This may or may not be the case. Either way it is not the reason for the
OPs problem. He doesn't have a trailing '5' do being with.
jue
------------------------------
Date: Sat, 27 Sep 2008 07:08:20 -0700 (PDT)
From: Kuhl <chen_zhitao@yahoo.com>
Subject: Re: Terminate the entire Perl script when control_C in an application
Message-Id: <d5c47d9c-7404-4520-b1ab-6d732b4ec9dd@i20g2000prf.googlegroups.com>
Hi, thank you everyone. It worked.
if(!$?==0){exit 0;}
------------------------------
Date: Sat, 27 Sep 2008 06:47:14 -0700 (PDT)
From: grocery_stocker <cdalten@gmail.com>
Subject: What does m@ stand for in the following regular expression.
Message-Id: <21d009de-7b8b-47af-b156-099716358217@i76g2000hsf.googlegroups.com>
Given
my ($title) = ($body =~ m@<title>\s*(.*?)\s*</title>@si);
What does m@ do in this case?
------------------------------
Date: Sat, 27 Sep 2008 16:02:28 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: What does m@ stand for in the following regular expression.
Message-Id: <c3fsd4lgdsehr3h20pnlu5m8slf7himor2@hive.bjoern.hoehrmann.de>
* grocery_stocker wrote in comp.lang.perl.misc:
>Given
>
>my ($title) = ($body =~ m@<title>\s*(.*?)\s*</title>@si);
>
>What does m@ do in this case?
The @ serves to delimit the regular expression, m@...@... is the same as
m/.../... except that different characters have to be escaped (using @
as delimiter, / does not have to be escaped inside the expression). m//
in turn is just the longhand for `/.../...`.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
------------------------------
Date: Sat, 27 Sep 2008 07:41:51 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: What does m@ stand for in the following regular expression.
Message-Id: <tdhsd4pvekhrh0mo3afa5qbdo9tr7skunr@4ax.com>
grocery_stocker <cdalten@gmail.com> wrote:
>Given
>
>my ($title) = ($body =~ m@<title>\s*(.*?)\s*</title>@si);
>
>What does m@ do in this case?
As a combination it doesn't do anything.
The m is the match operator (see perldoc perlop).
And the @ is the left delimiter of the following regular expression.
jue
------------------------------
Date: Sat, 27 Sep 2008 11:50:16 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: What does m@ stand for in the following regular expression.
Message-Id: <JfvDk.29$Ra2.27@newsfe06.iad>
grocery_stocker wrote:
> Given
>
> my ($title) = ($body =~ m@<title>\s*(.*?)\s*</title>@si);
>
>
> What does m@ do in this case?
m(anything) is making (anything) the delimiter. m// is just most common
to see, but m,, or m!! and so on, are perfectly acceptable. It can
help save typing over using m// when you have a lot of / characters
you'd otherwise have to backwack.
I.e.,
my ($title) = ($body =~
m!<title>\s*(.*?)\s*</title><b>this</b><i>that</i>!si);
saves typing over:
my ($title) = ($body =~
m@<title>\s*(.*?)\s*<\/title><b>this<\/b><i>that<\/i>@si);
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
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 1883
***************************************