[31383] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2635 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 14 00:09:44 2009

Date: Tue, 13 Oct 2009 21:09:09 -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           Tue, 13 Oct 2009     Volume: 11 Number: 2635

Today's topics:
    Re: FAQ 9.19 How do I return the user's mail address? <kst-u@mib.org>
    Re: FAQ 9.19 How do I return the user's mail address? <brian.d.foy@gmail.com>
    Re: FAQ 9.19 How do I return the user's mail address? (Alan Curry)
        permutations of symbols? <mikee@mikee.ath.cx>
    Re: permutations of symbols? <jurgenex@hotmail.com>
    Re: permutations of symbols? <mikee@mikee.ath.cx>
    Re: problem with perl + thread + extension <ben@morrow.me.uk>
    Re: problem with perl + thread + extension <ben@morrow.me.uk>
    Re: problem with perl + thread + extension <aotto1968@users.sourceforge.net>
    Re: problem with perl + thread + extension <ben@morrow.me.uk>
        Regexp help <mikaelpetterson@hotmail.com>
    Re: Regexp help <usenet@larseighner.com>
    Re: Regexp help <jurgenex@hotmail.com>
    Re: Regexp help <derykus@gmail.com>
    Re: Regexp help <mikaelpetterson@hotmail.com>
    Re: Regexp help <mikaelpetterson@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 13 Oct 2009 09:35:40 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: FAQ 9.19 How do I return the user's mail address?
Message-Id: <lniqej2qw3.fsf@nuthaus.mib.org>

PerlFAQ Server <brian@theperlreview.com> writes:
> 9.19: How do I return the user's mail address?
>
>     On systems that support getpwuid, the $< variable, and the Sys::Hostname
>     module (which is part of the standard perl distribution), you can
>     probably try using something like this:
>
>             use Sys::Hostname;
>             $address = sprintf('%s@%s', scalar getpwuid($<), hostname);
>
>     Company policies on mail address can mean that this generates addresses
>     that the company's mail system will not accept, so you should ask for
>     users' mail addresses when this matters. Furthermore, not all systems on
>     which Perl runs are so forthcoming with this information as is Unix.

It should probably be mentioned that hostname very often returns
just the simple host name, not including the domain.  For example,
it might return just "foo" rather than "foo.bar.com".  This is not
usually useful for constructing an e-mail address.

>     The Mail::Util module from CPAN (part of the MailTools package) provides
>     a mailaddress() function that tries to guess the mail address of the
>     user. It makes a more intelligent guess than the code above, using
>     information given when the module was installed, but it could still be
>     incorrect. Again, the best way is often just to ask the user.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


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

Date: Tue, 13 Oct 2009 17:29:05 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 9.19 How do I return the user's mail address?
Message-Id: <131020091729055965%brian.d.foy@gmail.com>

In article <lniqej2qw3.fsf@nuthaus.mib.org>, Keith Thompson
<kst-u@mib.org> wrote:

> PerlFAQ Server <brian@theperlreview.com> writes:
> > 9.19: How do I return the user's mail address?


> >             use Sys::Hostname;
> >             $address = sprintf('%s@%s', scalar getpwuid($<), hostname);

> It should probably be mentioned that hostname very often returns
> just the simple host name, not including the domain.  For example,
> it might return just "foo" rather than "foo.bar.com".  This is not
> usually useful for constructing an e-mail address.

Okay, I'll look into this.  Thanks,


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

Date: Tue, 13 Oct 2009 23:46:51 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: FAQ 9.19 How do I return the user's mail address?
Message-Id: <hb33hb$ijf$1@aioe.org>

In article <lniqej2qw3.fsf@nuthaus.mib.org>,
Keith Thompson  <kst-u@mib.org> wrote:
>
>It should probably be mentioned that hostname very often returns
>just the simple host name, not including the domain.  For example,
>it might return just "foo" rather than "foo.bar.com".  This is not
>usually useful for constructing an e-mail address.

$USER@$HOST should at least be usable for mailing to yourself on the same
machine, assuming it runs an MTA and knows its own name, which every good
unix box should.

However, the spirit of the question might be "generate an address that the
outside world can use to contact me", and that's hard, since people put all
kinds of obstacles between themselves and the outside world.

-- 
Alan Curry


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

Date: Wed, 14 Oct 2009 01:59:52 +0000 (UTC)
From: Mike <mikee@mikee.ath.cx>
Subject: permutations of symbols?
Message-Id: <hb3bao$tha$1@news.eternal-september.org>

Does anyone have some simple code to give all the permutations of
an array of symbols?

i.e. for two symbols in an array:

my @array = ('howard', 'geek');
my @permutations = &permute(@array);

print join(' ', $permutations[0]), "\n";
print join(' ', $permutations[1]), "\n";

howard geek
geek howard

It looks easy for two symbols. What about three, four, or more?

Mike

perl 5.8+


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

Date: Tue, 13 Oct 2009 19:19:17 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: permutations of symbols?
Message-Id: <l7dad5hj3d0pdb352u840q0qbrqdcc8pdl@4ax.com>

Mike <mikee@mikee.ath.cx> wrote:
>Does anyone have some simple code to give all the permutations of
>an array of symbols?

Anything wrong the answer to "perldoc -q permute"?

jue


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

Date: Wed, 14 Oct 2009 02:26:05 +0000 (UTC)
From: Mike <mikee@mikee.ath.cx>
Subject: Re: permutations of symbols?
Message-Id: <hb3crt$9e9$1@news.eternal-september.org>

On 2009-10-14, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Mike <mikee@mikee.ath.cx> wrote:
>>Does anyone have some simple code to give all the permutations of
>>an array of symbols?
>
> Anything wrong the answer to "perldoc -q permute"?
>
> jue

I had found that, yes, thanks.
Sure enough, after posting the question I find an acceptable answer.
The tsc_permute looks more simple.
<http://docstore.mik.ua/orelly/perl/cookbook/ch04_20.htm>

Mike


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

Date: Tue, 13 Oct 2009 14:42:55 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: problem with perl + thread + extension
Message-Id: <vnceq6-8g1.ln1@osiris.mauzo.dyndns.org>


Quoth Andreas Otto <aotto1968@users.sourceforge.net>:
> Ben Morrow wrote:
> > 
> > In your place I would probably allow the user to pass in a string as
> > well, and choose call_sv or call_method based on what type of SV I got.
> 
> well "man perl_call" -> "Using call_sv ..." says something about this:
> 
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><
> Because we are using an SV to call fred the following can all be used
> 
>            CallSubSV("fred");
>            CallSubSV(\&fred);
>            $ref = \&fred;
>            CallSubSV($ref);
>            CallSubSV( sub { print "Hello there\n" } );
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> you see "call_sv" already covers all kind of possibilities

Yes, but none of these are *method* calls (that is, none of them will
inherit). They are equivalent to

    fred();
    (\&fred)->();
    $ref->();
    (sub { print "Hello there\n" })->();

> > 
> >     ApR     |SV*    |sv_dup         |NULLOK const SV *const sstr|NN
> >         CLONE_PARAMS *const param
> 
> but I still not know what to do with the last parameter...CLONE_PARAMS
> -> what to fill in

Hmmm. Well, I can *tell* you (or you could look for yourself) that the
structure looks like

    typedef struct clone_params {
        AV *stashes;                    /* should be set to a newAV() */
        UV flags;                       /* as for perl_clone */
        PerlInterpreter *proto_perl;    /* where we're copying from */
    } CLONE_PARAMS;

but if you find you need this function I'd recommend you write to p5p
saying that the function is apparently in the public API but is
undocumented, and asking what use of it is considered supported.


> >> package Server;
> >> use base qw(MqS);
> > 
> 
> this is not all of my code the "toplevel" package called "perlmsgque"
> 
> from the start
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> use strict;
> use Switch;

Don't use Switch. It uses a source filter to do its work, and
occasionally produces very weird failures. If you can rely on 5.10, you
can use given/when, otherwise do without a switch statement.

> use perlmsgque;

Packages with all-lowercase names are reserved for Perl pragmata. Since
we already know we are writing in Perl, there's no need to put that in
the name, and since this is a fairly low-level utility I would call it
Net::MsgQue or IPC::MsgQue, depending on which feature is more important.

> ...
> package Server;
> use base qw(MqS);
> ...
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> "MqS" (this is from me) and is just a "subpackage" of "perlmsgque"
> (this is also from me)

No it's not. A subpackage of perlmsgque would look like perlmsgque::MqS.

> the package "Server" is a synonym for a "end-user" package
> I use this name for testing only
> 
> the full name is "perlmsgque::MqS"

OK, then you've misunderstood how 'use base' works (or something). Perl
package names always need to be fully-qualified; there is no 'current
super-package' or anything that will let you say MqS when you mean
perlmsgque::MqS. (This is rather annoying.)

Ben



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

Date: Tue, 13 Oct 2009 14:57:57 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: problem with perl + thread + extension
Message-Id: <5kdeq6-8g1.ln1@osiris.mauzo.dyndns.org>


Quoth Andreas Otto <aotto1968@users.sourceforge.net>:
> right now I have a more serious problem:
> 
> as opposite to "FactoryCreate" I have a "FactoryDelete" too
> 
> >>>>>>>>>>>>>>>>>>>>>>>
> static void FactoryDelete (
>   struct MqS * context,
>   MQ_BOL doFactoryCleanup,
>   MQ_PTR data
> ) {
>   enum MqStatusIsE statusIs = context->statusIs;
>   PerlInterpreter *itp = context->threadData;
>   if (statusIs & MQ_STATUS_IS_THREAD) {
>     PERL_SET_CONTEXT(itp);
>     perl_destruct (itp);
>     PERL_SET_CONTEXT(itp);
>     perl_free (itp);
>   } else {
>     SvREFCNT_dec((SV*)context->self);
>   }
> }
> <<<<<<<<<<<<<<<<<<<<<<<<<
> 
> now the problem :
> 
> "perl_destruct" delete all objects even the
> ones from the "original" interpreter copied
> into the new interpreter using "perl_clone"
> 
> for me every object is linked to a pointer
> of type "struct MqS" from "libmsgque"
> 
> now shutdown of interpreter "1" delete the
> "libmsgque" objects belonging to the original interpreter "0"
> too => not good :-(

Are you sure it destroys the Perl objects in the original interpreter?
Do you perhaps have a DESTROY method on your objects that frees the
libmsgque object, and this is getting called because the cloned object
has been destroyed? If that's the case then you need to refcount your
pointers to libmsgque object; if it's not, then can you provide a
*complete*, *minimal* (in particular: not using either libmsgque or
threads) C program that demonstrates your problem.

Ben



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

Date: Tue, 13 Oct 2009 16:56:18 +0200
From: Andreas Otto <aotto1968@users.sourceforge.net>
Subject: Re: problem with perl + thread + extension
Message-Id: <hb24ej$ele$00$1@news.t-online.com>

Ben Morrow wrote:

> 
> Quoth Andreas Otto <aotto1968@users.sourceforge.net>:
>> right now I have a more serious problem:
>> 
>> as opposite to "FactoryCreate" I have a "FactoryDelete" too
>> 
>> >>>>>>>>>>>>>>>>>>>>>>>
>> static void FactoryDelete (
>>   struct MqS * context,
>>   MQ_BOL doFactoryCleanup,
>>   MQ_PTR data
>> ) {
>>   enum MqStatusIsE statusIs = context->statusIs;
>>   PerlInterpreter *itp = context->threadData;
>>   if (statusIs & MQ_STATUS_IS_THREAD) {
>>     PERL_SET_CONTEXT(itp);
>>     perl_destruct (itp);
>>     PERL_SET_CONTEXT(itp);
>>     perl_free (itp);
>>   } else {
>>     SvREFCNT_dec((SV*)context->self);
>>   }
>> }
>> <<<<<<<<<<<<<<<<<<<<<<<<<
>> 
>> now the problem :
>> 
>> "perl_destruct" delete all objects even the
>> ones from the "original" interpreter copied
>> into the new interpreter using "perl_clone"
>> 
>> for me every object is linked to a pointer
>> of type "struct MqS" from "libmsgque"
>> 
>> now shutdown of interpreter "1" delete the
>> "libmsgque" objects belonging to the original interpreter "0"
>> too => not good :-(
> 
> Are you sure it destroys the Perl objects in the original interpreter?
> Do you perhaps have a DESTROY method on your objects that frees the
> libmsgque object, 

yes I have (code below) and this DESTROY is called during "perl_destruct"
on the objects already available before the "perl_clone" was done.

> and this is getting called because the cloned object
> has been destroyed? If that's the case then you need to refcount your
> pointers to libmsgque object; if it's not, then can you provide a
> *complete*, *minimal* (in particular: not using either libmsgque or
> threads) C program that demonstrates your problem.

yes I'm sure ... I see it from my application logfile.
I get an application CORE just after the "C" pointer is gone ....

but I already found an work-around:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void
DESTROY(SV *obj)
  PPCODE:
    if (!SvROK(obj) || !SvOK(SvRV(obj))) XSRETURN(0);
    MqS* context = INT2PTR(MqS*,SvIV((SV*)SvRV(ST(0))));
    SV* self = context->self;
    HV* hash = PERL_DATA;
    // well "perl_clone" clone everything including the "perl" objects
    // from the other interpreter. These objects get an "DESTROY" if
    // "perl_clone" interpreter is destroyed with "perl_destruct"
    // -> this is not good
    if (PERL_GET_CONTEXT != (PerlInterpreter*)context->threadData)
 XSRETURN(0);

^^^^^^^^^^^^^^^^^^^^^^^ this is the work-around ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    // the "Factory" is useless -> delete
    context->setup.Factory.Delete.fCall = NULL;
    // delete the context
    MqContextDelete(&context);
    // free the data
    if (self && SvREFCNT(self)) SvREFCNT_dec(self);
    if (hash) hv_undef (hash);
    // free the handle
    SvSetSV_nosteal (SvRV(ST(0)), &PL_sv_undef);
    XSRETURN(0);
<<<<<<<<<<<<<<<<<<

I save the context , where the object was created on, in a data entry of the
"struct MqS" pointer "context->threadData".

If the DESTROY is called from the wrong context it is blocked.

-> now it works

the problem is that "perl" does not increase the refCount on objects created 
with 
>>>>>>>>>>>>>>>>>>>>>>
void
new(SV* MqS_class)
  PPCODE:
    if (!SvROK(MqS_class)) {
      // called by a "class"
      MqS * context = (MqS*) MqContextCreate(sizeof(struct PerlContextS), 
NULL);
      ST(0) = sv_newmortal();
      sv_setref_pv(ST(0), SvPV_nolen(MqS_class), (void*)context);
 ...
<<<<<<<<<<<<<<<<<<<<<
during "perl_clone" 

it is in close to the same problem of \&calllback which were not updated
during "perl_clone"

=> but for now I'm fine


> 
> Ben




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

Date: Tue, 13 Oct 2009 17:03:30 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: problem with perl + thread + extension
Message-Id: <ivkeq6-8c2.ln1@osiris.mauzo.dyndns.org>


Quoth Andreas Otto <aotto1968@users.sourceforge.net>:
> Ben Morrow wrote:
> > 
> > Are you sure it destroys the Perl objects in the original interpreter?
> > Do you perhaps have a DESTROY method on your objects that frees the
> > libmsgque object, 
> 
> yes I have (code below) and this DESTROY is called during "perl_destruct"
> on the objects already available before the "perl_clone" was done.

I don't think so. I think it's being called on the *clones* of those
objects that live in the new interpreter.

    ~% perl -Mthreads -Mthreads::shared -E'
        sub DESTROY { say "DESTROY: $_[0]: " . threads->tid }
        my $x = bless [];
        share $x;
        (async { 1 })->join;
        say "after perl_destruct";'
    DESTROY: main=ARRAY(0x283db1d0): 1
    after perl_destruct
    DESTROY: main=ARRAY(0x283141e0): 0
    ~%

Even though I only created one object, the DESTROY method got called
twice (with different objects), since the object was cloned into the new
thread. If the first DESTROY call had freed a C structure both objects
held pointers to, I would have got a segfault the next time I tried to
use the original object.

<snip>
> but I already found an work-around:
> 
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> void
> DESTROY(SV *obj)
<snip>
>     if (PERL_GET_CONTEXT != (PerlInterpreter*)context->threadData)
>  XSRETURN(0);

This is only safe if you are certain the object in the original
interpreter will out-last the clone. If you are not, you would be better
off putting a refcount in there and incrementing it when the objects get
cloned. You can use the CLONE class method for this, but you will need
to keep track of all your objects: see "Making your module threadsafe"
in perlmod.

> the problem is that "perl" does not increase the refCount on objects created 
> with 
<snip>
> during "perl_clone" 

No, and it is correct it does not. It is perfectly permissible for an
object to go out of scope in the parent thread before it does in the
child:

    ~% perl -Mthreads -Mthreads::shared -E'
        sub DESTROY { say "DESTROY: " . threads->tid }
        my $t;
        {
            my $x = bless [];
            share $x;
            $t = async { sleep 5 };
        }
        $t->join'
    DESTROY: 0
    DESTROY: 1
    ~%

Notice that the object in thread 0 (the parent thread) was destroyed
first.

Ben



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

Date: Tue, 13 Oct 2009 07:30:50 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Regexp help
Message-Id: <9b5ecfe1-be59-4e4c-b94d-9c2a4deafb6e@v36g2000yqv.googlegroups.com>

Hi,

I need to find if the line before 'public void aMethod()' has a

// or */

I have tried the following:

if($current_line =~ /(?:\\\|\*\\)/){

}

br,

//mike

//here is some text
public void aMethod(){

}

or

/**
* Here is some text
*/
public void aMethod(){

}



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

Date: Tue, 13 Oct 2009 15:35:16 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: Regexp help
Message-Id: <slrnhd971d.e8q.usenet@debranded.larseighner.com>

In our last episode, 
<9b5ecfe1-be59-4e4c-b94d-9c2a4deafb6e@v36g2000yqv.googlegroups.com>, 
the lovely and talented mike 
broadcast on comp.lang.perl.misc:

> Hi,

> I need to find if the line before 'public void aMethod()' has a

> // or */

> I have tried the following:

> if($current_line =~ /(?:\\\|\*\\)/){

> }

Why do you think a backslash, even when escaped with a backslash, will match
a forward slash?

> br,

> //mike

> //here is some text
> public void aMethod(){

> }

> or

> /**
> * Here is some text
> */
> public void aMethod(){

> }

-- 
  Lars Eighner <http://larseighner.com/>                 September 5887, 1993
            265 days since Rick Warren prayed over Bush's third term.
  Obama: No hope, no change, more of the same. Yes, he can, but no, he won't.


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

Date: Tue, 13 Oct 2009 08:47:28 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regexp help
Message-Id: <e789d5lqdv9rhadiga27q8tpu2j6jr5190@4ax.com>

mike <mikaelpetterson@hotmail.com> wrote:
>I need to find if the line before 'public void aMethod()' has a
>
>// or */

for my $i (1..$#lines) {
     if (index($lines[$i], 'public void aMethod()') >=0) {
 	print 'Line ', $i-1, " contains //\n" 
	    if (index($lines[$i-1], '//') >=0);
 	print 'Line ', $i-1, " contains */\n" 
	    if (index($lines[$i-1], '*/') >=0);
     }
}

HTH

jue


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

Date: Tue, 13 Oct 2009 11:07:29 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Regexp help
Message-Id: <4c71e979-d0f5-4780-8181-f8b2d58984f0@f18g2000prf.googlegroups.com>

On Oct 13, 7:30=A0am, mike <mikaelpetter...@hotmail.com> wrote:
> Hi,
>
> I need to find if the line before 'public void aMethod()' has a
>
> // or */
>
> I have tried the following:
>
> if($current_line =3D~ /(?:\\\|\*\\)/){
>
> }
>
> br,
>
> //mike
>
> //here is some text
> public void aMethod(){
>
> }
>
> or
>
> /**
> * Here is some text
> */
> public void aMethod(){
>
> }
>
>

With 5.10, you could use lookbehind'x \K :

my $qr =3D qr[ (           # start look-behind
	        (?:      # non-capturing
		  //     #   alternative 1
	          |      #       or
	          \*/    #   alternative 2
                )        # end non-capturing
	        .* \n\K  # rest of line
             )           # end look-behind
             public \s+ void \s+ aMethod\(\){
            ]x;

if ( $current_line =3D~ /$qr/ ) {
  ...

--
Charles DeRykus




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

Date: Tue, 13 Oct 2009 12:14:44 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Re: Regexp help
Message-Id: <66084eb1-21b0-4fd1-b3b3-3683457c3fb8@l2g2000yqd.googlegroups.com>

On 13 Okt, 17:35, Lars Eighner <use...@larseighner.com> wrote:
> In our last episode,
> <9b5ecfe1-be59-4e4c-b94d-9c2a4deaf...@v36g2000yqv.googlegroups.com>,
> the lovely and talented mike
> broadcast on comp.lang.perl.misc:
>
> > Hi,
> > I need to find if the line before 'public void aMethod()' has a
> > // or */
> > I have tried the following:
> > if($current_line =3D~ /(?:\\\|\*\\)/){
> > }
>
> Why do you think a backslash, even when escaped with a backslash, will ma=
tch
> a forward slash?

You are absolutely correct I missed it.

Thanks!

//mike
>
> > br,
> > //mike
> > //here is some text
> > public void aMethod(){
> > }
> > or
> > /**
> > * Here is some text
> > */
> > public void aMethod(){
> > }
>
> --
> =A0 Lars Eighner <http://larseighner.com/> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 September 5887, 1993
> =A0 =A0 =A0 =A0 =A0 =A0 265 days since Rick Warren prayed over Bush's thi=
rd term.
> =A0 Obama: No hope, no change, more of the same. Yes, he can, but no, he =
won't.



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

Date: Tue, 13 Oct 2009 12:16:41 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Re: Regexp help
Message-Id: <ecf3ee99-af87-45e6-bbe7-46d91a6c784d@o41g2000yqb.googlegroups.com>

On 13 Okt, 20:07, "C.DeRykus" <dery...@gmail.com> wrote:
> On Oct 13, 7:30=A0am, mike <mikaelpetter...@hotmail.com> wrote:
>
>
>
> > Hi,
>
> > I need to find if the line before 'public void aMethod()' has a
>
> > // or */
>
> > I have tried the following:
>
> > if($current_line =3D~ /(?:\\\|\*\\)/){
>
> > }
>
> > br,
>
> > //mike
>
> > //here is some text
> > public void aMethod(){
>
> > }
>
> > or
>
> > /**
> > * Here is some text
> > */
> > public void aMethod(){
>
> > }
>
> With 5.10, you could use lookbehind'x \K :
>
> my $qr =3D qr[ ( =A0 =A0 =A0 =A0 =A0 # start look-behind
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (?: =A0 =A0 =A0# non-capturing
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // =A0 =A0 # =A0 alternative 1
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A0 =A0# =A0 =A0 =A0 or
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \*/ =A0 =A0# =A0 alternative 2
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ) =A0 =A0 =A0 =A0# end non-capturing
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .* \n\K =A0# rest of line
> =A0 =A0 =A0 =A0 =A0 =A0 =A0) =A0 =A0 =A0 =A0 =A0 # end look-behind
> =A0 =A0 =A0 =A0 =A0 =A0 =A0public \s+ void \s+ aMethod\(\){
> =A0 =A0 =A0 =A0 =A0 =A0 ]x;
>
> if ( $current_line =3D~ /$qr/ ) {
> =A0 ...
>
> --
> Charles DeRykus

Really nice with comments so this was easy to understand and learn
something from.

//mike


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2635
***************************************


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