Click here to get back home

Re: A little Direction Please

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Re: A little Direction Please Jürgen Exner 05-13-2008
Posted by Jürgen Exner on May 13, 2008, 1:20 pm
Please log in for more thread options
>Andy wrote:
>> if ($line =~ m/^(.+226\s+0\s+-\s+.*)$/) {
>
>Matching ^.+ is wasteful.
>You don't need to capture the whole line using ().
>
>> print OUTPUT "$1\n";
>
>Unless you chomp your input you'll output an extra blank line.

My first thought, too. However because of the rather 'interesting' way
he is printing the captured group instead of just the plain line he is
loosing the newline in the pattern match. Therefore he has to add it
back explicitely.

> print OUTPUT if /\s+0\s+-\s*$/;

Much nicer, of course.

jue

Posted by RedGrittyBrick on May 13, 2008, 2:09 pm
Please log in for more thread options
Jürgen Exner wrote:
>> Andy wrote:
>>> if ($line =~ m/^(.+226\s+0\s+-\s+.*)$/) {
>> Matching ^.+ is wasteful.
>> You don't need to capture the whole line using ().
>>
>>> print OUTPUT "$1\n";
>> Unless you chomp your input you'll output an extra blank line.
>
> My first thought, too. However because of the rather 'interesting' way
> he is printing the captured group instead of just the plain line he is
> loosing the newline in the pattern match. Therefore he has to add it
> back explicitely.
>

Ah yes. Thanks for the correction.


--
RGB

Posted by John W. Krahn on May 13, 2008, 4:56 pm
Please log in for more thread options
J=FCrgen Exner wrote:
>> Andy wrote:
>>> if ($line =3D~ m/^(.+226\s+0\s+-\s+.*)$/) {
>> Matching ^.+ is wasteful.
>> You don't need to capture the whole line using ().
>>
>>> print OUTPUT "$1\n";
>> Unless you chomp your input you'll output an extra blank line.
>=20
> My first thought, too. However because of the rather 'interesting' way
> he is printing the captured group instead of just the plain line he is
> loosing the newline in the pattern match. Therefore he has to add it
> back explicitely.

The \s+ at the end is greedy and will match everything at the end=20
including the newline unless there is a non-whitespace character after=20
it that .* will match.


John
--=20
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Posted by Jürgen Exner on May 13, 2008, 5:14 pm
Please log in for more thread options
>Jürgen Exner wrote:
>>> Andy wrote:
>>>> if ($line =~ m/^(.+226\s+0\s+-\s+.*)$/) {
>>> Matching ^.+ is wasteful.
>>> You don't need to capture the whole line using ().
>>>
>>>> print OUTPUT "$1\n";
>>> Unless you chomp your input you'll output an extra blank line.
>>
>> My first thought, too. However because of the rather 'interesting' way
>> he is printing the captured group instead of just the plain line he is
>> loosing the newline in the pattern match. Therefore he has to add it
>> back explicitely.
>
>The \s+ at the end is greedy and will match everything at the end
>including the newline unless there is a non-whitespace character after
>it that .* will match.

You are right. I was looking at the trailing .* only and didn't dissect
the RE beyond that.
This RE certainly has some Interesting side effects.

jue

Similar ThreadsPosted
Re: A little Direction Please May 13, 2008, 7:11 pm
Re: A little Direction Please May 13, 2008, 6:53 pm
Just need a pointer in the right direction... October 22, 2005, 4:17 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap