[31947] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3210 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 15 06:09:20 2010

Date: Mon, 15 Nov 2010 03:09:06 -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           Mon, 15 Nov 2010     Volume: 11 Number: 3210

Today's topics:
    Re: if ('A:B:C' =~ /:(.*?)$/) then why the heck is $1 ' <tadmc@seesig.invalid>
    Re: if ('A:B:C' =~ /:(.*?)$/) then why the heck is $1 ' <xhoster@gmail.com>
    Re: reading file containg passwords <xhoster@gmail.com>
        scripting web 2.0 sites to download howto <meshulum@gmail.com>
    Re: What is the array that contains all of $1, $2, $3 . <willem@turtle.stack.nl>
    Re: What is the array that contains all of $1, $2, $3 . <sherm.pendley@gmail.com>
    Re: What is the array that contains all of $1, $2, $3 . <sherm.pendley@gmail.com>
    Re: What is the array that contains all of $1, $2, $3 . <willem@turtle.stack.nl>
    Re: What is the array that contains all of $1, $2, $3 . <sherm.pendley@gmail.com>
    Re: What is the array that contains all of $1, $2, $3 . <willem@turtle.stack.nl>
    Re: What is the array that contains all of $1, $2, $3 . <skye.shaw@gmail.com>
    Re: What is the array that contains all of $1, $2, $3 . <uri@StemSystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Nov 2010 09:48:41 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: if ('A:B:C' =~ /:(.*?)$/) then why the heck is $1 'B:C' and not just 'C'
Message-Id: <slrnie01ma.2hk.tadmc@tadbox.sbcglobal.net>

Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> On 2010-11-13 03:37, Xho Jingleheimerschmidt <xhoster@gmail.com> wrote:
>> Really it is not non-greedy.  It is still greedy, it just greedy for 
>> less, rather than greedy for more.  It it is still greedy because it 
>> satisfies itself, without looking around at the "wants" of others.


Patterns match left-to-right, this is the essential thing that
the OP was missing.

There are no "wants" of others, unless the others are to the left
of the part being considered.


>> The colon is also greedy.  It is greedy to match as far left as it can 
>> get away with.  And because it comes before the .*? does, its greed wins.


It is not the colon's greed that makes it want to match as far left
as possible, it is the left-to-right nature of regular expressions
that makes it match at the leftmost opportunity.


> Please. "Greedy" in the context of regular expressions is a technical
> term with a precisely defined meaning. You are not helping by inventing
> a different meaning for the word based on its meaning in common English.


An important concept to grokking regex greed is that "greedy" never
changes whether a pattern will match or not.

If it matches greedy, it will match non-greedy.

If it fails to match greedy, it will fail to match non-greedy.

Greed does not affect "match or fail".

Greed only comes in to play when there is more than one way for
the match to succeed. If greedy, then it chooses the longest way,
if non-greedy it chooses the shortest way. There is no way to get
it to match any of the intermediate-length ways.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sun, 14 Nov 2010 16:33:20 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: if ('A:B:C' =~ /:(.*?)$/) then why the heck is $1 'B:C' and not just 'C'
Message-Id: <4ce07dce$0$10093$ed362ca5@nr5-q3a.newsreader.com>

Peter J. Holzer wrote:
> On 2010-11-13 03:37, Xho Jingleheimerschmidt <xhoster@gmail.com> wrote:
>> Really it is not non-greedy.  It is still greedy, it just greedy for 
>> less, rather than greedy for more.  It it is still greedy because it 
>> satisfies itself, without looking around at the "wants" of others.
> 
>> The colon is also greedy.  It is greedy to match as far left as it can 
>> get away with.  And because it comes before the .*? does, its greed wins.
> 
> Please. "Greedy" in the context of regular expressions is a technical
> term with a precisely defined meaning. You are not helping by inventing
> a different meaning for the word based on its meaning in common English.

Greedy is well defined in the field of computer science, and I am not 
the one inventing new meanings for it.

Xho


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

Date: Sat, 13 Nov 2010 19:55:41 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: reading file containg passwords
Message-Id: <4ce07d56$0$10080$ed362ca5@nr5-q3a.newsreader.com>

John wrote:
> Hi
> 
> I have a web perl script.  In the script I need to access a SQL database.  I 
> have the password as a string in the script.  Clearly anyone downloading the 
> script can see it. 

So then don't let people download the script.

> I tried putting the password in a file (chmod 0400 - 
> read by owner only). 

Who is the owner?

> Unforunately, being on the web I need to set it to 
> 0444 - read by everyone - which defeats the aim. I appreciate it is more of 
> a linux problem that Perl but what do other do when they have passwords they 
> need to send to a SQL database etc. when running a Perl script on the web.

Don't serve your meant-for-execution scripts as content over the web.

Don't run on a shared web server with other users you don't trust. 
Barring that, have the shared server in the hands of a good 
administrator who configures apache to use setuid or kin to isolate users.

Xho


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

Date: Sun, 14 Nov 2010 07:28:12 -0800 (PST)
From: shul <meshulum@gmail.com>
Subject: scripting web 2.0 sites to download howto
Message-Id: <a3d0457f-1d79-4f54-a32d-af06509f9124@y2g2000prf.googlegroups.com>

It is more and more difficult to script download stuff from websites
using tools like wget
or LWP because the sites dont have static contents.

Many web sites, even after you fill in a field and the site 'returns'
the data (such as links to files or even worse links to pages with
links to files), the data is not 'visible' in the sense that you
cannot save the content of the screen and be able to access the links
on the page to write a script. you must highlight each link and copy
its location by hand and then write a script to do your downloading.

i see that there are javascipt tools to work with this that can be
integrated into the browser, such as greasemonkey and Chickenfoot.

Are there any similar perl tools?

thanks


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

Date: Sun, 14 Nov 2010 11:19:26 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <slrnidvhdu.2vbd.willem@turtle.stack.nl>

jidanni@jidanni.org wrote:
) What is the array that contains all of $1, $2, $3 ...?
) man perlvar doesn't say which.
)
) I would like to say
) print "@zzz";
) instead of
) print "$1 $2 $3".

I searched for it and haven't found it.
IMO this is an oversight in the language.

However, there are the @+ and @- arrays which you can use,
together with substr, to create such an array.

Off the top of my head:

$str =~ /re/;
my @match = map { substr($str, $-[$_], $+[$_] - $-[$_]) } (0 .. $#- + 1);

Now $match[2] should be equal to $2.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Sun, 14 Nov 2010 08:09:25 -0500
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <m2sjz4t5kq.fsf@sherm.shermpendley.com>

jidanni@jidanni.org writes:

> What is the array that contains all of $1, $2, $3 ...?
> man perlvar doesn't say which.

There's no particular named variable, and none needed - just do the
matching in list context to assign the results of the subexpressions
to an array or to a list of scalars:

  my @zzz =~ /(what)(ever)/;
  my ($fee, $fie, $foe, $fum) =~ /(fee)(fie)(foe)(fum)/;

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Sun, 14 Nov 2010 08:11:48 -0500
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <m2oc9st5gr.fsf@sherm.shermpendley.com>

Willem <willem@turtle.stack.nl> writes:

> Off the top of my head:
>
> $str =~ /re/;
> my @match = map { substr($str, $-[$_], $+[$_] - $-[$_]) } (0 .. $#- + 1);

Ewwww!

  my @match =~ /re/;

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Sun, 14 Nov 2010 13:25:30 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <slrnidvoqa.io.willem@turtle.stack.nl>

Sherm Pendley wrote:
) Willem <willem@turtle.stack.nl> writes:
)
)> Off the top of my head:
)>
)> $str =~ /re/;
)> my @match = map { substr($str, $-[$_], $+[$_] - $-[$_]) } (0 .. $#- + 1);
)
) Ewwww!
)
)   my @match =~ /re/;

Technically, you meant: my @match = $str =~ /(re)/;

However, try that approach in this case:

 while ($str =~ /$regex/g) {
   my @match = map { substr($str, $-[$_], $+[$_] - $-[$_]) } (0 .. $#- + 1);
   ...
 }

Where $regex is user-supplied and has an unknown number
of capturing parens.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Sun, 14 Nov 2010 08:35:01 -0500
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <m239r41116.fsf@sherm.shermpendley.com>

Willem <willem@turtle.stack.nl> writes:

> Sherm Pendley wrote:
> ) Willem <willem@turtle.stack.nl> writes:
> )
> )> Off the top of my head:
> )>
> )> $str =~ /re/;
> )> my @match = map { substr($str, $-[$_], $+[$_] - $-[$_]) } (0 .. $#- + 1);
> )
> ) Ewwww!
> )
> )   my @match =~ /re/;
>
> Technically, you meant: my @match = $str =~ /(re)/;

Yep. Still have too much blood in the coffeestream this morning. :-)

> However, try that approach in this case:
>
>  while ($str =~ /$regex/g) {
>    my @match = map { substr($str, $-[$_], $+[$_] - $-[$_]) } (0 .. $#- + 1);
>    ...
>  }
>
> Where $regex is user-supplied and has an unknown number
> of capturing parens.

Untested, typed into mail:

while (my @matches = $str =~ /$regex/g) {
}

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Sun, 14 Nov 2010 15:12:09 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <slrnidvv29.2bf.willem@turtle.stack.nl>

Sherm Pendley wrote:
) Untested, typed into mail:
)
) while (my @matches = $str =~ /$regex/g) {
) }

Test it.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Sun, 14 Nov 2010 10:24:06 -0800 (PST)
From: "Skye Shaw!@#$" <skye.shaw@gmail.com>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <c177e840-6c53-4dae-bf2e-1754e79f7a58@r21g2000pri.googlegroups.com>

On Nov 14, 1:57=A0am, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "SS" =3D=3D Skye Shaw!@#$ <skye.s...@gmail.com> writes:
>
> =A0 SS> map $$_, grep defined $$_, (1..9)
>
> twice as horrible as it uses symrefs twice. i hope you don't code this
> way in production.

In general I agree that symrefs should be avoid. But I don't agree
that the mere use of them in certain contexts denotes horrible
code.

Do you prefer to explicitly code 10 simple setters just to avoid
creating them via an array with symrefs?

Manipulating the match offsets via @- and @+ is not horrible code?

(uh oh, have I just started a what makes Perl code horrible
conversation ;)

Though I believe your point is to never use a "no strict" solution if
there's an alternate, "strict" one and, in this case, as you've
pointed out, @zzz =3D~ m// is the way to go.

-Skye













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

Date: Sun, 14 Nov 2010 14:02:08 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: What is the array that contains all of $1, $2, $3 ...?
Message-Id: <87k4kfenkf.fsf@quad.sysarch.com>

>>>>> "SS" == Skye Shaw!@#$ <skye.shaw@gmail.com> writes:

  SS> On Nov 14, 1:57 am, "Uri Guttman" <u...@StemSystems.com> wrote:
  >> >>>>> "SS" == Skye Shaw!@#$ <skye.s...@gmail.com> writes:
  >> 
  >>   SS> map $$_, grep defined $$_, (1..9)
  >> 
  >> twice as horrible as it uses symrefs twice. i hope you don't code this
  >> way in production.

  SS> In general I agree that symrefs should be avoid. But I don't agree
  SS> that the mere use of them in certain contexts denotes horrible
  SS> code.

then you are wrong. they should ONLY be used when munging the actual
symbol table. do you realize that the symbol table is just a very
specialized hash tree? why use a slow special hash tree which can cause
bugs via action at a distance when you can use normal hashes? hashes are
safer, faster, isolated, easier to modify, etc.

  SS> Do you prefer to explicitly code 10 simple setters just to avoid
  SS> creating them via an array with symrefs?

no, just solve it with the correct solution. assigning the regex
expression to an array does it. no symrefs needed.


  SS> Manipulating the match offsets via @- and @+ is not horrible code?

no, it is not. i wouldn't use it to get all the grabs but they have
their uses. symrefs to get $1 is never a good idea nor EVER needed. it
is just a bad idea. drop it from your coding style. now.

  SS> (uh oh, have I just started a what makes Perl code horrible
  SS> conversation ;)

no, you started a what makes YOUR perl code bad conversation. perl is
just a fine language. like all langs, there are good and bad ways to use
it. symrefs are for munging the symbol table. all other uses are not
cool. simple rule, easy to understand, easy to obey. anyone violating it
is not coding good perl. there are no exceptions.

  SS> Though I believe your point is to never use a "no strict" solution if
  SS> there's an alternate, "strict" one and, in this case, as you've
  SS> pointed out, @zzz =~ m// is the way to go.

no, my point is not to use symrefs except when munging the symbol
table. this isn't an exception. you never need symrefs for normal perl
coding and data handling. you just don't need them. that is why strict
disallows them and why we always say to use strict. munging the symbol
table is a rare thing and only certain code needs to do it. it is not
common code so it should be the exception and you would need to disable
strict. you need a real reason, not some little shorthand code that is
very poor style and likely to be buggy. that is no excuse for symrefs.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

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


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