[29864] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1107 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 12 11:09:50 2007

Date: Wed, 12 Dec 2007 08:09:12 -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           Wed, 12 Dec 2007     Volume: 11 Number: 1107

Today's topics:
        (1)[0] ok but not 1[0] <sensorflo@gmail.com>
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: (1)[0] ok but not 1[0] <rvtol+news@isolution.nl>
    Re: (1)[0] ok but not 1[0] <sensorflo@gmail.com>
    Re: (1)[0] ok but not 1[0] <sensorflo@gmail.com>
    Re: (1)[0] ok but not 1[0] <krahnj@telus.net>
    Re: (1)[0] ok but not 1[0] <ben@morrow.me.uk>
    Re: (1)[0] ok but not 1[0] <ben@morrow.me.uk>
    Re: (1)[0] ok but not 1[0] <ben@morrow.me.uk>
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: Can't locate object method "readMessage" ... (Inher <ben@morrow.me.uk>
        computer coming on 2008 sexy model <mathivram@yahoo.com>
        lwp POST and proxies <dsphunxion@gmail.com>
    Re: lwp POST and proxies <ben@morrow.me.uk>
    Re: lwp POST and proxies <bisonho123456@gmail.com>
    Re: lwp POST and proxies <bisonho123456@gmail.com>
        Regular expression for matching words containing unders <rspai9@gmail.com>
    Re: Regular expression for matching words containing un <RedGrittyBrick@SpamWeary.foo>
    Re: Session Problem in Perl <visitprakashindia@gmail.com>
        split is not convinient <xueweizhong@gmail.com>
        Stupid Mistakes <inthepickle@gmail.com>
    Re: Stupid Mistakes <c7eqjyg02@sneakemail.com>
    Re: Stupid Mistakes <inthepickle@gmail.com>
    Re: Stupid Mistakes <inthepickle@gmail.com>
        When do I need to define a function with "use POSIX qw( (Thomas Blabb)
    Re: When do I need to define a function with "use POSIX <tadmc@seesig.invalid>
    Re: When do I need to define a function with "use POSIX <tzz@lifelogs.com>
    Re: When do I need to define a function with "use POSIX <joost@zeekat.nl>
    Re: When do I need to define a function with "use POSIX <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 12 Dec 2007 01:55:23 -0800 (PST)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: (1)[0] ok but not 1[0]
Message-Id: <9d6d8782-1b32-429f-8999-a13a7b374d80@v4g2000hsf.googlegroups.com>

Hello

I am still after the answer to the old question whats the difference
between an array and a list. Yes, I read the faq, and I am reading
Programming Perl.

In my current understanding, the array subscript operator [] forces
its left operand to be an array. Thus, if that left operand is a list,
that list is converted to an array. Thus things like
$x = (1,2,3)[0];
$x = (3)[0];

work. But then again, why shoudn't that work?
$x = 3[0];

I thought it's the operator , which composes/constructs a list, not
parantheses. Parantheses are in this discussion only used for
overwriting precedence. Eg this works to create an array with just one
element
@a = 3;

I don't have to write
@a = (3);

Thus a literal scalar like 3 in 'array context' (imposed by the array
subscript operator []) is just a list with one element, just as (3)
[0]. Thats why I expect 3[0] to work.

Greetings

Flo


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

Date: Wed, 12 Dec 2007 12:38:46 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <qnhvl3di4b0t051u1q83tp0afbola2d58v@4ax.com>

On Wed, 12 Dec 2007 01:55:23 -0800 (PST), Florian Kaufmann
<sensorflo@gmail.com> wrote:

>I am still after the answer to the old question whats the difference
>between an array and a list. Yes, I read the faq, and I am reading
>Programming Perl.

Basically, an array is a thing that has a name (yes, even when it's
anonymous!) into which a list can be stored, and out of which a list
can be extracted.

>In my current understanding, the array subscript operator [] forces
>its left operand to be an array. Thus, if that left operand is a list,

Your current understanding is wrong.

>that list is converted to an array. Thus things like

False. Since an array and a list are much similar, you can have array
and list subscripting (and slicing) which work in a quite similar way.

>$x = (1,2,3)[0];
>$x = (3)[0];
>
>work. But then again, why shoudn't that work?
>$x = 3[0];

Because 3 is not a list.

>I thought it's the operator , which composes/constructs a list, not
>parantheses. Parantheses are in this discussion only used for
>overwriting precedence. Eg this works to create an array with just one
>element
>@a = 3;

But assignment to an array creates list context.

>I don't have to write
>@a = (3);

That's a special case. You'll find that

C:\temp>perl -le "@a=3,5;@b=(3,5);print qq(@a|@b)"
3|3 5


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


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

Date: Wed, 12 Dec 2007 13:50:00 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <fjop2g.17o.1@news.isolution.nl>

Florian Kaufmann schreef:

> I am still after the answer to the old question whats the difference
> between an array and a list.

An array is a variable. 

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Wed, 12 Dec 2007 05:05:26 -0800 (PST)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <29c551cb-855d-4bb3-8b85-5730b91b998b@t1g2000pra.googlegroups.com>

> False. Since an array and a list are much similar, you can have array
> and list subscripting (and slicing) which work in a quite similar way.
> ....
> >But then again, why shoudn't that work?
> >$x = 3[0];
>
> Because 3 is not a list.

So then, why does the following work?
$x = (3)[0].

Where is a rule that states that parentheses make the difference?
Here, parentheses are only for grouping I thought. To create lists,
one has to use the operator ',' , not parentheses.

Flo


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

Date: Wed, 12 Dec 2007 05:28:47 -0800 (PST)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <de624b45-bc92-4dc8-a099-7d24afad2771@s19g2000prg.googlegroups.com>

Perldoc says that "List values are denoted by separating individual
values by commas (and enclosing the list in parentheses where
precedence requires it):". To repeat the point, parentheses are not
required to create/specify lists.

The following two are equivalent
print 1,2,3;
print (1,2,3);

Thus the following two should be equivalent too in my view
$x = 3[0];
$x = (3)[0];

Flo


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

Date: Wed, 12 Dec 2007 14:10:47 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <475FEBE9.127304FE@telus.net>

Florian Kaufmann wrote:
> 
> > False. Since an array and a list are much similar, you can have array
> > and list subscripting (and slicing) which work in a quite similar way.
> > ....
> > >But then again, why shoudn't that work?
> > >$x = 3[0];
> >
> > Because 3 is not a list.
> 
> So then, why does the following work?
> $x = (3)[0].
> 
> Where is a rule that states that parentheses make the difference?
> Here, parentheses are only for grouping I thought. To create lists,
> one has to use the operator ',' , not parentheses.

Who said that you needed ',' or parentheses?

$ perl -le'print qw/a b c d e f/[3]'
d


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 12 Dec 2007 14:33:59 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <n38535-jr1.ln1@osiris.mauzo.dyndns.org>


Quoth Florian Kaufmann <sensorflo@gmail.com>:
> 
> I am still after the answer to the old question whats the difference
> between an array and a list. Yes, I read the faq, and I am reading
> Programming Perl.

An array is a variable, a list is a value. That is, the contents of an
array can be modified (by assigning to a subscript, or with push, pop,
splice &c.) whereas the contents of a list cannot. All you can do is
build a *new* list based on the old one, say with map or grep. A list
also has no 'life' beyond the end of the expression it is part of: it
must be assigned into an array or it will be garbage-collected.
(Exception: the list passed to 'return' exists past the sub return and
into the expression that made the call.)

> In my current understanding, the array subscript operator [] forces
> its left operand to be an array.

No, this is incorrect. There are three different operators in Perl
spelled []: array subscript, array slice, and list slice.

    $ary[0]         array subscript
    $aref->[0]      also array subscript
    @ary[0]         array slice
    (LIST)[0]       list slice

For the 'list slice' form, the parens are part of the syntax, so @ary[0]
and (@ary)[0] are quite different expressions.

> Thus, if that left operand is a list,
> that list is converted to an array. Thus things like
> $x = (1,2,3)[0];
> $x = (3)[0];
> 
> work.

No. Otherwise exists( (1,2)[0] ) would work, which it doesn't.

> But then again, why shoudn't that work?
> $x = 3[0];

This is none of the forms above, so it is a syntax error.

> I thought it's the operator , which composes/constructs a list, not
> parantheses.

The comma only composes a list in list context. The inside of the parens
in the ()[] list slice operator are in list context, so you will get a
list to slice.

> Thus a literal scalar like 3 in 'array context' (imposed by the array
> subscript operator []) is just a list with one element, just as (3)
> [0]. Thats why I expect 3[0] to work.

There is no 'array context', at least, not in Perl 5. 3[0] is a syntax
error, so there are no contexts at all :); in (3)[0] the ()[] operator
does indeed provide list context to the 3.

I hope this helps you understand it: it *is* rather confusing :).

Ben



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

Date: Wed, 12 Dec 2007 14:39:53 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <pe8535-jr1.ln1@osiris.mauzo.dyndns.org>


Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Wed, 12 Dec 2007 01:55:23 -0800 (PST), Florian Kaufmann
> <sensorflo@gmail.com> wrote:
> 
> >I am still after the answer to the old question whats the difference
> >between an array and a list. Yes, I read the faq, and I am reading
> >Programming Perl.
> 
> Basically, an array is a thing that has a name (yes, even when it's
> anonymous!) into which a list can be stored, and out of which a list
> can be extracted.

You can do much more to an array than just store and extract lists.
splice, for instance, doesn't work on lists.

> >$x = (3)[0];
> >
> >work. But then again, why shoudn't that work?
> >$x = 3[0];
> 
> Because 3 is not a list.

Well... it can be. In (3)[0], the 3 is in list context, so it *is* (part
of) a list. The important point is that the parens are an integral part
of the list slice operator.

> >I don't have to write
> >@a = (3);
> 
> That's a special case. You'll find that
> 
> C:\temp>perl -le "@a=3,5;@b=(3,5);print qq(@a|@b)"
> 3|3 5

It's not a special case. Here the parens *are* just for precedence: =
binds more tightly than comma, so @a=3,5 evaluates as (@a=3),5 . If you
had @a = foo, then foo would be called in list context despite the lack
of parens.

Ben



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

Date: Wed, 12 Dec 2007 14:50:22 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <e29535-jr1.ln1@osiris.mauzo.dyndns.org>


Quoth "John W. Krahn" <krahnj@telus.net>:
> Florian Kaufmann wrote:
> > 
> > Where is a rule that states that parentheses make the difference?
> > Here, parentheses are only for grouping I thought. To create lists,
> > one has to use the operator ',' , not parentheses.
> 
> Who said that you needed ',' or parentheses?
> 
> $ perl -le'print qw/a b c d e f/[3]'
> d

Now that *is* a special case :). qw// pretends it has parens around it
(look for KEY_qw in toke.c: it actually inserts paren tokens into the
token stream) so that @a = qw/a b/ doesn't need extra parens. Of course,
it doesn't pretend hard enough to invoke the 'looks like a function'
rule... :)

Ben



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

Date: Wed, 12 Dec 2007 16:42:34 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <p5vvl3tailthnquaurbiisggndlk6g4nrs@4ax.com>

On Wed, 12 Dec 2007 05:05:26 -0800 (PST), Florian Kaufmann
<sensorflo@gmail.com> wrote:

>> Because 3 is not a list.
>
>So then, why does the following work?
>$x = (3)[0].

Because (3) is a list.
>
>Where is a rule that states that parentheses make the difference?
>Here, parentheses are only for grouping I thought. To create lists,
>one has to use the operator ',' , not parentheses.

Yep, the comma *does* create lists, in list context. In scalar
context, it does something entirely different.


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


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

Date: Wed, 12 Dec 2007 16:46:22 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <vb00m3hcau15ntb2sdesei4o3e6s78rdgb@4ax.com>

On Wed, 12 Dec 2007 05:28:47 -0800 (PST), Florian Kaufmann
<sensorflo@gmail.com> wrote:

>Perldoc says that "List values are denoted by separating individual
>values by commas (and enclosing the list in parentheses where
>precedence requires it):". To repeat the point, parentheses are not
>required to create/specify lists.

In fact, $x= ... binds stricter. Thus parens *are* required.

>The following two are equivalent
>print 1,2,3;
>print (1,2,3);

This is an entirely different matter: the parens around the arguments
for print are the optional ones of the print() function. Thus

  argon:~ [16:45:30]$ perl -le 'print 1,(2,3)'
  123
  argon:~ [16:45:49]$ perl -le 'print (2,3),4'
  23
  argon:~ [16:45:56]$ perl -le 'print((2,3),4)'
  234
  argon:~ [16:46:03]$ perl -le 'print +(2,3),4'
  234


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


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

Date: Wed, 12 Dec 2007 16:48:59 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <km00m3ppev27h0s2fnvmk7jupi66dqhsdl@4ax.com>

On Wed, 12 Dec 2007 14:39:53 +0000, Ben Morrow <ben@morrow.me.uk>
wrote:

>> C:\temp>perl -le "@a=3,5;@b=(3,5);print qq(@a|@b)"
>> 3|3 5
>
>It's not a special case. Here the parens *are* just for precedence: =
>binds more tightly than comma, so @a=3,5 evaluates as (@a=3),5 . If you
>had @a = foo, then foo would be called in list context despite the lack
>of parens.

Sorry for the misinformation. A braino on my part.


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


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

Date: Wed, 12 Dec 2007 14:14:59 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Can't locate object method "readMessage" ... (Inheritance question)
Message-Id: <307535-hj1.ln1@osiris.mauzo.dyndns.org>


Quoth ncherry@comcast.net:
> I'm trying to create a package that overrides the 'new' method in the
> package: ElkM1::Control but use the rest of the methods as is. Here's
> my initial portion of my code (without the indent):
> 
>   package ElkM1::Control::Serial;
> 
>   use 5.008006;
>   use strict;
>   use warnings;
>   use Carp;
> 
>   use Device::SerialPort; # this is the main difference
>   use ElkM1::Control;     # inherit from ElkM1::Control
> 
>   #@ISA = qw( "ElkM1::Control" );

    our @ISA = qw( ElkM1::Control );

Globals need to be declared with 'our' or 'use vars' (the former is
preferred, unless you need 5.005 compatibility) under 'use strict'.
Using extra quotes inside qw// will not do what you want.

You don't appear to be overriding the ->new method at all.
ElkM1::Control does not appear to be on CPAN, so I can't tell if it
defines one. If you are hoping to inherit methods from
Device::SerialPort you would need to add that to @ISA, however since
Device::SerialPort uses hash-based objects, this would not work.

Ben



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

Date: Wed, 12 Dec 2007 05:08:13 -0800 (PST)
From: ashik <mathivram@yahoo.com>
Subject: computer coming on 2008 sexy model
Message-Id: <cfa91f2d-50ef-429e-b092-b778cb8b2862@i12g2000prf.googlegroups.com>

iuw fhf jflksjh jhfl
http://www.freewebs.com/thuiss/
http://indianfriendfinder.com/go/g906725-pmem


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

Date: Wed, 12 Dec 2007 05:30:40 -0800 (PST)
From: sil <dsphunxion@gmail.com>
Subject: lwp POST and proxies
Message-Id: <2240cb44-0af8-40b5-9e8c-d7a99c3c7c3a@18g2000hsf.googlegroups.com>

Hey all hoping someone can point me in the right direction on this.
I've set up a proxy server to log into another server on my LAN, this
other server is running ZenOSS and is configured to create reports and
email them upon login.... I figured I could leverage it for a coworker
or manager to auto generate a report based on a list so I created the
following: I have a file with names that reads like this:

# more names
name1
name2
name3


Need to take those names and do a POST using a proxy server... This is
what I have...

Doesn't work does anyone have a solution to read from a file and then
do a POST?

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

use LWP;
my $data_file="names";
my $name;
my $browser = LWP::UserAgent->new;
$browser->agent('ZenOSS Report Generator');
$browser->proxy('10.10.15.20:3128');


open(FILE, $data_file) || die("Could not open file!");

while(<FILE>){

$name = $_;
print "Working on $name\n";
my $req = HTTP::Request->new(POST => "http://10.10.20.100/login.jsp?
UserID=$name&Password=password&x=27&y=28");
$req->content_type('application/x-www-form-urlencoded');

my $response = $browser->request($req);
print "Done: ", $response->status_line;
}

Thanks in advance


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

Date: Wed, 12 Dec 2007 15:09:35 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: lwp POST and proxies
Message-Id: <f6a535-jr1.ln1@osiris.mauzo.dyndns.org>


Quoth sil <dsphunxion@gmail.com>:
> Hey all hoping someone can point me in the right direction on this.
> I've set up a proxy server to log into another server on my LAN, this
> other server is running ZenOSS and is configured to create reports and
> email them upon login.... I figured I could leverage it for a coworker
> or manager to auto generate a report based on a list so I created the
> following: I have a file with names that reads like this:
> 
> # more names
> name1
> name2
> name3
> 
> 
> Need to take those names and do a POST using a proxy server... This is
> what I have...
> 
> Doesn't work does anyone have a solution to read from a file and then
> do a POST?

What do you mean by 'doesn't work'?

> #!/usr/bin/perl -w

-w is redundant with 'use warnings'.

> use strict;
> use warnings;
> 
> use LWP;
> my $data_file="names";
> my $name;
> my $browser = LWP::UserAgent->new;
> $browser->agent('ZenOSS Report Generator');
> $browser->proxy('10.10.15.20:3128');
> 
> 
> open(FILE, $data_file) || die("Could not open file!");

Use three-arg open.
Use lexical filehandles.
Say what you were trying to open, and why it failed.

    open(my $FILE, '<', $data_file) 
        || die("Could not open '$data_file': $!");

Personally I would prefer to use 'or' and omit all those parens, but
that's a matter of taste.

> while(<FILE>){
> 
> $name = $_;

This is silly. You're just clobbering your global $_ for no reason.

    while (my $name = <$FILE>) {

Ben



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

Date: Wed, 12 Dec 2007 07:26:23 -0800 (PST)
From: Guasco <bisonho123456@gmail.com>
Subject: Re: lwp POST and proxies
Message-Id: <05b2c772-5ec2-4017-954c-1f8e4352d8ed@d27g2000prf.googlegroups.com>


Hi,
there is no post fields, and the link dont appear a post method.
try use get method

# my $req = HTTP::Request->new(POST => "http://10.10.20.100/login.jsp?
# UserID=$name&Password=password&x=27&y=28");
# $req->content_type('application/x-www-form-urlencoded');
#
# my $response = $browser->request($req);
 my $response = $browser->get($req);


if it is a real post method then

 my $req = HTTP::Request->new(POST => "http://10.10.20.100/
login.jsp",
    ["UserID",$name,"Password","password","x","27","y","28"]);
     #array with field name, values


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

Date: Wed, 12 Dec 2007 07:29:17 -0800 (PST)
From: Guasco <bisonho123456@gmail.com>
Subject: Re: lwp POST and proxies
Message-Id: <5b28ac8a-06b0-4191-a3e0-52c523299e3e@l1g2000hsa.googlegroups.com>


Hi,
there is no post fields, and the link dont appear a post method.
try use get method

# my $req = HTTP::Request->new(POST => "http://10.10.20.100/login.jsp?
# UserID=$name&Password=password&x=27&y=28");
# $req->content_type('application/x-www-form-urlencoded');
#
# my $response = $browser->request($req);
 my $response = $browser->get("http://10.10.20.100/login.jsp? UserID=
$name&Password=password&x=27&y=28");


if it is a real post method then

 my $req = HTTP::Request->new(POST => "http://10.10.20.100/
login.jsp",
    ["UserID",$name,"Password","password","x","27","y","28"]);
     #array with field name, values


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

Date: Wed, 12 Dec 2007 07:27:02 -0800 (PST)
From: Raj <rspai9@gmail.com>
Subject: Regular expression for matching words containing underscore _  character
Message-Id: <486a7a36-f472-4e2b-8f6e-8bb393e868f9@b40g2000prf.googlegroups.com>

I have large text passages containing names of database tables,
procedures, packages, variables etc having the underscore character as
a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
Z0-9_]+\b" but it matches all words in the passage.

Thanks in advance for the help.

Raj



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

Date: Wed, 12 Dec 2007 15:47:42 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Regular expression for matching words containing underscore _ character
Message-Id: <4760029e$0$8427$db0fefd9@news.zen.co.uk>

Raj wrote:
> I have large text passages containing names of database tables,
> procedures, packages, variables etc having the underscore character as
> a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
> Z0-9_]+\b" but it matches all words in the passage.

Similarly "[ab]+" matches "aaa" and "aa" though neither contain "b".

Try "\b[a-zA-Z0-9]+_[a-zA-Z0-9_]+\b"

Or "\b\w+_\w+\b"


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

Date: Wed, 12 Dec 2007 06:59:14 -0800 (PST)
From: Praki <visitprakashindia@gmail.com>
Subject: Re: Session Problem in Perl
Message-Id: <843ad27c-6fb4-4696-8614-3887fa46a22e@e10g2000prf.googlegroups.com>

On Dec 12, 1:41 am, Ron Bergin <r...@i.frys.com> wrote:
> On Dec 11, 7:55 am, Praki <visitprakashin...@gmail.com> wrote:
>
>
>
> > Greetings All,
>
> > i m creating a session storing the loging credentials. i want to
> > access that data later after crossing two pages.i have created the
> > sesion but i could not get the data back some where i m going wrong
> > can u point me where ..
>
> > my first first file getting the login credentials
>
> > #!/usr/local/bin/perl5
> > &top();
> > &login_check();
> > &bottom();
> > sub top{
> > print <<EOM1;
> > Content-type: text/html
>
> > <html>
> >   <head>
> >     <title>Login Authentication</title>
> >   </head>
> > <body>
> > EOM1}
>
> > sub bottom{
> > print <<EOM2;
> > </body>
> > </html>
> > EOM2}
>
> > sub login_check{
> > print <<EOM;
> > <h3>Enter the login Password</h3>
> > <form  method="post" action="cookie.cgi">
> > <input type="hidden" name="username"  value='Submit'>
> > <p>Username: <input type="text" name="uid" size="20"></p>
> > <p>Password: <input type="password" name="passwd" size="20"></p>
> > <input type="submit" value="Submit" name="submit">
> > </form>
> > EOM
>
> > }
>
> > second file where i m creating the session.
>
> > #!/usr/local/bin/perl5
> > use Net::LDAP;
> > &top();
> > &login_check();
> > &bottom();
>
> > sub top{
> >   print <<EOM1;
> > Content-type: text/html
>
> > <html>
> >   <head>
> >     <title>Login Authentication</title>
> >   </head>
> > <body>
> > EOM1}
>
> > sub bottom{
> >   print <<EOM2;
> > </body>
> > </html>
> > EOM2}
>
> > sub login_check{
> >   my ($ret);
> >   use CGI;
> >   my $query = new CGI;
> >   $query->param("submit");
> >   my $userid = $query->param("uid");
> >   my $password = $query->param("passwd");
> > use CGI;
> > use CGI::Session;
>
> > $session = new CGI::Session("driver:File",undef,{'Directory'=>"/
> > tmp"});
> > $sid = $session->id();
> > print "Session id:".$sid;
>
> > #$session->name($userid);
> > # Write the session variable on the server
> > $session->param('username',$userid);
> > $session->param('password',$password);
> > print "username:".$userid."pass:";
>
> > $usernam = $session->param('username');
> > $passwor = $session->param('password');
>
> > print "username from the cookie:".$usernam;
>
> > #create session cookie
> > $cookie = $query->cookie(CGISESSID => $session->id);
> > print $query->header( -cookie=>$cookie );
> > #print "cookie:".$cookie;
> >    print <<EOM;
> >       <h5>Cookie created  <a href="/cgi-bin/sesion/cookie/
> > test.cgi">click here to check</a> </h5>
> > EOM
>
> > }
>
> > Third file to access the session values.
>
> > #!/usr/local/bin/perl5
> > &top();
> > &cookie_check();
> > &bottom();
> > sub top{
> > print <<EOM1;
> > Content-type: text/html
>
> > <html>
> >   <head>
> >     <title>Login Authentication</title>
> >   </head>
> > <body>
> > EOM1}
>
> > sub bottom{
> > print <<EOM2;
> > </body>
> > </html>
> > EOM2}
>
> > sub cookie_check{
> > use CGI;
> > use CGI::Session;
> > my $query = new CGI;
>
> > $sid = $query->cookie('CGISESSID') || $query->param('CGISESSID') ||
> > undef;
> > $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
> > $username = $session->param('username');
> > $password = $session->param('password');
>
> > print <<EOM;
> > <h3>Cookie test  $username $password</h3>
> > EOM
>
> > }
>
> > i m not getting the values when  i read here. i dont know where the
> > cookie is created. i check with the server i  could see the session
> > which is created in the server.please tell me where i m going
> > wrong.....
>
> > thanks in advance..
> > Prakash
>
> There are a number of issues that should be addressed, but the main
> issue is in cookie.cgi.  Your &top sub is outputting headers without
> the session cookie and then &login_check tries to output the headers
> again, this time with the session cookie, but it's too late.  You can
> only send the header once.

thanks for your input its working fine ...
thanks...
Prakash


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

Date: Wed, 12 Dec 2007 08:07:57 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: split is not convinient
Message-Id: <20d30e4a-8ded-4a3a-a99b-7828f7dad487@e23g2000prf.googlegroups.com>

Hi,


When I use split, there are serveral case frequently occured:

case1:

    split # default to split ' ', $_

case2:

    split /xxx/ # default to split /xxx/, $_

case3:

    split ' ', expr # ????


I do think case3 is most frequently used, but why i've to type ' '
every time, why there are no simpler syntax to use in this case?


Thanks,
Todd


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

Date: Wed, 12 Dec 2007 05:36:46 -0800 (PST)
From: inthepickle <inthepickle@gmail.com>
Subject: Stupid Mistakes
Message-Id: <6c53a51f-f120-472f-ad68-6c1351fefe3d@f3g2000hsg.googlegroups.com>

Apparently I am making a stupid mistake, but I can't see it.  I have a
text file with one 6 digit number per line which corresponds to a file
name on a network directory.  I want to find each file, then copy it
somewhere.  I am trying to do it in steps to make the find a little
faster.  If it finds the file in the first step, it should not go
through to the others, but it does.  Testing a file, I found it in the
fist step.  The length of $f was 38.  Can't figure out why it is not
picking up on the length of $f in the second step.  What am I doing
wrong?  Please help!


use File::Find ;
system ( "cls" ) ;
$incoming = "D:/Cutlist.txt" ; #directory to look in for job sheets:
$destination = "D:/SWFiles/"; #copy destination
open INC, $incoming ; #open file
@cutlist = <INC> ; #assign file to array
close INC ; #close file
foreach ( @cutlist ) { #for every number in file
	$swfile = $_ ;
	chop ( $swfile ) ;
	$subdir = substr ( $swfile,0,4 ) ; #get first 4 digits
	print "Searching Y:/SolidWorks Files/$subdir\n" ;
	@filetree = ( "Y:/SolidWorks Files/$subdir" ) ; #set to part sub dir
	find ( \&findswfile,@filetree ) ;
	if ( length ( $f ) < 2 ) { # if subdir finds failed
		print "Searching Y:/SolidWorks Files/\n" ;
		@filetree = ( "Y:/SolidWorks Files/" ) ; #set to sw dir
		find ( \&findswfile,@filetree ) ;
	} ; #end if for sw dir
	if ( length ( $f ) < 2 ) {# if subdir & swdir finds failed
		print "Searching Y:/\n" ;
		@filetree = ( "Y:/" ) ; #set entire drive
		find ( \&findswfile,@filetree ) ;
	} ; #end if for entire drive
}; #foreach
print "\nEnd Program\n" ;
sub findswfile {
	if ( ( /$swfile/ ) & ( /.SLDPRT/ | /.sldprt/ ) ) { #if part and
(caliptal or lower) match
		$f = $File::Find::name ;	#directory and file name
		print "     Found: $f\n\n" ;
		system ( "copy \"$f\" \"$destination\" >nul" ) ; #copy file to
destination
		} else {
			return ; #try again
	 } ; #end file match
} ; #endsub


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

Date: Wed, 12 Dec 2007 07:32:36 -0800 (PST)
From: "A. Bax" <c7eqjyg02@sneakemail.com>
Subject: Re: Stupid Mistakes
Message-Id: <b5256b88-206e-4465-ac0c-2b070999943a@e6g2000prf.googlegroups.com>

On Dec 12, 2:36 pm, inthepickle <inthepic...@gmail.com> wrote:

> I have a text file with one 6 digit number per line which corresponds to a
> file name on a network directory. I want to find each file, then copy it
> somewhere. I am trying to do it in steps to make the find a little faster.
> If it finds the file in the first step, it should not go through to the
> others, but it does. Testing a file, I found it in the fist step. The length
> of $f was 38. Can't figure out why it is not picking up on the length of $f
> in the second step. What am I doing wrong? Please help!

You have the wrong idea of what the find() function does. It visits
EVERY file
in the directory tree that you specify and calls findswfile() for it.
It does
not stop doing so when you decide that you found your file and print
"Found".
After executing the copy, findswfile() will return to the calling
find() which
will then go on processing the next file in the tree. The fact that
you omitted
the 'return' statement from that part of the if branch does not mean
that the
subroutine will not return! It will return when the closing '}' is
reached.

If you want to stop find() processing any more files, you have to take
some
special measures, which is setting the $File::Find::prune variable to
a true
value as soon as findswfile() is called. This involves setting a
global
variable to keep track whether the target file was found or not.

    our $f = "";
    find(\&findswfile, $topdir);
    ...

    sub findswfile
    {
        if (our $f) {
            # do not look further if we found our target
            $File::Find:prune = 1;
            return;
        }

        # Note some fixes here: use &&, not &; use ||, not |; use \.
for
        # matching of a literal full stop; collapse /\.sldprt/ || /
\.SLDPRT/
        # into /\.sldprt/i . There is still a big performance hit
because the
        # regexp /$swfile/ must be compiled for every call to
findswfile(), but
        # fixing that requires more work.

        if (/$swfile/ && /\.SLDPRT/i) {
            #if part and (caliptal or lower) match
            our $f = $File::Find::name;        #directory and file
name
            print "     Found: $f\n\n";
            system("copy \"$f\" \"$destination\" >nul"); #copy file to
destination
        }
    }

__END__


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

Date: Wed, 12 Dec 2007 07:35:03 -0800 (PST)
From: inthepickle <inthepickle@gmail.com>
Subject: Re: Stupid Mistakes
Message-Id: <3170c031-a30b-46dc-b26d-37c94f9073f1@j20g2000hsi.googlegroups.com>

FYI - It was a stupid mistake.  My text file had blank lines at the
end of the list.


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

Date: Wed, 12 Dec 2007 07:35:08 -0800 (PST)
From: inthepickle <inthepickle@gmail.com>
Subject: Re: Stupid Mistakes
Message-Id: <cfebe6ae-b466-413a-aee6-7ab13d742f5e@v4g2000hsf.googlegroups.com>

FYI - It was a stupid mistake.  My text file had blank lines at the
end of the list.


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

Date: 12 Dec 2007 11:45:37 GMT
From: t.blabb@gmail.com (Thomas Blabb)
Subject: When do I need to define a function with "use POSIX qw(.....)" and when not ?
Message-Id: <475fc9e1$0$16666$9b4e6d93@newsspool3.arcor-online.net>

I saw sometimes perl scripts where functions are defined in the POSIX line and others where not.
Example:

When should I write:

use POSIX qw(strftime);
 .... strftime ..... ;

and when simply:

use POSIX;
 .... strftime ..... ;

Tom



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

Date: Wed, 12 Dec 2007 12:04:47 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: When do I need to define a function with "use POSIX qw(.....)" and when not ?
Message-Id: <slrnflvjfc.lhb.tadmc@tadmc30.sbcglobal.net>

Thomas Blabb <t.blabb@gmail.com> wrote:
> I saw sometimes perl scripts where functions are defined in 
                                                   ^^^^^^^
> the POSIX line and others where not.


That is NOT where the function is defined.

The function is defined in the POSIX.pm module.


> Example:
>
> When should I write:
>
> use POSIX qw(strftime);
> .... strftime ..... ;


Here only one function from POSIX.pm is imported into your program's
namespace.


> and when simply:
>
> use POSIX;
> .... strftime ..... ;


Here every function in POSIX.pm's @EXPORT is imported into your program's
namespace.


The first is better Software Engineering, the second is more convenient.


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


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

Date: Wed, 12 Dec 2007 07:02:09 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: When do I need to define a function with "use POSIX qw(.....)" and when not ?
Message-Id: <86lk80f4mm.fsf@lifelogs.com>

On Wed, 12 Dec 2007 12:04:47 GMT Tad J McClellan <tadmc@seesig.invalid> wrote: 

TJM> Thomas Blabb <t.blabb@gmail.com> wrote:
>> use POSIX qw(strftime);
>> use POSIX;

TJM> The first is better Software Engineering, the second is more convenient.

(This is similar to "import package.class" vs. "import package.*" in
Java, which is also a matter of taste...)

I wonder if the first really is better.  I can think of two problems
with a full import:

1) memory usage
2) name conflicts

The latter seems bad until you realize none of your code should be
overriding POSIX functions anyhow.  For the former, these are C
interfaces so they shouldn't take up too much memory, right?  What other
problems are there?  I'm curious about this so please give me your
opinions.

Ted


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

Date: 12 Dec 2007 14:46:34 GMT
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: When do I need to define a function with "use POSIX qw(.....)" and when not ?
Message-Id: <475ff44a$0$16792$e4fe514c@dreader27.news.xs4all.nl>

On Wed, 12 Dec 2007 07:02:09 -0600, Ted Zlatanov wrote:

> I wonder if the first really is better.  I can think of two problems
> with a full import:
> 
> 1) memory usage

AFAIK if you don't explicitly import specific functions, they'll only be 
loaded when you actually use them. See AutoLoader. This does slow down 
the first call to such a function a bit.

> 2) name conflicts

Also, POSIX.pm is *large*. By explicitly importing the functions you use 
it's easy to find where they're coming from without having to look 
anywhere outside the file that uses them or having to rember that 
isxdigit is part of POSIX.pm.

Joost.



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

Date: Wed, 12 Dec 2007 15:05:08 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: When do I need to define a function with "use POSIX qw(.....)" and when not ?
Message-Id: <4u9535-jr1.ln1@osiris.mauzo.dyndns.org>


Quoth Joost Diepenmaat <joost@zeekat.nl>:
> On Wed, 12 Dec 2007 07:02:09 -0600, Ted Zlatanov wrote:
> 
> > I wonder if the first really is better.  I can think of two problems
> > with a full import:
> > 
> > 1) memory usage
> 
> AFAIK if you don't explicitly import specific functions, they'll only be 
> loaded when you actually use them. See AutoLoader. This does slow down 
> the first call to such a function a bit.

AutoLoading only happens on first call, regardless of imports:

~/src/perl% ktrace perl -MPOSIX=errno 
                        -e'open my $F, ">", "test-errno"; errno;'
~/src/perl% kdump -tn | grep errno
  2127 perl     NAMI  "test-errno"
  2127 perl     NAMI  "/usr/local/lib/perl5/5.8.8/mach/auto/POSIX/errno.al"
  2127 perl     NAMI  "/usr/local/lib/perl5/5.8.8/mach/auto/POSIX/errno.al"
  2127 perl     NAMI  "/usr/local/lib/perl5/5.8.8/mach/auto/POSIX/errno.al"

perl doesn't even look for the .al until after it's opened the file.
Whether functions are AutoLoaded or not depends entirely on the module:
most of POSIX's useful functions (including strftime) are written in C,
so they can't be, except insofar as your OS will only page in the
relevant parts of the .so when they are needed :).

Ben



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

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


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