[7517] in Perl-Users-Digest
Perl-Users Digest, Issue: 1143 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 8 07:07:07 1997
Date: Wed, 8 Oct 97 04:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 8 Oct 1997 Volume: 8 Number: 1143
Today's topics:
"19971008" and (....)(..) Koos_Pol@nl.compuware.com
Re: "19971008" and (....)(..) (Casper K. Clausen)
Re: "19971008" and (....)(..) (Lars Gregersen (c908239))
Re: $x = $y || $z - dangerous assumption? (Tony Bass)
Building on HPUX with shared libperl.sl (Keith Willis)
Re: Filehandle to file name? <seay@absyss.fr>
Re: Help wanted, building perl5.004_01 on unixware (Mike Heins)
I NEED AN EXPERT ON CGIpm; PROBLEM STATED HEREIN <ctw@vt.edu>
Re: I NEED AN EXPERT ON CGIpm; PROBLEM STATED HEREIN <ghowland@hotlava.com>
Lost output ? <sorenmp@iname.com>
Re: map in void context (was Re: $x = $y || $z - danger <seay@absyss.fr>
Memory usage of 30Meg scalars? <ghowland@hotlava.com>
Net:FTP Binary file transfer question. (Mike S)
Re: Passing Parameters from an HTML!! <sorenmp@iname.com>
Re: Perl and WINNT4.0 <jerry_hicks@bigfoot.com>
Re: Pro's and Cons - Sub's from Sub's? <seay@absyss.fr>
Re: Reading Excel <jerry_hicks@bigfoot.com>
Re: Sorting values such as 1.1, 1.1.1, 2.1 into order - <tony.mcdonald@ncl.ac.uk>
Re: Turning a formated string into a list <eike.grote@theo.phy.uni-bayreuth.de>
void map bad form? (was: Re: $x = $y || $z - dangerous (Tom Grydeland)
Re: Wanted: Wall/Schwartz book (1st ed) <jerry_hicks@bigfoot.com>
Weird Hash w/ n-dimensional two-dimensional array !!!!! <dan@corp.airmedia.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Oct 1997 08:17:56 GMT
From: Koos_Pol@nl.compuware.com
Subject: "19971008" and (....)(..)
Message-Id: <61ffjk$p75@news.nl.compuware.com>
($year,$month) = ("19971008" =~ (....)(..))
Why doesn't this return $year and $month? Instead, it returns the empty
string. But I have a match on the first two, don't I?
Koos Pol
--------------------------------------------------------------------------
S.C. Pol tel: +31 20 3116122
PC Systems Administrator email: Koos_Pol@nl.compuware.com
Compuware Europe PGP public key available upon request
A little inaccuracy sometimes saves tons of explanation.
-- H. H. Munroe
------------------------------
Date: 08 Oct 1997 10:39:17 +0200
From: ckc@dmi.min.dk (Casper K. Clausen)
Subject: Re: "19971008" and (....)(..)
Message-Id: <wvpsouc4pje.fsf@hobbes.dmi.min.dk>
"Koos" == Koos Pol <Koos_Pol@nl.compuware.com> writes:
Koos> ($year,$month) = ("19971008" =~ (....)(..)) Why doesn't this
Koos> return $year and $month? Instead, it returns the empty
Koos> string. But I have a match on the first two, don't I?
First of all, you forgot something important, namely slashes:
"19971008" =~ /(....)(..)/
However, your matches are assigned to $1 and
$2, not returned as values. What you want is probably something along
the lines of:
"19971008" =~ /(....)(..).*/ and ($year,$month) = ($1,$2);
Get ahold of the Camel Book and read it, it'll save you a lot of grief.
Regards,
Kvan.
--
-------Casper Kvan Clausen------ | 'Ah, Warmark, everything that passes
----------<ckc@dmi.dk>---------- | unattempted is impossible.'
Lokal 544 |
Mobil: 2127 0889 | - Lord Mhoram, Son of Variol.
------------------------------
Date: 8 Oct 1997 10:50:03 GMT
From: matlg@bohr.gbar.dtu.dk (Lars Gregersen (c908239))
Subject: Re: "19971008" and (....)(..)
Message-Id: <61fogr$e4j$1@news.uni-c.dk>
Casper K. Clausen (ckc@dmi.min.dk) wrote:
: "Koos" == Koos Pol <Koos_Pol@nl.compuware.com> writes:
: Koos> ($year,$month) = ("19971008" =~ (....)(..)) Why doesn't this
: Koos> return $year and $month? Instead, it returns the empty
: Koos> string. But I have a match on the first two, don't I?
It can't return much since it doesn't parse, but I take it that the line
was written from memory and was not the result of a cut'n'paste
: First of all, you forgot something important, namely slashes:
: "19971008" =~ /(....)(..)/
exactly! and a ; at the end
: However, your matches are assigned to $1 and
: $2
that they are too
: , not returned as values.
wrong! they are if you tell them to
: What you want is probably something along
: the lines of:
: "19971008" =~ /(....)(..).*/ and ($year,$month) = ($1,$2);
This will work but so will this
($year,$month) = ("19971008" =~ /(....)(..)/);
I hope this helps!
-------------------------------------------
Lars Gregersen
Department of Chemical Engineering
Technical University of Denmark
E-mail: lg@kt.dtu.dk
Homepage: http://www.gbar.dtu.dk/~matlg/
------------------------------
Date: 8 Oct 1997 10:02:45 +0100
From: aeb@brains.cartoon.bt.co.uk (Tony Bass)
Subject: Re: $x = $y || $z - dangerous assumption?
Message-Id: <61fi7l$7sm$1@brains.cartoon.bt.co.uk>
>From article <61e5bh$a82$1@towncrier.cc.monash.edu.au>, by damian@cs.monash.edu.au (Damian Conway):
> Randal Schwartz <merlyn@stonehenge.com> writes:
>>Damian> sub first_defined { map { return $_ if defined $_ } @_ }
>>Ewwwww. My eyes hurt. map/grep in a void context is Bad Form,
> Looks like you can take the programmer out of the functional paradigm,
> but you can't take the functional paradigm out of the programmer :-)
> For future reference, could you expand a little on _why_ that
> particular solution is inappropriate?
>>especially when this one could have been done by foreach so much easier:
>> sub first_defined { for (@_) { return $_ if defined $_; } }
> Well, no argument that this is more straight-forward from an imperative
> view-point. I'm guessing that it's probably slightly more efficient too?
In the particular example, the context is not necessarily void, so the
two may behave differently. Specifically, the result returned by a
call of first_defined with no defined argument is () for the first and
who knows what for the second.
Note also that the behaviour of map in void context is undocumented in
second camel and 5.001. The behaviour of grep in void context is
well-defined.
In one measurement some time ago I found for(;;) smallest and fastest,
then foreach() larger and slower, then void grep same size and slightly
slower, then void map largest and slowest. I am curious about another
poster's report of void map faster, and would be interested to see
details.
Tony Bass
--
# A E Bass Tel: (01473) 645305
# MLB 3/19, BT Laboratories e-mail: aeb@saltfarm.bt.co.uk
# Martlesham Heath, Ipswich, Suffolk, IP5 7RE DO NOT e-mail to From: line
# Opinions are my own
------------------------------
Date: Tue, 7 Oct 1997 16:03:30 GMT
From: keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com (Keith Willis)
Subject: Building on HPUX with shared libperl.sl
Message-Id: <34455837.1316220334@news>
I have had quite some difficulty building perl (5.004_03) under HPUX
10.20 using gcc. Basically, I wanted to produce a shared libperl.sl
instead of a static libperl.a. By answering the prompts on the
Configure script and adding the run-time search stuff to the link
options, I got an executable which refused point blank to look for the
library anywhere other than where it was at link-time. In other
words, perl coredumped when it was run after the source tree was
removed, as that was where it insisted on looking for the library.
The 'chatr' utility showed perl as:
perl:
shared executable
shared library dynamic path search:
SHLIB_PATH enabled second
embedded path enabled first
:/usr/local/lib:/usr/local/lib/perl5/PA-RISC1.1/5.00403/CORE:/usr/local/lib/gcc
-lib/hppa1.1-hp-hpux10.20/2.7.2.3:/usr/local/lib
internal name:
perl
shared library list:
static /disk7/perl-5.004.03/libperl.sl
dynamic /usr/lib/libnsl_s.1
dynamic /usr/lib/libdbm.1
dynamic /usr/lib/libdld.1
dynamic /usr/lib/libM.1
dynamic /usr/lib/libc.1
shared library binding:
deferred
static branch prediction disabled
data page size: 4K
instruction page size: 4K
It was that 'static' that was the killer - it overrides the search
along the embedded path. In the end, I had to hack the Makefile so
that instead of hardcoding the 'libperl.sl' on the link line, to put a
'-lperl' onto the libs list and a -L with the blah/blah/CORE location
in there instead.
I then had to copy libperl.sl out to the blah/blah/CORE location and
chmod it to 755 (because mmap refused to map the damned thing at run
time if it just had perms of 0444), then do a 'make clean' followed by
a 'make' so that the newly copyied version got linked to the
executables (phew!). I now have a perl which chatr shows as:
perl:
shared executable
shared library dynamic path search:
SHLIB_PATH enabled second
embedded path enabled first
:/usr/local/lib:/usr/local/lib/perl5/PA-RISC1.1/5.00403/CORE:/usr/local/lib/gcc
-lib/hppa1.1-hp-hpux10.20/2.7.2.3:/usr/local/lib
internal name:
perl
shared library list:
dynamic /usr/local/lib/perl5/PA-RISC1.1/5.00403/CORE/libperl.sl
dynamic /usr/lib/libnsl_s.1
dynamic /usr/lib/libdbm.1
dynamic /usr/lib/libdld.1
dynamic /usr/lib/libM.1
dynamic /usr/lib/libc.1
shared library binding:
deferred
static branch prediction disabled
data page size: 4K
instruction page size: 4K
And now it finally works as required. Anyway, the thrust of this
tirade is to enquire of the cognocenti whether there is some other,
simpler, less hassle-prone way of achieving the same thing for next
time I have to do this :)
----------------------------------------------------------------------
The above message reflects my own views, not those of Hewlett Packard.
When emailing me, please note that there is no '.junk' in my address.
------------------------------
Date: Wed, 08 Oct 1997 11:38:10 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Filehandle to file name?
Message-Id: <343B5482.E9929EB@absyss.fr>
Bart Lateur wrote:
>
> Actually: two. PC and Mac. Deleting or renaming a file that is open just
> fails.
>
> Since Perl programmers OUGHT to make their code platform independent
> ;-), at least they should be aware of the fact that they can't do all
> tricks on all platforms.
Hey, my code runs on Linux, Solaris, HP-UX and AIX. How much more
platform independant can I get and still have a platform worth using :-)
- doug
------------------------------
Date: 8 Oct 1997 07:15:21 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: Help wanted, building perl5.004_01 on unixware
Message-Id: <61fbu9$kat$1@vixen.cso.uiuc.edu>
anon (anon@symserve.prestel.co.uk) wrote:
: Hi,
: Can anyone help me with the error I am getting when attempting to
: build perl 5.004_01 on a unixware 2.03 machine.
: I get through to the stage where the Fcntl module builds and then get the
: errors shown below.
:
Aha! Have you tried the changes in the hints/svr4 directory, in
particular this one:
# libmalloc.a - Probably using Perl's malloc() anyway.
# libucb.a - Remove it if you have problems ld'ing. We include it because
# it is needed for ODBM_File and NDBM_File extensions.
if [ -r /usr/ucblib/libucb.a ]; then # If using BSD-compat. library:
d_gconvert='undef' # Unusuable under UnixWare 1.1 [use gcvt() instead]
# Use the "native" counterparts, not the BSD emulation stuff:
d_bcmp='undef' d_bcopy='undef' d_bzero='undef' d_safebcpy='undef'
d_index='undef' d_killpg='undef' d_getprior='undef' d_setprior='undef'
d_setlinebuf='undef' d_setregid='undef' d_setreuid='undef'
fi
Try removing libucb.a temporarily. Make perl, understanding that
you may error out in NDBM_File and ODBM_File (you should get GDBM first
anyway).
Also, have you tried using "./Configure -Dcc=gcc" if you have
the GCC compiler?
Regards,
Mike Heins
------------------------------
Date: Wed, 08 Oct 1997 02:40:29 -0700
From: Coyt Taylor Wilson <ctw@vt.edu>
Subject: I NEED AN EXPERT ON CGIpm; PROBLEM STATED HEREIN
Message-Id: <343B550D.25B2@vt.edu>
CGIpm is supposed to work on Linux because it was developed on Linux.
Well, it's bombing out for no explicable reason.
This is the error that shows up in my error_log:
Can't find string terminator "END_OF_AUTOLOAD" anywhere before EOF at
/xpr/jxv/httprdex/cgi-bin/clank/cgipm/CGI.pm line 645.
The scripts I'm using were written by the author of CGIpm and I've
done exactly what he said to do. I'm using the same scripts he uses at
his demo site. CGIpm is executing fine, but failing in the middle
of its activity before getting past line 7 (use CGI;) in my tryit script.
What's going on?
My man perlvar command says $^O is supported, and when I try
perl -e 'print $^O;' on the prompt, I get
linux
so that's not the problem. $^O is supported.
What else could be the problem? I don't know enough Perl
nor have the time to debug this thing. That's supposed to be the
author's job isn't it?
Jeeze.
------------------------------
Date: Wed, 08 Oct 1997 09:01:55 +0100
From: Gary Howland <ghowland@hotlava.com>
To: Coyt Taylor Wilson <ctw@vt.edu>
Subject: Re: I NEED AN EXPERT ON CGIpm; PROBLEM STATED HEREIN
Message-Id: <343B3DF3.2193@hotlava.com>
Coyt Taylor Wilson wrote:
>
> CGIpm is supposed to work on Linux because it was developed on Linux.
> Well, it's bombing out for no explicable reason.
>
> This is the error that shows up in my error_log:
>
> Can't find string terminator "END_OF_AUTOLOAD" anywhere before EOF at
> /xpr/jxv/httprdex/cgi-bin/clank/cgipm/CGI.pm line 645.
Sounds like you ahve a corrupt CGI.pm. Try re-installing.
Gary
--
pub 1024/C001D00D 1996/01/22 Gary Howland <gary@hotlava.com>
Key fingerprint = 0C FB 60 61 4D 3B 24 7D 1C 89 1D BE 1F EE 09 06
------------------------------
Date: Wed, 8 Oct 1997 09:51:24 +0200
From: "Soren M. Pedersen" <sorenmp@iname.com>
Subject: Lost output ?
Message-Id: <343b39b2.0@news.euroconnect.dk>
I try to run a perl script, as a CGI interface from at internet browser. The
script calling a NT .exe file. The .EXE file display some output, and the
perl script just formats commandline parameters for the exe file.
My problem is to redirect the .exe's output to back to the browser .
My Code:
print "Content-Type: text/html\n\n";
print "<HTML><BODY>Result is<HR>\n";
...
exec "NT_UTIL.EXE -options name data ";
..
print "<HR></BODY></HTML>\n";
Suggestions welcome.
regards
Soren M. Pedersen.
------------------------------
Date: Wed, 08 Oct 1997 11:25:11 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: map in void context (was Re: $x = $y || $z - dangerous assumption?)
Message-Id: <343B5177.21648B2F@absyss.fr>
Abigail wrote:
>
> Oh come on. Do you object to the "There are more ways to do it" slogan
> of perl?
Good Lord, no. The flexibility of Perl is part of the reason why I like
the language. But just because the langauge offers a lot of tools
doesn't mean that you shouldn't try pick the right tool for the job. We
are not argueing which tools can be used (obviously), but the more
subtle distinction of which one should be used.
If you want to use grep as a list iterator, go ahead. Knock yourself
out. Do it how ever you want. I'm not gonna stop you, but I will
support the programming style that I prefer.
> splice () returns a list too, do you always use it? chop and chomp
> return characters, do you always use them? s/// returns something too,
> do you always use that? It doesn't make sense to say that it is
> a misuse not to use the return value of map, while not having a
> problem ignoring the return value of many other functions.
Have you ever worked with a functional language (ie LISP)? I don't have
too much experience with 'em and I can't say that I like 'em, but one of
the things I do like is the idea that functions compute something and
don't have side effects. In my mind I make a big difference between
functions/operators/doohickies that change something and those that
compute something. Since most everything in Perl returns something, the
difference becomes "does it have side effects?". print() is called
because of its side effect. pack() doesn't have any side effects, it
just returns a computed value. Big difference. splice() is
destructive, you cannot avoid its side effect. While I may take
advantage of its return value (after all, that is why it is there), I
don't call it for that.
As for push/pop, they are optimized convience functions, nothing more.
In C I sometimes make macros for common cases of complicated functions,
same thing here.
> If map/grep were designed to do things without side effects, then
> why is $_ an *alias* for the current list element?
> C<@foo = map {$_ = 1;} @bar;> *changes* @bar, even while you are
> using the return value of map.
Speed. I think that the aliasing stuff is faster than copying
variables. Isn't that why sort uses $a and $b? Terry Michael Fletcher
posted that he has benchmarked map as being faster than foreach. I
would understand taking advantage of this for time critical blocks, but
since it is harder to read (IMHO), I don't like it for the general case.
General question: why is map faster than for? Is it just for some
cases, but for others for is faster? Is there something intrinsic about
the map that is easier to optimize? Is it because the iterating
variable is a local, not an alias?
- doug
------------------------------
Date: Wed, 08 Oct 1997 09:13:38 +0100
From: Gary Howland <ghowland@hotlava.com>
Subject: Memory usage of 30Meg scalars?
Message-Id: <343B40B2.7499@hotlava.com>
Hi,
I'm trying to use Perl for a backup system, and am reading the contents
of files into scalars. If the sizes of my files are anything up to 30
megs, is it unreasonable to assume that this is the cause of my perl
process growing to 121 megs?
Is this perhaps due to perl having three or four copies of my 30 meg
scalar?
And if this is normal behaviour, how can I improve the efficiency,
perhaps by preventing these extra copies? Would the use of references
help?
Or is my only solution to not read the whole file into a scalar? If so,
are there any modules out there that will copy the contents of one file
handle to another?
Many thanks in advance,
Gary
--
pub 1024/C001D00D 1996/01/22 Gary Howland <gary@hotlava.com>
Key fingerprint = 0C FB 60 61 4D 3B 24 7D 1C 89 1D BE 1F EE 09 06
------------------------------
Date: Wed, 08 Oct 1997 02:28:38 -0500
From: mshavel@erols.com (Mike S)
Subject: Net:FTP Binary file transfer question.
Message-Id: <mshavel-ya02408000R0810970228380001@news.erols.com>
Hi
I have gotten Net::FTP to work very well except for one thing.
I can't seem to transfer the files in binary mode.
I tried $ftp->type("binary") to no avail.
Anyone know how to do this? Thanks very much for the advice.
Mike
mshavel@erols.com
------------------------------
Date: Wed, 8 Oct 1997 10:58:39 +0200
From: "Soren M. Pedersen" <sorenmp@iname.com>
Subject: Re: Passing Parameters from an HTML!!
Message-Id: <343b4975.0@news.euroconnect.dk>
Ok - Here is a simple solution:
You need a small 2x2 transparent GIF file.
----HTML PART ------------------
<html>
<body>
.....
<img src="/cgi/world/register/register.pl?PageID=1234">
</body>
</html>
-------PERL PART--------------
print "Content-Type: text/html\n\n";
open(IMG,"world/register/NoImage.gif");
while (<IMG>)
{
print $_;
}
close(IMG);
# Save user ID and date in the logfile
$remote = $ENV{REMOTE_ADDR};
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
open(LOG, ">>register.log");
print LOG "$year-$mon-$mday,$hour:$min,$remote,$ENV{QUERY_STRING};\n";
close(LOG);
}
---------------------------------------
Hope this is the stuff you are looking for.
Regards
Soren M. Pedersen
sorenmp@iname.com
Billy Messemore wrote in message <343ad8ba.9653622@news.netdoor.com>...
>Hello Everyone,
>
> I have written a perl script the need a parameter to work. I
>do not wish to use a form. Because the parameter is unique to each
>page and the user does not need to enter it.
>
> Is there a way to execute a perl script with out using a
>button/form. I wish to have the script execute automaticly when an
>HTML page is load.
>
> I have tried the <!--#exec cgi="test.cgi"-->, but I could not
>figure out how to pass the parameters to the CGI.
>
> I would like to thank you in avdance for you help.
>
>Thanks,,
>
>Billy Messemore
>messemor@netdoor.com
>
------------------------------
Date: Wed, 08 Oct 1997 01:59:55 +0000
From: Jerry Hicks <jerry_hicks@bigfoot.com>
Subject: Re: Perl and WINNT4.0
Message-Id: <343AE91B.2E4DE6CB@bigfoot.com>
Tom C. gave the 21 days book a thumbs-down. According to his book
review, it was rife with errors.
------------------------------
Date: Wed, 08 Oct 1997 12:26:04 +0200
From: Doug Seay <seay@absyss.fr>
To: webmaster@proliferate.com
Subject: Re: Pro's and Cons - Sub's from Sub's?
Message-Id: <343B5FBC.3FC2AC05@absyss.fr>
[posted and mailed]
webmaster@proliferate.com wrote:
>
> Hello,
>
> I was wondering if anyone could point out the hazards of calling a
> subroutine from within another subroutine. Are there any drawbacks or
> other hazzards I should be aware of. I would greatly appriciate your
> thoughts on the matter. If you could E-mail me with your opinions I
> would
> be very grateful. I am running WIN32 PERL port.
No problems here. I have multi-level subroutine calls all the time.
There are some rules about passing @_ as a default parameter list. In
"perlsub" it says
To call subroutines:
NAME(LIST); # & is optional with parentheses.
NAME LIST; # Parentheses optional if
predeclared/imported.
&NAME; # Passes current @_ to subroutine.
so this could be a bit of a problem. Could this be what you've seen?
- doug
PS - I don't use Windoze, so I don't know if that port is buggy.
------------------------------
Date: Wed, 08 Oct 1997 01:21:05 +0000
From: Jerry Hicks <jerry_hicks@bigfoot.com>
Subject: Re: Reading Excel
Message-Id: <343AE001.C171FE55@bigfoot.com>
> On Wed, 1 Oct 1997 dsstevens@ingrDOT.com wrote:
>
> I am looking for the code to open existing MS Excel files and read the
> specific cells.
The OLE automation module (Win32 only) is your friend. Better get the
Office SDK though...
Good Luck,
Jerry Hicks.
jerry_hicks@bigfoot.com
------------------------------
Date: Wed, 08 Oct 1997 07:36:57 +0100
From: Tony McDonald <tony.mcdonald@ncl.ac.uk>
Subject: Re: Sorting values such as 1.1, 1.1.1, 2.1 into order - Many Thanks!
Message-Id: <tony.mcdonald-ya023080000810970736570001@news.ncl.ac.uk>
Hi all,
As the original poster of this question I'd like to say a big thank you to
all the people who took the trouble to write/debug and post code.
I'm using two different versions of code posted here and they are both
working well.
Thanks again
Tone
ps I've learnt *quite a bit* about Perl sorting watching these replies... :)
-----------------------------------------------
Tony.McDonald@newcastle.ac.uk, DESIRE trainer, Newt user
Dr Tony McDonald.,Computing Service,Newcastle University. Newcastle Upon
Tyne, NE1 7RU.
http://www.netskills.ac.uk/staff/mcdonald/ - Macs, News, Metadata...
------------------------------
Date: Mon, 06 Oct 1997 09:05:30 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: Turning a formated string into a list
Message-Id: <34388DBA.446B@theo.phy.uni-bayreuth.de>
Hi,
James Weisberg wrote:
>
> I have a fairly simple question. I would like to write a function
> which takes a string of the form: MMDDYYhhmm.ext and returns a
> list of each component. For example:
>
> $file="0903971430.txt"
>
> ($MM, $DD, $YY, $hh, $mm, $ext) = filetolist($file);
>
> Can someone show me how to write this function in Perl?
If the fields have always the same length you could use "unpack()"
(see 'perlfunc' manual page):
($MM, $DD, $YY, $hh, $mm, $ext) = unpack('a2a2a2a2a2a4',$file);
Bye, Eike
--
======================================================================
Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
e-mail -> eike.grote@theo.phy.uni-bayreuth.de
WWW -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html
http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================
------------------------------
Date: 8 Oct 1997 10:49:05 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: void map bad form? (was: Re: $x = $y || $z - dangerous assumption?)
Message-Id: <slrn63mp91.oqb.Tom.Grydeland@mitra.phys.uit.no>
On Tue, 7 Oct 1997 20:41:49 -0500,
Tad McClellan <tadmc@flash.net> wrote:
> Perl FAQ, part 6:
>
> ---------------------------------------------
> =head2 What's wrong with using grep or map in a void context?
>
> Strictly speaking, nothing. Stylistically speaking, it's not a good
> way to write maintainable code. That's because you're using these
> constructs not for their return values but rather for their
> side-effects, and side-effects can be mystifying. There's no void
> grep() that's not better written as a C<for> (well, C<foreach>,
> technically) loop.
> ---------------------------------------------
In this particular case, I'd agree in the case of grep, but I'd disagree
when it comes to map. Ever since I discovered map, I've used it for
more and more cases. Sometimes it has sideeffects, sometimes not.
grep has (to me) the sound of something selecting some of many, and
*should* use the return value, and avoid sideeffects.
map (to me) doesn't imply that. However reluctant I am about using map
for *both* its sideeffects and its return value, I'll freely use it for
one or the other.
Feel free to consider it bad style. I won't.
> Tad McClellan SGML Consulting
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: Wed, 08 Oct 1997 01:39:27 +0000
From: Jerry Hicks <jerry_hicks@bigfoot.com>
Subject: Re: Wanted: Wall/Schwartz book (1st ed)
Message-Id: <343AE44F.F0DE2D4B@bigfoot.com>
Bart Lateur wrote:
>
> Doug Seay <seay@absyss.fr> wrote:
>
> >But for me, the reason I like pefer the first camel is the tone. To me,
> Now, let's all join hands, and try to keep Randal out of prison for
> doing something that can hardly be considered to be a crime, shall we?
>
> Bart.
Woefully, the way I understand things, that's been firmly decided. Bro'
Schwartz could still use the bucks though...
A 'deadicated' Intel boycotter,
Jerry Hicks
jerry_hicks@bigfoot.com
------------------------------
Date: Wed, 8 Oct 1997 03:12:07 -0400
From: "Daniel Delgado" <dan@corp.airmedia.com>
Subject: Weird Hash w/ n-dimensional two-dimensional array !!!!!!
Message-Id: <61fbrm$3uj$1@client3.news.psi.net>
TO ALL:
First off, let me apologize for this code. I am a c++ (Win-MFC mainly
(sorry)) - Due to need, I am helping in writing an installer for a large
project for a major company. I am not sure of "disclosure" so I keep
putting in "xxx" and the like to "hide" names. (>>sorry<<). I have never
before 2 days ago written in Perl (much less tried to program under UNIX - I
am doing the code in CodeWrite in Win and saving to a Samba drive, I don't
know VI very well at all).
I am trying to learn as I go - so there are awkward constructs galore! - I
also get an idea and then try too look up in the two O'Reilly books how to
do it (Therefore I THINK very un-Perl-like and try to fit square peg in
round hole at times.) I am only up to page 70 in the "Learning" book. So
again, I'm sorry.
The section of code works so far (actually I haven't looked at not
allowing duplicate 1st array vals in the hash, the "name" - but I'm sure I
did a tiny flub, I had it working in a previous incarnation before I ran
into my major prob!!!!!)
The PROB:
I have a hash of questions to ask the user. Look at the first lines for
an example of ONE question (for this module there will be 10 or so). The
two "y" vals are whether the answer should be verified (necessitating a hard
link between question included and the verification code. And whether the
question is asked until the user hits enter on a blank line.
The reading of questions and enforcing of two answers works.
Finally, I need to construct an object, It will contain a Key value
(the ini variable key, so to speak, and the list of answers (in this case a
name and pw).
So I envisioned:
%somehash = ( theKey => [ [answer1Name, answer1pwd], [answer2Name,
answer2pwd], ... [answerNName, answerNpwd]] );
(if I "manually were to create it...)
AFTER MUCH playing/reading - I got that to be assigned/created properly and
tested thru prints. BBBBUUUUUTTTTTT , I can't seem to find out some way of
iterating thru this construct (so-called) to "list" all values. I can do so
only (as you'll see some of the "debug" prints I did) do so if I loop on the
Keys and assum that the last array indices are "0" & "1" (I can "live" with
that assumption) But, I can find no way to detect how many, for a given hash
key, answers there are - Will I have to check until the values are "" (I
don't even know if Perl guarantees that an unassigned array index will be so
(though, now as I say it, I think I read that...)).
P L E A S E HELP! - I am going on vacation Fri, and I need the skeleton
of one of these done, so I can spread out the work and continue (on paper)
while I vacation overseas.
AS SOON as anyone can clue me in - please do => Again I am not even
consisten in including scalars in "Value is $something" print statements,
what hope do I have?
Thanks o' Perl-Community-at-large,
Dan Delgado
EMAIL: dan@corp.airmedia.com (please...)
P.S. => WOW, anyone ?read? this far... (it's late - I got to be in in 4
hours, I ramble...)
THE "CODE":
>I include this from a file:
%XXX_questions =
(
XXXXX => ["y", "y", "Please type in the names and passwords the XXXXXXX
modules will use to log into the XXXXXX.\n(Format: <XXXXNAME> <XXXXX
password>)\n"]
);
#!/usr/bin/perl
# REMOVED
# REMOVED
#
# NOTE: Validation routine requires updating of this file if the
XXX_questions.inc changes.
#
if ($no_questions = $ARGV[0] =~ /noquestions/i)
{
require '.XXXX_installrc';
}
else
{
require 'XXXX_questions.inc';
%answers = ();
}
unless ($noquestions)
{
while (($key, $question_info) = each %XXX_questions)
{
$question = $XXX_questions{$key}[2];
$multiple = $XXX_questions{$key}[1];
$check = $XXX_questions{$key}[0];
# Loop at least once or until a blank line is entered if it is a
# multiple answer question
for ($index = 0; ($index == 0) || ($multiple eq "y") ; $index++)
{ print $question;
chomp( $input = <STDIN> );
@answer = split(/\s+/, $input);
# Entering an empty line will
end the loop
if ($#answer > -1) # if empty
{
if ( $check eq "y" )
{
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if ( check_answer(\$key, \@answer ) )
{
$answers{$key}[$index] = [@answer];
}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
else
{
$answers{$key}[$index] = [@answer];
}
}
else
{
last;
}
}
}
}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
foreach $key (keys(%answers))
{
for($i; $i <= @$answers{$key}; $i++)
{
@hope = $answers{$key};
print "Number of items: $hope[0] or" . $hope;
#print "\n" . $answers{$key};
print "\n\n";
print "\nNum: " . $answers{$key};
print "XXX" . $answers{$key}[0][0];
print "XXX" . $answers{$key}[0][1];
print "\nNum: " . $answers{$key};
print "XXX" . $answers{$key}[1][0];
print "XXX" . $answers{$key}[1][1];
print "\nNum: " . $answers{$key};
print "XXX" . $answers{$key}[2][0];
print "XXX" . $answers{$key}[2][1];
}
}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sub check_answer
{
local (*key, *answer) = @_;
local ($input);
@answer_keys = keys(%answers);
if ($key eq "XXXXX")
{
# Global %answers
while ( $#answer != 1) # (2 items)
{
print "\nPlease re-enter values (Format: <XXXXXNAME> <XXXXX
password>)\n";
chomp ( $input = <STDIN> );
@answer = split(/\s+/, $input);
}
# Should we allow only a difference in the case or append 'i' to regexp?
if (@keys =~ /$key/)
{
if ( get_yn('Warning Duplicate XXXXX name: Do you wish to replace the old
value? (y/n) ') )
{
# Replace XXXX's password value
return 1;
}
else
{
# Keep old password value
return 0;
}
}
return 1;
}
}
#
# Get_yn() returns 1 for a "y" or "yes" (irregardless of case)
#
sub get_yn()
{
print $_[0];
chomp( $_ = <STDIN> );
return ( /y|yes/ );
}
------------------------------
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 1143
**************************************