[18069] in Perl-Users-Digest
Perl-Users Digest, Issue: 229 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 7 06:05:38 2001
Date: Wed, 7 Feb 2001 03:05:14 -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: <981543914-v10-i229@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 7 Feb 2001 Volume: 10 Number: 229
Today's topics:
Re: "Average of List of Numbers" by Abigail (Monte Phillips)
Re: "Average of List of Numbers" by Abigail (Monte Phillips)
Re: "Average of List of Numbers" by Abigail (Monte Phillips)
Beginners Question <sferguson@rationalconsulting.com>
Re: Beginners Question (Abigail)
Re: Convert postscript to jpeg? (Martien Verbruggen)
Re: er, how? (Bernard El-Hagin)
Re: er, how? <ducateg@info.bt.co.uk>
Fastest way of left-padding a number? <jll63@easynet.be>
Re: Fastest way of left-padding a number? (Abigail)
Re: Fastest way of left-padding a number? <tore@extend.no>
Re: Fastest way of left-padding a number? <ccx138@coventry.ac.uk>
Re: Fastest way of left-padding a number? <h.camp@scm.de>
Get file in string by virtual path????? <Martijn.vanPoppel@atosorigin.com>
Re: Get file in string by virtual path????? <thoren@southern-division.com>
Re: Hashes (Garry Williams)
Re: Hashes <uri@sysarch.com>
Re: Help with calling functions from dynamic/shared lib jimjim123@my-deja.com
Re: Logfile pattern search & print (Garry Williams)
Re: Mysql and Perl multiple insert? (Garry Williams)
Re: Need Help Checking IP Address Syntax w/ PERL? (Bernard El-Hagin)
Re: Need Help Checking IP Address Syntax w/ PERL? <bart.lateur@skynet.be>
Re: newbie - grep non-used uid from passwd <krahnj@acm.org>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Feb 2001 09:47:16 GMT
From: montep@hal-pc.org (Monte Phillips)
Subject: Re: "Average of List of Numbers" by Abigail
Message-Id: <3a82198e.2090756@news.hal-pc.org>
On Wed, 7 Feb 2001 04:58:17 +0000 (UTC), Gregory Neil Bastow
<gregbast@tartarus.uwa.edu.au> wrote:
>In comp.lang.misc Chris Stith <mischief@velma.motion.net> wrote:
>: In the context of programming, I've always thought elegance had to do
>: with doing something in a way that is either conscise and fast or simple
>: but not necessarily obvious.
>
>Not sure what you mean about "obviousness" with respect to elegance.
>I think it should be fairly easy to see what it does and how it works, but
>usually taking a non-obvious step to come up with it in the first place.
>-Greg
Elegance in all matters, whether mathematical, musical, visual or
anything else is simply this(pun intended<grin>):
The shortest line between two points!
HERE:route:OBJECTIVE
Monte
.
.
.
.
.
.
.
.
.
.
------------------------------
Date: Wed, 07 Feb 2001 09:39:12 GMT
From: montep@hal-pc.org (Monte Phillips)
Subject: Re: "Average of List of Numbers" by Abigail
Message-Id: <3a811730.1484234@news.hal-pc.org>
On Wed, 7 Feb 2001 04:58:17 +0000 (UTC), Gregory Neil Bastow
<gregbast@tartarus.uwa.edu.au> wrote:
>In comp.lang.misc Chris Stith <mischief@velma.motion.net> wrote:
>: In the context of programming, I've always thought elegance had to do
>: with doing something in a way that is either conscise and fast or simple
>: but not necessarily obvious.
>
>Not sure what you mean about "obviousness" with respect to elegance.
>I think it should be fairly easy to see what it does and how it works, but
>usually taking a non-obvious step to come up with it in the first place.
>-Greg
Elegance in all matters, whether mathematical, musical, visual or
anything else is simply this(pun intended<grin>):
The shortest line between two points!
HERE:route:OBJECTIVE
Monte
------------------------------
Date: Wed, 07 Feb 2001 09:46:17 GMT
From: montep@hal-pc.org (Monte Phillips)
Subject: Re: "Average of List of Numbers" by Abigail
Message-Id: <3a811966.2050989@news.hal-pc.org>
On Wed, 7 Feb 2001 04:58:17 +0000 (UTC), Gregory Neil Bastow
<gregbast@tartarus.uwa.edu.au> wrote:
>In comp.lang.misc Chris Stith <mischief@velma.motion.net> wrote:
>: In the context of programming, I've always thought elegance had to do
>: with doing something in a way that is either conscise and fast or simple
>: but not necessarily obvious.
>
>Not sure what you mean about "obviousness" with respect to elegance.
>I think it should be fairly easy to see what it does and how it works, but
>usually taking a non-obvious step to come up with it in the first place.
>-Greg
Elegance in all matters, whether mathematical, musical, visual or
anything else is simply this(pun intended<grin>):
The shortest line between two points!
HERE:route:OBJECTIVE
Monte
------------------------------
Date: Wed, 07 Feb 2001 08:57:46 GMT
From: Scott Ferguson <sferguson@rationalconsulting.com>
Subject: Beginners Question
Message-Id: <36B64F09.3D047C91@rationalconsulting.com>
I wrote a basic PERL program, mostly "system" functions, that passes a
few string into the program via the traditional:
print "\nEnter the label name to create (no spaces): ";
$label=<STDIN>; chomp $label;
Now, I want remove this prompt for data and make it a command line
option.
The name of the file is build.pl, so I want the user to be able to type
build.pl REL2, on the command, and then have the program read the REL2
as the $label variable string.
Any help or direction will be greatly appreciated.
Scott
------------------------------
Date: 7 Feb 2001 09:05:30 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Beginners Question
Message-Id: <slrn9823uq.of7.abigail@tsathoggua.rlyeh.net>
Scott Ferguson (sferguson@rationalconsulting.com) wrote on MMDCCXVII
September MCMXCIII in <URL:news:36B64F09.3D047C91@rationalconsulting.com>:
[] I wrote a basic PERL program, mostly "system" functions, that passes a
No, you didn't. Go look into the FAQ to see how to spell the language
discussed here.
[] few string into the program via the traditional:
[]
[] print "\nEnter the label name to create (no spaces): ";
[] $label=<STDIN>; chomp $label;
[]
[] Now, I want remove this prompt for data and make it a command line
[] option.
[]
[] The name of the file is build.pl, so I want the user to be able to type
[] build.pl REL2, on the command, and then have the program read the REL2
[] as the $label variable string.
[]
[] Any help or direction will be greatly appreciated.
man perlvar
Abigail
--
perl -wlne '}for($.){print' file # Count the number of lines.
------------------------------
Date: Wed, 7 Feb 2001 19:17:12 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Convert postscript to jpeg?
Message-Id: <slrn982148.vht.mgjv@martien.heliotrope.home>
On Tue, 6 Feb 2001 18:45:56 -0800,
Jürgen Exner <juex@deja.com> wrote:
> "Scott Bossi" <Scott.Bossi@fmr.com> wrote in message
> news:3A805CA6.7797164A@fmr.com...
>> I have an application that generates output in postscript format, which
>> is no good, since it needs to be viewed from a web browser. Does anyone
>> know of a way to convert postscript to another format, such as a jpeg?
>> Or am I missing something obvious here...
>
> Well, what you are asking for is similar to converting Perl into GIF or C++
> into BMP.
I fail to see the similarity. Sure, PostScript is not the same as GIF or
JPEG, but it is eminently possible to render a PostScript page or
fragment, and outputting it to GIF or JPEG. Ghostscript does it.
> Are you sure that is what you want? I don't think so.
I don't think it's an odd thing to ask. People do it all the time. Some
LaTeX to HTML convertors use ghostscript to render equations and other
things that don't have a direct equivalent in HTML. Output is generally
GIF or PNG.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: Wed, 7 Feb 2001 08:58:52 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: er, how?
Message-Id: <slrn9823ib.2uq.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 6 Feb 2001 18:41:36 +0100, Rudolf Polzer <rpolzer@web.de> wrote:
>Géry <ducateg@info.bt.co.uk> schrieb Folgendes:
>> Hi
>>
>> I have a config file that looks like
>>
>> package mypackage;
>>
>> $FOO = "Hello";
>> $BAR = "Yadayada";
>>
>> ...
>>
>> I would like to be able to update the config file. I can manage that, the
>> problem is that the script does not pick up the changes. I guess it is
>> because it compiles the code once and then every variable is in the
>> "mypackage" variable table. How do I get Perl to compile the config file
>> again?
>
>Why not change the variables at the same time?
>
>sub ChangeConfig
>{
> my $name, $value = @_;
This doesn't compile if you've got strictures on. And if you don't it
gives an incorrect result. Didn't you check this before posting.
> # ...
> no strict 'refs';
> $name = "mypackage::$name";
> $$name = $value;
>}
Now you're just being silly.
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Wed, 7 Feb 2001 08:53:55 -0000
From: "Géry" <ducateg@info.bt.co.uk>
Subject: Re: er, how?
Message-Id: <95r2kn$6a1$1@pheidippides.axion.bt.co.uk>
The config file is updated from a third party script (a config update web
page). The script that is concerned with the changes and from where I check
the config file runs continuously on the server, it checks the config file
every now and then for changes. Still your idea is interesting, It may be
valuable throughout the evolution of my scripts, thanks.
"Rudolf Polzer" <rpolzer@web.de> wrote in message
news:slrn980dqg.3no.rpolzer@rebounce.rpolzer-lx...
> Géry <ducateg@info.bt.co.uk> schrieb Folgendes:
> > Hi
> >
> > I have a config file that looks like
> >
> > package mypackage;
> >
> > $FOO = "Hello";
> > $BAR = "Yadayada";
> >
> > ...
> >
> > I would like to be able to update the config file. I can manage that,
the
> > problem is that the script does not pick up the changes. I guess it is
> > because it compiles the code once and then every variable is in the
> > "mypackage" variable table. How do I get Perl to compile the config file
> > again?
>
> Why not change the variables at the same time?
>
> sub ChangeConfig
> {
> my $name, $value = @_;
> # ...
> no strict 'refs';
> $name = "mypackage::$name";
> $$name = $value;
> }
>
> --
> $p=q;.;;$_=<<'learn.to/quote';s/./pack"C",9^unpack"C",$&/gem;eval;'RP'
> -u""2of{!zye`}&&%+khza)*)'{'d')'$'{'o')'&'Ug'''khza)*)'e'f'n'f'|'}'UgU
> C|z})b`mm`gn.g.hgf}al{)'Y'l'{'e)ahjbl{Ug+ r-V)lx-y//zelly)8'9uuy{`g}2t
> learn.to/quote
------------------------------
Date: 07 Feb 2001 09:37:11 +0100
From: Jean-Louis Leroy <jll63@easynet.be>
Subject: Fastest way of left-padding a number?
Message-Id: <m3hf26khxk.fsf@enterprise.starfleet>
Given a number, say 17; given a fixed size, say 4; what's the fastest
way of producing 0017? Faster than sprintf("%04d", $val)? TIA.
--
Jean-Louis Leroy
http://users.skynet.be/jll
------------------------------
Date: 7 Feb 2001 08:39:11 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Fastest way of left-padding a number?
Message-Id: <slrn9822df.of7.abigail@tsathoggua.rlyeh.net>
Jean-Louis Leroy (jll63@easynet.be) wrote on MMDCCXVII September MCMXCIII
in <URL:news:m3hf26khxk.fsf@enterprise.starfleet>:
;; Given a number, say 17; given a fixed size, say 4; what's the fastest
;; way of producing 0017? Faster than sprintf("%04d", $val)? TIA.
Write it in C.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Wed, 7 Feb 2001 10:17:07 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: Fastest way of left-padding a number?
Message-Id: <MPG.14eb3100ebb92aa989895@news.online.no>
In article <m3hf26khxk.fsf@enterprise.starfleet>, jll63@easynet.be
says...
> Given a number, say 17; given a fixed size, say 4; what's the fastest
> way of producing 0017? Faster than sprintf("%04d", $val)? TIA.
How fast do you really want this thing to be? According to the
Benchmark module, my 650MHz (Pentium III) can do 17-18 millions
operations like this one per second.
--
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
------------------------------
Date: Wed, 07 Feb 2001 09:39:55 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: Fastest way of left-padding a number?
Message-Id: <3A8117EB.2135AE0F@coventry.ac.uk>
Tore Aursand wrote:
> In article <m3hf26khxk.fsf@enterprise.starfleet>, jll63@easynet.be
> says...
> > Given a number, say 17; given a fixed size, say 4; what's the fastest
> > way of producing 0017? Faster than sprintf("%04d", $val)? TIA.
>
> How fast do you really want this thing to be? According to the
> Benchmark module, my 650MHz (Pentium III) can do 17-18 millions
> operations like this one per second.
>
> --
> Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
What you trying to do?
Either you're using the wrong language or you algorithm is wrong and could
do with a rethink.
Explain the context and the need for speed.
------------------------------
Date: Wed, 7 Feb 2001 10:38:16 +0100
From: H. Camphausen <h.camp@scm.de>
Subject: Re: Fastest way of left-padding a number?
Message-Id: <95r4qg$ru4$1@surz18.uni-marburg.de>
[F'up zu Jean-Louis Leroy's Posting vom 07 Feb 2001 09:37:11 +0100]
> Given a number, say 17; given a fixed size, say 4; what's the fastest
> way of producing 0017? Faster than sprintf("%04d", $val)? TIA.
print '0017';
SCNR :-)
mfg, Hartmut
--
CREAGEN Computerkram Fon: 06422/850527
Hartmut Camphausen Fax: 06422/850528
Am kleinen Born 1 E-Mail: h.camp@creagen.de
35287 Amöneburg WWW: http://www.creagen.de
------------------------------
Date: Wed, 7 Feb 2001 11:19:41 +0100
From: "Martijn van Poppel" <Martijn.vanPoppel@atosorigin.com>
Subject: Get file in string by virtual path?????
Message-Id: <0E16861EE7BCD111BE9400805FE6841F144A33E5@c1s5x001.cor.srvfarm.origin-it.com>
Hi,
I have a question about reading files into strings in Perl.
Right now I use the real location of the file on the server to get the file.
I would like to use the virtual location to get the file. (the file can be
opened by an URL too, because it's part of a site)
For example:
Right now I have to following piece of code:
$/ = undef;
open TOP, '../../htdocs/inc/top_perl.inc' or die $!;
my $top = <TOP>;
But I would like to do something like:
$/ = undef;
open TOP, 'http://servername/inc/top/top_perl.inc' or die $!;
my $top = <TOP>;
This doesn't work.
Does anybody know how to get a file by the virtual location and not the real
location?
Thanks in advance,
Martijn van Poppel
------------------------------
Date: Wed, 7 Feb 2001 11:47:01 +0100
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: Get file in string by virtual path?????
Message-Id: <MPG.14eb4614ed2dd68989853@news.btx.dtag.de>
In article
<0E16861EE7BCD111BE9400805FE6841F144A33E5@c1s5x001.cor.srvfarm.origin-
it.com>, Martijn van Poppel aka Martijn.vanPoppel@atosorigin.com says...
> But I would like to do something like:
>
> $/ = undef;
> open TOP, 'http://servername/inc/top/top_perl.inc' or die $!;
> my $top = <TOP>;
>
> This doesn't work.
>
> Does anybody know how to get a file by the virtual location and not the real
> location?
use the 'LWP::Simple' module
perldoc LWP::Simple
--
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
eval('+qjmw!:wqv"C/kplavyVctj&Aacke`\l "I &8%im_"'^(1x42)^((((((('j'.'2'x
5).'a'.'3'x5).'p'.'5'x5).'h'.'7'x5).'8'.'11'x2).'#'.'13'x2).'X'.'17'x2));
------------------------------
Date: Wed, 07 Feb 2001 05:25:31 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Hashes
Message-Id: <f%4g6.1387$561.8850@eagle.america.net>
On Wed, 07 Feb 2001 02:52:27 GMT, aramis1631@my-deja.com
<aramis1631@my-deja.com> wrote:
>In article <95qbrr$cku$1@nnrp1.deja.com>,
> bakor@my-deja.com wrote:
[snip]
>> %days_in_month=(Jan,31,Feb,28,Mar,31);
>>
>> $month=`date +%b`;
>> print $month;
>> print $days_in_month($month);
>
>It appears to me, that you have parens (), when you mean to use curly
>braces {}.
Nope.
Braces will produce a reference to an anonymous hash.
He's got it right, but he's not using strict. That's a Bad Thing.
[snip]
--
Garry Williams
------------------------------
Date: Wed, 07 Feb 2001 09:22:56 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Hashes
Message-Id: <x7hf26q236.fsf@home.sysarch.com>
>>>>> "MM" == Mike McPherson <hafateltec@hotmail.com> writes:
MM> #Correct the indate for calculating leap year
MM> my $inyear = substr($indate,0,4);
MM> my $leap = &leap($inyear);
MM> my %DaysInMonth =
MM> (0,31,1,$leap,2,31,3,30,4,31,5,30,6,31,7,31,8,30,9,31,10,30,11,31);
eww. why not make that a simple array indexed by 0-11?
MM> my $cordate = $indate."02000000";
MM> my @array = localtime(&CurrentLineTime($cordate));
MM> my $month = $array[4];
MM> #Define Days in month and there names.
MM> my %NamesOfMonth = (0 => January, 1 => Febuary,
MM> 2 => March, 3 => April,
MM> 4 => May, 5 => June,
MM> 6 => July, 7 => August,
MM> 8 => September, 9 => October,
MM> 10 => November, 11 => December);
again, indexing by an integer means that should be an array.
MM> #Return The name of the month and how many days it has.
MM> my $Month = $NamesOfMonth{$month};
MM> my $TotalDaysInMonth = $DaysInMonth{$month};
MM> if ($DaysInMonth{1} eq "28") {
MM> print "\nThis is a not a leap year";
MM> } else {
MM> print "\nThis is a leap year";
MM> }
better to have a boolean leap flag set rather than hard coding 28 all
over the place.
MM> foreach $today(1..$TotalDaysInMonth) {
MM> if ($today == 1 || $today == 2 || $today == 3 || $today == 4 || $today == 5
MM> || $today == 6 || $today == 7 || $today == 8 || $today == 9){
MM> @day = localtime(&CurrentLineTime($indate."0".$today."000000"));
MM> } else {
MM> @day = localtime(&CurrentLineTime($indate.$today."000000"));
MM> }
ouch!!
@day = localtime(&CurrentLineTime( sprintf "$indate%02d000000", $today));
MM> my $wday = $day[6];
MM> if ($wday eq 0) {
MM> $table{0}++;
MM> }
MM> if ($wday eq 1) {
MM> $table{1}++;
MM> }
MM> if ($wday eq 2) {
MM> $table{2}++;
MM> }
MM> if ($wday eq 3) {
MM> $table{3}++;
MM> }
MM> if ($wday eq 4) {
MM> $table{4}++;
MM> }
MM> if ($wday eq 5) {
MM> $table{5}++;
MM> }
MM> if ($wday eq 6) {
MM> $table{6}++;
MM> }
MM> }
HUH???? you have the $wday value, so why not just index with it?
$table{ $wday }++ ;
MM> print "\nThere are $table{0} Sundays";
MM> print "\nThere are $table{1} Mondays";
MM> print "\nThere are $table{2} Tuesdays";
MM> print "\nThere are $table{3} Wednsdays";
MM> print "\nThere are $table{4} Thursdays";
MM> print "\nThere are $table{5} Fridays";
MM> print "\nThere are $table{6} Saturdays\n";
make that into a loop with the days looked up from another array.
MM> # Format:YYYYMMDDHHMMSS
MM> sub CurrentLineTime {
MM> my $time = 0;
MM> my $date = $_[0];
don't use $_[0] in normal code. use shift or assign @_ to a list.
MM> my $day = substr($date,6,2);
MM> my $month = substr($date,4,2);
MM> my $year = substr($date,0,4);
MM> my %month = ("01", 0, "02", 31, "03", 59, "04", 90,
MM> "05", 120, "06", 151, "07", 181, "08", 212,
MM> "09", 243, "10", 273, "11", 304, "12", 334);
again, if this was an array, it would be cleaner and you wouldn't need
those keys. you have hash on the brane. arrays are good for something
you know.
MM> $time += (substr($date,0,4) - 1970) * 31536000;
does that take into account all the leap years since then? you should
check your results against timelocal which is known to be correct.
MM> $time += ($month{substr($date,4,2)} + substr($date,6,2) - 1) * 86400;
MM> my ($hours, $minutes, $seconds);
MM> if (substr($date,8,2) eq " ") {
MM> $hours = 0;
MM> } elsif (substr($date,8,1) eq " ") {
MM> $hours = substr($date,9,1);
MM> } else {
MM> $hours = substr($date,8,2);
MM> }
$hours = substr($date,8,2) + 0 ;
MM> if (substr($date,10,2) eq "00" || substr($date,10,2) eq " "){
MM> $minutes = 0;
MM> }elsif (substr($date,10,1) eq "0" || substr($date,10,1) eq " "){
MM> $minutes = substr($date,11,1);
MM> } else {
MM> $minutes = substr($date,10,2);
MM> }
ditto
MM> if (substr($date,12,2) eq "00" || substr($date,12,2) eq " "){
MM> $seconds = 0;
MM> }elsif (substr($date,12,1) eq "0" || substr($date,12,1) eq " "){
MM> $seconds = substr($date,13,1);
MM> } else {
MM> $seconds = substr($date,12,2);
MM> }
ditto
MM> $time += ($hours * 3600);
MM> $time += ($minutes * 60);
MM> $time += $seconds;
MM> # Total Correction = (# of leap years) + (System Clock Correction)
MM> # There have been ? leap years since 1970.
MM> # System clock correction is -10 hours for this specific system.
MM> # Total Correction = ? - 10*3600 for this specific system.
MM> #---------------------------------------------------------#
MM> # Calculate Time correction for leap year
MM> #---------------------------------------------------------#
MM> my $value = ($year - 1970)/4;
i don't see anything handling 2000 being a leap year. you seem to assume
it is but that means this code breaks in the year 2100.
MM> my $fixval = int($value);
MM> my $truevalue = 0;
i prefer ace hardware. :)
MM> my $monthday = $month.$day;
MM> if ($fixval eq 0 and $monthday gt "0229"){
MM> $truevalue = 1;
MM> } elsif ($fixval eq 0 and $monthday lt "0229") {
MM> $truevalue = 0;
MM> } elsif ($fixval gt 0 and $monthday gt "0229") {
MM> $truevalue = $fixval + 1;
MM> } else {
MM> $truevalue = $fixval;
MM> }
you have to learn to get away from all those flags. that code is impenetrable.
MM> #---------------------------------------------------------#
MM> $time += 86400 * $truevalue ; #Correction for leap year
MM> $time -= 36000 ; #Correction for Time Zone
fixed time zone is not cool.
MM> return $time;
MM> }
MM> #Determine if it is a leep year.
MM> sub leap {
MM> my $inyear = $_[0];
MM> # rule leapyear is divisable by 4 except those divisable by 100 unless
MM> divisable by 400...
MM> my $dividedyear = $inyear / 4;
MM> my $intyear = int($inyear / 4);
MM> my $centryyear = $inyear / 100;
MM> my $intcentryyear = int($inyear / 100);
MM> if ($dividedyear == $intyear){
MM> $leap = 29;
MM> } elsif ($dividedyear == $intyear && $centryyear == $intcentryyear){
MM> $leap = 28;
MM> } else {
MM> $leap = 28;
MM> }
MM> print $leap;
MM> return $leap;
MM> }
yech.
$is_leap = $year % 4 == 0 && $year % 100 || $year % 400 == 0 ;
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 07 Feb 2001 08:41:12 GMT
From: jimjim123@my-deja.com
Subject: Re: Help with calling functions from dynamic/shared libraries
Message-Id: <95r1n7$u4t$1@nnrp1.deja.com>
Hmm, Dynaloader should enable you to call functions like this. Let me
see if I'm understanding this correctly... You have a perl progam,
that calls functions in external shared objects (.so), and you want to
know if the .so's are updated, if your perl program will still work?
Is that what you want to know?
Well it should, as long as your perl software calls the function in the
shared library, and doesn't compile it into a binary and call it
locally, then it should all be sweet. Yeah, as long as it calls it
from the external object....
I'm fairly certain DynaLoader can do this....
Just off topic a little, have you tried linking shared and static
libraries in the same object, and running it via perl? This is my
issue at the moment...
Cheers!
H.
In article <3A805B39.B113676@yahoo.com>,
"Jeffry A. Nokes" <jeff_nokes@yahoo.com> wrote:
> Thanks for the response. I've actually thought of doing that, but
> basically, I'm making platform specific executable applications using
> perl2exe. I'm trying to find a way to just update shared object
files and
> thus update my application. I'm also trying to use the same code for
all
> platforms. I'm writing the exe's in Perl and the shared libraries in
GNU
> C. I've looked at Dynaloader, and from what I've read, I don't think
this
> will do the trick. Also, I'm looking at the new FFI (Foreign Function
> Interface) module, but it's too new and there is barely in
documentation on
> it, that I can find anyway. Would you happen to know if the Perl 6
effort
> is tackling these issues?
>
> jimjim123@my-deja.com wrote:
>
> > My advice is read the perlxs man pages.... There are tutorials
around
> > which show you how to include C functions in your PERL code. In
fact,
> > I have a problem with this right now, but no-one answered my message
> > about it :-(
> >
> > In article <3A7F9E04.1F238A77@yahoo.com>,
> > "Jeffry A. Nokes" <jeff_nokes@yahoo.com> wrote:
> > > Greetings,
> > > I was wondering if anyone new of a way to call functions from
a ".so"
> > > file in Linux/Unix from a Perl script? I currently use Perl on
Win32
> > > and call functions from DLLs using Win32::API. Is there an
equivalent
> > > Perl module I can use to call functions from the Linux/Unix
> > > environments? Or even better, a single Perl module that will work
> > bothe
> > > with DLLs in Win32, and .so files in Linux/Unix? This would save
me a
> > > lot of time.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 07 Feb 2001 05:49:48 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Logfile pattern search & print
Message-Id: <0m5g6.1397$561.9468@eagle.america.net>
On Wed, 07 Feb 2001 01:34:52 GMT, mgrime@my-deja.com
<mgrime@my-deja.com> wrote:
>
>I have a log file where the first field is a date followed by the time
>and finally followed by some details like this:
>
>06Feb01 15:49:33 [6] OK:exec sendfsock
>
>Is there someone who would give me a hand with some simple code to
>search for a pattern (preferably the whole line) and print that line and
>all the following lines? Is there maybe a one-liner?
perl -ne 'next unless /06Feb01/../$^/;print'
--
Garry Williams
------------------------------
Date: Wed, 07 Feb 2001 05:08:44 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Mysql and Perl multiple insert?
Message-Id: <wL4g6.1383$561.8162@eagle.america.net>
On Tue, 06 Feb 2001 19:55:14 GMT, vivekvp <vivekvp@spliced.com> wrote:
>
>I am trying to insert data from form to an sql database.
>The syntax for an insert with mysql is INSERT INTO <table>
>(field1),field2),(field3) VALUES (data1,data2,data3)
No, it isn't.
>I have split all the table names and values then done the below: but
>it only inserts the first value. I suspect the all the data is not
>going across from the $names portion. ^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What does that mean?
>foreach $pair (@pairs)
>{
What's in @pairs?
> ($name, $value) = split(/=/, $pair);
> print"<br> name: $name, value: $value \n";
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> if ($FORM{$name} eq "") { $value eq "0"; }
Oh, this is a CGI script.
You should read about the CGI module in its manual page.
You should use the CGI module (or its cousins) to parse forms instead
of doing it yourself.
> $row=$dbh->do("INSERT INTO wwinfo ($name) VALUES ($value)")||
> die "Error on insert : $DBI::errstr";
You don't show the DBI->connect(). But you claim that one row was
inserted by this statement, so I guess the connect() method was
successful. Have you examined the Web server's error log to see if
this statement ever failed?
What's in @pairs?
Aside from problems with unquoted values in $value or maybe newlines
in $name or $value, this looks okay. (See $dbh->quote() in the DBI
manual page.) You should probably consider preparing the statement
and binding your values when you call execute() so that quoting isn't
a factor.
What does the table definition look like for wwinfo? Are required
column values missing? Were they defined with a default value?
What's in @pairs?
--
Garry Williams
------------------------------
Date: Wed, 7 Feb 2001 08:39:51 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Need Help Checking IP Address Syntax w/ PERL?
Message-Id: <slrn9822en.2uq.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 6 Feb 2001 18:20:29 +0100, Rudolf Polzer <rpolzer@web.de> wrote:
>webbgroup <webbgroup@my-deja.com> schrieb Folgendes:
>> I am writing a script right now that is asking for an IP address.
>> It needs to check the syntax with limiting it to a valid IP address.
>> Obviously the end user should be able to put in any three numbers, but
>> not > 256 for each octect.
>>
>> Does anybody know a simpler way of doing it than the following?
>>
>> unless (($ip2add =~ [0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9].[0-
>> 9][0-9][0-9]) || ($ipadd =~ [0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9]
>> [0-9].[0-9][0-9]) || (ip2add =~ [0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-
>> 9].[0-9][0-9][0-9]) || ($ip2add =~ [0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]
>> [0-9].[0-9][0-9][0-9]))
>
>Does this even work? The slashes or m operators are missing.
>
>my @nums = split /./, $ip;
Are you sure that's the expression you want to split on, oh Master of
JAPHs?
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Wed, 07 Feb 2001 08:48:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Need Help Checking IP Address Syntax w/ PERL?
Message-Id: <jp228t8bpo9ui3j82a6osvi4pgdj16nm27@4ax.com>
webbgroup wrote:
>> You don't even seem to think that "127.0.0.1" is a valid IP address.
>
>My test isn't going to test the loopback address.
Oh. One of the addresses my ISP provides, is [66.33.17.191].
I fail to see your reason for accepting less than 14% of all possible IP
addresses. ((156/256)**4 == 0.1378).
--
Bart.
------------------------------
Date: Wed, 07 Feb 2001 06:14:47 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: newbie - grep non-used uid from passwd
Message-Id: <3A80E8E6.A9FE45F3@acm.org>
"Richard J. Rauenzahn" wrote:
>
> "John W. Krahn" <krahnj@acm.org> writes:
> >
> >#!/usr/bin/perl -w
> >use strict;
> >
> >my $uid;
> >my %hash;
> >
> >while ( ( undef, undef, $uid ) = getpwent() ) {
> > if ( $uid >= 100 && $uid <= 999 ) {
> > $hash{ $uid } = 1;
> > }
> > }
> >
> >my @keys = sort {$a <=> $b} keys %hash;
> >
> >for ( $keys[0] .. $keys[-1] ) {
> > unless ( exists $hash{ $_ } ) {
> > print "$_\n";
> > last;
> > }
> > }
>
> You have a minor bug -- you will report no number if there isn't a hole
> between $keys[0] and $keys[-1].
>
> One way to fix it...
>
> push(@keys, $keys[-1]+1) if($keys[-1] < 999);
>
> After you perform the sort.
Yeah, I was thinking about that and came up with:
for ( $keys[0] .. $keys[-1] + 1 ) {
unless ( exists $hash{ $_ } ) {
print "$_\n";
last;
}
}
John
------------------------------
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 V10 Issue 229
**************************************