[31065] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2310 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 31 14:09:45 2009

Date: Tue, 31 Mar 2009 11:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 31 Mar 2009     Volume: 11 Number: 2310

Today's topics:
    Re: Being more restrictive when using blessed hash ref  jl_post@hotmail.com
    Re: Help using PAR, installed not able to use it jl_post@hotmail.com
    Re: Net::SSH::Perl Help <vendion@charter.net>
    Re: Net::SSH::Perl Help <vendion@charter.net>
    Re: Net::SSH::Perl Help <glex_no-spam@qwest-spam-no.invalid>
        Pass Match Values to Variable <Ansher.M@gmail.com>
    Re: Pass Match Values to Variable <peter@makholm.net>
    Re: Pass Match Values to Variable <Ansher.M@gmail.com>
    Re: Pass Match Values to Variable <peter@makholm.net>
    Re: Pass Match Values to Variable <tadmc@seesig.invalid>
    Re: Pass Match Values to Variable <Ansher.M@gmail.com>
    Re: Pass Match Values to Variable <someone@example.com>
    Re: Pass Match Values to Variable <jurgenex@hotmail.com>
    Re: Pass Match Values to Variable <jurgenex@hotmail.com>
        Question about the example in perlthrtut <jl_post@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 31 Mar 2009 08:32:23 -0700 (PDT)
From: jl_post@hotmail.com
Subject: Re: Being more restrictive when using blessed hash ref for OOP
Message-Id: <01238aad-c2c0-4752-8330-5b7505d6ca16@f41g2000pra.googlegroups.com>

On Mar 30, 6:55 am, "A. Farber" <Alexander.Far...@gmail.com> wrote:
>
> I define and use several classes in my Perl application,
> and I use blessed hash refs to store the data members.
>
> Often I wonder, if there is a possibility for being
> more restrictive - for example I'd prefer to get
> a warning, when I reference or vivificate a
> $href->{PLAYER} instead of $href->{PLAYERS} by mistake
>
> Any suggestions please?


   You might want to take a look at the "fields" module.  (Read about
it with "perldoc fields".)

   It's been years since I last used it (so my memory on it is a bit
sketchy), but it'll allow you to do things like:

#/usr/bin/perl
package Game;
use strict;
use warnings;
use fields qw(PLAYERS);
sub new
{
    my Game $self = shift;
    $self = fields::new($self)  unless (ref $self);
    return $self;
}
my $href = Game->new;
$href->{PLAYERS} = [];  # acceptable
$href->{PLAYER} = [];  # generates an error
__END__

   When I try to run this script, I get:

Attempt to access disallowed key 'PLAYER' in a restricted hash at -
line 14.

   I THOUGHT barewords would be checked at compile-time, but my own
experimentation just now leads me to believe it's a run-time check.
Either way, that's better than nothing.

   I hope this helps.

   -- Jean-Luc


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

Date: Tue, 31 Mar 2009 06:56:38 -0700 (PDT)
From: jl_post@hotmail.com
Subject: Re: Help using PAR, installed not able to use it
Message-Id: <d6daac7d-299c-4753-a680-e2ae1236f195@q30g2000prq.googlegroups.com>

perl Newbie wrote:
> I have installed the latest version of PAR,
> but I am unable to use it to convert perl script
> to exe. Any help on this will be of great help.


I used to use ActiveState Perl, but I had my share of trouble
installing modules though the ppm interface (including PAR and
PAR::Packer), so I switched to Strawberry Perl.  I'm mostly pleased
with the switch.

Whereas with ActiveState Perl I installed new modules using ppm like
this:

ppm install PAR
ppm install PAR-Packer

with Strawberry Perl I install new modules like this:

cpan PAR
cpan PAR::Packer

The Strawberry Perl approach is more Unix-like, and in my experience,
more successful, as it compiles its own version instead of relying on
pre-compiled binaries.  (However, I'll tell you up front that modules
that depend on pre-installed libraries require more work than just one
"cpan" command.)

If you're interested in trying out Strawberry Perl for yourself, you
can download it from http://strawberryperl.com/ .  (Be sure to
uninstall any previous versions of Perl before it, though.)

I hope this helps.

-- Jean-Luc


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

Date: Tue, 31 Mar 2009 03:40:07 -0700 (PDT)
From: vendion <vendion@charter.net>
Subject: Re: Net::SSH::Perl Help
Message-Id: <68c3f2d2-88c4-4cd0-bb8f-a57ac368ce5a@e21g2000yqb.googlegroups.com>

On Mar 30, 5:49 pm, Ben Morrow <b...@morrow.me.uk> wrote:.
>
> It looks to me as though this is the message you get if authentication
> fails. Check that you can ssh to the host concerned with ssh(1).
>
> Ben

That's the thing when I use just SSH same username and password
authentication is correct and I am able to login to the computers.


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

Date: Tue, 31 Mar 2009 03:44:38 -0700 (PDT)
From: vendion <vendion@charter.net>
Subject: Re: Net::SSH::Perl Help
Message-Id: <7424157e-5a63-48dc-8ecd-2744a4b48ad5@c36g2000yqn.googlegroups.com>

On Mar 30, 5:50 pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> vendion <vend...@charter.net> wrote:
> > #upgrader.pl This is the server side of a two part perl script that
> > uses ssh to
>
> Is that one line or two lines?

Yes that is one line
>
> > for my $computer ( '01' .. '26' ) { #loop once for each computer,
> > total 26 times
>
> Is that one line or two lines?

Same for that
>
> > Permission denied at /home/e-307-20/bin/upgrader.pl line 11
>
> Should we be looking at the 11th line or the 13th line of what
> you posted?
>

If you diff what I recently posted to what I posted in my first
message (yes I did post my working code there too) then you will see
that in the recent copy I changed from a while loop to a for loop that
cut down on the number of lines in my code affecting where the "error"
is happening it is the same problem just now the line is 11 instead of
13.

> Please either:
>
>    Disable word wrap when posting long lines
>
> or, better, do not *have* any long lines in your code
>
>     #upgrader.pl This is the server side of a two part perl script
>     #            that uses ssh to
>
>     for my $computer ( '01' .. '26' ) { #loop once for each computer,
>                                         # total 26 times
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"



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

Date: Tue, 31 Mar 2009 10:22:19 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Net::SSH::Perl Help
Message-Id: <49d2352b$0$33217$815e3792@news.qwest.net>

vendion wrote:
> On Mar 30, 5:49 pm, Ben Morrow <b...@morrow.me.uk> wrote:.
>> It looks to me as though this is the message you get if authentication
>> fails. Check that you can ssh to the host concerned with ssh(1).
>>
>> Ben
> 
> That's the thing when I use just SSH same username and password
> authentication is correct and I am able to login to the computers.

Are you running this program as the same user you used to
test SSH? Or is it secretly running as a CGI, or as some
other user?


I'd say, at this point, you should simplify your code and
ask for more verbose output.

use warnings;
use strict;
use Net::SSH::Perl;

my $computer = '10.18.1.101';
print "Making connection to computer\n";
my $ssh = Net::SSH::Perl->new($computer, debug => 1);
$ssh->login('user', 'password');
my ($stout, $sterr, $exit) = $ssh->cmd('date');
print   "stout: $stout\n",
	"sterr: $sterr\n",
	"exit=$exit\n";

Possibly it's using a different ssh (e.g. /usr/bin/ssh vs 
/usr/local/bin/ssh ) or SSH-2 or something is different
compared to running it in your shell.

Compare the output against running 'ssh -v' in your shell.

If that doesn't help, then fire up the debugger and step
through the code when it gets to the cmd method.  That way
you can print out "@cmd" to see exactly what is being called.


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

Date: Tue, 31 Mar 2009 06:02:25 -0700 (PDT)
From: perl Newbie <Ansher.M@gmail.com>
Subject: Pass Match Values to Variable
Message-Id: <5f5d264b-93d4-4b48-b562-4cd1c9e56295@o6g2000yql.googlegroups.com>

Hi

Please let me know what I am doing wrong .. I need to pass the regex
match values to a new variable.

This is the code .. but both  $capture_txt  & @nettxt is blank, values
I am expecting in @nettxt are

SAMPLE (NET) & SINGLE (net).


@txt=(
"SAMPLE (NET)"
,"Sample txt 1"
,"sample txt 2"
,"SINGLE (net) junk text"
,"Single txt 1"
,"Single txt 2"
);


foreach $txt(@txt) {

        if ($txt =~ /\w+\s*\(net\)/i) {
                print "True - $txt \n";
                $capture_txt = /\w+\s*\(net\)/ ;
                print "$capture_txt \n";
                push @nettxt, /(\w+\s*\(net\))/g;
        }

}

print @nettxt;






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

Date: Tue, 31 Mar 2009 15:10:01 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Pass Match Values to Variable
Message-Id: <87prfxx2hi.fsf@vps1.hacking.dk>

perl Newbie <Ansher.M@gmail.com> writes:

> Please let me know what I am doing wrong .. I need to pass the regex
> match values to a new variable.

You code is missing the following two lines:

    use strict;
    use warnings;

Insert them and remember to decalre all you variables with my, and
then perl will tell you the two places where you're matching against
uninitialized values.

//Makholm


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

Date: Tue, 31 Mar 2009 06:20:55 -0700 (PDT)
From: perl Newbie <Ansher.M@gmail.com>
Subject: Re: Pass Match Values to Variable
Message-Id: <35813d8a-2e7b-46d2-a62b-261e4f672439@e21g2000yqb.googlegroups.com>

On Mar 31, 6:10=A0pm, Peter Makholm <pe...@makholm.net> wrote:
> perl Newbie <Anshe...@gmail.com> writes:
> > Please let me know what I am doing wrong .. I need to pass the regex
> > match values to a new variable.
>
> You code is missing the following two lines:
>
> =A0 =A0 use strict;
> =A0 =A0 use warnings;
>
> Insert them and remember to decalre all you variables with my, and
> then perl will tell you the two places where you're matching against
> uninitialized values.
>
> //Makholm

I tried this but I am getting some error message, I am new to perl if
you could explain me that will be nice

use strict;
use warnings;


my @txt=3D(
"SAMPLE (NET)"
,"Sample txt 1"
,"sample txt 2"
,"SINGLE (net) junk text"
,"Single txt 1"
,"Single txt 2"
);

my @nettxt=3D();;
foreach my $txt(@txt) {

        if ($txt =3D~ /\w+\s*\(net\)/i) {
                print "True - $txt ";
                my $capture_txt =3D /\w+\s*\(net\)/gi ;
                print "$capture_txt \n";
                push @nettxt, /(\w+\s*\(net\))/gi;
        }

}

print @nettxt;


cmd message ...

Use of uninitialized value $_ in pattern match (m//) at H:\Test
\temp3.pl line 20.
Use of uninitialized value $_ in pattern match (m//) at H:\Test
\temp3.pl line 22.
Use of uninitialized value $_ in pattern match (m//) at H:\Test
\temp3.pl line 20.
Use of uninitialized value $_ in pattern match (m//) at H:\Test
\temp3.pl line 22.
True - SAMPLE (NET)
True - SINGLE (net) junk text





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

Date: Tue, 31 Mar 2009 15:27:56 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Pass Match Values to Variable
Message-Id: <87ljqlx1nn.fsf@vps1.hacking.dk>

perl Newbie <Ansher.M@gmail.com> writes:

> Use of uninitialized value $_ in pattern match (m//) at H:\Test
> \temp3.pl line 20.
> Use of uninitialized value $_ in pattern match (m//) at H:\Test
> \temp3.pl line 22.
> Use of uninitialized value $_ in pattern match (m//) at H:\Test
> \temp3.pl line 20.
> Use of uninitialized value $_ in pattern match (m//) at H:\Test
> \temp3.pl line 22.

This tells you two things. You're matching against $_ and it contains
an uninitialized value. You probably want to match against $txt
instead.



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

Date: Tue, 31 Mar 2009 08:49:11 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Pass Match Values to Variable
Message-Id: <slrngt47qn.etb.tadmc@tadmc30.sbcglobal.net>

perl Newbie <Ansher.M@gmail.com> wrote:
> On Mar 31, 6:10 pm, Peter Makholm <pe...@makholm.net> wrote:
>> perl Newbie <Anshe...@gmail.com> writes:
>> > Please let me know what I am doing wrong .. I need to pass the regex
>> > match values to a new variable.
>>
>> You code is missing the following two lines:
>>
>>     use strict;
>>     use warnings;
>>
>> Insert them and remember to decalre all you variables with my, and
>> then perl will tell you the two places where you're matching against
>> uninitialized values.
>>
>> //Makholm
>
> I tried this but I am getting some error message, 


They are not error messages. They are warning messages.

You can tell this by looking up the message with

    perldoc perldiag


> I am new to perl if
> you could explain me that will be nice


If you can figure it out for yourself, it will be even nicer...

 ... because then you won't be dependant on others every time
you encounter the problem.


>         if ($txt =~ /\w+\s*\(net\)/i) {


Q: What string are you trying to match the pattern against here?

A: The string in $txt.


>                 my $capture_txt = /\w+\s*\(net\)/gi ;


Q: What string are you trying to match the pattern against here?

A: The warning message gives you the answer. So does the documentation
   for the operator that you are using:

    perldoc perlop

        /PATTERN/cgimosx

        If no string is specified via the =~ or !~ operator, 
        the $_ string is searched.


Q: What will be stored in $capture_text if the pattern match succeeds?

A: A true value

Q: What will be stored in $capture_text if the pattern match fails?

A: A false value


Note that neither of those possibilities is the captured text...


Q: How can you tell what will be stored in $capture_txt?

A: By reading the documentation for the operator that you are using:

    perldoc perlop

        /PATTERN/cgimosx

        Searches a string for a pattern match, and in scalar context returns
        true if it succeeds, false if it fails.


Above you are using a pattern match in a scalar context.


>                 push @nettxt, /(\w+\s*\(net\))/gi;


Here you are using a pattern match in a list context.

Why are you including the m//g modifier? Do you expect the pattern
to match more than once on the same line?


> Use of uninitialized value $_ in pattern match (m//) at H:\Test
                             ^^
                             ^^
> \temp3.pl line 20.


There is the name of the variable that you are using but that has
an uninitialize value.

Figuring out where you are using it leads to the solution to your problem.


So, bind your pattern match to the correct string ($txt), don't include
the m//g option, do include some capturing parenthesis, do a pattern
match in list context rather than in scalar context:

     my($capture_txt) = $txt =~ /(\w+\s*\(net\))/i ;

Bind your pattern match to the correct string ($txt), don't include
the m//g option:

     push @nettxt, $txt =~ /(\w+\s*\(net\))/i;


Note that you don't need the if() block at all:

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

my @txt=(
"SAMPLE (NET)"
,"Sample txt 1"
,"sample txt 2"
,"SINGLE (net) junk text"
,"Single txt 1"
,"Single txt 2"
);

my @nettxt=();;
foreach my $txt(@txt) {
    push @nettxt, $txt =~ /(\w+\s*\(net\))/i;
}

print @nettxt;
-----------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 31 Mar 2009 07:28:18 -0700 (PDT)
From: perl Newbie <Ansher.M@gmail.com>
Subject: Re: Pass Match Values to Variable
Message-Id: <994e547c-9dc2-4081-b556-9818e8caa34e@k19g2000prh.googlegroups.com>

On Mar 31, 6:49=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> perl Newbie <Anshe...@gmail.com> wrote:
> > On Mar 31, 6:10=A0pm, Peter Makholm <pe...@makholm.net> wrote:
> >> perl Newbie <Anshe...@gmail.com> writes:
> >> > Please let me know what I am doing wrong .. I need to pass the regex
> >> > match values to a new variable.
>
> >> You code is missing the following two lines:
>
> >> =A0 =A0 use strict;
> >> =A0 =A0 use warnings;
>
> >> Insert them and remember to decalre all you variables with my, and
> >> then perl will tell you the two places where you're matching against
> >> uninitialized values.
>
> >> //Makholm
>
> > I tried this but I am getting some error message,
>
> They are not error messages. They are warning messages.
>
> You can tell this by looking up the message with
>
> =A0 =A0 perldoc perldiag
>
> > I am new to perl if
> > you could explain me that will be nice
>
> If you can figure it out for yourself, it will be even nicer...
>
> ... because then you won't be dependant on others every time
> you encounter the problem.
>
> > =A0 =A0 =A0 =A0 if ($txt =3D~ /\w+\s*\(net\)/i) {
>
> Q: What string are you trying to match the pattern against here?
>
> A: The string in $txt.
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 my $capture_txt =3D /\w+\s*\(net\)/gi ;
>
> Q: What string are you trying to match the pattern against here?
>
> A: The warning message gives you the answer. So does the documentation
> =A0 =A0for the operator that you are using:
>
> =A0 =A0 perldoc perlop
>
> =A0 =A0 =A0 =A0 /PATTERN/cgimosx
>
> =A0 =A0 =A0 =A0 If no string is specified via the =3D~ or !~ operator,
> =A0 =A0 =A0 =A0 the $_ string is searched.
>
> Q: What will be stored in $capture_text if the pattern match succeeds?
>
> A: A true value
>
> Q: What will be stored in $capture_text if the pattern match fails?
>
> A: A false value
>
> Note that neither of those possibilities is the captured text...
>
> Q: How can you tell what will be stored in $capture_txt?
>
> A: By reading the documentation for the operator that you are using:
>
> =A0 =A0 perldoc perlop
>
> =A0 =A0 =A0 =A0 /PATTERN/cgimosx
>
> =A0 =A0 =A0 =A0 Searches a string for a pattern match, and in scalar cont=
ext returns
> =A0 =A0 =A0 =A0 true if it succeeds, false if it fails.
>
> Above you are using a pattern match in a scalar context.
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 push @nettxt, /(\w+\s*\(net\))/gi;
>
> Here you are using a pattern match in a list context.
>
> Why are you including the m//g modifier? Do you expect the pattern
> to match more than once on the same line?
>
> > Use of uninitialized value $_ in pattern match (m//) at H:\Test
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^^
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^^
>
> > \temp3.pl line 20.
>
> There is the name of the variable that you are using but that has
> an uninitialize value.
>
> Figuring out where you are using it leads to the solution to your problem=
 .
>
> So, bind your pattern match to the correct string ($txt), don't include
> the m//g option, do include some capturing parenthesis, do a pattern
> match in list context rather than in scalar context:
>
> =A0 =A0 =A0my($capture_txt) =3D $txt =3D~ /(\w+\s*\(net\))/i ;
>
> Bind your pattern match to the correct string ($txt), don't include
> the m//g option:
>
> =A0 =A0 =A0push @nettxt, $txt =3D~ /(\w+\s*\(net\))/i;
>
> Note that you don't need the if() block at all:
>
> -----------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my @txt=3D(
> "SAMPLE (NET)"
> ,"Sample txt 1"
> ,"sample txt 2"
> ,"SINGLE (net) junk text"
> ,"Single txt 1"
> ,"Single txt 2"
> );
>
> my @nettxt=3D();;
> foreach my $txt(@txt) {
> =A0 =A0 push @nettxt, $txt =3D~ /(\w+\s*\(net\))/i;
>
> }
>
> print @nettxt;
> -----------------
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hid=
e quoted text -
>
> - Show quoted text -

Thanks for your detailed explanation.

I am new to Perl (learning for the last 15 days) and using "Learning
Perl" book. But it doesn=92t help me much in understanding the way you
have explained the details here :( Some of the other links I freq. use
are

http://www.physics.rutgers.edu/~kotliar/perltut.html
http://www.comp.leeds.ac.uk/Perl/basic.html

Could you please suggest any book or links which will help me to
better understand the concepts?

Thanks again.


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

Date: Tue, 31 Mar 2009 09:47:49 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Pass Match Values to Variable
Message-Id: <VOrAl.6280$Jm4.4595@newsfe09.iad>

perl Newbie wrote:
> 
> Please let me know what I am doing wrong .. I need to pass the regex
> match values to a new variable.
> 
> This is the code .. but both  $capture_txt  & @nettxt is blank, values
> I am expecting in @nettxt are
> 
> SAMPLE (NET) & SINGLE (net).
> 
> 
> @txt=(
> "SAMPLE (NET)"
> ,"Sample txt 1"
> ,"sample txt 2"
> ,"SINGLE (net) junk text"
> ,"Single txt 1"
> ,"Single txt 2"
> );
> 
> 
> foreach $txt(@txt) {
> 
>         if ($txt =~ /\w+\s*\(net\)/i) {
>                 print "True - $txt \n";
>                 $capture_txt = /\w+\s*\(net\)/ ;
>                 print "$capture_txt \n";
>                 push @nettxt, /(\w+\s*\(net\))/g;
>         }
> 
> }
> 
> print @nettxt;

$ perl -le'
my @txt = (
     "SAMPLE (NET)",
     "Sample txt 1",
     "sample txt 2",
     "SINGLE (net) junk text",
     "Single txt 1",
     "Single txt 2",
     );
my @nettxt = map /(\w+\s*\(net\))/i ? $1 : (), @txt;
print for @nettxt;
'
SAMPLE (NET)
SINGLE (net)




John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov


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

Date: Tue, 31 Mar 2009 10:24:09 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Pass Match Values to Variable
Message-Id: <86k4t4h7rbi53otpllvieh9lde119pdfnn@4ax.com>

perl Newbie <Ansher.M@gmail.com> wrote:


>                $capture_txt = /\w+\s*\(net\)/ ;

You are matching against $_, which from the rest of your code ist empty,
so the pattern match will fail. The return value of the pattern match is

    m/PATTERN/cgimosx
    /PATTERN/cgimosx
            Searches a string for a pattern match, and in scalar context
            returns true if it succeeds, false if it fails. 

>                print "$capture_txt \n";

Which means you are printing the empty string (= the textual value of
the logical false return value) here.

jue


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

Date: Tue, 31 Mar 2009 10:43:27 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Pass Match Values to Variable
Message-Id: <k8l4t49ipkc530nc764s33r9st84hrf4re@4ax.com>

Jürgen Exner <jurgenex@hotmail.com> wrote:
>perl Newbie <Ansher.M@gmail.com> wrote:
>
>
>>                $capture_txt = /\w+\s*\(net\)/ ;
>
>You are matching against $_, which from the rest of your code ist empty,
>so the pattern match will fail. The return value of the pattern match is
>
>    m/PATTERN/cgimosx
>    /PATTERN/cgimosx
>            Searches a string for a pattern match, and in scalar context
>            returns true if it succeeds, false if it fails. 
>
>>                print "$capture_txt \n";
>
>Which means you are printing the empty string (= the textual value of
>the logical false return value) here.

Forgot to mention:

From your description it seems you want to capture the exact text that
was matched by the RE. To do so you just need to 'group' the part of the
RE, for which you want to capture the text, e.g.

	/(\w+\s*\(net\))/

for the whole RE.
Any matched by the RE can then be found in the variable $1 (and $2, $3,
 ... if you have more than one group in the RE).

Note that those variable are only valid if the match succeeded.
Therefore the typical usage is 

	if (//\w+\s*\(net\)/) {
		# so something with $1
	}

jue


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

Date: Tue, 31 Mar 2009 07:21:51 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Question about the example in perlthrtut
Message-Id: <758810c7-5f78-4885-adcc-f998609ff094@r31g2000prh.googlegroups.com>


Hi,

   I recently read the "perldoc perlthrtut" document to learn how to
do threading with Perl, and I understand most of what it's teaching.
However, I have a question regarding the complete example given (the
one about generating prime numbers using a pipeline model):


#!/usr/bin/perl
# prime-pthread, courtesy of Tom Christiansen

use strict;
use warnings;

use threads;
use Thread::Queue;

my $stream = Thread::Queue->new();
for my $i ( 3 .. 1000 ) {
    $stream->enqueue($i);
}
$stream->enqueue(undef);

threads->create(\&check_num, $stream, 2)->join();

sub check_num {
    my ($upstream, $cur_prime) = @_;
    my $kid;
    my $downstream = Thread::Queue->new();
    while (my $num = $upstream->dequeue()) {
        next unless ($num % $cur_prime);
        if ($kid) {
            $downstream->enqueue($num);
        } else {
            print("Found prime $num\n");
            $kid = threads->create(\&check_num, $downstream, $num);
        }
    }
    if ($kid) {
        $downstream->enqueue(undef);
        $kid->join();
    }
}


(For the record, I deleted the first "$kid->join();" line (the one
that was right after the first "thread->create" call) and appended "-
>join()" to the previous line to make the program compile.)

If I understand correctly, each thread takes a queue of numbers,
reports that the first is prime (otherwise it wouldn't be first in the
queue), and then starts a new thread.  The old thread then gives the
new thread all the numbers in its queue that are not multiples of the
prime number it reported.

I ran the script, and it works great.  However, it seems that a thread
won't end until its child thread (that is, the thread it created/
started) ends.  And since it seems like it creates another thread for
every prime number, that would mean that around 167 different threads
can be running (or at least exist) at once.  (I say 167 because there
are 167 primes from 3 to 1000.)

So am I correct in saying that there are over 100 threads running at
once?  If so, isn't that a bit taxing on the operating system?  I
mean, I've noticed that in some cases over 100 levels of recursion can
error out (or at least give a warning message), so wouldn't
recursively creating a thread over 100 times also be something we'd
want to avoid?  Or are threads different in this respect?

Thanks in advance for any advice.

-- Jean-Luc


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

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


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