[28302] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9666 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 30 18:05:44 2006

Date: Wed, 30 Aug 2006 15:05: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           Wed, 30 Aug 2006     Volume: 10 Number: 9666

Today's topics:
    Re: A Sort Optimization Technique: decorate-sort-dedeco (Jamie)
    Re: Beginner: read $array with line breaks line by line <mstep@t-online.de>
        Can overloaded '+' return an array? If so, how? <shenkin@gmail.com>
    Re: Can overloaded '+' return an array? If so, how? <nospam-abuse@ilyaz.org>
    Re: Can overloaded '+' return an array? If so, how? xhoster@gmail.com
    Re: Can overloaded '+' return an array? If so, how? <shenkin@gmail.com>
    Re: Can overloaded '+' return an array? If so, how? <shenkin@gmail.com>
    Re: Can overloaded '+' return an array? If so, how? <shenkin@gmail.com>
    Re: Can overloaded '+' return an array? If so, how? <jl_post@hotmail.com>
        Close a Running Sub-Process <mumebuhi@gmail.com>
    Re: Close a Running Sub-Process axel@white-eagle.invalid.uk
    Re: Close a Running Sub-Process <mumebuhi@gmail.com>
    Re: FAQ 6.22 How can I match strings with multibyte cha <brian.d.foy@gmail.com>
    Re: FAQ 6.22 How can I match strings with multibyte cha <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Aug 2006 20:32:33 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: A Sort Optimization Technique: decorate-sort-dedecorate
Message-Id: <Lc115696919285360x777cac@air.tunestar.net>

In <x7r6z0vd2t.fsf@mail.sysarch.com>,
Uri Guttman <uri@stemsystems.com> mentions:
>>>>>> "R" == Ruud  <rvtol+news@isolution.nl> writes:
>
>  R> Basically it first builds, than sorts an index.
>
>  R> The pre-computed (multi-)keys can often be optimized, see Uri's
>  R> Sort::Maker http://search.cpan.org/search?query=Sort::Maker
>  R> for facilities.
>
>gack, now i ave been mentioned and responding to a thread started by the
>moron xah. his flame on the ST shows how stupid he is. he calls it
>decorate/sort/undecorate but he doesn't know it was a well known
>technique way back in the 50's and 60's. typical of his narrow mind and
>lack of real understanding and computer history. the ST didn't invent it
>but just showed how to do it easily in perl. and the GRT didn't invent
>pack/sort either, it just (and Sort::Maker) just does it easily for you
>in perl. both the ST and GRT are implemetation idioms of a known sort
>optimization trick used in the real world. in pure algorithmic analysis,
>neither one would be even considered as they don't improve the actual
>growth curve of the sort. and all the other langs (deleted from the
>headers) are just showing their simple equivilent sort/cmp ops. BFD.

I don't really grok why this is such a big deal. 

"Schwartzian xform" (or whatever you want to call it) is just a nice, simple
way of explaining a well known concept that should seem fairly obvious to
most people. (I've always been partial to "alternate index" myself, but who
cares?)

'Course, some people probably want some huge words that no one
understands.

Hmm..

How about "the virtual paradomain transformation" ? :-) 

To keep fully buzzword compliant, we could maybe get one of the folks
from w3c.org or something to write up a huge 200 page document about
it. 

In the interest of being complete, we could implement the alternate
index (the virtual paradomain blah blah) in XML, using some namespace
tags and stuff describing the "methodology". An example could be written
using a DOM object for the "source data linkage descriptors". Proving
once again how XML can be used to solve all of our problems. 

Or...

We could just use common sense. Naaa! :-)

Jamie
-- 
http://www.geniegate.com                    Custom web programming
guhzo_42@lnubb.pbz (rot13)                User Management Solutions


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

Date: Wed, 30 Aug 2006 22:50:30 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <C11BC6B6.2BA6E%mstep@t-online.de>

On 30.08.2006 15:18, in article 8u2bf2h6367tdsebm94hh3uen6f1kv6ib6@4ax.com,
"Michele Dondi" <bik.mido@tiscalinet.it> wrote:

> All in all clumsy clumsy stuff. How 'bout an $addr example along with
> a description of how you want it to be parsed?


ok, dear Michele, I see I abused your time and patience. I will try this
weekend to make run this script. Meanwhile I changed it like follows, but
$first_name and $last_name, $gender, and $address is not working or inserted
only in a wacky way. Probably the data are not regular enough, to automat an
output with Perl ...

If you read in this script

    % ./addresses_comp.pl competitionsfunds.htm

against the page on:

http://podiuminternational.org/htdocs/addresses/competitions/competitionsfun
ds.htm

you will get the example you are asking about.


thanx again Michele and all, who responded, I learned a lot with this
script, also if I did not achieve, finally ...


marek


#! /usr/bin/perl

use strict;
use warnings;
use HTML::Entities;

$/ = undef;

my (@competitions);

while (<>)
  {
      push @competitions, (m!<a name="([^"]+)">.+?<dd>(.+?)</dd>!g);
  }

    
foreach (@competitions)
  {
    s!<span\s+class="comp2">([^<]+)</span>!Competition: $1\n\n!g;
    s!<br />!\n!g;
    s!<p [^>]+>!\n!g;
    s!<[^>]+>!!g;
  }

my $out_file1 = 'letter_comp_addr_01.adr';
open OUT1, '>', $out_file1 or die "Connot create your out_file $out_file1:
$!";
my $out_file2 = 'letter_comp_addr_02.adr';
open OUT2, '>', $out_file2 or die "Connot create your out_file $out_file2:
$!";

print OUT1 join ("\n\n", @competitions);
print OUT1 "\n\n";

my ($last_name, $first_name, $address, $phone, $gender, $competition,
$email, $comment);
foreach my $addr (@competitions)
  {
    foreach (split(/\n/, $addr))
      {
        ($first_name, $last_name) = $_ =~
/^([A-Z][a-z]+(?:\s+[A-Z][a-z]*\.?)?)\s+([A-Z][a-z]+(?:[-A-Z][a-z]+)?)\s?$/;
        if ($address and m/^[-,.\s\w]+$/)
          {
            $address .= "$&";
          }
        else
          {
            $address = "$& \\\\" if m/^[-,.\s\w]+$/;
          }
        if ($phone and m/^\s*(Fon:? .+|Fax:? .+|http:.+)/i)
          {
            $phone .= "$& ";
          }
        else
          {
            $phone = "$& " if m/^\s*(?:(Fon:? .+)|(Fon:? .+))/i;
          }
        ($gender) = $& if m/(Mrs(?:\.|\b)|Mr(?:\.|\b).+)/i;
        if ($gender)
          {
            if ( $gender =~ m/Mrs.?/ )
              {
                $gender = "w";
              }
              elsif ( $gender =~ m/Mr.?/ )
              {
                $gender = "m";
              }
              else
              {
                $gender = "u";
              }
            }
        ($competition) = $1 if m/^Competition:\s+(.+)/;
        ($email) = $_ =~ m"((&#\d+;)+)";
        $email = decode_entities($email) if $email;
        if ($comment and m/^\s?((?:International|National)
Competition)\s*$/i)
          {
            $comment .= "$1. ";
           }
        else
          {
            $comment = "$1. " if m/^\s?((?:International|National)
Competition)\s*$/i;
          }
        if ($comment and
m/^(Categories.+|Age.+|Application.+|mentioned.+)/i)
          {
            $comment .= "$1. ";
          }
        else
          {
            $comment = "$1. " if
m/^(Categories.+|Age.+|Application.+|mentioned.+)/i;
          }
      }
      if ($competition)
        {
          print OUT2 "\\addrentry\n";
          print OUT2 $last_name ? "\t{$last_name}\n" : "\t{last_name}\n";
          print OUT2 $first_name ? "\t{$first_name}\n" : "\t{first_name}\n";
          print OUT2 $address ? "\t{$address}\n" : "\t{address}\n";
          print OUT2 $phone ? "\t{$phone}\n" : "\t{phone}\n";
          print OUT2 "\t{$competition}\n";
          print OUT2 $gender ? "\t{$gender}\n" : "\t{gender}\n";
          print OUT2 $email ? "\t{$email}\n" : "\t{email}\n";
          print OUT2 $comment ? "\t{$comment}\n" : "\t{comment}\n";
        }
     ($last_name, $first_name, $address, $phone, $gender, $competition,
$email, $comment) = '';
  }

close OUT1;
close OUT2;



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

Date: 30 Aug 2006 09:49:16 -0700
From: "PeterSShenkin" <shenkin@gmail.com>
Subject: Can overloaded '+' return an array? If so, how?
Message-Id: <1156956556.295061.69620@h48g2000cwc.googlegroups.com>

The following sample code prints:

combine: result= [1 2 3 4]
main: ar = [4]

I expect it to print:

combine: result= [1 2 3 4]
main: ar = [1 2 3 4]

The issue is that "combine", which is the function that '+' maps to,
returns an array.  When, in the main program, I say:

my @ar = $ca1 + ca2

I expect the "combine" function to be called in list context.  But
evidently it is called in scalar context, because my @ar variable
receives the cardinality of the "result" array, rather than a copy of
the array.

Looking at Ch 13 of the Camel book, I don't see any restriction on
return values of overloaded operators; but maybe I'm just missing it.
If there's a way to do it, but I'm doing it wrong, I'd like to know
that.  Either way, please advise.

(If, instead of what I do in the example, I return a reference to the
array, and alter my main routine correspondingly, then, of course,
everything works.)

Thanks,
-P.

Example:

====================
use strict;

my $ca1 = ClassAct->new( 1, 3 );
my $ca2 = ClassAct->new( 2, 4 );

my @ar = $ca1 + $ca2;
print "main: ar = [@ar]\n";

{
    package ClassAct;

    use overload (
        '+' => "combine",
        fallback => 1,
    );

    sub combine {
        my $obj1 = shift;
        my $obj2 = shift;
        my @result = sort ( @{$obj1}, @{$obj2} );
        print "combine: result= [@result]\n";
        return @result;
    };

    sub new {
        my $class = shift;
        my $self = [
        ];
        while( my $value = shift ) {
            push @{$self}, $value;
        }
        bless $self, $class;
        return $self;
    }
}
====================



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

Date: Wed, 30 Aug 2006 18:59:02 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Can overloaded '+' return an array? If so, how?
Message-Id: <ed4n5m$26lc$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
PeterSShenkin
<shenkin@gmail.com>], who wrote in article <1156956556.295061.69620@h48g2000cwc.googlegroups.com>:
> The issue is that "combine", which is the function that '+' maps to,
> returns an array.  When, in the main program, I say:
> 
> my @ar = $ca1 + ca2
> 
> I expect the "combine" function to be called in list context.

Some hints: you forgot about cryptocontext.  What would you think

  myMultiplyArgs($ca1 + $ca2, $ca3 + $ca4, $ca5 + $ca6)

would return if your semantic would hold?

Overloading changes IMPLEMENTATION of operations; the SEMANTIC returns
the same.

> (If, instead of what I do in the example, I return a reference to the
> array, and alter my main routine correspondingly, then, of course,
> everything works.)

Enjoy it.  ;-)

Hope this helps,
Ilya


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

Date: 30 Aug 2006 19:16:17 GMT
From: xhoster@gmail.com
Subject: Re: Can overloaded '+' return an array? If so, how?
Message-Id: <20060830151638.945$Zo@newsreader.com>

"PeterSShenkin" <shenkin@gmail.com> wrote:
> The following sample code prints:
>
> combine: result= [1 2 3 4]
> main: ar = [4]
>
> I expect it to print:
>
> combine: result= [1 2 3 4]
> main: ar = [1 2 3 4]
>
> The issue is that "combine", which is the function that '+' maps to,
> returns an array.  When, in the main program, I say:
>
> my @ar = $ca1 + ca2
>
> I expect the "combine" function to be called in list context.  But
> evidently it is called in scalar context, because my @ar variable
> receives the cardinality of the "result" array, rather than a copy of
> the array.
>
> Looking at Ch 13 of the Camel book, I don't see any restriction on
> return values of overloaded operators; but maybe I'm just missing it.
>
> If there's a way to do it, but I'm doing it wrong, I'd like to know
> that.  Either way, please advise.


Your understanding seems to be correct (all overloaded operators are
called in scalar context), and you seem to be correct that this is not
well documented.  The closest thing to it seems to be, under overload's
section on <> operator:

            BUGS Even in list context, the iterator is currently called
            only once and  with scalar context.

(This fact seems to be true for all operators, but apparently is only
considered to be a bug for the <> operator.)

> (If, instead of what I do in the example, I return a reference to the
> array, and alter my main routine correspondingly, then, of course,
> everything works.)

Yep.  And, in fact, I would usually expect an overloaded addition
operator to turn something of the same class as (at least one of) it's
operands, so I suggest that not only should it return a ref, but a ref
that is blessed into ClassAct.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 30 Aug 2006 13:19:54 -0700
From: "PeterSShenkin" <shenkin@gmail.com>
Subject: Re: Can overloaded '+' return an array? If so, how?
Message-Id: <1156969194.578631.71170@e3g2000cwe.googlegroups.com>

xhoster@gmail.com wrote:

> Yep.  And, in fact, I would usually expect an overloaded addition
> operator to turn something of the same class as (at least one of) it's
> operands, so I suggest that not only should it return a ref, but a ref
> that is blessed into ClassAct.

That expectation is not fulfilled either in mathematics or in Perl
native types.

In Perl, an int divided by an int is not necessarily an int.

In mathematics, the dot product of two vectors is a scalar.  The outer
product is a matrix.

Thus, if the inability of an overloaded '+' to always return a scalar
was a conscious decision, I believe it was the wrong one.  What if you
want to add two arrays?

Be all this as it may, my thanks to those who responded.  I guessed
this is the way it would turn out, because I couldn't see anything I
was doing wrong.  I'll have to add it to my list of Perl sins (along
with the inability to handle IEEE exceptional values in a standard
way).

Cheers,
-P.



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

Date: 30 Aug 2006 13:22:14 -0700
From: "PeterSShenkin" <shenkin@gmail.com>
Subject: Re: Can overloaded '+' return an array? If so, how?
Message-Id: <1156969334.014418.282710@p79g2000cwp.googlegroups.com>


PeterSShenkin wrote:
> Thus, if the inability of an overloaded '+' to always return a scalar
> was a conscious decision, I believe it was the wrong one.  What if you
> want to add two arrays?

Whoops.... of course I meant "to only return a scalar...."

-P.



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

Date: 30 Aug 2006 13:24:08 -0700
From: "PeterSShenkin" <shenkin@gmail.com>
Subject: Re: Can overloaded '+' return an array? If so, how?
Message-Id: <1156969448.071369.293470@p79g2000cwp.googlegroups.com>


PeterSShenkin wrote:
> PeterSShenkin wrote:
> > Thus, if the inability of an overloaded '+' to always return a scalar
> > was a conscious decision, I believe it was the wrong one.  What if you
> > want to add two arrays?
>
> Whoops.... of course I meant "to only return a scalar...."


Whoops.. sigh.  "if the inability of an overloaded '+' to return
anything but
a scalar was a conscious decision, I believe it was the wrong one."

I'll shut up now. :-)

-P.



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

Date: 30 Aug 2006 13:40:56 -0700
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Can overloaded '+' return an array? If so, how?
Message-Id: <1156970456.718508.87870@b28g2000cwb.googlegroups.com>

PeterSShenkin wrote:
>
> The issue is that "combine", which is the function that '+' maps to,
> returns an array.  When, in the main program, I say:
>
> my @ar = $ca1 + ca2
>
> I expect the "combine" function to be called in list context.  But
> evidently it is called in scalar context, because my @ar variable
> receives the cardinality of the "result" array, rather than a copy of
> the array.
>
> ...
>
> (If, instead of what I do in the example, I return a reference to the
> array, and alter my main routine correspondingly, then, of course,
> everything works.)


   I fiddled around with your test code, and I found that, while the
code:

      my @ar = $ca1 + ca2;

is not called in list context, the following three functionally
equivalent lines:

      my @ar = $ca1->combine($ca2);
      my @ar = combine $ca1 $ca2;
      my @ar = ClassAct::combine($ca1, $ca2);

do return an array as you want -- without the need to change the
combine() method.

   (I don't know if this information is useful to you or not, but I
thought I'd share it anyway).

   -- Jean-Luc

--
perl -le "print(pack'B*','0'.unpack'B*',pack'w*',
5592691776,37562575106519616,25926642752,354130435682904)"



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

Date: 30 Aug 2006 14:07:42 -0700
From: "mumebuhi" <mumebuhi@gmail.com>
Subject: Close a Running Sub-Process
Message-Id: <1156972062.467350.13770@m79g2000cwm.googlegroups.com>

I have a problem closing a filehandle, which is a pipe to a forked
process. The forked process basically tails a log file in another
server. I need to stop the child process once a particular line is
found.

The code is as the following:
# start code
my $fh = undef;
my $child_process = "ssh username@host tail --follow=name
file_to_be_tailed"
open $fh, $child_process || Carp::confess("can't open $child_process:
$!");
while (<$fh>) {
  chomp;
  if (/successful/) {
    last;
  }
}
close $fh;
# end code

The script will block when it tries to close the filehandle. How do I
force it to close while tail is still running?

Thank you very much.


Buhi



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

Date: Wed, 30 Aug 2006 21:33:16 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Close a Running Sub-Process
Message-Id: <wunJg.9098$cw.3504@fed1read03>

mumebuhi <mumebuhi@gmail.com> wrote:
> I have a problem closing a filehandle, which is a pipe to a forked
> process. The forked process basically tails a log file in another
> server. I need to stop the child process once a particular line is
> found.
 
> The code is as the following:

It is not valid Perl code for a start.

	use warnings;
	use strict;

Would have should you that.  Actually it will not compile anyway.

> # start code
> my $fh = undef;
> my $child_process = "ssh username@host tail --follow=name
> file_to_be_tailed"

No ; at end of statement.

> open $fh, $child_process || Carp::confess("can't open $child_process:
> $!");

The format of $child_process shows that you are trying to open a file
for reading, nothing more... and the || has a high prority so as long as
$child_process is true then the right-hand side will be ignored.

> while (<$fh>) {
>  chomp;
>  if (/successful/) {
>    last;
>  }
> }
> close $fh;
> # end code
 
> The script will block when it tries to close the filehandle. How do I
> force it to close while tail is still running?

Not sure what is going on... but I suggest you clean up your code
properly first.

Axel

 


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

Date: 30 Aug 2006 14:40:24 -0700
From: "mumebuhi" <mumebuhi@gmail.com>
Subject: Re: Close a Running Sub-Process
Message-Id: <1156974024.088652.86060@p79g2000cwp.googlegroups.com>

# start
use strict;
use warnings;

my $fh = undef;
# there is a '|' at the end
my $child_process = "ssh username@host tail --follow=name
file_to_be_tailed |";
open $fh, $child_process || Carp::confess("can't open $child_process:
$!");
while (<$fh>) {
  chomp; 
  if (/successful/) { 
    last; 
  }
} 
close $fh; 
# end



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

Date: Wed, 30 Aug 2006 10:19:15 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.22 How can I match strings with multibyte characters?
Message-Id: <300820061019151119%brian.d.foy@gmail.com>

In article <slrnef9bi8.db6.hjp-usenet2@yoyo.hjp.at>, Peter J. Holzer
<hjp-usenet2@hjp.at> wrote:

> On 2006-08-29 19:03, PerlFAQ Server <brian@stonehenge.com> wrote:
> > 6.22: How can I match strings with multibyte characters?


> >     Starting from Perl 5.6 Perl has had some level of multibyte character
> >     support. Perl 5.8 or later is recommended. Supported multibyte character
> >     repertoires include Unicode, and legacy encodings through the Encode
> >     module. See perluniintro, perlunicode, and Encode.

> >     If you are stuck with older Perls,  ...

> I get the impression from this article that these problems are present
> in perl's unicode support. 

The problems with multi-character support are in the older versions of 
Perl.

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Wed, 30 Aug 2006 23:04:26 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 6.22 How can I match strings with multibyte characters?
Message-Id: <slrnefbvau.bkv.hjp-usenet2@yoyo.hjp.at>

On 2006-08-30 15:19, brian d foy <brian.d.foy@gmail.com> wrote:
> In article <slrnef9bi8.db6.hjp-usenet2@yoyo.hjp.at>, Peter J. Holzer
><hjp-usenet2@hjp.at> wrote:
>> On 2006-08-29 19:03, PerlFAQ Server <brian@stonehenge.com> wrote:
>> > 6.22: How can I match strings with multibyte characters?
>
>> >     Starting from Perl 5.6 Perl has had some level of multibyte character
>> >     support. Perl 5.8 or later is recommended. Supported multibyte character
>> >     repertoires include Unicode, and legacy encodings through the Encode
>> >     module. See perluniintro, perlunicode, and Encode.
>
>> >     If you are stuck with older Perls,  ...
>
>> I get the impression from this article that these problems are present
>> in perl's unicode support. 
>
> The problems with multi-character support are in the older versions of 
> Perl.

Yes. I know that. But when I ignore what I know and just read the
article that isn't clear at all. And the question isn't answered at all
for current perl versions. I'll try to formulate a clearer answer, but
it'll probably have to wait until the weekend.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

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:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#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 V10 Issue 9666
***************************************


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