[33100] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4376 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 22 14:09:19 2015

Date: Sun, 22 Feb 2015 11:09:04 -0800 (PST)
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, 22 Feb 2015     Volume: 11 Number: 4376

Today's topics:
    Re: [Completely OT ] Re: Why can I get away with this? <see.my.sig@for.my.address>
    Re: [Completely OT ] Re: Why can I get away with this? <ben.usenet@bsb.me.uk>
    Re: [Completely OT ] Re: Why can I get away with this? <m@rtij.nl.invlalid>
        grep <ruben@mrbrklyn.com>
    Re: grep <whynot@pozharski.name>
        Poor man's "object", and question on regex capture list <see.my.sig@for.my.address>
    Re: Poor man's "object", and question on regex capture  <hjp-usenet3@hjp.at>
    Re: Poor man's "object", and question on regex capture  <ben.usenet@bsb.me.uk>
    Re: Poor man's "object", and question on regex capture  <hjp-usenet3@hjp.at>
    Re: Poor man's "object", and question on regex capture  <ben.usenet@bsb.me.uk>
    Re: Poor man's "object", and question on regex capture  <rweikusat@mobileactivedefense.com>
    Re: Poor man's "object", and question on regex capture  <derykus@gmail.com>
    Re: Poor man's "object", and question on regex capture  <ben.usenet@bsb.me.uk>
    Re: Traversing through sub dirs and read file contents (Tim McDaniel)
    Re: Why can I get away with this? <see.my.sig@for.my.address>
    Re: Why can I get away with this? <m@rtij.nl.invlalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 20 Feb 2015 23:45:48 -0800
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Re: [Completely OT ] Re: Why can I get away with this?
Message-Id: <2OydnTdMVLA_qnXJnZ2dnUVZ57ydnZ2d@giganews.com>

#! /usr/bin/perl
use v5.14;
use strict;
use warnings;

=pod

On 2/19/2015 5:08 AM, jurgenex@hotmail.com wrote:

 > Martijn Lievaart <m@rtij.nl.invlalid> wrote:
 >
 > > ... Carrying a stack of cards.
 >
 > And dropping them ...
 >
 > > That brings back memories, not all good.
 >
 > .... while having forgotten to mark their sequence

I did that once. Back in 1973 when I was attending Orange Coast College,
Costa Mesa, California, taking computer science classes, I'd just
written a lengthy program in Fortran. The sysop of our dual IBM 370
computers came strolling through the room where the card punches,
card reader, and line printer were located, and found me sitting in front
of a card punch machine, crying. He stopped, and ask concernedly,
"What's wrong, son?"  I answered, "I dropped my deck" and held up a thick
deck of now-thoroughly-shuffled punched cards.  He nodded compassionately,
gave me a pat on the back, and said "I feel you pain". Took me a long time
to match up each card to the correct line number and get the deck back in
order.

http://en.wikipedia.org/wiki/File:FortranCardPROJ039.agr.jpg

Those were the days.

And to think that this $600 Asus notebook probably has more computing
power than both of those IBM 370s combined. And they probably cost
the college about $2000000.

I'm trying to think of some way to make this comment on-topic, but in
1973, Larry Wall hadn't started college yet, and wouldn't invent Perl
for another 14 years. Ah, I know, I'll make this entire post a valid
Perl program.


-- 
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley

=cut

say 'Hello, world.';
exit 0;



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

Date: Sat, 21 Feb 2015 14:16:42 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: [Completely OT ] Re: Why can I get away with this?
Message-Id: <87ioevuz79.fsf@bsb.me.uk>

Jürgen Exner <jurgenex@hotmail.com> writes:

> Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>>On Thu, 19 Feb 2015 02:42:52 -0800, $Bill wrote:
>>
>>> Things were tough with tape and cards, wasn't till we modified our
>>> Modcomp mini-computers to read word processor disks that things started
>>> to get easier on the way to actual realtime editors on computers.  You
>>> could carry a floppy to the machine room instead of a tray of cards or
>>> mag tape.
>>
>>Carrying a stack of cards. 
>
> And dropping them ...

As a part-time operator of an IBM 360 I made a more dramatic mistake.
The high speed card reader had a sort of wave-shaped capture device on
the exit that gently stops the cards and lets then fall into place in
the collecting hopper.  The end of the wave can be flipped up (I don't
know why but you can see where this is going...) so you have to remember
to leave it down or the reader turns into a machine that splays very
large confetti all over the computer room.  It's memorable enough to be
one-time error (and it it was not my deck so I could not get it back
into order).

<snip>
-- 
Ben.


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

Date: Sun, 22 Feb 2015 16:54:19 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: [Completely OT ] Re: Why can I get away with this?
Message-Id: <bmaprb-76m.ln1@news.rtij.nl>

On Sat, 21 Feb 2015 14:16:42 +0000, Ben Bacarisse wrote:

> As a part-time operator of an IBM 360 I made a more dramatic mistake.
> The high speed card reader had a sort of wave-shaped capture device on
> the exit that gently stops the cards and lets then fall into place in
> the collecting hopper.  The end of the wave can be flipped up (I don't
> know why but you can see where this is going...) so you have to remember
> to leave it down or the reader turns into a machine that splays very
> large confetti all over the computer room.  It's memorable enough to be
> one-time error (and it it was not my deck so I could not get it back
> into order).

Magnificent! Thanks for sharing.

M4


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

Date: Sat, 21 Feb 2015 20:10:13 -0500
From: ruben safir <ruben@mrbrklyn.com>
Subject: grep
Message-Id: <mcba9m$d9$1@reader1.panix.com>

any idea why this might fail with a known match

open (WHITELIST, "<", "/home/ruben/mail/whitelist") or die;
my @oknames = <WHITELIST>;
close(WHITELIST);

 ...
        if( /(From: *"?[ \w-.].*"?)\b<?([\w].+\@[-a-z.A-Z=]+\.(\w.+))(?!<)/ ){
#               print  STDERR "HEY a WINNER\nONE $1 \n Two $2 \n Three $3";
                if ($2 =~ /ruben\@mrbrklyn\.com/){
                        last;
                }
                my @ret;
                if( @ret = grep( /.*$2.*/ , @oknames) ){
                        print STDERR "\n$2 WHITELISTED @ret\n";
                        last;
                }


The test program works:

  1 #!/usr/bin/perl -w
  2 
  3 my $mail = "ruben2\@mrbrklyn\.com";
  4 
  5 open (WHITELIST, "<", "/home/ruben/mail/whitelist") or die;
  6 my @oknames = <WHITELIST>;
  7 my @ret;
  8 if(@ret = grep( /.*$mail.*/ , @oknames)){
  9    print STDERR "\n$mail WHITELISTED @ret\n";
 10 }
 11 
 12 print "@ret";
 13 
 14 
 15 
 16 


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

Date: Sun, 22 Feb 2015 13:55:15 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: grep
Message-Id: <slrnmejgt3.t85.whynot@orphan.zombinet>

with <mcba9m$d9$1@reader1.panix.com> ruben safir wrote:

> any idea why this might fail with a known match
>
> open (WHITELIST, "<", "/home/ruben/mail/whitelist") or die;
> my @oknames = <WHITELIST>;
> close(WHITELIST);
>
> ...
>         if( /(From: *"?[ \w-.].*"?)\b<?([\w].+\@[-a-z.A-Z=]+\.(\w.+))(?!<)/ ){
> #               print  STDERR "HEY a WINNER\nONE $1 \n Two $2 \n Three $3";
>                 if ($2 =~ /ruben\@mrbrklyn\.com/){
>                         last;
>                 }
>                 my @ret;
>                 if( @ret = grep( /.*$2.*/ , @oknames) ){
>                         print STDERR "\n$2 WHITELISTED @ret\n";
>                         last;
>                 }

Sure:

  (1) See difference (with your so-called-test-program-works)?

	% perl -wle '
	"abcdef" =~ m/(ab).*(ef)/ or die "foo";
	print $2;
	"abcdef" =~ m/ab.*ef/ or die "bar";
	print $2
	'                                     
	ef
	Use of uninitialized value $2 in print at -e line 5.

  (2) use-strict-use-warnings!  Even in production.  That's why your
      so-called-test-program-works works and your
      so-called-intest-program-works doesn't work.

  (3) I see that your gigantic regexp in all captures accepts
      metachaarcters.  Guess what will happen here?

	% perl -wle '
	"abc+++" =~ m/(\w)\w+(\W)\W+/ or die "foo";
	"abc+++" =~ m/(\w$2)/ or die "bar";
	print $1
	'                

  (4) Seriously, dude, seriously.  Email::Address->can( 'parse' )


*CUT*

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Sat, 21 Feb 2015 00:13:50 -0800
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Poor man's "object", and question on regex capture list.
Message-Id: <PcSdnUWAXaWoo3XJnZ2dnUVZ572dnZ2d@giganews.com>


I just wrote a script (see below) to test regular expressions.
Invoked like this:
test-regex.perl 'Samuel Goldstein' '(old)?'
It prints whether the text matches the regex, lists the
parenthetical captures, and gives the pre-match, match, and
post-match.

I HAVE TWO QUESTIONS ABOUT THIS SCRIPT:

1. I don't know how to do Perl classes yet, so I had to create
    a half-baked "object" by using a closure. What would this
    "object" of mine look like if written as an actual Perl class?

2. If the text matches the regex but there were no parentheses in
    the regex, the script erroneously says "number of captures = 1"
    and lists (1) as being the list of captures. Is there a way to
    obtain a list of parenthetical captures which is EMPTY if no
    captures occurred?




#! /usr/bin/perl
# "test-regex.perl"
use v5.14;
use strict;

MY_OBJECT: {
    my $text    = '';
    my $regex   = '';
    my @matches = ();

    sub set_text
    {
       $text = shift;
    }

    sub set_regex
    {
       $regex = shift;
    }

    sub print_results
    {
       my @matches= ();
       say '';
       say "Text  = $text";
       say "Regex = $regex";
       if (not @matches = $text =~ m/$regex/)
       {
          say "Does not match.";
          return;
       }
       say "Matches.";
       say ( "Number of captures = ", scalar(@matches)    );
       say ( "Captures = ",           join(' ', @matches) );
       say ( "Content of \$` = ",     $`                  );
       say ( "Length  of \$` = ",     length($`)          );
       say ( "Content of \$& = ",     $&                  );
       say ( "Length  of \$& = ",     length($&)          );
       say ( "Content of \$' = ",     $'                  );
       say ( "Length  of \$' = ",     length($')          );
    }
}

set_text($ARGV[0]);
set_regex($ARGV[1]);
print_results;





-- 
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley


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

Date: Sat, 21 Feb 2015 10:50:01 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <slrnmegl69.emn.hjp-usenet3@hrunkner.hjp.at>

On 2015-02-21 08:13, Robbie Hatley <see.my.sig@for.my.address> wrote:
> 2. If the text matches the regex but there were no parentheses in
>     the regex, the script erroneously says "number of captures = 1"
>     and lists (1) as being the list of captures. Is there a way to
>     obtain a list of parenthetical captures which is EMPTY if no
>     captures occurred?

There's no option to do that.

You could wrap the entire regexp in parentheses (thus making sure that
there is at least one group) and then ignore the first match:

       if (not @matches = $text =~ m/($regex)/)
       {
          say "Does not match.";
          return;
       }
       shift @matches;

> 1. I don't know how to do Perl classes yet, so I had to create
>     a half-baked "object" by using a closure. What would this
>     "object" of mine look like if written as an actual Perl class?

Read perlootut and perlobj.

There's more than one way to do it, of course (It's Perl, after all), so
I'm showing two ways, the traditional way (using only perl builtins) and
the Moose way (which is sort of becoming the new standard way, but as
Wikipedia informs me, some Moose can weigh up to 725 kg, so that's a
rather heavyweight solution):


#! /usr/bin/perl
# Object oriented RegEx demo - the traditional way
use v5.14;
use strict;

package RegexTest {

    sub new {
        my ($class) = @_;

        my $self = {};
        bless $self, $class;

        $self->{text}    = '';
        $self->{regex}   = '';

        return $self;
    }

    sub set_text
    {
        my ($self, $text) = @_;
        $self->{text} = $text;
    }

    sub set_regex
    {
        my ($self, $regex) = @_;
        $self->{regex} = $regex;
    }

    sub print_results
    {
       my ($self) = @_;
       my @matches= ();
       say '';
       say "Text  = $self->{text}";
       say "Regex = $self->{regex}";
       if (not @matches = $self->{text} =~ m/$self->{regex}/)
       {
          say "Does not match.";
          return;
       }
       say "Matches.";
       say ( "Number of captures = ", scalar(@matches)    );
       say ( "Captures = ",           join(' ', @matches) );
       say ( "Content of \$` = ",     $`                  );
       say ( "Length  of \$` = ",     length($`)          );
       say ( "Content of \$& = ",     $&                  );
       say ( "Length  of \$& = ",     length($&)          );
       say ( "Content of \$' = ",     $'                  );
       say ( "Length  of \$' = ",     length($')          );
    }
}

my $regex_test = RegexTest->new();
$regex_test->set_text($ARGV[0]);
$regex_test->set_regex($ARGV[1]);
$regex_test->print_results;
__END__

I have preserved as much of your code as possible. Normally I would add
text and regex as arguments to the constructor and not bother with
explicit setters in such a simple case. Also I usually combine setters
and getters, so I would have a «sub text» which acts as getter if called
with 0 arguments and as setter if called with one. Finally, classes
usually reside in their own .pm file.


#! /usr/bin/perl
# Object oriented RegEx demo - the Moose way
use v5.14;
use strict;

package RegexTest {

    use Moose;

    has text  => ( is => 'rw', isa => 'Str' );
    has regex => ( is => 'rw', isa => 'RegexpRef' );

    sub print_results
    {
       my ($self) = @_;
       my $text = $self->text;
       my $regex = $self->regex;
       my @matches= ();
       say '';
       say "Text  = $text";
       say "Regex = $regex";
       if (not @matches = $text =~ m/$regex/)
       {
          say "Does not match.";
          return;
       }
       say "Matches.";
       say ( "Number of captures = ", scalar(@matches)    );
       say ( "Captures = ",           join(' ', @matches) );
       say ( "Content of \$` = ",     $`                  );
       say ( "Length  of \$` = ",     length($`)          );
       say ( "Content of \$& = ",     $&                  );
       say ( "Length  of \$& = ",     length($&)          );
       say ( "Content of \$' = ",     $'                  );
       say ( "Length  of \$' = ",     length($')          );
    }
}

my $regex_test = RegexTest->new();
$regex_test->text($ARGV[0]);
$regex_test->regex(qr{$ARGV[1]});
$regex_test->print_results;
__END__

No definition of explicit constructor and getters or setters here. Moose
creates them for us (and it creates combined getters and setters by
default). You can also tell Moose what types your attributes are
supposed to be and it will create code to check them (so
$regex_test->regex($ARGV[1]) would yield an error message).

        hp



-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sat, 21 Feb 2015 13:15:40 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <874mqfwglf.fsf@bsb.me.uk>

Robbie Hatley <see.my.sig@for.my.address> writes:

> I just wrote a script (see below) to test regular expressions.
> Invoked like this:
> test-regex.perl 'Samuel Goldstein' '(old)?'
> It prints whether the text matches the regex, lists the
> parenthetical captures, and gives the pre-match, match, and
> post-match.
<snip>
> 2. If the text matches the regex but there were no parentheses in
>    the regex, the script erroneously says "number of captures = 1"
>    and lists (1) as being the list of captures. Is there a way to
>    obtain a list of parenthetical captures which is EMPTY if no
>    captures occurred?

The problem, as I am sure you know, is that a successful match like this

  my @matches = $text =~ m/$regex/;

will, when $regex has no capturing ()s, set $matches[0] to the *status*
of the match, so it seems that you can't tell the difference between

  my @matches = "1" =~ m/1/;

and

  my @matches = "1" =~ m/(1)/;

But Data::Dumper can:

  print Dumper("1" =~ /1/, "1" =~ /(1)/);

This prints 1 and '1' because, internally, Perl "knows" the difference
between the scalar 1 and the scalar '1';

So you *could* set $Data::Dumper::Terse = 1; and (if @matches < 2) test
Dumper($matches[0]) to see if it starts with a quote.  Yucky... very
yucky.

But maybe whatever Data::Dumper is doing using internally is available
to mortal Perl programmers.  That might remove some of the yuckiness
from this idea.

I hesitate to mention this (since it seems so hacky and fragile) but
I'll post it anyway in the hope that I might learn something if the
experts chip in.

<snip>
-- 
Ben.


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

Date: Sat, 21 Feb 2015 15:09:01 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <slrnmeh4bt.e1.hjp-usenet3@hrunkner.hjp.at>

On 2015-02-21 13:15, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Robbie Hatley <see.my.sig@for.my.address> writes:
>> 2. If the text matches the regex but there were no parentheses in
>>    the regex, the script erroneously says "number of captures = 1"
>>    and lists (1) as being the list of captures.
[...]
> But Data::Dumper can:
>
>   print Dumper("1" =~ /1/, "1" =~ /(1)/);
>
> This prints 1 and '1' because, internally, Perl "knows" the difference
> between the scalar 1 and the scalar '1';
>
> So you *could* set $Data::Dumper::Terse = 1; and (if @matches < 2) test
> Dumper($matches[0]) to see if it starts with a quote.  Yucky... very
> yucky.
>
> But maybe whatever Data::Dumper is doing using internally is available
> to mortal Perl programmers. 

You could use Scalar::Util::dualvar:

#!/usr/bin/perl
use v5.20;
use Scalar::Util qw(isdual);

my ($x) = "1" =~ /1/;
my ($y) = "1" =~ /(1)/;

say "x: ", isdual($x);
say "y: ", isdual($y);
__END__

prints:

x: 1
y: 



> That might remove some of the yuckiness from this idea.

Maybe less yucky, but at least as fragile. What if a future version of
perl "optimizes" the first case by returning a pure number instead of a
dualvar?

        hp

-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sat, 21 Feb 2015 14:20:18 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <87d253uz19.fsf@bsb.me.uk>

"Peter J. Holzer" <hjp-usenet3@hjp.at> writes:

> On 2015-02-21 13:15, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>> Robbie Hatley <see.my.sig@for.my.address> writes:
>>> 2. If the text matches the regex but there were no parentheses in
>>>    the regex, the script erroneously says "number of captures = 1"
>>>    and lists (1) as being the list of captures.
> [...]
>> But Data::Dumper can:
>>
>>   print Dumper("1" =~ /1/, "1" =~ /(1)/);
>>
>> This prints 1 and '1' because, internally, Perl "knows" the difference
>> between the scalar 1 and the scalar '1';
>>
>> So you *could* set $Data::Dumper::Terse = 1; and (if @matches < 2) test
>> Dumper($matches[0]) to see if it starts with a quote.  Yucky... very
>> yucky.
>>
>> But maybe whatever Data::Dumper is [...] using internally is available
>> to mortal Perl programmers. 
>
> You could use Scalar::Util::dualvar:
>
> #!/usr/bin/perl
> use v5.20;
> use Scalar::Util qw(isdual);
>
> my ($x) = "1" =~ /1/;
> my ($y) = "1" =~ /(1)/;
>
> say "x: ", isdual($x);
> say "y: ", isdual($y);
> __END__
>
> prints:
>
> x: 1
> y: 

Ah, right.  Thanks.

>> That might remove some of the yuckiness from this idea.
>
> Maybe less yucky, but at least as fragile. What if a future version of
> perl "optimizes" the first case by returning a pure number instead of a
> dualvar?

Ack.  Unless there's a guarantee that the two cases will always be
distinguishable (and surely there isn't), it remains just a toy idea.

-- 
Ben.


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

Date: Sat, 21 Feb 2015 19:12:31 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <87pp93krj4.fsf@doppelsaurus.mobileactivedefense.com>

Robbie Hatley <see.my.sig@for.my.address> writes:

[...]

> I HAVE TWO QUESTIONS ABOUT THIS SCRIPT:
>
> 1. I don't know how to do Perl classes yet, so I had to create
>    a half-baked "object" by using a closure. What would this
>    "object" of mine look like if written as an actual Perl class?

[...]

> #! /usr/bin/perl
> # "test-regex.perl"
> use v5.14;
> use strict;
>
> MY_OBJECT: {
>    my $text    = '';
>    my $regex   = '';
>    my @matches = ();
>
>    sub set_text
>    {
>       $text = shift;
>    }
>
>    sub set_regex
>    {
>       $regex = shift;
>    }

[...]

This can be made more object-like by using an anonymous subroutine and a
subroutine creating these:

------------
sub ctor
{
    my $text;
    my %ops = ('set', sub { $text = $_[0] }, 'get', sub { $text });

    return sub {
	&{$ops{shift,}};
    }
}

my $o = ctor();
my $p = ctor();

$o->('set', 110);
$p->('set', 'Feldmaeuse');

print($o->('get'), ' ', $p->('get'), "\n");
------------

But this is really writing average Java in Perl: An object should
provide behaviour and not storage space, hence, whenever 'an accessor'
has to be  written, this is a sign of a design deficiency[*].

[*] Things get more bziarre than that: JSF has a standard way to access
object properties, eg, when writing

#{box.content}

[an EL expression]

this will end up as a call to box.getContent() (with a similar
convention for setting a property by substituting a call to
box.setContent(...) in place of an assignment). This combined with the
bad habit of using objects as structures (Surely, the fact that the
default access is private couldn't mean that accesses to data members
from outside an object weren't supposed to be made!) led to the
universal Java convention of exposing the guts of any object by
providing 'accessors' for all data members, overloaded with all kinds of
'mythological meaning' to make them appear as an end in themselves
instead of a means to an end and from there, the idea invaded Perl: Poke
around in the state of an object in whatever way you like, for as long
as this is incapsulated in method calls, you're absolved and properly
object oriented. Auto-generating accessors then finally undoes the last
outward respect to 'encapsulation' and hazy concepts like that normal
people can't be bothered with as they're to busy to "get shit done"
(quite literaly) ...


		      



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

Date: Sat, 21 Feb 2015 12:27:33 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <a8fbabc0-ad55-49b5-9335-3a15f27e358e@googlegroups.com>

On Saturday, February 21, 2015 at 5:15:44 AM UTC-8, Ben Bacarisse wrote:
> Robbie Hatley <see.my.sig@for.my.address> writes:
> 
> > I just wrote a script (see below) to test regular expressions.
> > Invoked like this:
> > test-regex.perl 'Samuel Goldstein' '(old)?'
> > It prints whether the text matches the regex, lists the
> > parenthetical captures, and gives the pre-match, match, and
> > post-match.
> <snip>
> > 2. If the text matches the regex but there were no parentheses in
> >    the regex, the script erroneously says "number of captures = 1"
> >    and lists (1) as being the list of captures. Is there a way to
> >    obtain a list of parenthetical captures which is EMPTY if no
> >    captures occurred?
> 
> The problem, as I am sure you know, is that a successful match like this
> 
>   my @matches = $text =~ m/$regex/;
> 
> will, when $regex has no capturing ()s, set $matches[0] to the *status*
> of the match, so it seems that you can't tell the difference between
> 
>   my @matches = "1" =~ m/1/;
> 
> and
> 
>   my @matches = "1" =~ m/(1)/;
> ...



say $+ // "no captures";

-- 
Charles DeRykus



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

Date: Sat, 21 Feb 2015 20:40:22 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Poor man's "object", and question on regex capture list.
Message-Id: <87r3tjq9qh.fsf@bsb.me.uk>

"C.DeRykus" <derykus@gmail.com> writes:

> On Saturday, February 21, 2015 at 5:15:44 AM UTC-8, Ben Bacarisse wrote:
>> Robbie Hatley <see.my.sig@for.my.address> writes:
>> 
>> > I just wrote a script (see below) to test regular expressions.
>> > Invoked like this:
>> > test-regex.perl 'Samuel Goldstein' '(old)?'
>> > It prints whether the text matches the regex, lists the
>> > parenthetical captures, and gives the pre-match, match, and
>> > post-match.
>> <snip>
>> > 2. If the text matches the regex but there were no parentheses in
>> >    the regex, the script erroneously says "number of captures = 1"
>> >    and lists (1) as being the list of captures. Is there a way to
>> >    obtain a list of parenthetical captures which is EMPTY if no
>> >    captures occurred?
>> 
>> The problem, as I am sure you know, is that a successful match like this
>> 
>>   my @matches = $text =~ m/$regex/;
>> 
>> will, when $regex has no capturing ()s, set $matches[0] to the *status*
>> of the match, so it seems that you can't tell the difference between
>> 
>>   my @matches = "1" =~ m/1/;
>> 
>> and
>> 
>>   my @matches = "1" =~ m/(1)/;
>> ...
>
>
>
> say $+ // "no captures";

Excellent, though it makes me think that I should have thought of just
examining $1.

-- 
Ben.


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

Date: Sun, 22 Feb 2015 18:34:46 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Traversing through sub dirs and read file contents
Message-Id: <mcd7g6$pod$1@reader1.panix.com>

In article <fu5tqb-3lm.ln1@news.rtij.nl>,
Martijn Lievaart  <m@rtij.nl.invlalid> wrote:
>On Wed, 11 Feb 2015 21:58:47 +0100, Peter J. Holzer wrote:
>
>> That depends on what the OP means by "a lot of files". Hundreds?
>> Thousands? Tens of thousands? Millions? Billions? Probably hundreds or
>> thousands. And it probably doesn't matter unless we get into at least
>> the 100k to 1M files per directory range, possibly even higher.
>
>As a side note, current file systems may handle that many files in a 
>directory gracefully, but maybe not.

Exemplia gratia: I *very occasionally* run P4V, a GUI front-end for
Perforce. [1]  The problems:
- the one thing that isn't fast is the network latency
- one of the directories has a bazillion directories and files, and is
  the parent of most of the source tree
- P4V insists on showing every directory in the sidebar, so it does
  the moral equivalent of
    @all = readdir(...)
  with both Perforce metadata and some filesystem metadata
None of which I have the slightest control over.

When I just want the time-lapse view of
//depot/this/that/exploderdir/sub1/sub2/Peccant.pm,
I'd be overjoyed if it went straight there.  Unfortunately, when I
paste that filename into the text bar, it expands
    //depot/*
    //depot/this/*
    //depot/this/that/*
    //depot/this/that/exploderdir/*
and I can go to a half-hour-long meeting and maybe it'll be done when
I get back.

And then P4V sometimes realizes "Wait!  It's been a while since I got
all that information!  I'd better go refresh it!"
    //depot/this/that/exploderdir/*

Which is why I started with "I *very occasionally* run P4V".

[1] Yes, I use the command-line p4 for 98% of my operations, but there
are a few operations for which a GUI display works much better:
- graph of file branching
- 3-way conflict resolve merge, with the current result in a 4th window
- time-lapse view of changes to a file, with sliders to control which
  ranges of revisions are being highlighted

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Fri, 20 Feb 2015 22:44:12 -0800
From: Robbie Hatley <see.my.sig@for.my.address>
Subject: Re: Why can I get away with this?
Message-Id: <GamdnVUUS6eutHXJnZ2dnUVZ572dnZ2d@giganews.com>


On 2/16/2015 6:57 AM, Martijn Lievaart wrote:

>...
> Using embedded nulls in Perl strings only makes sense when an external
> interface demands it. So embedded nulls are actually only likely when
> talking to real-world OSses, hardware and external libraries, about the
> opposite of what you said above. :-)

Yes, I can see why that would be so: Perl has its own idioms for strings,
which don't use '\0' as end-of-string (except, perhaps, in the underlying
implementation of a Perl interpreter, in C), so a Perl programmer normally
isn't going to be using '\0' for EOS.

Whereas, if interfacing with, say, the registry in Microsoft Windows,
some of those values are type "REG_MULTI_SZ" which are lists of strings
using '\0' not only as record terminator but as field separator,
so that the Perl list qw(Bob Fred Tom) would be stored in MS-Win Reg as
"Bob\0Fred\0Tom\0".


-- 
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley


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

Date: Sun, 22 Feb 2015 16:55:54 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Why can I get away with this?
Message-Id: <apaprb-76m.ln1@news.rtij.nl>

On Fri, 20 Feb 2015 22:44:12 -0800, Robbie Hatley wrote:

> Whereas, if interfacing with, say, the registry in Microsoft Windows,
> some of those values are type "REG_MULTI_SZ" which are lists of strings
> using '\0' not only as record terminator but as field separator,
> so that the Perl list qw(Bob Fred Tom) would be stored in MS-Win Reg as
> "Bob\0Fred\0Tom\0".

Excellent example, thanks.

M4


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

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


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