[17365] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4787 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 1 21:05:34 2000

Date: Wed, 1 Nov 2000 18:05:12 -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: <973130712-v9-i4787@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 1 Nov 2000     Volume: 9 Number: 4787

Today's topics:
        [OT] Spherical cows (Was: CGI Perl vs. Java Servlets... (Jon Bell)
    Re: About killing processes?? (Mark-Jason Dominus)
    Re: Auth DBI (Mark-Jason Dominus)
    Re: bidirectional communication <lisa@acc.com>
    Re: CGI new user/password needed... (Garry Williams)
    Re: Detecting socket closure (Charles DeRykus)
        Downloading a file <java@dashmail.net>
    Re: Downloading a file (Jerome O'Neil)
    Re: Downloading a file <java@dashmail.net>
        efficiently passing objects <dale@emmons.dontspamme.com>
    Re: even or odd ? <nospam@david-steuber.com>
    Re: even or odd ? <nospam@david-steuber.com>
        hashes and references from an array michael.cambray@wellpoint.com
    Re: hashes and references from an array <rick.delaney@home.com>
    Re: hashes and references from an array (Jerome O'Neil)
    Re: How to speedup the following <nospam@david-steuber.com>
    Re: In case you were wondering (Mark-Jason Dominus)
        mySQL & Perl <vitaliy@canada.com>
    Re: mySQL & Perl <rick.delaney@home.com>
    Re: mySQL & Perl (Martien Verbruggen)
        Need help substituting text except when in an HTML anch <cole@ukans.edu>
    Re: Need help substituting text except when in an HTML  <java@dashmail.net>
    Re: Need help substituting text except when in an HTML  <ren.maddox@tivoli.com>
        newbie looking for help on pattern matching tizatron@my-deja.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 2 Nov 2000 00:24:48 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: [OT] Spherical cows (Was: CGI Perl vs. Java Servlets...)
Message-Id: <G3DFtC.4xn@presby.edu>

In article <3A007BB3.DACFF8CF@who.net>, jesus X  <jesusx@who.net> wrote:
>"Randal L. Schwartz" wrote:
>> Sorta like that old phrase, "Presume a perfectly spherical cow..."
>
>Ok, I must admit, I don't know this old phrase. I'd love to hear the rest
>though, as the idea of a spherical cow has me rolling in laughter. =-]

The version of the story I heard, as an undergraduate physics major over
25 years ago, involved a dairy cooperative that wanted to increase milk
production.  For whatever reason, they decided to call in a
theoretical physicist as a consultant.  After several weeks of work, he
gave a presentation which began "To simplify our calculations, we will
assume a spherical cow of uniform density..."

The joke is more effective if you've studied Newton's proof that the
Earth's gravitational field behaves as if all the Earth's mass were
concentrated at the center; or if you've studied Gauss's Law in
electromagnetism.  ;-)

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA
[ Questions about newsgroups?  Visit http://www.geocities.com/nnqweb/  ]
[                or ask in news:news.newusers.questions                ]


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

Date: Wed, 01 Nov 2000 19:21:30 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: About killing processes??
Message-Id: <3a006d37.523f$3c2@news.op.net>
Keywords: Agatha, grandparent, jazzy, teakwood

In article <8tp08e$t2d$1@juuri.cc.lut.fi>,
Esa Vihtonen <esa.vihtonen@lut.fi> wrote:
>I want to run a c-program which will be started using perl script. What
>would be the easiest way for controlling the time that c-program has been
>running and how to kill it if running time gets too long (for example the
>c-program has got into neverending loop)?

A program that does this is a useful tool.  The program is very
simple:

        #!/usr/bin/perl
        #
        # runfor -- run another command, and exit after a certain
        #           amount of time
        #
        # Usage: runfor TIME command args...
        #
        my $time = shift or die "Usage: $0 time-in-secs command args...;
        alarm($time);
        exec @ARGV;
        die "$0: Couldn't exec @ARGV: $!";


Now in your main perl program, when you want to run a C program for at
most five minutes, simply do:

        system("runfor 300 cprogram... &");

The C program will run until it completes, or for 300 seconds,
whichever comes first.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 01 Nov 2000 19:44:22 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Auth DBI
Message-Id: <3a007295.52d5$1e9@news.op.net>

In article <8tm5al$bpp$1@nnrp1.deja.com>,
Tom Tom  <thomas1280@my-deja.com> wrote:
>Does anyone know where I can find some docs on writing Auth DBI
>with Perl for Apache? In particular, dealing with handles and
>connections to the web server?

The book by Stein and MacEachern ('Apache Modules in Perl and C', I
think) is really excellent and discusses this in great detail with
many examples.

You might also consider looking at the source code for some simple
Auth modules.  Check out perl.apache.org.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 01 Nov 2000 16:04:07 -0800
From: Lisa Williams <lisa@acc.com>
Subject: Re: bidirectional communication
Message-Id: <3A00AF77.FB9C4A66@acc.com>

Hello,

I had to do something similar recently and used the IPC::Open2 method.  One
note is that I couldn't get it to work unless I turned buffering off with
the following command:          $|=1;
Just incase this helps...
-lisa

AndreasKleiner wrote:

> Hello all,
>
> I have a C-program which takes multi-line input and produces multi-line
> output. I have to run it in the background - as it compiles some info
> into the memory which takes some seconds - and now and then feed it with
> input and read and interpret the output - with some perl-skript of
> course.
>
> Under which headwords do I have to look for a solution:
>
> IPC::Open2
>
> Pipes
>
> fork
>
> other ?
>
> Thanks for your help,
>
> Andreas



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

Date: Thu, 02 Nov 2000 01:50:32 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: CGI new user/password needed...
Message-Id: <IL3M5.121$FG.7917@eagle.america.net>

On Wed, 01 Nov 2000 22:31:47 GMT, Mark Jaffe <mjaffe@futuristics.net>
wrote:

>I am admin to a CVS server and I need a method to allow users to log
>in and change their passwords and make new accounts. I do NOT want or
>need them directly accessing the machine through shell accounts.
>
>I've tried a method where a perl CGI calls system executables tpo
>create user and change password, but I am not getting expected
>results. The CGI is marked suid but it fails to do the adduser call
>for a new user and also does not do the passwd call to change an
>existing  user. What could be going wrong?

You don't say what happened.  You don't show any code.  

But...

I bet you are calling the adduser command with system() and not checking
the return code from system().  I bet if you did that, you'd find out
why the process is failing.  (You should review the system manual page
to know how to interpret the `exit status' returned by system().)  

I also bet that you are not changing the real uid to zero before
calling adduser.  

You should also review the perlsec manual page carefully, if you have
not done so already.  

-- 
Garry Williams


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

Date: Wed, 1 Nov 2000 06:38:40 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Detecting socket closure
Message-Id: <G3C2GG.89H@news.boeing.com>

In article <39FDD56F.446B@wecan.com>, Fulko Hew  <fulko@wecan.com> wrote:
>Another followup to my own post, this time the answer...
>
>You need to add a signal handler for SIGPIPE!
>
>Just by adding the handler, it tells the system to inform you of a PIPE
>failure.  Receiving any signal causes the OS to interrupt any system
>call currently in progress.  (This will cause send() to return undef.)

>(God only knows what would happen if I tried running this on a Windows
>machine that doesn't support signals.)
>
>Although this has solved the problem, it begs the question:
>
>" Why does send() return undef under some conditions, and still blocks
> (if you don't have the signal handler) under other situations?"
>

Just curious but with your signal handler installed, what 
do you now see with: 

  defined( send(...) ) || die "send $host: $!"; 

Also, what does your handler look like? 

--
Charles DeRykus


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

Date: Wed, 01 Nov 2000 02:09:36 -0800
From: John Golubenko <java@dashmail.net>
Subject: Downloading a file
Message-Id: <39FFEBDF.248A4D8F@dashmail.net>

Hello,
Im trying to download a file from HTTP, for example a txt or zip or
jpeg. (in Perl of course)
I know how to download/upload with FTP, but have no luck with regular
HTTP get/post methods.
For example I need to download http://server/text.txt file, and save to
disk.
Anyone can help me? (point me where to look)
thank you a lot.

P.S. Sorry if this is off topic.





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

Date: Wed, 01 Nov 2000 23:20:40 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Downloading a file
Message-Id: <cz1M5.1415$q81.336209@news.uswest.net>

John Golubenko <java@dashmail.net> elucidates:
> Hello,
> Im trying to download a file from HTTP, for example a txt or zip or
> jpeg. (in Perl of course)
> I know how to download/upload with FTP, but have no luck with regular
> HTTP get/post methods.
> For example I need to download http://server/text.txt file, and save to
> disk.
> Anyone can help me? (point me where to look)

Look at the LWP modules, and it's as easy as pie.

perl -MLWP::Simple -e 'print get("http://server/text.txt")'

HTH!

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Wed, 01 Nov 2000 03:48:00 -0800
From: John Golubenko <java@dashmail.net>
Subject: Re: Downloading a file
Message-Id: <3A0002F0.E6162625@dashmail.net>

Jerome O'Neil wrote:

> John Golubenko <java@dashmail.net> elucidates:
> > Hello,
> > Im trying to download a file from HTTP, for example a txt or zip or
> > jpeg. (in Perl of course)
> > I know how to download/upload with FTP, but have no luck with regular
> > HTTP get/post methods.
> > For example I need to download http://server/text.txt file, and save to
> > disk.
> > Anyone can help me? (point me where to look)
>
> Look at the LWP modules, and it's as easy as pie.
>
> perl -MLWP::Simple -e 'print get("http://server/text.txt")'
>
> HTH!
>
> --
> "Civilization rests on two things: the discovery that fermentation
> produces alcohol, and the voluntary ability to inhibit defecation.
> And I put it to you, where would this splendid civilization be without
> both?" --Robertson Davies "The Rebel Angels"

Thank you Jerome,
Thats exactly what I wanted!
John





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

Date: Wed, 1 Nov 2000 17:21:57 -0600
From: "Dale Emmons" <dale@emmons.dontspamme.com>
Subject: efficiently passing objects
Message-Id: <t01996nriifu78@corp.supernews.com>

I'm curious, is code like this efficient? Or is there a better way to do it?

Thanks,
Dale


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

use strict;
use Carp;
use DBI;

my %settings = (
    dbUser            => "db_user",
    dbPassword        => "db_password",
    dbName           => "db_name"
);

my $something = "a string";

my $dbh = new_DB_connection();
do_sth_with_db( dbh => $dbh, something => $something );
close_DB_connection($dbh);


sub new_DB_connection {
    return DBI->connect("dbi:mysql:$settings{dbName}", $settings{dbUser},
$settings{dbPassword}, {
        PrintError => 0,
        RaiseError => 1
    });
}

sub close_DB_connection {
    $_[0]->disconnect;
    return 1;
}

sub do_sth_with_db {

    my %passed = @_;

    my $something = $passed{dbh}->quote( $passed{something} );

    $passed{dbh}->do(qq{
        DO SOMETHING
        WHERE something_else = $something
    });

}

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




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

Date: Wed, 01 Nov 2000 23:59:25 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: even or odd ?
Message-Id: <m3aebjw8f6.fsf@solo.david-steuber.com>

NOSPAM.billy@easynet.be (Billy) writes:

' Does an instruction exist which can test if an number is odd (eg 1, 3,
' 5, ...) or even (eg 2, 4, 6, 8, ...) ?

There are a number of expressions that will do the job.  The truth of
n&1 is one of my favorite if only numbers >=0 are considered.  The
general case would be the truth of n%2.

Take a math class.  It will really help you out in life to not be
innumerate.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Thu, 02 Nov 2000 00:16:04 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: even or odd ?
Message-Id: <m31ywvw7nf.fsf@solo.david-steuber.com>

real.email@signature.this.is.invalid (Csaba Raduly) writes:

' David Steuber, are you listening ?
' :-)

I was late to the party and rather surprised that I was expected.

Well, it looks like we have a really stupid question for my dumb FAQ!

I wish I had the time to whip up a response as eloquent as Tom's.  I
didn't even go with any habenero.  Oh well.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Thu, 02 Nov 2000 00:15:02 GMT
From: michael.cambray@wellpoint.com
Subject: hashes and references from an array
Message-Id: <8tqblv$t84$1@nnrp1.deja.com>

Any help is appreciated.
I have received help on a similar problem in this forum.
I have gone through the man pages, all 6 perl reference books we have
on CD, and a lot of the messages in this forum. I know hashes and
references can solve my problem, but I just can't figure out how to
apply them. It is the kind of thing where if I could see it done once,
I could understand it and apply the logic to other programs.

I have simplified the problem to the lowest level I can, where in
reality the actual query will return 99 fields. I also know I'm
missing logic.

Below is the script with the results shown at the end:

#!/home/tools/bin/perl
use DBI;
$dbh = DBI->connect("DBI:Informix:pro" ,
       { PrintError => 1, RaiseError => 1 } );
$sth = $dbh->prepare(q%select id, addr, icn, typ, seq, chg from names
                       order by 1, 2, 3, 4%);
$sth->execute();
$sth->bind_columns( \$id, \$addr, \$icn, \$typ, \$seq, \$chg );
while ( $sth->fetch ) {
      push(@fullarray, "$id $addr $icn $typ $seq $chg");
}
$dbh->disconnect;

for $row (@fullarray) {
    my ($id, $addr, $icn, $typ, $seq, $chg) = @$row;
    my $key = "$id $addr";
    push@{$items{$key}}, $row;
}

while (($key, @allrows) = each %items) {
    print "$id $addr\n";
    foreach $row (@$allrows) { print "    $seq $chg\n"; }
}
END_PERL:

Script output (1 line):
B E

desired output shown below:
A C
  1 W
    01 F
    02 G
  2 X
    01 H
A D
  3 Y
    01 I
B E
  4 Z
    01 J

If I put in 'print "@fullarray\n";' it generates:

A C 1 W 01 F A C 1 W 02 G A C 2 X 01 H A D 3 Y 01 I B E 4 Z 01 J

If I put in 'for $row (@fullarray) { print "$row\n"; }' it generates:

A C 1 W 01 F
A C 1 W 02 G
A C 2 X 01 H
A D 3 Y 01 I
B E 4 Z 01 J

What I am trying to do:
  foreach unique "$id $addr" combo
    do some calcs and print $id $addr (& eventually other fields)
    foreach unique $icn under above combo
      do some calcs and print $icn $typ (& eventually other fields)
      foreach $seq per $icn
        do some calcs and print $seq $chg (& eventually other fields)



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 02 Nov 2000 00:47:31 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: hashes and references from an array
Message-Id: <3A00BCAA.53AE98B@home.com>

[posted & mailed]

michael.cambray@wellpoint.com wrote:
> 
> #!/home/tools/bin/perl

No -w.  No use strict.  How do you expect to debug this without Perl's
help?  You should not be using references if you're not comfortable with
'use strict'.

> use DBI;
> $dbh = DBI->connect("DBI:Informix:pro" ,
>        { PrintError => 1, RaiseError => 1 } );
> $sth = $dbh->prepare(q%select id, addr, icn, typ, seq, chg from names
>                        order by 1, 2, 3, 4%);
> $sth->execute();
> $sth->bind_columns( \$id, \$addr, \$icn, \$typ, \$seq, \$chg );
> while ( $sth->fetch ) {
>       push(@fullarray, "$id $addr $icn $typ $seq $chg");

Here you're pushing a string onto the array but I think you want an
array reference.  That would be:

    push(@fullarray, [$id, $addr, $icn, $typ, $seq, $chg]);

Reread perlreftut, perlref and perldsc.

> }
> $dbh->disconnect;
> 
> for $row (@fullarray) {
>     my ($id, $addr, $icn, $typ, $seq, $chg) = @$row;

Now @$row can dereference an array with something in it.  If you'd used
strict your program would have died here as it tried to dereference an
array named "$id $addr $icn $typ $seq $chg" for some values of ($id,
$addr, $icn, $typ, $seq, $chg).  You want it to die here.

>     my $key = "$id $addr";
>     push@{$items{$key}}, $row;

If this is all you want then it can be done in the first loop:

    while ( $sth->fetch ) {
        my $key = "$id $addr";
        push@{$items{$key}}, [$id, $addr, $icn, $typ, $seq, $chg];
    }


> }
> 
> while (($key, @allrows) = each %items) {

each returns a list of two *scalars*:  a key and a value.  The value in
this case is an array reference.  References are always scalars. 
@allrows is not a scalar so it is not an array *reference*.

    while (my ($key, $allrows) = each %items) {

>     print "$id $addr\n";
>     foreach $row (@$allrows) { print "    $seq $chg\n"; }

Here you derefence $allrows properly (but you hadn't set it) but $seq
and $chg do not magically get assigned by doing so.  You must extract
their corresponding values from the array referenced by $row.

    ($seq, $chg) = @{$row}[-2,-1];

> }


-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 02 Nov 2000 00:49:15 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: hashes and references from an array
Message-Id: <fS2M5.1527$q81.391813@news.uswest.net>

michael.cambray@wellpoint.com elucidates:

While I'm not going to go into your code line by line, I will 
offer up a few comments.
> Below is the script with the results shown at the end:
> 
> #!/home/tools/bin/perl

-w is missing.  This would have given you much information regarding
what Perl thinks you mean, as opposed to what you think you mean.

use strict; # Also missing.


> while ( $sth->fetch ) {
>       push(@fullarray, "$id $addr $icn $typ $seq $chg");
> }

Here you do not push a list reference onto your array.  I think 
what you want is

push @fullarray, [$id, $addr, $icn, $typ, $seq, $chg];

Which pushes a reference to a list onto your array.

> for $row (@fullarray) {
>     my ($id, $addr, $icn, $typ, $seq, $chg) = @$row;

This should now dereference like you want.

>     my $key = "$id $addr";
>     push@{$items{$key}}, $row;

I'm not sure what this is supposed to do, but what I think you
want is

$items{$key} = $row;

> }
 
> while (($key, $listref) = each %items) {
>     print "$key\n";
>     foreach $row (@$listref) { print "$_\n"; }
> }

HTH!


-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Wed, 01 Nov 2000 23:49:35 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: How to speedup the following
Message-Id: <m3em0vw8vl.fsf@solo.david-steuber.com>

logan@cs.utexas.edu (Logan Shaw) writes:

' Actually, you probably (but not definitely) could have sped up the
' program just by altering your regular expression.  I'll take a guess
' and say that non-greedy matching might have helped alot.

I was pretty carefull about that, although there could still have been
some back tracking going on that I didn't know about due to missing a
? in my regex or some similar gaff.

I ended up with something that worked fast and I declared victory and
moved on.  The code was reusable.  It did read the format string that
Netscape's Enterprise Server puts at the head of a logfile so that the
code that read the log entries was general.  They went into a hash.  I
pulled out the ones I wanted.

Sadly, I do not have access to that code anymore.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Wed, 01 Nov 2000 19:00:57 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: In case you were wondering
Message-Id: <3a006865.51a4$69@news.op.net>

In article <3a0065db$0$35011$44a10c7e@news.net-link.net>,
Jeff Boes  <jboes@eomonitor.com> wrote:
>Stones, glass houses, and imparting of horizontal momentum thereto. 

Sorry, I'm not sure what you are referring to.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Thu, 2 Nov 2000 03:33:29 +0300
From: "Vitaliy" <vitaliy@canada.com>
Subject: mySQL & Perl
Message-Id: <8tqcl3$c6s$1@news.sovam.com>

Hi!
How can I put gif image (BLOB) into mySQL?
Please, write to me simple program (by Perl).

Thank you!
Vitaliy




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

Date: Thu, 02 Nov 2000 00:53:15 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: mySQL & Perl
Message-Id: <3A00BE07.65CFD796@home.com>

[posted & mailed]

Vitaliy wrote:
> 
> Hi!
> How can I put gif image (BLOB) into mySQL?

Beats me.  Perhaps you could try asking in a mySQL group.

> Please, write to me simple program (by Perl).

If you have a Perl program that you're having trouble with, then please,
post the relevant portion (suitably trimmed or people will be unlikely
to read it) that is giving you trouble.  Don't forget to say what you
expect it to do and what it is doing.

If you don't have a program yet, I recommend doing some research on DBI.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 02 Nov 2000 01:34:37 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: mySQL & Perl
Message-Id: <slrn901h5d.l2.mgjv@verbruggen.comdyn.com.au>

On Thu, 2 Nov 2000 03:33:29 +0300,
	Vitaliy <vitaliy@canada.com> wrote:
> Hi!
> How can I put gif image (BLOB) into mySQL?

You should ask this question on a group that discusses MySQL. Even
though Perl can be used to talk to a MySQL server doesn't make this
question a Perl issue.

ObPerl: Use DBI and the appropriate DBD:: driver.

> Please, write to me simple program (by Perl).

Please, send me a postal order to the amount of $1500. I'll consider
it after reception. Final rates can be negotiated at that point.

In other words: It is really rude to expect other people to do your
work for you, for free. People voluntarily do things for free, but
that is a different thing. Now, after you've visited a MySQL group,
read the MySQL documentation and the documentation on DBI. Once you
have done that, you should be able to at least write an attempt at a
program that does this. If you have that, and you have trouble making
the Perl parts of that program work, feel free to submit it here, and
we'll talk again. 

Until then, you have some work to do. Or, you could hire someone who
knows how to do it.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: Wed, 01 Nov 2000 17:11:42 -0600
From: Cole Robison <cole@ukans.edu>
Subject: Need help substituting text except when in an HTML anchor
Message-Id: <cole-1E96A1.17114201112000@news.ukans.edu>

I want to be able to substitute for text in HTML that's matched only 
when it doesn't appear in an anchor. For example, given

blah blah foo blah <em>foo</em> blah <a href="foo.html">foo</a> blah blah

I'd want the first and second instances of the word "foo" to match, and 
be substituted for, but not the third or fourth (because they're in the 
anchor). Notice that foo can be in another element, as with EM in the 
example above.

My reason for this requirement is that the substitution I want to do is 
to make an occurence of the sought-after string into an anchor, 
replacing, for example, 'foo' with '<a href="foo.html">foo</a>'. The 
problem is I want to do this in a situation where the program can be run 
again and again with the same input text, so I don't want text that's 
already been made an anchor to be modified again. (I.e., I don't want

<a href="<a href="foo.html">foo</a>.html"><a href="foo.html">foo</a></a>

the second time through.)

I hope I've made it clear what I'm after. Any help would be appreciated.

-- 
Cole Robison
Software Training Specialist
Academic Computing Services, The University of Kansas
cole@ukans.edu


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

Date: Wed, 01 Nov 2000 02:32:02 -0800
From: John Golubenko <java@dashmail.net>
Subject: Re: Need help substituting text except when in an HTML anchor
Message-Id: <39FFF122.64111759@dashmail.net>

Cole Robison wrote:

> I want to be able to substitute for text in HTML that's matched only
> when it doesn't appear in an anchor. For example, given
>
> blah blah foo blah <em>foo</em> blah <a href="foo.html">foo</a> blah blah
>
> I'd want the first and second instances of the word "foo" to match, and
> be substituted for, but not the third or fourth (because they're in the
> anchor). Notice that foo can be in another element, as with EM in the
> example above.
>
> My reason for this requirement is that the substitution I want to do is
> to make an occurence of the sought-after string into an anchor,
> replacing, for example, 'foo' with '<a href="foo.html">foo</a>'. The
> problem is I want to do this in a situation where the program can be run
> again and again with the same input text, so I don't want text that's
> already been made an anchor to be modified again. (I.e., I don't want
>
> <a href="<a href="foo.html">foo</a>.html"><a href="foo.html">foo</a></a>
>
> the second time through.)
>
> I hope I've made it clear what I'm after. Any help would be appreciated.
>
> --
> Cole Robison
> Software Training Specialist
> Academic Computing Services, The University of Kansas
> cole@ukans.edu

hey, here is copy of perl file that replaces a words in HTML file, but not
in tags <a href=...>
probably what u want. but of course u need to change what it does with each
word. (ie not replace but extract,
print...or something)

changewords.pl
--------------------
#!/usr/bin/perl -w
# changewords.pl - make substitutions in normal text of HTML files

sub usage { die "Usage: $0 <from> <to> <file> ...\n" }

my $from = shift or usage;
my $to = shift or usage;
usage unless @ARGV;

# Build the HTML::Filter subclass to do the substituting.

package MyFilter;
require HTML::Filter;
@ISA=qw(HTML::Filter);
use HTML::Entities qw(decode_entities encode_entities);

sub text {
 my $self = shift;
 my $text = decode_entities($_[0]);
 $text =~ s/\Q$from/$to/go; #most important line
 $self->SUPER::text(encode_entities($text));
}

# now use the class

package main;
foreach(@ARGV) {
 MyFilter->new->parse_file($_);
}





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

Date: 01 Nov 2000 17:49:29 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Need help substituting text except when in an HTML anchor
Message-Id: <m3y9z345iu.fsf@dhcp11-177.support.tivoli.com>

Cole Robison <cole@ukans.edu> writes:

> I want to be able to substitute for text in HTML that's matched only 
> when it doesn't appear in an anchor. For example, given
> 
> blah blah foo blah <em>foo</em> blah <a href="foo.html">foo</a> blah blah
> 
> I'd want the first and second instances of the word "foo" to match, and 
> be substituted for, but not the third or fourth (because they're in the 
> anchor). Notice that foo can be in another element, as with EM in the 
> example above.
> 
> My reason for this requirement is that the substitution I want to do is 
> to make an occurence of the sought-after string into an anchor, 
> replacing, for example, 'foo' with '<a href="foo.html">foo</a>'. The 
> problem is I want to do this in a situation where the program can be run 
> again and again with the same input text, so I don't want text that's 
> already been made an anchor to be modified again. (I.e., I don't want
> 
> <a href="<a href="foo.html">foo</a>.html"><a href="foo.html">foo</a></a>
> 
> the second time through.)
> 
> I hope I've made it clear what I'm after. Any help would be appreciated.

You probably need to use the HTML::Parser (or, more likely,
HTML::Filter) module for this.  It really is to complicated to
roll-your-own solution.

I've needed to practice this, so here you go (needs some error
checking):

#!/usr/local/bin/perl
use strict;
use warnings;

package FilterTextNoAnchors;
use base qw/HTML::Filter/;

sub new {
  my $invocant = shift;
  my $filter = shift;    # sub ref to filter $_
  my $class = ref $invocant || $invocant;
  my $self = $invocant->SUPER::new(@_);
  $self->{filter} = $filter;
  return $self;
}

sub text {
  my $self = shift;
  local $_ = shift;
  $self->{filter}() unless $self->{anchor};
  $self->output($_);
}

sub start {        
  my $self = shift; 
  $self->{anchor}++ if $_[0] eq "a";
  $self->SUPER::start(@_);                  
}         

sub end {        
  my $self = shift; 
  $self->SUPER::end(@_); 
  $self->{anchor}-- if $_[0] eq "a";    
}         

package main;
my $p = FilterTextNoAnchors->new(sub { s/\bfoo\b/bar/ig } );
$p->parse( join "", <DATA> );
$p->eof;

__DATA__
blah blah foo blah <em>foo</em> blah <a href="foo.html">foo</a> blah blah
__END__


Hope that helps you as much as it helped me to write it!

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 02 Nov 2000 01:20:52 GMT
From: tizatron@my-deja.com
Subject: newbie looking for help on pattern matching
Message-Id: <8tqfhd$kk$1@nnrp1.deja.com>

Hi,

I want to match today's date on one file and then check a
second file for the same date.

File one looks like this...

| Tue Sep 19 19:55:05 PDT 2000 | rcsfilename | data2 | data3 |

File 2 is an rlog type file, named rcsfilename, something like

----------------------
revsion: blah blah bah
date: blah blah blah
RCS COMMENTS HERE
----------------------

So i would like to check the first file, if the date matches I would
like to see if there is a RCS comment for the rcsfilename matched in th
e first.

I am trying something like,

open(FH, "$filename1")
while (<FH>) {
	chop($today);
	if (/$today/) {

		($stupid, $date, $rcs_file, $whatever) = split(/\|/,$_);
		open(RCSFILE,"rlog $rcsfile |");
		while(<RCSFILE>) {
			$modify the date, make it RCS
			if (/$date/) {
				&runsomefunctiontogetRCScomments
			}
		}
	}
}


However the results are poor, and this seems clumsy and slow.

Is there a better way to do this???

Regs
-Dean



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4787
**************************************


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