[31897] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3160 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 3 21:09:26 2010

Date: Sun, 3 Oct 2010 18:09:07 -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           Sun, 3 Oct 2010     Volume: 11 Number: 3160

Today's topics:
    Re: FAQ 1.3 Which version of Perl should I use? <sherm.pendley@gmail.com>
    Re: FAQ 4.32 How do I strip blank space from the beginn <marc.girod@gmail.com>
    Re: FAQ 4.32 How do I strip blank space from the beginn <marc.girod@gmail.com>
    Re: FAQ 4.32 How do I strip blank space from the beginn <marc.girod@gmail.com>
    Re: FAQ 4.32 How do I strip blank space from the beginn <marc.girod@gmail.com>
    Re: FAQ 4.32 How do I strip blank space from the beginn <marc.girod@gmail.com>
    Re: FAQ 4.32 How do I strip blank space from the beginn sln@netherlands.com
    Re: FAQ 4.32 How do I strip blank space from the beginn sln@netherlands.com
    Re: FAQ 4.32 How do I strip blank space from the beginn <tadmc@seesig.invalid>
    Re: Need Regex for phone number <cwilbur@chromatico.net>
    Re: Need Regex for phone number sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 03 Oct 2010 18:10:58 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: FAQ 1.3 Which version of Perl should I use?
Message-Id: <m262xjsz9p.fsf@sherm.shermpendley.com>

PerlFAQ Server <brian@theperlreview.com> writes:

>     There is often a matter of opinion and taste, and there isn't any one
>     answer that fits everyone. In general, you want to use either the
>     current stable release, or the stable release immediately prior to that
>     one. Currently, those are perl5.10.x and perl5.8.x, respectively.

That needs updating to "5.12.x and 5.10.x, respectively."

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


------------------------------

Date: Sun, 3 Oct 2010 07:38:37 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <40cf8603-59ab-48db-bb25-a162724c4f3b@t20g2000yqa.googlegroups.com>

On Oct 2, 11:00=A0pm, PerlFAQ Server <br...@theperlreview.com> wrote:

> =A0 =A0 [...] If need to keep embedded blank lines, you have
> =A0 =A0 to do a little more work. Instead of matching any whitespace (sin=
ce that
> =A0 =A0 includes a newline), just match the other whitespace.
>
> =A0 =A0 =A0 =A0 =A0 =A0 $string =3D~ s/^[\t\f ]+|[\t\f ]+$//mg;

But this matters only for the first part of the alternation, so that
the following is equivalent:

            $string =3D~ s/^[\t\f ]+|\s+$//mg;

No?

Marc


------------------------------

Date: Sun, 3 Oct 2010 10:01:48 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <16252c63-996f-4631-a178-6c128516472f@i3g2000yql.googlegroups.com>

On Oct 3, 5:01=A0pm, Tad McClellan <ta...@seesig.invalid> wrote:

> No.

Indeed, thanks.
I admit that I misread the FAQ entry, and precisely this:

    With the "/m" flag, the "$" matches *before* an embedded newline,
so it
    doesn't remove it. It still removes the newline at the end of the
    string.

Is it clear?
What does the second 'it' stand for here?
The "$" matches before the newline, but *who* then removes it?

Marc


------------------------------

Date: Sun, 3 Oct 2010 10:09:46 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <a31e61f1-4f99-462d-a3a0-1752cf2a4b78@l20g2000yqm.googlegroups.com>

On Oct 3, 6:01=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:

> What does the second 'it' stand for here?
> The "$" matches before the newline, but *who* then removes it?

Sorry, bad questions, although I still find the text confusing.
The second 'it' stands for the same as the first: the 'regular
expression'.

So, we do have two newlines in a row: the one which gets removes is
the one at the end of the previous line.

Marc


------------------------------

Date: Sun, 3 Oct 2010 10:10:48 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <fb6015c9-e719-4544-b3e3-ec7f68762f71@f25g2000yqc.googlegroups.com>

On Oct 3, 6:09=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:

> So, we do have two newlines in a row: the one which gets removes is
                                                                 ^
> the one at the end of the previous line.

removed.


------------------------------

Date: Sun, 3 Oct 2010 10:23:47 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <15268a0e-f7b3-4713-8699-d06faa44a628@f25g2000yqc.googlegroups.com>

On Oct 3, 6:09=A0pm, Marc Girod <marc.gi...@gmail.com> wrote:

> Sorry, bad questions, although I still find the text confusing.

Tfuu!
Next try. There is something confusing, but not what I pointed at.
The sentence:
  It still removes the newline at the end of the string.

is clear, and concerns the very end of the multiline string.

The problem is the word 'string' in:

  Remember that lines consisting entirely of whitespace will
disappear,
  since the first part of the alternation can match the entire string
and
  replace it with nothing.

This string does *not* refer to the multiline string, but to the
substring matching the 'line of whitespace'.
My confusion comes from the fact that the second part of the
alternation will *not* match this same substring, but a different one
which starts one character earlier (the newline at the end of the
previous line), and ends one character earlier.

So indeed, the text is correct, only... it did confuse me.
My fault?

Marc


------------------------------

Date: Sun, 03 Oct 2010 11:15:07 -0700
From: sln@netherlands.com
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <11hha69ogl1h1vs7a6l0vk6f8ti1epe471@4ax.com>

On Sun, 3 Oct 2010 07:38:37 -0700 (PDT), Marc Girod <marc.girod@gmail.com> wrote:

>On Oct 2, 11:00 pm, PerlFAQ Server <br...@theperlreview.com> wrote:
>
>>     [...] If need to keep embedded blank lines, you have
>>     to do a little more work. Instead of matching any whitespace (since that
>>     includes a newline), just match the other whitespace.
>>
>>             $string =~ s/^[\t\f ]+|[\t\f ]+$//mg;
>
>But this matters only for the first part of the alternation, so that
>the following is equivalent:
>
>            $string =~ s/^[\t\f ]+|\s+$//mg;
>
>No?
>

Not really.  In multiple line mode, \s+ is going to consume all the
newlines until the anchor $ matches, which is before a newline OR THE
END of a string.

So
"  line1 \n\n\n line 2\n" =~  /\s+$/mg;
 will match  
   " \n\n" then "\n"

This deletes embedded blank lines instead of keeping them.
-----------
  while ("line1\n\n\n line2\n" =~ /(.\s+)$/mg ) {
     print "\$1 = '$1'\n";
  }
-----------
$1 = '1

'
$1 = '2
'

-sln


------------------------------

Date: Sun, 03 Oct 2010 11:43:33 -0700
From: sln@netherlands.com
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <baiha6hjtb4lh9nmgm20cq2191p2nbon2r@4ax.com>

On Sun, 3 Oct 2010 10:23:47 -0700 (PDT), Marc Girod <marc.girod@gmail.com> wrote:

>On Oct 3, 6:09 pm, Marc Girod <marc.gi...@gmail.com> wrote:
>
>> Sorry, bad questions, although I still find the text confusing.
>
>Tfuu!
>Next try. There is something confusing, but not what I pointed at.
>The sentence:
>  It still removes the newline at the end of the string.
>
>is clear, and concerns the very end of the multiline string.
>
>The problem is the word 'string' in:
>
>  Remember that lines consisting entirely of whitespace will
>disappear,
>  since the first part of the alternation can match the entire string
>and
>  replace it with nothing.
>
>This string does *not* refer to the multiline string, but to the
>substring matching the 'line of whitespace'.
>My confusion comes from the fact that the second part of the
>alternation will *not* match this same substring, but a different one
>which starts one character earlier (the newline at the end of the
>previous line), and ends one character earlier.
>
>So indeed, the text is correct, only... it did confuse me.
>My fault?
>

Remember that ^ and $ are zero width things, they don't *consume* anything.
I guess they are called anchors.

Remember, the //m is a modifier that says the string is to be treated as
having multiple lines. That USUALLY means ^ is after a "\n" (or begining of
string) and $ is before a "\n" (or end of string), this without consuming anything.

In //m, multi-line mode, you can explain a single line to the regex engine as being
     "this is a line1 \n\n\n"
and the next line as:
     "this is a line2 \n\n\n"

"this is a line1 \n\n\n
this is a line2 \n\n\n" =~ /^(.+\s+)$/mg;

It all depends on what you want to do.
Even though it says multi-line mode, its your choice as to what
*a line* is.

-sln


------------------------------

Date: Sun, 03 Oct 2010 11:01:26 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <slrniaha9q.lhr.tadmc@tadbox.sbcglobal.net>

Marc Girod <marc.girod@gmail.com> wrote:
> On Oct 2, 11:00 pm, PerlFAQ Server <br...@theperlreview.com> wrote:
>
>>     [...] If need to keep embedded blank lines, you have
>>     to do a little more work. Instead of matching any whitespace (since that
>>     includes a newline), just match the other whitespace.
>>
>>             $string =~ s/^[\t\f ]+|[\t\f ]+$//mg;
>
> But this matters only for the first part of the alternation, 


If the first (left) part of the alternation fails to match, then
the second (right) part will be tried.


> so that
> the following is equivalent:
>
>             $string =~ s/^[\t\f ]+|\s+$//mg;
>
> No?


No.


---------------------
#!/usr/bin/perl
use warnings;
use strict;

my $string1 =<<ENDSTR;
line one

line three
line four


line seven
ENDSTR
my $string2 = $string1;

$string1 =~ s/^[\t\f ]+|[\t\f ]+$//mg;
print $string1;

print "-----\n";

$string2 =~ s/^[\t\f ]+|\s+$//mg;
print $string2;
---------------------

output:
line one

line three
line four


line seven
-----
line one
line three
line four


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Sat, 02 Oct 2010 14:45:59 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Need Regex for phone number
Message-Id: <86eic877rs.fsf@mithril.chromatico.net>

>>>>> "PJH" == Peter J Holzer <hjp-usenet2@hjp.at> writes:

    PJH> The problem which you refuse to see is that outside of the US
    PJH> there is no "simple parser for a basic number". 

I am completely missing how a clarification that says "This is a toy
problem; for its sake we're only interested in US phone numbers" lines
up with refusing to see that there are international phone numbers.

    PJH> Maybe he does but I think he filters for the wrong skills. But
    PJH> maybe he's looking for code monkeys, not programmers.

The skills necessary to be a competent code monkey are a subset of the
skills necessary to be a good programmer.  The last thing my company
needs is more "programmers" who can spout hours of bafflegab but can't
code to save themselves.  This question takes five to ten minutes out of
an hour, and very quickly establishes whether the candidate has basic
programming skills.

You don't fail this interview question by pointing out that there are
international phone number formats.  You fail by being incapable of
parsing a string to recognize whether or not it contains a recognizable
North American phone number.  You fail it by turning it into a pissing
contest about the true meaning of "valid" or "well-formed." 

So, Mr. Holzer, put yourself in the interviewer's position.  How do you
ascertain whether the candidate has basic Perl knowledge, including
whether he or she is actually the one that wrote any code samples you
may have received?  

Charlton






-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Sat, 02 Oct 2010 12:31:33 -0700
From: sln@netherlands.com
Subject: Re: Need Regex for phone number
Message-Id: <va1fa6pa924vc9i7m9t2mns6uuroebac7g@4ax.com>

On Sat, 02 Oct 2010 14:45:59 -0400, Charlton Wilbur <cwilbur@chromatico.net> wrote:
>...  How do you
>ascertain whether the candidate has basic Perl knowledge, including
>whether he or she is actually the one that wrote any code samples you
>may have received?  
>
This is not a critique of interview blabla, but one way, if the samples
were the reason you have that person in for an interview, is to pick a
good spot in the sample and actually start the questioning at that point.
Usually the sample will leave some super-duper code impression.
To ignore it alltogether and start with something as simple as parsing
a group of digits, might be demeaning.

Spending time on a candidates submission indicates you are of the
level to understand him, and the candidate will immediatly be at ease.
Then you can hit him with all the junk and crap, helter skelter code
that is really written at (not yours but) most companies.

-sln


------------------------------

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3160
***************************************


home help back first fref pref prev next nref lref last post