[23356] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5575 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 27 14:06:31 2003

Date: Sat, 27 Sep 2003 11:05:10 -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           Sat, 27 Sep 2003     Volume: 10 Number: 5575

Today's topics:
        authentication <bob_smith85@hotmail.com>
    Re: authentication <jwillmore@cyberia.com>
    Re: choose from duplicate hash keys <mpapec@yahoo.com>
        date in hash keys & sorting <king21122@yahoo.com>
    Re: date in hash keys & sorting <noreply@gunnar.cc>
    Re: date in hash keys & sorting <phddas@tpg.com.au>
    Re: date in hash keys & sorting <noreply@gunnar.cc>
    Re: date in hash keys & sorting (Sam Holden)
    Re: dim <jurgenex@hotmail.com>
    Re: Explaining how a (Mind) program works (Arthur T. Murray)
    Re: Explaining how a (Mind) program works <REMOVEsdnCAPS@comcast.net>
    Re: Find what is in array1 and not in array2 <postmaster@castleamber.com.invalid>
    Re: hash reference as a hash key (Steve)
        how to match leading '*' ?? (Leor Zolman)
    Re: how to match leading '*' ?? <postmaster@castleamber.com.invalid>
    Re: how to match leading '*' ?? <ak+usenet@freeshell.org>
    Re: how to match leading '*' ?? (Leor Zolman)
    Re: how to match leading '*' ?? <ak+usenet@freeshell.org>
    Re: how to match leading '*' ?? <noreply@gunnar.cc>
    Re: how to match leading '*' ?? (Leor Zolman)
    Re: How to test speed difference of Perl/Apache and SSI <nospam@bigpond.com>
        MythTV Perl script (Dennis)
    Re: MythTV Perl script <noreply@gunnar.cc>
    Re: New FAQ: How do I compute the difference of two arr (Randal L. Schwartz)
    Re: New FAQ: How do I compute the difference of two arr <nospam@bigpond.com>
        New version - Perl 5.8.1 is out! <cyde@umd.edu>
    Re: Passing a directory into $ARGV[0] from a shell scri <jwillmore@cyberia.com>
    Re: perl "password safe"-like program -- pws.pl <zentara@highstream.net>
        POD docs and ANSI escapes <kalinaubears@iinet.net.au>
    Re: POD docs and ANSI escapes <jwillmore@cyberia.com>
        reduce sockets creation (zehn)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 27 Sep 2003 15:24:17 +0300
From: Bob Smith <bob_smith85@hotmail.com>
Subject: authentication
Message-Id: <3F758171.D3520E15@hotmail.com>

hiya all
could some kind sole give some guidance as how to implement user
authentication for a perl web app running mysql RDBMS.
some pointers in the correct direction would be *nighly* appreciated.
( did have a look at www::authenticate but don't know if it is good or
not. )
tia
/B



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

Date: Sat, 27 Sep 2003 14:33:40 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: authentication
Message-Id: <20030927103339.0b1d5335.jwillmore@cyberia.com>

On Sat, 27 Sep 2003 15:24:17 +0300
Bob Smith <bob_smith85@hotmail.com> wrote:

> hiya all
> could some kind sole give some guidance as how to implement user
> authentication for a perl web app running mysql RDBMS.
> some pointers in the correct direction would be *nighly*
> appreciated.( did have a look at www::authenticate but don't know if
> it is good or not. )

Go to http://www.w3c.org/Security/Faq/www-security-faq.html and read
it over.  This is a good "primer" on web security.

Also look over persec to get a better idea of security in relation to
Perl.

Then look over the DBI module's documentation.

If you have more specific questions after that, post them here.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
If I had any humility I would be perfect.   -- Ted Turner 



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

Date: Sat, 27 Sep 2003 12:38:47 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: choose from duplicate hash keys
Message-Id: <cmoanvcnfn9fjqqa7no9uch5je018sr6nb@4ax.com>

X-Ftn-To: JohnWalter 

JohnWalter <phddas@yahoo.com> wrote:
>> the last line of this code prints the whole file again which is not 
>> helpful with a file of thousands of lines.
>> 
>so I just deleted that print line.
>
>which line of this code deletes the non-selected lines. I tried the code 
>but still ends up with the unwanted 'not selected' data lines.

:) Well, these lines could not write back to the file by themselves; you'll
have to open the same or another file and print into it all lines but
duplicates.

print NEWFILE "$k ", (join ' ', @{$table{$k}[$keep]}), "\n";


-- 
Matija


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

Date: Sat, 27 Sep 2003 17:38:40 +1000
From: King <king21122@yahoo.com>
Subject: date in hash keys & sorting
Message-Id: <3F753E80.3080000@yahoo.com>

Hello

I've got to choose a way to go about how to approch this problem.
provided is a hash of arrays. the hash key is dates in a given formate.

I am asked to run some mathematical operations on the column data for a 
colections of dates. keeping the sequance as I go along.

well.. since the date is a key then the fact the hash is not sorted does 
not pose a problem. each collection of date can be calculated by adding 
to dates, use Date::Calc,...etc. and thus the sequance will not suffer!?

+ do I need to sort the hash by sorting the date key and if I have to, 
do I need to change the formate to yyyymmdd for an easy sort?



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

Date: Sat, 27 Sep 2003 09:56:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: date in hash keys & sorting
Message-Id: <bl3g0b$7ru5k$1@ID-184292.news.uni-berlin.de>

King wrote:
> I've got to choose a way to go about how to approch this problem. 
> provided is a hash of arrays. the hash key is dates in a given
> formate.
> 
> I am asked to run some mathematical operations on the column data
> for a colections of dates. keeping the sequance as I go along.
> 
> well.. since the date is a key then the fact the hash is not sorted
> does not pose a problem. each collection of date can be calculated
> by adding to dates, use Date::Calc,...etc. and thus the sequance
> will not suffer!?
> 
> + do I need to sort the hash by sorting the date key and if I have
> to, do I need to change the formate to yyyymmdd for an easy sort?

What is the "given" format you mention? If it's one of the ambigous
date formats, I don't know how it would be possible to sort by date at
all...

Maybe you'd better build the hash with a sortable date format in the
first place. One of the advantages with complying with ISO 8601 is
just that, btw.

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



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

Date: Sat, 27 Sep 2003 18:33:01 +1000
From: Sam <phddas@tpg.com.au>
Subject: Re: date in hash keys & sorting
Message-Id: <3F754B3D.8080605@tpg.com.au>

King wrote:
 > Hello
 >
 > I've got to choose a way to go about how to approch this problem.
 > provided is a hash of arrays. the hash key is dates in a given formate.
 >
 > I am asked to run some mathematical operations on the column data for a
 > colections of dates. keeping the sequance as I go along.
 >
 > well.. since the date is a key then the fact the hash is not sorted does
 > not pose a problem. each collection of date can be calculated by adding
 > to dates, use Date::Calc,...etc. and thus the sequance will not suffer!?
 >
 > + do I need to sort the hash by sorting the date key and if I have to,
 > do I need to change the formate to yyyymmdd for an easy sort?
 >

one of the problems I am facing is converting the date, the result are
2002124 for 2002-Jan-24
2002124 for 2002-Dec-4
that sorting will not work, any idea is appriciated

thanks



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

Date: Sat, 27 Sep 2003 11:27:32 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: date in hash keys & sorting
Message-Id: <bl3ldm$7n3o0$1@ID-184292.news.uni-berlin.de>

Sam wrote:
> one of the problems I am facing is converting the date, the result
> are
> 2002124 for 2002-Jan-24
> 2002124 for 2002-Dec-4
> that sorting will not work, any idea is appriciated

Check out the sprintf() function. Example:

     @dates = ('2002-Jan-24', '2002-Dec-4');

     %months = ( Jan => 1, Feb => 2, Mar => 3, Apr => 4,
                 Maj => 5, Jun => 6, Jul => 7, Aug => 8,
                 Sep => 9, Oct => 10, Nov => 11, Dec => 12 );

     @sortabledates = map { sprintf '%d%02d%02d',
         map { /[a-z]{3}/i ? $months{$_} : $_ } split /-/
     } @dates;

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



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

Date: 27 Sep 2003 09:48:44 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: date in hash keys & sorting
Message-Id: <slrnbnan7s.2kq.sholden@flexal.cs.usyd.edu.au>

On Sat, 27 Sep 2003 18:33:01 +1000, Sam <phddas@tpg.com.au> wrote:
> King wrote:
> >
> > + do I need to sort the hash by sorting the date key and if I have to,
> > do I need to change the formate to yyyymmdd for an easy sort?
> >
> 
> one of the problems I am facing is converting the date, the result are
> 2002124 for 2002-Jan-24
> 2002124 for 2002-Dec-4
> that sorting will not work, any idea is appriciated

perldoc -f sprintf

Something like:

$date = sprintf '%d%02d%02d', $year, $month, $day;

If the usual way of generating a conveniant to sort date format.

-- 
Sam Holden



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

Date: Sat, 27 Sep 2003 14:03:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: dim
Message-Id: <jNgdb.18917$ZR1.3684@nwrddc01.gnilink.net>

Eric J. Roode wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in
> news:xf_cb.11207$Wd7.6576@nwrddc03.gnilink.net:
>
>> Untested, only a sketch. Adding error checking is left as an
>> excercise:
>>
>> my @greplist=qw( var full error over repeats no_space );
>> my @all;
>>
>> open F, '/var/adm/syslog';
>> while (<F>) { #we go through the file only once, line by line
>>     for ($word = @greplist){ #in each line we check for every word
>
> You mean
>       foreach my $word (@greplist) {
> of course.

Ooops, sorry.
As I said, it was only a sketch ;-(.

> I'm not sure, but I suspect it'd be faster to do:
>
>       my $pat = join '|', @greplist;  # at top of program
>       push @all, $_  if /$pat/i;      # within file loop

Not sure, maybe. You are trading the loop for a more complex RE.
Now the RE engine itself must iterate over the alternatives. I don't know if
this will be significantly faster.
Would be interesting to run some benchmarks.

However, while you may gain some time in the match you still need to read
the OP's giant file and for sure that will be the limiting factor when it
comes to performance.

jue




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

Date: 27 Sep 2003 01:35:23 -0800
From: uj797@victoria.tc.ca (Arthur T. Murray)
Subject: Re: Explaining how a (Mind) program works
Message-Id: <3f754bcb@news.victoria.tc.ca>

"Eric J. Roode" wrote on Sat, 27 Sep 2003:
>
> [...] uj797@victoria.tc.ca (Arthur T. Murray) wrote in
> news:3f7487d7@news.victoria.tc.ca:
>
>>
>> A.T. Murray
>
> Art, Art, Art, Art....  How is this remotely relevant to
> comp.lang.perl.misc?
>
> - --
> Eric
> $_ = reverse sort $ /. r , qw p ekca lre uJ reh
> ts p , map $ _. $ " , qw e p h tona e and print
> [...]

Eric!

http://mentifex.virtualentity.com/perl.html Perl is one of the 
strategically important programming languages in which we are
trying to promote the coding of open-source AI Mind software.

Q.E.D.

A.T. Murray
-- 
http://www.cpan.org/authors/id/M/ME/MENTIFEX/mind.txt Mind-Modules
http://www.amazon.com/exec/obidos/ASIN/0595654371/ -- AI Textbook;
http://www.sl4.org/archive/0205/3829.html -- Goertzel on Mentifex;
http://doi.acm.org/10.1145/307824.307853 -- ACM SIGPLAN Mind.Forth


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

Date: Sat, 27 Sep 2003 06:35:11 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Explaining how a (Mind) program works
Message-Id: <Xns94034D0EED36Asdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

uj797@victoria.tc.ca (Arthur T. Murray) wrote in 
news:3f754bcb@news.victoria.tc.ca:

> "Eric J. Roode" wrote on Sat, 27 Sep 2003:
>>
>> [...] uj797@victoria.tc.ca (Arthur T. Murray) wrote in
>> news:3f7487d7@news.victoria.tc.ca:
>>
>>>
>>> A.T. Murray
>>
>> Art, Art, Art, Art....  How is this remotely relevant to
>> comp.lang.perl.misc?
 
> Eric!
> 
> http://mentifex.virtualentity.com/perl.html Perl is one of the 
> strategically important programming languages in which we are
> trying to promote the coding of open-source AI Mind software.
> 
> Q.E.D.


So what?  This newsgroup is not about products and systems that happen to 
be written in the Perl language; it's about the Perl programming language 
itself.  I could write the world's greatest web server or text editor in 
Perl, and my broadcasting new developments in that web server or text 
editor would still be completely off-topic for this newsgroup.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP3V1xGPeouIeTNHoEQJjxACgqzXHj2ONXB3bQfP83o+RPCULghwAoKgt
XgIKxdaxkdn+dX/7VGTGhf7M
=CKUd
-----END PGP SIGNATURE-----


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

Date: Sat, 27 Sep 2003 13:14:17 +0200
From: John Bokma <postmaster@castleamber.com.invalid>
Subject: Re: Find what is in array1 and not in array2
Message-Id: <1064661386.486819@halkan.kabelfoon.nl>

Eric J. Roode wrote:

> Use a temporary hash:
> 
> my %temphash;
> @temphash{@array1} = ();
> delete @temphash{@array2};
> my @in_1_but_not_in_2 = keys %temphash;

Very clever one, thanks.

> I'm not sure how to compute the runtime; my guess is that it'd be O(m+n).

O(max(m,n))

Since O(2n) = O(n).

-- 
Kind regards,       virtual home: http://johnbokma.com/  ICQ: 218175426
                     web site hints: http://johnbokma.com/websitedesign/
John       I count my toes ~ one to ten ~ I meditate ~ and feel the Zen



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

Date: 27 Sep 2003 01:28:10 -0700
From: ineverlookatthis@yahoo.com (Steve)
Subject: Re: hash reference as a hash key
Message-Id: <f0d57f86.0309270028.3c439600@posting.google.com>

>refs as keys are a fine thing as long as the ref itself is also in the
>value part (either the value itself or inside someother structure which
>is the value). one simple use for this is to track a set of objects by
>their references. you can search/add/delete from a hash which has the
>object as both the key and the value.
>
>uri

Do you mean I could add a value such as 
$eachDNA->{uniqueaddress} = $eachDNA; 
and then use that as a hash key ?

I can see how that is better than what I am presently doing, but not
fundamentally different. I can of course ensure that the hashref will
remain in existence, but does that mean that it won't change its value
when stringified ? If not I still risk that happening before I capture
a unique value within the data structure.

Steve


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

Date: 27 Sep 2003 09:03:56 -0700
From: leor@bdsoft.com (Leor Zolman)
Subject: how to match leading '*' ??
Message-Id: <d38469a3.0309270803.47d0133f@posting.google.com>

(Sorry, I posted this in comp.lang.perl first before a different
newsreader showed me the existence of this sub-group; there seems to
be more activity here.)

I'm probably going to feel really stupid when I see the answer, but
I'm now stuck nevertheless... I need to match a leading literal '*',
and Perl isn't getting the idea. Reading from standard input, typing
"const" into the program below yields "just const" as expected, but
typing "*const" ALSO results in "just const", rather than "*const" as
I would have hoped.

This is a simplification of a much more complex r.e. where I need to
detect an asterisk immediately preceding "const" in the middle of the
r.e., and it isn't working there either.

How am I being brain-dead?
        -leor

while (<>)
{
        if (/const/)
        {
                print "just const\n\n";
        }
        elsif (/\*const/)  # should match leading literal '*', no???
        {
                print "*const\n\n";
        }
        else
        {
                print "None.\n";
        }
}


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

Date: Sat, 27 Sep 2003 18:16:13 +0200
From: John Bokma <postmaster@castleamber.com.invalid>
Subject: Re: how to match leading '*' ??
Message-Id: <1064679503.9206@halkan.kabelfoon.nl>

Leor Zolman wrote:

> (Sorry, I posted this in comp.lang.perl first before a different
> newsreader showed me the existence of this sub-group; there seems to
> be more activity here.)

That's because comp.lang.perl is obsolete. However I replied there.

-- 
Kind regards,       virtual home: http://johnbokma.com/  ICQ: 218175426
                     web site hints: http://johnbokma.com/websitedesign/
John       I count my toes ~ one to ten ~ I meditate ~ and feel the Zen



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

Date: Sat, 27 Sep 2003 16:46:35 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: how to match leading '*' ??
Message-Id: <slrnbnbfn9.h6k.ak+usenet@vinland.freeshell.org>

In article <d38469a3.0309270803.47d0133f@posting.google.com>, Leor Zolman wrote:
> (Sorry, I posted this in comp.lang.perl first before a different
> newsreader showed me the existence of this sub-group; there seems to
> be more activity here.)

That group is dead.

[cut]
> 
> How am I being brain-dead?
> 

Reverse the order of the tests.



-- 
Andreas Kähäri


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

Date: Sat, 27 Sep 2003 16:54:50 GMT
From: leor@bdsoft.com (Leor Zolman)
Subject: Re: how to match leading '*' ??
Message-Id: <thjdb.599479$Ho3.116667@sccrnsc03>

In article <1064679503.9206@halkan.kabelfoon.nl>, 
postmaster@castleamber.com.invalid says...
>
>Leor Zolman wrote:
>
>> (Sorry, I posted this in comp.lang.perl first before a different
>> newsreader showed me the existence of this sub-group; there seems to
>> be more activity here.)
>
>That's because comp.lang.perl is obsolete. However I replied there.

Thanks -- I'll stick to this group now ;-)

Figures, in trying to simplify the problem (which was pure r.e.'s, no "if" 
statmeents), I introduced the ordering bug, which has nothing to do with my 
original problem. But at least now I do know what my original problem 
is. Here's a shorter version of the test program that illustrates the issue:

while (<>)
{
	$pat = "\*const";
	
#	if (/\*const/)	# OK, '*' is literal
	if (/$pat/)	# oops, now it's a leading r.e. '*' operator!
	{
		print "*const\n\n"; # should match leading literal '*', no???
	}
}

The trouble is that the escaped '*' is no longer escaped when I use it in the 
"if", due to the use of the variable. In fact I'm building a big, fat, complex 
r.e. composed of several nested variables...and the place I need to 
"escape" the '*' is in one of the "inner" ones. Any way to make that work?
Thanks,
	-leor




>
>-- 
>Kind regards,       virtual home: http://johnbokma.com/  ICQ: 218175426
>                     web site hints: http://johnbokma.com/websitedesign/
>John       I count my toes ~ one to ten ~ I meditate ~ and feel the Zen
>



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

Date: Sat, 27 Sep 2003 17:01:39 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: how to match leading '*' ??
Message-Id: <slrnbnbgji.h6k.ak+usenet@vinland.freeshell.org>

In article <thjdb.599479$Ho3.116667@sccrnsc03>, Leor Zolman wrote:
[cut]
> The trouble is that the escaped '*' is no longer escaped when I use it in the 
> "if", due to the use of the variable. In fact I'm building a big, fat, complex 

Escape the * twice ("\\*") or single quote the expression ('\*').


-- 
Andreas Kähäri


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

Date: Sat, 27 Sep 2003 19:07:32 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to match leading '*' ??
Message-Id: <bl4ge9$7vo8b$1@ID-184292.news.uni-berlin.de>

Leor Zolman wrote:
> 
> while (<>)
> {
> 	$pat = "\*const";

That resulted in a fatal error when running your code with Perl 5.8.0:
"Quantifier follows nothing in regex; marked by <-- HERE in
m/* <-- HERE const/"

You'd better use single quotes:

	$pat = '\*const';

or making the backslash literal:

	$pat = "\\*const";

> #	if (/\*const/)	# OK, '*' is literal
> 	if (/$pat/)	# oops, now it's a leading r.e. '*' operator!
> 	{
> 		print "*const\n\n"; # should match leading literal '*', no???
> 	}
> }

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



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

Date: Sat, 27 Sep 2003 17:13:57 GMT
From: leor@bdsoft.com (Leor Zolman)
Subject: Re: how to match leading '*' ??
Message-Id: <pzjdb.598719$YN5.439405@sccrnsc01>

In article <slrnbnbgji.h6k.ak+usenet@vinland.freeshell.org>, 
ak+usenet@freeshell.org says...
>
>In article <thjdb.599479$Ho3.116667@sccrnsc03>, Leor Zolman wrote:
>[cut]
>> The trouble is that the escaped '*' is no longer escaped when I use it in 
the 
>> "if", due to the use of the variable. In fact I'm building a big, fat, 
complex 
>
>Escape the * twice ("\\*") or single quote the expression ('\*').


Ahh, thank you. That's it. I was comparing what I'd written to other instances 
where I used '\*' within single quotes -- when no variables were involved -- 
and didn't catch on to the implications. Now I can get back to business...
	-leor


>
>
>-- 
>Andreas Kähäri



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

Date: Sat, 27 Sep 2003 22:26:05 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: How to test speed difference of Perl/Apache and SSI/Apache
Message-Id: <8199375.6ZdvQCiDvu@gregs-web-hosting-and-pickle-farming>

It was a dark and stormy night, and The Poor managed to scribble:

> I am using SSI now and it can not include external things. I want to
> use Perl/CGI to do that, but worried about slower speed. How do I
> test/benchmark the different of loading on Perl/Apache and SSI/Apache.
> 
> in perl
> open a file for read, print it, close file
> 
> in ssi
> include the file
> 
> because the network speed vary much, how do i calculate the speed of
> the perl vs ssi? i can easily open/read/print/close 100 times in perl,
> but i can not do that in ssi to compare...

But you can write two Perl script using LWP::Simple to retrieve the two different URLs using get(). One URL is for the Perl cgi, the otheris for SSI.
Its a easy matter to time each of the scripts.


For example, URL1.pl contains:
  #!/usr/bin/perl
  use strict;
  use LWP::Simple;
  get('http://mysite.com/Perltest.cgi');

URL2.pl contains:
  #!/usr/bin/perl
  use strict;
  use LWP::Simple;
  get('http://mysite.com/ssitest');


and in linux you just 'time URL1.pl' and 'time URL2.pl' will tell you how long it takes to retrieve each page.


gtoomey


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

Date: 27 Sep 2003 09:02:17 -0700
From: 4hands@earthlink.net (Dennis)
Subject: MythTV Perl script
Message-Id: <366305e3.0309270802.2480ac01@posting.google.com>

Can anyone tell me why this isn't working. This script is supposed to
take this pay per view information off this webpage and put it into a
MySQL database. Unfortunately it doesn't do that. All it does is give
me the readout that it has downloaded and updated and give me one
single record that is of no use to me. All of the modules have been
installed. Oh, I am a newbie but am willing to learn. Any help at all
would be greatly appreciated. Thanks

#!/usr/bin/perl

package main;

# Load required stuffs

use HTTP::Request;
use LWP::UserAgent;
use POSIX qw(strftime);
use DBI;

if(@ARGV[0] != 1 && @ARGV[0] != 2){printf("Please use either \"1\"
(delete) or \"2\" (update)\n");exit();}

if(@ARGV[0] == 1){
printf("Deleting all PPV Database entries...");
my $dbh = DBI->connect("dbi:mysql:mythconverg:127.0.0.1", mythtv,
mythtv, {
      RaiseError => 1, AutoCommit => 0
  });
  my $sqldel = $dbh->prepare( q{
    DELETE FROM program WHERE chanid > 1100 AND chanid < 1200
  });

 $sqldel->execute();
 $dbh->commit;
 $dbh->disconnect;
printf("done.\n");
 exit();
}
my $dbh = DBI->connect("dbi:mysql:mythconverg:127.0.0.1", mythtv,
mythtv, {
      RaiseError => 1, AutoCommit => 0
  });


# Get the webpage (note: webpage is hardcoded)

printf("Downloading PPV information...");
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request(GET =>
'http://www.geocities.com/paglierani/showlist.jpg');
my $response = $ua->request($request);
printf("done.\n");

printf("Updating database with PPV information...");
# For each line, look to see if it begins sections; process sections
accordingly
# Sections are: channels (has channels) ; shows (has shows)

foreach (split /\r\n/, $response->content()) {
 if ($_ eq "proc addChannels { } {")
 { 
  $addchans = 1;
 }
 elsif ($_ eq "proc addPrograms { } {")
 {
  $addprogs = 1;
 }

if ($addchans == 1 && $_ ne "proc addChannels { } {" and $_ ne "}")
 {
  $_ =~ s/^\S+\s+//;
$channum = substr($_, 3);
$channum =~ s/\s+$//;
 
 }

elsif ($addprogs == 1 && $_ ne "proc addPrograms { } {" && $_ ne "}")
 {
  ($foo1, $ProgramID, $foo3, $SingTitle, $foo5) = split ' ', $_;
  (@ProgramArray) = split '{', $_;
  ($ProgramTitle, $ProgramDescription) = @ProgramArray[1,-1];
  if (index($SingTitle, '{') == -1) {
   $ProgramTitle = $SingTitle;

  }
  else{
   ($ProgramTitle) = split '}', $ProgramTitle;
   }
  ($ProgramDescription) = split '}', $ProgramDescription;
  $ProgramID = substr($ProgramID,2);
  @progtit[$ProgramID] = $ProgramTitle;
  @progdesc[$ProgramID] = $ProgramDescription;
 }

#Turn off section designations, which stops processing the section.

 if ($_ eq "}" && $addchans == 1 ) {
  $addchans = 0;
 }
 elsif ($_ eq "}" && $addprogs == 1 ) {
  $addprogs = 0;
 }

}

foreach (split /\r\n/, $response->content()) {
 if ($_ eq "proc addPrograms { } {")
 {
  $addprogs = 1;
 }

 if (index($_, 'ads ') != -1 && $addprogs != 1) {
  (@RawPrograms) = split ' ', $_;
  ($ChannelNum, $ProgDate, $ProgStart, $ProgDur, $ProgPoint) = 
@RawPrograms[2,3,4,5,6];
  $ProgPoint = substr($ProgPoint, 2);
  $ChannelNum = substr($ChannelNum, 3) + 1000;
  $ProgStart = $ProgDate * 86400 + $ProgStart;
  $ProgStop = $ProgStart + $ProgDur;
  $StartTime = strftime ("%Y%m%d%H%M%S %Z", localtime($ProgStart));
  $StopTime = strftime ("%Y%m%d%H%M%S %Z", localtime($ProgStop));
  my $sqladd = $dbh->prepare( q{
      INSERT INTO program
(chanid,starttime,endtime,title,description,subtitle,category) VALUES
(?,?,?,?,?,"","")
  });

 $sqladd->execute($ChannelNum,$StartTime,$StopTime,@progtit[$ProgPoint],@progdesc[$ProgPoint]);
 $dbh->commit;
  
 }
}
  $dbh->disconnect;
printf("done.\n");


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

Date: Sat, 27 Sep 2003 19:14:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: MythTV Perl script
Message-Id: <bl4gs0$80m2i$1@ID-184292.news.uni-berlin.de>

Dennis wrote:
> Can anyone tell me why this isn't working.

Did you ask Perl?

     use strict;
     use warnings;

(I don't know if that will help you in this case, but you shouldn't 
ask here without having asked Perl first. ;-) )

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



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

Date: Sat, 27 Sep 2003 11:47:18 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: a@job.mx.2y.net (The Poor)
Subject: Re: New FAQ: How do I compute the difference of two arrays?
Message-Id: <0384ffbaed7f59efb0c90cb48e401ac7@news.teranews.com>

>>>>> "The" == The Poor <a@job.mx.2y.net> writes:

The> - 
The> New:
The> +
The>   How do I compute the difference of two arrays?  How do I compute the
The> intersection of two arrays?

The>     Use a hash. Here's code to do both and more. It assumes that each
The>     element is unique in a given array:

Here's code that doesn't require that uniqueness, and would be a better
candidate for the FAQ:

    my %tally;
    $tally{$_} .= "a" for @array_a;
    $tally{$_} .= "b" for @array_b;
    my @union = keys %tally;
    my @intersection = grep $tally{$_} =~ /ab/, @union;
    my @a_not_b = grep $tally{$_} =~ /a$/, @union;
    my @b_not_a = grep $tally{$_} =~ /^b/, @union;

print "Just another Perl hacker,";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 27 Sep 2003 21:59:05 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: New FAQ: How do I compute the difference of two arrays?
Message-Id: <1504623.a2TSuqBBRq@gregs-web-hosting-and-pickle-farming>

It was a dark and stormy night, and Randal L. Schwartz managed to scribble:

>>>>>> "The" == The Poor <a@job.mx.2y.net> writes:
> 
> The> -
> The> New:
> The> +
> The>   How do I compute the difference of two arrays?  How do I compute
> the The> intersection of two arrays?
> 
> The>     Use a hash. Here's code to do both and more. It assumes that each
> The>     element is unique in a given array:
> 
> Here's code that doesn't require that uniqueness, and would be a better
> candidate for the FAQ:
> 
>     my %tally;
>     $tally{$_} .= "a" for @array_a;
>     $tally{$_} .= "b" for @array_b;
>     my @union = keys %tally;
>     my @intersection = grep $tally{$_} =~ /ab/, @union;
>     my @a_not_b = grep $tally{$_} =~ /a$/, @union;
>     my @b_not_a = grep $tally{$_} =~ /^b/, @union;
> 
> print "Just another Perl hacker,";

Having coded this problem myself, your solution is minimal & very elegant (as expected).

gtoomey


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

Date: Sat, 27 Sep 2003 11:46:35 -0400
From: Cyde Weys <cyde@umd.edu>
Subject: New version - Perl 5.8.1 is out!
Message-Id: <bl4bcs$fv8$2@grapevine.wam.umd.edu>

http://developers.slashdot.org/article.pl?sid=03/09/27/1345229&mode=nested&tid=126&tid=145&tid=156&tid=162&tid=164&tid=185&tid=99



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

Date: Sat, 27 Sep 2003 14:24:01 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Passing a directory into $ARGV[0] from a shell script
Message-Id: <20030927102355.4a8a9cab.jwillmore@cyberia.com>

On Thu, 25 Sep 2003 16:12:15 GMT
"John" <none@none.com> wrote:
<snip>
> My shell script does some things and when it finds a particular file
> it calls a perl script [from within the shell script] like this:
> change.pl . myfile.txt  << 2 command line parameters, a directory
> [DOT] and a filename

Simple - $ARGV{0] and $ARGV[1].  Let's move on :-)

> 
> I wanted . to reflect the working directory of the file that that
> needs to be edited. Since my shell script has already descended into
> the file's directory then there is no need to pass any other
> directory to the perl script. Hence, I wanted to use . [DOT] as I
> don't really want to change the directories at this point.

Huh?  Okay, so you're in the directory you want to be in, but you want
to pass a directory to the script - right?  There's a phrase that
comes to mind, but since the 'Net is suppose to be 'G' rated, I won't
use it :-)

> 
> But my perl script dies due to the following line in its contents:
> chdir '$ARGV[0]' || die "Cannot chdir to: $!\n";

Why?  Oh, that's the question you're asking ;-)  Okay, we'll get to
that, okay?

> 
> On the other hand, if I want to run the perl script on its own, I
> need to be able to give it some sort of a directory - hence the
> $ARGV[0].

Ah.  What do you mean "on its own"?  Are you running this from cron or
some other utility that runs automated tasks?  Still a bit confused.

> 
> If I remove the DIE option both scripts run together as expected. Am
> I doing something wrong? Why is the perl script unable to chdir '.'?

Yes, you are doing something wrong :-)  It appears that you have a few
issues.  First, use '-w' on the first line of your script.  This will
issue warnings.  Second, use the strict pragma.  If you have duplicate
variables, undefined variables, etc., this will cause the script to
die and issue (a) message(s) describing what went wrong.  You may want
to look over what I wrote and see if it's what you wanted.

==untested==
#!/usr/bin/perl -w

#use the strict pragma - prevents you from hanging yourself
use strict;
#use warnings to catch what the '-w' command line option misses
use warnings;
#use diagnostics - print more useful messages if we die
use diagnostics;

#the home environmental variable does not exist for 
#some versions of Windows - however, the present 
#working directory _should_ exist on either OS
my $chdir = $ENV{HOME} || $ENV{PWD};

#get the first parameter passed to the script and make
#that $chidr if something was passed to the script
#(ie if $ARGV[0] is defined)
$chdir = $ARGV[0] if(defined $ARGV[0]);

#now, try and change the current working directory - 
#die if we can't
chdir $chdir || die "Can't chdir to $chdir: $!\n";

#execute the 'pwd' command - not sure of the Windows 
#equivlent - this is just "proof of concept" (show we did
#change to the directory)
system("pwd");
==untested==

Now - if the first parameter is the file, -not- the directory, then
the script will die (because you'll be trying to change the working
directory to a file and, well, that doesn't work so well -unless- you
have a file _and_ a directory by the same name).  You may want to look
over Getopt::Std or Getopt::Long if you want non-positional parameters
passed to the script.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
One Page Principle:  A specification that will not fit on one
page of 8.5x11 inch paper cannot be understood.   -- Mark Ardis 


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

Date: Sat, 27 Sep 2003 11:48:31 -0400
From: zentara <zentara@highstream.net>
Subject: Re: perl "password safe"-like program -- pws.pl
Message-Id: <r4cbnv0gq9ekpak2mrvd7n2g2a1gbmo767@4ax.com>

On 25 Sep 2003 09:06:36 -0700, q2m3eft02@sneakemail.com (Robert
Jacobson) wrote:

>On a Windows platform, I typically use the program "Password Safe" to
>keep all my passwords.  But, as it only works on Windows, I was
>looking for a cross-platform solution.
>
>I wrote a program (below) that has the basic functionality of the
>program -- it stores your passwords in a database, encrypting both the
>keys (except the KEYCHECK key) and the values with blowfish.   I guess
>someone could brute-force the password by encrypting the string
>"JUSTCHECKING" with blowfish, trying a bunch of different passphrases.
> How long would that take, assuming, say, an 16 characters passphrase?

I found 1 glitch already....you have a mistake which prevents your
"HIDDEN" password method from working.

>
>$JOIN = "	"; # That's a tab, not a space
>

Actually put the tab in there, or when you "View All", the password
isn't hidden and is concatenated to the login name.

$JOIN = "\t";



Our body's 20 milligrams of beta radioactive Potassium 40
emit about 340 million neutrinos per day, which go at
lightspeed to the ends of the universe!..even thru the earth. 


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

Date: Sat, 27 Sep 2003 22:29:36 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: POD docs and ANSI escapes
Message-Id: <3f758364$0$23602$5a62ac22@freenews.iinet.net.au>

Hi,
On my linux box 'perldoc' (but not 'man') is failing to interpret the 
ANSI escapes. How do I remedy this ?

I'm seeing:
ESC[1mNAMEESC[0m
instead of:
NAME

(Is this answered in the faq somewhere ? I have a feeling it is, but 
couldn't find it.)

Cheers,
Rob
-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Sat, 27 Sep 2003 14:29:42 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: POD docs and ANSI escapes
Message-Id: <20030927102940.372e56f3.jwillmore@cyberia.com>

On Sat, 27 Sep 2003 22:29:36 +1000
Sisyphus <kalinaubears@iinet.net.au> wrote:
> Hi,
> On my linux box 'perldoc' (but not 'man') is failing to interpret
> the ANSI escapes. How do I remedy this ?
> 
> I'm seeing:
> ESC[1mNAMEESC[0m
> instead of:
> NAME
> 
> (Is this answered in the faq somewhere ? I have a feeling it is, but
> 
> couldn't find it.)

The "quick fix" is to run perldoc with the '-t' option.

I tend to remember having the same issue, but it was a _long_ time
ago.  I _think_ you _may_ have to change the language setting to
something more "sane" (like en_US).  Do an 'echo $LANG' if in bash to
see what it's set to now.  However, I could be wrong about this.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
I'm a Lisp variable -- bind me! 



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

Date: 27 Sep 2003 08:17:51 -0700
From: bennyc@magix.com.sg (zehn)
Subject: reduce sockets creation
Message-Id: <fdc14960.0309270717.4e54a5c9@posting.google.com>

hi,

  i wrote a TCP client socket script that would send data to a TCP
server. However, this script was being called 100 times per second and
it caused hugh amount of sockets created utilizing all the resources
in my server. Hence a "netstat -a" would show up with lots of
TIME_WAIT.

  i was thinking if there is a way i could create the socket in
another script, and just allow multiple scripts to SEND data through
it? Hence it would just be like a single socket connection.

  any examples would be great.

benny


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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