Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Dermot
2009/11/23 Dave Tang : > On Tue, 24 Nov 2009 09:39:09 +1000, Dermot wrote: > >> 2009/11/23 Dave Tang : >>> >>> On Mon, 23 Nov 2009 23:14:51 +1000, Shawn H Corey >>> >>> Hi Shawn et al., >>> >>> I am also intrigued by the \z anchor. I had a look at perldoc perlreref >>> and >>> found >>> >>> \z  M

Re: 答复: Regex to get last 3 digits of a number.

2009-11-24 Thread Shawn H Corey
gaochong wrote: > But I think substr is better . > > my $str="0111"; > my $r=substr ($str,-3); TimTowTdi (there is more than one way to do it): my $n = "0111"; my $last_3_chars = join('',(split(//,$n))[-3..-1]); print "$last_3_chars\n"; -- Just my 0.0002 million do

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Yonghua Peng
--- On Tue, 24/11/09, Shawn H Corey wrote: > From: Shawn H Corey > Subject: Re: 答复: Regex to get last 3 digits of a number. > To: "gaochong" > Cc: "'John W. Krahn'" , "'Perl Beginners'" > > Received: Tuesday, 24 November, 2009, 8:26 PM > gaochong wrote: > > But I think substr is better . >

RE: Find out if a method calls another method

2009-11-24 Thread Hack, Gabi (ext)
> From: Steve Bertrand [mailto:st...@ibctech.ca] > Hi everyone, > > I'm curious to know if there is an easy way to scan a list of module > files and identify how many subs are calling a different specific sub. > > I've got a method that must be called once by each and every > sub within > the

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Dave Tang
On Tue, 24 Nov 2009 18:33:30 +1000, Dermot wrote: 2009/11/23 Dave Tang : On Tue, 24 Nov 2009 09:39:09 +1000, Dermot wrote: 2009/11/23 Dave Tang : On Mon, 23 Nov 2009 23:14:51 +1000, Shawn H Corey Hi Shawn et al., I am also intrigued by the \z anchor. I had a look at perldoc perl

Re: Find out if a method calls another method

2009-11-24 Thread Steve Bertrand
Hack, Gabi (ext) wrote: >> From: Steve Bertrand [mailto:st...@ibctech.ca] >> Hi everyone, >> >> I'm curious to know if there is an easy way to scan a list of module >> files and identify how many subs are calling a different specific sub. >> >> I've got a method that must be called once by each an

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Shawn H Corey
Yonghua Peng wrote: > > --- On Tue, 24/11/09, Shawn H Corey wrote: > >> From: Shawn H Corey >> Subject: Re: 答复: Regex to get last 3 digits of a number. >> To: "gaochong" >> Cc: "'John W. Krahn'" , "'Perl Beginners'" >> >> Received: Tuesday, 24 November, 2009, 8:26 PM >> gaochong wrote: >>> B

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Alan Haggai Alavi
Hi, The following should work: my $number = '0111'; my ($index) = ( $number =~ /\d+(\d{3})/ ); $index would contain the last three digits: '111'. To learn about regular expressions in Perl, you can go through `perldoc perlre` and `perldoc perlretut`. The Perldoc website (http://pe

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread shadow52
On Nov 23, 9:22 am, jwkr...@shaw.ca (John W. Krahn) wrote: > shadow52 wrote: > > Hey everyone, > > Hello, > > > I am trying to get just the last 3 numbers from the following number > > from perl using regexs but I have not had no success so I was hoping > > that I could get a little help on this. I

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread shadow52
On Nov 23, 9:22 am, jwkr...@shaw.ca (John W. Krahn) wrote: > shadow52 wrote: > > Hey everyone, > > Hello, > > > I am trying to get just the last 3 numbers from the following number > > from perl using regexs but I have not had no success so I was hoping > > that I could get a little help on this. I

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread shadow52
On Nov 23, 9:22 am, jwkr...@shaw.ca (John W. Krahn) wrote: > shadow52 wrote: > > Hey everyone, > > Hello, > > > I am trying to get just the last 3 numbers from the following number > > from perl using regexs but I have not had no success so I was hoping > > that I could get a little help on this. I

Re: how to write a debug-print sub with one argument?

2009-11-24 Thread Mark_Galeck
Thank you very much for the great suggestions, I appreciate! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread shadow52
On Nov 23, 9:22 am, jwkr...@shaw.ca (John W. Krahn) wrote: > shadow52 wrote: > > Hey everyone, > > Hello, > > > I am trying to get just the last 3 numbers from the following number > > from perl using regexs but I have not had no success so I was hoping > > that I could get a little help on this. I

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread John W. Krahn
Shawn H Corey wrote: Yonghua Peng wrote: --- On Tue, 24/11/09, Shawn H Corey wrote: From: Shawn H Corey Subject: Re: 答�: Regex to get last 3 digits of a number. To: "gaochong" Cc: "'John W. Krahn'" , "'Perl Beginners'" Received: Tuesday, 24 November, 2009, 8:26 PM gaochong wrote: But

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread Philip Potter
2009/11/23 Alan Haggai Alavi : > my $number = '0111'; > my ($index) = ( $number =~ /\d+(\d{3})/ ); > > $index would contain the last three digits: '111'. \d+ should be \d* above, otherwise you fail to match on 3 digit numbers: p...@tui:~/tmp$ perl -E ' my $number = q{111}; my ($index)

Re: return {}->{'name'};

2009-11-24 Thread Dermot
2009/11/18 Randal L. Schwartz : > > I prefer a pattern that looks more like this: > > sub expensive_to_calculate { > >  my $self = shift; >  my $input = shift; # cache on this scalar > >  our %cache_for_expensive_to_calculate; >  return $cache_for_expensive_to_calculate{$input} ||= do { >    expens

Re: return {}->{'name'};

2009-11-24 Thread Randal L. Schwartz
> "Dermot" == Dermot writes: Dermot> It' is perl, v5.6.2, on a modperl 1, ... Dermot> I guess the question is: Will the declaration of our %cache within a Dermot> function-orientated sub-routine render it always uninitialized? I believe what you are seeing is that %cache is per-child, so

IF... OR... not working

2009-11-24 Thread Chad Morland
I have a feeling I am missing something basic so I am looking to this list for help. Assume the following: my $vhost_server_name = qw(somedomain.com); my @vhost_server_alias_array = qw(www.somedomain.com *.somedomain.com sub.somedomain.com); foreach my $vhost_server_alias (@vhost_server_alias_ar

Re: IF... OR... not working

2009-11-24 Thread Steve Bertrand
Chad Morland wrote: > I have a feeling I am missing something basic so I am looking to this list > for help. > > Assume the following: > > my $vhost_server_name = qw(somedomain.com); > my @vhost_server_alias_array = qw(www.somedomain.com *.somedomain.com > sub.somedomain.com); > > foreach my $vh

Re: IF... OR... not working

2009-11-24 Thread Chad Morland
Thanks Steve, that seemed to do the trick. Perhaps my reading comprehension was not up to par when I was reading up on these operators. I figured AND(&&) operators had to match both conditions in order to be true, hence me trying to use OR(||). I guess it's the opposite? -CM On Tue, Nov 24, 200

Re: IF... OR... not working

2009-11-24 Thread Shawn H Corey
Chad Morland wrote: > Thanks Steve, that seemed to do the trick. > > Perhaps my reading comprehension was not up to par when I was reading up on > these operators. > > I figured AND(&&) operators had to match both conditions in order to be > true, hence me trying to use OR(||). I guess it's the o

Re: Find out if a method calls another method

2009-11-24 Thread C.DeRykus
On Nov 23, 8:08 am, st...@ibctech.ca (Steve Bertrand) wrote: > Hi everyone, > > I'm curious to know if there is an easy way to scan a list of module > files and identify how many subs are calling a different specific sub. > > I've got a method that must be called once by each and every sub within >

Re: IF... OR... not working

2009-11-24 Thread Robert Wohlfarth
On Tue, Nov 24, 2009 at 11:12 AM, Chad Morland wrote: > I figured AND(&&) operators had to match both conditions in order to be > true, hence me trying to use OR(||). I guess it's the opposite? > > On Tue, Nov 24, 2009 at 12:03 PM, Steve Bertrand wrote: > > > Chad Morland wrote: > > > my $vhost_

Documentation practices

2009-11-24 Thread Steve Bertrand
I've noticed that the POD for several modules do not include method usage for the functions/methods that are designed as 'internal-only'. I've reached a stage where not having POD for ALL of my methods is becoming overwhelmingly cumbersome, as I have to read the code to remember usage. Is there a

Re: Documentation practices

2009-11-24 Thread Shawn H Corey
Steve Bertrand wrote: > I've noticed that the POD for several modules do not include method > usage for the functions/methods that are designed as 'internal-only'. > > I've reached a stage where not having POD for ALL of my methods is > becoming overwhelmingly cumbersome, as I have to read the cod

Re: Documentation practices

2009-11-24 Thread Jim Gibson
On 11/24/09 Tue Nov 24, 2009 11:09 AM, "Steve Bertrand" scribbled: > I've noticed that the POD for several modules do not include method > usage for the functions/methods that are designed as 'internal-only'. > > I've reached a stage where not having POD for ALL of my methods is > becoming ove

Re: Documentation practices

2009-11-24 Thread Philip Potter
2009/11/24 Steve Bertrand : > I've noticed that the POD for several modules do not include method > usage for the functions/methods that are designed as 'internal-only'. > > I've reached a stage where not having POD for ALL of my methods is > becoming overwhelmingly cumbersome, as I have to read th

a match question

2009-11-24 Thread 兰花仙子
Hi, # perl -le '$_="aXXXb"; print "one word is $1" while(/(X*)/g);' one word is one word is XXX one word is one word is what are the three empty values in the output? Thanks. # perl -v This is perl, v5.8.8 built for i486-linux-thread-multi -- To unsubscribe, e-mail: beginners-unsubscr...@per

Re: a match question

2009-11-24 Thread John W. Krahn
Orchid Fairy (À¼»¨ÏÉ×Ó) wrote: Hi, Hello, # perl -le '$_="aXXXb"; print "one word is $1" while(/(X*)/g);' one word is one word is XXX one word is one word is what are the three empty values in the output? The pattern X* can match zero characters. $ perl -le'$_="aXXXb"; print "one word is

Re: a match question

2009-11-24 Thread Shawn H Corey
Orchid Fairy (兰花仙子) wrote: > Hi, > > # perl -le '$_="aXXXb"; print "one word is $1" while(/(X*)/g);' > one word is > one word is XXX > one word is > one word is > > > what are the three empty values in the output? Adding pos() (see `perldoc -f pos`) shows what is happening: $ perl -le '$_="aXX

Re: a match question

2009-11-24 Thread 兰花仙子
On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey wrote: > > It seems to be picking up an extra empty string after a non-zero length > match. > Thanks John and Shawn. Yup what let me be confused is that, why there is an additional empty string there? -- To unsubscribe, e-mail: beginners-unsubscr.

Re: a match question

2009-11-24 Thread Jim Gibson
On 11/24/09 Tue Nov 24, 2009 4:42 PM, "Orchid Fairy (兰花仙子)" scribbled: > On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey wrote: > >> >> It seems to be picking up an extra empty string after a non-zero length >> match. >> > > Thanks John and Shawn. > Yup what let me be confused is that, wh

Re: a match question

2009-11-24 Thread Shawn H Corey
Jim Gibson wrote: > On 11/24/09 Tue Nov 24, 2009 4:42 PM, "Orchid Fairy (兰花仙子)" > scribbled: > >> On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey wrote: >> >>> It seems to be picking up an extra empty string after a non-zero length >>> match. >>> >> Thanks John and Shawn. >> Yup what let me b

Re: a match question

2009-11-24 Thread John W. Krahn
Shawn H Corey wrote: Also: $ perl -le '$_="aXXXb"; @captured = $_ =~ m{ (X*) }gmsx;print "captured: <", join( ">, <",@captured), ">"' captured: <>, , <>, <> @captured = $_ =~ m{ (X*) }gmsx; Is usually written as: @captured = /X*/g; John -- The programmer is fighting against the two most

Re: a match question

2009-11-24 Thread John W. Krahn
Shawn H Corey wrote: Jim Gibson wrote: On 11/24/09 Tue Nov 24, 2009 4:42 PM, "Orchid Fairy (À¼»¨ÏÉ×Ó)" scribbled: On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey wrote: It seems to be picking up an extra empty string after a non-zero length match. Thanks John and Shawn. Yup what let m

Re: a match question

2009-11-24 Thread 兰花仙子
On Wed, Nov 25, 2009 at 11:06 AM, John W. Krahn wrote: > > $ perl -le '$_="aXXXb"; print "one word is $1 at $-[0] to $+[0]" while > /(X*)/g;' > one word is  at 0 to 0 > one word is XXX at 1 to 4 > one word is  at 4 to 4 > one word is  at 5 to 5 > Thanks that's so smart~ But I'm still confused s