[24488] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6668 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 9 00:05:57 2004

Date: Tue, 8 Jun 2004 21:05: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, 8 Jun 2004     Volume: 10 Number: 6668

Today's topics:
    Re: Beginner needs help with script :) <notachance@inhell.com>
    Re: Beginner needs help with script :) <Andrew@DeFaria.com>
    Re: call win32 API from linux perl script <Petri_member@newsguy.com>
        CGI::Cookie    Setting Expiry <ducott_99@yahoo.com>
    Re: CGI::Cookie    Setting Expiry <emschwar@pobox.com>
    Re: CGI::Cookie    Setting Expiry <mb@uq.net.au.invalid>
    Re: CGI::Cookie    Setting Expiry <matthew.garrish@sympatico.ca>
    Re: CGI::Cookie    Setting Expiry <ducott_99@yahoo.com>
    Re: CGI::Cookie    Setting Expiry <noreply@gunnar.cc>
    Re: CGI::Cookie    Setting Expiry <matthew.garrish@sympatico.ca>
    Re: CGI::Cookie    Setting Expiry <matthew.garrish@sympatico.ca>
    Re: CGI::Cookie    Setting Expiry <tadmc@augustmail.com>
        Contructing a dir. tree (Prabh)
    Re: Converting a string to multiple search patterns (Anno Siegel)
    Re: Converting a string to multiple search patterns <bmb@ginger.libs.uga.edu>
    Re: Converting a string to multiple search patterns <bmb@ginger.libs.uga.edu>
    Re: Converting a string to multiple search patterns <bmb@ginger.libs.uga.edu>
    Re: Cute bit of Perl to Assign $1,$2 to named variables <uri@stemsystems.com>
        match aaa but not 123aaa <ken_sington@nospam_abcdefg.com>
    Re: match aaa but not 123aaa (Jay Tilton)
    Re: match aaa but not 123aaa <matthew.garrish@sympatico.ca>
    Re: Net::SMTP fails connection in CGI <matthew.garrish@sympatico.ca>
    Re: Text GUI with Perl (Kevin Collins)
        Upgrading from 5.6.0 to latest version on SuSE 7.3 box <no_replies@fake_email_address.invalid>
    Re: Upgrading from 5.6.0 to latest version on SuSE 7.3  (David Efflandt)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 9 Jun 2004 02:28:11 +0100
From: "Player" <notachance@inhell.com>
Subject: Re: Beginner needs help with script :)
Message-Id: <ca5p3a$di0$1@newsg4.svr.pol.co.uk>


> Sorry Tad I can't let that go unchallnged.
>
> On entering any new social situation (club, workplace, country) one is
> expected to research (or at least try to observe) what is accepted
> behaviour.  Not doing so would be classed as bein rude by any normal
> person.
>
> Usenet is no different at all.  We should not give 'Player' the get
> out clause of preteding that what he did would not be seen as rude in
> the 'real world'.

I wouldn't, many a person says, "I beg your pardon" or words to similar
effect when confronted with replies similar to what experienced, and that is
more or less how I replied.

Player




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

Date: Tue, 8 Jun 2004 19:03:48 -0700
From: "Andrew DeFaria" <Andrew@DeFaria.com>
Subject: Re: Beginner needs help with script :)
Message-Id: <89626$40c66fea$c09cfc9$23187@msgid.meganewsservers.com>

"Player" <notachance@inhell.com> wrote in message
news:ca5p3a$di0$1@newsg4.svr.pol.co.uk...
>
> > Sorry Tad I can't let that go unchallnged.
> >
> > On entering any new social situation (club, workplace, country) one is
> > expected to research (or at least try to observe) what is accepted
> > behaviour.  Not doing so would be classed as bein rude by any normal
> > person.
> >
> > Usenet is no different at all.  We should not give 'Player' the get
> > out clause of preteding that what he did would not be seen as rude in
> > the 'real world'.
>
> I wouldn't, many a person says, "I beg your pardon" or words to similar
> effect when confronted with replies similar to what experienced, and that
is
> more or less how I replied.
>
> Player

Or perhaps, "Excuse me, where's the bathroom". Never had a restaurant or
club throw me out for asking that question!




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

Date: 8 Jun 2004 16:53:14 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: call win32 API from linux perl script
Message-Id: <ca5jha0mk5@drn.newsguy.com>

In article <ca31rt$gt1$1@wisteria.csv.warwick.ac.uk>, Ben Morrow says...
> AFAIK COM+ automation (OLE) doesn't allow you to interact with
> an object on another machine, so you would have the same problem
> calling an OLE function on one windows machine from another.

This is exactly what COM+ is meant for, distributing backend logic onto other
machines.
It is way of accomplishing middle-tier resource sharing, to protect more
expensive resources such as database connections.
It used to be called MS Transaction Server in the NT4 days.
You can also run separate DCOM (Distributed COM) components, outside of the COM+
resource sharing environment.

When you are running remotely, you have to remember to provide a matching
identity and correct authentication.


Petri



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

Date: Tue, 08 Jun 2004 23:43:32 GMT
From: "Robert TV" <ducott_99@yahoo.com>
Subject: CGI::Cookie    Setting Expiry
Message-Id: <Easxc.714573$Ig.256078@pd7tw2no>

Hello,

I got the basic coding from perdoc on the usage of use CGI::Cookie. The main
examples show an expiry of  '+3M'  which they say means 3 months. I would
like my cookie to expire after 10 minutes. Does anyone know the equivalent
value? I cannot locate any other info in perdoc on this issue. Another
question I would like to ask is ... if a cookie is expired, will it still
return data if fetched? Can Perl read the cookie and determine its expiry
time and print that data to screen?



[Why I'm Asking]
I am trying to build a timeout subroutine for my program. When a user logs
in, a cookie is set for 10 minutes. Each primary subroutine of the program
will check the cookie to make sure its not expired and data is being
returned, if not, user is directed back to login page. I am doing this to
prevent bookmarking of the software once logged in. If the cookie had not
expired, it writes a new 10 minute cookie then shows the relevant dat for
that section/subroutine.


TIA!! Robert





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

Date: Tue, 08 Jun 2004 18:18:06 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <eto65a1r3cx.fsf@fc.hp.com>

"Robert TV" <ducott_99@yahoo.com> writes:
> I got the basic coding from perdoc on the usage of use CGI::Cookie. The main
> examples show an expiry of  '+3M'  which they say means 3 months. I would
> like my cookie to expire after 10 minutes. Does anyone know the equivalent
> value? I cannot locate any other info in perdoc on this issue.

I don't want to be too snarky, but in the *very same sentence* where
CGI::Cookie's docs explain that +3M means 3 months in the future, it
says: "-expires accepts any of the relative or absolute date formats
recognized by CGI.pm . . .".  It also refers you to CGI.pm's documentation
in the very next sentence.  I'm hard-pressed to see how you could have
missed this.

> Another question I would like to ask is ... if a cookie is expired,
> will it still return data if fetched? Can Perl read the cookie and
> determine its expiry time and print that data to screen?

This isn't a specifically Perl question; the answer would be the same
if you were coding in PHP or Ruby.  That's not a slam, by the way;
partitioning a problem correctly is not always simple.  Anyway, read
RFC2109 for the answer, or ask on comp.infosystems.www.authoring.cgi,
where it's at least on-topic for the group.

> I am trying to build a timeout subroutine for my program. When a user logs
> in, a cookie is set for 10 minutes. Each primary subroutine of the program
> will check the cookie to make sure its not expired and data is being
> returned, if not, user is directed back to login page. I am doing this to
> prevent bookmarking of the software once logged in.

Sorry, that's not going to help much.  Cookie expiration times are
tracked on the client, not the server, and a malicious user-agent
could easily ignore the cookie's Max-Age setting.  There are better
ways to go about this; I suggest you ask around in CIWAC, where that
sort of thing is more appropriate.

> If the cookie had not expired, it writes a new 10 minute cookie then
> shows the relevant dat for that section/subroutine.

I think you have a minor, but basic misunderstanding of how cookies
work.  Asking around on a newsgroup where they discuss such things
would probably help clear things up.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Wed, 09 Jun 2004 10:34:17 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <ca5lu9$4e1$1@bunyip.cc.uq.edu.au>

Robert TV wrote:

> [Why I'm Asking]
> I am trying to build a timeout subroutine for my program. When a user logs
> in, a cookie is set for 10 minutes. Each primary subroutine of the program
> will check the cookie to make sure its not expired and data is being
> returned, if not, user is directed back to login page. I am doing this to
> prevent bookmarking of the software once logged in. If the cookie had not
> expired, it writes a new 10 minute cookie then shows the relevant dat for
> that section/subroutine.

Eeek. Bad way to do it - you're allowing the client to handle your timeouts, and 
you really shouldn't trust your clients to do that.

Another way to do it would be to simply keep a connection id in the cookie, and 
then store timeouts for connections in a DB table (which you control). Your 
checking would go something like:

	Get connection ID from cookie
		-> go to login if none found
	Get timeout for connection ID from DB
		-> go to login if expired (delete from DB as well)
	Update timeout for connection ID
	Do whatever it is you wanted to do

You could also lock it down to source IP instead of a connection ID, but 
problems arise here if the machine connecting is behind a NAT.

I'll leave other security concerns (such as guessing connection IDs - you may 
want to consider some kind of authentication hash to accompany each connection 
ID) up to you to research.

MB



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

Date: Tue, 8 Jun 2004 20:23:16 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <TLsxc.32796$sS2.978851@news20.bellglobal.com>


"Robert TV" <ducott_99@yahoo.com> wrote in message
news:Easxc.714573$Ig.256078@pd7tw2no...
> Hello,
>
> I got the basic coding from perdoc on the usage of use CGI::Cookie. The
main
> examples show an expiry of  '+3M'  which they say means 3 months. I would
> like my cookie to expire after 10 minutes. Does anyone know the equivalent
> value? I cannot locate any other info in perdoc on this issue.

Laziness usually isn't rewarded, since CGI::Cookie's documentation says:

-expires accepts any of the relative or absolute date formats recognized by
CGI.pm, for example ``+3M'' for three months in the future. See CGI.pm's
documentation for details.

Notice the last part of the explanation. If you'd gone to CGI.pm's
documentation, you would have inevitably found this:

+30s                              30 seconds from now
+10m                              ten minutes from now
+1h                               one hour from now
-1d                               yesterday (i.e. "ASAP!")
now                               immediately
+3M                               in three months
+10y                              in ten years time
Thursday, 25-Apr-1999 00:40:33 GMT  at the indicated time & date

Matt




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

Date: Wed, 09 Jun 2004 01:19:36 GMT
From: "Robert TV" <ducott_99@yahoo.com>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <IAtxc.676945$Pk3.647491@pd7tw1no>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

> Laziness usually isn't rewarded, since CGI::Cookie's documentation says:
>
> -expires accepts any of the relative or absolute date formats recognized
by
> CGI.pm, for example ``+3M'' for three months in the future. See CGI.pm's
> documentation for details.
>
> Notice the last part of the explanation. If you'd gone to CGI.pm's
> documentation, you would have inevitably found this:
>
> +30s                              30 seconds from now
> +10m                              ten minutes from now
> +1h                               one hour from now
> -1d                               yesterday (i.e. "ASAP!")
> now                               immediately
> +3M                               in three months
> +10y                              in ten years time

Laziness? I checked out the documentation at
http://www.perldoc.com/perl5.8.4/lib/CGI.html there is no reference to the
information you posted above. I only have access to www.perldoc.com for my
documentation. I also seached for cgi.pm, brought up the same page. There is
only a small section at the bottom called "HTTP COOKIES" and you info isn't
there.

R




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

Date: Wed, 09 Jun 2004 03:49:43 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <2in8mmFphtu1U1@uni-berlin.de>

Matt Garrish wrote:
> Laziness usually isn't rewarded,

That was uncalled for, Matt.

> Notice the last part of the explanation. If you'd gone to CGI.pm's
> documentation, you would have inevitably found this:
> 
> +30s                              30 seconds from now
> +10m                              ten minutes from now
> +1h                               one hour from now
> -1d                               yesterday (i.e. "ASAP!")
> now                               immediately
> +3M                               in three months
> +10y                              in ten years time
> Thursday, 25-Apr-1999 00:40:33 GMT  at the indicated time & date

Not "inevitably", since you don't find it in the section "HTTP 
COOKIES", as you could (would?) have expected, but you need to get 
sight of the reference to the header() method in the description of 
the -expires parameter.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 8 Jun 2004 21:37:37 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <zRtxc.22044$8k4.609327@news20.bellglobal.com>


"Robert TV" <ducott_99@yahoo.com> wrote in message
news:IAtxc.676945$Pk3.647491@pd7tw1no...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
> > Notice the last part of the explanation. If you'd gone to CGI.pm's
> > documentation, you would have inevitably found this:
> >
> > +30s                              30 seconds from now
> > +10m                              ten minutes from now
> > +1h                               one hour from now
> > -1d                               yesterday (i.e. "ASAP!")
> > now                               immediately
> > +3M                               in three months
> > +10y                              in ten years time
>
> Laziness? I checked out the documentation at
> http://www.perldoc.com/perl5.8.4/lib/CGI.html there is no reference to the
> information you posted above. I only have access to www.perldoc.com for my
> documentation. I also seached for cgi.pm, brought up the same page. There
is
> only a small section at the bottom called "HTTP COOKIES" and you info
isn't
> there.
>

You're just making yourself look worse. Once again, if you'd bothered to
read the only section you're interested in you would have found this:

-expires The optional expiration date for this cookie. The format is as
described in the section on the header() method:

What do you find here (using the handy link you provided):

http://www.perldoc.com/perl5.8.4/lib/CGI.html#CREATING-A-STANDARD-HTTP-HEADER-

I find the info I pasted above...

Matt




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

Date: Tue, 8 Jun 2004 22:10:44 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <Ckuxc.22115$8k4.614589@news20.bellglobal.com>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2in8mmFphtu1U1@uni-berlin.de...
> Matt Garrish wrote:
> > Laziness usually isn't rewarded,
>
> That was uncalled for, Matt.
>

I don't see why not.

> > Notice the last part of the explanation. If you'd gone to CGI.pm's
> > documentation, you would have inevitably found this:
> >
> > +30s                              30 seconds from now
> > +10m                              ten minutes from now
> > +1h                               one hour from now
> > -1d                               yesterday (i.e. "ASAP!")
> > now                               immediately
> > +3M                               in three months
> > +10y                              in ten years time
> > Thursday, 25-Apr-1999 00:40:33 GMT  at the indicated time & date
>
> Not "inevitably", since you don't find it in the section "HTTP
> COOKIES", as you could (would?) have expected, but you need to get
> sight of the reference to the header() method in the description of
> the -expires parameter.
>

Er, he was trying to find out how to *expire* the cookie, after all. I would
have expected the expires parameter to be the first place one would look.
You couldn't document the trail to the info more clearly (even starting from
the Cookies module), so I stand by my laziness comment...

Matt




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

Date: Tue, 8 Jun 2004 20:41:14 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: CGI::Cookie    Setting Expiry
Message-Id: <slrncccqlq.5al.tadmc@magna.augustmail.com>

Robert TV <ducott_99@yahoo.com> wrote:

> I only have access to www.perldoc.com for my
> documentation.


Why is that?


If you have perl installed, you should have all its docs installed
right along with it.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 8 Jun 2004 18:07:37 -0700
From: Prab_kar@hotmail.com (Prabh)
Subject: Contructing a dir. tree
Message-Id: <e7774537.0406081707.4ffd52ea@posting.google.com>

Hello all,
I'm given a path to an element,"foo/bar1/bar2/XYZ.txt" and I'm trying
to print the following format from my input:

======================================================
Parent Folder: foo
{
   Some text here about "foo"
   Child Folder: bar1
   {
      Some text here about "bar1"
      Child Folder: bar2
      {
        Some text here about "bar2"
      }
   }
}

File element:  Some text about "XYZ.txt"
======================================================

I'm trying to do this as:

#!/usr/local/bin/perl

use strict ;
use warnings ;

my $input = 'foo/bar1/bar2/XYZ.txt' ;
my @arr = split(/\//,$input) ; # Get all folders.
my $finalIndex = $#arr ;       # The final index of @arr.
my $count = 0 ;
my @out ;                      # Array stores the o/p format.

foreach my $line ( @arr )
{
        # count == 0, parent folder.
        if ( $count == 0 )
        {
                print "Parent Folder: $line \n { \n Some text here \n
} \n" ;
                push(@out,"Parent Folder: $line \n { \n Some text here
\n }") ;

        } elsif ( $count == $finalIndex ) # The file element, XYZ.txt
        {
                print "File element: $line\n" ;
                push(@out,"File element: $line") ;
        } else  # All sub-directories here.
        {
                print "Sub-Folder: $line. Insert under $arr[$count -
1]\n" ;
                push(@out,"Sub-Folder: $line. Insert under $arr[$count
- 1]") ;
        }

        $count++ ;

}

print "======================================\n" ;
map { print "$_\n" ; } @out ;

===========================================================
It outputs,

Parent Folder: foo 
 { 
 Some text here 
 }
Sub-Folder: bar1. Insert under foo
Sub-Folder: bar2. Insert under bar1
File element: XYZ.txt

How do I insert the info about the sub-folder inside each other in a
nested way and all of such info under the parent folder section?

Could anyone tell me how I go about doing it?

I tried looking up at splice, but it requires I give an offset to
insert some elements inside my @out array.

Thanks for your time,
Prabh


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

Date: 8 Jun 2004 22:14:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Converting a string to multiple search patterns
Message-Id: <ca5dna$ddp$1@mamenchi.zrz.TU-Berlin.DE>

Jeff 'japhy' Pinyan  <pinyaj@rpi.edu> wrote in comp.lang.perl.misc:
> On Tue, 8 Jun 2004, Brad Baxter wrote:

> Well, my regex solution agrees with you, and while the insides of the
> regex are a bit ugly to look at, the algorithm is far simpler than it
> seems.
> 
>   #!/usr/bin/perl -l
> 
>   my $rx;
> 
>   {
>     use re 'eval';
>     my @kw = qw( A B C D E );
>     $rx = qr{
>       (?{ local ($s, $f) = (0, 1) })
>       ^ \s*
>       @{[map qq{ (?:
>           \Q$_\E (?{ \$s += \$f <<= 1 }) |
>           (?{ \$f = 1 })
>         ) \\s*
>       }, @kw ]}
>       $
>       (?{ $s })
>     }x;
>   }
> 
>   while (<{A,}{B,}{C,}{D,}{E,}>) {
>     chomp;
>     print "$^R\t$_" if /$rx/ and $^R;
>   }
> 
> Run that code through '| sort -n', and you'll get:
> 
> 2       A
> 2       B
> 2       C
> 2       D
> 2       E
> 4       AC
> 4       AD
> 4       AE
> 4       BD
> 4       BE
> 4       CE
> 6       AB
> 6       ACE
> 6       BC
> 6       CD
> 6       DE
> 8       ABD
> 8       ABE
> 8       ACD
> 8       ADE
> 8       BCE
> 8       BDE

[...]

> 
> which I think is consistent with the rules.

Consistent, yes, and the fact that it sorts all combinations of n before
those of n+1 is significant.  

However, the order of matches with equal score is undefined.  So the
score by itself is insufficient to define the required sequence.

Anno


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

Date: Tue, 8 Jun 2004 21:49:08 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Converting a string to multiple search patterns
Message-Id: <Pine.A41.4.58.0406082129420.13140@ginger.libs.uga.edu>

On Tue, 8 Jun 2004, David K. Wall wrote:

> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
>
> > On Tue, 8 Jun 2004, David K. Wall wrote:
> >
> [snip code]
>
> (BTW, I don't like the way my posted code (mis)handles the empty set,
> but never mind)
>
> > I think I disagree with this.  While it agrees with the OP's
> > stated specs, I'm not sure it agrees with the spirit of the specs.
> >  :-)
>
> Heh.
>
> >        Of course, my interpretation may simply be wrong.
>
> Or mine. It's Tore's problem, let him worry about it. :-)

Indeed.  He has certainly gotten some food for thought.


> > Where I disagree first is with the stated specs:
> >
> >> >>     1. A B C D
> >> >>     2. A B C
> >> >>     3.   B C D
> >> >>     4. A B   D
> >> >>     5. A   C D
> >> >>     6. A B
> >> >>     7.   B C
> >> >>     8.     C D
> >> >>     9. A   C
> >> >>    10.   B   D
> >> >>    11. A     D
> >> >>    12. A
> >> >>    13.   B
> >> >>    14.     C
> >> >>    15.       D
> >
> > I think 11. A D should come before 10. B D, because all else being
> > equal, A comes before B.
>
> But all else isn't equal. The "distance" between A and D is greater
> than the "distance" between B and D.  I'm not sure how to express
> this clearly other than in code, but the way I understood Tore was
> this: the combinations are grouped
>
>     	first by the number of terms/elements in a combination,
>     	then by the "range" of the combination,
>     	then by the order of the original set.
>
> -- but maybe I was reading too much into the choice of 'A'..'D' for
> the example?

Now I'm not so sure you're wrong.   I hadn't thought in terms of
"closeness", only in terms of adjacent or closest-to-first.  I'll grant
that closeness is probably more meaningful.


> >                            In addition, when your code expands the
> > terms 'A'..'E', you get:
> >
> > A B C D E
> > A B C D
> > B C D E
> > A B C E
> > A B D E
> > A C D E
> > A B C
> > B C D
> > C D E
> > ...
> >
> > While 'A B D E' has more terms, I think 'A B C', 'B C D', and 'C D
> > E' should outrank it, because they have more adjacent terms in a
> > row.
>
> That's a good point -- I certainly won't argue against it. What Would
> Google Do?  :-)

I assumed that was the issue.  Perhaps my thinking is colored toward
three-of-a-kind beats two-pair.  :-)  That analogy is highly likely
dubious, and I, too, wonder what research indicates.

Randal mentions "edit distance" which seems to lean toward closeness.

My mind is open.

Regards,

Brad


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

Date: Tue, 8 Jun 2004 21:58:00 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Converting a string to multiple search patterns
Message-Id: <Pine.A41.4.58.0406082151550.13140@ginger.libs.uga.edu>

On Tue, 8 Jun 2004, Jeff 'japhy' Pinyan wrote:

> On Tue, 8 Jun 2004, Brad Baxter wrote:
>
> >I think 11. A D should come before 10. B D, because all else being equal,
> >A comes before B.  In addition, when your code expands the terms 'A'..'E',
> >you get:
> >
> >A B C D E
> >A B C D
> >B C D E
> >A B C E
> >A B D E
> >A C D E
> >A B C
> >B C D
> >C D E
> >
> >While 'A B D E' has more terms, I think 'A B C', 'B C D', and 'C D E'
> >should outrank it, because they have more adjacent terms in a row.
>
> Well, my regex solution agrees with you, and while the insides of the
> regex are a bit ugly to look at, the algorithm is far simpler than it
> seems.
>
>   #!/usr/bin/perl -l
>
>   my $rx;
>
>   {
>     use re 'eval';
>     my @kw = qw( A B C D E );
>     $rx = qr{
>       (?{ local ($s, $f) = (0, 1) })
>       ^ \s*
>       @{[map qq{ (?:
>           \Q$_\E (?{ \$s += \$f <<= 1 }) |
>           (?{ \$f = 1 })
>         ) \\s*
>       }, @kw ]}
>       $
>       (?{ $s })
>     }x;
>   }
>
>   while (<{A,}{B,}{C,}{D,}{E,}>) {
>     chomp;
>     print "$^R\t$_" if /$rx/ and $^R;
>   }
>
> Run that code through '| sort -n', and you'll get:
>
> 2       A
> 2       B
> 2       C
> 2       D
> 2       E
> 4       AC
> 4       AD
> 4       AE
> 4       BD
> 4       BE
> 4       CE
> 6       AB
> 6       ACE
> 6       BC
> 6       CD
> 6       DE
> 8       ABD
> 8       ABE
> 8       ACD
> 8       ADE
> 8       BCE
> 8       BDE
> 12      ABDE
> 14      ABC
> 14      BCD
> 14      CDE
> 16      ABCE
> 16      ACDE
> 30      ABCD
> 30      BCDE
> 62      ABCDE
>
> which I think is consistent with the rules.

I'm on that page, too, but I'm not sure the rules are well defined.  I'm
also not sure the rules for an English phrase are applicable to, say, a
Russian phrase.

Curiouser and curiouser.

--Brad


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

Date: Tue, 8 Jun 2004 22:22:12 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Converting a string to multiple search patterns
Message-Id: <Pine.A41.4.58.0406082202030.13140@ginger.libs.uga.edu>

On Tue, 8 Jun 2004, Randal L. Schwartz wrote:

> *** post for FREE via your newsreader at post.newsfeed.com ***
>
> >>>>> "Brad" == Brad Baxter <bmb@ginger.libs.uga.edu> writes:
>
> Brad> I think 11. A D should come before 10. B D, because all else being equal,
> Brad> A comes before B.  In addition, when your code expands the terms 'A'..'E',
> Brad> you get:
>
> Brad> A B C D E
> Brad> A B C D
> Brad> B C D E
> Brad> A B C E
> Brad> A B D E
> Brad> A C D E
> Brad> A B C
> Brad> B C D
> Brad> C D E
> Brad> ...
>
> Brad> While 'A B D E' has more terms, I think 'A B C', 'B C D', and 'C D E'
> Brad> should outrank it, because they have more adjacent terms in a row.
>
> It appears as though you are sorting on "edit distance", which is a
> well-defined term, and even has a module, String::Approx, to compute
> it.
>
>     use strict;
>     use String::Approx 'adist';
>     my @strings = glob "{,A}{,B}{,C}{,D}{,E}"; # lazy. :)
>     shift @strings; # leave out empty string
>     my @dists = map { abs adist("ABCDE", $_) } @strings;
>     my @sorted = sort {
>       $dists[$a] <=> $dists[$b] or $strings[$a] cmp $strings[$b]
>     } 0..$#strings;
>     printf "%5s %d\n", $strings[$_], $dists[$_] for @sorted;
>
> ==>
>
>     ABCDE 0
>      ABCD 1
>      ABCE 1
>      ABDE 1
>      ACDE 1
>      BCDE 1
>       ABC 2
>       ABD 2
>       ABE 2
>       ACD 2
>       ACE 2
>       ADE 2
>       BCD 2
>       BCE 2
>       BDE 2
>       CDE 2
>        AB 3
>        AC 3
>        AD 3
>        AE 3
>        BC 3
>        BD 3
>        BE 3
>        CD 3
>        CE 3
>        DE 3
>         A 4
>         B 4
>         C 4
>         D 4
>         E 4
>

Nice.

Brad


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

Date: Tue, 08 Jun 2004 23:09:23 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Cute bit of Perl to Assign $1,$2 to named variables
Message-Id: <x73c55ir4u.fsf@mail.sysarch.com>

>>>>> "CH" == Christopher Hamel <hamelcd@hotmail.com> writes:

  CH> david@tvis.co.uk (zzapper) wrote in message 
  >> How about some of the people in this thread posting a few of their
  >> Perl tit-bits
  >> 
  >> zzapper

  CH> I, for one, love &&=.  Most others seem to feel it's as useless and
  CH> obscure as the "reset" function, but I think it's quite useful and
  CH> very Perl-esque.

i have used it in one place i can find where i will zero out a flag if
another flag is zero:

	$entry->{'flag'} &&= $flag_val ;

show some of your uses of that.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 08 Jun 2004 22:22:06 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: match aaa but not 123aaa
Message-Id: <fJqcnawlQeXW6VvdRWPC-g@speakeasy.net>

i have these arbitary strings
   "YaaaY" and "123YaaaY"
I'm having trouble matching only if "aaa" exist between Ys without 
having 123 preceeding it.

example:
"YaaaY" --> pass
"  YaaaY  " --> pass
"XXXYaaaYXXX" --> pass
"alskdjlkajf 123YaaaY laskdjf" --> fail

my one liner didn't work
  $x =~ s/(!\123)(Y)(a{3})(Y)/$1$2$3$4/g;
the ! doesn't seem to negate it.

for an extra bonus, how about if I wanted "aaa" to go between "[" and 
"]"? or ( and )?

what don't I see here??


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

Date: Wed, 09 Jun 2004 03:20:57 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: match aaa but not 123aaa
Message-Id: <40c67fd1.178630577@news.erols.com>

Ken Sington <ken_sington@nospam_abcdefg.com> wrote:

: i have these arbitary strings
:    "YaaaY" and "123YaaaY"
: I'm having trouble matching only if "aaa" exist between Ys without 
: having 123 preceeding it.
: 
: example:
: "YaaaY" --> pass
: "  YaaaY  " --> pass
: "XXXYaaaYXXX" --> pass
: "alskdjlkajf 123YaaaY laskdjf" --> fail

    /(?<!123)YaaaY/

: my one liner didn't work
:   $x =~ s/(!\123)(Y)(a{3})(Y)/$1$2$3$4/g;
: the ! doesn't seem to negate it.

What did you read in perlre that made you believe it would?

: for an extra bonus, how about if I wanted "aaa" to go between "[" and 
: "]"? or ( and )?

See perlfaq6, "Can I use Perl regular expressions to match balanced text?"



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

Date: Tue, 8 Jun 2004 23:18:20 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: match aaa but not 123aaa
Message-Id: <pkvxc.22469$8k4.634471@news20.bellglobal.com>


"Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
news:fJqcnawlQeXW6VvdRWPC-g@speakeasy.net...
> i have these arbitary strings
>    "YaaaY" and "123YaaaY"
> I'm having trouble matching only if "aaa" exist between Ys without
> having 123 preceeding it.
>
> example:
> "YaaaY" --> pass
> "  YaaaY  " --> pass
> "XXXYaaaYXXX" --> pass
> "alskdjlkajf 123YaaaY laskdjf" --> fail
>

What about 123abcYaaaY? Is that a pass or fail?

> my one liner didn't work
>   $x =~ s/(!\123)(Y)(a{3})(Y)/$1$2$3$4/g;
> the ! doesn't seem to negate it.
>

Why are you using a substitution if you're trying to test whether '123'
precedes 'YaaaY' or not? And if you don't want '123', why capture it *and*
use it in the replacement? I would recommend something like the following:

if ( ( $x =~ /YaaaY/ ) && ( $` !~ /123$/ ) ) {
   print $x;
}

If '123' can appear anywhere before 'YaaaY', just don't anchor the numbers
to the end of the pre-match.

> for an extra bonus, how about if I wanted "aaa" to go between "[" and
> "]"? or ( and )?
>

In the substitution or you have going above or are you back to matching
three a's again?

Matt




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

Date: Tue, 8 Jun 2004 19:48:05 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Net::SMTP fails connection in CGI
Message-Id: <Uesxc.32750$sS2.968058@news20.bellglobal.com>


"CMCLab" <jfp24@cornell.edu> wrote in message
news:MPG.1b2ff4f3ac81a087989681@newsstand.cit.cornell.edu...
> Hello,
> I'm running an IIS server on Windows 2000 with ActiveState Perl
> 5.8.  I need an automated e-mailer that attaches a PDF file.  To do so,
> I'm using MIME::Lite; I need to use Net::SMTP in turn to interface with
> the SMTP server.  Whenever I try to instantiate the Net::SMTP object
> through the CGI interface, the following error occurs:
>
> "Failed to connect to mail server: Unknown error"
>
> When I run the script from the command line interface, it makes the
> connection fine, and sends the e-mail without problems.  However in the
> CGI interface, it fails.  This is suggestive of a permissions problem,
> but I'm unclear about which permissions I would have to change if this
> was indeed the case.
>

CGI processes on IIS run as the IUSR. Check that you allow anonymous access
to the smtp server (in the snap-in control). If not, enable it and the
problem should go away. It would also be a good idea to only allow messages
to be sent from the local machine once you do, though.

Matt




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

Date: Wed, 09 Jun 2004 02:58:40 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Text GUI with Perl
Message-Id: <slrncccv71.beh.spamtotrash@doom.unix-guy.com>

In article <ca4ht0$bjo@netnews.proxy.lucent.com>, Tulan W. Hu wrote:
> "Thorsten Gottschalk" wrote in...
>> Hi all,
>>
>> I search a module for doing easy text dialogs with perl.
>> I tried to find something in CPAN, but I only find curses or something
> similar.
>> But curses is to complex for that I want to do.
>> I only need very basic dialoges like that tool dialog under Linux can
> provide.
>> Is there an interface or module for that?
>>
>> Remeber I need no colors, no mouse, only text.
> 
> http://search.cpan.org/~ni-s/Tk-804.027/
> http://www.perltk.org/contrib/perltk-01/index.htm
> 
> Tk::Dialog

Maybe I'm stupid, but which part of Perl/Tk is text-based as the OP specified
was what he needed more than once?

Kevin


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

Date: Tue, 8 Jun 2004 18:19:40 -0400
From: "Robert Oschler" <no_replies@fake_email_address.invalid>
Subject: Upgrading from 5.6.0 to latest version on SuSE 7.3 box
Message-Id: <4Rqxc.1295$JF6.467@bignews5.bellsouth.net>

Hello,

I am running SuSE Linux 7.3 with Apache 1.3.9 and Perl 5.6.0.  I want to
upgrade my Perl installation to the latest version.  I am a Perl newbie so
I'd like to know the best way to do this.  I have already setup CPAN to work
on my system and I get to a CPAN prompt without trouble.  What I need to
know is

- Is the CPAN the right way to upgrade my Perl installation, or is it just
for modules?
- If CPAN is the way to go, where can I find a doc outlining the proper
steps for a smooth upgrade?
- Do I need to upgrade mod_perl myself, so that Apache recognizes the
upgrade?
- Or is SuSE's Yast2 the better way to do this?  If so, I need to know how
to use Yast2 to upgrade a specific package.

URL's welcome.

Thanks

-- 
Robert




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

Date: Wed, 9 Jun 2004 01:30:19 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Upgrading from 5.6.0 to latest version on SuSE 7.3 box
Message-Id: <slrncccq1a.o3t.efflandt@typhoon.xnet.com>

On Tue, 8 Jun 2004, Robert Oschler <no_replies@fake_email_address.invalid> 
wrote:
> I am running SuSE Linux 7.3 with Apache 1.3.9 and Perl 5.6.0.  I want to
> upgrade my Perl installation to the latest version.  I am a Perl newbie so
> I'd like to know the best way to do this.  I have already setup CPAN to work
> on my system and I get to a CPAN prompt without trouble.  What I need to
> know is
> 
> - Is the CPAN the right way to upgrade my Perl installation, or is it just
> for modules?
> - If CPAN is the way to go, where can I find a doc outlining the proper
> steps for a smooth upgrade?
> - Do I need to upgrade mod_perl myself, so that Apache recognizes the
> upgrade?
> - Or is SuSE's Yast2 the better way to do this?  If so, I need to know how
> to use Yast2 to upgrade a specific package.

You might want to upgrade your SuSE, 7.3 is getting rather old and not 
sure how long it will be supported for security updates, etc.  YaST2 in 
newer versions is much quicker doing system updates.

I just ftp installed the 64-bit version of SuSE 9.1 on a new PC.  It came 
with Perl v5.8.3 (in my case built for x86_64-linux-thread-multi).  My 
other SuSE 8.2 Pro box has v5.8.0 built for i586-linux-thread-multi.

-- 
David Efflandt - All spam ignored  http://www.de-srv.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:

#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 V10 Issue 6668
***************************************


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