[13849] in Perl-Users-Digest
Perl-Users Digest, Issue: 1259 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 2 21:05:36 1999
Date: Tue, 2 Nov 1999 18:05:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941594720-v9-i1259@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 2 Nov 1999 Volume: 9 Number: 1259
Today's topics:
Re: * Robust NEWS Application needed ASAP *** (Kragen Sitaker)
Re: * Robust NEWS Application needed ASAP *** (Matthew Bafford)
Re: Book suggestions <uri@sysarch.com>
Re: Capturing data returned after a POST <makkulka@cisco.com>
Re: Card shuffling (Abigail)
Re: Card shuffling (Abigail)
chdir (perl v4) <jim.chappellNOjiSPAM@tivoli.com.invalid>
Re: comparing text with words (Abigail)
Re: comparing text with words (Abigail)
Re: Counting multiple macthing vars in an array <lr@hpl.hp.com>
Re: Counting multiple macthing vars in an array <s1.brown@qut.edu.au>
Re: DBI error: ORA-06401: NETCMN: invalid driver design <makkulka@cisco.com>
Re: Determining Open Mode <rootbeer@redcat.com>
Re: Extracting just the date from a string (Abigail)
File::Find <shon@mad.scientist.com>
Re: File::Find <shon@mad.scientist.com>
Re: File::Find (Bill Moseley)
Re: Formatting a Date Properly <lr@hpl.hp.com>
Re: Formatting a Date Properly (Kragen Sitaker)
Re: Formatting a Date Properly <lr@hpl.hp.com>
getting a file size <jazz108@yahoo.com>
Re: help with simple registration CGI script (Kragen Sitaker)
Re: Hiding Perl Scripts? (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 02 Nov 1999 23:24:40 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: * Robust NEWS Application needed ASAP ***
Message-Id: <YoKT3.22554$23.1159458@typ11.nn.bcandid.com>
In article <381EEAC3.76078185@baselogic.com>,
Mick Knutson <mick.knutson@headland-media.com> wrote:
>I need a robust way to manage news on my web site.
>I have multiple columnists, and want to manage the news via a web page.
Why don't you use Perl?
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Wed, 03 Nov 1999 00:12:30 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: * Robust NEWS Application needed ASAP ***
Message-Id: <slrn81ut10.b1g.*@dragons.duesouth.net>
Mick Knutson <mknutson@baselogic.com>, thinking with his hands, posted
the following to comp.lang.perl.misc:
: I need a robust way to manage news on my web site.
: I have multiple columnists, and want to manage the news via a web page.
I'm sorry, but your Perl question got cut out of your post.
: Mick Knutson
--Matthew
------------------------------
Date: 02 Nov 1999 18:09:40 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Book suggestions
Message-Id: <x7r9i88p8r.fsf@home.sysarch.com>
>>>>> "DC" == David Cassell <cassell@mail.cor.epa.gov> writes:
DC> Actually, I just received _free_ from Manning a copy of
DC> Andrew Johnson's book "Elements of Programming with Perl".
DC> It looks like it may be a very good choice for a true beginner
DC> who has never programmed before. It doesn't attempt to be
DC> an encyclopedic presentation, but it does seem to carefully
DC> cover most of the key topics. I'll give you a more
DC> definite statement after I have a chance to scan it.
funny, i just my free copy. on FWP the author plugged it and i mentioned
i wanted a copy to review and he sent me one. having a realtionship
already with manning from OOP helped. i hope to have time to look at it
soon. i hear good things about it. this might be the first serious
competitor to the llama.
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: Tue, 02 Nov 1999 17:25:11 -0800
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Capturing data returned after a POST
Message-Id: <381F8EF6.D539BB06@cisco.com>
David Taylor wrote:
> Problem with data being returned after some
> form-filling and initial processing:
>
.. { LOT OF CODE SNIPPED ..}
> read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
> @names = split(/\,/,$in);
> print "Content-type: text/html\n\n";
> foreach $name(@names) {
> print "$name<br>" ;
> }
> ### just to print on screen, for example, but to no avail.
> ### What am I doing wrong?
when u are using cgi.pm you need not do a read on STDIN and
read the POSTed name/value pairs etc. This is done for you
by CGI.pm and is in the cgi object.
you should do
@names = $query->param
foreach ( @names )
{
print "value of ", $_, " is ", $query->param( $_), "\n" ;
}
--
------------------------------
Date: 2 Nov 1999 19:35:37 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Card shuffling
Message-Id: <slrn81v4a2.tjn.abigail@alexandra.delanet.com>
Bennett Todd (bet@network.rahul.net) wrote on MMCCLIV September MCMXCIII
in <URL:news:slrn81u5d1.9ap.bet@localhost.localdomain>:
""
"" For the first one, the only slight improvement I see is that it adds a
"" check to optimize out the case of a null swap. I've no idea whether the
"" test costs enough to pay for itself. So of course now I have to time
"" 'em..... Meanwhile, the FAQ may call the latter one "bad", but I think it
"" wins on understandability, and that's sometimes worth sacrificing a little
"" performance for. So on to the benchmark. Here's the code I used:
""
"" #!/usr/bin/perl -w
"" use strict;
"" use Benchmark;
""
"" timethese(-10, {
"" FAQFY => sub {
"" my(@deck) = 0 .. 51;
"" my $i;
"" for ($i = @deck; --$i; ) {
"" my $j = int rand ($i+1);
"" next if $i == $j;
"" @deck[$i,$j] = @deck[$j,$i];
"" }
"" },
"" BFY => sub {
"" my(@deck) = 0 .. 51;
"" for my $i (0..$#deck-1) {
"" @deck[$i, $_]=@deck[$_, $i] for $i+rand($#deck-$i+1)
"" }
"" },
"" BS => sub {
"" my(@deck) = 0 .. 51;
"" my @shuffled = ();
"" push @shuffled, splice(@deck, rand(@deck), 1) while @deck;
"" },
"" });
""
"" Whitespace-squoze results:
""
"" Benchmark: running BFY, BS, FAQFY, each for at least 10 CPU seconds...
"" BFY: 20 wallclock secs (11.47usr+0.76sys=12.23 CPU)@373.67/s (n=4570)
"" BS: 17 wallclock secs (11.46usr+0.31sys=11.77 CPU)@805.44/s (n=9480)
"" FAQFY: 23 wallclock secs (14.07usr+0.50sys=14.57 CPU)@662.94/s (n=9659)
""
"" where BFY is my Fisher-Yates (swapping) shuffle, BS is my splice shuffle, and
"" FAQFY is the Fisher-Yates from the FAQ. I'm surprised all over. My splice
"" version is the speed winner. Maybe perl has noticed that I'm not doing
"" anything with the results and optimizing the whole shuffle out of existence? I
"" didn't think it was that brilliant. But if so, that says something for going
"" for the more understandable code:-).
""
"" Maybe implementation of rand scaling likes the pattern of rands better?
No, your array size is too small. Since splice() is a Perl primitive,
it's extremely fast compared to doing things in Perl, so you need to
use larger datasets to see the linear vs quadratic behaviour. Also note
that the Fisher Yates shuffle do the shuffling in situ - no need to
recreate the array each time; while the splice is destructive.
Here's a modified version of your benchmark, with a larger dataset:
#!/opt/perl/bin/perl -w
use strict;
use Benchmark;
my $size = 10000;
my @deck = 0 .. $size;
timethese (-30, {
FAQFY => sub {
my $i;
for ($i = @deck; --$i; ) {
my $j = int rand ($i+1);
next if $i == $j;
@deck[$i,$j] = @deck[$j,$i];
}
},
BFY => sub {
for my $i (0..$#deck-1) {
@deck[$i, $_]=@deck[$_, $i] for $i+rand($#deck-$i+1)
}
},
BS => sub {
my @d = @deck;
my @shuffled = ();
push @shuffled, splice(@d, rand(@d), 1) while @d;
},
});
Benchmark: running BFY, BS, FAQFY, each for at least 30 CPU seconds...
BS: 37 wallclock secs (33.97 usr + 0.00 sys = 33.97 CPU) @ 2.74/s (n=93)
BFY: 42 wallclock secs (33.98 usr + 0.01 sys = 33.99 CPU) @ 2.97/s (n=101)
FAQFY: 35 wallclock secs (31.65 usr + 0.00 sys = 31.65 CPU) @ 6.32/s (n=200)
"" I'm also kinda surprised at the amount of difference between my formulation
"" of Fisher-Yates and the FAQ's; as best I can tell, there's an extra test in
"" the FAQ's that will save a small fraction of the swaps, so it might be a win
"" or a lose (which costs more, the test or the swaps that it saves); and the
"" FAQ Fisher Yates counts in the opposite direction, back from the end where
"" I count forwards. I can't see either of those explaining the factor of 1.77
"" difference.
Well, yours has 2 for loops. Granted, the inner one only has one
element, but Perl still has to localize $_, assign $i + rand ($#deck
- $i + 1) to $_, and test for the end of the loop. You also have 3
additions/subtractions, where the FAQ solution has one.
If we get rid for the inner for loop, and Benchmark:
BFY2 => sub {
for my $i (0..$#deck-1) {
my $j = $i+rand($#deck-$i+1);
@deck[$i, $j]=@deck[$j, $i];
}
},
we get:
Benchmark: running BFY, BFY2, BS, FAQFY, each for at least 30 CPU seconds...
BS: 36 wallclock secs (33.62 usr + 0.00 sys = 33.62 CPU) @ 2.71/s (n=91)
BFY: 38 wallclock secs (34.27 usr + 0.00 sys = 34.27 CPU) @ 2.98/s (n=102)
BFY2: 35 wallclock secs (31.77 usr + 0.00 sys = 31.77 CPU) @ 6.11/s (n=194)
FAQFY: 34 wallclock secs (31.54 usr + 0.00 sys = 31.54 CPU) @ 6.31/s (n=199)
See? Almost as fast as the FAQ solution now. It was the 'for' that
did it.
There are other cases where using a more inefficient algorithm is
actually faster than a more efficient one, for reasonable sized datasets,
just because C is so much faster than Perl.
Consider sorting a large array, with many, many duplicates. Normally,
sorting is O (N log N), but if we only have U different values, we
can sort in O (N + U log U) time, by creating U buckets, counting how
many elements are in each bucket, sorting the buckets, then rebuilding
the array. A variation on counting sort - except that you don't know the
buckets in advance. But the linear Perl overhead is rather large compared
to the C speed of the N log N sort.
Here's my benchmark:
#!/opt/perl/bin/perl -w
use strict;
use Benchmark;
my $iter = 1 << ($ARGV [0] || 4);
my $items = 1 << ($ARGV [1] || 8);
my $size = 1 << ($ARGV [2] || 16);
my @items = map {join '' => map {chr rand 256} 1 .. 3 + rand 4} 1 .. $items;
@::bigarr = map {$items [rand $items]} 1 .. $size;
print "Size = " . @::bigarr . " in " . @items . " buckets\n";
timethese $iter => {
def_blank => 'my @sort = @::bigarr',
def => 'my @sort = sort @::bigarr;',
uniq_blank => 'my @sort = do {my %h;
$h {$_} ++ for @::bigarr;
map {($_) x $h {$_}} keys %h}',
uniq => 'my @sort = do {my %h;
$h {$_} ++ for @::bigarr;
map {($_) x $h {$_}} sort keys %h}',
};
__END__
And here are some results:
Size = 4096 in 64 buckets
Benchmark: timing 256 iterations of def, def_blank, uniq, uniq_blank...
def: 6 wallclock secs ( 5.81 usr + 0.01 sys = 5.82 CPU)
def_blank: 3 wallclock secs ( 2.35 usr + 0.00 sys = 2.35 CPU)
uniq: 7 wallclock secs ( 6.49 usr + 0.00 sys = 6.49 CPU)
uniq_blank: 7 wallclock secs ( 6.42 usr + 0.00 sys = 6.42 CPU)
Size = 16384 in 64 buckets
Benchmark: timing 256 iterations of def, def_blank, uniq, uniq_blank...
def: 32 wallclock secs (28.80 usr + 0.43 sys = 29.23 CPU)
def_blank: 12 wallclock secs (10.72 usr + 0.34 sys = 11.06 CPU)
uniq: 29 wallclock secs (27.03 usr + 0.00 sys = 27.03 CPU)
uniq_blank: 33 wallclock secs (27.09 usr + 0.00 sys = 27.09 CPU)
Size = 65536 in 64 buckets
Benchmark: timing 256 iterations of def, def_blank, uniq, uniq_blank...
def: 148 wallclock secs (128.20 usr + 1.56 sys = 129.76 CPU)
def_blank: 49 wallclock secs (43.68 usr + 1.83 sys = 45.51 CPU)
uniq: 119 wallclock secs (109.17 usr + 0.02 sys = 109.19 CPU)
uniq_blank: 120 wallclock secs (109.03 usr + 0.03 sys = 109.06 CPU)
As you can see, the 'uniq' algorithm hard spends any time sorting, while
the 'def' algorithm spends most of its time sorting. Unfortunally, the
Perl setup to only sort a small array is so large, that the size where
the gain might be significant is close to the size where the program
would start swapping....
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 2 Nov 1999 19:36:27 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Card shuffling
Message-Id: <slrn81v4bl.tjn.abigail@alexandra.delanet.com>
Larry Rosler (lr@hpl.hp.com) wrote on MMCCLIV September MCMXCIII in
<URL:news:MPG.1288e43c7a0c5cfb98a191@nntp.hpl.hp.com>:
==
== Yes, that's the slight improvement I meant. Your benchmark seems to
== indicate that testing for redundant swaps instead of just doing them is
== a timesaver.
Eh, no, that's not the only difference. The 'for' is the killer.
Abigail
--
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 02 Nov 1999 12:56:45 -0800
From: JRC <jim.chappellNOjiSPAM@tivoli.com.invalid>
Subject: chdir (perl v4)
Message-Id: <012072c6.81e80413@usw-ex0109-069.remarq.com>
we use
chdir ("/etc/blahblah")
at the begining of a program. Later a
system("xyz");
returns incorrect results. As I said above, we're on a
SUN Ultra runnig perl 4. (Don't ask why, that's a legacy
issue!)
Jim
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
------------------------------
Date: 2 Nov 1999 17:15:25 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: comparing text with words
Message-Id: <slrn81us36.ren.abigail@alexandra.delanet.com>
Ala Qumsieh (aqumsieh@matrox.com) wrote on MMCCLIV September MCMXCIII in
<URL:news:x3y904gucd3.fsf@tigre.matrox.com>:
%%
%% The (undocumented?) use of *anything* as a delimiter is useful for
%% obfuscation also:
%%
%% tr s\r\n\t s ss;
%%
%% I don't know if this is supported 100%, but if it is, then I think I
%% found a bug:
%%
%% % perl -wl
%% $_ = "this is\na nice \nthing ";
%% tr s\r\n\t s ss;
%% print;
%% __END__
%% this is a nice thing
%%
%%
%% Good. Let's change the delimiter from 's' to 't':
%%
%% % perl -wl
%% $_ = "this is\na nice \nthing ";
%% tr t\r\n\t t ts;
%% print;
%% __END__
%% his is a nice hing
Not a bug. tr t\r\n\t t ts; is equivalent to tr /\r\nt / /s; so,
of course it changes the t to a space.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 2 Nov 1999 17:21:56 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: comparing text with words
Message-Id: <slrn81usfe.tjn.abigail@alexandra.delanet.com>
Ala Qumsieh (aqumsieh@matrox.com) wrote on MMCCLIV September MCMXCIII in
<URL:news:x3yaeowucyo.fsf@tigre.matrox.com>:
""
"" I rarely see the use of y/// instead of tr/// for translation (or
"" transliteration, but let's not start another thread about that).
""
"" I wonder why? Unix?
RTFM.
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 2 Nov 1999 15:47:56 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Counting multiple macthing vars in an array
Message-Id: <MPG.1289180b9de3357698a195@nntp.hpl.hp.com>
In article <MPG.12890c14c9f12d6e98a192@nntp.hpl.hp.com> on Tue, 2 Nov
1999 14:56:53 -0800, Larry Rosler <lr@hpl.hp.com> says...
...
> > # Remove quotes and dashes from the array
> > my @foo = map {join "",(split '"|-')} grep {!/^\s*$/} @ary;
> >
> > foreach (@foo){
>
> while (<INF>) { # Process one line at a time.
> next unless /\S/; # Ignore blank lines.
> s/"\|-//g; # Strip garbage (your code above).
Oh, sh.t! I over-corrected for that frigging string literal in the
split instead of a regex. How I wish that drew a warning! I thought he
really wanted to remove the strings '"|-', for whatever reason, hence
the parenthetical comment.
The correct code is:
s/"|-//g; # Strip '"' and '-'.
Or much better, as Kragen observed and as I have been touting for a long
time,
tr/"-//d; # Strip '"' and '-'.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 3 Nov 1999 00:20:28 GMT
From: shane <s1.brown@qut.edu.au>
Subject: Re: Counting multiple macthing vars in an array
Message-Id: <8E73692DEs1brownquteduau@news.qut.edu.au>
Hawkwynd <hawkwynd@my-deja.com> wrote in <7vnjhk$hea$1@nnrp1.deja.com>:
>So, with that, I need to be able to print a report, that
>shows all OPID's, and how many times each OPID shows up
>in that entire list. However, I only need to show the
>OPID once, with it's corresponding hit count.
>Here's the code I've got so far...
> foreach (@foo){
...
do stuff to get $opid
...
> push @opslist, $opid;
> }
># count the OPIDs, how many of each?
> foreach $item(@opslist){
> $count = grep {$_ eq $item} @opslist;
> print "$item $count \n";
> }
(My first offering....Luminaries please be gentle.)
Creating an array of OPIDs seems unnecessary.
You could instead make a simple counter
from a hash, to ensure that each OPID count
returned at the finale is unique.
A simplified example follows.
use strict;
my %opids;
while (<DATA>) {
chomp ;
$opids{$_}++; ## the counter.
}
print"OPIDS\tCOUNT\n";
foreach (sort keys (%opids)) {
print "$_\t$opids{$_}\n";
}
__DATA__
1234
1234
1234
1236
1236
6666
6666
6666
------------------------------
Date: Tue, 02 Nov 1999 17:38:29 -0800
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: DBI error: ORA-06401: NETCMN: invalid driver designator
Message-Id: <381F9215.78A207C4@cisco.com>
Chris Beels wrote:
> Hi,
>
> I'm trying to connect to an Oracle DB using DBI (Solaris) and am receiving
> the error mentioned above. I've tried both of the following connection
> strings:
> $dbh = DBI->connect('dbi:Oracle:','$username@T:$host:$sid','$password')
This will not work because of using ' and '. Values of username and password
will never be passed to the function unless you use " and ".
> and
> $dbh = DBI->connect("DBI:Oracle:host=$host:sid=$sid", $username, $password)
as per perldoc DBI
Examples of $data_source values:
dbi:DriverName:database_name
dbi:DriverName:database_name@hostname:port
dbi:DriverName:database=database_name;host=hostname;port=port
your connect () statement does not seem to be following this scheme for driver
naming.
Also try running tnsping from your machine to see if the database you are
trying
to connect is really reachable. Maybe some entries in your tnsnames.ora file
are missing
Good luck
-
------------------------------
Date: Tue, 2 Nov 1999 16:32:09 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Determining Open Mode
Message-Id: <Pine.GSO.4.10.9911021624120.29670-100000@user2.teleport.com>
On Tue, 2 Nov 1999, Jim Williams wrote:
> Given a filehandle, how do I tell if it was originally opened to be
> read from, written to, both, etc.?
It's much like knowing whether you may have a chocolate from the candy
box: You should ask whoever opened it to tell you. :-)
I'm actually serious; if your routine has been passed a filehandle, the
caller should be telling you what modes to use with it, if that's unknown.
But I suspect that the real answer is 'mu': Unask the question. It may be
that you should rethink your program design so as to avoid these mystery
filehandles.
Of course, you could try reading or writing zero bytes (with sysread or
syswrite) and see whether you get EBADF. But it's possible that that won't
work on all systems. Or maybe not _any_ systems - I haven't checked. :-)
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 2 Nov 1999 19:44:27 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Extracting just the date from a string
Message-Id: <slrn81v4ql.tjn.abigail@alexandra.delanet.com>
Larry Rosler (lr@hpl.hp.com) wrote on MMCCLIV September MCMXCIII in
<URL:news:MPG.1288acfe93f08e1498a18a@nntp.hpl.hp.com>:
\\
\\ It could also be done with a regular expression, but the 'split ..., 2'
\\ approach shold be just fine.
split, of course, uses a regular expression as well.
substr and index don't:
$date = substr $str => 2 + index $str => " ";
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 02 Nov 1999 23:35:51 GMT
From: Shon Stephens <shon@mad.scientist.com>
Subject: File::Find
Message-Id: <7vnsgn$oa0$1@nnrp1.deja.com>
Where is the documentation for the File::Find module?
I want to search a directory tree and search for files specified by a
scalar variable $foo. Then if the file ($foo) doesn't exist, print that
filename.
Any novel ideas? I think I could actually accomplish this myself if I
could just find the docs for File::Find.
--
Shon Stephens
UNIX Systems Administrator
shon@mad.scientist.com
"You want a piece of me?"
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 02 Nov 1999 23:59:55 GMT
From: Shon Stephens <shon@mad.scientist.com>
Subject: Re: File::Find
Message-Id: <7vntto$pei$1@nnrp1.deja.com>
In article <7vnsgn$oa0$1@nnrp1.deja.com>,
Shon Stephens <shon@mad.scientist.com> wrote:
> Where is the documentation for the File::Find module?
I found the documentation.
> I want to search a directory tree and search for files specified by a
> scalar variable $foo. Then if the file ($foo) doesn't exist, print
that
> filename.
Still no clue how to accomplish this. File::Find::name assumes that the
value of $_ doesn't change(?).
--
Shon Stephens
UNIX Systems Administrator
shon@mad.scientist.com
"You want a piece of me?"
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 2 Nov 1999 16:05:41 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: File::Find
Message-Id: <MPG.12891c35e4bf280b989833@nntp1.ba.best.com>
Shon Stephens (shon@mad.scientist.com) seems to say...
> Where is the documentation for the File::Find module?
It's in the module.
perldoc File::Find
--
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.
------------------------------
Date: Tue, 2 Nov 1999 15:40:15 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Formatting a Date Properly
Message-Id: <MPG.12891638514d8f9f98a194@nntp.hpl.hp.com>
In article <9TJT3.22485$23.1156010@typ11.nn.bcandid.com> on Tue, 02 Nov
1999 22:48:37 GMT, Kragen Sitaker <kragen@dnaco.net> says...
> In article <7vn5qi$6hn$1@nnrp1.deja.com>, <reedjd@bitsmart.com> wrote:
...
> >perl -e '($d,$m,$y)=(localtime(time))[3..5];$m+=1;$y+=1900;print
> >sprintf "%4.0d%2.0d%2.0d\n",$y,$m,$d;'
print sprintf ...
is rather weird, because that' identical to
printf ...
> BTW, the stuff after the decimal point (zeroes here) is called the
> "precision" -- it's what you'd think it would be for %f, but for %d, it
> specifies a minimum width. So it's unnecessary, since that's what's
> before the decimal point too.
No, it doesn't specify a minimum width -- as you say, that's what the
field before the decimal point is for. It specifies the minimum number
of digits to appear -- i.e., the number of digits to which leading zeros
shall pad if needed.
Thus '%9.5d' would specify a number left-padded with zeros to at least
five digits, all right-adjusted in a space-filled nine-digit field.
Odd, but possible.
Which gives me another opportunity to bitch a bit about the alternate
ways of zero-filling an integer field, say for lexicographic sorting.
sprintf '%.10d' => $number;
sprintf '%010d' => $number;
These in fact do the same thing, but I keet seeing an octal number with
the decimal value 8 in the second form.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 Nov 1999 00:07:23 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Formatting a Date Properly
Message-Id: <%0LT3.22651$23.1169476@typ11.nn.bcandid.com>
In article <MPG.12891638514d8f9f98a194@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <9TJT3.22485$23.1156010@typ11.nn.bcandid.com> on Tue, 02 Nov
>1999 22:48:37 GMT, Kragen Sitaker <kragen@dnaco.net> says...
>> BTW, the stuff after the decimal point (zeroes here) is called the
>> "precision" -- it's what you'd think it would be for %f, but for %d, it
>> specifies a minimum width. So it's unnecessary, since that's what's
>> before the decimal point too.
>
>No, it doesn't specify a minimum width -- as you say, that's what the
>field before the decimal point is for. It specifies the minimum number
>of digits to appear -- i.e., the number of digits to which leading zeros
>shall pad if needed.
Ahh. And so %.3d is equivalent to %03d, but you can do things like
%5.2d, which has a minimum width of five, but a minimum of two digits.
Spiffy. Thanks.
>These in fact do the same thing, but I keet seeing an octal number with
>the decimal value 8 in the second form.
Perhaps using leading zeroes to *mean* something was unwise of
Kernighan and Ritchie.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Tue, 2 Nov 1999 16:33:24 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Formatting a Date Properly
Message-Id: <MPG.128922b05ffb628e98a196@nntp.hpl.hp.com>
In article <%0LT3.22651$23.1169476@typ11.nn.bcandid.com> on Wed, 03 Nov
1999 00:07:23 GMT, Kragen Sitaker <kragen@dnaco.net> says...
> In article <MPG.12891638514d8f9f98a194@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
...
> >These in fact do the same thing, but I keep seeing an octal number with
> >the decimal value 8 in the second form.
>
> Perhaps using leading zeroes to *mean* something was unwise of
> Kernighan and Ritchie.
Don't blame either of them. Many hands went into the specification of
the Standard C Library.
In this case, the leading-zero flag came first, and was deemed clever.
The '%w.pd' specification came later, and was deemed more powerful, as
you noted. But, just as now in Perl, once in, never out.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 Nov 1999 01:05:43 GMT
From: "n.thiyagarajan" <jazz108@yahoo.com>
Subject: getting a file size
Message-Id: <381F8D9C.E8EBE400@yahoo.com>
i'm new to perl...
i'm trying to get the size of a file by using the file test -s
$filesize = -s $filename;
when i try to print the file size nothing is printed.
any thoughts???
jazz108@yahoo.com
------------------------------
Date: Tue, 02 Nov 1999 23:24:15 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: help with simple registration CGI script
Message-Id: <zoKT3.22553$23.1162005@typ11.nn.bcandid.com>
In article <7vmpbp$sqp$1@nnrp1.deja.com>, <muhudin@my-deja.com> wrote:
>My teacher gave me an assignment. And I really need help. Please help. I
>want a simple CGI registration script
First, learn about CGI. If you don't understand the Web, read
http://photo.net/wtr/thebook/, which should probably take about six
hours. Then take a look at http://photo.net/wtr/cgi-unix.html to learn
CGI itself, which is very short and sweet and should take you minutes.
Then ignore all of what you have just learned about decoding form data
and read the docs for CGI.pm. If you have Perl installed, you can type
perldoc CGI, and you can probably generate decent printed output of the
CGI.pm documentation via some sequence of commands depending on what
you have installed on your system. (I.e. if you have LaTeX, pod2latex
followed by latex and dvips is probably best, and if you have groff or
troff but not LaTeX, pod2man followed by groff -Tps -mandoc is probably
best, and if you have neither, you can probably print
http://www-genome.wi.mit.edu/ftp/distribution/software/WWW/cgi_docs.html
from your web browser.)
Then when you have problems with your CGI scripts -- and probably even
if you don't -- you should read the Perl CGI programming FAQ at
http://www.perl.com/CPAN-local/doc/FAQs/cgi/perl-cgi-faq.html and the
Idiot's Guide to Solving Perl/CGI Problems at
http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html (also
available from other CPAN sites, such as
ftp://ftp.epix.net/pub/languages/perl/doc/FAQs/cgi/idiots-guide.html.)
>It should have one text field for name, one for email, one for password
>and one more for re-enter password.
You will probably know how to do this after you have devoured the above
resources.
> Also the SQL commands that save that
>information in Oracle database.
I recommend Philip Greenspun's _SQL for Web Nerds_, at
http://photo.net/sql/. There is some duplication between this and his
guide to web publishing, but if you can learn stuff like this by
reading it only once, you're smarter than I am.
Oh, and you should probably use the DBI and DBD::* (DBD::Oracle I think in
your case) modules to interface your script with Oracle. (You can also
write the SQL statements to a temp file and spawn off an SQL
interpreter with that file as input.)
> Information on all registered members
>are kept in Oracle database NOT in Unix file.
Good idea.
From looking at the above, can you see why it is not possible to give a
full answer to your question on the newsgroup?
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 2 Nov 1999 19:56:07 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Hiding Perl Scripts?
Message-Id: <slrn81v5gh.tjn.abigail@alexandra.delanet.com>
LorainCounty.com Webmaster (webmaster@LorainCounty.com) wrote on MMCCLIV
September MCMXCIII in <URL:news:381F0086.C07A440B@LorainCounty.com>:
\\
\\ How could I hide the source code of a Perl Script so
\\ it can't be modified or viewed?
$ > script
HTH. HAND.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
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 1259
**************************************