[28596] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9960 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 13 11:06:01 2006

Date: Mon, 13 Nov 2006 08:05:07 -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           Mon, 13 Nov 2006     Volume: 10 Number: 9960

Today's topics:
    Re: "Did not find leading dereferencer" - new findings  <ro.naldfi.scher@gmail.com>
    Re: compare two string and make some operation on it? <bik.mido@tiscalinet.it>
    Re: compare two string and make some operation on it? <bol@adv.magwien.gv.at>
    Re: compare two string and make some operation on it? <mritty@gmail.com>
    Re: compare two string and make some operation on it? anno4000@radom.zrz.tu-berlin.de
        Loop over regexp groups <january.weiner@gmail.com>
    Re: Loop over regexp groups <rvtol+news@isolution.nl>
    Re: Loop over regexp groups micmath@gmail.com
    Re: Loop over regexp groups anno4000@radom.zrz.tu-berlin.de
    Re: Loop over regexp groups <january.weiner@gmail.com>
    Re: Loop over regexp groups <january.weiner@gmail.com>
    Re: Loop over regexp groups (reading news)
        parse recdescent oddity <spam.meplease@ntlworld.com>
    Re: perl threading; ->join; best method? <nospam-abuse@ilyaz.org>
        perldoc of study <bol@adv.magwien.gv.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Nov 2006 04:37:07 -0800
From: "Ronny" <ro.naldfi.scher@gmail.com>
Subject: Re: "Did not find leading dereferencer" - new findings to an old puzzle
Message-Id: <1163421427.699083.14150@i42g2000cwa.googlegroups.com>

Peter J. Holzer schrieb:
> > The use Switch was in the code only for historic reason, and I have
> > removed it. I don't know of course if *this* was sufficient to make
> > the error go away: After all, the removal of the statement made the
> > code a little bit smaller, so the problem might simply have
> > disappeared for *this* reason (removing a comment line instead of the
> > use Switch would have had the same effect).
>
> Possible, but unlikely. Unless you use another module which uses
> Text::Balanced, you aren't calling Text::Balanced any more and hence
> can't get any error messages from it any more.

Well, you are free to get a copy of my code to see what I'm using.
Aside from the Switch, I'm using:

use Carp qw(croak cluck confess);
use File::Temp qw(mktemp);
use File::Basename;

I have no idea whether these modules use Text::Balanced, but note that
even
when I do a "use Switch", I never actually *write* a switch statement.

Then I have the impression that the error message "comes from the
Switch module
and goes away when I remove it". I think this does not describe the
situation. If at
all, we can say that the Switch module somehow *masks* the real
error/warning
message. This means: I *do* have some construct which normally would
yield an
error (or warning) message, but instead I get the "leading
dereferencer" error; and
when I simplify the program (for example, by only removing a single
comment line
out of a set of other comment lines, in a completely different part of
the program),
the "leading dereferencer" error disappears and instead I see the
*real* error (or
warning) message.

If you can explain this behaviour just by the fact that I have a "use
Switch" at
the beginning, without ever using a switch, I am curious to know how
you do it...

> I don't think it has anything to do with the size. The problem was
> probably that the Switch module needs to parse the source code and that
> uses a different grammar than perl (which is unavoidable, as the purpose
> of Switch is to change the grammar). So changing a character which
> shouldn't make a difference in Perl does make a difference in
> Perl+Switch.

I've had a look at Switch.pm .... this module doesn't even have a BEGIN
section.
It definitely does not need to parse the source code of the whole
program.
Instead it works by passing around code blocks when a switch
"statement"
is actually used in my program.

Then I've checked Text::Balanced. Looks similarly harmless (nothing be
done
unless you actually *use* some of its features). The only *probably*
suspicious
line is an overloading of the string conversion, i.e.

use overload '""' => sub { "$_[0]->{error}, detected at offset
$_[0]->{pos}" };

and the "leading dereferencer" is triggered when on code analysis, a
variable
name was expected and the leading "$" or "@" or "%" was not found.
Still I didn't
see anything which might cause this error to pop up when none of the
features
in the "use" module are never actually called.

In addition, I would like to point out that I had the same error
message a few
months ago in a different context. Following a recommendation in this
newsgroup,
I found in that case that it helped to remove the prototype declaration
from a
function definition, and the problem disappeared (i.e. I got the "real"
error message
displayed again, instead of the "dereferencer" one).

There is one point in which I agree with you: The error message is
likely related
to the fact that Text::Balanced is somehow included in the compilation
- after
all, that message is defined there and the Perl compiler is unlikely to
invent
this wording on its own. But I don't believe that this is due to a bug
in Text::Balanced.
At least to me, it is very hard to imagine that a bug in a module,
which is only
"use"'d, but never "used" (pun intended), could turn a very valid error
message at
a completely different point in the source code, into a "Leading
Dereferencer"
one, unless we also assume a bug in the Perl compiler itself. This
would require
- if it is possible at all, which I doubt - such a deep "introspection"
in its own code,
that one would find a trace of it by glancing over the source code of
Balanced. 

Ronald



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

Date: Mon, 13 Nov 2006 10:53:28 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: compare two string and make some operation on it?
Message-Id: <3ffgl2p7acap7i5ug6ojt33or8b3q23tgc@4ax.com>

On Mon, 13 Nov 2006 08:44:22 +0100, "Tutico" <moreno@tututico.it>
wrote:

>Subject: compare two string and make some operation on it?
[snip]
>I need to compare two string and make some operation on it?

Who knows better than you?

>Boot strings are same size length. In real world they are much longer then
>10 characters, lenght of strings (files) is aprox 1 milion characters (1
>MB). I need fastest way to compare stings and make result. If I make
>comparing character by character and making operatin on string character by
>character, computing is to slow to be realy usefull.

What do you mean with "compare"? Equality? If so C<eq> is for testing
string equality. 1Mb is not that much by nowadays standards, and you
can safely hold your strings in memory. However you may be interested
in File::Compare.

>----------------------------------------------------
># 1234567890

?!?

>$a= "a...my....";
>$b= "..mom....w";

Incidentally, be careful when using $a and $b as general purpose
variables, as they're special. Read more about this in

  perldoc -f sort
  perldoc perlvar

>$result="a.momy...w"; # operation is "OK"
>
>but:
># 1234567890
>$a= "a...my....";
>$b= "..mox....w";
>$result="a...my...."; # result is first string $a and operation is "NOK"

It is still not entirely clear to me what you want to do, but I think
you may be interested in bitwise operators on strings. Read more about
them in

  perldoc perlop

>If is problem to use "." as empty character in Perl it is possible to use
>some other caracter like "?" , space " " , "*" , "_" , "-" or some other
>character.

I can hardly grok the concept of an "empty" charachter quite about in
any language, but the closest thing that springs to mind is "\0" and
if you like "." then you can tr/./\0/; but for this to be reliable you
have to be sure you don't have pre-existing \0's in your strings.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Mon, 13 Nov 2006 13:29:05 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: compare two string and make some operation on it?
Message-Id: <1163420945.68420@proxy.dienste.wien.at>

Michele Dondi:

> >$a= "a...my....";
> >$b= "..mom....w";
>
> Incidentally, be careful when using $a and $b as general purpose
> variables, as they're special.

Well, special inside of sort blocks, OK. But else (in this example)?

What's the difference between

$a = "...";
$b = "...";

and

$c = "...";
$d = "...";

in a string compare operation?

Greetings, Ferry

-- 
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at




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

Date: 13 Nov 2006 06:21:33 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: compare two string and make some operation on it?
Message-Id: <1163427692.728699.120540@i42g2000cwa.googlegroups.com>

Ferry Bolhar wrote:
> Michele Dondi:
>
> > >$a= "a...my....";
> > >$b= "..mom....w";
> >
> > Incidentally, be careful when using $a and $b as general purpose
> > variables, as they're special.
>
> Well, special inside of sort blocks, OK. But else (in this example)?
>
> What's the difference between
>
> $a = "...";
> $b = "...";
>
> and
>
> $c = "...";
> $d = "...";

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

$c = "foo";
$d = "bar";

print "$c $d\n";
__END__

Global symbol "$c" requires explicit package name at ./abcd.pl line 5.
Global symbol "$d" requires explicit package name at ./abcd.pl line 6.
Global symbol "$c" requires explicit package name at ./abcd.pl line 8.
Global symbol "$d" requires explicit package name at ./abcd.pl line 8.
Execution of ./abcd.pl aborted due to compilation errors.



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

$a = "foo";
$b = "bar";

print "$a $b\n";
__END__

foo bar



Paul Lalli



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

Date: 13 Nov 2006 14:33:36 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: compare two string and make some operation on it?
Message-Id: <4rre20Fsg59mU1@mid.dfncis.de>

Ferry Bolhar <bol@adv.magwien.gv.at> wrote in comp.lang.perl.misc:
> Michele Dondi:
> 
> > >$a= "a...my....";
> > >$b= "..mom....w";
> >
> > Incidentally, be careful when using $a and $b as general purpose
> > variables, as they're special.
> 
> Well, special inside of sort blocks, OK. But else (in this example)?
> 
> What's the difference between
> 
> $a = "...";
> $b = "...";
> 
> and
> 
> $c = "...";
> $d = "...";
> 
> in a string compare operation?

If the string compare operation involves sorting you can be in trouble.

Anno


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

Date: Mon, 13 Nov 2006 13:49:17 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Loop over regexp groups
Message-Id: <ej9pkd$bd7$1@sagnix.uni-muenster.de>

Hello,

I am matching a regexp with an a priori unknown number of groups.  I would
like to loop over all groups that were matched.  For example:

  /(\w+)\s(\w+)/ ; 
  #or 
  /(\w+)\s(\w+)\s(\w+)/ ; 
  # or something else

  @groups = ...???

  for( @groups ) {
    process_match( $_ ) ;
  }

Of course, the above example is simplifying reality and could be replaced
by split().  Here are more details on the problem:

I am processing protein sequence files in the FASTA format.  Depending on
the database, the FASTA headers may look like that:

>O81231 (Q81999) Dehydrogenase alpha subunit

or like that

>    O81231   123   Q81999

or

>gi|O81231||li|Q81999

or, possibly,

>O81231; synonyms: Q81999, P89812, O77781

or, basically, anything else.  As you might guess, I'm interested in the
"Q81231" or "Q81231" part.  The idea is that my utility can take an
optional "regexp" string that matches the type of headers that are found in
a given database; while looping through the database, the regexp is
matched, and entries are made for any of the synonymous identifiers found
in one header.

Currently, I am assuming that I will not find more than four synonims, and
I do the following:

  for( $1, $2, $3, $4 ) {
    last unless $_ ;
    process_match( $_ ) ;
  }

 ...which is, of course, crap.

Thanks in advance,
January

P.S. No, ([A-Z]\d{5}) would not match any identifier; the id format can
differ as well.  Sometimes it is HBA_HUMAN.

-- 


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

Date: Mon, 13 Nov 2006 14:30:20 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Loop over regexp groups
Message-Id: <ej9vqk.1hc.1@news.isolution.nl>

January Weiner schreef:

> I am matching a regexp with an a priori unknown number of groups.  I
> would like to loop over all groups that were matched.

Use the g-modifier, see perlre.
Or use split + grep.

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: 13 Nov 2006 05:45:28 -0800
From: micmath@gmail.com
Subject: Re: Loop over regexp groups
Message-Id: <1163425527.992313.87810@m73g2000cwd.googlegroups.com>



On Nov 13, 12:49 pm, January Weiner <january.wei...@gmail.com> wrote:
> I am matching a regexp with an a priori unknown number of groups.  I would
> like to loop over all groups that were matched.  For example:
>
>   /(\w+)\s(\w+)/ ;
>   #or
>   /(\w+)\s(\w+)\s(\w+)/ ;
>   # or something else
>
>   @groups = ...???
>
>   for( @groups ) {
>     process_match( $_ ) ;
>   }


use strict;
use warnings;

my %styles = (
    style1 => qr/([A-Z]\d{5})/,
    style2 => qr/([A-Z]{3}_[A-Z]{5})/,
);

my $header1 = "O81231 (Q81999) Dehydrogenase alpha subunit";
my $header2 = "O81231 (HBA_HUMAN) Dehydrogenase alpha subunit";

sub get_id {
    my ($header, $style) = @_;
    my ($id) = $header =~ m/$style/;
    return $id;
}

print get_id($header1, $styles{style1}), "\n"; # prints Q81999
print get_id($header2, $styles{style2}), "\n"; # prints HBA_HUMAN

__END__

I'm not sure I entirely understand your question, but if you want to
store regular expressions in a structure you can loop over, you just
need the qr// operator. If I'm off base, just clarify what you mean and
I'll try again, but I hope that helps! :-)

Regards,
Michael
http://www.perlcircus.org/



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

Date: 13 Nov 2006 14:12:39 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Loop over regexp groups
Message-Id: <4rrcqnFsn5amU1@mid.dfncis.de>

January Weiner  <january.weiner@gmail.com> wrote in comp.lang.perl.misc:
> Hello,
> 
> I am matching a regexp with an a priori unknown number of groups.  I would
> like to loop over all groups that were matched.  For example:
> 
>   /(\w+)\s(\w+)/ ; 
>   #or 
>   /(\w+)\s(\w+)\s(\w+)/ ; 
>   # or something else
> 
>   @groups = ...???

Very easy.  Assuming the regex (with captures) in $re, and the string to
match in $_ (untested):

    my @groups = m/$re/;

A regex in list context returns all its captures.

>   for( @groups ) {
>     process_match( $_ ) ;
>   }

Right on.  Even

    process_match( $_) for m/$re/;

would work.

Anno


> Of course, the above example is simplifying reality and could be replaced
> by split().  Here are more details on the problem:
> 
> I am processing protein sequence files in the FASTA format.  Depending on
> the database, the FASTA headers may look like that:
> 
> >O81231 (Q81999) Dehydrogenase alpha subunit
> 
> or like that
> 
> >    O81231   123   Q81999
> 
> or
> 
> >gi|O81231||li|Q81999
> 
> or, possibly,
> 
> >O81231; synonyms: Q81999, P89812, O77781
> 
> or, basically, anything else.  As you might guess, I'm interested in the
> "Q81231" or "Q81231" part.  The idea is that my utility can take an
> optional "regexp" string that matches the type of headers that are found in
> a given database; while looping through the database, the regexp is
> matched, and entries are made for any of the synonymous identifiers found
> in one header.
> 
> Currently, I am assuming that I will not find more than four synonims, and
> I do the following:
> 
>   for( $1, $2, $3, $4 ) {
>     last unless $_ ;
>     process_match( $_ ) ;
>   }
> 
> ...which is, of course, crap.
> 
> Thanks in advance,
> January
> 
> P.S. No, ([A-Z]\d{5}) would not match any identifier; the id format can
> differ as well.  Sometimes it is HBA_HUMAN.
> 
> -- 




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

Date: Mon, 13 Nov 2006 16:05:07 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Loop over regexp groups
Message-Id: <eja1j2$bd7$2@sagnix.uni-muenster.de>

micmath@gmail.com wrote:
> I'm not sure I entirely understand your question, but if you want to
> store regular expressions in a structure you can loop over, you just
> need the qr// operator. If I'm off base, just clarify what you mean and
> I'll try again, but I hope that helps! :-)

Sorry, I think I did not get it clear.  Assume the following:

- you have a regular expression
- the regular expression contains an unknown number of groups enclosed in
  parentheses
- you would like to print these groups, one by one.


If you know exactly that there are two groups, you can do the following:

  $a =~ /(one) (two)/ ;

  print "group one: $1\n" ;
  print "group two: $2\n" ;

My question is: what can I do if I do not know the number of the groups?
For example, the regexp can be
  /(one) (two)/

or it can be
  /(one) (two) (three)/

or even
  /(one) (two) (three) (four)/

My question rephrased: how can I loop through the automatic variables $1
 ... $n, where n is the number of groups in the regexp?

Regards,
j.

-- 


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

Date: Mon, 13 Nov 2006 16:07:32 +0100 (CET)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Loop over regexp groups
Message-Id: <eja1nk$bd7$3@sagnix.uni-muenster.de>

anno4000@radom.zrz.tu-berlin.de wrote:
> Very easy.  Assuming the regex (with captures) in $re, and the string to
> match in $_ (untested):

>     my @groups = m/$re/;

> A regex in list context returns all its captures.

Yes! That's it. Thank you so much. (very intuitive, when you think of it!)

j.

-- 


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

Date: Mon, 13 Nov 2006 15:50:46 GMT
From: "Mumia W. (reading news)" <paduille.4060.mumia.w@earthlink.net>
Subject: Re: Loop over regexp groups
Message-Id: <qv06h.6206$L6.4320@newsread3.news.pas.earthlink.net>

On 11/13/2006 06:49 AM, January Weiner wrote:
> Hello,
> 
> I am matching a regexp with an a priori unknown number of groups.  I would
> like to loop over all groups that were matched.  For example:
> 
>   /(\w+)\s(\w+)/ ; 
>   #or 
>   /(\w+)\s(\w+)\s(\w+)/ ; 
>   # or something else
> 
>   @groups = ...???
> 
>   for( @groups ) {
>     process_match( $_ ) ;
>   }
> 
> Of course, the above example is simplifying reality and could be replaced
> by split().  Here are more details on the problem:
> 
> I am processing protein sequence files in the FASTA format.  Depending on
> the database, the FASTA headers may look like that:
> 
>> O81231 (Q81999) Dehydrogenase alpha subunit
> 
> or like that
> 
>>    O81231   123   Q81999
> 
> or
> 
>> gi|O81231||li|Q81999
> 
> or, possibly,
> 
>> O81231; synonyms: Q81999, P89812, O77781
> 
> or, basically, anything else.  As you might guess, I'm interested in the
> "Q81231" or "Q81231" part.  The idea is that my utility can take an
> optional "regexp" string that matches the type of headers that are found in
> a given database; while looping through the database, the regexp is
> matched, and entries are made for any of the synonymous identifiers found
> in one header.
> 
> Currently, I am assuming that I will not find more than four synonims, and
> I do the following:
> 
>   for( $1, $2, $3, $4 ) {
>     last unless $_ ;
>     process_match( $_ ) ;
>   }
> 
> ....which is, of course, crap.
> 
> Thanks in advance,
> January
> 
> P.S. No, ([A-Z]\d{5}) would not match any identifier; the id format can
> differ as well.  Sometimes it is HBA_HUMAN.
> 

This

my @ids = /([[:upper:]\d]{3,})/g;

is a possibility.


-- 
paduille.4060.mumia.w@earthlink.net


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

Date: 13 Nov 2006 07:53:34 -0800
From: "doolittle" <spam.meplease@ntlworld.com>
Subject: parse recdescent oddity
Message-Id: <1163433214.722450.268790@e3g2000cwe.googlegroups.com>

I introduced an error in my recdescent grammar with the line

              |'AP'|'CA') <commit> ...Text

This brought up the error

      ERROR (line 18): Untranslatable item encountered: ")"
                (Hint: Did you misspell ")" or forget to comment it
out?)

but only if $RD_TRACE was not set to '1'

If I put the line

$RD_TRACE = 1;

in my module, everything appeared to go OK, ie no errors reported

?



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

Date: Mon, 13 Nov 2006 09:30:30 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: perl threading; ->join; best method?
Message-Id: <ej9dvm$e8m$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to

<xhoster@gmail.com>], who wrote in article <20061112182050.498$t6@newsreader.com>:
> > >     $_->join() foreach threads->list();

> > This assumes that threads->list() returns only joinable threads,

> Isn't that exactly what it does?

You mean *now*?  Maybe...  I do not care much, since last time I
checked, Perl threading API was pretty lame in this respect.  E.g., is
there a way to specify that "I do not care to ever join this thread"
at thread start?  This could shave some overhead...

> > and
> > that they all return in a suitable order.

> From the original post, there was no order dependent code.  So any
> order is suitable.

For the OP, yes.  But I was discussing an API, which should better
work in a more general case too.

Ilya


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

Date: Mon, 13 Nov 2006 15:54:54 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: perldoc of study
Message-Id: <1163429694.397139@proxy.dienste.wien.at>

Hi @ all,

in the docs of the study function, I've found this:

"From each search string, the rarest character is
selected, based on some static frequency tables constructed
from some C programs and English text."

However, when looking at the sources (pp_study in pp.c),
it seems the only thing to find the "rarest character is this:

for (ch = 256; ch; --ch)
    *sfirst++ = -1;
sfirst -= 256;

while (--pos >= 0) {
   ch = s[pos];
    if (sfirst[ch] >= 0)
        snext[pos] = sfirst[ch] - pos;
    else
        snext[pos] = -pos;
    sfirst[ch] = pos;
}

Where are the 'static frequency tables constructed from
some C programs and English text'?

Greetings, Ferry

-- 
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at




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

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


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