[17367] in Perl-Users-Digest
Perl-Users Digest, Issue: 4789 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 00:05:37 2000
Date: Wed, 1 Nov 2000 21:05:10 -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: <973141509-v9-i4789@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 1 Nov 2000 Volume: 9 Number: 4789
Today's topics:
Re: "chown" of symlink instead of linked file (Chris Fedde)
Re: About killing processes?? (Gwyn Judd)
Re: CGI file uploading <admin@salvador.venice.ca.us>
Re: Collecting data (Chris Fedde)
Re: hashes and references from an array <ren.maddox@tivoli.com>
Re: hashes and references from an array <jeff@vpservices.com>
Re: hashes and references from an array (Tad McClellan)
i'm in 'use vars' hell <mcdonabNO@SPAMyahoo.com>
Re: i'm in 'use vars' hell <rick.delaney@home.com>
Re: i'm in 'use vars' hell <jeff@vpservices.com>
Re: i'm in 'use vars' hell <mcdonabNO@SPAMyahoo.com>
Re: i'm in 'use vars' hell <jeff@vpservices.com>
Multipart response <tambaah@x.hotmail.com>
Re: mySQL & Perl (Chris Fedde)
Re: newbie looking for help on pattern matching <bwalton@rochester.rr.com>
Re: Newbie: seeing scalars within require files? (Tad McClellan)
Re: OT: Yes there _are_ stupid questions. Anyone colle (Tad McClellan)
Re: Perl Question (Gwyn Judd)
Re: Perl Question (Logan Shaw)
Re: Perl style and module searches (Gwyn Judd)
Re: SMS - text messaging <cak@putzl.com>
Re: Stultiloquent Queries (was: even or odd?) (Randal L. Schwartz)
Re: Stultiloquent Queries (was: even or odd?) (NP)
Re: Stultiloquent Queries (was: even or odd?) (Gwyn Judd)
Re: Stultiloquent Queries (was: even or odd?) (Chris Fedde)
times array robbelljr@my-deja.com
Re: times array (Chris Fedde)
Re: Want to process all files less than 24 hours old <mark-lists@webstylists.com>
Re: Want to process all files less than 24 hours old (Tad McClellan)
Re: What's wrong with this regex? <ianb@ot.com.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 02 Nov 2000 04:36:44 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: "chown" of symlink instead of linked file
Message-Id: <wb6M5.96$Bf7.188784640@news.frii.net>
In article <1eje32w.1k450821htj5hcN%otto.wyss@bluewin.ch>,
Otto Wyss <otto.wyss@bluewin.ch> wrote:
>> tom, calm down. i am not in need of the chown -h option and i have it on
>> my box if i needed it. i am just saying it is not a widespread option so
>> it makes changing the symlink owner problem trickier from perl. if you
>>
>
>Anyway since I'm not a very good perl programmer, could anybody tell my
>how I have to change my statements
>
> my (atime, $mtime) = (stat($file))[8,9];
> chown $uid, $gid, $file;
> utime ($atime, $mtime, $file);
>
>so it just changes the owner of the symlink.
>
Another poster pointed out in another sub thread that the correct way for
the a script to do this is to remove the symlink and re-create it.
unlink $symlink;
symlink $file, symlink;
Now the link is owned by the uid:gid of the script. Elsewhere it
was mentioned that running a CGI with privileges to change the
owner of the file might be exceeding what is prudent for a webserver.
And if you want to hide your tampering you probably want to use
lstat rather than stat.
But there is still the admin script case. Another poster demonstrated how
lchown can be executed using the syscall function. Then he went on to
state how this might not be to useful for scripts that are not run as
root.
--
This space intentionally left blank
------------------------------
Date: Thu, 02 Nov 2000 03:26:42 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: About killing processes??
Message-Id: <slrn901nne.4sn.tjla@thislove.dyndns.org>
I was shocked! How could Mark-Jason Dominus <mjd@plover.com>
say such a terrible thing:
>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.
Unless the sub-process ignores SIGALRM of course. Or calls sleep(3). Or
any other call that interferes with alarm. Would it be better to
do a fork/exec and kill() the child from the parent if the wait was too
long? Something like (untested):
defined $pid = fork or die "Cannot fork: $!";
if ($pid)
{
$SIG{ALRM} = sub { kill 2, $pid; sleep 2; kill 9, $pid };
alarm($time);
waitpid $pid, 0;
exit;
}
exec(@ARGV);
die "etc";
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
There is no satisfaction in hanging a man who does not object to it.
-- G.B. Shaw
------------------------------
Date: Wed, 01 Nov 2000 18:20:32 -0800
From: Salvador <admin@salvador.venice.ca.us>
Subject: Re: CGI file uploading
Message-Id: <3A00CF70.BB502AC5@salvador.venice.ca.us>
nobull@mail.com wrote:
> I find it somewhat hard to believe that you are trying. Would you
> care to enumerate exaclty what forms this trying has taken to date?
> Have you done a Usenet search? Have you looked in the manual?
> Did you know that Deja is French (and possibly Latin too) for
> "already"? Deja.com (formerly "DejaNews") is so called bacause it
> allows to see if the question you are about to ask on Usenet has been
> asked and answered already.
> For anyone to post a question to Usenet without doing a search first
> is bad enough, to do it via Deja is simply indefensible.
It's funny... as good a beginner's language as Perl is, primarily
because any nitwit can program in Perl, some people in other usenet
programming groups recommend against it as a language for beginner's, in
part because of how rude many of the people are to beginners in the
comp.lang.perl.* groups. And based on abusive posts like yours, THEY
ARE MAKING A LEGITIMATE CASE. Unfortunately, yours is far from the only
one. It's becoming a norm.
Yes, I realize that Perl comes with excellent documentation. Yes, I
realize that practically *every* question that a beginner asks in this
ng has already been answered. But do we have to go out of our way to be
pricks to newbies?
Let's face it, you pasted 1 decent piece of information, RTFM, in
between 3 paragraphs of ripping someone who is here because they want to
learn the language and feel that they need some help. You couldn't even
be bothered to tell him to try perldoc CGI from anywhere on a linux
distro or from his bin on a win32 distro.
And save the "I'm just sick of having to explain the same sh*t to people
who can't be bothered to go do $X..." Just because someone is a novice
and therefore appears clueless to you is not license for you to go out
and treat them like sh*t.
Oh, and if you the original poster has cgi.pm installed, but not the
recommended v2.47, here's one way do it:
---
#!/usr/local/bin/perl
use CGI ':standard';
# invoke CGI.pm and then
# pass the field data into a scalar.
$file = param('file_name');
# don't forget to set the enctype on the html form
# to multipart/form in the <FORM> tag
# or you won't get the data you want.
$file_fixed = $file;
# you don't really need to copy the $file string to another string.
# Nevertheless, it's probably a good idea to use some regex's
# to get rid of the extra path info that most browsers pass along
# with the file name. the following regex is an ugly way to get rid
# of the path info for win32 users. RTFM won't help there.
$file_fixed =~ s/\w+\\//g; # yeah, I know these regex's
$file_fixed =~ s/.://; # suck, and that I should get
$file_fixed =~ s/\\//g; # the whole thing in one pass
# now store the data to a file somewhere on your system.
$data = "/path/to/stored/output/$file_fixed;
open(FH, ">$data") or die "could not open file";
while(<$file>) {
print FH $_;
}
close(FH);
# a purist will tell you to use local variables
# and take an oo approach.
# I'm just a hacker and often don't bother for smaller
# scripts because it means more typing unless i'm
# running mod_perl or speedy cgi or fast cgi, etc.
# In which case scope actually matters
# or if I'm running larger projects where oo
# actually matters. if you want a better way, RTFM.
------------------------------
Date: Thu, 02 Nov 2000 04:49:46 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Collecting data
Message-Id: <Kn6M5.99$Bf7.170911232@news.frii.net>
In article <8tmuqt$tb$1@nnrp1.deja.com>, <nodo70@my-deja.com> wrote:
>All,
>Can I activate to run a script under Unix box from a script under NT
>server? For example,
>#!perl -w
>$activate = ARGV[1];
>if (defined $activate) {
> `F:\scriptRun.pl`; #F drive which I map to Unix box by using Samba
^^^^^
There is a cute way to do this using Samba. Maybe you could look
at the Samba manual (smb.conf). Or perhaps ask the question in a
group that has Samba somewhere in it's name.
Good luck
chris
--
This space intentionally left blank
------------------------------
Date: 01 Nov 2000 18:49:21 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: hashes and references from an array
Message-Id: <m3ofzz42r2.fsf@dhcp11-177.support.tivoli.com>
michael.cambray@wellpoint.com writes:
> #!/home/tools/bin/perl
Obligatory mention of usefulness of using warnings and 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");
OK, so @fullarray contains space-separated strings...
> }
> $dbh->disconnect;
>
> for $row (@fullarray) {
> my ($id, $addr, $icn, $typ, $seq, $chg) = @$row;
Um... no. Too bad you don't have warnings and/or strict enabled so
that Perl could catch this type of mistake for you....
$row is just a string because that's all you filled @fullarray with.
Either use "push(@fullarray, [ $id, $addr, $icn, $typ, $seq, $chg ])"
above or use "split / /, $row" here.
> my $key = "$id $addr";
Because @$row above is creating an empty array on-the-fly, the only
$key that gets set is always " " (a space).
> push@{$items{$key}}, $row;
OK, so %items is a hash whose value is an array reference. Might you
mean simply:
$items{$key} = $row;
And since $key never changes, it only has the last $row, not that that
really matters at this point.
> }
>
> while (($key, @allrows) = each %items) {
each is only going to return two scalars, so assigning to an array
(@allrows) doesn't make much sense.
> print "$id $addr\n";
You aren't setting $id or $addr here, so they have their previous
values, if any, which in this case is from the last fetch. That's why
you get "B E" printed below.
> foreach $row (@$allrows) { print " $seq $chg\n"; }
Where did $allrows come from? That's the first time you've referenced
it and you expect it to have a value? You did use @allrows above
(incorrectly) but that has no affect on $allrows. If you change the
previous @allrows to $allrows, you will have a better chance, though
the other problems will still be in the way. This is yet another
example of a problem that either warnings or strict would have caught.
> }
> 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
Naturally, since you pushed those strings onto @fullarray with each
fetch.
> 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)
Perhaps someone else will re-tool your script for you, or maybe you
can figure out how to fix it based on my comments above. At the
beginning you mentioned that you've read through lots of documentation
and books. It looks to me like you really need to start from scratch
and try to understand each section before you move on to the next.
That includes writing small programs that use the material covered in
each section. I recommend that you start with _Learning_Perl_ and
forget everything you think you know.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 01 Nov 2000 19:01:35 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: hashes and references from an array
Message-Id: <3A00D90F.CC2395E1@vpservices.com>
michael.cambray@wellpoint.com wrote:
>
> #!/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");
> }
Others have given you some helpful info on referencing and
dereferencing. My comment has more to do with your DBI style. If you
are going to be dumping the entire results of the fetch into an array
anyway, you might as well let DBI do that for you. Instead of the
prepare, execute, bind, fetch, push, lines above, you can just do this:
my $table = $dbh->selectall_arrayref(q%
SELECT id, addr, icn, typ, seq, chg
FROM names
ORDER BY 1, 2, 3, 4
%);
This will result in $table containing a reference to an array, each row
of which is a reference to an array of the individual column values.
All the rows and columns will be in the same order you specified them in
the SQL statement.
Then you can dereference like this (just a sample, you could process
other ways within the loops as well):
for my $row( @$table ) {
for my $column(@$row) {
print "[$column] ";
}
print "\n";
}
Or, if you want the column names in there, dereference like this:
for my $row( @$table ) {
my($id,$addr,$icn,$typ,$seq,$chg) = @$row;
# ... whatever
}
Or use the other dereferencing techiniques suggested by others.
HTH,
--
Jeff
------------------------------
Date: Wed, 1 Nov 2000 21:34:16 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: hashes and references from an array
Message-Id: <slrn901kl8.ctb.tadmc@magna.metronet.com>
On Thu, 02 Nov 2000 00:15:02 GMT, michael.cambray@wellpoint.com
<michael.cambray@wellpoint.com> wrote:
>I have gone through the man pages,
I hope that includes 'perlreftut'. It seems to cover some of the
problems I see below.
>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,
A demonstration of a most effective troubleshooting stategy!
Thank you.
>#!/home/tools/bin/perl
You should be enabling warnings and the "use strict" pragma.
#!/home/tools/bin/perl -w
use strict;
>use DBI;
I don't have that available here and haven't used it much, but I
think I see some problems nonetheless.
>while ( $sth->fetch ) {
> push(@fullarray, "$id $addr $icn $typ $seq $chg");
>}
Here you push a string. So the elements of @fullarray are strings.
>for $row (@fullarray) {
> my ($id, $addr, $icn, $typ, $seq, $chg) = @$row;
^^^^^
Here you try to dereference *a string* that you push()ed earlier.
Dereferencing a string (as opposed to dereferencing a real reference)
is called a "symbolic reference". You don't want to use those
(but you are), you don't need them in modern Perl. Nowadays we
have real references.
I think you are trying to get back the same six space-separated
things you push()ed earlier. If so then to fix your problem
here, you can either:
push an (anonymous) array reference instead of a string:
push(@fullarray, [$id, $addr, $icn, $typ, $seq, $chg]);
and deref it as you have done.
OR
split $row instead of dereferencing it:
my ($id, $addr, $icn, $typ, $seq, $chg) = split /\s+/, $row;
[snip]
>while (($key, @allrows) = each %items) {
^
^
What's that?
each() will always return either a 2-element list, or an empty list.
So @allrows will always get either 1 or zero elements. Might as
well just use a scalar there.
Oh wait! I think you are trying to DEreference it here. Is that it?
If so, then you get the array ref in the while() and deref
it in the body of the loop:
while (($key, $ref2array) = each %items) {
foreach ( @{$ref2array} ) ...
$ref2array->[0] = ...
>END_PERL:
^^^^^^^^
^^^^^^^^
Perl actually has a token that is used to mark the end of code.
You can just say:
__END__
and Perl folks will know what it means.
[ snip all of the outputs. It isn't wildly useful without
the input that is to produce it.
]
Hope this helps!
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 1 Nov 2000 18:21:59 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: i'm in 'use vars' hell
Message-Id: <Zd4M5.11940$Wq1.7704488@nnrp5-w.sbc.net>
hi.
i believe i'm in 'use vars' hell. and i hope that someone can propose an
alternate solution to the one that is making me burn.
presently i have a bunch (as in a whole lot) of variable definitions in two
files:
datadefs.pm
lsdmltags.pm
these are essentially modeled on C header files and are serving the same
purpose... namely, to get the mass of defs out of the top of the script.
also, in the near future it is likely that there will be other scripts that
will include these files.
but, perl makes me trade one mess of variables for another... since now the
top of my script looks like this:
<CODE>
use vars qw($lessthan $greathan $amp $apos $quot
$roottag $rootetag
@lsdml_child_st @lsdml_child_et @doc_child_st @doc_child_et
@stats_child_st @stats_child_et @util_child_st @util_child_et
@wp_child_st @wp_child_et @media_child_st @media_child_et
@biblio_child_st @biblio_child_et @ctrlids_child_st @ctrlids_child_et
...
ad infinitum);
require 'lsdmltags.pm';
require 'datadefs.pm';
</CODE>
what method will allow me to *not* have to explicitly name every variable in
the 'use vars' declaration? ...a method that does not require me to create a
single global variable by way of a hash? (which reminds me... why is this
done? what is the value of the giant hash?)
TIA,
Brian
------------------------------
Date: Thu, 02 Nov 2000 02:56:03 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: i'm in 'use vars' hell
Message-Id: <3A00DACF.7426E0D8@home.com>
Brian McDonald wrote:
>
> what method will allow me to *not* have to explicitly name every variable in
> the 'use vars' declaration? ...a method that does not require me to create a
> single global variable by way of a hash? (which reminds me... why is this
> done? what is the value of the giant hash?)
Duh, declaring only one variable?
But if you don't want to declare them at all, put a package name at the
tops of 'lsdmltags.pm' and 'datadefs.pm' and use Exporter. Then use
'use' instead of 'require'.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Wed, 01 Nov 2000 19:00:20 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: i'm in 'use vars' hell
Message-Id: <3A00D8C4.206D75E9@vpservices.com>
Brian McDonald wrote:
>
> what method will allow me to *not* have to explicitly name every variable in
> the 'use vars' declaration? ...a method that does not require me to create a
> single global variable by way of a hash?
What method will allow me to walk to the store but does not require me
to go outside? [1]
> (which reminds me... why is this
> done? what is the value of the giant hash?)
What is the value of the giant hash? It allows you to just name the one
hash in the 'use vars' without having to explicitly name one variable
for each key in the hash. (hmm, does that sound familiar?)
[1] yes, there are other ways to do it than a hash, but since you
haven't explained why you object to the hash and a hash accomplishes
exactly what you specified as wanting, there's not alot of point in
going into them since you might object to them also.
--
Jeff
------------------------------
Date: Wed, 1 Nov 2000 20:27:51 -0800
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: i'm in 'use vars' hell
Message-Id: <Z36M5.11961$Wq1.7733984@nnrp5-w.sbc.net>
"Jeff Zucker" <jeff@vpservices.com> wrote in message
> Brian McDonald wrote:
> >
> > what method will allow me to *not* have to explicitly name every
variable in
> > the 'use vars' declaration? ...a method that does not require me to
create a
> > single global variable by way of a hash?
>
> What method will allow me to walk to the store but does not require me
> to go outside? [1]
well, i now see that my question was stupid in a way that i could not have
imagined.
>
> > (which reminds me... why is this
> > done? what is the value of the giant hash?)
>
> What is the value of the giant hash? It allows you to just name the one
> hash in the 'use vars' without having to explicitly name one variable
> for each key in the hash. (hmm, does that sound familiar?)
>
> [1] yes, there are other ways to do it than a hash, but since you
> haven't explained why you object to the hash and a hash accomplishes
> exactly what you specified as wanting, there's not alot of point in
> going into them since you might object to them also.
>
my objection to the giant hash is that it seems like an extraordinarily
strange data structure to have to concoct in order to include global
variable declarations from another place. in other words, why, in perl,
couldn't it just be as simple as #include "datadefs.h" is in C? i guess, in
a way, my desire for another option takes on a philosophical dimension. but,
i am not hash intolerant.
that said, i am all ears as to the alternatives to the giant hash... unless,
of course, the giant hash is considered *the* perl way to go.
what is the preferred perl solution to this problem?
brian
------------------------------
Date: Wed, 01 Nov 2000 20:55:17 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: i'm in 'use vars' hell
Message-Id: <3A00F3B5.FBEF5689@vpservices.com>
Brian McDonald wrote:
> my objection to the giant hash is that it seems like an extraordinarily
> strange data structure to have to concoct in order to include global
> variable declarations from another place.
If you regard a hash as a strange data structure, I'm not sure you will
ever go very far with Perl.
The reason I prefer it for a situation like this, is that when I use a
varaible declared "in another place", I like to know that it is from
another place and that if I happen to forget that I used a name for it
in that other place and use that name again in my current "place", that
I won't be shooting myself in the foot. Keeping the variables in an
object with its own access methods is also another way to accomplish
that in some situations, but a hash is often quicker and easier.
> what is the preferred perl solution to this problem?
See Rick's suggestion about Exporter for another option.
--
Jeff
------------------------------
Date: Wed, 1 Nov 2000 20:12:24 -0600
From: "Tambaa Hapa" <tambaah@x.hotmail.com>
Subject: Multipart response
Message-Id: <8tqijj$sl3$1@tilde.csc.ti.com>
Hi,
Anyone know whether libwww-perl has a function to extract multipart
responses in name= value pairs? For example, for the following response we
might get something like ReturnCode=7 and ReturnMessage=Error.
--Boundary-=_qmZrHLajoetbkwlTZTViemHPfybp
Content-Type: Text/Plain
Content-Transfer-Encoding: 7bit
Content-Disposition: form-data; name=ReturnCode
7
--Boundary-=_qmZrHLajoetbkwlTZTViemHPfybp
Content-Type: Text/Plain
Content-Transfer-Encoding: 7bit
Content-Disposition: form-data; name=ReturnMessage
Error
Thanks in advance.
T. H.
------------------------------
Date: Thu, 02 Nov 2000 04:39:30 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: mySQL & Perl
Message-Id: <6e6M5.97$Bf7.169981440@news.frii.net>
In article <8tqcl3$c6s$1@news.sovam.com>, Vitaliy <vitaliy@canada.com> wrote:
>Hi!
>How can I put gif image (BLOB) into mySQL?
>Please, write to me simple program (by Perl).
>
I'm available for contract. Drop me a note.
--
This space intentionally left blank
------------------------------
Date: Thu, 02 Nov 2000 02:48:38 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: newbie looking for help on pattern matching
Message-Id: <3A00D5E7.4D6F23FB@rochester.rr.com>
tizatron@my-deja.com wrote:
...
> 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
> ----------------------
...
> -Dean
...
Try the Date::Manip module. It can decode many common date formats
automatically and make the compares easy. It should be on your hard
drive. Do:
perldoc Date::Manip
to learn more.
--
Bob Walton
------------------------------
Date: Wed, 1 Nov 2000 21:43:21 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Newbie: seeing scalars within require files?
Message-Id: <slrn901l69.ctb.tadmc@magna.metronet.com>
On Wed, 1 Nov 2000 22:49:42 +0000, Robin Bowen <spam@pagans.demon.co.uk> wrote:
>I'm trying to build a subroutine library, and also to declare common
>scalars.
"common scalars" sounds to me like "global variables". See below.
[snip]
>is there any way I can reference $cons1 from
>within file2.pl?
Yes, but you cannot get it done with lexical (my) variables.
>Any help or pointers would be appreciated!
See the recent thread here with:
Subject: Re: global variables and use strict
wherein this topic was just discussed rather extensively.
Also check out the Perl FAQ, part 7:
"What's the difference between dynamic and lexical (static) scoping?
Between local() and my()?"
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 1 Nov 2000 21:48:00 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: OT: Yes there _are_ stupid questions. Anyone collect them?
Message-Id: <slrn901lf0.ctb.tadmc@magna.metronet.com>
On Wed, 01 Nov 2000 23:43:25 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>then sends "GET RICK QUICK(LY) !!!!!!"
I'll bet that made Rick feel uneasy...
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2000 03:57:27 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Perl Question
Message-Id: <slrn901ph4.4sn.tjla@thislove.dyndns.org>
I was shocked! How could Mark-Jason Dominus <mjd@plover.com>
say such a terrible thing:
>
>In article <ant0117327a1fNdQ@oakseed.demon.co.uk>,
>James Taylor <james@NOSPAM.demon.co.uk> wrote:
>>I'm curious about your suggestion that people actually skip articles
>>that do not have a descriptive subject.
>
>Probably some do and some don't. I usually do.
>
>I also kill off posts that contain 'urgent' because I figure that it's
>probably too late by the time I get to them anyway. I also kill off
>posts with subjects that end in '!', because experience has shown that
>they're not ususally worth my while.
Not to mention subjects containing the words 'beginner', 'newbie',
help', multiple exclamation marks or question marks, and one word
subjects.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Counting in binary is just like counting in decimal -- if you are
all thumbs.
-Glaser and Way
------------------------------
Date: 1 Nov 2000 23:03:02 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Perl Question
Message-Id: <8tqsi6$cdl$1@provolone.cs.utexas.edu>
In article <ant020100339fNdQ@oakseed.demon.co.uk>,
James Taylor <james@NOSPAM.demon.co.uk> wrote:
>It's spooky to think that a choice of subject line could render my
>post invisible to a number of knowledgeable people.
Why? Isn't the Subject line supposed to contain useful information?
Is that information supposed to be used by people in determining
whether they want to read the article?
When I read a regular newspaper, I don't even open the sports section.
Sure, there could be something interesting in there, but probably I
don't care about whatever it is. So there are certain things I never
see.
> It feels like an
>indiscriminate censorship,
It's not indiscriminate. In fact, it's very deliberate.
I guess I just don't see why it would be a problem if any individual
chooses to read whatever they want to, even if they let the computer do
some of that deciding for them.
- Logan
------------------------------
Date: Thu, 02 Nov 2000 04:20:58 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Perl style and module searches
Message-Id: <slrn901qt7.4sn.tjla@thislove.dyndns.org>
I was shocked! How could Dave E <dave_at_hm@hotmail.com>
say such a terrible thing:
>I have 2 newbie questions:
>
>1) Is there a style, or "best practices" guide for Perl?
Well I don't know if there is but I'm sure if there was it would include
stuff like 'use hashes', 'use regular expressions', 'use perl style for
loops if you can', 'have fun', 'learn about all the different
interesting features of the language', 'use modules', 'don't overuse
modules', 'shell out to other programs if (necessary|you can)' and 'but for
god's sake don't overdo it' etc...
> I am a network administrator that inherited some Perl scripts I have
>to maintain. I taught myself the basics and can, imho,
>code in Perl fairly well; my scripts do what I want them to. But, when
>I look at other people's scripts -- they don't look anything like what I
>do :(
Well there isn't really any Perl 'style'. If you read much of Larry
Walls speeches you will note he emphasises that he designed Perl from
the point of vies of a linguistics background. The whole point is that
most human languages are not terribly logical or orthogonal or a whole
heap of other words ending in 'al'. There really is more than one way to
do it. It may make Perl harder to learn, but in the end the degree of
expressiveness that you gain is immense. At the risk of sounding pompous
I like to think of Perl as a language for programmers. A simple language
such as java may be easier to learn but it is the equivalent of a
language with seven verbs and 5 nouns ie. you have to do a lot of work
to do anything with it. On the other hand Perl is like English, you get
five words to express exactly the same thing :) Actually I think it's
still not really "there" yet and I'd like to see it go even further,
Perl 6 sounds promising in that respect. Anyway, even though there is no
Perl 'style' it is still possible to write 'good' Perl. Good Perl is
simply code that solves the problem simply, is easy to understand and is
not excessively verbose.
>Is there a good source for example scripts that I can look at?
>Something that says "this part is included because ..." I've found
>"perlstyle" that came with my install of Perl, but I'd really like some
>solid examples to look over. Not modules though... way to confusing
>for my newbie mind. I just need an anatomy of a basic Perl script.
I can recommend Randal Schwartz's monthly columns that he writes for
magazines such as Web Techniques and Linux magazine. See:
http://www.stonehenge.com/merlyn
>2) Is there some searchable index for module capabilities?
http://search.cpan.org
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Flame on!
-- Johnny Storm
------------------------------
Date: Wed, 01 Nov 2000 18:21:00 -0800
From: Chris Kantarjiev <cak@putzl.com>
Subject: Re: SMS - text messaging
Message-Id: <3A00CF8C.1E928DC9@putzl.com>
Steve wrote:
>
> Richard J. Rauenzahn wrote:
> >
> <snip>
> >
> > I wish many posters on clpm would try to write clearer questions.
>
> Sorry I thought it was clear ;-) - I want visitors to my site to be
> able to send text messages (sms) from my site to a mobile phone
> of their choice. They type a text message into an input box - then
> type the phone number and then press send and it's sent to the phone.
>
> Any Ideas?
>
> cheers
>
> Steve
Well, first you have to figure out what carrier handles the phone, and
then you need a relationship with that carrier that allows you to submit
messages to be delivered, and then you have to format the message
correctly and submit it.
People are building business around this. You might want to look at,
say, http://www.unimobile.com
------------------------------
Date: 01 Nov 2000 19:05:23 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Stultiloquent Queries (was: even or odd?)
Message-Id: <m1r94vxedo.fsf@halfdome.holdit.com>
>>>>> "David" == David Steuber <nospam@david-steuber.com> writes:
David> You mean this question had been asked before? How many VB programmers
David> are there?
And would it be an even or odd number of VB programmers?
--
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: Thu, 02 Nov 2000 04:13:59 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: Stultiloquent Queries (was: even or odd?)
Message-Id: <bS5M5.112882$bI6.4338490@news1.giganews.com>
merlyn@stonehenge.com wrote:
:
: And would it be an even or odd number of VB programmers?
Kind of.
--
Nate II
------------------------------
Date: Thu, 02 Nov 2000 04:29:31 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Stultiloquent Queries (was: even or odd?)
Message-Id: <slrn901rd9.4sn.tjla@thislove.dyndns.org>
I was shocked! How could Randal L. Schwartz <merlyn@stonehenge.com>
say such a terrible thing:
>And would it be an even or odd number of VB programmers?
How do you tell if a number is even or odd again?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Absence extinguishes small passions and increases great ones, as the
wind blows out a candle, and fans a bonfire.
-- La Rochefoucauld
------------------------------
Date: Thu, 02 Nov 2000 04:42:59 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Stultiloquent Queries (was: even or odd?)
Message-Id: <nh6M5.98$Bf7.171104768@news.frii.net>
In article <m1r94vxedo.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "David" == David Steuber <nospam@david-steuber.com> writes:
>
>David> You mean this question had been asked before? How many VB programmers
>David> are there?
>
>And would it be an even or odd number of VB programmers?
>
VB programmers are all even. That is assuming of course that perl
programmers are odd. Or maybe they are just irrational in which
case they are neither.
--
This space intentionally left blank
------------------------------
Date: Thu, 02 Nov 2000 04:16:13 GMT
From: robbelljr@my-deja.com
Subject: times array
Message-Id: <8tqpq9$8p1$1@nnrp1.deja.com>
From the Perl Man Pages:
times - return elapsed time for self and child processes
Returns a four-element array giving the user and system times, in
seconds, for this process and the children of this process.
($user,$system,$cuser,$csystem) = times;
My question:
For a simple test of elapsed time processing a script is the following
valid?
# at the beginning of the script
my $start = (times)[0];
...
# at the end of the script
my $end = (times)[0];
print "Server side this page was generated in ";
print $end - $start;
print " seconds";
To be quite honest I do not understand what the various elements of the
times array represent but am guessing that practically speaking the
$user time might be most meaningful?
Thanks,
Rob Bell
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 02 Nov 2000 04:58:56 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: times array
Message-Id: <kw6M5.100$Bf7.170605568@news.frii.net>
In article <8tqpq9$8p1$1@nnrp1.deja.com>, <robbelljr@my-deja.com> wrote:
>
>For a simple test of elapsed time processing a script is the following
>valid?
>
The perl function times() returns CPU times. that is the time your
program spent executing instructions in the CPU and not waiting
for disk or network or user inout or blocked by something else.
Wall clock time is probably what you are looking for. If you are
OK resolution in seconds then use time() just about as you have
described in your posting. Or if you need higher precision look up
gettimeofday or Time::HiRes.
--
This space intentionally left blank
------------------------------
Date: Wed, 01 Nov 2000 19:59:38 -0800
From: Mark Thompson <mark-lists@webstylists.com>
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <p9p10tk2sp6s2q8poklv74onp8afh910vh@4ax.com>
On Thu, 02 Nov 2000 00:02:25 GMT, jerome@activeindexing.com (Jerome
O'Neil) wrote:
>Mark Thompson <mark-lists@webstylists.com> elucidates:
>> Well, had my plans of how I was going to do this until I saw you
>> mention File::Find and I really can't find much on it that would help
>> me use it (I found some cryptic documentation but even the Perl 5
>> books that I have don't cover this to any level but they cover the old
>> methods extensively.)
>
>Well, lets take another tac on this, then. What in particular do
>you find 'cryptic' about the documentation for File::Find? I find it
>pretty well documented, myself, and am always curious as to what parts
>others find problematic.
>
>I think once we know that, you'll be much enlightened.
The only thing I could find on the subject in the documentation was
what's at:
http://search.cpan.org/doc/JHI/perl-5.7.0/lib/File/Find.pm
This lets me know that there has to be way more than I can see here
(by mentioning things such as Find::File::name), but it doesn't point
me in the right direction. I have the idea that there's an entire
online collection of documentation that I'm missing if I could ever
find it.
Thanks,
Mark
------------------------------
Date: Wed, 1 Nov 2000 21:52:17 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <slrn901ln1.ctb.tadmc@magna.metronet.com>
On Thu, 02 Nov 2000 00:02:25 GMT, Jerome O'Neil
<jerome@activeindexing.com> wrote:
>Mark Thompson <mark-lists@webstylists.com> elucidates:
>> On Wed, 01 Nov 2000 21:53:57 GMT, jerome@activeindexing.com (Jerome
>> O'Neil) wrote:
>>
>>>Its a fine way of doing things. Just ensure you use File::Find when
>>>you do it.
>>
>> Well, had my plans of how I was going to do this until I saw you
>> mention File::Find and I really can't find much on it that would help
>> me use it (I found some cryptic documentation but even the Perl 5
>> books that I have don't cover this to any level but they cover the old
>> methods extensively.)
>
>Well, lets take another tac on this, then. What in particular do
>you find 'cryptic' about the documentation for File::Find? I find it
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>pretty well documented, myself, and am always curious as to what parts
>others find problematic.
>
>I think once we know that, you'll be much enlightened.
I might guess that perhaps Mark does not know how to get the
real (official) documentation.
So, just in case that is it, you access the File::Find docs like this:
perldoc File::Find
Is _that_ the "cryptic documentation" that you are referring to?
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2000 12:45:56 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: What's wrong with this regex?
Message-Id: <3A00C754.69AE014@ot.com.au>
Dominique Lorre wrote:
> In article <39FCAB13.15D27DC8@ot.com.au>,
> Ian Boreham <ianb@ot.com.au> wrote:
> > Dominique Lorre wrote:
> >
> > > $some_variable = $1 + $2/$3
> > >
> > > when $3 is zero you will get an error.
> >
> > True, but the code below gives an incorrect answer, when an error is
> > preferable.
> >
> Not here, you should first look at what is doing the code before giving
> your opinion.
You didn't test this, though, did you? I did (see "Nov 10" example below),
and it gives an incorrect answer, when it should give an error.
> > > foreach $other_variable(@examples) {
> > > $some_variable = -1 ; # undef marker
> > > $some_variable = $3?$1+$2/$3:$1
> First, you should read the (only!) comment in the code. Even if it was
> incorrect you would have an idea of what is going here. Then you should
> read the second line and notice there is no ';' character, thus the
> code line is not ended. The correct line was:
> $some_variable = $3?$1+$2/$3:$1
> if ($other_variable =~ |\d{2} [A-Za-z]{3} (\d*) (\d*)/*(\d*)|);
My apologies for missing the semi-colon. I suggest you format your code to
reflect your intent. Did you manually transcribe this? It didn't even
compile.
> This makes much more sense. I put -1 in other variable to check if it
> has been set later. Such programming practice is part of what is
<snip COMPSCI 101>
I'd recommend you use "undef" as an "undef marker". Negative numbers can't
be read from the data, but -1 may have some meaning in this (problem)
context. It doesn't affect the examples in the OP, so I'll leave it as is,
here.
> $1, $2 and $3 are set correctly here. I know it is
> confusing but I had to split the line somewhere to keep the regexp
> intact.
Yes, it makes more sense now, but I will argue that $1, $2 and $3 are not
always being set correctly. There is not enough error-checking being done.
Either the regex needs to be tightened up, or the error-checking of the
captured values needs to be stricter. Personally, I would prefer to use
"die" with a descriptive message, rather than an (undef) error code in this
case, because I would want to distinguish between unrecognisable input and
recognisable but pathological input. You could use different numeric
values, assuming that negative numbers have no meaning here.
After fixing the code so it compiles, reformatting it for clarity, and
adding some more examples to simulate imperfect data, we end up with:
#!/usr/bin/perl -w
use strict;
my($some_variable, $other_variable, @examples) ;
@examples = (
"00 Nov 5 (IFQ KA-E)",
"00 Nov 7 1/2 (IFQ KB-E)",
"00 Nov 10 (IFQ KC-E)",
"00 Nov 12 1/2 (IFQ KD-E)",
"00 Nov 8 / (Blah)",
"00 Nov 8 //////////////// (Blah)",
"00 Nov 9 /35 (Blah)",
"00 Nov 10 9/0 (Blah)",
"00 Nov 11 9//////0 (Blah)",
"00 Nov 21 #9/11 (Blah)",
"00 Nov / (Blah)",
"00 Nov 21 9/00 (Blah)",
);
foreach $other_variable(@examples) {
$some_variable = -1 ; # undef marker
$some_variable = $3?$1+$2/$3:$1
if ($other_variable =~ m|\d{2} [A-Za-z]{3} (\d*) (\d*)/*(\d*)|);
print "$some_variable = $some_variable\n" ;
}
__END__
This produces the following results:
5 = 5
7.5 = 7.5
10 = 10
12.5 = 12.5
8 = 8
8 = 8
Argument "" isn't numeric in divide at m2.pl line 23.
9 = 9
10 = 10
11 = 11
21 = 21
=
Illegal division by zero at m2.pl line 23.
-----
The "8"s and "9" should be unrecognisable input data, but they match and
give potentially spurious results. "10" should give an error (division by
zero), but gives 10 (this is the incorrect value error I am talking about).
"11", "21" and the no-number should be unrecognisable input. The final
string ("21") actually gives a division by zero error.
If we rewrite the regex to fail when we don't have recognisable input, to
use match delimiters that aren't also metacharacters, and provide better
error-checking, we get:
#!/usr/bin/perl -w
use strict;
my($some_variable, $other_variable, @examples) ;
@examples = (
"00 Nov 5 (IFQ KA-E)",
"00 Nov 7 1/2 (IFQ KB-E)",
"00 Nov 10 (IFQ KC-E)",
"00 Nov 12 1/2 (IFQ KD-E)",
"00 Nov 8 / (Blah)",
"00 Nov 8 //////////////// (Blah)",
"00 Nov 9 /35 (Blah)",
"00 Nov 10 9/0 (Blah)",
"00 Nov 11 9//////0 (Blah)",
"00 Nov 21 #9/11 (Blah)",
"00 Nov / (Blah)",
"00 Nov 21 9/00 (Blah)",
);
foreach $other_variable(@examples) {
$some_variable = -1 ; # undef marker
if ($other_variable =~ m%\d{2} [A-Za-z]{3} (\d+) (?:(\d+)/(\d+) )?\(%)
{
if (defined($3))
{
$some_variable = $1+$2/$3 if ($3 != 0);
}
else
{
$some_variable = $1;
}
}
print "$some_variable = $some_variable\n" ;
}
__END__
You could munge all the branches into a single line of "?:"s, but I'll
leave it this way for clarity. The results are:
5 = 5
7.5 = 7.5
10 = 10
12.5 = 12.5
-1 = -1
-1 = -1
-1 = -1
-1 = -1
-1 = -1
-1 = -1
-1 = -1
-1 = -1
------
> > > print "$some_variable = $some_variable\n" ;
> >
> > This will print the value twice. You should escape the first "$".
> >
> I am not sure to understand what you mean.
This in known in computer science terms as "printing the same thing twice".
I could only assume you wanted output that looked something like:
$some_variable = 7.5
If you really want:
7.5 = 7.5
then stick with what you've got. I was just suggesting you escape (\$) the
first "$", if you were trying to achieve the output I suggested.
> I am new to Perl and maybe
> this expression is not perfect but it seems to work (at least it worked
> for the examples given by OP).
Well, now that my misconception has been rectified, it certainly seems to
go a long way towards a correct solution.
Regards,
Ian
------------------------------
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 4789
**************************************