newbie question

K

Keith Keller

Please put the subject of your post in the Subject: of your post.

What does the following do?

($input) = $input =~ /^\s*(.+)\s*$/;

Have you read perldoc perlre? Have you read the Posting Guidelines that
are posted here frequently?

--keith
 
A

A. Sinan Unur

(e-mail address removed) wrote in @t39g2000cwt.googlegroups.com:
Subject: newbie question

Please read the posting guidelines for this group.
What does the following do?

($input) = $input =~ /^\s*(.+)\s*$/;

It matches $input in list context and stores the captured match in
$input.

The purpose seems to be to trim leading and trailing spaces, but it
fails because the capture group matches any character. See:

D:\Home\asu1\UseNet\clpmisc> cat r.pl
#!/usr/bin/perl

use warnings;
use strict;

my $s = "\t \t \n test \n\n\n";

($s) = $s =~ m{ \A \s* (.+) \s* \z}x;

print "-$s-\n";

__END__

D:\Home\asu1\UseNet\clpmisc> r
-test -

Compare that to:

D:\Home\asu1\UseNet\clpmisc> cat r.pl
#!/usr/bin/perl

use warnings;
use strict;

my $s = "\t \t \n test \n\n\n";

($s) = $s =~ m{ \A \s* (\S+) \s* \z}x;

print "-$s-\n";

__END__

D:\Home\asu1\UseNet\clpmisc> r
-test-

Note that this will not work if $s is

$s = ""\t \t \n test me \n\n\n";

A better way to trim leading and trailing spaces in this case would be:

$s =~ s{\A\s+}{};
$s =~ s{\s+\z}{};

Sinan
 
U

UkJay

Keith Keller said:
Please put the subject of your post in the Subject: of your post.

He did Keith, next you will be wanting the whole message there as well !



--
Best Regards,
James (ukjay)

http://www.ukjay.co.uk

Garden WebCam,Photography,Competitions,Weather (AWS)
 
A

Anno Siegel

UkJay said:
Yes he did
It was a NEWBIE QUESTION
and his question was in the message!

Wrong. The message is about a substitution operation, not a newbie
question. "Substitution Operation" would be an appropriate subject,
"newbie question" isn't.

Anno
 
U

UkJay

Anno Siegel said:
Wrong. The message is about a substitution operation, not a newbie
question. "Substitution Operation" would be an appropriate subject,
"newbie question" isn't.

Anno
Sorry Anno I don't fully agree with that...
The poster thought it prudent to advise n.g. readers that his question was
of a simple nature.
I get so angry with pedantic replies about posts here! So this is my final
reply on this subject,
you carry on if you like, but I have had my say, and am far too busy to
play!
Ok I'll settle for newbie question - Substitution Operation :)


--
Best Regards,
James (ukjay)

http://www.ukjay.co.uk

Garden WebCam,Photography,Competitions,Weather (AWS)
 
I

Ian Wilson

UkJay said:
Yes he did
It was a NEWBIE QUESTION
and his question was in the message!

The posting guidelines for this newsgroup
(http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html) say

"Carefully choose the contents of your Subject header
You have 40 precious characters of Subject to win out and be
one of the posts that gets read. Don't waste them. Take care
while composing them, they are the key that opens the door to
getting an answer.

Spend them indicating what aspect of Perl others will find
if they should decide to read your article.

Do not spend them indicating ``experience level'' (guru, newbie...).

Do not spend them pleading (please read, urgent, help!...).

Do not spend them on non-Subjects
Perl question, one-word Subject...)

For more information on choosing a Subject see
``Choosing Good Subject Lines'':

http://www.cpan.org/authors/id/D/DM/DMR/subjects.post"


http://www.catb.org/~esr/faqs/smart-questions.html#bespecific gives
similar good advice.
 
J

Josef Moellers

UkJay said:
Sorry Anno I don't fully agree with that...
The poster thought it prudent to advise n.g. readers that his question was
of a simple nature.

So, what distinguishes "newbie question" from "newbie question" from
"newbie question" from ...?
Maybe others have a "newbie question" about dynamic scoping! Where
should they look for an answer?
If I have a "Simple question" about the substitution operator, where
should I look for an answer?

Most, if not all newsreaders, first give you a list of subject lines to
choose articles from. Having a subject line that clearly states the
subject of the article
1. allows me to skip questions that I surely will be unable to answer
2. allows me to peek into threads that may enlighten me on certain subjects.
I get so angry with pedantic replies about posts here! So this is my final
reply on this subject,
you carry on if you like, but I have had my say, and am far too busy to
play!
Ok I'll settle for newbie question - Substitution Operation :)

Much better!

My 2cts as a co-reader and potential answerer,
 
I

Ian Wilson

Ian Wilson said:
"Carefully choose the contents of your Subject header
You have 40 precious characters of Subject to win out and be
one of the posts that gets read. Don't waste them. Take care
while composing them, they are the key that opens the door to
getting an answer.
Spend them indicating what aspect of Perl others will find
if they should decide to read your article.
Do not spend them indicating ``experience level'' (guru, newbie...).
Do not spend them pleading (please read, urgent, help!...).
Do not spend them on non-Subjects
Perl question, one-word Subject...)
For more information on choosing a Subject see
``Choosing Good Subject Lines'':


http://www.catb.org/~esr/faqs/smart-questions.html#bespecific gives
similar good advice.

Holy ****, are you guys ever anal! I have never seen anything like
this before. "Choosing Good Subject Lines."

Hilarious!

cordially, as always,

rm
 
J

Josef Moellers

Ian said:
Holy ****, are you guys ever anal! I have never seen anything like
this before. "Choosing Good Subject Lines."

No need to use four letter words (d'ya know: "UNIX" is a four letter
word? B-{).

You might want to read RFC1178 ;-)

Josef, who prefers RFCs 1149 and 2549
 
T

Tad McClellan

Sorry Anno I don't fully agree with that...


Then you are in the vast minority.

Having 50 threads about "newbie question" that are about 50 different
aspects of Perl help neither someone searching for a problem similar
to theirs, nor to folks looking for questions that they can answer.

The Subject header is like a book's index. Nobody will be able
to find what they are looking for if every indexed entry is
the same.

The poster thought it prudent to advise n.g. readers that his question was
of a simple nature.


That's fine, but he should still include what the simple question
is _about_.

People that know about that subject are much more likely to read
the question when they know that it is about something that they
might be able to answer.

I get so angry with pedantic replies about posts here!


That's fine, but what does it have to do with replies that
are teaching something widely valuable rather than something
of narrow focus?

Putting the subject of your article in the Subject of your
article is not being pedantic, it is helping the OP to draw
in readers familar with that subject, and allows peers with
a similar problem to find previous discussions of that problem.

So this is my final
reply on this subject,


On the subject of "newbie question"?

you carry on if you like, but I have had my say,


People will be hurt if they do as you said.

Please try saying things that will be helpful rather than hurtful.

Ok I'll settle for newbie question - Substitution Operation :)


Then the OP could have been helped even more.

Subject: Substitution Operation - simple question

would get more folks to read the article than your proposed Subject,
increasing the OP's chances of getting an answer.

Consider these article scoring rules:

% red flag subjects
Score:: -5000
Subject: newbie

% interesting subjects
Score:: 9000
Subject: beginner


I expect that 1st one to be a rather common scorerule.

Why do you suppose that "newbie" is scored down while "beginner"
is scored up?
 
G

Glenn Jackman

At 2006-03-01 04:02PM said:
my $s = "\t \t \n test \n\n\n";
($s) = $s =~ m{ \A \s* (.+) \s* \z}x;
print "-$s-\n";
-test -

Although all trailing spaces would be trimmed if the capturing
expression was not greedy:
($s) = $s =~ m{ \A \s* (.+?) \s* \z}x;
 
D

Dr.Ruud

Glenn Jackman schreef:
($s) = $s =~ m{ \A \s* (.+?) \s* \z}x;

If there were only spaces in the line, one would survive.
If there were no spaces at both ends, a lot of work would be done to
achieve exactly nothing.
 
T

Tad McClellan

Are you "Ian Wilson" masquerading as "Roger Maynard",
or are you "Roger Maynard" masquerading as "Ian Wilson"?

Why are you masquerading at all?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top