[9462] in Perl-Users-Digest
Perl-Users Digest, Issue: 3056 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 3 20:07:25 1998
Date: Fri, 3 Jul 98 17:00:28 -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 Fri, 3 Jul 1998 Volume: 8 Number: 3056
Today's topics:
@list problem <nospam@xx.com>
Re: @list problem (Bob Trieger)
Re: @list problem (Josh Kortbein)
ANNOUNCE:: DateTime::Precise 0.03 (Blair Zajac)
Re: capturing STDOUT ouput from a child process <tchrist@mox.perl.com>
Re: Chopping a String (Craig Berry)
Re: Difference between ', `, and " ? <tchrist@mox.perl.com>
Re: Difference between ', `, and " ? <kirks@dialnet.net>
Re: editing a file properly... (Bob Trieger)
Re: editing a file properly... <tchrist@mox.perl.com>
Re: Field Sort without modules? <maierc@chesco.com>
Re: Flames.... <ismkoehlerism@nmism-us.campus.mci.net>
Re: How does one remove ^H metacharacters from STDIN? <tchrist@mox.perl.com>
Re: Invalid regexp in grep (Charles DeRykus)
last modified date <stephen@penna.demon.co.uk>
Re: last modified date (brian d foy)
Re: last modified date <dean@mail.biol.sc.edu>
lib/open3.........open3: open(GLOB(0x80cceec), >&FHOPEN <wcjones@fccj.org>
limits of glob() ? <dtbaker_@flash.net>
Re: MacPerl::Ask (Paul J. Schinder)
Re: MacPerl::Ask (Kevin Reid)
my perl object becomes a HASH when I try to use it. ple (Stephen Riehm)
Re: Pg.pm (Gabor)
Re: problems with creating new directories <tchrist@mox.perl.com>
problems with DBD::empress <goodrob@shaw.wave.ca>
Re: Redirecting output? <tchrist@mox.perl.com>
Skript f|r Veranstaltungskalender <lauchhammer@gmx.net>
Re: The vagaries of read()ing (John Siracusa)
Re: Virtual functions. (Kevin Reid)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 03 Jul 1998 14:54:42 -0700
From: Eric Hilding <nospam@xx.com>
Subject: @list problem
Message-Id: <359D5322.42D5@xx.com>
It's gotta be something simple that I'm tripping over, but can't
seem to find it.
I have a lengthy text file of words and phrases (on separate lines)
that I am trying to read into an @list, sort it alphabetically, and
write the sorted thing out to a new text file with only one word or
phrase per line as with the original.
# START OF PERL SCRIPT
print "Enter File Name To Parse: "; #instructions for entering file name
$filename = <STDIN>; #enter file name to parse
print "Enter Output File Name: "; #instructions for entering
output file name
$pmbfoutfile = <STDIN>; #enter output file name
open (INFILE, "$filename"); #open input file
$totalrecs = 1; #initialize total record count
while ($line = <INFILE>) #primary loop
{
if ($line =~ m/\w+.*/) #line must begin with alpha or numeric
{
$line =~ m/(.*)/; #match the word or phrase
$pmbfwp = $1; #assign word or phrase from $1
$pmbfwp =~ s/^\s+|\s+$//g; #whitespace cleanup on word or phrase
@wplist = $pmbfwp; #assign word or phrase to array list
$totalrecs++; #count the total records
}
}
close (INFILE); #close input file #close the input file
print "Net Records: $totalrecs -1\n"; #print a count of the total
records
@sortedwplist = sort @wplist; #sort the list alphabetically
open (FILE ,">>$pmbfoutfile"); #open output file for append
print FILE "@sortedwplist\n"; #write sorted data to new text file
close (FILE); #close output file
# END OF PERL SCRIPT
Any help is appreciated. Please do NOT e-mail - post to group only.
Tnx.
EH
------------------------------
Date: Fri, 03 Jul 1998 23:35:04 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: @list problem
Message-Id: <6njpv6$4o1$1@strato.ultra.net>
Eric Hilding <nospam@xx.com> wrote:
-> It's gotta be something simple that I'm tripping over, but can't
-> seem to find it.
That is why you should use the `-w' switch. It will show you the errors.
-> I have a lengthy text file of words and phrases (on separate lines)
-> that I am trying to read into an @list, sort it alphabetically, and
-> write the sorted thing out to a new text file with only one word or
-> phrase per line as with the original.
->
-> # START OF PERL SCRIPT
Use a shebang line with the -w switch as the very first line:
#1/usr/bin/perl -w or #!c:/perl/bin/perl -w
-> print "Enter File Name To Parse: "; #instructions for entering file name
-> $filename = <STDIN>; #enter file name to parse
The last character of your variable is now a newline character from when you
hit enter.
Look at the documentation for `chomp' or `chop' to fix this.
-> print "Enter Output File Name: "; #instructions for entering
-> output file name
-> $pmbfoutfile = <STDIN>; #enter output file name
Need chomp or chop here also.
-> open (INFILE, "$filename"); #open input file
You should always check the status of your open.
-> $totalrecs = 1; #initialize total record count
-> while ($line = <INFILE>) #primary loop
-> {
-> if ($line =~ m/\w+.*/) #line must begin with alpha or
-> numeric
-> {
-> $line =~ m/(.*)/; #match the word or phrase
-> $pmbfwp = $1; #assign word or phrase from $1
The 2 lines above as well as the $pmbfwp variable are not needed. You don't
use the $line variable after this point so why not modify it?
-> $pmbfwp =~ s/^\s+|\s+$//g; #whitespace cleanup on word or phrase
You started this loop looking for $line to begin with a word character.
Therefore there is no reason to try and substitute beginning whitespace.
-> @wplist = $pmbfwp; #assign word or phrase to array list
Check out the documentation for the `push' function.
-> $totalrecs++; #count the total records
-> }
-> }
-> close (INFILE); #close input file #close the input file
-> print "Net Records: $totalrecs -1\n"; #print a count of the total
Why subtract 1 from your $totalrecs variable? Just initialize it as 0 instead
of 1.
-> records
-> @sortedwplist = sort @wplist; #sort the list alphabetically
Sorting is quite not that simple, weird things happen.
@sortedwplist = sort { $a cmp $b } @wplist; #this is in the FAQ.
-> open (FILE ,">>$pmbfoutfile"); #open output file for append
Check the status of all opens! I'm not quite sure that you want to be
appending to the outfile instead of writing it anew.
-> print FILE "@sortedwplist\n"; #write sorted data to new text file
You're going to end up with a single space before every line but the first.
don't put the double quotes around the array when you are printing it.
print FILE @sortedwplist,"\n";
I don't know if you need the newline character, you never strip the ones at
the end of the lines.
-> close (FILE); #close output file
-> # END OF PERL SCRIPT
HTH
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
and let the jerk that answers know that his
toll free number was sent as spam. "
------------------------------
Date: 3 Jul 1998 23:39:24 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: @list problem
Message-Id: <6njq3c$580$1@news.iastate.edu>
Eric Hilding (nospam@xx.com) wrote:
: It's gotta be something simple that I'm tripping over, but can't
: seem to find it.
: I have a lengthy text file of words and phrases (on separate lines)
: that I am trying to read into an @list, sort it alphabetically, and
: write the sorted thing out to a new text file with only one word or
: phrase per line as with the original.
: # START OF PERL SCRIPT
: print "Enter File Name To Parse: "; #instructions for entering file name
: $filename = <STDIN>; #enter file name to parse
: print "Enter Output File Name: "; #instructions for entering
: output file name
: $pmbfoutfile = <STDIN>; #enter output file name
: open (INFILE, "$filename"); #open input file
You don't need to put the filename in quotes here.
: $totalrecs = 1; #initialize total record count
: while ($line = <INFILE>) #primary loop
: {
: if ($line =~ m/\w+.*/) #line must begin with alpha or numeric
If you want to match at the beginning of a line, put a carat (^) at
the beginning of the regexp.
Your regexp just grabs lines containing one or more word characters,
anywhere in the line.
: {
: $line =~ m/(.*)/; #match the word or phrase
: $pmbfwp = $1; #assign word or phrase from $1
I'm not sure exactly what you want here, but if you just want the part
before the newline,
chomp;
will handle it for you. (If that's not what you want, then you need something
else here, because that's what your code does.)
: $pmbfwp =~ s/^\s+|\s+$//g; #whitespace cleanup on word or phrase
: @wplist = $pmbfwp; #assign word or phrase to array list
This doesn't do what you seem to want. Try
push(@wplist, $pbmfwp);
Your code nukes the rest of the array every time through, since you're
assigning a scalar to it.
: $totalrecs++; #count the total records
: }
: }
: close (INFILE); #close input file #close the input file
: print "Net Records: $totalrecs -1\n"; #print a count of the total
Variables are interpolated inside doublequoted-strings, but perl expressions
aren't.
Plus, if you had started your total at 0 you wouldn't have to subtract one
from it anyway.
A better idea is to just do something like
$totalrecs = @wplist;
since an array evaluated in a scalar context returns the number of
elements in the array.
: records
: @sortedwplist = sort @wplist; #sort the list alphabetically
: open (FILE ,">>$pmbfoutfile"); #open output file for append
I don't know what you're using your code for, but you might want
to check and make sure appending is what you want to do.
: print FILE "@sortedwplist\n"; #write sorted data to new text file
Above, you say you want one word/phrase per line. This won't give it
to you, since you got rid of the newlines above.
: close (FILE); #close output file
: # END OF PERL SCRIPT
It looks like you really should read through the Camel book some more,
especially the "Gory details" chapter.
A solution of mine I used when figuring out what you were doing follows
below. I don't think it does quite what you wanted, but what you're doing
isn't quite clear.
#!/usr/local/bin/perl5 -w
# Josh Kortbein 7-2-98
# Tested, but not fully
if (($ARGV[0] eq '') || ($ARGV[1] eq '')) {
die "USAGE: perl skank.pl infilename outfilename";
}
# Bad for very large files
open(IN, $ARGV[0]) or die "open $ARGV[0] failed: $!\n";
@data = <IN>;
close(IN);
# From right to left:
# Take only the elements from @data that start with a word char.,
# and possibly some spaces.
# Take those elements, and from those remove all of the beginning
# and ending spaces.
# Sort the result.
@data = sort(grep(s/(^\s+)|(\s+$)//g, (grep(/^\s*\w+/, @data))));
open(OUT, '>' . $ARGV[1]) or die "open $ARGV[1] failed: $!\n";
# I know this is naughty, but I know not why
map {print OUT "$_\n"} @data;
close(OUT);
$num = @data;
print "Got $num records.\n";
__END__
Cheers,
Josh
--
__________________________________________
She had heard all about excluded middles;
they were bad shit, to be avoided.
- Thomas Pynchon
------------------------------
Date: 3 Jul 1998 19:58:36 GMT
From: blair@gobi.gps.caltech.edu (Blair Zajac)
Subject: ANNOUNCE:: DateTime::Precise 0.03
Message-Id: <6njd5c$akl@gap.cco.caltech.edu>
I am pleased to announce the first release of DateTime::Precise 0.03.
>From the README:
This is the DateTime::Precise package. This module provides for the
representation and manipulation of (almost) arbitrary locations in
time including fractional seconds.
DateTime::Precise.pm is not intended to be a replacement for any of
the existing Date:: or Time:: modules, but you may find it useful as a
supplement. Notable features:
* Date and time can include fractional seconds.
* Date is represented internally by an array of year, month, day,
hours, minutes, seconds, and fractional seconds. Using this method,
dates as far back as the start of the Gregorian calendar) can be
used.
* Methods are provided for doing date/time calculations.
Increment and decrement, as well as round, floor and ceil
functions by unit (second through year) are provided, as well as
simple date-difference operations.
* Methods are provided for input from and output to user-specified
formats (dprintf, dscanf, get_time, set_time, strftime).
This module is based on the DateTime module written by Greg Fast
(gdfast@usgs.gov).
REQUIREMENTS
* Perl 5.004_04 or greater.
AVAILABILITY
The latest version of this package is available for download from a CPAN
(Comprehensive Perl Archive Network) site near your at
http://www.perl.com/CPAN/authors/id/B/BZ/BZAJAC/
or from my FTP site:
ftp://ftp.gps.caltech.edu/pub/blair/Perl/
INSTALLATION
In order to use this package you will need Perl version 5.004_04 or
better. Once that is completed, you install DateTime::Precise as you
would install any perl module library, by running these commands:
perl Makefile.PL
make
make test
make install
If you want to install a private copy of this package in some other
directory, then you should try to produce the initial Makefile with
something like this command:
perl Makefile.PL LIB=~/perl
DOCUMENTATION
See the CHANGES file for a list of recent changes. POD style
documentation is included in all modules and scripts. These are
normally converted to manual pages end installed as part of the "make
install" process. You should also be able to use the 'perldoc'
utility to extract documentation from the module files directly.
IMPLEMENTATION
This package is based on the DateTime package written by Greg Fast
<gdfast@usgs.gov>. The _week_of_year routine is based on the
Date_WeekOfYear routine from the Date::DateManip package written by
Sullivan Beck.
Instead of using the string representation used in the original DateTime
package, this package represents the time internally as a seven element
array, where the elements correspond to the year, month, day, hours,
minutes, seconds, and fractional seconds.
AUTHOR, COMMENTS, AND BUGS
I welcome all comments and bug reports. Please email them to
Blair Zajac <blair@gps.caltech.edu>.
--
Dr. Blair Zajac Division of Geological and Planetary Sciences
blair@gps.caltech.edu California Institute of Technology
(626) 583-6729, FAX: 583-7827 252-21, Pasadena, CA 91125
------------------------------
Date: 3 Jul 1998 20:45:23 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: capturing STDOUT ouput from a child process
Message-Id: <6njft3$5vd$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, john.kelly@citicorp.com writes:
:I'm having a problem getting results back from a child process.
:The following script does not have anything returned into @return, the
:messages I get are echoed to STDOUT.
No, they're coming out standard error. How to copy with that
is dealt with in section 8 of the FAQ.
--tom
--
"I do not feel obliged to believe that the same God who endowed us with sense,
reason and intellect has intended us to forgo their use." -- Galileo Galilei
------------------------------
Date: 3 Jul 1998 20:20:51 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Chopping a String
Message-Id: <6njef3$8ve$1@marina.cinenet.net>
Bob Trieger (sowmaster@juicepigs.com) wrote:
: Else @array = split /(.{50})/,$your_string;
Note that will result in empty strings interleaved with the string pieces.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 3 Jul 1998 20:44:06 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Difference between ', `, and " ?
Message-Id: <6njfqm$5vd$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Bryan T Hoch <bth@acsu.buffalo.edu> writes:
:Hi, I've found that ' , ` , and " have different effects when I use them
:with variables and strings in the Perl programs I use and write. I never
:came to an understanding what is different about them and I haven't found
:anywhere that actually discusses it.
You mean besides the standard perlop manpage that's on your
very system? You really haven't read the perl documentation?
--tom
--
I think I can sum up the difference between *BSD and Linux as follows:
"In Linux, new users get flamed for asking questions in the newsgroups
(or heaven forfend, the wrong newsgroup). In *BSD the principals
flame each other." --Warner Losh
------------------------------
Date: Fri, 3 Jul 1998 17:27:10 -0500
From: "Kirk Strauser" <kirks@dialnet.net>
Subject: Re: Difference between ', `, and " ?
Message-Id: <6njltr$cm1$1@ns2.dialnet.net>
Tom Christiansen wrote:
>You mean besides the standard perlop manpage that's on your
>very system? You really haven't read the perl documentation?
I understand his position; as a Perl newbie, I feel as if I've walked into
a largish municipal library with the assignment of "learning about
writing". On the other hand, I've got both the Camel and Llama books,
so that helps a bit. :)
- Kirk
- Still at the "oh, it'll do that?" phase.
------------------------------
Date: Fri, 03 Jul 1998 20:25:46 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: editing a file properly...
Message-Id: <6njes9$m0o$1@ligarius.ultra.net>
[ posted and mailed ]
"Ric Alcazar" <alcazar@netcomp.net> wrote:
-> Hello all,
->
-> I'm trying to edit a file, but am not doing it properly... my file is
-> similiar to this example:
->
-> line1 - and some contents
-> line2 - and some more contents
-> line3 - and some more contents
-> line4 - blah blah blah
-> ....
-> ....
->
-> the way I'm doing it, (which btw doesn't seem to be working efficiently)
-> is reading a each line into an array, and performing modifications on each
-> of the elements and then truncating to the existing file.
->
-> that seems to work, however, it doesn't achieve the result I am looking
-> for.
-> The modification I would like to do is the same for each of the lines,
-> that is, I'm trying to delete them. For instance, say I wanted to delete
-> line3, all i have to do is remove the contents of the corresponding array
-> element and then print out the array elements accordingly. The only problem
-> is that I get something that looks like this:
->
-> line1 - and some contents
-> line2 - and some contents
->
-> line4 - ...
Sounds like you want the splice function.
perldoc -f splice
But there are many ways to do it. Give us the snippet of the code where you
are stepping through the file and it will be easier to tell you what to use so
that you don't have to change much of the work you did.
HTH
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
and let the jerk that answers know that his
toll free number was sent as spam. "
------------------------------
Date: 3 Jul 1998 20:41:09 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: editing a file properly...
Message-Id: <6njfl5$5vd$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Ric Alcazar" <alcazar@netcomp.net> writes:
Did you happen to look through the second question to perlfaq5 yet?
Is there something you wish to do differently than that?
--tom
--
A power tool is not a toy. Unix is a power tool.
------------------------------
Date: Fri, 03 Jul 1998 21:16:24 GMT
From: Charles Maier <maierc@chesco.com>
Subject: Re: Field Sort without modules?
Message-Id: <359CE364.1994@chesco.com>
Trent Hare wrote:
>
> Looking for field sorting without modules installed...
>
> (ie)
> an comma separated ascii file , sorted by field[2] (after the split)
>
> Clues anyone?
>
> Thanks,
> Trent
I had worked up a sub-field sort that is specially designed to do
column-linear data.. database stuff. You could use this same idea on
your table data if you modify the line after the first FOR and the line
after the second FOR..
plus you would probably have to concatinate the keystring with some
"delimiter" between the key and record pointer to allow you to extract
the record pointer off the end of the key at the second FOR. For column
linear data this is not a problem.
The way this works:
1. pull out the pertainant data
2. concat an original record number
3. sort this key
4. pull the original array into that order.
The call to this sub is tricky only in that you must pass a reference to
the array @myarray by preceeding it with a backslash. The call is
sending starting COLUMN and ending COLUMN
&colsort(6,12,\@myarray);
This will sort @myarray on column 6 to 12 (remember.. starts at ZERO)
sub colsort {
($stcol,$endcol,$mry) = @_;
my($i,$a,$b,@tmp,@tmp2);
# break out the piece to be sorted and remember where it came from
# also.. copy the input'd array to @tmp2
for($a=0;$a<@$mry;$a++){
push(@tmp,substr(@$mry[$a],$stcol,$endcol-$stcol+1).$a);
push(@tmp2,@$mry[$a]);
}
@tmp = sort(@tmp);
for($i=0;$i<@tmp;$i++){ # move to pointer
$b=substr(@tmp[$i],$endcol-$stcol+1); # from pointer
@$mry[$i] = $tmp2[$b];
}
}
--
Chuck Maier
CDM Consulting Services
http://www.cdmcon.com
(610) 943-2726
------------------------------
Date: Fri, 3 Jul 1998 16:34:49 -0600
From: "Rick K" <ismkoehlerism@nmism-us.campus.mci.net>
Subject: Re: Flames....
Message-Id: <6njmah$jm9$1@news.campus.mci.net>
Steve McNabb wrote in message <6nitdv$jr0$1@nntp1.uunet.ca>:
>I would have to disagree. I started out with Perl as my first language,
>and although I found it to be _very_ tough going at first, eight months
>later, I'm now happily dancing around the symbol table and slinging
>lean, fast, powerful OO perl all over the place. [snip lots of good stuff]
I would have to agree with Mr. McNabb.
And continuing on the subject of flames in general ...
At the risk of being flamed into absolute nothingness, of being
mocked and socked, heckled, rejected, and worst of all, shunned ...
What is the deal with all the quibbling posts to this newsgroup,
seemingly by some of the movers and shakers of perl?
Are we expected to line up behind the true leader? Do you guys
have some flags or colors we can rally to?
Ask yourself this: how many complaints about clueless newbies
have you launched, vs. how many "Did not!" - "Did too!" counter-
posts? It seems to me that if you're concerned about the wasted
bandwidth caused by Johnnie "Didn't-Read-the-Whole-Camel-Book"
Newbie's beginner question, maybe you'd also be concerned about
the endless rounds of put-downs and "I'm smarter than you" posts.
I am thankful for the help I have received from this newsgroup, and
do not wish to alienate "the wizards", but perhaps some folks could
conduct a gentle self-analysis. Whew, stepping down off the
soapbox now. Thank you.
------------------------------
Date: 3 Jul 1998 20:34:41 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How does one remove ^H metacharacters from STDIN?
Message-Id: <6njf91$5vd$1@csnews.cs.colorado.edu>
Keywords: bouncy mangle melodramatic Nairobi
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
edew@netcom.com (Eric Dew) writes:
:But now, even though what I see (if I were to print("$name"); for example)
:is Job, it's really Joe^Hb. How do I remove the ^H's?
You fix your tty settings so that backspace backspaces.
--tom
--
And just as you're under no obligation to publish your source code
to please me, I'm under no obligation to help you hide it.
--Russ Allbery (rra@cs.stanford.edu)
------------------------------
Date: Fri, 3 Jul 1998 22:46:41 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Invalid regexp in grep
Message-Id: <EvJJ9t.MxJ@news.boeing.com>
In article <MPG.1005f162f21c476398970f@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>[This followup was posted to comp.lang.perl.misc and a copy was sent to
>the cited author.]
>
>In article <EvHwD9.94z@news.boeing.com> on Fri, 3 Jul 1998 01:34:21 GMT,
>Charles DeRykus <ced@bcstec.ca.boeing.com> says...
>> In article <MPG.10059329f633d6979896e2@nntp.hpl.hp.com>,
>> Larry Rosler <lr@hpl.hp.com> wrote:
>...
>#!/usr/local/bin/perl -w
>use Benchmark;
>
>my @a;
>my $i;
>for ($i = 0; $i < 400_000; ++$i) { push @a, int rand 256 }
>
>timethese (1, {
> Cntrl => sub { my @b = @a },
> Grep => sub { my @b = grep 7 <= $_ && $_ <= 176, @a },
> Index => sub { my (@b, $i);
> for ($i = 0; $i < @a; ++$i)
> { push @b, $_ if 7 <= ($_ = $a[$i]) && $_ <= 176 }
> },
> Shift => sub { my @b;
> 7 <= ($_ = shift @a) && $_ <= 176 and push @b, $_ while @a;
> },
>} );
>
>> >Benchmark: timing 1 iterations of Cntrl, Grep, Index, Shift...
>> > Cntrl: 14 secs ( 2.21 usr 0.17 sys = 2.38 cpu)
>> > (warning: too few iterations for a reliable count)
>> > Grep: 54 secs ( 7.05 usr 0.50 sys = 7.55 cpu)
>> > (warning: too few iterations for a reliable count)
>> > Index: 51 secs (13.74 usr 0.37 sys = 14.11 cpu)
>> > (warning: too few iterations for a reliable count)
>> > Shift: 87 secs ( 9.11 usr 1.88 sys = 10.99 cpu)
>> > (warning: too few iterations for a reliable count)
>> >
>>
> ... omitted
>
>You cannot run the benchmark as written with more than one iteration.
>'Shift' destroys the input array, so the remaining 9 iterations do
>nothing. Why it was *faster* than Cntrl is a minor mystery, though.
Whoops, yes. A re-work though still illustrates that a
single iteration casts 'index' in too favorable a light;
timethese (10, {
Cntrl => sub { my @c = @a; },
Grep => sub { my @c = @a; my @b = grep 7 <= $_ && $_ <= 176, @a },
Index => sub { my @c = @a; my (@b, $i);
for ($i = 0; $i < @a; ++$i) {
push @b, $_ if 7 <= ($_ = $a[$i]) && $_ <= 176
}
},
Shift => sub {
my @c = @a; my @b;
7 <= ($_ = shift @c) && $_ <= 176 and
push @b, $_ while @c;
},
} );
Benchmark: timing 10 iterations of Cntrl, Grep, Index, Shift...
Cntrl: 30 secs (28.63 usr 0.99 sys = 29.62 cpu)
Grep: 202 secs (196.11 usr 5.38 sys = 201.49 cpu)
Index: 502 secs (500.10 usr 0.53 sys = 500.63 cpu)
Shift: 320 secs (317.93 usr 0.69 sys = 318.62 cpu)
HTH,
--
Charles DeRykus
------------------------------
Date: Fri, 3 Jul 1998 22:00:51 +0100
From: "Stephen Penna" <stephen@penna.demon.co.uk>
Subject: last modified date
Message-Id: <899499712.28611.0.nnrp-04.9e988163@news.demon.co.uk>
how do i get the last modified date of a file in perl?
(equivilant of the ssi command)
---------
Steve Penna
steve@penna.demon.co.uk
http://actuaweb.gamestats.com/ - Actua Sports Web
http://www.penna.demon.co.uk/pureseeds/ - Pure Lightning Seeds
------------------------------
Date: Fri, 03 Jul 1998 17:51:44 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: last modified date
Message-Id: <comdog-ya02408000R0307981751440001@news.panix.com>
Keywords: from just another new york perl hacker
In article <899499712.28611.0.nnrp-04.9e988163@news.demon.co.uk>, "Stephen Penna" <stephen@penna.demon.co.uk> posted:
>how do i get the last modified date of a file in perl?
have you tried stat()?
perldoc -f stat
good luck :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>
------------------------------
Date: 03 Jul 1998 17:22:34 -0400
From: Dean Pentcheff <dean@mail.biol.sc.edu>
Subject: Re: last modified date
Message-Id: <m3lnqaeijp.fsf@mail.biol.sc.edu>
"Stephen Penna" <stephen@penna.demon.co.uk> writes:
> how do i get the last modified date of a file in perl?
Check perlfunc for -M and stat.
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org>
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-7068)
------------------------------
Date: Fri, 03 Jul 1998 19:27:37 -0400
From: Bill 'Sneex' Jones <wcjones@fccj.org>
Subject: lib/open3.........open3: open(GLOB(0x80cceec), >&FHOPEN019) failed: Illegal seek at ./lib/open3.t line 113
Message-Id: <359D68E8.4989D0D@fccj.org>
Anyone get this error on their Linux box? Just curious...
lib/open3.........open3: open(GLOB(0x80cceec), >&FHOPEN019) failed:
Illegal seek at ./lib/open3.t line 113
FAILED at test 17
lib/ops...........ok
<snip other stuff...>
lib/trig..........ok
Failed 1 test script out of 182, 97.25% okay.
### Since not all tests were successful, you may want to run some
<snip other stuff...>
### in directory ./t.
u=3.11 s=1.22 cu=144.28 cs=22.92 scripts=178 tests=6107
make: *** [test] Error 1
I have gotten this same message since 5.004_64...
I love Perl :) It's is very consistent. :P
-Sneex- :-)
____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
mailto:webmaster@fccjmail.fccj.org | http://webmaster.fccj.org/Webmaster
____________________________________________________________________________
Pay attention to your enemies, for they are
the first to discover your mistakes.
------------------------------
Date: Fri, 03 Jul 1998 16:05:56 -0500
From: Dan Baker <dtbaker_@flash.net>
Subject: limits of glob() ?
Message-Id: <359D47B4.2FBB@flash.net>
I've read that using glob() to return a list of items has limitations
with "large numbers" of items.... What IS the limit? i.e. when should I
consider using opendir(), readdir(), closedir()?
A related topic that I've been wondering about is whether there is any
*significant* difference using glob() versus the magic <*>. I tried a
timing test , but didn't see any real difference speedwise, and am
wondering if there would be any other reasons to use one versus the
other?
while (glob("*")){
... whatever
}
versus....
foreach $item (<*>) {
... whatever
}
thanx,
Dan
------------------------------
Date: 3 Jul 1998 19:22:27 -0400
From: schinder@leprss.gsfc.nasa.gov (Paul J. Schinder)
Subject: Re: MacPerl::Ask
Message-Id: <6njp3j$k2u@shell.clark.net>
In <359C200F.BE597D2D@pop.dnvr.uswest.net> sprigen687 <sprigen687@pop.dnvr.uswest.net> writes:
>I'm curious about the MacPerl::Ask and MacPerl::Answer functions. Can I
>use them to give input to the script? If there is a page about this,
>could you send me a link? Thank you.
Curious, but not curious enough to read the docs that came with
MacPerl? Look in your MacPerl folder. You'll find an application
called Shuck. Start it up, and start playing with it.
--
--------
Paul J. Schinder
NASA Goddard Space Flight Center
schinder@leprss.gsfc.nasa.gov
------------------------------
Date: Fri, 3 Jul 1998 19:30:51 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: MacPerl::Ask
Message-Id: <1dbk52f.1shfudbceg2wwN@slip-32-100-246-226.ny.us.ibm.net>
sprigen687 <sprigen687@pop.dnvr.uswest.net> wrote:
> I'm curious about the MacPerl::Ask and MacPerl::Answer functions. Can I
> use them to give input to the script? If there is a page about this,
> could you send me a link? Thank you.
Open :MacPerl f:pod:macperl.pod in Shuck.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 3 Jul 1998 23:38:03 GMT
From: sr@wildkogel.pc-plus.de (Stephen Riehm)
Subject: my perl object becomes a HASH when I try to use it. please help
Message-Id: <slrn6pqqqq.ieq.sr@wildkogel.pc-plus.de>
Hi Perl Hackers,
I'm using Data::Dumper to create a little 2Mb database, which is
essentially a table of nested objects, where each object contains an
object or two - so far so easy - and it all works fine - until now.
Here's a bit of test code: (the real code is an eval which ends up
being the same - and displays the same results)
my $ref = $self->{"platforms"}{$Pkg::Overview::platform};
print "ref is a ", ref( $ref ), "\n";
# print $ref->get( "package_dir" ), "\n";
(Note the last line is commented out!)
and here's the output that goes with it:
ref is a Pkg::Installation
ie: the expansion of all that hash in a hash is an object - right?
OK, now remove the comment on the last line, and all of a sudden the
output becomes:
ref is a HASH
Can't call method "get" on unblessed reference at Object.pm line 158.
how can this be? Absolutely nothing else in the program changed (it's
only test code to prove that I wasn't losing my mind after all)
I found this behaviour on AIX 4.1 and on HP-UX 10.20. (Full perl
version information below)
Has anybody else seen anything like this happen? How can introducing a
print AFTER the ref() cause the ref() to fail? Is perl doing some
nasty lookahead stuff here?
Can anybody help? I'm baffled!
Thanks in advance,
Steve
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
Platform:
osname=aix, osvers=4.1.4.0, archname=aix
uname='aix kibo 1 4 000883b0a000 '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=n useperlio=undef d_sfio=undef
Compiler:
cc='xlc', optimize='-O', gccversion=
cppflags='-qmaxmem=8192 -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE
-I/usr/local/include'
ccflags ='-qmaxmem=8192 -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE
-I/usr/local/include'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=1, d_casti32=define, d_castneg=undef
intsize=4, alignbytes=8, usemymalloc=n, prototype=define
Linker and Libraries:
ld='ld', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
libs=-ldbm -lld -lm -lc -lbsd -lPW
libc=/lib/libc.a, so=a
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_aix.xs, dlext=so, d_dlsymun=undef, ccdlflags='-bE:perl.exp'
cccdlflags=' ', lddlflags='-H512 -T512 -bhalt:4 -bM:SRE
-bI:$(PERL_INC)/perl.exp -bE:$(BASEEXT).exp -b noentry -lc
-L/usr/local/lib'
Summary of my perl5 (5.0 patchlevel 4 subversion 0) configuration:
Platform:
osname=hpux, osvers=10, archname=PA-RISC1.1
uname='hp-ux lotus b.10.20 a 9000859 489553312 two-user license '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=n useperlio= d_sfio=
Compiler:
cc='cc', optimize='-O', gccversion=
cppflags='-D_HPUX_SOURCE -Aa -I/usr/local/include'
ccflags ='-D_HPUX_SOURCE -Aa -I/usr/local/include'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, randbits=15
Linker and Libraries:
ld='ld', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib/pa1.1 /lib /usr/lib /usr/ccs/lib
libs=-lnet -lnsl_s -lndbm -ldld -lm -lc -lndir -lcrypt
libc=/lib/libc.sl, so=sl
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=, ccdlflags='-Wl,-E -Wl,-B,deferred '
cccdlflags='+z', lddlflags='-b -L/usr/local/lib'
------------------------------
Date: 3 Jul 1998 20:41:37 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Pg.pm
Message-Id: <slrn6pqgjb.1p4.gabor@localhost.vmunix.com>
In comp.lang.perl.misc, rasyidi@my-dejanews.com <rasyidi@my-dejanews.com> wrote :
# Where can I get the full documentation, reference, example script and
# tutorial for Pg.pm(Perl for PostgreSQL)?
Use DBI instead. It's better documented and better for your health. :)
For Postgres yuo'll also need the DBD::Pg module.
------------------------------
Date: 3 Jul 1998 19:58:45 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: problems with creating new directories
Message-Id: <6njd5l$4hd$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Ross Mullen <rmullen@mcmail.com> writes:
:mkdir("/home/dynamic/$name",777);
That doesn't look very octal.
--tom
--
The probability of someone watching you is proportional to the
stupidity of your action.
------------------------------
Date: Fri, 03 Jul 1998 21:11:38 GMT
From: "Rob Goodwin" <goodrob@shaw.wave.ca>
Subject: problems with DBD::empress
Message-Id: <eObn1.2800$606.14100145@news.rdc1.ab.wave.home.com>
Hi there,
I'm having some trouble getting the DBD module for Empress working
correctly. I've been in touch with the Empress support people who had
some suggestions but I'm having a bit of trouble rationalizing them
because they were to basically just reinstall everything. I will try
this but thought maybe I would run this problem past the group first in
case somebody might have some ideas as to which specific files I could
target rather than all of them.
Everything seems to compile and install OK but then:
[root@benway DBD-Empress-0.50]# perl test.pl
Using Empress Version located at /usr/empress/v6.8
Running tests in local mode
Testing: DBI->install_driver( 'Empress' ):
and it craps out right there. the error log reads as so:
[root@benway DBD-Empress-0.50]# more test.stderr.11947
install_driver(Empress) failed: Can't load
'/usr/lib/perl5/site_perl/i386-linux/auto/DBD/Empress/Empress.so' for module
DBD::Empress:
/usr/lib/perl5/site_perl/i386-linux/auto/DBD/Empress/Empress.so: undefined
symbol: spok at /usr/lib/perl5/i386-linux/5.00404/DynaLoader.pm line 166.
at (eval 1) line 2
DBI::install_driver('DBI', 'Empress') called at test.pl line 54
some info about my machine:
DBI-0.93
(Red Hat 5.0)
uname -a
---------
Linux benway.secretshopnet.com 2.0.31 #1 Sun Nov 9 21:45:23 EST 1997
i586 unknown
perl -v
--------
This is perl, version 5.004_04 built for i386-linux
rpm -qa |grep perl
--------------
perl-5.004-6
If more info would be helpful please let me know. thanks.,
rob
------------------------------
Date: 3 Jul 1998 20:47:57 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Redirecting output?
Message-Id: <6njg1t$5vd$5@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Bry <bth@acsu.buffalo.edu> writes:
:I'm writing a Perl program that executes a system call to see who is
No, that's not a system call. It's a function called system().
:logged in on the server, but whenever it makes that system call it always
:sends its output to the screen. I don't want that. Is there anyway that I
:can have the output redirected into an array within the program that
:called it?
: if ((system "rusers -l $hostA | fgrep $personA") == 0){
: push(@logged_on, $personA."@".$hostA);
: print $logged_on[i];
: $x++;
You'll find that there's a question in section 8 of the
perlfaq that answers this question.
--tom
--
/* Force them to make up their mind on "@foo". */
--Larry Wall, from toke.c in the v5.0 perl distribution
------------------------------
Date: Fri, 3 Jul 1998 23:48:00 +0200
From: "Cornel" <lauchhammer@gmx.net>
Subject: Skript f|r Veranstaltungskalender
Message-Id: <6njjju$k6o$1@news.nacamar.de>
Hallo!
Kennt jemand von Euch ein gutes und einfaches Skript f|r einen
Veranstaltungskalender, das, wenn mvglich, keine Werbung enthdlt.
Tsch|_ Cornel
------------------------------
Date: 3 Jul 1998 20:20:25 GMT
From: macintsh@cs.bu.edu (John Siracusa)
Subject: Re: The vagaries of read()ing
Message-Id: <6njee9$kga$1@news1.bu.edu>
As usual, I'm following up my own post to clarify a bit. The
actual problem I'm trying to solve is how to create a network
client that never gets stuck on any blocking network i/o calls.
That is, it'd spin through an idle pseudo-event-loop every 1.5
seconds or whatever. To pull that off, I need to know when
there's data available to be read, read X number of bytes, and
go back to my event loop. I also have to be able to distinguish
between a server that is no longer there and a server that just
doesn't have any data to send at the moment.
My solution was to use IO::Socket::INET in non-blocking mode,
and perl's built-in read() and sysread() (not mixed, mind you; I
just mean that I've tried both as per my inital post) to handle
the reading, and the return values from [sys]read() along with
the value of $! to handle the "is there something ready to be
read?" and the "have we been disconnected?" problems.
I'm in the process of poring through DejaNews and the other
likely suspects looking for alternate solutions like using
select(), recv(), etc. Since I've already written a substantial
amount of code using the read() family, I'd prefer to find a
solution to the problem as posed in my previous post. But I'm
completely open to alternate solutions if they're "better" in
some way. Thanks...
-----------------+----------------------------------------
John Siracusa | If you only have a hammer, you tend to
macintsh@bu.edu | see every problem as a nail. -- Maslow
------------------------------
Date: Fri, 3 Jul 1998 19:30:53 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Virtual functions.
Message-Id: <1dbk55f.1n8e54ftri7oeN@slip-32-100-246-226.ny.us.ibm.net>
Igor Krivokon <igor.k@usa.net> wrote:
> Kevin Reid wrote in message
> <1dbi2iz.1yecwrd1g2sjgaN@slip-32-100-246-61.ny.us.ibm.net>...
> >> Probably, it helps; but that's not the same effect.
> >> Using C++ pure virtual functions, you get an error message
> >> 1) when you try to instantiate your class (not when you call the
> function)
> >
> >Then put the error in the new() class method.
>
> Bad idea.
> You get an error for any derived class, unless it implements
> it's own new() method.
> That's not what abstract classes for.
package AClass;
sub new {
my ($class, $path) = @_;
die 'I'm virtual!' if $class eq 'AClass';
bless {
path => $path,
}, $class;
}
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
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 3056
**************************************