[8211] in Perl-Users-Digest
Perl-Users Digest, Issue: 1829 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 7 13:07:13 1998
Date: Sat, 7 Feb 98 10:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 7 Feb 1998 Volume: 8 Number: 1829
Today's topics:
Re: Anyone built Perl 5.004 on BSDi 3.1? (Ned Schumann)
ASP and PerlScript <mikew@mailhost.uni-koblenz.de>
Re: Book review wanted <camerond@mail.uca.edu>
change ctime [creation time] of a file to any time? (Michael Wang)
Re: change ctime [creation time] of a file to any time? <doug@tc.net>
cmp CONUNDRUM <NOSPAMkEynOn@panix.comNOSPAM>
Re: Find ^M in file (Gabor)
Generating customer ID (Mark666769)
Re: Global variable names <tchrist@mox.perl.com>
Re: How to sort data from a file (Michael Wang)
Re: How to use libnet (Clay Irving)
Re: Is Perl 5 year 2000 compliant? <msa@micronexus.net>
Re: New member guide?? <beans@bedford.net>
Re: Newbie with Perl 32 on NT workstation (Johnny Fingers.)
Re: pattern with a star in it (Jeff Stampes)
Re: Perl - Oracle Interface (Michael Ward)
Re: Perl 4 and Associative Arrays? (Don)
Re: perl and file system (Michael Wang)
Re: Perl and SunOS 5.5.1 <xxTony.Curtis@vcpc.univie.ac.at>
Re: Perl Getpwent under Solaris 2.X problems <xxTony.Curtis@vcpc.univie.ac.at>
read out a certain content of a file <jahnel@xarch.tu-graz.ac.at>
Re: returning the date (Clay Irving)
Re: returning the date <tchrist@mox.perl.com>
Re: returning the date <ajohnson@gpu.srv.ualberta.ca>
Sharing variables between scripts (Brian M. Beaulieu)
Re: sorting hash by numeric values (Gabor)
Re: Tie-Dee-Perl (Cleanliness is next to Goodliness, or (Jeff Stampes)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 07 Feb 1998 08:15:55 -0800
From: ned@olympus.net (Ned Schumann)
Subject: Re: Anyone built Perl 5.004 on BSDi 3.1?
Message-Id: <ned-0702980815550001@pine.olympus.net>
In article <MPG.f45e63794bf28cc98968d@news-server>, rusty@san.rr.com
(Russell C. Jackson) wrote:
> I am getting a compile error stating that some of the arguments in a
> function call are incompatible in doio.c. Does anyone know how to get
> Perl 5.004 to compile on BSDi 3.1?
>
> Please copy me in email if you respond so that I get the response
> immediately.
Here's Vivek Khera's post in www.nexial.nl Use patch -l < fileNameOfPatch
Don't forget the '-l' to take care of the spaces....
Regards,
Ned Schumann
--- hints/bsdos.sh.dist Wed Sep 10 09:34:42 1997
+++ hints/bsdos.sh Tue Nov 4 12:04:58 1997
@@ -3,7 +3,7 @@
# hints file for BSD/OS (adapted from bsd386.sh)
# Original by Neil Bowers <neilb@khoros.unm.edu>; Tue Oct 4 12:01:34 EDT 1994
# Updated by Tony Sanders <sanders@bsdi.com>; Sat Aug 23 12:47:45 MDT 1997
-# Added 3.1 with ELF dynamic libraries
+# Added 4.0 with ELF dynamic libraries
# SYSV IPC tested Ok so I re-enabled.
#
# To override the compiler on the command line:
@@ -69,7 +69,7 @@
'') cc='gcc2' ;;
esac
;;
-2.0*|2.1*|3.0*)
+2.0*|2.1*|3.0*|3.1*)
so='o'
# default to GCC 2.X w/shared libraries
@@ -88,14 +88,14 @@
libswanted="Xpm Xaw Xmu Xt SM ICE Xext X11 $libswanted"
libswanted="rpc curses termcap $libswanted"
;;
-3.1*)
- # ELF dynamic link libraries starting in 3.1
+4.0*)
+ # ELF dynamic link libraries starting in 4.0
useshrplib='true'
so='so'
dlext='so'
case "$cc" in
- '') cc='cc' # cc is gcc2 in 3.1
+ '') cc='cc' # cc is gcc2 in 4.0
cccdlflags="-fPIC"
ccdlflags=" " ;;
esac
v.
--
------------------------------
Date: Sat, 07 Feb 1998 12:56:27 +0100
From: Mike Weiss <mikew@mailhost.uni-koblenz.de>
Subject: ASP and PerlScript
Message-Id: <34DC4BEB.3153@mailhost.uni-koblenz.de>
HI !
I'm using perlScript with ASP, MS-SQL-Server and IIS 4.0 for building an
Intranet-Application. My problem: an ASP-Script written in VBScript for
updating a database works fine (ODBC-Connection is OK). A PerlScript,
which uses the same ODBC-Connection crashes with error 80004005, because
it cannot open the ODBC-Connection. The user-rights and the ODBC are OK.
Whats the big difference between using the ADODB-Connection via VBScript
and via Perl-Script. Who can help me ??
Thanx, Mike
--
--------------------------------------------------------------------
Mike Weiss - In der Lueck 14 - 56073 Koblenz - Germany
+49-02606-1857
eMail: mikew@informatik.uni-koblenz.de
Scall: 9449198@Scall.de (nur Subject fuellen)
------------------------------
Date: Sat, 07 Feb 1998 07:30:16 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
To: Jacqui Caren <Jacqui.Caren@ig.co.uk>
Subject: Re: Book review wanted
Message-Id: <34DC61E8.78BE1FFE@mail.uca.edu>
Jacqui Caren wrote:
>
> [1] perhaps its time to visibly contribute something to the PRP :-)
>
> Jacqui
>
> [1] - this is a joke, for anyone who finds themselves humour
> impaired...
Humor accepted, appreciated. But for the relatively new (read: clueless)
to several of the acronyms here (read: me), what is PRP? perl [R]
porters?
TIA
Cameron
camerond@mail.uca.edu
------------------------------
Date: 7 Feb 1998 15:53:54 GMT
From: mwang@alhena.ibk.ml.com (Michael Wang)
Subject: change ctime [creation time] of a file to any time?
Message-Id: <6bi02i$q2m$1@news.ml.com>
In article <m3sopvkfuh.fsf@lorien.ajs.com>, Aaron Sherman <ajs@ajs.com> wrote:
>
>Under my copy of Linux (2.0.33) and a Solaris 2.5 system that I have
>access to, touch DOES update the ctime.
I check both Solaris touch and GNU touch, none of them update ctime.
The following is GNU touch usage:
touch [-acfm] [-r file] [-t MMDDhhmm[[CC]YY][.ss]] [-d time]
[ - -time={atime,access,use,mtime,modify}] [--date=time] [--
reference=file] [--no-create] [--help] [--version] file...
ctime is not there. I assume that you can not change ctime to any
time.
You can change system time and then use chmod, but that is not acceptable.
------------------------------
Date: 07 Feb 1998 12:46:34 -0500
From: Douglas McNaught <doug@tc.net>
Subject: Re: change ctime [creation time] of a file to any time?
Message-Id: <m24t2bnw91.fsf@ono.tc.net>
mwang@alhena.ibk.ml.com (Michael Wang) writes:
> In article <m3sopvkfuh.fsf@lorien.ajs.com>, Aaron Sherman <ajs@ajs.com> wrote:
> >
> >Under my copy of Linux (2.0.33) and a Solaris 2.5 system that I have
> >access to, touch DOES update the ctime.
>
> I check both Solaris touch and GNU touch, none of them update ctime.
> The following is GNU touch usage:
> You can change system time and then use chmod, but that is not acceptable.
Just a note for those who are misled by the Subject: line: ctime is
*not* the creation time of the file. It's the "inode change" time,
updated by the system when the information in the file's inode
(permissions, ownership etc) is modified. As you note, it can't be
changed by the user. Why would you want to?
-Doug
--
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";
------------------------------
Date: 7 Feb 1998 17:01:17 GMT
From: k y n n <NOSPAMkEynOn@panix.comNOSPAM>
Subject: cmp CONUNDRUM
Message-Id: <6bi40t$6q7@news1.panix.com>
Keywords: cmp
Is there any value that I can give to $x such that, for all $y != $x,
the expression $x cmp $y is *less* than 0?
Thanks,
K.
--
To reply directly by e-mail, remove the upper-case letters from the
return address in the header.
------------------------------
Date: 7 Feb 1998 13:50:45 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Find ^M in file
Message-Id: <slrn6dopfr.l3f.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, SJL <perl@nospam.larson4.demon.co.uk> wrote :
# On 28 Jan 1998 21:50:31 GMT, Tom Christiansen <tchrist@mox.perl.com>
# wrote:
#
# >I can't imagine a slower approach, even if it were right. Here's a tip:
# >doing things a byte at a time in perl is much much much more often wrong
# >than it is right.
#
# Can you expand a bit on this? Specifically, if I'm using perl to read
# from a binary data file (such as a PCM sampled .wav file) should
# I do buffered reading rather than a byte-at-a-time? (or should I not
# be using perl to manipulate such files?). Once upon a time I suppose
# it was more efficient to do buffered i/o in C but I think nowadays
# it's safe to assume the compiler is doing it for you. From your
# statement, I take it that it is not safe to assume the same of perl?
Well it depends. If you use sysread in perl you get C's write
primitive which will actually read a byte at a time, if you use read
in perl then you don't have to worry because although you get one byte
at a time the I/O is actually buffered.
gabor.
--
There is, however, a strange, musty smell in the air that reminds me of
something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
-- Larry Wall in Configure from the perl distribution
------------------------------
Date: 7 Feb 1998 14:12:53 GMT
From: mark666769@aol.com (Mark666769)
Subject: Generating customer ID
Message-Id: <19980207141200.JAA10600@ladder03.news.aol.com>
Hi,
Can anyone point me to some sample Perl code
that can generate a unique Customer ID value
suitable for a cookie?
The value generated should be guaranteed unique,
yet also be readable by the users and not total
gibberish.
Thanks in advance.
------------------------------
Date: 7 Feb 1998 15:33:25 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Global variable names
Message-Id: <6bhus5$fnu$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Aaron Sherman <ajs@ajs.com> writes:
:return(\@array, \%hash, \$scalar);
Which could also be written:
return \(@array, %hash, $scalar);
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
There are many times when you want it to ignore the rest of the string just
like atof() does. Oddly enough, Perl calls atof(). How convenient. :-)
--Larry Wall in <1991Jun24.231628.14446@jpl-devvax.jpl.nasa.gov>
------------------------------
Date: 7 Feb 1998 15:41:58 GMT
From: mwang@alhena.ibk.ml.com (Michael Wang)
Subject: Re: How to sort data from a file
Message-Id: <6bhvc6$q26$1@news.ml.com>
>In comp.lang.perl.misc, davidh@wwwpromote.com writes:
>:I need some help sorting the contents of a file by a certain field on
>:each line.
The following is from "man sort":
+POS1 [-POS2]
Specify a field within each line to use as a sorting
key. The field consists of the portion of the line
starting at POS1 and up to (but not including) POS2 (or
to the end of the line if POS2 is not given). The
fields and character positions are numbered starting
with 0.
-k POS1[,POS2]
An alternate syntax for specifying sorting keys. The
fields and character positions are numbered starting
with 1.
------------------------------
Date: 7 Feb 1998 10:02:48 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: How to use libnet
Message-Id: <6bht2o$e8c@panix.com>
In <34DB57E2.723362A6@concentric.net> Vic Hargrave <hargrave@concentric.net> writes:
>I'm getting started with using Perl for network programming. I have been
>using the Socket library for doing the basics. Now I would like to use the
>libnet for FTP and other high level protocols. I have two questions in this
>regard:
>1. How do you include libnet in your program to use its facilites?
> In other words what do you put in the "use" statment, e.g.
> "use Socket", to get libnet loaded?
Most of the man pages are available at:
http://reference.perl.com/query.cgi?net
>2. Is libnet supported within the Perl for Win32 environment?
Gurusamy Sarathy's distribution of Perl does -- It includes:
perl5.004_02
dmake-4.1
Alias-2.3
Bit-Vector-4.2
Curses-1.01 [*]
Data-Dumper-2.07
DateCalc-3.2
DateManip-5.10
DBD-ODBC-0.16
DBI-0.89
Devel-Peek-0.83
Devel-Symdump-2.00
DProf-19970614 [*]
GD-1.14 [*]
libnet-1.0505 [*]
libwin32-0.08
libwww-perl-5.11
MD5-1.7
MIME-Base64-2.03
MLDBM-1.23
Storable-0.5 [*]
String-Approx-2.1
Tk402.002
NOTES:
[*] These packages needed porting or other fixes to compile and
run properly. All changes are included in the form of patches
(the kind that can be applied using the GNU patch utility) in
the `patches' subdirectory. The full sources of all of
these packages (with the exception of dmake, see below for that)
can be found on the Comprehensive Perl Archive Network (CPAN).
Point your web browser at "http://www.perl.com/CPAN" to find the
CPAN site nearest you.
Available at:
http://www.perl.com/CPAN/ports/win32/Standard/x86/
--
Clay Irving <clay@panix.com> I think, therefore I am. I think?
http://www.panix.com/~clay/
------------------------------
Date: Sat, 7 Feb 1998 23:29:04 +1100
From: "Scott Kane - MSA" <msa@micronexus.net>
Subject: Re: Is Perl 5 year 2000 compliant?
Message-Id: <6bho80$lvj$1@news.eaa.com.au>
Actually Borland are out doing Microsoft in this presently.
Scott
>Gary L. Smith wrote in message ...
>Tiberius (Abraxas@hell.com) wrote:
>
>: Well, exactly what *isn't* in the documentation? Of course it's in the
>: documentation. Virtually everything is. If only questions that had no
>: answers in the docs were posted in the newsgroups, there'd be like,
>: what, 2 questions a day?
>
>Have you ever used a Microsoft product? A good deal of what's worth
>knowing is not in any documentation, and when it is there, you often
>can't find it. Responding to a question with "look in the documentation
>under strange-term-you'd-never-come-up-with-on-your-own" can be
>trememdously helpful.
>
>--
>
>Gary L. Smith gls@infinet.com
>Columbus, Ohio Gary_Smith@oclc.org
------------------------------
Date: 7 Feb 98 13:14:53 GMT
From: "TomH" <beans@bedford.net>
Subject: Re: New member guide??
Message-Id: <01bd310c$b311d1e0$1a9163ce@beans.bedford.net>
http://www.perl.org
http://www.perl.com
Both have links.
Scott Norris <snorris@post.cis.smu.edu> wrote in article
<6bfrt0$pto$1@hermes.seas.smu.edu>...
> I have heard various references to "THE Perl FAQ" and "the form you were
> sent after your first posting". However, I recently reformatted, and lost
> that message, which I assume contains links to help references. Would it
be
> possible to get another copy of this message?
>
> Thanks,
> scott norris
>
>
>
------------------------------
Date: Sat, 07 Feb 1998 15:02:13 GMT
From: wyldkard@total.net (Johnny Fingers.)
Subject: Re: Newbie with Perl 32 on NT workstation
Message-Id: <MPG.f4641bdb6a28a14989683@news.videotron.ca>
In article <886795093.3541.0.nnrp-11.9e98f6f2@news.demon.co.uk>,
ed@infodial.demon.co.uk says...
> I just recently inherited an NT Workstation PC with Perl 32 installed on it.
>
> Could anyone please give me pointers on how to get started. For example,
> where is the Perl interpreter installed?
> Do I need to modify the registry? Example scripts would also be helpful.
>
>
>
Hey
If it's the Wins32 version from CPAN, then you merely put a shortcut to
the perl interpreter in EVERY diretory where you develope perl code. NOw
I don't knwo if htere is a fix for this, BUT when I put it in my path, it
didn't work, I had to use the multiple shortcut option, Then drop the
prog on the shortcut and voila, instant interpretation.
Try searching "CPAN" in a search engine, and you'll find a million
resources for perl.
(Interpreter is usually in c:\program files\perl\bin)
--
--------------------------------
J.Fingers - wyldkard@total.net
--------------------------------
------------------------------
Date: 7 Feb 1998 15:06:37 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: pattern with a star in it
Message-Id: <6bht9t$g4m$1@neocad.com>
Sylvain Juneau (sjuneau@microtec.net) wrote:
: I have another file. I open that file and I want to search in it:
: A700*P then *P then *C.
All on one line? In separate places in the file? Makes a
difference.
: My question is how do I search through this file using a wildcard?
Well you'll want to learn perls regular expressions for the
pattern matching (see man perlre), and you'll also need to
know how to open and iterate through a file. For this you'll
probably just need the open() and close() commands, and an
understanding of the <FILEHANDLE> construct.
In other words something like:
open IN, $file or die "Couldn't open: $!";
while (<IN>) {
print if (/A700*P*C/);
}
close IN;
Consult the wealth of information available at www.perl.com for
the latest version of perl and the thousands of pages of free
documentation that comes with it for more details.
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Sat, 07 Feb 1998 09:45:45 -0800
From: mward@veelos.com (Michael Ward)
Subject: Re: Perl - Oracle Interface
Message-Id: <mward-ya023580000702980945450001@news.slip.net>
Oraperl/DBI is the better way to go, but they require that PRO-C libraries
be available on your host. If PRO-C is not available and sqlplus is, this
will work (don't expect great performance):
#!/usr/local/bin/perl
$child = open(CHILD, "-|");
if ($child == 0) {
$CMD2 = "| $ENV{'ORACLE_HOME'}/bin/sqlplus -SILENT me/pass\@mydb";
open(SQL, $CMD2);
select(SQL); $| = 1;
select(STDOUT); $| = 1;
print (SQL "set AUTOCOMMIT OFF", "\n");
print (SQL "set TERMOUT OFF", "\n");
print (SQL "set FEEDBACK OFF", "\n");
print (SQL "set HEADING OFF", "\n");
print (SQL "set LINESIZE 200", "\n");
print(SQL "select * from sometable;\n");
print (SQL "exit\n");
}
while (<CHILD>) {
print;
}
exit;
--
Michael Ward
mward@veelos.com
------------------------------
Date: Sat, 07 Feb 1998 16:52:25 GMT
From: defike@ilstu.edu..spam.not (Don)
Subject: Re: Perl 4 and Associative Arrays?
Message-Id: <34dc90f3.5335580@news.ice.net>
On Sat, 07 Feb 1998 00:35:57 -0500, Chipmunk <rjk@coos.dartmouth.edu>
wrote:
I like the approach you describe below. It seems more concise. I
hope it works. I will give it a try.
Thanks,
Don
>BTW, you don't actually need to check if the key exists or the value is true.
>Just do $urls{$url_from}++; The first time, it will increment 0, giving you
>a value of 1, just as you'd expect.
>
>Chipmunk
------------------------------
Date: 7 Feb 1998 16:20:41 GMT
From: mwang@alhena.ibk.ml.com (Michael Wang)
Subject: Re: perl and file system
Message-Id: <6bi1kp$q3g$1@news.ml.com>
Tom Christiansen <tchrist@mox.perl.com> wrote:
>:Well, I should have said how determine the TYPE of fs
>:(i.e ufs jfs tmpfs nfs ...) with a PERL command, that works on nearly
>:all Un*x systems
>
> $ mount | grep fs | perl -pe 's/.+type\s+(\S+).*/$1/'
Or on solaris with GNU df:
[julie:/tmp]df -P -T
Filesystem Type 1024-blocks Used Available Capacity Mounted on
/dev/dsk/c0d0s0 ufs 43762 12337 27055 31% /
/dev/dsk/c0d0s6 ufs 241567 195936 21481 90% /usr
...
And I would assume that GNU df would generate the same output on any
other Unixes. So the portability is achieved through df.c which is
achieved through the use of ifdef's.
>Today is the day that the world forgets the toolbox.
That is because of Perl. People now think Perl is toolbox of all
toolboxes. I think it is a big advantage of ksh that it does not
distinguage internal commands and external commands. And I think
there is nothing wrong using system(mkdir -p) versus using File::Path,
do you think so? Thanks.
------------------------------
Date: 07 Feb 1998 16:38:14 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
To: bill@inta.demon.co.uk
Subject: Re: Perl and SunOS 5.5.1
Message-Id: <7x67mrh1cp.fsf@beavis.vcpc.univie.ac.at>
Re: Perl and SunOS 5.5.1, Bill <bill@inta.demon.co.uk> said:
Bill> No such signal SIGQUIT, SIGINT, SIGHUP etc. These are
Bill> obviously correct signals. The signal handler does not
Bill> therefore get called.
The keys to the %SIG hash don't have the "SIG" in the name.
e.g.
sub single_to_station { ... }
$SIG{BUS} = 'single_to_station';
Is that it?
hth,
tony
------------------------------
Date: 07 Feb 1998 17:31:56 +0100
From: Remove xx to reply <xxTony.Curtis@vcpc.univie.ac.at>
Subject: Re: Perl Getpwent under Solaris 2.X problems
Message-Id: <7x1zxfgyv7.fsf@beavis.vcpc.univie.ac.at>
Re: Perl Getpwent under Solaris 2.X problems, James
<jdehnert@fiberlane.com> said:
James> Im running Perl 5.003 under Sun Solaris 2.5.2 & 2.6.
James> I'm not able to get getpwent to read its info from
James> the NIS+ tables. It will get info from the system
James> /etc/passwd file, but this isn't what I need!
James> getgrent ( on the other hand ) seems to work
James> fine...
What does /etc/nsswitch.conf say?
hth,
tony
------------------------------
Date: Sat, 07 Feb 1998 15:55:30 +0100
From: Jahnel Klaus <jahnel@xarch.tu-graz.ac.at>
Subject: read out a certain content of a file
Message-Id: <34DC75E2.73528D16@xarch.tu-graz.ac.at>
how can i read out a content of an html file
which is between these tags and save them in an string or what ever?
<table> .......CONTENT .......</table>
TIA
Klaus
------------------------------
Date: 7 Feb 1998 09:35:42 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: returning the date
Message-Id: <6bhrfu$d2u@panix.com>
In <6bgsv0$71v$1@news.cc.ucf.edu> "Scully" <scully@barimens.com> writes:
>I have been searching through perl books looking for an example use of the
>localtime function similar to what I need, but I haven't been able to find
>one.
>Can anybody tell me what perl code I'd need to include in my script to print
>the date to an open file in the format mm/dd/yy ?
#!/usr/local/bin/perl -w
$date = localtime;
print "$date\n";
outputs:
Sat Feb 7 09:19:29 1998
Let's look at what localtime does -- The localtime function actually accepts
an expression of time in number of seconds since January 1 1970 (commonly
refered to as "the Epoch") and returns time in a list or scalar context.
For example:
#!/usr/local/bin/perl -w
$date = localtime(860000000);
print "$date\n";
returns in scalar context:
Wed Apr 2 11:53:20 1997
Conveniently, one of the other built-in Perl functions is time. It returns
the number of non-leap seconds since January 1 1970. This program:
#!/usr/local/bin/perl -w
$seconds_since_epoch = time;
print "$seconds_since_epoch\n";
outputs:
886861265
Put time and localtime together, and you have a method to get the current
date and time:
#!/usr/local/bin/perl -w
$date = localtime(time);
If no arguement is given to localtime, time is the default. So, you commonly
see just: $date = localtime;
The localtime function also returns time in a list context. For example:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
The elements returned in list context are:
$sec Seconds
$min Minutes
$hour Hour
$mday Day of the month
$mon Month number, starting with 0 (Jan = 0, Aug = 7)
$year Year with 1900 subtracted from it (2002 = 102)
$wday Day of the week (Sun = 0, Sat = 6)
$yday Day of the year
$isdst Is is Daylight Savings Time? (0 or 1)
Don't forget that the $mon has the range 0 through 11 and the $year has
1900 subtracted from it! For example:
#!/usr/local/bin/perl -w
$mon = (localtime)[4]; # Get the 5th element of the localtime array
$year = (localtime)[5]; # Get the 6th element of the localtime array
print "$mon $year\n";
$mon++; # Increment the month by 1
$year = $year + 1900; # Add 1900 to the year;
print "$mon $year\n";
outputs:
1 98
2 1998
Don't be fooled into thinking that localtime has a Year 2000 problem because
you add 1900 to the date! Look how the localtime function interprets the date
four years from now:
#!/usr/local/bin/perl -w
# 4 years x 365 days/year * 24 hours/day * 3600 seconds/hour
$four_years_from_now = 4 * 365 * 24 * 3600;
# Add 4 years worth of seconds to the result of time
$year = (localtime(time + $four_years_from_now))[5];
print "$year years since 1900";
$year = $year + 1900\n; # NEVER "19$year" -- Alway ADD 1900
print "The year is $year\n";
$date = localtime(time + $four_years_from_now);
print "Four years from now is $date\n";
It doesn't have a Year 2000 problem -- The output of the program is:
102 years since 1900
The year is 2002
Four years from now is Wed Feb 6 09:26:23 2002
Now that you have an understanding of date and time under your belt, get
the date in mm/dd/yy format:
#!/usr/local/bin/perl -w
($mm,$yy,$dd) = (localtime)[4,5,6]; # A slice of the list
$mm++; # Increment the month by 1
print "Today is $mm/$dd/$yy\n";
The program outputs:
Today is 2/6/98
--
Clay Irving <clay@panix.com> I think, therefore I am. I think?
http://www.panix.com/~clay/
------------------------------
Date: 7 Feb 1998 15:40:27 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: returning the date
Message-Id: <6bhv9b$fnu$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, clay@panix.com (Clay Irving) writes:
:>Can anybody tell me what perl code I'd need to include in my script to print
:>the date to an open file in the format mm/dd/yy ?
:Don't be fooled into thinking that localtime has a Year 2000 problem because
:you add 1900 to the date!
: ($mm,$yy,$dd) = (localtime)[4,5,6]; # A slice of the list
: $mm++; # Increment the month by 1
: print "Today is $mm/$dd/$yy\n";
:
:The program outputs:
:
: Today is 2/6/98
I don't know which is worse, the fellow who wanted two digit
dates, or Clay for having told him. :-(
First of all, a two-digit date is fundamentally error-prone.
Secondly, in a couple years, the cited code above with
start saying 2/6/102 and such, which is hardly better.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"If Dennis Ritchie were the man who developed Modula-2 then C would be long forgotten."
--Tarjei Jensen
------------------------------
Date: Sat, 07 Feb 1998 10:44:27 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: returning the date
Message-Id: <34DC8F6B.1ED8965E@gpu.srv.ualberta.ca>
Clay Irving wrote:
!
[snip]
! Now that you have an understanding of date and time under your
! belt, get the date in mm/dd/yy format:
!
! #!/usr/local/bin/perl -w
!
! ($mm,$yy,$dd) = (localtime)[4,5,6]; # A slice of the list
! $mm++; # Increment the month by 1
! print "Today is $mm/$dd/$yy\n";
note, (localtime)[6] is the number of the day of the week
from 0-6, while (localtime)[3] is the day of the month. And
as Tom C notes, the year will have problems in the near
future if used as above, so:
($dd,$mon,$yy)=(localtime)[3,4,5];
printf "Today is %02d/%02d/%02d",++$mon,$dd,$yy=~/(\d\d)$/;
but using all four digits in the year,
printf "Today is %02d/%02d/%04d",++$mon,$dd,$yy+1900;
is probably a better way to go.
regards
andrew
------------------------------
Date: 7 Feb 1998 10:57:39 -0600
From: banman@earth.execpc.com (Brian M. Beaulieu)
Subject: Sharing variables between scripts
Message-Id: <6bi3q4$koj@newsops.execpc.com>
I've seen this done before but can't recall how again. All I need to do
is share variables that are located in 1 perl script between other scripts
.. I've tried 'require' .. that didn't seem to do the trick (and I did
give it the relative path to the script with my variables)
Any hints?
Thanks,
Brian
------------------------------
Date: 7 Feb 1998 13:42:49 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: sorting hash by numeric values
Message-Id: <slrn6dop0v.l3f.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, rlindner@avsgroup.com <rlindner@avsgroup.com> wrote :
# Greetings,
#
# I'm trying to output a bunch of keywords and their associated count for a
# log analysis program I'm writing. I've got it working just fine with
# this:
#
# while (($keyword, $count) = each(%keywords))
# {
# print "$count\t$keyword\n";
# }
#
#
# However, I'd love it if I could see the results printed in descending
# order of $count but I am too new to perl to figure out an easy way to
# sort the keywords hash numerically by the values.
@keywords = sort {$keywords{$b} <=> $keywords{$a}} keys %keywords;
for (@keywords) {
print $keywords{$_},"\t",$_,"\n";
}
#
# Could someone help me out with this?
#
# Thanks in advance,
#
# Bob
#
# P.S. - please cc me when you post to the group.
#
# -------------------==== Posted via Deja News ====-----------------------
# http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 7 Feb 1998 15:22:19 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Tie-Dee-Perl (Cleanliness is next to Goodliness, or Perl-White Code)
Message-Id: <6bhu7b$g4m$2@neocad.com>
I R A Aggie (fl_aggie@thepentagon.com) wrote:
: + On 4 Feb 1998, Craig Berry wrote:
: + open NUMBERS, "irrationals.txt" or die "Damn irrationals.txt is big: $!";
: Danger! Danger, Will Robinson! If memory serves (and the perlop manpage
: indicates this is true), the way this is going to be evaluated is like:
: (open NUMBERS), ("irrationals.txt" or die...)
>From perlop:
As more readable alternatives to && and ||, Perl provides ``and'' and
``or'' operators (see below). The short-circuit behavior is
identical. The precedence of ``and'' and ``or'' is much lower, however, so
that you can safely use them after a list operator
without the need for parentheses:
unlink "alpha", "beta", "gamma"
or gripe(), next LINE;
With the C-style operators that would have been written like this:
unlink("alpha", "beta", "gamma")
|| (gripe(), next LINE);
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1829
**************************************