[19933] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2128 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 14 00:10:33 2001

Date: Tue, 13 Nov 2001 21:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005714611-v10-i2128@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 13 Nov 2001     Volume: 10 Number: 2128

Today's topics:
    Re: Need help -- Perl Docs in HTML (Joe Smith)
    Re: RegEx problem -- trying to match To: or From: at be <admin@asarian-host.net>
    Re: RegEx problem -- trying to match To: or From: at be <admin@asarian-host.net>
        Regular Expression BackTracking (Artist)
    Re: Regular Expression BackTracking <mgjv@tradingpost.com.au>
    Re: stacked if statements <godzilla@stomp.stomp.tokyo>
    Re: stacked if statements <godzilla@stomp.stomp.tokyo>
    Re: stacked if statements (Damian Conway)
    Re: stacked if statements <wyzelli@yahoo.com>
    Re: stacked if statements (Garry Williams)
    Re: stacked if statements <mgjv@tradingpost.com.au>
    Re: using modules in subdirectories with a dash <goldbb2@earthlink.net>
        what is this non-sense? (Newbie)
    Re: what is this non-sense? <uri@stemsystems.com>
    Re: Why Perl For Database Handling? (Matthew Persico)
    Re: Why Perl For Database Handling? <mgjv@tradingpost.com.au>
        WWWBoard alternative?  Images? (Jay S.)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 14 Nov 2001 00:43:30 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: Need help -- Perl Docs in HTML
Message-Id: <S6jI7.4077$Le.99872@sea-read.news.verio.net>

In article <m3wv0veshl.fsf@saba.bass>,  <jks@saba.bass> wrote:
>I need a repeatable process to build a complete, static directory tree of the
>Perl documentation in HTML format from the Perl source distribution, with
>working links.

Personally, I would let someone else do all the work.
1) Install ActiveState perl on a PC.
2) Create a zip file of D:\perl\html.
3) Extract the zip file on another PC, on Unix, etc.
	-Joe

--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Wed, 14 Nov 2001 03:58:13 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <pZlI7.6540$jp.751419@bin2.nnrp.aus1.giganews.com>

"jennyw" <donotspam-jen@dangerousideas.com> wrote in message
news:9spcgl$su1$1@bob.news.rcn.net...

> Actually, I realized the problem. I need to use:
>
> /(^To:)|(^From:)/
>
> I'm not sure why the carets (^) need to be inside the parentheses, but it
> works this way.


Actually, you need:

/^(To|From):/i

- Mark

        System Administrator Asarian-host.org

---
"If you were supposed to understand it,
we wouldn't call it code." - FedEx




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

Date: Wed, 14 Nov 2001 04:29:36 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <PqmI7.44774$XR.3464393@bin3.nnrp.aus1.giganews.com>

"jennyw" <donotspam-jen@dangerousideas.com> wrote in message
news:9spcgl$su1$1@bob.news.rcn.net...

> Actually, I realized the problem. I need to use:
>
> /(^To:)|(^From:)/
>
> I'm not sure why the carets (^) need to be inside the parentheses, but it
> works this way.

A small word extra. The caret needs to be outside the parentheses. Now you
are matching two distinct entities: "(either something starting with To,
followed by a colon), or (something starting with From, followed by a
colon)."

But, what you want is this:

/^(To|From):/i

Which matches "something that starts with (either To or From), followed by a
colon."

So, if you were to just say:

(^To:)|(From:)/

You would match "(either something starting with To, followed by a colon),
or (From, anywhere in the line, followed by a colon)." That is why the caret
goes outside the parentheses, as it always applies, and the parentheses only
go around the either/or condition.

- Mark

        System Administrator Asarian-host.org

---
"If you were supposed to understand it,
we wouldn't call it code." - FedEx




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

Date: 13 Nov 2001 19:37:41 -0800
From: googleartist@yahoo.com (Artist)
Subject: Regular Expression BackTracking
Message-Id: <de3ad953.0111131937.6fa03aff@posting.google.com>

Hi,
 How I can have 'the same regex as \1 or \2' ?
 I would like to do:
 m[(\w+\d)(\s+)(\w+\d)]

This should match 'hello2 hi3'.


Now, note (\w+\d) come twice here.. I would like to avoid that..
ie.. I would like to have it mentioned only once and then some type of
backtracking..to repeate the 'same type of regex pattern'.


Note that,  intention is not just to match 'hello2 hello2' but to
match 'hello2 hi3' also..

Thanks,
Artist..


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

Date: Wed, 14 Nov 2001 03:57:20 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Regular Expression BackTracking
Message-Id: <slrn9v3qtq.6ia.mgjv@verbruggen.comdyn.com.au>

On 13 Nov 2001 19:37:41 -0800,
	Artist <googleartist@yahoo.com> wrote:
> Hi,
>  How I can have 'the same regex as \1 or \2' ?
>  I would like to do:
>  m[(\w+\d)(\s+)(\w+\d)]
> 
> This should match 'hello2 hi3'.
> 
> 
> Now, note (\w+\d) come twice here.. I would like to avoid that..
> ie.. I would like to have it mentioned only once and then some type of
> backtracking..to repeate the 'same type of regex pattern'.
> 
> 
> Note that,  intention is not just to match 'hello2 hello2' but to
> match 'hello2 hi3' also..

I don't think there is any magical metacharacter for that. For small
regexen like this, I wouldn't bother, but you could use the qr()
operator for more complex situations:

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

my $word_digit = qr/\w+\d/;

while (<DATA>)
{
	if (m/($word_digit)\s+($word_digit)/)
	{
		print "'$1' - '$2'\n";
	}
}

__DATA__
hello2 hi3
hello hi3
some stuff otherword1 and1 foo


Especially when the regular expression becomes complicated this can
make your matching a lot more readable.

I've got some log parsing scripts somewhere where I use this, quite
satisfactory.

Martien
-- 
                                | 
Martien Verbruggen              | For heaven's sake, don't TRY to be
Trading Post Australia Pty Ltd  | cynical. It's perfectly easy to be
                                | cynical.


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

Date: Tue, 13 Nov 2001 15:11:49 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: stacked if statements
Message-Id: <3BF1A8B5.A684A127@stomp.stomp.tokyo>

Tom McDonough wrote:
 
> Registrants for a conference will fill out my form and my script will
> confirm their registration info.  There are three sessions.  Registrants
> may register for one, two or all.  Selection of a single session or
> 'all' works fine but if someone registers for two, only the later
> session is printed.  I'll bet this is Perl 101 but I'm learning as I go.
 
> Here's my snippet:

(snipped)

>         if ($form{'session'}=~'one') {
>                 print "January session\n";}
>         if ($form{'session'}=~'two') {
>                 print "February session\n";}
>         if ($form{'session'}=~'three') {
>                 print "March session\n";}


Others have highlighted your common error in use
of " = " where " eq " should be used. No big deal.

You can improve your logic on this quite a bit and,
improve the efficiency and speed of your script.

Based on what you have presented you strongly suggest
you are using radio buttons or check boxes for input.
There is no hint of compensation for a visitor making
a typographical error such as "too" instead of "two."

With fixed choices, this is, no typing required by
a visitor but rather clickables, radio buttons would
be a great choice, your code can be made very simple
and quick with little effort.

Rather than use your current values and converting
them as needed to months of the year, have your
form input the names of the months directly.

<... some button Name="session" Value="All">
<... some button Name="session" Value="January">
<... etc... etc...>

print "You have registered for: $form('session') sessions.\n";

Incidently, you need an article such as "the" or "a" in
front of your month names and, a choice between singular
or plural sessions along with a period. It is common to
introduce trade-offs for more efficient code. Your true
skill is in weighing which of many methods is best.


if ($form(session) eq "All")
 { print "You have registered for: All sessions\n"; }
else
 { print "You have registered for: The $form('session') session.\n"; }
 

A little if / else logic seems appropriate, yes?

Have your form input month names directly via user
clickables rather than having your script convert
numerical words to months. You will find this easier
and more efficient along with eliminating user typos.


Godzilla!


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

Date: Tue, 13 Nov 2001 15:24:42 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: stacked if statements
Message-Id: <3BF1ABBA.6B570940@stomp.stomp.tokyo>

Godzilla! wrote:
 
> Tom McDonough wrote:
 

(snipped.)


>  { print "You have registered for: All sessions\n"; }


Did I mention you need to add a period to your sentences?


{ print "You have registered for: All sessions.\n"; }


Well, you appear to be male so no worries about this, yes?
Seems your concerns may lean more towards Richard and Harry.


Godzilla!


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

Date: 13 Nov 2001 23:52:20 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: stacked if statements
Message-Id: <9ssbnk$ks0$1@towncrier.cc.monash.edu.au>

"Bruce Irvine" <bruce@sportingpulse.com> writes:

   > Is it true that Perl 6 will have a "switch/Select Case" statement for
   > this type of code.

Yes.

And Perl 5 has them too: take a look at the Switch.pm module on CPAN.

Damian


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

Date: Wed, 14 Nov 2001 09:52:38 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: stacked if statements
Message-Id: <vOiI7.2$sJ.150@vicpull1.telstra.net>

"Damian Conway" <damian@cs.monash.edu.au> wrote in message
news:9ss2s9$it3$1@towncrier.cc.monash.edu.au...
> Tom McDonough <tam@patriot.net> writes:
<snip>
>
> if ($form{'session'} =~ 'all') {

I remembered reading that the m was optional with / as the delimiter,
and having never seen a match performed like that before.  (I tried it and I
know it works)  So I went looking through the documentation to try and find
where bare ' as delimiters (without the m) is described.

It would appear from the documentation that they aren't - vis:

From perlop:
If ``/'' is the delimiter then the initial m is optional. With the m you can
use any pair of non-alphanumeric, non-whitespace characters as delimiters.
This is particularly useful for matching path names that contain ``/'', to
avoid LTS (leaning toothpick syndrome). If ``?'' is the delimiter, then the
match-only-once rule of ?PATTERN? applies. If ``''' is the delimiter, no
interpolation is performed on the PATTERN.

However, also from perlop:

Customary  Generic        Meaning        Interpolates
    ''       q{}          Literal             no
    ""      qq{}          Literal             yes
    ``      qx{}          Command             yes (unless '' is delimiter)
            qw{}         Word list            no
    //       m{}       Pattern match          yes (unless '' is delimiter)
            qr{}          Pattern             yes (unless '' is delimiter)
             s{}{}      Substitution          yes (unless '' is delimiter)
            tr{}{}    Transliteration         no (but see below)

This may be an area of the documentation that is not as clear as it might
be, since extrapolating from the above (that '' can be used as a match
operator without the m), it would appear that ? can be used this way too
(which it can - I tried) though that is not clear from the documentation.

This is the type of thing I would comment on if sections of the
documentation were frequently posted, though in this case, I have learned
from someone's example rather than the docs.


Wyzelli
--
push@x,$_ for(a..z);push@x,'
';@z='092018192600131419070417261504171126070002100417'=~/(..)/g;foreach
$y(@z){$_.=$x[$y]}y/jp/JP/;print;









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

Date: Wed, 14 Nov 2001 04:00:26 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: stacked if statements
Message-Id: <slrn9v3r2t.3e9.garry@zfw.zvolve.net>

On Wed, 14 Nov 2001 09:52:38 +0930, Wyzelli <wyzelli@yahoo.com> wrote:
> "Damian Conway" <damian@cs.monash.edu.au> wrote in message
> news:9ss2s9$it3$1@towncrier.cc.monash.edu.au...
>> Tom McDonough <tam@patriot.net> writes:
> <snip>
>>
>> if ($form{'session'} =~ 'all') {
> 
> I remembered reading that the m was optional with / as the delimiter,
> and having never seen a match performed like that before.  (I tried it and I
> know it works)  So I went looking through the documentation to try and find
> where bare ' as delimiters (without the m) is described.

That is described in the perlop manual page under "Binding Operators": 

     Binary "=~" binds a scalar expression to a pattern match.
     ...
     If the right argument is an expression rather than a search
     pattern, substitution, or transliteration, it is interpreted
     as a search pattern at run time.  This can be less efficient
     than an explicit search, because the pattern must be
     compiled every time the expression is evaluated.

> This may be an area of the documentation that is not as clear as it might
> be, since extrapolating from the above (that '' can be used as a match
> operator without the m), it would appear that ? can be used this way too
> (which it can - I tried) though that is not clear from the documentation.

But ? *is* a delimiter for a pattern match.  ' is not.  

-- 
Garry Williams


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

Date: Wed, 14 Nov 2001 04:33:45 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: stacked if statements
Message-Id: <slrn9v3t23.6ia.mgjv@verbruggen.comdyn.com.au>

On Wed, 14 Nov 2001 04:00:26 GMT,
	Garry Williams <garry@ifr.zvolve.net> wrote:
> On Wed, 14 Nov 2001 09:52:38 +0930, Wyzelli <wyzelli@yahoo.com> wrote:
>> "Damian Conway" <damian@cs.monash.edu.au> wrote in message
>> news:9ss2s9$it3$1@towncrier.cc.monash.edu.au...
>>> Tom McDonough <tam@patriot.net> writes:
>> <snip>
>>>
>>> if ($form{'session'} =~ 'all') {

[snip documentation quite showing why that works]

>> This may be an area of the documentation that is not as clear as it might
>> be, since extrapolating from the above (that '' can be used as a match
>> operator without the m), it would appear that ? can be used this way too
>> (which it can - I tried) though that is not clear from the documentation.
>
> But ? *is* a delimiter for a pattern match.  ' is not.  

I think you probably know this, but just for the record: all three
mentioned pattern mathing operations are slightly different.

The following are all equivalent:

  $foo =~ m[pattern];
  $foo =~ m#pattern#;
  $foo =~ m%pattern%;
  $foo =~ /pattern/;

  $pattern = qr/pattern/;
  $foo =~ /$pattern/;
  $foo =~ $pattern;

Some other characters can be used as delimiters, without changing the
way these operations work.


These are also equivalent, but different from the previous set:

  $foo =~ m'pattern'; # Single quote delimiters prevent interpolation

  $pattern = qr'pattern';
  $foo =~ /$pattern/;
  $foo =~ m[$pattern];
  $foo =~ $pattern;

These ones get interpreted at run time:

  $foo =~ 'pattern';

  $pattern = 'pattern';
  $foo =~ $pattern;


These next ones only matches between calls to the reset operator, which
could surprise people if they decided to start using it without
reading up on it in perlop:

  $foo = ?pattern?;
  $foo =~ m?pattern?; 

(There is no qr?? special behaviour. qr?? behaves the same as qr//)  

This last one is "vaguely deprecated, which means it just might
possibly be removed in some distant future version of Perl, perhaps
somewhere around the year 2168."


Confusing? Indeed.


Recommended reading: perlop documentation, sections "Binding
Operators" and "Regexp Quote-Like Operators";


Martien
-- 
                                | 
Martien Verbruggen              | I used to have a Heisenbergmobile.
Trading Post Australia Pty Ltd  | Every time I looked at the
                                | speedometer, I got lost.


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

Date: Tue, 13 Nov 2001 23:57:47 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: using modules in subdirectories with a dash
Message-Id: <3BF1F9CB.F1D13948@earthlink.net>

Lee Rossey wrote:
[snip]

BEGIN: {
    require UNIVERSAL::require;
    require UNIVERSAL::import;
    "me::exploits::CVE-2000-1131_GCI_Guestbook::gbook"->require;
    "me::exploits::CVE-2000-1131_GCI_Guestbook::gbook"->import;
}

Don't leave out the quotes, or it won't work.

-- 
Klein bottle for rent - inquire within.


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

Date: 13 Nov 2001 15:55:13 -0800
From: youradmirer@onebox.com (Newbie)
Subject: what is this non-sense?
Message-Id: <582bc82b.0111131555.20b88e25@posting.google.com>

From perl manpage for kill:
    .....
    Unlike in the shell, if SIGNAL is negative, it kills process
groups
    instead of processes. (On System V, a negative PROCESS number will
    also kill process groups, but that's not portable.) That means you
    usually want to use positive not negative signals. You may also
use
    a signal name in quotes. 
    .....

From perlipc:
    .....
    Sending a signal to a negative process ID means that you send the 
    signal to the entire Unix process-group. This code sends a hang-up
    signal to all processes in the current process group (and sets 
    $SIG{HUP} to IGNORE so it doesn't kill itself)
    .....

What? The previous implies that only System V does what is described
in the latter while the latter seems to indicate that this is true for
all Unix-lie OSes.


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

Date: Wed, 14 Nov 2001 04:59:01 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: what is this non-sense?
Message-Id: <x77ksuhrpx.fsf@home.sysarch.com>

>>>>> "N" == Newbie  <youradmirer@onebox.com> writes:

what is this subject line? your post is about signals and you caould
have written a much better subject line.

  N> From perl manpage for kill:
  N>     .....
  N>     Unlike in the shell, if SIGNAL is negative, it kills process
  N> groups
  N>     instead of processes. (On System V, a negative PROCESS number will
  N>     also kill process groups, but that's not portable.) That means you
  N>     usually want to use positive not negative signals. You may also
  N> use
  N>     a signal name in quotes. 
  N>     .....

  N> From perlipc:
  N>     .....
  N>     Sending a signal to a negative process ID means that you send the 
  N>     signal to the entire Unix process-group. This code sends a hang-up
  N>     signal to all processes in the current process group (and sets 
  N>     $SIG{HUP} to IGNORE so it doesn't kill itself)
  N>     .....

  N> What? The previous implies that only System V does what is described
  N> in the latter while the latter seems to indicate that this is true for
  N> all Unix-lie OSes.

there are 2 kill related system calls, kill and killpg. on sysV type
systems and linux and who knows what else, kill with a negative proc
number sends the signal to a process group. on BSD flavors, the killpg
call is made:

        if (val < 0) {
            val = -val;
            while (++mark <= sp) {
                I32 proc = SvIVx(*mark);
                APPLY_TAINT_PROPER();
#ifdef HAS_KILLPG
                if (PerlProc_killpg(proc,val))  /* BSD */
#else
                if (PerlProc_kill(-proc,val))   /* SYSV */
#endif

so perl itself supports the negative process id to mean the process
group. by doing so, it isolates the sysV kill which it rightly calls not
portable. the docs are not exactly clear here but i wouldn't call it
nonsense.

on solaris (sysV flavor), killpg is a library call and kill is a system
call. 

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 13 Nov 2001 19:06:50 -0800
From: persicom@acedsl.com (Matthew Persico)
Subject: Re: Why Perl For Database Handling?
Message-Id: <3cfe42ff.0111131906.4c394b76@posting.google.com>

"Ann Thompson" <annthompson2000USA@yahoo.com> wrote in message news:<9sqr1n$n71$1@slb0.atl.mindspring.net>...
> I'm a SQL person, but my boss wants me to do this in Perl. I'm thinking of
> resigning.
> 

Of course, this being a Perl group, many people were kind enough to
respond with Perl hints. But that's putting the cart ahead of the
horse. I'd like to know:

1) What is the environment you are programming in (interactive client,
web page, automated batch process)?

2) Why has your boss specified not only the problem, but also the
solution? There must be a reason, good or bad.

I'd like a bit more info before I reply.

-- 
Matthew O. Persico
NY, DC, PA - United We Stand


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

Date: Wed, 14 Nov 2001 03:39:01 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Why Perl For Database Handling?
Message-Id: <slrn9v3prf.6ia.mgjv@verbruggen.comdyn.com.au>

On 13 Nov 2001 19:06:50 -0800,
	Matthew Persico <persicom@acedsl.com> wrote:
> "Ann Thompson" <annthompson2000USA@yahoo.com> wrote in message news:<9sqr1n$n71$1@slb0.atl.mindspring.net>...
>> I'm a SQL person, but my boss wants me to do this in Perl. I'm thinking of
>> resigning.

[snip]

> 2) Why has your boss specified not only the problem, but also the
> solution? There must be a reason, good or bad.

Unfortunately, this is all too common with a certain class of
(micro)managers. It's the death of many projects before they have even
started.

Martien
-- 
                                | 
Martien Verbruggen              | 
Trading Post Australia Pty Ltd  | Curiouser and curiouser, said Alice.
                                | 


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

Date: 13 Nov 2001 17:13:23 -0800
From: hawk_214@mailandnews.com (Jay S.)
Subject: WWWBoard alternative?  Images?
Message-Id: <5ae90e89.0111131713.3b27774c@posting.google.com>

I have a WWWBoard running OK, but I would like users to be able to
post images within messages.  I know I can now post a URL, but I would
rather be able to put the image directly into the message.

It would be great to be able to put something like /image name/ within
the message, and then when they press submit, it prompts me for a file
name from their hard drive.  I have heard that Discus can do this, but
it is *so* complex for a simple board like mine.

Thanks.


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

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.  

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 V10 Issue 2128
***************************************


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