[30750] in Perl-Users-Digest
Perl-Users Digest, Issue: 1995 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 21 03:09:47 2008
Date: Fri, 21 Nov 2008 00:09:11 -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 Fri, 21 Nov 2008 Volume: 11 Number: 1995
Today's topics:
Re: Chase credit cards HERE ALL <jurgenex@hotmail.com>
Re: Copy constructor and Dup method in Perl sln@netherlands.com
Dose package name has to be the same as the filename? ( <PengYu.UT@gmail.com>
Re: Dose package name has to be the same as the filenam <spamtrap@dot-app.org>
Re: Dose package name has to be the same as the filenam <PengYu.UT@gmail.com>
Re: Dose package name has to be the same as the filenam <spamtrap@dot-app.org>
Re: Hash keys with range of values -- How? <whynot@pozharski.name>
Re: How to find all the strings in a long that are at m <jurgenex@hotmail.com>
Re: How to find all the strings in a long that are at m sln@netherlands.com
Re: How to find all the strings in a long that are at m <spamtrap@dot-app.org>
Re: How to find all the strings in a long that are at m <PengYu.UT@gmail.com>
Re: How to find all the strings in a long that are at m <PengYu.UT@gmail.com>
Re: How to find all the strings in a long that are at m <pilcrow6@gmail.com>
Re: How to find all the strings in a long that are at m sln@netherlands.com
How to iterator array in order? <PengYu.UT@gmail.com>
Re: How to iterator array in order? sln@netherlands.com
Re: How to iterator array in order? <jurgenex@hotmail.com>
new CPAN modules on Fri Nov 21 2008 (Randal Schwartz)
post increment or pre increment? <PengYu.UT@gmail.com>
Re: post increment or pre increment? sln@netherlands.com
Re: post increment or pre increment? <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Nov 2008 21:35:16 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Chase credit cards HERE ALL
Message-Id: <04ici4h8r3ehhamkafc7l9fv9e4shk2sce@4ax.com>
bushrat60@yahoo.com wrote:
>Chase Credit Cards & CreditCard Offers at CreditCardFlyers
There are several credit card modules on CPAN, did you check there?
jue
------------------------------
Date: Fri, 21 Nov 2008 04:25:14 GMT
From: sln@netherlands.com
Subject: Re: Copy constructor and Dup method in Perl
Message-Id: <3kcci4d82hennehpce9v9mdll6qhbvei56@4ax.com>
On Wed, 19 Nov 2008 17:36:55 -0800, Jim Gibson <jimsgibson@gmail.com> wrote:
>In article <laq8i4dv2peu23jcjl0jtnsleji2rf8591@4ax.com>,
><sln@netherlands.com> wrote:
>
>> Hi, I have a need for a Class copy constructor and wonder
>> if anybody has implemented this.
>
>See the dclone function of the Storable module or the article
><http://www.stonehenge.com/merlyn/UnixReview/col30.html>
I knew about deep copy. I read the whole article. I didn't look
at the dclone function yet (as they recommend on that page).
I found it interresting, the recursive sub to find array's that
need to be dup'd. And I'm even better appretiative of Dumper now.
I had some anonymous sub ref's hanging around, wondered about them.
One thing is that if you 'empty' an array, reference or not, by
declaring it with () again, does it create another reference to it
(anonymous or if a reference is taken of it before its cleared)?
I haven't looked at it specifically yet in terms of deep copy but
something like this I will have to resolve:
$href = {};
$href->{aray} = ['1','2'];
or
@tt = ('1','2');
$href->{aray} = \@tt;
@{$href->{aray}} = ();
I know $href->{aray} is a reference,
but if a copy of $href was made,
before it was cleared with = (), is the data
still intact in the copy, or would I have to
do an explicit $newhref->{aray} = [@{$href->{aray}}] ?
Convuluted. Thanks!
sln
------------------------------
Date: Thu, 20 Nov 2008 18:51:31 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: Dose package name has to be the same as the filename? (for OO)
Message-Id: <469c10c3-bbd9-4477-97a4-b98fa9e522da@n10g2000yqm.googlegroups.com>
Hi,
In this webpage, the package name is the same as the filename.
http://www.tutorialspoint.com/perl/perl_oo_perl.htm
I checked some perl modules, it seems that the filename is always the
same as the package name. I'm wondering if this is required. Or the
package name and the filename can be different?
Thanks,
Peng
------------------------------
Date: Thu, 20 Nov 2008 22:22:40 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Dose package name has to be the same as the filename? (for OO)
Message-Id: <m1prkp2267.fsf@dot-app.org>
Peng Yu <PengYu.UT@gmail.com> writes:
> http://www.tutorialspoint.com/perl/perl_oo_perl.htm
>
> I checked some perl modules, it seems that the filename is always the
> same as the package name. I'm wondering if this is required. Or the
> package name and the filename can be different?
In a non-OO module that exports functions, they have to be the same for
Exporter to do its thing. When you use() a module - let's call it "Foo",
the following steps are basically what happens:
BEGIN {
require Foo;
import Foo qw(args);
}
The second step is optional - if there's no import() function in module
Foo, the use() will still succeed.
Now, let's suppose that package Bar is in Foo.pm. Foo.pm is compiled by
the require() with no problems. Because its code is in package Bar, the
import() function, explicitly declared or inherited from Exporter, is
compiled into that package too.
But the use() still tries to call an import() function in package
Foo. Worse, because import() is optional it will *silently* fail. The
only clue the user will get that something has gone wrong, is that none
of the functions declared in package Bar will be usable without a fully-
specified package name, i.e. Bar::baz(), because the import() failed to
create aliases for them in the current package.
Other things can depend on the filename = package convention too. Take
perldoc, for example. If a user of your module runs "perldoc Foo" to get
your module's docs, it will read the docs found in Foo.pm. The user's
going to be confused if those docs describe a package named "Bar."
Even if your module is "pure" OO and doesn't export anything, following
the established convention helps avoid confusion - imagine a maintenance
programmer looking at your script a year from now, and seeing this:
use Foo;
my $bar = Bar->new();
It's not very intuitive to see a class Bar defined in Foo.pm.
So no, it's not required in theory. But the convention of naming them
the same is followed so widely, that in practice it's really more or
less required.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 20 Nov 2008 19:54:53 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: Re: Dose package name has to be the same as the filename? (for OO)
Message-Id: <c7827d03-b20b-4174-b681-97f553cc0c6d@13g2000yql.googlegroups.com>
On Nov 20, 9:22=A0pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> Peng Yu <PengYu...@gmail.com> writes:
> >http://www.tutorialspoint.com/perl/perl_oo_perl.htm
>
> > I checked some perl modules, it seems that the filename is always the
> > same as the package name. I'm wondering if this is required. Or the
> > package name and the filename can be different?
>
> In a non-OO module that exports functions, they have to be the same for
> Exporter to do its thing. When you use() a module - let's call it "Foo",
> the following steps are basically what happens:
>
> =A0 =A0 BEGIN {
> =A0 =A0 =A0 =A0 require Foo;
> =A0 =A0 =A0 =A0 import Foo qw(args);
> =A0 =A0 }
>
> The second step is optional - if there's no import() function in module
> Foo, the use() will still succeed.
>
> Now, let's suppose that package Bar is in Foo.pm. Foo.pm is compiled by
> the require() with no problems. Because its code is in package Bar, the
> import() function, explicitly declared or inherited from Exporter, is
> compiled into that package too.
>
> But the use() still tries to call an import() function in package
> Foo. Worse, because import() is optional it will *silently* fail. The
> only clue the user will get that something has gone wrong, is that none
> of the functions declared in package Bar will be usable without a fully-
> specified package name, i.e. Bar::baz(), because the import() failed to
> create aliases for them in the current package.
>
> Other things can depend on the filename =3D package convention too. Take
> perldoc, for example. If a user of your module runs "perldoc Foo" to get
> your module's docs, it will read the docs found in Foo.pm. The user's
> going to be confused if those docs describe a package named "Bar."
>
> Even if your module is "pure" OO and doesn't export anything, following
> the established convention helps avoid confusion - imagine a maintenance
> programmer looking at your script a year from now, and seeing this:
>
> =A0 =A0 use Foo;
> =A0 =A0 my $bar =3D Bar->new();
>
> It's not very intuitive to see a class Bar defined in Foo.pm.
>
> So no, it's not required in theory. But the convention of naming them
> the same is followed so widely, that in practice it's really more or
> less required.
Therefore, in one file, only one package can be defined practically,
right? If that is the case, why we still need to have the keyword
'package'? Why perl not just use the file name as the package name?
Thanks,
Peng
------------------------------
Date: Fri, 21 Nov 2008 01:06:40 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Dose package name has to be the same as the filename? (for OO)
Message-Id: <m1k5ax4npr.fsf@dot-app.org>
Peng Yu <PengYu.UT@gmail.com> writes:
> Therefore, in one file, only one package can be defined practically,
> right? If that is the case, why we still need to have the keyword
> 'package'? Why perl not just use the file name as the package name?
Because forcing the issue would not be the Perl Way (tm). Remember the
Perl motto - There Is More Than One Way To Do It, or TIMTOWTDI. What
this means in practice is, if you want to shoot yourself in the foot,
Perl will let you.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Fri, 21 Nov 2008 00:17:36 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Hash keys with range of values -- How?
Message-Id: <slrngibog4.6q2.whynot@orphan.zombinet>
On 2008-11-20, Ed Jay <edMbj@aes-intl.com> wrote:
> I'm trying to use a hash to replace:
>
> if ($scoreR >= 0) {$th_right = TH1;}
> if ($scoreR >= 30) {$th_right = TH2;}
> if ($scoreR >= 75) {$th_right = TH3;}
> if ($scoreR >= 120) {$th_right = TH4;}
> if ($scoreR >= 150) {$th_right = TH5;}
>
> My hash:
> %thVal = ("x1","TH1","x2","TH2","x3","TH3","x4","TH4","x5","TH5");
>
> I want to use: $th_right = $thVal{$scoreR};
>
> What is the syntax for x1, x2,...x5? I've tried
> %thVal = (">=0","TH1",">=30","TH2",etc), but it doesn't work.
None. Your syntax is OK. (Just a suggestion -- put B<if>s in reverse
order and replace the 2nd and so on with B<elsif>s.)
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: Thu, 20 Nov 2008 19:06:24 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <ju8ci41dqunhi8ddm2q6hkioj22hr7i5o8@4ax.com>
Peng Yu <PengYu.UT@gmail.com> wrote:
>On Nov 20, 3:46 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>> Peng Yu <PengYu...@gmail.com> wrote innews:8f31f2be-e332-4d6d-a5ad-337e18208809@o2g2000yqd.googlegroups.com:
>> > It seems that the perldoc is not easy to understand by a newbie.
It is a reference, concise and accurate (as much as possible), it is not
and never will be a tutorial.
>> > While
>> > it explains @-, the perldoc keeps on referring to others things that I
>> > don't understand. Can somebody help explain @- for me with more
>> > examples?
Then you will have to look for a tutorial or dig down into those other
things. Very often it is not possible or not desirable to explain
something without making references to other concepts. And @- is
certainly not the right place to explain grouping in regular
expressions.
>> I looked at the perldoc perlvar page to remind myself what it said. I am
>> unable to figure out how one could make it clearer:
>Thank you the example. I see what it means. In general, I think the
>document can be made easier to read with more examples.
But there are examples in that section:
<quote>
After a match against some variable $var:
"$`" is the same as "substr($var, 0, $-[0])"
"$&" is the same as "substr($var, $-[0], $+[0] - $-[0])"
"$'" is the same as "substr($var, $+[0])"
"$1" is the same as "substr($var, $-[1], $+[1] - $-[1])"
"$2" is the same as "substr($var, $-[2], $+[2] - $-[2])"
"$3" is the same as "substr $var, $-[3], $+[3] - $-[3])"
</quote>
>I agree that adding more examples would make the manual to long to be
>read by experts. But I think that this can be solved by having two
>sets of document---one is with examples, the other is without
>examples.
Go ahead and write the fivehundredandnintysecond tutorial about Perl.
You will find that either you are repeating yourself all over the place
or you start using references all over the place because Perl's concept
are so intertwined and cannot be explained stand-alone.
Not to mention the ensuing maintenance nightmare when you have to fix
something all over the place.
jue
------------------------------
Date: Fri, 21 Nov 2008 03:52:15 GMT
From: sln@netherlands.com
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <79bci4dvaf9eahdrgit1h35iq853mipmaj@4ax.com>
On Thu, 20 Nov 2008 19:06:24 -0800, Jürgen Exner <jurgenex@hotmail.com> wrote:
>Peng Yu <PengYu.UT@gmail.com> wrote:
>>On Nov 20, 3:46 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>>> Peng Yu <PengYu...@gmail.com> wrote innews:8f31f2be-e332-4d6d-a5ad-337e18208809@o2g2000yqd.googlegroups.com:
>>> > It seems that the perldoc is not easy to understand by a newbie.
>
>It is a reference, concise and accurate (as much as possible), it is not
>and never will be a tutorial.
What are you defending, a reference?? A reference is and has always been
another word for a POS! It is just a list of prototypes.
A reference has been and always will be nothing of significance at all.
Used by somebody who already knows it all to adjust for typo's and syntax.
I hope those people don't actually write the referece.
>
>>> > While
>>> > it explains @-, the perldoc keeps on referring to others things that I
>>> > don't understand. Can somebody help explain @- for me with more
>>> > examples?
>
>Then you will have to look for a tutorial or dig down into those other
>things. Very often it is not possible or not desirable to explain
>something without making references to other concepts. And @- is
>certainly not the right place to explain grouping in regular
>expressions.
Why the f*ck not? Can't explain something you have no idea where you
learned it from, then blowhard to someone else needing answer's? Get off man..
>
>>> I looked at the perldoc perlvar page to remind myself what it said. I am
>>> unable to figure out how one could make it clearer:
>
>>Thank you the example. I see what it means. In general, I think the
>>document can be made easier to read with more examples.
>
>
>But there are examples in that section:
><quote>
> After a match against some variable $var:
>
> "$`" is the same as "substr($var, 0, $-[0])"
> "$&" is the same as "substr($var, $-[0], $+[0] - $-[0])"
> "$'" is the same as "substr($var, $+[0])"
> "$1" is the same as "substr($var, $-[1], $+[1] - $-[1])"
> "$2" is the same as "substr($var, $-[2], $+[2] - $-[2])"
> "$3" is the same as "substr $var, $-[3], $+[3] - $-[3])"
></quote>
>
>
>>I agree that adding more examples would make the manual to long to be
>>read by experts. But I think that this can be solved by having two
>>sets of document---one is with examples, the other is without
>>examples.
>
>Go ahead and write the fivehundredandnintysecond tutorial about Perl.
>You will find that either you are repeating yourself all over the place
>or you start using references all over the place because Perl's concept
>are so intertwined and cannot be explained stand-alone.
>
You my friend should not be involved in Perl. You have cactus up your
ass, every move you make when reading posts on this group drive's that
POINT home brother!!!
>Not to mention the ensuing maintenance nightmare when you have to fix
>something all over the place.
>
>jue
Go fly a friggin kite friend..
sln
------------------------------
Date: Fri, 21 Nov 2008 00:58:00 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <m1od094o47.fsf@dot-app.org>
Peng Yu <PengYu.UT@gmail.com> writes:
> On Nov 20, 9:06 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>>
>> But there are examples in that section:
>> <quote>
>> After a match against some variable $var:
>>
>> "$`" is the same as "substr($var, 0, $-[0])"
>> "$&" is the same as "substr($var, $-[0], $+[0] - $-[0])"
>> "$'" is the same as "substr($var, $+[0])"
>> "$1" is the same as "substr($var, $-[1], $+[1] - $-[1])"
>> "$2" is the same as "substr($var, $-[2], $+[2] - $-[2])"
>> "$3" is the same as "substr $var, $-[3], $+[3] - $-[3])"
>> </quote>
>
> I didn't understand the above examples because it refers to $-[0],
> which was exactly what I wanted to understand.
Arrays are referred to with @, but array *elements* with $. So, given
the array @-, its first element is $-[0].
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 20 Nov 2008 18:40:39 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <75ed77e4-43aa-446e-9f7b-1942be8a80f8@l14g2000yqj.googlegroups.com>
On Nov 20, 3:46=A0pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> Peng Yu <PengYu...@gmail.com> wrote innews:8f31f2be-e332-4d6d-a5ad-337e18=
208809@o2g2000yqd.googlegroups.com:
>
> > On Nov 20, 12:19=A0am, "John W. Krahn" <some...@example.com> wrote:
> >> Peng Yu wrote:
> >> > On Nov 19, 7:55 pm, s...@netherlands.com wrote:
>
> ...
>
> >> > I can not find what '$-[$i]' means in your code on online perl
> >> > documentation. Would you please let me know its meaning? Where is
> >> > its documentation?
>
> >> You can find out about the @- array in:
>
> >> perldoc perlvar
>
> > It seems that the perldoc is not easy to understand by a newbie. While
> > it explains @-, the perldoc keeps on referring to others things that I
> > don't understand. Can somebody help explain @- for me with more
> > examples?
>
> I looked at the perldoc perlvar page to remind myself what it said. I am
> unable to figure out how one could make it clearer:
>
> <blockquote>
> This array holds the offsets of the beginnings of the last
> successful submatches in the currently active dynamic scope.
> $-[0] is the offset into the string of the beginning of the
> entire match. The *n*th element of this array holds the offset
> of the *n*th submatch, so $-[1] is the offset where $1 begins,
> $-[2] the offset where $2 begins, and so on.
> </blockquote>
>
> Consider the example below:
>
> C:\DOCUME~1\asu1\LOCALS~1\Temp> cat t.pl
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $s =3D '123abcABC';
>
> if ( $s =3D~ /^([0-9]+([0-9]))[a-z]+([A-Z]([A-Z]+))$/ ) {
> =A0 =A0 print "@-\n";
> =A0 =A0 print "$_\n" for $1, $2, $3, $4;
>
> }
>
> __END__
>
> In this case, a successful match would produce
>
> $1 =3D 123 (offset =3D 0)
> $2 =3D 3 =A0 (offset =3D 2)
> $3 =3D ABC (offset =3D 6)
> $4 =3D BC =A0(offset =3D 7)
>
> The entire match starts at offset 0, so we have @- =3D (0, 0, 2, 6, 7).
Thank you the example. I see what it means. In general, I think the
document can be made easier to read with more examples.
I agree that adding more examples would make the manual to long to be
read by experts. But I think that this can be solved by having two
sets of document---one is with examples, the other is without
examples.
Thanks,
Peng
------------------------------
Date: Thu, 20 Nov 2008 21:08:13 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <255734ce-9bcf-4445-88e7-484e042022be@y18g2000yqn.googlegroups.com>
On Nov 20, 9:06=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> Peng Yu <PengYu...@gmail.com> wrote:
> >On Nov 20, 3:46=A0pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> >> Peng Yu <PengYu...@gmail.com> wrote innews:8f31f2be-e332-4d6d-a5ad-337=
e18208809@o2g2000yqd.googlegroups.com:
> >> > It seems that the perldoc is not easy to understand by a newbie.
>
> It is a reference, concise and accurate (as much as possible), it is not
> and never will be a tutorial.
>
> >> > While
> >> > it explains @-, the perldoc keeps on referring to others things that=
I
> >> > don't understand. Can somebody help explain @- for me with more
> >> > examples?
>
> Then you will have to look for a tutorial or dig down into those other
> things. Very often it is not possible or not desirable to explain
> something without making references to other concepts. And @- is
> certainly not the right place to explain grouping in regular
> expressions.
>
> >> I looked at the perldoc perlvar page to remind myself what it said. I =
am
> >> unable to figure out how one could make it clearer:
> >Thank you the example. I see what it means. In general, I think the
> >document can be made easier to read with more examples.
>
> But there are examples in that section:
> <quote>
> =A0 =A0 =A0 =A0 =A0 =A0 After a match against some variable $var:
>
> =A0 =A0 =A0 =A0 =A0 =A0 "$`" is the same as "substr($var, 0, $-[0])"
> =A0 =A0 =A0 =A0 =A0 =A0 "$&" is the same as "substr($var, $-[0], $+[0] - =
$-[0])"
> =A0 =A0 =A0 =A0 =A0 =A0 "$'" is the same as "substr($var, $+[0])"
> =A0 =A0 =A0 =A0 =A0 =A0 "$1" is the same as "substr($var, $-[1], $+[1] - =
$-[1])"
> =A0 =A0 =A0 =A0 =A0 =A0 "$2" is the same as "substr($var, $-[2], $+[2] - =
$-[2])"
> =A0 =A0 =A0 =A0 =A0 =A0 "$3" is the same as "substr $var, $-[3], $+[3] - =
$-[3])"
> </quote>
I didn't understand the above examples because it refers to $-[0],
which was exactly what I wanted to understand.
> >I agree that adding more examples would make the manual to long to be
> >read by experts. But I think that this can be solved by having two
> >sets of document---one is with examples, the other is without
> >examples.
>
> Go ahead and write the fivehundredandnintysecond tutorial about Perl.
> You will find that either you are repeating yourself all over the place
> or you start using references all over the place because Perl's concept
> are so intertwined and cannot be explained stand-alone.
>
> Not to mention the ensuing maintenance nightmare when you have to fix
> something all over the place.
I agree your points. But I think that the perldoc shall have as less
cyclic references as possible. If the example that you mentioned in
the perldoc is not cyclic referred, it would easier to read.
Thanks,
Peng
------------------------------
Date: Thu, 20 Nov 2008 20:38:01 -0800
From: Pilcrow <pilcrow6@gmail.com>
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <jieci4hu02qd98u5rl7av8j5ccavki9csk@4ax.com>
On Thu, 20 Nov 2008 10:06:33 -0800, "John W. Krahn"
<someone@example.com> wrote:
>Pilcrow wrote:
>> On Wed, 19 Nov 2008 15:34:17 -0800 (PST), Peng Yu <PengYu.UT@gmail.com>
>> wrote:
>>>
>>> Suppose I have a long string $a, and a test string $b.
>>>
>>> I want to fine all the substrings in $a, whose length is the same as
>>> $b with at most n mismatches.
>>>
>>> For example, string 'abcdef' and string 'aacdxf' have two mismatches
>>> at the 2nd character and the 5th character.
>>>
>>> I'm wondering if this can be done easily in perl. Can I use regular
>>> expression to solve this problem?
>>
>> Not too hard the simple way.
>> -------------------------------------------------------------------
>> #!/usr/bin/perl
>> use strict; use warnings;
>>
>> my $a =
>> "abcdefbacdefabbdefaaaaacdxfaaacdefcdefbacdefabbdefaaaaacdxfaaacdefaacdxfaacdfx";
>> my $b = "aacdxf";
>>
>> my @a = split //,$a;
>> my @b = split //,$b;
>> my $limit = 2;
>> my $cnt;
>> my $lenb = length $b;
>> my @substrings = ();
>>
>> print "\nmatching '$a' against '$b'\n";
>>
>> OUTER:
>> for (my $i = 0; $i <= $#a-$lenb+1; $i++) {
>> $cnt = 0;
>> for (my $j = 0; $j <= $#b; $j++) {
>> $cnt++ unless $a[$i+$j] eq $b[$j];
>> next OUTER if $cnt > $limit;
>> }
>> my $sub = substr($a,$i,$lenb);
>> # push @substrings, $sub; # alternate output
>> print "match '$sub' at offset $i\n";
>> }
>
>Or more simpler as:
>
>#!/usr/bin/perl
>use strict;
>use warnings;
>
>my $a =
>'abcdefbacdefabbdefaaaaacdxfaaacdefcdefbacdefabbdefaaaaacdxfaaacdefaacdxfaacdfx';
>my $b = 'aacdxf';
>
>my $limit = 2;
>my $lenb = length $b;
>
>print "\nmatching '$a' against '$b'\n";
>
>while ( $a =~ /(?=(.{$lenb}))/sog ) {
> next if ( $1 ^ $b ) =~ tr/\0//c > $limit;
> print "match '$1' at offset $-[0]\n";
> }
>
>__END__
>
Very elegant and fast, but you don't need all the modifiers /sog to the
regex, just /g will do.
------------------------------
Date: Fri, 21 Nov 2008 04:54:40 GMT
From: sln@netherlands.com
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <2cfci4t43qgsrgc9hsvkbelf37rn5nfg8b@4ax.com>
On Thu, 20 Nov 2008 20:38:01 -0800, Pilcrow <pilcrow6@gmail.com> wrote:
>On Thu, 20 Nov 2008 10:06:33 -0800, "John W. Krahn"
><someone@example.com> wrote:
>
>>Pilcrow wrote:
>>> On Wed, 19 Nov 2008 15:34:17 -0800 (PST), Peng Yu <PengYu.UT@gmail.com>
>>> wrote:
>>>>
>>>> Suppose I have a long string $a, and a test string $b.
>>>>
>>>> I want to fine all the substrings in $a, whose length is the same as
>>>> $b with at most n mismatches.
>>>>
>>>> For example, string 'abcdef' and string 'aacdxf' have two mismatches
>>>> at the 2nd character and the 5th character.
>>>>
>>>> I'm wondering if this can be done easily in perl. Can I use regular
>>>> expression to solve this problem?
>>>
>>> Not too hard the simple way.
>>> -------------------------------------------------------------------
>>> #!/usr/bin/perl
>>> use strict; use warnings;
>>>
>>> my $a =
>>> "abcdefbacdefabbdefaaaaacdxfaaacdefcdefbacdefabbdefaaaaacdxfaaacdefaacdxfaacdfx";
>>> my $b = "aacdxf";
>>>
>>> my @a = split //,$a;
>>> my @b = split //,$b;
>>> my $limit = 2;
>>> my $cnt;
>>> my $lenb = length $b;
>>> my @substrings = ();
>>>
>>> print "\nmatching '$a' against '$b'\n";
>>>
>>> OUTER:
>>> for (my $i = 0; $i <= $#a-$lenb+1; $i++) {
>>> $cnt = 0;
>>> for (my $j = 0; $j <= $#b; $j++) {
>>> $cnt++ unless $a[$i+$j] eq $b[$j];
>>> next OUTER if $cnt > $limit;
>>> }
>>> my $sub = substr($a,$i,$lenb);
>>> # push @substrings, $sub; # alternate output
>>> print "match '$sub' at offset $i\n";
>>> }
>>
>>Or more simpler as:
>>
>>#!/usr/bin/perl
>>use strict;
>>use warnings;
>>
>>my $a =
>>'abcdefbacdefabbdefaaaaacdxfaaacdefcdefbacdefabbdefaaaaacdxfaaacdefaacdxfaacdfx';
>>my $b = 'aacdxf';
>>
>>my $limit = 2;
>>my $lenb = length $b;
>>
>>print "\nmatching '$a' against '$b'\n";
>>
>>while ( $a =~ /(?=(.{$lenb}))/sog ) {
>> next if ( $1 ^ $b ) =~ tr/\0//c > $limit;
>> print "match '$1' at offset $-[0]\n";
>> }
>>
>>__END__
>>
>
>Very elegant and fast, but you don't need all the modifiers /sog to the
>regex, just /g will do.
>
Actually, he needs 'so' as well. If this is used in a multi-lined
way, the '.' needs the 's' modifier if it is possible a '\n' is encounterred
and could be part of the pattern.
The 'o' suggests to not recompile, which might happen, don't know, anything is
possible. By including both, no harm, ho foul.
sln
------------------------------
Date: Thu, 20 Nov 2008 20:39:04 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: How to iterator array in order?
Message-Id: <e8564471-8e7d-43d8-84b9-1c0a3769bfc2@s9g2000prm.googlegroups.com>
Hi,
I know at least three ways to iterator an array. But I'm not sure if
the first two iteration methods would iterator the array in order
(from the first element to the last element). Can somebody let me
know?
What is the best way to iterator an array?
Thanks,
Peng
#!/usr/bin/perl
@array = (1, 2, 3, 4);
foreach(@array) {
print "$_\n";
}
for my $elem (@array) {
print "$elem\n";
}
for($i = 0; $i <= $#array; ++ $i) {
print "$array[$i]\n";
}
------------------------------
Date: Fri, 21 Nov 2008 05:15:13 GMT
From: sln@netherlands.com
Subject: Re: How to iterator array in order?
Message-Id: <ongci4dfdd9gvanda6a4cv3f6rs29n8kkf@4ax.com>
On Thu, 20 Nov 2008 20:39:04 -0800 (PST), Peng Yu <PengYu.UT@gmail.com> wrote:
>Hi,
>
>I know at least three ways to iterator an array. But I'm not sure if
>the first two iteration methods would iterator the array in order
>(from the first element to the last element). Can somebody let me
>know?
>
>What is the best way to iterator an array?
>
>Thanks,
>Peng
>
>#!/usr/bin/perl
>
>@array = (1, 2, 3, 4);
>
>foreach(@array) {
> print "$_\n";
>}
>
>for my $elem (@array) {
> print "$elem\n";
>}
>
>for($i = 0; $i <= $#array; ++ $i) {
> print "$array[$i]\n";
>}
Yes, all three would. The 'foreach' is a special,
unrelated case. The target becomes an alias for the
actual element. If you write to the target, you write
to the element, be careful on that one.
sln
------------------------------
Date: Thu, 20 Nov 2008 21:30:41 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to iterator array in order?
Message-Id: <79hci494tlp2cbsi0o3edmaod8qqosngr9@4ax.com>
Peng Yu <PengYu.UT@gmail.com> wrote:
>I know at least three ways to iterator an array. But I'm not sure if
>the first two iteration methods would iterator the array in order
>(from the first element to the last element). Can somebody let me
>know?
>What is the best way to iterator an array?
>@array = (1, 2, 3, 4);
>
>foreach(@array) {
> print "$_\n";
>}
>
>for my $elem (@array) {
> print "$elem\n";
>}
That's exactly the same as the first version except that you are using a
different variable ($_ versus $elem). "for" and "foreach" are synonyms.
Which one is better depends only on if you want to use $_ (often as the
default in following operations) or not.
>for($i = 0; $i <= $#array; ++ $i) {
> print "$array[$i]\n";
>}
This does something totally different because it iterates over the
indices of the array.
BTW: if you are using $#array instead of the length of the array then
you probably should also start your iteration with $[ instead of with 0.
The combination you are using doesn't make much sense because your start
value is hardcoded to ignores non-default values for $[ while your end
respects them.
As for your original question: use whatever is is more appropriate for
the task at hand: if you want to iterate over the elements then do so.
If you want to iterate over the indices (sometimes that cannot be
avoided) then iterate over the indices.
jue
------------------------------
Date: Fri, 21 Nov 2008 05:42:26 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Fri Nov 21 2008
Message-Id: <KAo56q.1Kp0@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Apache-LogRegex-1.5
http://search.cpan.org/~peterhi/Apache-LogRegex-1.5/
Parse a line from an Apache logfile into a hash
----
Apache2-ASP-2.00_24
http://search.cpan.org/~johnd/Apache2-ASP-2.00_24/
ASP for Perl, reloaded.
----
Apache2-ASP-2.00_25
http://search.cpan.org/~johnd/Apache2-ASP-2.00_25/
ASP for Perl, reloaded.
----
Apache2-Archive-0.1
http://search.cpan.org/~damog/Apache2-Archive-0.1/
Expose archive files through the Apache web server.
----
App-TaskBuilder-1.000
http://search.cpan.org/~hdp/App-TaskBuilder-1.000/
build empty, dependency-only distributions
----
App-ZofCMS-Plugin-NavMaker-0.0103
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-NavMaker-0.0103/
ZofCMS plugin for making navigation bars
----
App-ZofCMS-Plugin-UserLogin-0.0103
http://search.cpan.org/~zoffix/App-ZofCMS-Plugin-UserLogin-0.0103/
restrict access to pages based on user accounts
----
CGI-ExceptionManager-0.01
http://search.cpan.org/~tokuhirom/CGI-ExceptionManager-0.01/
DebugScreen with detach!
----
CGI-ExceptionManager-0.02
http://search.cpan.org/~tokuhirom/CGI-ExceptionManager-0.02/
DebugScreen with detach!
----
CGI-IDS-1.0103
http://search.cpan.org/~hinnerk/CGI-IDS-1.0103/
PerlIDS - Perl Website Intrusion Detection System (XSS, CSRF, SQLI, LFI etc.)
----
Catalyst-Authentication-AuthTkt-0.07
http://search.cpan.org/~karman/Catalyst-Authentication-AuthTkt-0.07/
shim for Apache::AuthTkt
----
Catalyst-Controller-RequestToken-0.04
http://search.cpan.org/~hide/Catalyst-Controller-RequestToken-0.04/
Handling transaction token across forms
----
Catalyst-Plugin-Params-Demoronize-1.0
http://search.cpan.org/~diz/Catalyst-Plugin-Params-Demoronize-1.0/
convert common UTF-8 and Windows-1252 characters to their ASCII equivalents
----
Catalyst-Plugin-SmartURI-0.030
http://search.cpan.org/~rkitover/Catalyst-Plugin-SmartURI-0.030/
Configurable URIs for Catalyst
----
Class-Wheel-0.02
http://search.cpan.org/~plcgi/Class-Wheel-0.02/
simple class wheel
----
Config-Any-Merge-0.06
http://search.cpan.org/~mdom/Config-Any-Merge-0.06/
Overrinding of configuration variables based on file order
----
Config-Find-0.25
http://search.cpan.org/~salva/Config-Find-0.25/
Find configuration files in the native OS fashion
----
Coro-5.0
http://search.cpan.org/~mlehmann/Coro-5.0/
coroutine process abstraction
----
Crypt-SKey-0.09
http://search.cpan.org/~kwilliams/Crypt-SKey-0.09/
Perl S/Key calculator
----
DBD-drizzle-0.002
http://search.cpan.org/~capttofu/DBD-drizzle-0.002/
MySQL driver for the Perl5 Database Interface (DBI)
----
Data-Microformat-0.04
http://search.cpan.org/~ussjoin/Data-Microformat-0.04/
A base class for hCards and related modules
----
DayDayUp-0.02
http://search.cpan.org/~fayland/DayDayUp-0.02/
good good study, day day up
----
DayDayUp-0.03
http://search.cpan.org/~fayland/DayDayUp-0.03/
good good study, day day up
----
Encode-UTR22-0.14
http://search.cpan.org/~mhosken/Encode-UTR22-0.14/
Implement Unicode TR22 complex conversions
----
Git-PurePerl-0.33
http://search.cpan.org/~lbrocard/Git-PurePerl-0.33/
A Pure Perl interface to Git repositories
----
HTML-Toc-0.92
http://search.cpan.org/~fvulto/HTML-Toc-0.92/
Generate, insert and update HTML Table of Contents.
----
HTTP-Session-0.22
http://search.cpan.org/~tokuhirom/HTTP-Session-0.22/
simple session
----
IO-AIO-3.17
http://search.cpan.org/~mlehmann/IO-AIO-3.17/
Asynchronous Input/Output
----
Inline-Python-0.27
http://search.cpan.org/~nine/Inline-Python-0.27/
Write Perl subs and classes in Python.
----
JSON-XS-2.231
http://search.cpan.org/~mlehmann/JSON-XS-2.231/
JSON serialising/deserialising, done correctly and fast
----
JavaScript-Packer-0.0101
http://search.cpan.org/~nevesenin/JavaScript-Packer-0.0101/
Perl version of Dean Edwards' Packer.js
----
LWP-Simple-WithCache-0.02
http://search.cpan.org/~leeym/LWP-Simple-WithCache-0.02/
LWP::Simple with cache
----
Mail-SPF-Iterator-0.04
http://search.cpan.org/~sullr/Mail-SPF-Iterator-0.04/
iterative SPF lookup
----
Mail-SPF-Iterator-0.05
http://search.cpan.org/~sullr/Mail-SPF-Iterator-0.05/
iterative SPF lookup
----
MediaWiki-API-0.21
http://search.cpan.org/~exobuzz/MediaWiki-API-0.21/
Provides a Perl interface to the MediaWiki API (http://www.mediawiki.org/wiki/API)
----
MediaWiki-API-0.22
http://search.cpan.org/~exobuzz/MediaWiki-API-0.22/
Provides a Perl interface to the MediaWiki API (http://www.mediawiki.org/wiki/API)
----
MobileFilterWURFLFilter-0.2
http://search.cpan.org/~ifuschini/MobileFilterWURFLFilter-0.2/
----
NCGI-0.12
http://search.cpan.org/~mlawren/NCGI-0.12/
A Common Gateway Interface (CGI) Class
----
POE-Component-Server-SimpleSMTP-1.32
http://search.cpan.org/~bingos/POE-Component-Server-SimpleSMTP-1.32/
A simple to use POE SMTP Server.
----
Padre-Plugin-AcmePlayCode-0.04
http://search.cpan.org/~fayland/Padre-Plugin-AcmePlayCode-0.04/
Acme::PlayCode Plugin for Padre
----
Padre-Plugin-CPAN-0.04
http://search.cpan.org/~fayland/Padre-Plugin-CPAN-0.04/
CPAN in Padre
----
Padre-Plugin-Encrypt-0.02
http://search.cpan.org/~fayland/Padre-Plugin-Encrypt-0.02/
encrypt/decrypt file in Padre
----
Padre-Plugin-HTML-Export-0.02
http://search.cpan.org/~fayland/Padre-Plugin-HTML-Export-0.02/
export highlighted HTML in Padre
----
Padre-Plugin-Validator-0.03
http://search.cpan.org/~fayland/Padre-Plugin-Validator-0.03/
validate HTML/CSS in Padre
----
Padre-Plugin-ViewInBrowser-0.02
http://search.cpan.org/~fayland/Padre-Plugin-ViewInBrowser-0.02/
view selected doc in browser for Padre
----
Parse-Gnaw-0.21
http://search.cpan.org/~gslondon/Parse-Gnaw-0.21/
Define a grammar and create a parser by calling nothing but perl subroutines.
----
Pod-Simple-Wiki-Wikka-0.08
http://search.cpan.org/~dstaal/Pod-Simple-Wiki-Wikka-0.08/
A class for creating Pod to Wikka wiki filters.
----
SQL-DB-0.17
http://search.cpan.org/~mlawren/SQL-DB-0.17/
Perl interface to SQL Databases
----
SysAdmin-0.01
http://search.cpan.org/~marr/SysAdmin-0.01/
Perl master class for SysAdmin wrapper modules.
----
Term-TermKey-0.01
http://search.cpan.org/~pevans/Term-TermKey-0.01/
perl wrapper around libtermkey
----
TestGen4Web-Runner-0.10
http://search.cpan.org/~mackers/TestGen4Web-Runner-0.10/
A PERL module to replay files recorded with TestGen4Web
----
Text-FindIndent-0.01
http://search.cpan.org/~smueller/Text-FindIndent-0.01/
Heuristically determine the indent style
----
Text-FindIndent-0.02
http://search.cpan.org/~smueller/Text-FindIndent-0.02/
Heuristically determine the indent style
----
URI-ParseSearchString-More-0.10
http://search.cpan.org/~oalders/URI-ParseSearchString-More-0.10/
Extract search strings from more referrers.
----
URI-Platonic-0.03
http://search.cpan.org/~masaki/URI-Platonic-0.03/
Platonic and Distinct URIs
----
WWW-Mechanize-1.51_03
http://search.cpan.org/~petdance/WWW-Mechanize-1.51_03/
Handy web browsing in a Perl object
----
WWW-Myspace-0.91
http://search.cpan.org/~stevenc/WWW-Myspace-0.91/
Access MySpace.com profile information from Perl
----
WWW-Ohloh-API-1.0_1
http://search.cpan.org/~yanick/WWW-Ohloh-API-1.0_1/
Ohloh API implementation
----
Wiki-OpenWiki-v01
http://search.cpan.org/~goyali/Wiki-OpenWiki-v01/
----
XML-Feed-Format-hAtom-0.5
http://search.cpan.org/~simonw/XML-Feed-Format-hAtom-0.5/
plugin to provide transparent parsing and generation support for hAtom to XML::Feed
----
o2sms-3.31
http://search.cpan.org/~mackers/o2sms-3.31/
A module to send SMS messages using the website of O2 Ireland
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Thu, 20 Nov 2008 20:23:30 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: post increment or pre increment?
Message-Id: <ec97c28c-f570-4e0c-84f4-c6063cc761b1@z1g2000yqn.googlegroups.com>
Hi,
I learned in C++, that it is better to use pre increment rather than
post increment. I'm wondering which one is better to use in perl, for
example, in a for loop.
for(my $i = 0; $i <10; ++ $i)
or
for(my $i = 0; $i <10; $i ++)
Which one is better?
Thanks,
Peng
------------------------------
Date: Fri, 21 Nov 2008 04:39:00 GMT
From: sln@netherlands.com
Subject: Re: post increment or pre increment?
Message-Id: <c9eci4ltgr15rkpspd9vrp5glbf9n42emo@4ax.com>
On Thu, 20 Nov 2008 20:23:30 -0800 (PST), Peng Yu <PengYu.UT@gmail.com> wrote:
>Hi,
>
>I learned in C++, that it is better to use pre increment rather than
>post increment. I'm wondering which one is better to use in perl, for
>example, in a for loop.
>
>for(my $i = 0; $i <10; ++ $i)
>
>or
>
>for(my $i = 0; $i <10; $i ++)
>
>Which one is better?
>
>Thanks,
>Peng
I think the same rules apply. I never use pre increment
in general.
But you would never do something like a function lvalue in C++:
if (func() == 5)...
better this
if (5 == func())
sln
------------------------------
Date: Thu, 20 Nov 2008 21:32:47 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: post increment or pre increment?
Message-Id: <ishci4ltlm4icuhusu93nducg8vb3c6h0b@4ax.com>
Peng Yu <PengYu.UT@gmail.com> wrote:
>Hi,
>
>I learned in C++, that it is better to use pre increment rather than
>post increment. I'm wondering which one is better to use in perl,
It depends on what you want to do. In that expression, do you need the
old value before the increment or the new value after the increment?
>example, in a for loop.
>
>for(my $i = 0; $i <10; ++ $i)
>
>or
>
>for(my $i = 0; $i <10; $i ++)
>
>Which one is better?
Neither, nor. The best is a very simple and much more readable
for my $i (0..9)
jue
------------------------------
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 V11 Issue 1995
***************************************