[17040] in Perl-Users-Digest
Perl-Users Digest, Issue: 4452 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 27 21:10:32 2000
Date: Wed, 27 Sep 2000 18:10:21 -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: <970103421-v9-i4452@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 27 Sep 2000 Volume: 9 Number: 4452
Today's topics:
Re: foreach two elements at a time? (Martien Verbruggen)
Re: foreach two elements at a time? <uri@sysarch.com>
Re: foreach two elements at a time? (Martien Verbruggen)
Re: foreach two elements at a time? <lr@hpl.hp.com>
Re: foreach two elements at a time? <uri@sysarch.com>
Re: How can I combine regular expressions? <ren.maddox@tivoli.com>
Re: how to read dir info ? <edward@netcomi.com>
Re: how to read dir info ? <dougw@cnation.com>
Re: how to read dir info ? <vioon@hotmil.com>
Re: how to read dir info ? <lr@hpl.hp.com>
Re: how to read dir info ? <lr@hpl.hp.com>
Re: how to read dir info ? <ren.maddox@tivoli.com>
Re: how to read dir info ? <ren.maddox@tivoli.com>
Re: how to read dir info ? <lr@hpl.hp.com>
Re: how to read dir info ? (Gwyn Judd)
Re: I Found 1000s Of Free Hits at MDS 5796 <anmcguire@ce.mediaone.net>
Re: I Found 1000s Of Free Hits at MDS 5796 <flavell@mail.cern.ch>
Re: Is there some free perl script packget for download <elephant@squirrelgroup.com>
Re: Is this routine OK? <anmcguire@ce.mediaone.net>
Re: Is this routine OK? <tim@ipac.caltech.edu>
Re: lowercase and UPPERCASE (Daniel Chetlin)
Re: Module load error <tim@ipac.caltech.edu>
Re: MySQL vs. mSQL <OfficerS@aries.tucson.saic.com>
need help with LWP/https/proxy <mbudash@sonic.net>
perl cookies <troyr@vicnet.net.au>
Programming the Perl DBI <sxm124@po.cwru.edu>
Re: Programming the Perl DBI <troyr@vicnet.net.au>
Re: Programming the Perl DBI <jeff@vpservices.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Sep 2000 23:37:50 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: foreach two elements at a time?
Message-Id: <slrn8t5165.64u.mgjv@verbruggen.comdyn.com.au>
On Wed, 27 Sep 2000 16:58:33 GMT,
Bart Lateur <bart.lateur@skynet.be> wrote:
> Abigail wrote:
>
> >%% In particular $a and $b. These seem to shout "sort sub!" at me.
> >
> >Since the code in question is neither a sub, nor does it involve
> >sort, that would be a pretty strange reaction.
>
> Well... if you have file-scoped lexicals $a and $b, that will pretty
> much mess up any sort subs you may ever want to have in the script.
>
> my($a, $b);
> print join "\n", sort { $a <=> $b } map { int rand 100 } 1 .. 20;
> -->
> Can't use "my $a" in sort comparison at test.pl line 4.
\begin{peeve}
That's an argument to allow sort subs to act on @_, so that we can
write them in a slighlty more sane way.
my @foo = sort { $_[0] <=> $_[1] } @bar;
It's longer, and I have no clue how hard it would be to implement, but
I've always had a bit of a problem with the reservedness[1] of $a and
$b. I have much less problems with all the non-alpha character
variables being special, but $a and $b? It wasn't as bad before 5.0,
but since lexical scoping, problems like the one you highlighted are
possible.
It's worse in situation where you have things like:
# This can be used to compare objects of type BAR
# call as
# $obj1->compare($obj2) or compare($obj1, $obj2)
#
sub compare
{
my $object1 = shift;
my $object2 = shift;
# Very long piece of code to compare oblique objects
return $some_number;
}
sub sort_compare { compare($a, $b) }
my @foo = sort sort_compare @bar;
I now am forced to either have two implementations of this code, or to
accept that I'll have a lot of extra calls to subs, simpy because I
_have_ to use $a and $b, instead of being able to use standard ways in
which subs work. Besides that, keeping a sort sub around for the sole
purpose of sorting when I already have a sub that would do the job
perfectly fine is just inelegant.
\end{peeve}
Martien
[1] Probably not a word, but use your imagination.
--
Martien Verbruggen |
Interactive Media Division | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: Wed, 27 Sep 2000 23:48:46 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: foreach two elements at a time?
Message-Id: <x7wvfx75wh.fsf@home.sysarch.com>
>>>>> "MV" == Martien Verbruggen <mgjv@verbruggen.comdyn.com.au> writes:
MV> That's an argument to allow sort subs to act on @_, so that we can
MV> write them in a slighlty more sane way.
MV> my @foo = sort { $_[0] <=> $_[1] } @bar;
MV> It's longer, and I have no clue how hard it would be to implement,
MV> but I've always had a bit of a problem with the reservedness[1] of
MV> $a and $b. I have much less problems with all the non-alpha
MV> character variables being special, but $a and $b? It wasn't as bad
MV> before 5.0, but since lexical scoping, problems like the one you
MV> highlighted are possible.
$a and $b were not picked for simplicity but for speed. it is much
faster to alias them to the elements being compared than to push them on
the stack for access by @_. since the compare code ref is called O(N log
N), you want to make that as fast as possible. hence the wins of the ST
and GRT which factor key extraction code out of the compare sub.
MV> It's worse in situation where you have things like:
MV> # This can be used to compare objects of type BAR
MV> # call as
MV> # $obj1->compare($obj2) or compare($obj1, $obj2)
MV> #
MV> sub compare
MV> {
MV> my $object1 = shift;
MV> my $object2 = shift;
MV> # Very long piece of code to compare oblique objects
MV> return $some_number;
MV> }
MV> sub sort_compare { compare($a, $b) }
MV> my @foo = sort sort_compare @bar;
MV> I now am forced to either have two implementations of this code, or to
MV> accept that I'll have a lot of extra calls to subs, simpy because I
MV> _have_ to use $a and $b, instead of being able to use standard ways in
MV> which subs work. Besides that, keeping a sort sub around for the sole
MV> purpose of sorting when I already have a sub that would do the job
MV> perfectly fine is just inelegant.
i don't see why you jump through all those hoops. why not do:
@sorted = sort { $a->compare( $b ) } @objs ;
i may not get the exact compare method you need, but there is no reason
you can't use $a and $b instead of @_ in the compare code block. just
call the compare methods as you would normally. you don't need a special
sort sub, just use an inline code block.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 28 Sep 2000 00:04:23 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: foreach two elements at a time?
Message-Id: <slrn8t52o3.64u.mgjv@verbruggen.comdyn.com.au>
On Wed, 27 Sep 2000 23:48:46 GMT,
Uri Guttman <uri@sysarch.com> wrote:
>
> i don't see why you jump through all those hoops. why not do:
>
> @sorted = sort { $a->compare( $b ) } @objs ;
That's an idea. it's still one extra level of sub calls though (unless
perl does something very clever with that block). And it still doesn't
solve the problem of having $a or $b in lexical scope though. Yes, I
know that they are special, and I avoid any use of $a and $b outside
sort subs. I avoid any single character variables, unless I'm in a
short loop, or unless I'm working with something that's supposed to
express coordinates, or unless I have another burning reason to not
want to type to much.
However, I _mainly_ avoid $a and $b because I have known for a long
time that $a and $b are special. I don't avoid them because I never
ever would be able to come up with a situation in which $a and $b
would be perfectly fine variable names.
As for speed, they could have been aliased to other variable names
that were less likely to fall in the range of names that users are
likely to use. Maybe $1 and $2 could have been used (localised), or
maybe $< and $>. I still feel it was a design decision that may have
been good at the time, but that no longer is the best way.
And yes, I know about the prototyping possibility, but I just don't
believe Perl's prototyping is strong enough. Besides, as you said, it
is documented to be slower. But that could just mean that it needs to
be worked on.
Just as an extra question, _why_ is aliasing two variables slower than
creating references to them in @_?
Martien
--
Martien Verbruggen |
Interactive Media Division | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: Wed, 27 Sep 2000 17:06:36 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: foreach two elements at a time?
Message-Id: <MPG.143c2b658c99247e98adcf@nntp.hpl.hp.com>
In article <x7wvfx75wh.fsf@home.sysarch.com> on Wed, 27 Sep 2000
23:48:46 GMT, Uri Guttman <uri@sysarch.com> says...
...
> $a and $b were not picked for simplicity but for speed. it is much
> faster to alias them to the elements being compared than to push them on
> the stack for access by @_. since the compare code ref is called O(N log
> N), you want to make that as fast as possible. hence the wins of the ST
> and GRT which factor key extraction code out of the compare sub.
As you know but chose not to say, the GRT goes further than the ST, by
eliminating the compare sub completely.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 28 Sep 2000 00:21:15 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: foreach two elements at a time?
Message-Id: <x7snql74eb.fsf@home.sysarch.com>
>>>>> "MV" == Martien Verbruggen <mgjv@verbruggen.comdyn.com.au> writes:
MV> Just as an extra question, _why_ is aliasing two variables slower
MV> than creating references to them in @_?
aliasing $a is a simple global copy of the ref to the value. but @_
resides on the stack and so there has to be memory allocation for the
aliases which still have to be copied.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 27 Sep 2000 15:16:20 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: How can I combine regular expressions?
Message-Id: <m3aectr3or.fsf@dhcp11-177.support.tivoli.com>
cberry@cinenet.net (Craig Berry) writes:
> Philip Lees (pjlees@ics.forthcomingevents.gr) wrote:
> : >$line =~ s/\b([A-Z])([A-Z])(?=[a-z]|\W)/$1\l$2/g;
> : >
> : >Then you don't need the list of possibilities.
> :
> : That's brilliant - I was in the proverbial wood of vision-obstructing
> : trees.
>
> The trouble is that you'll nuke other adjacent capitals besdies those
> encoding Greek letters. "When I was in CA last weekend, I watched an XX
> movie." You don't want the CA and XX to become Ca and Xx.
Which happens anyway if any such abbreviations happen to be the same as
a converted Greek letter. You can exclude the "|\W" piece to avoid
this, keeping in mind that any stand-alone two-character converted
Greek letters will not be case adjusted.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 27 Sep 2000 17:18:25 -0500
From: Edward Valencia <edward@netcomi.com>
Subject: Re: how to read dir info ?
Message-Id: <39D27231.EDD34C48@netcomi.com>
opendir(DIR, "/www");
@dirs = sort(grep(!/^\.\.?$/, readdir(DIR)));
close(DIR);
chomp(@dirs);
foreach $line (@dirs) {
print "$line\n";
}
------------------------------
Date: Wed, 27 Sep 2000 15:33:54 -0700
From: dougw <dougw@cnation.com>
Subject: Re: how to read dir info ?
Message-Id: <39D275D2.5DEDF055@cnation.com>
Put a -d check in the grep.
Ex:
@dir = grep( (!/^\./ && -d), readdir(DIR) );
--
Doug
qwerty wrote:
>
> I want to read a directory with only the subdirs
> Right now i have something like this :
>
> @dir = grep(!/\./, readdir(DIR));
> closedir(DIR);
>
> foreach $line(sort(@dir)){
> print "<option>$line\n";
>
> etc.
>
> This filters out all the files which contains a dot and shows all
> the directories. But if the directory contains a file without a
> dot it is listed too, is there a way to show only the directories.
>
> Heard and read about a -d option but could not find a solution.
>
> Thanks.
------------------------------
Date: Thu, 28 Sep 2000 00:40:20 +0200
From: "qwerty" <vioon@hotmil.com>
Subject: Re: how to read dir info ?
Message-Id: <8qttej$o0m$1@tesla.a2000.nl>
Thanks, but it just does not work
@dir = grep( (!/^\./ && -d), readdir(DIR) );
>
> --
> Doug
>
> qwerty wrote:
> >
> > I want to read a directory with only the subdirs
> > Right now i have something like this :
> >
> > @dir = grep(!/\./, readdir(DIR));
> > closedir(DIR);
> >
> > foreach $line(sort(@dir)){
> > print "<option>$line\n";
> >
> > etc.
> >
> > This filters out all the files which contains a dot and shows all
> > the directories. But if the directory contains a file without a
> > dot it is listed too, is there a way to show only the directories.
> >
> > Heard and read about a -d option but could not find a solution.
> >
> > Thanks.
------------------------------
Date: Wed, 27 Sep 2000 15:48:01 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to read dir info ?
Message-Id: <MPG.143c18fddeddca9f98adcb@nntp.hpl.hp.com>
In article <39D27231.EDD34C48@netcomi.com> on Wed, 27 Sep 2000 17:18:25
-0500, Edward Valencia <edward@netcomi.com> says...
It would be helpful in responding to a post to post the relevant part.
In this case, that would have shown that you aren't answering the
question at all.
Q> In article <8qtqga$j0t$1@tesla.a2000.nl> on
Q> Wed, 27 Sep 2000 23:56:02 +0200, qwerty <vioon@hotmil.com> says...
Q>
Q> I want to read a directory with only the subdirs
...
Q> ... is there a way to show only the directories.
Q>
Q> Heard and read about a -d option but could not find a solution.
> opendir(DIR, "/www");
Don't show, even in example code, an 'open' without a check for failure.
> @dirs = sort(grep(!/^\.\.?$/, readdir(DIR)));
That serves only to remove the pseudo-directories '.' and '..' (and real
directories ".\n" and "..\n", were such things conceivable).
> close(DIR);
> chomp(@dirs);
Gratuitous removal of terminating newlines from elements that aren't
lines at all.
> foreach $line (@dirs) {
> print "$line\n";
> }
Indeed one needs to filter on the '-d' attribute.
my $dir = '/path/to/dir';
opendir DIR, $dir or die "Couldn't open '$dir'. $!\n";
my @dirs = grep !/^\.\.?\z/ && -d "$dir/$_" => readdir DIR;
Alternatively (and more efficiently):
my $dir = '/path/to/dir';
chdir $dir or die "Couldn't chdir to '$dir'. $!\n";
opendir DIR, '.' or die "Couldn't open '$dir'. $!\n";
my @dirs = grep !/^\.\.?\z/ && -d => readdir DIR;
Sprinkle with 'sort' if you wish, but that wasn't asked for.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 27 Sep 2000 15:49:53 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to read dir info ?
Message-Id: <MPG.143c196d28b0ec8d98adcc@nntp.hpl.hp.com>
In article <39D275D2.5DEDF055@cnation.com> on Wed, 27 Sep 2000 15:33:54
-0700, dougw <dougw@cnation.com> says...
> Put a -d check in the grep.
>
> Ex:
>
> @dir = grep( (!/^\./ && -d), readdir(DIR) );
That fails unless the directory is the current directory.
<SNIP complete Jeopardy posting, which might be warning enough! :->
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 27 Sep 2000 17:24:12 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: how to read dir info ?
Message-Id: <m3r965pj77.fsf@dhcp11-177.support.tivoli.com>
"qwerty" <vioon@hotmil.com> writes:
> I want to read a directory with only the subdirs
> Right now i have something like this :
>
> @dir = grep(!/\./, readdir(DIR));
> closedir(DIR);
>
> foreach $line(sort(@dir)){
> print "<option>$line\n";
>
> etc.
>
> This filters out all the files which contains a dot and shows all
> the directories. But if the directory contains a file without a
> dot it is listed too, is there a way to show only the directories.
>
> Heard and read about a -d option but could not find a solution.
-d is certainly part of the answer.
#!/usr/local/bin/perl -w
use strict;
my $dir = shift || '.';
opendir DIR, $dir or die "Could not open $dir, $!\n";
$\=$,="\n";
print grep -d, readdir(DIR)
__END__
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 27 Sep 2000 17:59:25 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: how to read dir info ?
Message-Id: <m3g0mlphki.fsf@dhcp11-177.support.tivoli.com>
[double Jeopardectomy and re-attribution]
"qwerty" <vioon@hotmil.com> writes:
> dougw <dougw@cnation.com> writes:
>
> > qwerty wrote:
> > >
> > > I want to read a directory with only the subdirs
> > > Right now i have something like this :
> > >
> > > @dir = grep(!/\./, readdir(DIR));
> > > closedir(DIR);
> > >
> > > foreach $line(sort(@dir)){
> > > print "<option>$line\n";
> > >
> > > etc.
> > >
> > > This filters out all the files which contains a dot and shows all
> > > the directories. But if the directory contains a file without a
> > > dot it is listed too, is there a way to show only the directories.
> > >
> > > Heard and read about a -d option but could not find a solution.
> >
> > @dir = grep( (!/^\./ && -d), readdir(DIR) );
> >
>
> Thanks, but it just does not work
Please describe exactly how it does not work. It worked fine for me
in the following context:
#!/usr/local/bin/perl -w
use strict;
opendir DIR, "." or die "Could not open directory, $!\n";
my @dirs = grep( (!/^\./ && -d), readdir(DIR) );
print "@dirs\n";
__END__
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 27 Sep 2000 17:03:25 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to read dir info ?
Message-Id: <MPG.143c2aadf09d2d3298adce@nntp.hpl.hp.com>
In article <m3r965pj77.fsf@dhcp11-177.support.tivoli.com> on 27 Sep 2000
17:24:12 -0500, Ren Maddox <ren.maddox@tivoli.com> says...
...
> #!/usr/local/bin/perl -w
> use strict;
>
> my $dir = shift || '.';
> opendir DIR, $dir or die "Could not open $dir, $!\n";
> $\=$,="\n";
> print grep -d, readdir(DIR)
Wrong if any argument that doesn't specify the current directory is
given.
Where is that top-ten list? Surely this one is or should be in it.
Look how many wrong answers there are in this thread alone!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 28 Sep 2000 00:30:20 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: how to read dir info ?
Message-Id: <slrn8t54g4.q6.tjla@thislove.dyndns.org>
I was shocked! How could qwerty <vioon@hotmil.com>
say such a terrible thing:
>
>I want to read a directory with only the subdirs
>Right now i have something like this :
>
>@dir = grep(!/\./, readdir(DIR));
> closedir(DIR);
>
>foreach $line(sort(@dir)){
>print "<option>$line\n";
>
>etc.
>
>This filters out all the files which contains a dot and shows all
>the directories. But if the directory contains a file without a
>dot it is listed too, is there a way to show only the directories.
>
>Heard and read about a -d option but could not find a solution.
So you want a list of all the directories that do not contain a dot?
@dirs = grep { !/\./ && -d } readdir(DIR);
print "<option>$_\n" for sort @dirs;
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I have always believed that I was slightly saner than most people. Then
again, most insane people think this.
-Truman Capote (contributed by Nathan Poznick)
------------------------------
Date: Wed, 27 Sep 2000 17:49:08 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: I Found 1000s Of Free Hits at MDS 5796
Message-Id: <Pine.LNX.4.21.0009271745270.18929-100000@hawk.ce.mediaone.net>
[ advertisement censored with +++ ]
On Wed, 27 Sep 2000, JakeMS12@sydney.au quoth:
> +++ +++ - ++++ +++ +++ Has
>
> Free Web Site Advertising, Classifieds, Advertising For Small Business,
> what I like best, is that the posts dont roll off every couple of hours,
> they stay on for 3 days, so you only have to repost twice a week.
>
> if you want to post to a new +++ try
No thanks. This is a technical newsgroup, please do not post advertisements
here, it is very bad netiquette.
anm
--
$ENV{PAGER} = 'cat';
system perldoc => '-t', '-F', $0;
=head1
Just another Perl Hacker
------------------------------
Date: Thu, 28 Sep 2000 01:55:09 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: I Found 1000s Of Free Hits at MDS 5796
Message-Id: <Pine.GHP.4.21.0009280147540.27604-100000@hpplus03.cern.ch>
On Wed, 27 Sep 2000, Andrew N. McGuire wrote:
> No thanks. This is a technical newsgroup, please do not post advertisements
> here, it is very bad netiquette.
Unfortunately there seem to be increasing numbers of desperate
spammers who are trying their very best to get blacklisted by
discerning customers (they couldn't afford to have to deal with
discerning customers, after all) and are hell-bent on finding the
0.0001% (or however few readers it is) who are naive enough to do
business with spammers.
Asking that kind of vermin to kindly follow netiquette is like
asking... well, analogies never quite work out, but I'm sure you can
supply your own.
(whatever became of NoCem...?)
------------------------------
Date: Thu, 28 Sep 2000 10:11:21 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Is there some free perl script packget for download?
Message-Id: <MPG.143d37b6685526d39897d1@localhost>
i0519@my-deja.com wrote ..
>Something like transfer a DOC file into a html, or upload some user
>file.
no
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Wed, 27 Sep 2000 17:42:52 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Is this routine OK?
Message-Id: <Pine.LNX.4.21.0009271734260.18929-100000@hawk.ce.mediaone.net>
On Wed, 27 Sep 2000, Rick Freeman quoth:
RF> I use this little routine quite a bit in various scripts to save data
RF> to disk (in my quirky but useful datafile formats). I'm not very savy
RF> about file locking and concurrent file accesses, though, and wonder if
RF> I'm doing enough to avoid troubles. Would greatly appreciate feedback
RF> on that issue and anything else you see here. I'm including the
RF> routines I use to read the data files, as well, just for reference.
[ snip ]
RF> # Reads a newline separated array from disk
RF> sub listit {
RF> my $file = shift;
RF> my @data = ();
RF>
RF> open(HANDLE, "$file");
^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open(HANDLE, $file) || die "can't read $file: $!\n";
The biggest thing wrong I see is that in several critical places you have
thrown error-checking by the wayside. The above quote is one of them. Also
in the above quote, the quotes around $file are superfluous. The question
you have to ask yourself is what can you not afford to have fail in your
script (open, unlink, flock, ...). Error check those things that you can't
afford to have fail, or would like to be notified about. If in doubt, check
for errors.
(This is just from a quick glance though.)
Regards,
anm
--
$ENV{PAGER} = 'cat';
system perldoc => '-t', '-F', $0;
=head1
Just another Perl Hacker
------------------------------
Date: Wed, 27 Sep 2000 16:52:24 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Is this routine OK?
Message-Id: <39D28838.762E6ADC@ipac.caltech.edu>
Rick Freeman wrote:
>
> I use this little routine quite a bit in various scripts to save data
> to disk (in my quirky but useful datafile formats). I'm not very savy
> about file locking and concurrent file accesses, though, and wonder if
> I'm doing enough to avoid troubles. Would greatly appreciate feedback
> on that issue and anything else you see here.
[ Code excised ]
Together these ...
perldoc -f flock
perldoc -q lock
perldoc perlopentut
... tell you more than you asked. Read up.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: 27 Sep 2000 23:38:34 GMT
From: daniel@chetlin.com (Daniel Chetlin)
Subject: Re: lowercase and UPPERCASE
Message-Id: <8qu0dq02kav@news2.newsguy.com>
On Wed, 27 Sep 2000 11:42:33 -0400,
Jeff Pinyan <jeffp@crusoe.net> wrote:
>Remember, $ matches /\n?\z/
/(?=\n?\z)/
-dlc
------------------------------
Date: Wed, 27 Sep 2000 16:42:46 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Module load error
Message-Id: <39D285F6.27E6047@ipac.caltech.edu>
Waqar Hafiz wrote:
>
> I'm trying to run a perl script and getting the following error:
>
> Can't load module DBI, dynamic loading not available in this perl.
> (You may need to build a new perl executable which either supports
> dynamic loading or has the DBI module statically linked into it.)
> Can some one please tell me how to overcome this problem without
> recompiling perl.
Since the error message pretty clearly tells you that recompiling perl is the
only solution, I think you're hosed. The only option I see is write your own
pure perl version of DBI/DBD. Good luck.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Wed, 27 Sep 2000 16:00:53 -0700
From: Sarah Officer <OfficerS@aries.tucson.saic.com>
Subject: Re: MySQL vs. mSQL
Message-Id: <39D27C25.C7F56441@aries.tucson.saic.com>
Which database is "best" depends on your needs. I think if you poke
around the postgres site enough you'll find a page comparing their
features to other databases. Some of the other free databases do
the same. I *think* the postgres URL is www.postgresql.org. Figure
out your requirements before choosing.
Young Chi-Yeung Fan wrote:
>
> Want to add a few related questions...what's the best free database to use for
> web sites, and why? How does it / do they compare to databases like Oracle's?
>
> Michael Satkevich wrote:
>
> > Is MySQL better than mSQL? I see more books and references to MySQL, so I
> > am beginning to think I should be using MySQL.
> >
> > So far I have used mSQL on 2 sites. Should I switch to MySQL?
> >
> > Is another free database even better? PostGre??
> >
> > -Mike
------------------------------
Date: Wed, 27 Sep 2000 15:27:49 +0100
From: "Michael Budash" <mbudash@sonic.net>
Subject: need help with LWP/https/proxy
Message-Id: <tzuA5.80$QH1.85022@news.pacbell.net>
hey all -
has anyone out there ever used LWP to access a secure url thru a proxy? i
encounter a "communications error (-8192)" when doing so... anybody got a
clue? this is a high profile project at my current contract - i'd like to
come out a hero!
tia -
michael
------------------------------
Date: Thu, 28 Sep 2000 11:38:44 +1100
From: "Troy Rasiah" <troyr@vicnet.net.au>
Subject: perl cookies
Message-Id: <xqwA5.7406$O7.142055@ozemail.com.au>
Hi there,
When i try to reset a cookies expire in IE it doesn't
reset..compared to when i do it in Netscape
For example...
my $cookie_expire='+1s' ;
$cookie = $query->cookie(-name=>'OPENRD',
-value=>$session{_session_id},
-expires=>$cookie_expire,
-path=>'/',
-domain=>$cookie_domain);
print $query->header(-cookie=>$cookie);
If the cookie was set to 10 minutes then it will expire after 10 minutes
using IE.
With Netscape it resets the cookie expire to 1s
Anyone have any idea's?
Cheers
--
----------------------------------------------------------------------------
----------------
Troy Rasiah
Database/Web Developer
Vicnet
troyr@vicnet.net.au
----------------------------------------------------------------------------
----------------
------------------------------
Date: Wed, 27 Sep 2000 20:42:49 -0400
From: Sid Malhotra <sxm124@po.cwru.edu>
Subject: Programming the Perl DBI
Message-Id: <39D29409.3F62B0AF@po.cwru.edu>
I am looking to buy "Programming the PERL DBI: Database Programming with
PERL" by Alligator Descartes and Tim Bruce. I need to start writing
scripts with better databases than the plain text that I am using right
now.
Any suggestions? Comments?
Sid.
sxm124@cwru.edu
ps: It is not I, but BARNES & NOBLE.com that calls it PERL. Amazon.com
says "Perl". :-)
------------------------------
Date: Thu, 28 Sep 2000 11:46:18 +1100
From: "Troy Rasiah" <troyr@vicnet.net.au>
Subject: Re: Programming the Perl DBI
Message-Id: <CxwA5.7410$O7.141998@ozemail.com.au>
use Postgres or MYSQL
both free and open source
--
----------------------------------------------------------------------------
----------------
Troy Rasiah
Database/Web Developer
Vicnet
troyr@vicnet.net.au
----------------------------------------------------------------------------
----------------
"Sid Malhotra" <sxm124@po.cwru.edu> wrote in message
news:39D29409.3F62B0AF@po.cwru.edu...
> I am looking to buy "Programming the PERL DBI: Database Programming with
> PERL" by Alligator Descartes and Tim Bruce. I need to start writing
> scripts with better databases than the plain text that I am using right
> now.
>
> Any suggestions? Comments?
>
> Sid.
> sxm124@cwru.edu
>
> ps: It is not I, but BARNES & NOBLE.com that calls it PERL. Amazon.com
> says "Perl". :-)
>
------------------------------
Date: Wed, 27 Sep 2000 17:52:27 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Programming the Perl DBI
Message-Id: <39D2964B.82BB7B0@vpservices.com>
Sid Malhotra wrote:
>
> I am looking to buy "Programming the PERL DBI: Database Programming with
> PERL" by Alligator Descartes and Tim Bruce. I need to start writing
> scripts with better databases than the plain text that I am using right
> now.
>
> Any suggestions?
Buy the book! Read the book!
> Comments?
If you want to start playing with the DBI immediately, get DBD::RAM and
just start using the DBI examples without having to worry about creating
files or installing an rdbms. Or use that same DBD on your existing
text files with DBI syntax. When you're ready to move to a real
database, just install the rdbms, switch DBDs and all your practice
scripts should work pretty much as is.
> ps: It is not I, but BARNES & NOBLE.com that calls it PERL. Amazon.com
> says "Perl". :-)
Ah, but the book itself spells it Perl. :-)
--
Jeff
------------------------------
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 4452
**************************************