[16542] in Perl-Users-Digest
Perl-Users Digest, Issue: 3954 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 8 18:15:41 2000
Date: Tue, 8 Aug 2000 15:15:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965772928-v9-i3954@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 8 Aug 2000 Volume: 9 Number: 3954
Today's topics:
Parsing name list -- Help! <tramador@fas.harvard.edu>
Re: Parsing name list -- Help! <panderse@us.ibm.com>
Perl DBI question <kj0@mailcity.com>
Re: Perl DBI question <care227@attglobal.net>
Question <mike@accutekcomputers.com>
Re: Question <care227@attglobal.net>
Reg Expression multiple parsing <glchyNOglSPAM@email.com.invalid>
Re: Reg Expression multiple parsing (Greg Bacon)
Re: reg expressions - protect html <lr@hpl.hp.com>
Re: reg expressions - protect html <godzilla@stomp.stomp.tokyo>
Re: reg expressions - protect html <care227@attglobal.net>
Re: reg expressions - protect html <lr@hpl.hp.com>
Re: reg expressions - protect html <lr@hpl.hp.com>
Re: reg expressions - protect html <care227@attglobal.net>
Re: reg expressions - protect html <godzilla@stomp.stomp.tokyo>
Re: regexp - extract substrings (Andrew J. Perrin)
Re: returning error message (daemon)
Re: totally newbie to perl, I ... <bart.lateur@skynet.be>
using stat function <sraatni@NoSPAM.yahoo.com>
Re: using stat function <tony_curtis32@yahoo.com>
What to do with 1A(hex) in a file? <hartmut.wind@t-online.de>
Re: When does it pay to presize an array? (Richard J. Rauenzahn)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Aug 2000 19:16:46 GMT
From: Tarun Ramadorai <tramador@fas.harvard.edu>
Subject: Parsing name list -- Help!
Message-Id: <8mpmau$l9i$1@news.fas.harvard.edu>
Hi,
I'm just learning how to be a perl hacker, and I have the following problem:
I have a list of names, some of which are the same, but mistyped, e.g.
MCDONALD'S
M.CDONALDS
MACDONALDS
etc. etc.
I'm trying to write a Perl script which will parse this sort of list, in such a way that
if any adjacent names on the list differ by N characters or less, then it prints OUT the first one
instead of the misspelled one. For e.g., the above list now looks like:
MCDONALD'S
MCDONALD'S
MCDONALD'S
I've tried converting the comparison strings into lists of letters, sorting the list, and then comparing the resulting sorted
lists, but if one character is different at the beginning of the sorted string, this shifts everything, and the program
screws up. Another thing I tried was to keep the ordering, truncate up to N from the end of each string, and then compare
the resulting strings, but this again doesn't work if the difference lies at the beginning of the string.
Any suggestions will be greatly welcome,
Thanks,
TR
------------------------------
Date: Tue, 08 Aug 2000 15:10:29 -0500
From: "Paul R. Andersen" <panderse@us.ibm.com>
Subject: Re: Parsing name list -- Help!
Message-Id: <39906935.5C6C68A0@us.ibm.com>
Tarun Ramadorai wrote:
>
> Hi,
>
> I'm just learning how to be a perl hacker, and I have the following problem:
>
> I have a list of names, some of which are the same, but mistyped, e.g.
>
> MCDONALD'S
> M.CDONALDS
> MACDONALDS
>
> etc. etc.
>
> I'm trying to write a Perl script which will parse this sort of list, in such a way that
> if any adjacent names on the list differ by N characters or less, then it prints OUT the first one
> instead of the misspelled one. For e.g., the above list now looks like:
>
> MCDONALD'S
> MCDONALD'S
> MCDONALD'S
>
> I've tried converting the comparison strings into lists of letters, sorting the list, and then comparing the resulting sorted
> lists, but if one character is different at the beginning of the sorted string, this shifts everything, and the program
> screws up. Another thing I tried was to keep the ordering, truncate up to N from the end of each string, and then compare
> the resulting strings, but this again doesn't work if the difference lies at the beginning of the string.
>
> Any suggestions will be greatly welcome,
>
> Thanks,
> TR
No suggestion for a cure, but some questions. What will happen when
Andersen is followed by Anderson. Both are correct and only differ by
one letter (the same is true of many names, of course). How do you
determine what to print? For that matter, how did the list get sorted
such that the first occurance of some arbitrary string was determined to
be a correctly spelled name? If you can find that out, your problem
should be solved since someone already did it in effect.
--
Paul Andersen
+++++++++++++
The difference between theory and practice is that in theory there is no
difference between theory and practice; but in practice there is.
------------------------------
Date: 8 Aug 2000 17:22:58 -0400
From: kj0 <kj0@mailcity.com>
Subject: Perl DBI question
Message-Id: <8mptni$h64$1@panix3.panix.com>
I'm learning about the Perl DBI (and about SQL, etc.) as I comb
through some legacy code at my company. My understanding is that the
rationale behind the Perl DBI design is to make database access as
uniform as possible, independent of the type (Oracle, Sybase, etc.) of
database being accessed. But as I go through this code I've noticed
that whenever a Sybase database is being accessed, the connection has
the form
my $dbh = DBI->connect('dbi:Sybase:SYB_DB', $username, $password);
$dbh->do('use some_database');
...
my $sth = $dbh->prepare("SELECT key, field1, field2 " .
"FROM some_table");
whereas when an Oracle database is being accessed, it has the form
my $dbh = DBI->connect('dbi:Oracle:ORA_DB', $username, $password);
...
my $sth = $dbh->prepare("SELECT key, field1, field2 " .
"FROM some_database.some_table");
Thus, in the Sybase case, the connect statement is followed by a "do
statement" specifying some database, and the argument of FROM in the
subsequent SQL query mentions only the name of some table in that
database. In contrast, in the case of Oracle, there is no "do
statement", and the SQL specifies both the database and the table as
the argument to FROM.
I've tried to use the "Sybase method" with an Oracle database, and
viceversa, and both bomb. Is there a way to write the above
in a way that is uniform for both types of databases?
Thanks,
KJ
------------------------------
Date: Tue, 08 Aug 2000 17:23:29 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Perl DBI question
Message-Id: <39907A51.A908C270@attglobal.net>
kj0 wrote:
>
> I'm learning about the Perl DBI (and about SQL, etc.) as I comb
> through some legacy code at my company. My understanding is that the
> rationale behind the Perl DBI design is to make database access as
> uniform as possible, independent of the type (Oracle, Sybase, etc.) of
> database being accessed.
That is correct, concerning DBI, but you also have to use a DBD
portion, which allows connections to specific databases. This is
where syntax may shift and sway, and that is what we see in your
example.
------------------------------
Date: Tue, 08 Aug 2000 19:51:47 GMT
From: "Mike Rembisz" <mike@accutekcomputers.com>
Subject: Question
Message-Id: <nxZj5.15081$c8.4118838@typhoon-news1.southeast.rr.com>
Hi group,
Does anybody know of a forms script which will email an HTML document back
to the person instead of just text? TIA
--
Regards
Mike
WebTek Direct: 336-727-1958
1800 Silas Creek Pky. Corporate: 336-727-1997
Winston Salem, NC USA Fax: 336-727-1998
Email: info@mjrsolutions.com
Website Hosting for $9.95/month! - http://mjrSolutions.com
------------------------------
Date: Tue, 08 Aug 2000 16:07:04 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Question
Message-Id: <39906868.AC098D2B@attglobal.net>
Mike Rembisz wrote:
>
> Hi group,
> Does anybody know of a forms script which will email an HTML document back
> to the person instead of just text? TIA
>
http://www.google.com
As it is, your question is off topic for this group.
------------------------------
Date: Tue, 08 Aug 2000 12:28:20 -0700
From: G <glchyNOglSPAM@email.com.invalid>
Subject: Reg Expression multiple parsing
Message-Id: <06522eaf.1a91ca5e@usw-ex0104-031.remarq.com>
Hi,
i want to parse a file and extract config vars (in upper case).
The vars can actually be $,@,% with '_' in between like
@THIS_IS_A_CFG_VAR or %SIMPLEVAR.
I could extract the first occurence but the /m parameter seems
not to take the single string ($_) and treat it as a multiple
string. Hence in a line like 'something or {the*other}
@THIS_IS_A_CFG_VAR other blah&blah&blah %SECONDVAR continuing
blah', i can only extract @THIS_IS_A_CFG_VAR. How to i get both
@THIS_IS_A_CFG_VAR and %SECONDVAR?
while (<FILE>) {
/([\$|@|%][A-Z]*(_?[A-Z]*)*)/mg;
$a1 = $1;
if ($a1 =~ /[\$|@|%]\S+/) {
print "$a1\n";
}
Thanks,
GC.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Tue, 08 Aug 2000 20:17:27 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Reg Expression multiple parsing
Message-Id: <sp0qmn1s63a82@corp.supernews.com>
In article <06522eaf.1a91ca5e@usw-ex0104-031.remarq.com>,
G <glchyNOglSPAM@email.com.invalid> wrote:
: i want to parse a file and extract config vars (in upper case).
: The vars can actually be $,@,% with '_' in between like
: @THIS_IS_A_CFG_VAR or %SIMPLEVAR.
Do you specify configuration parameters with Perl code? If so, then
use require or do to process the file.
Greg
--
Woody: Hey, Mr. Peterson, there's a cold one waiting for you.
Norm: I know, and if she calls, I'm not here
------------------------------
Date: Tue, 8 Aug 2000 11:25:28 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reg expressions - protect html
Message-Id: <MPG.13f9f0751febb3c398ac4b@nntp.hpl.hp.com>
In article <39902E01.E815F06A@stomp.stomp.tokyo> on Tue, 08 Aug 2000
08:57:53 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> Eli the Bearded wrote:
...
> > Benchmark: timing 1000000 iterations ...
> > WarnStrict: 19 wallclock secs (17.52 usr + 0.36 sys = 17.88 CPU)
> > WarnNoStrict: 18 wallclock secs (16.95 usr + 0.38 sys = 17.33 CPU)
> > NoWarnStrict: 19 wallclock secs (18.11 usr + 0.44 sys = 18.55 CPU)
> > NoWarnNoStrict: 17 wallclock secs (17.00 usr + 0.41 sys = 17.41 CPU)
...
> I've been thinking on this since your posting. Currently
> you show an average ratio of 19:17 for pragma versus
> no pragma usage.
I see nothing of the kind in those data. The left-most number has the
least significance, because elapsed time has high statistical
fluctuations; the resolution of each measurement is 1 second. Look at
the other numbers, then try to justify your generalization from them.
> Clearly use of pragma hints slows down a
> script which implies some memory bloat as well.
Not clear in the first place; not related to memory use in the second
place. Words without substance, as usual.
> However,
> your results don't reflect enough of a difference to
> cause real concern, unless you extrapolate on this.
That is correct -- there should be no real concern about this
nonexistent performance hit. The focus should be on functionality.
<SNIP maunderings about potential measurements>
> It seems to me, with larger more complex scripts, this
> ratio between time factors, pragma versus no pragma,
> could reach 2:1 or, use of pragma could possibly slow
> down a script by a very significant human perceptible
> amount, more than one of my eye blink measurements.
Then how about doing some measurements, instead of talking about them?
Experimental vs. theoretical, remember?
> What really has me curious is use of my declarations
> provides for release of memory blocks once a my variable
> is 'used up' and gone. However, I am wondering if pragma
> checking releases memory it uses to check my variables
> once a my variable is destroyed and memory released.
> Otherwords, does pragma checking release memory it no
> longer needs as my variables are destroyed? I would
> hedge a bet it doesn't. I would bet this pragma memory
> usage is retained and wasted; deadwood.
You have created a memtal model that bears little relationship to
reality.
> This point you have made does imply use of pragma hints
> might be an exceptionally poor choice for larger more
> complex scripts, especially commercial scripts. It does
> appear pragma hints might be very well contributing to
> Perl's reputation for being slow and a memory hog.
How long do you imagine it might take for the program to check whether a
variable is undefined (so it might issue a warning) before proceeding
with a calculation?
> So, advice to always use pragma hints, might be some
> of the worst advice given. I would say removing pragma
> hints from a program as soon as is reasonable, would
> be sound good advice. This would speed up a program
> and reduce memory usage; greater efficiency.
Based on what evidence?
> I've always been suspicious of pragma hints and often
> suggest to not use them. Appears my suspicion just
> might be valid.
Based on no external evidence whatsoever, just your own self-serving
speculation.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 08 Aug 2000 12:08:22 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: reg expressions - protect html
Message-Id: <39905AA6.6961F46C@stomp.stomp.tokyo>
Larry Rosler meekly defends himself:
> Godzilla! intelligently orates
> > Eli the Bearded stirs up a stink:
(Mr. Bearded presents evidence pragma hints slow a program)
(Godzilla draws logical inferences from this evidence)
(lots of snippage of Rosler bruised ego massaging)
> Based on no external evidence whatsoever, just your
> own self-serving speculation.
Hmm... quite a change from yours and Stowe's stance
benchmark is the beat-all master of statistics.
Ha! Had you personally posted these stats to support
one of your notions, you would be singing an entirely
different off-key tune. Scientific evidence, Mr. Rosler,
does not play favorites as your fragile ego would have.
* sticks out her tongue, raspberry noise *
Godzilla!
------------------------------
Date: Tue, 08 Aug 2000 15:41:05 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: reg expressions - protect html
Message-Id: <39906251.D493446F@attglobal.net>
"Godzilla!" wrote:
>
> Larry Rosler meekly defends himself:
>
> > Godzilla! intelligently orates
> > > Eli the Bearded stirs up a stink:
>
> (Mr. Bearded presents evidence pragma hints slow a program)
>
Look at the benchmark results you ignorant twit:
WarnStrict: 19 wallclock secs (17.52 usr + 0.36 sys = 17.88 CPU)
WarnNoStrict: 18 wallclock secs (16.95 usr + 0.38 sys = 17.33 CPU)
NoWarnStrict: 19 wallclock secs (18.11 usr + 0.44 sys = 18.55 CPU)
NoWarnNoStrict: 17 wallclock secs (17.00 usr + 0.41 sys = 17.41 CPU)
As Larry pointed out, and as you ignored, the granularity of the
time marking is 1 second, so we don't really want to focus on that
statistic, now do we? Well, I know you do, but the rest of the
woorld would like to see some statistics that are measured with a
little more precision. Which we have, and which you fail to see.
We have an additional overhead of .47 when looking at the total
CPU time comparing WarnStrict to NoWarnNoStrict. Factor out any
interference caused by other processes munging up the numbers,
and we see that the difference is so slight that considering
it would be foolish, at best.
------------------------------
Date: Tue, 8 Aug 2000 12:56:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reg expressions - protect html
Message-Id: <MPG.13fa05c25cc6fef998ac4c@nntp.hpl.hp.com>
In article <39905AA6.6961F46C@stomp.stomp.tokyo> on Tue, 08 Aug 2000
12:08:22 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> Larry Rosler meekly defends himself:
^^^^^^ Hah!
> > Godzilla! intelligently orates
^^^^^^^^^^^^^ Hah, hah!
> > > Eli the Bearded stirs up a stink:
^^^^^ Hardly!
> (Mr. Bearded presents evidence pragma hints slow a program)
Nothing of the sort. Why don't you quote specifically what data you
think support your assertion, instead of blowing smoke all the time?
> (Godzilla draws logical inferences from this evidence)
Nothing logical, because the data don't support it. Just words, words,
words!
> (lots of snippage of Rosler bruised ego massaging)
Right! I cannot stand the pain of it all.
> > Based on no external evidence whatsoever, just your
> > own self-serving speculation.
>
> Hmm... quite a change from yours and Stowe's stance
> benchmark is the beat-all master of statistics.
Oh, no. The benchmark numbers have been posted, and I accept them. You
choose to blow dust over them without quoting the numbers that support
your assertions.
> Ha! Had you personally posted these stats to support
> one of your notions, you would be singing an entirely
> different off-key tune. Scientific evidence, Mr. Rosler,
> does not play favorites as your fragile ego would have.
Indeed. I accept that the limited set of data shows no significant
correlation between the runtime performance of the code and the use of
'-w' or 'use strict;'. You hide the absence of significance behind
words.
> * sticks out her tongue, raspberry noise *
>
> Godzilla!
I waste my time with you out of a hope that the uninformed who
unfortunately happen upon your posts will not be misled by your
logorrhea. Caveat lector!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 8 Aug 2000 13:03:34 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reg expressions - protect html
Message-Id: <MPG.13fa076db2e4000b98ac4d@nntp.hpl.hp.com>
In article <39906251.D493446F@attglobal.net> on Tue, 08 Aug 2000
15:41:05 -0400, Drew Simonis <care227@attglobal.net> says...
...
> Look at the benchmark results you ignorant twit:
>
> WarnStrict: 19 wallclock secs (17.52 usr + 0.36 sys = 17.88 CPU)
> WarnNoStrict: 18 wallclock secs (16.95 usr + 0.38 sys = 17.33 CPU)
> NoWarnStrict: 19 wallclock secs (18.11 usr + 0.44 sys = 18.55 CPU)
> NoWarnNoStrict: 17 wallclock secs (17.00 usr + 0.41 sys = 17.41 CPU)
>
> As Larry pointed out, and as you ignored, the granularity of the
> time marking is 1 second, so we don't really want to focus on that
> statistic, now do we? Well, I know you do, but the rest of the
> woorld would like to see some statistics that are measured with a
> little more precision. Which we have, and which you fail to see.
>
> We have an additional overhead of .47 when looking at the total
> CPU time comparing WarnStrict to NoWarnNoStrict. Factor out any
> interference caused by other processes munging up the numbers,
> and we see that the difference is so slight that considering
> it would be foolish, at best.
Note that NoWarnStrict is slower than WarnStrict. I don't conclude from
this that '-w' speeds a program up, though. In fact, I find no
sgnificance in this data set at all.
Thanks for responding with specifics. I was beginning to wonder if I
was in a vacuum, the only one in all of Usenet bothering to read and
respond to this blather.
What a waste of electrons this 'ignorant twit' is perpetrating.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 08 Aug 2000 16:15:03 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: reg expressions - protect html
Message-Id: <39906A47.F2EAF9E5@attglobal.net>
Larry Rosler wrote:
>
> Thanks for responding with specifics. I was beginning to wonder if I
> was in a vacuum, the only one in all of Usenet bothering to read and
> respond to this blather.
>
Hopefully its because s/he does no more than clutter kill files at
this point...
------------------------------
Date: Tue, 08 Aug 2000 13:51:38 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: reg expressions - protect html
Message-Id: <399072DA.59BB6CA1@stomp.stomp.tokyo>
Larry Rosler whimpers:
> > Drew Simonis drools:
> > Look at the benchmark results you ignorant twit:
> Thanks for responding with specifics. I was beginning to wonder if I
> was in a vacuum, the only one in all of Usenet bothering to read and
> respond to this blather.
> What a waste of electrons this 'ignorant twit' is perpetrating.
* enjoys an eloquent high society giggle *
Oh rahhhly dahhhling, you boys are simply smashing!
For my next dinner social, I have made a decision to
employ your services to delight my guests with your
humorous entertainment. You rahhhly are quite hilarious!
Bravo! Slapstick at its finest, I am certain.
James.. oh James dahhhling, fetch my day planner please!
Godzilla!
Putting On The Ritz And Glitz
http://la.znet.com/~callgirl3/ritz16.mid
------------------------------
Date: 08 Aug 2000 15:37:04 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: regexp - extract substrings
Message-Id: <ud7jjzgrj.fsf@demog.berkeley.edu>
rgarciasuarez@free.fr (Rafael Garcia-Suarez) writes:
> gregosse2409@my-deja.com wrote in comp.lang.perl.misc:
> >I've a string - on multiple lines (there are \n in the string).
> >
> >Each substring has this structure : first|second|third| (pipe is the
> >separator)
> >
> >I want to extract, one by one, all the substrings in my string...
> >How to do that ?
>
> Use the split function.
> @fields = split /\|/ => $yourstring;
> Read the docs, read the faqs, read the answers to newbies in this
> newsgroup... split is a very common and very useful function in perl
> programs.
>
But, in itself, it doesn't answer the OP's other issue re: the fields
sometimes containing newlines.
Assuming you're reading these records in from a file, the easiest
solution is to set $/ (the input record separator) to whatever does
separate your groups of fields, or to undef if there's nothing
separating them and your file isn't too big. Then, when you do:
$line = <FILE>;
you'll get the whole thing in one string. If you want to keep your
newlines within the fields you get back, just do the split in that
file:
@recs = split(/\|/, $line);
as Rafael suggested. If you want to get rid of the newlines, so (for
example)
first|sec
ond|third
becomes ('first','second','third'), you'll want to do an s/\n//g on
it/them, either before or after you do the split().
Hope this helps.
--
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------
------------------------------
Date: Tue, 08 Aug 2000 20:03:43 GMT
From: daemon@i.am.daemon (daemon)
Subject: Re: returning error message
Message-Id: <slrn8p0psv.jje.daemon@snowcrash.0x68656c6c.net>
>I'm not really sure what you want to do. You don't need to set $!
>because
>
>> unless (open (FILE, $file)) {
>
>will set it when it fails. If you get an error, return something that
>you and the caller have agreed upon to mean 'error' (0, -1, etc), and
>make sure the caller understands that it is to look in $! upon
>failure. This is how open works, and loosely how the *nix C library
>works.
Yeah, but doing it that way is a lot of extra work. I have to define my
own error codes and their meanings. And then, each script which uses this
module has to understand those error codes. So far the easiest way I could
find was to use a global variable to store the error message into, and
just return an undef value so that the calling script knows something
blew up and can simply print that string (and it doesn't have to contain a
lookup table of error codes; only the module has to have this).
I want to be able to set my own error messages rather than use only the $!
since those can sometimes be cryptic for a regular user to interpret.
So instead of having this:
module.pm:
open (FILE, $file) || return (-1);
<more code> || return (-2);
<etc> || return (-3);
script.pl:
$result = DoStuff($blah);
if ($result == -1) { foo; }
elsif ($result == -2) { bar; }
elsif ($result == -3) { argh; }
<more code>
It looks like this:
module.pm:
unless (open (FILE, $file)) {
$Module_errmsg = "can't open $file: $!";
return;
}
unless (<more code>) {
$Module_errmsg = "can't find entry blargh!";
return;
}
unless (<etc>) {
$Module_errmsg = "oops, not again";
return;
}
script.pl:
DoStuff || die "$Module_errmsg\n";
So most of the work only has to be done once (in the module) and the
scripts are simpler. That's the general idea anyway.
--
Citizens, elect Satan in 2000!
------------------------------
Date: Tue, 08 Aug 2000 20:42:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: totally newbie to perl, I ...
Message-Id: <23s0ps8car6d91r37lchid4r4oscsgqppp@4ax.com>
seb wrote:
>If there is no possibility for theses platforms, I also have a box running
>FreeBSD (but I'm also a newbie there, that's why I would prefer Windows
>info).
Perl is installed on every FreeBSD box by default.
The problem will be getting a decent text editor (vi: yuck, emacs: yuck.
Let the flames begin... ;-)
--
Bart.
------------------------------
Date: Tue, 08 Aug 2000 13:26:26 -0700
From: SREENIDHI RAATNI <sraatni@NoSPAM.yahoo.com>
Subject: using stat function
Message-Id: <39906CF2.9914454A@NoSPAM.yahoo.com>
Hi,
I need some help in getting a file's last modified date using the stat
function. stat function returns the last modified date of a file since
epoch in the vatiable $mtime. But I do not know how to convert this
$mtime for eg. 43781762 into a form like Jun 26 2000.
Can anyone help me out.
Thanks,
Sreenidhi.
------------------------------
Date: 08 Aug 2000 16:01:17 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: using stat function
Message-Id: <87aeen31sy.fsf@limey.hpcc.uh.edu>
>> On Tue, 08 Aug 2000 13:26:26 -0700,
>> SREENIDHI RAATNI <sraatni@NoSPAM.yahoo.com> said:
> Hi,
> I need some help in getting a file's last modified date
> using the stat function. stat function returns the last
> modified date of a file since epoch in the vatiable
> $mtime. But I do not know how to convert this $mtime
> for eg. 43781762 into a form like Jun 26 2000.
use strict;
use POSIX 'strftime';
use File::stat;
my $filename = '/etc/passwd'; # or whatever
my $st = stat($filename) or die "Can't stat($filename): $!\n";
my $modstr = strftime('%b %d %Y', localtime($st->mtime));
print "$filename: $modstr\n";
==> perldoc POSIX
perldoc File::stat
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Tue, 08 Aug 2000 22:22:33 +0200
From: Hartmut Wind <hartmut.wind@t-online.de>
Subject: What to do with 1A(hex) in a file?
Message-Id: <8mpq2d$96a$11$1@news.t-online.com>
I get a file from another computer (via ftp in ASCII mode). A perl
script running through all of the
43200 lines to pick up some parts. Sometimes, it happens that only the
first part is processed,
caused by an character, which is 1A(hex). perl assumes that the file is
at the end (remaining
appr. 8000 lines got ignored).
Note: I use 'binmode(IN)' for the input stream, so that 0A(hex), 0D(hex)
is not modified
(Windows Environment)
I'd like to adapt the script to replace 1A by e.g. a space (20(hex)),
but..
how could I read the bytes after the 'last line', which contains the
"abort character" 1A(hex)?
Regards
Hartmut
------------------------------
Date: 8 Aug 2000 19:05:22 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: When does it pay to presize an array?
Message-Id: <965761519.928995@hpvablab.cup.hp.com>
aperrin@demog.berkeley.edu (Andrew J. Perrin) writes:
>nospam@hairball.cup.hp.com (Richard J. Rauenzahn) writes:
>
>[snip]...
>>
>> So, I made the following changes and got *significantly* better results:
>
>> $#array = $size - 1;
>> $#array = -1; # change 1: This 'resets' the array,
>> # but doesn't deallocate the memory.
>
> ^^^^^^^^^
>Is this documented? I couldn't find it on an admittedly cursory glance.
I've read somewhere that the only way to deallocate the memory is use
undef, so I'm assuming that by not using undef, I'm not deallocating the
array's storage.
I might be misremembering, though. Here's an excerpt from perldata:
You can also gain some miniscule measure of efficiency by pre-
extending an array that is going to get big. You can also extend an
array by assigning to an element that is off the end of the array.
You can truncate an array down to nothing by assigning the null list
() to it. The following are equivalent:
@whatever = ();
$#whatever = -1;
According to perlfunc, in description of function 'delete'.
%HASH = (); # completely empty %HASH
undef %HASH; # forget %HASH ever existed
@ARRAY = (); # completely empty @ARRAY
undef @ARRAY; # forget @ARRAY ever existed
>
>> foreach (0..$#array) {
>
>Well, yes, this is faster, but it's not doing the same thing, since $#
>is now -1. When I changed it to
<face color=shades of red>
DOH!
Thanks for catching that -- that code should have never left my machine!
</face>
So, on my system (with the fixed code), presized still takes slightly
longer, even with emptying the array and using push. [Although I have
to wonder if emptying the array is undoing the prealloc]
hairball /tmp>./presizetest.pl
1000 Trials:
Benchmark: timing 1000 iterations of Presized, Pushed...
Presized: 4 secs ( 3.89 usr 0.02 sys = 3.91 cpu)
Pushed: 4 secs ( 3.84 usr 0.00 sys = 3.84 cpu)
---*---
10000 Trials:
Benchmark: timing 1000 iterations of Presized, Pushed...
Presized: 40 secs (39.06 usr 0.03 sys = 39.09 cpu)
Pushed: 40 secs (38.51 usr 0.02 sys = 38.53 cpu)
..and reversing the order of execution doesn't change anything.
Something you might try is lowering the number of trials by an order of
magnitude or two and raising the size of the array by an order of
magnitude or two (and also measure the indexing solution in case
resizing the array to 0 deallocates the storage.)
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3954
**************************************