[12406] in Perl-Users-Digest
Perl-Users Digest, Issue: 6006 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 15 17:07:26 1999
Date: Tue, 15 Jun 99 14:01:39 -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 Tue, 15 Jun 1999 Volume: 8 Number: 6006
Today's topics:
how to substitute a whole paragrah in a file jbell@263.net
Re: how to substitute a whole paragrah in a file (Tad McClellan)
Re: how to substitute a whole paragrah in a file (Greg Bacon)
Re: how to substitute a whole paragrah in a file <tchrist@mox.perl.com>
Re: I dont understand system calls (M.J.T. Guy)
Re: I dont understand system calls (Tad McClellan)
Re: Net::FTP & timeout - problem <grayku@my-deja.com>
param($variable) <james@britlinks.co.uk>
Re: parse a string in triplet ? <garethr@cre.canon.co.uk>
Re: removing $array[$i]Many Thank (Andrew Allen)
Re: removing $array[$i]Many Thank <tchrist@mox.perl.com>
Re: removing $array[$i]Many Thank (Larry Rosler)
Re: removing $array[$i]Many Thank (Tad McClellan)
Saving Structures <sherlock@genome.stanford.edu>
Re: Saving Structures (Greg Bacon)
Re: Saving Structures (brian d foy)
Setting up MS Visual Studio for Perl <james.wiltshire@lexis-nexis.com>
single vs. double quotes (Weborium)
Re: single vs. double quotes (Greg Bacon)
Re: single vs. double quotes (brian d foy)
Re: single vs. double quotes (Jerome O'Neil)
sprintf padding with zeroes <john.wood@diamond.co.uk>
Re: sprintf padding with zeroes <uri@sysarch.com>
Re: sprintf padding with zeroes <tchrist@mox.perl.com>
SQL statement in Perl paulm@dirigo.com
Re: SQL statement in Perl (brian d foy)
Re: taint checking setuid error message <john@nonet.com>
There is a smarter way, but i dont know how. <martin@adoma.se>
Re: There is a smarter way, but i dont know how. (Greg Bacon)
Re: There is a smarter way, but i dont know how. <martin@adoma.se>
Re: There is a smarter way, but i dont know how. <tchrist@mox.perl.com>
Re: There is a smarter way, but i dont know how. (brian d foy)
UDP broadcasts in Win32?? <MurphKE1@aplmsg.jhuapl.edu>
Re: What is functional difference between .pm and .pl? <gbartels@xli.com>
Re: What is functional difference between .pm and .pl? <tchrist@mox.perl.com>
Re: What is functional difference between .pm and .pl? <upsetter@ziplink.net>
WIN32 USERADMIN DOESN'T WORK (sam@cheapnet.co.uk)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Jun 1999 17:59:50 GMT
From: jbell@263.net
Subject: how to substitute a whole paragrah in a file
Message-Id: <7k64af$t2e$1@nnrp1.deja.com>
Hi,
How can I substitute a paragraph in a file
with a new paragraph?
Or how can I insert a paragraph in a file?
Thanks in advance!
---
Regards,
Jim B.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 15 Jun 1999 10:35:19 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to substitute a whole paragrah in a file
Message-Id: <7bo5k7.tje.ln@magna.metronet.com>
jbell@263.net wrote:
: How can I substitute a paragraph in a file
: with a new paragraph?
You have to tell us how to identify what you mean by "paragraph"...
: Or how can I insert a paragraph in a file?
Perl FAQ, part 5:
"How do I change one line in a file/
delete a line in a file/
insert a line in the middle of a file/
append to the beginning of a file?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Jun 1999 19:52:42 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: how to substitute a whole paragrah in a file
Message-Id: <7k6aua$5kt$2@info2.uah.edu>
In article <7k64af$t2e$1@nnrp1.deja.com>,
jbell@263.net writes:
: How can I substitute a paragraph in a file
: with a new paragraph?
Imagine that you are relaying a message to someone for me. For whatever
reason, I am writing each paragraph of the message on a separate sheet
of paper. How would you substitute one paragraph for another in that
situation?
: Or how can I insert a paragraph in a file?
How would you insert a paragraph into my message?
Greg
--
Sam: What'd you like, Normie?
Norm: A reason to live. Gimmie another beer.
------------------------------
Date: 15 Jun 1999 14:26:05 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how to substitute a whole paragrah in a file
Message-Id: <3766b6dd@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
Cursed to torture himself and all of Usenet by using that embarrassingly
inadequate bloatware newsreader, Mozilla/4.0 (compatible; MSIE 5.0;
Windows NT; DigExt), jbell@263.net writes in comp.lang.perl.misc:
:How can I substitute a paragraph in a file
:with a new paragraph?
:
:Or how can I insert a paragraph in a file?
Is there something particularly unclear about the second question of the
standard perlfaq5 manpage shipped with every Perl system on inserting
or deleting elements from text files, or the documentation on the $/
variable in the standard perlvar manpage shipped with every Perl system,
or the documentation of the -0 command-line option in the standard
perlrun manpage shipped with every Perl system?
--tom
--
"Software is like sex: It's better when it's free." (Linus Torvalds, from
FSF T-shirt)
"I just found out that the brain is like a computer. If that's true, then
there really aren't any stupid people. Just people running Windows
------------------------------
Date: 15 Jun 1999 17:50:36 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: I dont understand system calls
Message-Id: <7k63pc$f8n$1@pegasus.csx.cam.ac.uk>
Mark Conlin <Mark.Conlin@bridge.bellsouth.com> wrote:
>I am having problems understanding the system command.
>
>I want to use system to look for a file, How can I get
>the results from
>
>system("ls"); or
>system("find", "myfile");
Unless you're just working on a quick-and-dirty one off script, you
ought to consider using the File::Find module instead.
Mike Guy
------------------------------
Date: Tue, 15 Jun 1999 10:02:13 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: I dont understand system calls
Message-Id: <5dm5k7.fde.ln@magna.metronet.com>
Mark Conlin (Mark.Conlin@bridge.bellsouth.com) wrote:
: I figured it out myself
Good for you!
Most folks only find out about it after reading the documentation
for the system() function that you were using.
If you had tried that first, you would have had your answer
even faster!
: the trick is to use backticks
"This is NOT what you want to use to capture the output
from a command, for that you should use merely backticks"
Right there in the docs, waiting for you to read it...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Jun 1999 18:30:31 GMT
From: Kurt Gray <grayku@my-deja.com>
Subject: Re: Net::FTP & timeout - problem
Message-Id: <7k6648$tqn$1@nnrp1.deja.com>
I think the issue is the ftp connection is never made,
so the $ftp object doesn't exist, so when you try to
do something like $ftp->login() perl then quits because
you're trying to invoke a method on an undefined object.
I think the solution is something like this
$ftp = Net::FTP->new("some.host.name", Timeout => 120);
if ($ftp) {
$ftp->login("anonymous","me@here.there");
$ftp->cwd("/pub");
$ftp->get("that.file");
$ftp->quit;
} else {
print "Could not open FTP connection within 120 seconds";
}
Kurt
http://linux.davecentral.com/
>
> i'm using Net::FTP module. And i have problem with timeout
> when I downloading file and timeout elapsed, program is terminated
> and control is not returned to my program.
>
> Can somebody help ?
>
> thanks Vaq
>
> $ftp = Net::FTP->new("some.host.name");
> $ftp->login("anonymous","me@here.there");
> $ftp->cwd("/pub");
> $ftp->get("that.file");
> <-timeout = exit ????
> $ftp->quit;
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 15 Jun 1999 19:07:46 +0100
From: James Stewart <james@britlinks.co.uk>
Subject: param($variable)
Message-Id: <ant151846256Lh==@ch0128.charis.co.uk>
Hi,
I'm trying to read a list of fields from a form using CGI.pm. The fields
are named
NDD1, NDD2 ... NDD10 etc. and I want to make it easy to develop my code
as the page grows.
The variable $entriesone contains the final form number and I tried to
use the following code snippet to move the values to an array. The only
problem is that it doesn't seem to receive anything into $NW.
for ($loop=1; $loop<=$entriesone; $loop++) {
$variable = "NDD".$loop;
my $NW = param($variable);
push @NWONE, $NW;
}
James.
--
James Stewart - james@britlinks.co.uk | "Telecom ignored us and
The Britlinks - http://www.britlinks.co.uk | democracy has died."
Phantom Tollbooth - http://www.tollbooth.org | -- Fat And Frantic
Sixpence None The Richer in the UK - http://www.britlinks.co.uk/sixpence/
------------------------------
Date: Tue, 15 Jun 1999 19:40:41 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
To: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: parse a string in triplet ?
Message-Id: <sik8t52qx2.fsf@cre.canon.co.uk>
Larry Rosler wrote:
> print join '+' => map substr($dna, 3 * $_, 3), 0 .. (length $dna)/3;
Gareth Rees wrote:
> $_ = $dna; s/\G([ACGT]{3})/$1+/g; print;
M.J.T. Guy wrote:
> Don't do that. It's O(N**2) while most of the other responses are
> O(N). And DNA strings can get quite long ...
I'm not sure you're right. The substr/map/join and s///g techniques
both appear to have roughly O(n) behaviour to the limits of memory, with
s///g being slightly faster:
use Benchmark;
foreach (4 .. 6) {
my $n = 10 ** $_;
print "\nResults for n = $n\n";
timethese(10, {
baseline => sub {
$dna = 'ACG' x $n;
},
substitute => sub {
$dna = 'ACG' x $n;
$dna =~ s/\G([ACGT]{3})/$1+/g;
},
join => sub {
$dna = 'ACG' x $n;
$dna = join '+' => map { substr($dna,3*$_,3) } 0 .. (length $dna)/3;
}
});
}
Results for n = 10000
Benchmark: timing 10 iterations of baseline, join, substitute...
baseline: 0 wallclock secs ( 0.02 usr + 0.00 sys = 0.02 CPU)
(warning: too few iterations for a reliable count)
join: 4 wallclock secs ( 2.87 usr + 0.01 sys = 2.88 CPU)
substitute: 2 wallclock secs ( 1.75 usr + 0.00 sys = 1.75 CPU)
Results for n = 100000
Benchmark: timing 10 iterations of baseline, join, substitute...
baseline: 1 wallclock secs ( 0.23 usr + 0.00 sys = 0.23 CPU)
(warning: too few iterations for a reliable count)
join: 35 wallclock secs (28.94 usr + 0.07 sys = 29.01 CPU)
substitute: 22 wallclock secs (17.76 usr + 0.01 sys = 17.77 CPU)
Results for n = 1000000
Benchmark: timing 10 iterations of baseline, join, substitute...
baseline: 3 wallclock secs ( 2.04 usr + 0.05 sys = 2.09 CPU)
join: 356 wallclock secs (288.56 usr + 1.24 sys = 289.80 CPU)
substitute: 212 wallclock secs (180.25 usr + 0.16 sys = 180.41 CPU)
I couldn't run the benchmark for n = 1e7; Perl quit with an "Out of
memory!" error.
I know that DNA sequences run to many megabases, so this suggests to me
that operating on long strings of bases may not be the right approach.
--
Gareth Rees
------------------------------
Date: 15 Jun 1999 18:05:19 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: removing $array[$i]Many Thank
Message-Id: <7k64kv$dp5$3@fcnews.fc.hp.com>
bernd1615@my-deja.com wrote:
: Dear Participants,
: I know there is the substitution operator in Perl.
: But is there also a delete operator ?
There's splice. But you really don't want to do that during a foreach
loop.
: foreach (@array) {
: if ( $_ =~ /#matches something/ ) {
: # delete $array[$i] }
: }
How about
@array=grep(!/something/,@array);
(BTW, $_=~ is redundant)
Andrew
------------------------------
Date: 15 Jun 1999 12:17:24 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: removing $array[$i]Many Thank
Message-Id: <376698b4@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
bernd1615@my-deja.com writes:
:I know there is the substitution operator in Perl.
:But is there also a delete operator ?
:foreach (@array) {
: if ( $_ =~ /#matches something/ ) {
: # delete $array[$i] }
: }
You mean:
foreach (@array) {
if (/matches something/ ) {
# delete $array[$i]
}
}
Because you never want to use "$_ =~ " -- it's highly confusing.
Also, it's very scary to see things deleted out from under oneself.
The standard Perl idiom for what you are attempting is:
@array = grep { !/matches something/ } @array;
--tom
--
I think it's a new feature. Don't tell anyone it was an accident. :-)
--Larry Wall on s/foo/bar/eieio in <10911@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Tue, 15 Jun 1999 11:13:52 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: removing $array[$i]Many Thank
Message-Id: <MPG.11d037b3f09d1f9d989bed@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7k5v9s$qr3$1@nnrp1.deja.com> on Tue, 15 Jun 1999 16:34:05
GMT, bernd1615@my-deja.com <bernd1615@my-deja.com> says...
> I know there is the substitution operator in Perl.
> But is there also a delete operator ?
Yes, but it is for elements of a hash. For elements of arrays there is
splice, pop and shift. For lists there is grep. What you want here is
grep.
> foreach (@array) {
> if ( $_ =~ /#matches something/ ) {
> # delete $array[$i] }
> }
@array = grep !/#matches something/, @array;
perldoc -f grep
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 15 Jun 1999 10:24:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: removing $array[$i]Many Thank
Message-Id: <cnn5k7.fde.ln@magna.metronet.com>
bernd1615@my-deja.com wrote:
: Dear Participants,
: I know there is the substitution operator in Perl.
: But is there also a delete operator ?
perldoc -f delete
On my system, that shows that Perl's delete() function
has to do with hashes, not arrays...
: foreach (@array) {
: if ( $_ =~ /#matches something/ ) {
: # delete $array[$i] }
: }
splice() can be made to do that, but beware changing an
array while iterating over it...
So I would just use grep() instead (UNTESTED):
@array = grep ! /#matches something/, @array;
Of course that deletes _all_ the matching elements, not
just one...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Jun 1999 12:27:38 -0700
From: Gavin Sherlock <sherlock@genome.stanford.edu>
Subject: Saving Structures
Message-Id: <150619991227384972%sherlock@genome.stanford.edu>
Hi,
If I have a cgi that needs to parse a number of files, to create
various hashes, there's a reasonable amount of overhead associated with
this. Is it possible to create the hashes once, and save them in some
kind of binary format, so that they can be rapidly read directly back
into memory?
Cheers,
Gavin Sherlock
------------------------------
Date: 15 Jun 1999 19:58:00 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Saving Structures
Message-Id: <7k6b88$5kt$3@info2.uah.edu>
In article <150619991227384972%sherlock@genome.stanford.edu>,
Gavin Sherlock <sherlock@genome.stanford.edu> writes:
: Is it possible to create the hashes once, and save them in some
: kind of binary format, so that they can be rapidly read directly back
: into memory?
Yep. Search the CPAN module list[*] and search for `Marshaling'.
* <URL:http://www.perl.com/CPAN/modules/00modlist.long.html>
Greg
--
If I wanted to listen to an asshole I woulda farted.
------------------------------
Date: Tue, 15 Jun 1999 16:55:37 -0400
From: brian@pm.org (brian d foy)
Subject: Re: Saving Structures
Message-Id: <brian-ya02408000R1506991655370001@news.panix.com>
In article <150619991227384972%sherlock@genome.stanford.edu>, Gavin Sherlock <sherlock@genome.stanford.edu> posted:
> If I have a cgi that needs to parse a number of files, to create
> various hashes, there's a reasonable amount of overhead associated with
> this.
use Storable; #or Data::Dumper, or MLDBM, or ...
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: 15 Jun 1999 19:05:01 GMT
From: "Jim Wiltshire" <james.wiltshire@lexis-nexis.com>
Subject: Setting up MS Visual Studio for Perl
Message-Id: <01beb761$f8f662c0$99120c8a@lnxwiltjs>
I've seen various posts indicating some Perl capability in MS Visual
Studio.
Can Visual Studio be setup to actually debug Perl?
In any case, what must be done to "tweek" Visual Studio for Perl?
TIA.
Jim
------------------------------
Date: 15 Jun 1999 19:58:44 GMT
From: weborium@aol.com (Weborium)
Subject: single vs. double quotes
Message-Id: <19990615155844.03733.00000103@ng-cs1.aol.com>
If I'm printing a statement using double quotes, and I want to use double
quotes in the statement, will using single quotes get the same effect? Like in
line 4 below, I want it to say <body bgcolor="black"> however I can't use (" ")
or it'll mess it up.
open (CUSTOM, ">/edited.htm");
flock (CUSTOM, 2);
print CUSTOM "<html><head><title>Console</title></head>\n";
print CUSTOM "<body bgcolor='black' text='white' link='yellow'>\n";
print CUSTOM "<h2>Welcome\n";
print CUSTOM "</body></html>\n";
flock (CUSTOM, 8);
close (CUSTOM);
.
.
---- How Microsoft would like to deal with Linux:
"Windows has detected a faster, superior, more efficient operating system on
your computer. Do you wish to delete it?
[yes] [yes]
----------
------------------------------
Date: 15 Jun 1999 20:05:26 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: single vs. double quotes
Message-Id: <7k6bm6$5kt$4@info2.uah.edu>
In article <19990615155844.03733.00000103@ng-cs1.aol.com>,
weborium@aol.com (Weborium) writes:
: If I'm printing a statement using double quotes, and I want to use
: double quotes in the statement, will using single quotes get the same
: effect?
That depends on who's interpreting the output. Still, there are several
ways to put double quotes in your output:
print "This sentence contains a phrase in \"double quotes\".\n";
print qq{This sentence contains a phrase in "double quotes".\n};
$dq = '"';
print "This sentence contains a phrase in ${dq}double quotes$dq.\n";
print "This sentence contains a phrase in ", '"double quotes"', ".\n";
# et cetera
TMTOWTDI! :-)
Greg
--
Let me guess: you're a Windows ``programmer'', aren't you? Do you
know why Unix programmers make more money than Windows ``programmers''?
Because we Unix people know how to read the manual -- and you don't.
-- Tom Christiansen
------------------------------
Date: Tue, 15 Jun 1999 16:52:49 -0400
From: brian@pm.org (brian d foy)
Subject: Re: single vs. double quotes
Message-Id: <brian-ya02408000R1506991652490001@news.panix.com>
In article <19990615155844.03733.00000103@ng-cs1.aol.com>, weborium@aol.com (Weborium) posted:
> If I'm printing a statement using double quotes, and I want to use double
> quotes in the statement, will using single quotes get the same effect? Like in
> line 4 below, I want it to say <body bgcolor="black"> however I can't use (" ")
> or it'll mess it up.
see my answer to your similar question in CIWAC.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: 15 Jun 1999 20:44:27 GMT
From: jeromeo@atrieva.com (Jerome O'Neil)
To: weborium@aol.com (Weborium)
Subject: Re: single vs. double quotes
Message-Id: <7k6dvb$kbo$1@brokaw.wa.com>
[Posted and mailed]
In article <19990615155844.03733.00000103@ng-cs1.aol.com>,
weborium@aol.com (Weborium) writes:
>
> If I'm printing a statement using double quotes, and
> I want to use double quotes in the statement, will using
> single quotes get the same effect?
Use the quote like operators q and qq:
print qq{I'm not afraid of "double quotes"!};
print q{Single quotes are 'groovy,' too!};
For all the exciting detail on quote like operators, see the perlop
document that came with your perl distribution.
Good Luck!
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Tue, 15 Jun 1999 21:41:48 +0100
From: "Paul Wood" <john.wood@diamond.co.uk>
Subject: sprintf padding with zeroes
Message-Id: <7k6drm$8r4$1@nclient3-gui.server.ntli.net>
Is there any way to force sprinf to pad with zeros? The Camel says that
"Padding is typicly done with spaces for strings and zeroes for numbers",
but no matter what, it always pads with spaces.
What I have is this:
$dig = 5;
return sprintf("%${dig}d", ++substr $line,0,$dig);
I've tried using int(), but it still pads with spaces.
Thanks in advance <cringe>...
-Paul.
------------------------------
Date: 15 Jun 1999 16:55:32 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: sprintf padding with zeroes
Message-Id: <x7d7yxfakb.fsf@home.sysarch.com>
>>>>> "PW" == Paul Wood <john.wood@diamond.co.uk> writes:
PW> Is there any way to force sprinf to pad with zeros? The Camel says that
PW> "Padding is typicly done with spaces for strings and zeroes for numbers",
PW> but no matter what, it always pads with spaces.
PW> What I have is this:
PW> $dig = 5;
PW> return sprintf("%${dig}d", ++substr $line,0,$dig);
this is an faq (which i wrote). find the latest FAQ on www.perl.com. it
will solve this problem and most of your future perl questions.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 15 Jun 1999 14:57:36 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: sprintf padding with zeroes
Message-Id: <3766be40@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
"Paul Wood" <john.wood@diamond.co.uk> writes:
:Is there any way to force sprinf to pad with zeros? The Camel says that
:"Padding is typicly done with spaces for strings and zeroes for numbers",
:but no matter what, it always pads with spaces.
$ MANPATH=/usr/local/perl/man man 3 sprintf
NAME
sprintf - formatted print into a string
SYNOPSIS
sprintf FORMAT, LIST
DESCRIPTION
Returns a string formatted by the usual `printf' conventions of
the C library function `sprintf'. See the sprintf(3) manpage or
the printf(3) manpage on your system for an explanation of the
general principles.
Perl does its own `sprintf' formatting--it emulates the C
function `sprintf', but it doesn't use it (except for floating-
point numbers, and even then only the standard modifiers are
allowed). As a result, any non-standard extensions in your local
`sprintf' are not available from Perl.
Perl's `sprintf' permits the following universally-known
conversions:
%% a percent sign
%c a character with the given number
%s a string
%d a signed integer, in decimal
%u an unsigned integer, in decimal
%o an unsigned integer, in octal
%x an unsigned integer, in hexadecimal
%e a floating-point number, in scientific notation
%f a floating-point number, in fixed decimal notation
%g a floating-point number, in %e or %f notation
In addition, Perl permits the following widely-supported
conversions:
%X like %x, but using upper-case letters
%E like %e, but using an upper-case "E"
%G like %g, but with an upper-case "E" (if applicable)
%b an unsigned integer, in binary
%p a pointer (outputs the Perl value's address in hexadecimal)
%n special: *stores* the number of characters output so far
into the next variable in the parameter list
Finally, for backward (and we do mean "backward") compatibility,
Perl permits these unnecessary but widely-supported conversions:
%i a synonym for %d
%D a synonym for %ld
%U a synonym for %lu
%O a synonym for %lo
%F a synonym for %f
Perl permits the following universally-known flags between the
`%' and the conversion letter:
space prefix positive number with a space
+ prefix positive number with a plus sign
- left-justify within the field
-----> 0 use zeros, not spaces, to right-justify
# prefix non-zero octal with "0", non-zero hex with "0x"
number minimum field width
.number "precision": digits after decimal point for
floating-point, max length for string, minimum length
for integer
l interpret integer as C type "long" or "unsigned long"
h interpret integer as C type "short" or "unsigned short"
There is also one Perl-specific flag:
V interpret integer as Perl's standard integer type
Where a number would appear in the flags, an asterisk (`*') may
be used instead, in which case Perl uses the next item in the
parameter list as the given number (that is, as the field width
or precision). If a field width obtained through `*' is
negative, it has the same effect as the `-' flag: left-
justification.
If `use locale' is in effect, the character used for the decimal
point in formatted real numbers is affected by the LC_NUMERIC
locale. See the perllocale manpage.
--
pos += screamnext[pos] /* does this goof up anywhere? */
--Larry Wall in util.c from the perl source code
------------------------------
Date: Tue, 15 Jun 1999 18:33:19 GMT
From: paulm@dirigo.com
Subject: SQL statement in Perl
Message-Id: <7k669f$ts0$1@nnrp1.deja.com>
Does anyone have any familiarity with writing SQL statements in Perl?
I have a script that's using Win32 OLE and calling a System DSN. The
call to the system DSN is working, but the script is failing when
running the SQL statement. I'm attempting to grab info from an Access
97 database. It looks as follows:
my $db = new Win32::ODBC( $dsn ) || die "Error: " . Win32::ODBC::Error
();
$stmt = "SELECT ALL * FROM [Forecast]";
I've tried multiple combinations of the SQL. It's attempting to grab
the data from the Forecast table and print it, but it keeps erring out.
Does this have something to do with Access 97?
Any help would be largely appreciated.
Thanks in advance.
--
Paul R. Mesker
System Engineer
Dirigo Inc.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 15 Jun 1999 16:54:44 -0400
From: brian@pm.org (brian d foy)
Subject: Re: SQL statement in Perl
Message-Id: <brian-ya02408000R1506991654440001@news.panix.com>
In article <7k669f$ts0$1@nnrp1.deja.com>, paulm@dirigo.com posted:
> Does anyone have any familiarity with writing SQL statements in Perl?
Perl doesn't know anything about SQL. data are data. make sure that
you are constructing the proper strings to send to the database server.
that only requires you to know SQL, and not Perl ;)
good luck :)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Tue, 15 Jun 1999 20:56:15 GMT
From: "John" <john@nonet.com>
Subject: Re: taint checking setuid error message
Message-Id: <01beb771$7f8a2560$cd261ca5@B19592-WS.kcc.com>
I agree that I need to update to a newer version of Perl. The problem is
that a vendor supplied app has not yet been updated to run with anything
greater than version 4.
I did get a chuckle from the OJ comment but was hoping for some
enlightenment regarding the taint checking message. That could help even
when I eventually do upgrade.
David Cassell <cassell@mail.cor.epa.gov> wrote in article
<37667D82.9DEF2165@mail.cor.epa.gov>...
> Tom Phoenix wrote:
> >
> > On Mon, 14 Jun 1999, John wrote:
> >
> > > I'm running perl v4
> >
> > When that version of Perl was current, OJ Simpson was best known for
being
> > a Heisman trophy winner. He still can't seem to find the real killer,
but
> > you can (and should) find the real Perl.
> >
> > http://www.cpan.org/
>
> In the words of Randal, "heh".
>
> > There are even CERT advisories telling why such old software isn't safe
to
> > use. Please upgrade.
> >
> > > (actually ingperl v4).
> >
> > Well, you can probably do whatever it is that was special about ingperl
> > with a module (a database module, perhaps?). And your code will be more
> > reliable for no extra cost.
>
> IngPerl was the old Ingres database code for Perl. It has been
> supplanted by the DBI module and the appropriate DBD::* module.
> And these need a modern Perl to run. So pay attention to TomP.
>
> HTH,
> David
> --
> David Cassell, OAO cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician
>
------------------------------
Date: Tue, 15 Jun 1999 21:48:15 +0100
From: "Martin Quensel" <martin@adoma.se>
Subject: There is a smarter way, but i dont know how.
Message-Id: <7k6bri$jei$1@cubacola.tninet.se>
Hello!
I want the 10 first variables in an array, but it seems like i have to use
foreach, instead of a simple "for".
My problem looks like this.
I have a logger, that logs every visitor on my website, and prints info in a
text file, like this:
IPnumber|URL|time
i create am empty hash, read the file line by line.
The URLs are stored as keys, and the values are how many times the same URL
occur in the file.
Then i sort the hash like this:
@SortedURLs = sort { $Urls{$b} <=> $Urls{$a} } keys %Urls;
i now want to print out the information, in a table like this:
times found URL
85 www.perl.com
76 www.imnotagoodprogrammer.com
5
www.why-dident-i-start-with-programming-when-i-was-five.com
This i can do like this i think...dont know if it works yet
for($i=0;$i<10;$i++)
{
print "%Urls{@SortedUrls[$i]} @SortedUrls[$i]\n";
}
But if this works..isent there another better way? Am i at least thinking in
the right direction??
And if it doesent, how should i do?
I have tried to show what i want to acomplish, so i hope you understand, if
my code is totally from an outerspace alien mind and doesent help to
explain.
I am sorry if my english isent good enough to explain the problem.....and
what i need help/explaining with.
im sorry if it exists in the FAQ, but i dident find it..
Thanx in advance.
------------------------------
Date: 15 Jun 1999 20:26:18 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: There is a smarter way, but i dont know how.
Message-Id: <7k6cta$645$1@info2.uah.edu>
In article <7k6bri$jei$1@cubacola.tninet.se>,
"Martin Quensel" <martin@adoma.se> writes:
: I want the 10 first variables in an array, but it seems like i have to use
: foreach, instead of a simple "for".
The distinction went away with perl version 5. With modern perls,
C<for> and C<foreach> are identical. So you are free to write these
for $var (@array) { ... }
foreach $var (@array) { ... }
interchangably. You can even say
foreach ($i = 0; $i < 10; $i++) { print "\$i = $i\n" }
: Then i sort the hash like this:
:
: @SortedURLs = sort { $Urls{$b} <=> $Urls{$a} } keys %Urls;
:
: i now want to print out the information, in a table like this:
:
: times found URL
: 85 www.perl.com
: 76 www.imnotagoodprogrammer.com
I would do this:
splice @SortedURLs, 10; # chop past 10th element
for (@SortedURLs) {
print "$Urls{$_} $_\n";
}
Greg
--
Why do they call it a "building"? It looks like they're finished. Why isn't
it a `built'?
-- Jerry Seinfeld
------------------------------
Date: Tue, 15 Jun 1999 22:06:25 +0100
From: "Martin Quensel" <martin@adoma.se>
Subject: Re: There is a smarter way, but i dont know how.
Message-Id: <7k6ctj$fpd$1@zingo.tninet.se>
Martin Quensel skrev i meddelandet <7k6bri$jei$1@cubacola.tninet.se>...
I mean:
sorry..
for($i=0;$i<10;$i++)
{
print "%Urls{$SortedUrls[$i]} $SortedUrls[$i]\n";
}
the @SortedUrls kan consist of more than 100 urls..the problem is that i
only want the 10 first ones.
------------------------------
Date: 15 Jun 1999 14:35:26 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: There is a smarter way, but i dont know how.
Message-Id: <3766b90e@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Greg Bacon <gbacon@cs.uah.edu> writes:
:The distinction went away with perl version 5.
No -- there's never been a distinction. Check back
around perl2 for the foreach() introduction.
--tom
--
"A well-written program is its own heaven;
a poorly-written program is its own hell."
------------------------------
Date: Tue, 15 Jun 1999 17:02:46 -0400
From: brian@pm.org (brian d foy)
Subject: Re: There is a smarter way, but i dont know how.
Message-Id: <brian-ya02408000R1506991702460001@news.panix.com>
In article <7k6bri$jei$1@cubacola.tninet.se>, "Martin Quensel" <martin@adoma.se> posted:
> I want the 10 first variables in an array, but it seems like i have to use
> foreach, instead of a simple "for".
> @SortedURLs = sort { $Urls{$b} <=> $Urls{$a} } keys %Urls;
> This i can do like this i think...dont know if it works yet
why not try it before posting. then you would know. :)
> for($i=0;$i<10;$i++)
> {
> print "%Urls{@SortedUrls[$i]} @SortedUrls[$i]\n";
> }
>
> But if this works..isent there another better way? Am i at least thinking in
> the right direction??
the right answer is whatever solves the problem :)
and if that works, do you want another way?
foreach my $url ( @SortedURLs[0..9] ) { }
foreach my $index ( 0..9 ) { print $SortedURLs[$index] }
$" = "\n"; print "@SortedURLs[0..9]\n";
...
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Tue, 15 Jun 1999 15:09:10 -0400
From: "Kevin Murphy" <MurphKE1@aplmsg.jhuapl.edu>
Subject: UDP broadcasts in Win32??
Message-Id: <7k68c0$dv4$1@houston.jhuapl.edu>
I am attempting to write a perl script to receive UDP broadcasts on a
WinNT machine with the latest ActiveState Perl. After searching the perl
man pages, DejaNews, etc., I was able to construct simple client-server
UDP apps to talk to each other from/to specific addresses and ports.
I have been unable, however, to successfully receive UDP broadcasts.
Can anyone provide a link, reference, or outright info on how to do this??
Thanks,
--
"I know nothing, and that which I believe is mostly
wrong and subject to continual revision"
Kevin Murphy
------------------------------
Date: Tue, 15 Jun 1999 13:22:06 -0400
From: Greg Bartels <gbartels@xli.com>
Subject: Re: What is functional difference between .pm and .pl?
Message-Id: <37668BBE.FE0EFF85@xli.com>
Neil wrote:
> I understand that
> foo.pm is a "perl module" but what distinguishes this from
> a "perl script"?
you generaly "run" perl scripts, which in turn, "use"
perl modules. run as in from the command line.
use as in use module_name in perl code.
modules are a way to modularize the complexity of
some code. they can also behave similar to C++
objects, allowing you to create instances of
objects.
> is a module more of a library ?
yes, more like that
> Any explanations of what CPAN is all about would be appreciated.
its about 50 feet long and 20 feet high...
sorry.
the "Perl Cookbook" published by Oreilly gives a
run down on a few of the interesting modules
available on CPAN, and how to use them.
such modules as ftp, mail, telnet, all sorts of
funky stuff like that.
you can also dig around the website if you want.
theres a search engine. and all tar.gz files are
supposed ot be right beside a readme file which
should describe the contents of teh tar.gz file.
go to www.cpan.org/modules/by-name and you should
get a general impression of whats available.
and if you have no clue, you could possibly
ask here or in comp.lang.perl.modules
and someone might point you to a specific
module that fits your needs.
Greg
------------------------------
Date: 15 Jun 1999 14:28:45 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: What is functional difference between .pm and .pl?
Message-Id: <3766b77d@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Neil <neil@pacifier.com> writes:
:I have used and hacked many .pl and .cgi scripts, but I'm
:now curious enough to want to learn more. I understand that
:foo.pm is a "perl module" but what distinguishes this from
:a "perl script"?
Um, ".pl" is Perl library, and ".pm" is Perl module, which is just
a library with more rules. This has nothing to do with stand-alone
executable Perl programs, which require no suffix whatsoever.
In fact, apart from modules, neither do libraries, really.
--tom
--
"An American monkey, an Ateles, after getting drunk on brandy,
would never touch it again, and thus was wiser than many men."
- Charles Darwin
------------------------------
Date: Tue, 15 Jun 1999 20:55:54 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: What is functional difference between .pm and .pl?
Message-Id: <u5z93.5832$nn.1063383@news.shore.net>
Tom Christiansen <tchrist@mox.perl.com> wrote:
: Um, ".pl" is Perl library, and ".pm" is Perl module, which is just
: a library with more rules. This has nothing to do with stand-alone
: executable Perl programs, which require no suffix whatsoever.
: In fact, apart from modules, neither do libraries, really.
Some people use .pl to represent a perl script. It makes it very easy to
do things like
grep <some pattern> *.cgi *.pl
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Tue, 15 Jun 1999 19:05:45 GMT
From: sam@cheapnet.co.uk (sam@cheapnet.co.uk)
Subject: WIN32 USERADMIN DOESN'T WORK
Message-Id: <3766a309.21904279@news.cheapnet.co.uk>
I just bought the OReilly octopus book "NT USER ADMIN" and downloaded
the accompanying scrpits.
however i cannot get any of the modules to work.
i am trying to us the UserAdmin module to create NT accounts.
anyone have any joy with this ?
i am using the latest port from active state v517
i get the error message "cant locate loadable object for module
win32::useradmin in @INC (where @INC contains d:/perl/lib
d:/perl/site/lib"
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 6006
**************************************