Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > newbie question

Reply
Thread Tools

newbie question

 
 
fzhang@calamos.com
Guest
Posts: n/a
 
      03-01-2006
What does the following do?

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

Thanks.

Frank

 
Reply With Quote
 
 
 
 
Keith Keller
Guest
Posts: n/a
 
      03-01-2006
Please put the subject of your post in the Subject: of your post.

On 2006-03-01, <> wrote:
> 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

--
kkeller-
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-01-2006
wrote in news:1141246133.873937.255500
@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


--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
UkJay
Guest
Posts: n/a
 
      03-02-2006

"Keith Keller" <kkeller-> wrote in message
news...
> 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)






 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-02-2006
"UkJay" <> wrote in
news:du68g8$rdb$:

>
> "Keith Keller" <kkeller-> wrote in
> message news...
>> Please put the subject of your post in the Subject: of your post.
>>

>
> He did Keith,


No he did not.

Please read the posting guidelines.

> next you will be wanting the whole message there as well


On second thought, bye!

Sinan

--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
UkJay
Guest
Posts: n/a
 
      03-02-2006

"A. Sinan Unur" <> wrote in message
news:Xns977A2301FE25Dasu1cornelledu@127.0.0.1...
> "UkJay" <> wrote in
> news:du68g8$rdb$:
>
>>
>> "Keith Keller" <kkeller-> wrote in
>> message news...
>>> Please put the subject of your post in the Subject: of your post.
>>>

>>
>> He did Keith,

>
> No he did not.
>


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


--
Best Regards,
James (ukjay)

http://www.ukjay.co.uk

Garden WebCam,Photography,Competitions,Weather (AWS)







 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      03-02-2006
UkJay <> wrote in comp.lang.perl.misc:
>
> "A. Sinan Unur" <> wrote in message
> news:Xns977A2301FE25Dasu1cornelledu@127.0.0.1...
> > "UkJay" <> wrote in
> > news:du68g8$rdb$:
> >
> >>
> >> "Keith Keller" <kkeller-> wrote in
> >> message news...
> >>> Please put the subject of your post in the Subject: of your post.
> >>>
> >>
> >> He did Keith,

> >
> > No he did not.
> >

>
> 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
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
UkJay
Guest
Posts: n/a
 
      03-02-2006

"Anno Siegel" <> wrote in message
news:du6dq8$ero$...
> UkJay <> wrote in comp.lang.perl.misc:
>>
>> "A. Sinan Unur" <> wrote in message
>> news:Xns977A2301FE25Dasu1cornelledu@127.0.0.1...
>> > "UkJay" <> wrote in
>> > news:du68g8$rdb$:
>> >
>> >>
>> >> "Keith Keller" <kkeller-> wrote in
>> >> message news...
>> >>> Please put the subject of your post in the Subject: of your post.
>> >>>
>> >>
>> >> He did Keith,
>> >
>> > No he did not.
>> >

>>
>> 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

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)









 
Reply With Quote
 
Ian Wilson
Guest
Posts: n/a
 
      03-02-2006
UkJay wrote:
> "A. Sinan Unur" <> wrote in message
> news:Xns977A2301FE25Dasu1cornelledu@127.0.0.1...
>
>>"UkJay" <> wrote in
>>news:du68g8$rdb$:
>>
>>>"Keith Keller" <kkeller-> wrote in
>>>message news...
>>>
>>>>Please put the subject of your post in the Subject: of your post.
>>>
>>>He did Keith,

>>
>>No he did not.
>>

>
> 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/cl...uidelines.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-...tml#bespecific gives
similar good advice.

 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      03-02-2006
UkJay wrote:
> "Anno Siegel" <> wrote in message
> news:du6dq8$ero$...
>
>>UkJay <> wrote in comp.lang.perl.misc:
>>
>>>"A. Sinan Unur" <> wrote in message
>>>news:Xns977A2301FE25Dasu1cornelledu@127.0.0.1.. .
>>>
>>>>"UkJay" <> wrote in
>>>>news:du68g8$rdb$:
>>>>
>>>>
>>>>>"Keith Keller" <kkeller-> wrote in
>>>>>message news...
>>>>>
>>>>>>Please put the subject of your post in the Subject: of your post.
>>>>>>
>>>>>
>>>>>He did Keith,
>>>>
>>>>No he did not.
>>>>
>>>
>>>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

>
> 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,
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57