[22379] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4600 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 21 09:06:21 2003

Date: Fri, 21 Feb 2003 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 21 Feb 2003     Volume: 10 Number: 4600

Today's topics:
    Re: Chucking up text on word boundaries? (Helgi Briem)
        Combining maps <neil.shadrach@corryn.com>
    Re: Combining maps <tassilo.parseval@post.rwth-aachen.de>
    Re: Combining maps <neil.shadrach@corryn.com>
        Compare two strings (Rob Boerman)
    Re: Compare two strings <Steffen.Beyer@de.bosch.com>
    Re: having PERL respond to a key press (Helgi Briem)
    Re: having PERL respond to a key press <tyrannous@o-space.com>
    Re: How do I get the current date? <abigail@abigail.nl>
        Issue Using System on a Perl CGI <bkeogh@sbcglobal.net>
    Re: Issue Using System on a Perl CGI <ian@WINDOZEdigiserv.net>
        perl download script - how to minimize server memory us (Adrian Grigore)
    Re: perl download script - how to minimize server memor <ubl@schaffhausen.de>
    Re: perl download script - how to minimize server memor <nobull@mail.com>
    Re: Problem with buffering on non-blocking socket under <news@wildgooses.com>
    Re: reading excel spreadsheet with perl <s_grazzini@hotmail.com>
    Re: Religious question: commenting (Helgi Briem)
    Re: Religious question: commenting <mr@sandman.net>
    Re: Religious question: commenting <mr@sandman.net>
    Re: Retrieving Information <simon.andrews@bbsrc.ac.uk>
    Re: Retrieving Information (Helgi Briem)
    Re: Switch order of sprintf conversions <noreply@gunnar.cc>
    Re: Switch order of sprintf conversions <noreply@gunnar.cc>
    Re: Switch order of sprintf conversions (Anno Siegel)
    Re: use DBI; (Helgi Briem)
    Re: When is perl6 expected to be available? (Hiroki Horiuchi)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 21 Feb 2003 12:00:12 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Chucking up text on word boundaries?
Message-Id: <3e5611be.1209481402@news.cis.dfn.de>

First of all, don't top-post.  It annoys the regulars and
*SEVERELY* reduces your chances of receiving useful
help. If you don't know what top-posting (TOFU) is, read
the following:
http://jargon.watson-net.com/jargon.asp?w=top%2Dpost

For further guidelines on how to post to 
comp.lang.perl.misc, read:
http://mail.augustmail.com/~tadmc/clpmisc.shtml

    For more information about netiquette in general, see
the "Netiquette Guidelines" at:

http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

>"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message 
news:<Xns932888705A19Esdn.comcast@216.166.71.239>...

>> Suggest you look into the Text::Wrap module.

On 20 Feb 2003 20:03:23 -0800, robert@elastica.com (Robert
Nicholson) wrote:
>Actually I did but I cannot get it to wrap anything. It seems to not
>split any of the lines I'm giving it. I'll look at it some more
>shortly.

The code below (mostly from perldoc Text::Wrap) doesn't 
work??  How extraordinary!  Have you told the author ;-)

#!perl
use warnings;
use strict;
use Text::Wrap qw(wrap);
$Text::Wrap::columns = 50;
my @text = (<DATA>);
my  $initial_tab = "\t";    # Tab before first line
my $subsequent_tab = '';   # All other lines flush left
print wrap($initial_tab, $subsequent_tab, @text);
__END__
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 21 Feb 2003 12:11:18 +0000
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Combining maps
Message-Id: <3E561766.4090103@corryn.com>

Looking for a neat way to combine the two maps.
When I try get additional "[.txt]" lines in the output.

#!/usr/bin/perl -w
use strict;

foreach my $f (map $_.".txt", map /^(?![#\s])(.+)$/, <DATA>)
{
   print "[",$f,"]\n"
}
__DATA__
# Comment
aaa
bbb
ccc

ddd

eee
# End

The output as is :
[aaa.txt]
[bbb.txt]
[ccc.txt]
[ddd.txt]
[eee.txt]



------------------------------

Date: 21 Feb 2003 12:38:28 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Combining maps
Message-Id: <b356k4$dav$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Neil Shadrach:

> Looking for a neat way to combine the two maps.
> When I try get additional "[.txt]" lines in the output.
> 
> #!/usr/bin/perl -w
> use strict;
> 
> foreach my $f (map $_.".txt", map /^(?![#\s])(.+)$/, <DATA>)

How about:

    foreach my $f (map { /^(?![#\s])(.+)$/ ? "$1.txt" : () } <DATA>) {

If you DATA is actually a filehandle belonging to a real file, be aware.
The above slurps the whole file into memory. If the file is large,
better go for a 'while (<HANDLE>)' solution (no more map() then).

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Fri, 21 Feb 2003 12:51:53 +0000
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Re: Combining maps
Message-Id: <3E5620E9.2020803@corryn.com>

Tassilo v. Parseval wrote:

> How about:
> 
>     foreach my $f (map { /^(?![#\s])(.+)$/ ? "$1.txt" : () } <DATA>) {
> 
> If you DATA is actually a filehandle belonging to a real file, be aware.
> The above slurps the whole file into memory. If the file is large,
> better go for a 'while (<HANDLE>)' solution (no more map() then).

Thanks for that.
I had tried "?" but didn't get the no-match case right.



------------------------------

Date: 21 Feb 2003 03:46:41 -0800
From: rob@tevreden.nl (Rob Boerman)
Subject: Compare two strings
Message-Id: <2f19585c.0302210346.17b067ba@posting.google.com>

Hello,

Say I have two strings: 'this question is too simple' and 'is this
question too simple'

Is there a way to compare these strings lexically and get a 'match
percentage' or something?
I've got a lot of questionnaires containing similar but not identical
questions, and I want to group together the questions which 'match'
above a certain percentage.

Is this possible,

Thanks a lot for any help
Rob Boerman,
Delft, The Netherlands


------------------------------

Date: Fri, 21 Feb 2003 14:02:28 +0100
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: Compare two strings
Message-Id: <b35815$bg4$1@ns2.fe.internet.bosch.com>


"Rob Boerman" <rob@tevreden.nl> wrote in message news:2f19585c.0302210346.17b067ba@posting.google.com...
> Hello,
> 
> Say I have two strings: 'this question is too simple' and 'is this
> question too simple'
> 
> Is there a way to compare these strings lexically and get a 'match
> percentage' or something?
> I've got a lot of questionnaires containing similar but not identical
> questions, and I want to group together the questions which 'match'
> above a certain percentage.
> 
> Is this possible,
> 
> Thanks a lot for any help
> Rob Boerman,
> Delft, The Netherlands

Sounds like you need the module String::Approx:
http://search.cpan.org/author/JHI/String-Approx-3.19/Approx.pm

Or ask Jarkko Hietaniemi (the module's author) for more information.

(See http://www.perl.com/CPAN/authors/00whois.html which
is the CPAN "Who is who" guide)

Hope this helps.

Cheers,
Steffen


------------------------------

Date: Fri, 21 Feb 2003 13:04:35 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: having PERL respond to a key press
Message-Id: <3e5623bb.1214086494@news.cis.dfn.de>

On Thu, 20 Feb 2003 21:14:18 -0000, <tyrannous@o-space.com>
wrote:

>I want to have perl exit from a WHILE loop when the user 
>presses a certain key on the keyboard

Why are you re-posting this question?

Were you not satisfied with the answers you got last time?

If not, what was your problem with them?
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 21 Feb 2003 13:36:40 -0000
From: <tyrannous@o-space.com>
Subject: Re: having PERL respond to a key press
Message-Id: <b359vt$fsf$1@newsg4.svr.pol.co.uk>

none of the ideas worked.

is there any simple way to do this?
"Helgi Briem" <helgi@decode.is> wrote in message
news:3e5623bb.1214086494@news.cis.dfn.de...
> On Thu, 20 Feb 2003 21:14:18 -0000, <tyrannous@o-space.com>
> wrote:
>
> >I want to have perl exit from a WHILE loop when the user
> >presses a certain key on the keyboard
>
> Why are you re-posting this question?
>
> Were you not satisfied with the answers you got last time?
>
> If not, what was your problem with them?
> --
> Regards, Helgi Briem
> helgi AT decode DOT is




------------------------------

Date: 21 Feb 2003 08:13:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How do I get the current date?
Message-Id: <slrnb5bnu1.cvd.abigail@alexandra.abigail.nl>

Steffen Beyer (Steffen.Beyer@de.bosch.com) wrote on MMMCDLXI September
MCMXCIII in <URL:news:b34juu$ics$1@ns2.fe.internet.bosch.com>:
;;  
;; > {}  And yes, this has a Y10K bug (sort of). ;-)
;; > What makes you think there's a Y10K bug? 
;;  
;;  The fact that I wrote %04d in the sprintf.
;;  
;;  Which BTW is unnecessary for the next (roughly) 8000 years
;;  (in theory - in practice localtime will break in 2038 on
;;  32 bit machines).
;;  
;;  This is almost a bug because in year 10000, the sprintf will
;;  automatically use 5 digits for the year (despite the %04d) -
;;  which may break other code which expects 4 digits only.


But that would be a bug in the *other* software. Otherwise, any code
that prints a date would have a bug. Even in you'd use a billion digits
to write down the year, there will be a point in time where a billion
digits isn't enough.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


------------------------------

Date: Fri, 21 Feb 2003 04:52:31 GMT
From: "brendankeogh" <bkeogh@sbcglobal.net>
Subject: Issue Using System on a Perl CGI
Message-Id: <jgi5a.1270$ZX7.1178@newssvr16.news.prodigy.com>

I am running a set of perl.cgi's on Win2000 where I download a file and then
unzip it using winzip's command line command.
Using the system command in perl. However, it hangs up half-way through the
unzipping. If I stop the Apache Server, the unzipping finishes. Any ideas
would be appreciated.



 $ziparams = " -d -ybc C:\\gsswebav\\download\\test1\.zip
c:\\gsswebav\\download\\expand";
 $wzuzzip = "C:\\progra~1\\winzip\\wzunzip.exe";
system ($wzuzzip.$ziparams);








------------------------------

Date: Fri, 21 Feb 2003 13:24:55 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Issue Using System on a Perl CGI
Message-Id: <7v9c5vk7ps1m8ebo4vui7gumb6ptpa18l9@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Fri, 21 Feb 2003 04:52:31 GMT,
"brendankeogh" <bkeogh@sbcglobal.net> managed to scribble:

> I am running a set of perl.cgi's on Win2000 where I download a file
> and then unzip it using winzip's command line command.
> Using the system command in perl. However, it hangs up half-way
> through the unzipping. If I stop the Apache Server, the unzipping
> finishes. Any ideas would be appreciated.
> 
> 
> 
>  $ziparams = " -d -ybc C:\\gsswebav\\download\\test1\.zip
> c:\\gsswebav\\download\\expand";
>  $wzuzzip = "C:\\progra~1\\winzip\\wzunzip.exe";
> system ($wzuzzip.$ziparams);
> 
> 
> 
> 
> 

Why not use the Archive::Zip module? No need for any external system
calls (meaning that'd it become portable in that part of the code
anyway too). AFAIK, you'd have much better control over error
handling this way around too.



Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPlYooWfqtj251CDhEQJiowCg3B1nids6UiJIaa2YA8xG17NPBE8AoJyV
XRo3uXRk1THGW5Bpg5iFIMAc
=L4yc
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


------------------------------

Date: 21 Feb 2003 03:33:17 -0800
From: lobbister.2.wuni@spamgourmet.com (Adrian Grigore)
Subject: perl download script - how to minimize server memory usage?
Message-Id: <b4ed8910.0302210333.6f8c77b6@posting.google.com>

Hi,

I am using a download script written in perl to serve shareware
downloads of about 2-3 MB per file. The script is patching the
referrer URL into the file for various reasons, so redirecting
visitors to the actual download url is not an option.

Now, while this script works fine for over 1 month now, I noticed that
it also puts very heavy memory load (>400 MB) on the server when about
150 or more users try to access it at the same time (don't worry -
it's on my dedicated server hosted by another webhost, not at FQ!).

My guess is that this happens because the script writes the whole file
to stdout within a matter of seconds (or maybe even a fraction of a
second) whenever the file is requested. Then the server has to buffer
this output until the client has eventually downloaded the file or
aborted the download. The script works like this:

open(FILE, "<$_[0]") || die "download failed: could not open $_[0]";
binmode FILE;
binmode STDOUT;
my $BytesRead = read (FILE, $buff, 8192);
while ($BytesRead) 
	{
 	print $buff;
	$BytesRead = read (FILE, $buff, 8192);
	}
close(FILE);

Is there any way I can delay the output so that the script is only a
few kbytes ahead of the client? Using a "static" delay would do no
good for those using high-speed connections, but on the other side if
my software is mentioned in a really big newsletter it might even
crash the server.

 Is there some way to solve this problem without reducing the maximum
download speed for those downloaders who have the bandwidth?

Thanks in advance for any ideas you might have :)

-- Adrian


------------------------------

Date: Fri, 21 Feb 2003 13:41:37 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: perl download script - how to minimize server memory usage?
Message-Id: <b35a15$gam$1@news.dtag.de>

Adrian Grigore wrote:
> My guess is that this happens because the script writes the whole file
> to stdout within a matter of seconds (or maybe even a fraction of a
> second) whenever the file is requested. Then the server has to buffer
> this output until the client has eventually downloaded the file or
> aborted the download. The script works like this:

I guess, you could write to a temp file and then redirect the user to 
that one.

The better question is, why would you want the referrer url in the file. 
Maybe you can achieve the same by handing out a transaction id to the 
user that you can use later to identify the referrer.

->malte



------------------------------

Date: 21 Feb 2003 12:38:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl download script - how to minimize server memory usage?
Message-Id: <u9heaxerlb.fsf@wcl-l.bham.ac.uk>

lobbister.2.wuni@spamgourmet.com (Adrian Grigore) writes:

> I am using a download script written in perl to serve shareware
> downloads of about 2-3 MB per file. The script is patching the
> referrer URL into the file for various reasons, so redirecting
> visitors to the actual download url is not an option.

I'll get back to you on that one - see below.
 
> Now, while this script works fine for over 1 month now, I noticed that
> it also puts very heavy memory load (>400 MB) on the server when about
> 150 or more users try to access it at the same time (don't worry -
> it's on my dedicated server hosted by another webhost, not at FQ!).
> 
> My guess is that this happens because the script writes the whole file
> to stdout within a matter of seconds (or maybe even a fraction of a
> second) whenever the file is requested. Then the server has to buffer
                                                          ^^^^^^
> this output until the client has eventually downloaded the file or
> aborted the download. 

> Is there any way I can delay the output so that the script is only a
> few kbytes ahead of the client?

This is a question about your web server software, it has nothing to
so with Perl.

>  Is there some way to solve this problem without reducing the maximum
> download speed for those downloaders who have the bandwidth?

The normal approach to CGIs that generate huge output is to create a
temporary file and generate an internal redirect.

Furthermore, if you arrange that the temporary file is reused rather
than regenerated in the event of an identical request this will allow
the download to be restartable.

This, as I said, has nothing to do with Perl.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Fri, 21 Feb 2003 08:14:38 GMT
From: "Ed W" <news@wildgooses.com>
Subject: Re: Problem with buffering on non-blocking socket under win32
Message-Id: <Ndl5a.899913$zx5.141198@news.easynews.com>

Thanks for this thought, however, thats EXACTLY the problem.  I am using a
select loop to read and write to a pair of sockets.  The app is a POP3
proxy, and so I am listening to a mail client on localhost and speaking to a
mail server over a 300 byte/sec link on the other socket.  The point is not
to read too much from the mail client socket because it will take ages to
write out to the slow remote socket (with possible timeouts on the mail
client in the meantime)

I am looking for the neatest way to fill up the send socket over the slow
link, and the best algorithm I have so far is perhaps to write in 1kb
chunks, checking "can_write" each time.  When can_write returns false then
stop writing...  It would be desirable to:

a) have a neater algorithm
b) be able to control the size of the OS buffers, eg anticipating a slow
connection, drop the size of the buffer somewhat.  However, in practice I
think this will not be required as long as I read from the fast socket in
small enough chunks (still nasty though).  However, the thought occurs that
dropping the size of the OS receive buffer to the localhost socket would be
a very good idea...

Thanks for any thoughts

Ed

"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3E5596AD.7025B2D3@earthlink.net...
> Ed W wrote:
> [snip]
> > any better ideas?
>
> Yes.  Instead of simply doing reading, then writing, then reading, use a
> more generic select() loop, with proper multiplexing using callbacks.
>
> Something like:
>
>    http://groups.google.com/groups?selm=3D44BB7F.7765DD28@earthlink.net
>
> The most important thing to note is how very simple the main part of the
> program, before the 'exit', is.  It's a simple loop, which calls
> IO::Select->select(...), and then calls some functions appropriate to
> which handles were ready for reading/writing.  Depending on what your
> needs are, you would likely have different stuff for the callbacks.
>
> To see other code which does multiplexing like this, see:
>
>    http://groups.google.com/groups?&q=io-select-select+author:goldberg
>
> Some of my older stuff isn't as well written, but it's still
> educational.
>
> --
> $;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
> my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
> $__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print




------------------------------

Date: Fri, 21 Feb 2003 08:13:23 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: reading excel spreadsheet with perl
Message-Id: <Dcl5a.31568$Mh3.10710883@twister.nyc.rr.com>

Bart Lateur <bart.lateur@pandora.be> writes:
> Bob Dubery wrote:
> 
>>Recent versions of Excel can ouput spreadsheets as XML,
> 
> Does that option preserve text formatting?
> 

Yep!  It's really good:

  http://msdn.microsoft.com/library/default.asp?
      url=/library/en-us/dnexcl2k2/html/odc_xlsmlinss.asp

-- 
Steve


------------------------------

Date: Fri, 21 Feb 2003 11:38:12 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Religious question: commenting
Message-Id: <3e560e1e.1208553598@news.cis.dfn.de>

On Thu, 20 Feb 2003 19:16:10 GMT, "J. F. Cornwall"
<JCornwall@cox.net> wrote:

>Data Point:  As a novice Perl programmer (with 19 years of experience in 
>Fortran), I rather like seeing clear comments interspersed with the 
>code.  Experts can pick out the functions from the code with no aids, 
>but those of us who are still earning the language can definitely 
>benefit from good, clear, *accurate* commenting.  My code (in any 
>language) has lots of comments, because my priorities include making it 
>easy for the next guy to see what the code is for and how it functions. 
>  Yes, I have to make sure comments get updated when the code does. 
>Yes, I have to work harder on it to ensure the code and the comments 
>match.  No, I don't care much for programmers' work that depends on 
>[Fortran|C|Perl] being a "self-documenting" language.

Well chosen variable and subroutine names and
clear logic go a long way towards making the code clear.

That sort of 'non-commenting' is usually much better 
than excessive comments.

I absolutely hate this sort of thing:

# Open the phonebook file for appending:
open I, ">>$i" or die $!;

when something like this would have been much
clearer and needed no comments at all:

open PHONEBOOK, $phonebook 
or die "Cannot open $phonebook for appending:$!\n";

>What's wrong with spending a bit of extra effort and putting in *good* 
>comments, ones that are accurate and helpful to the non-experts?

Where they are necessary, sure, put them in.  If I 
am writing code I find complex, I often write the
comments first and then stick the code in later
between the comments.  But good code is better. 
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 21 Feb 2003 13:54:54 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Religious question: commenting
Message-Id: <mr-665D9F.13545421022003@news.fu-berlin.de>

In article <pan.2003.02.20.16.34.28.738834@aursand.no>,
 "Tore Aursand" <tore@aursand.no> wrote:

> > I disagree. If I ask you where you usually put captions to pictures and
> > give you a picture and a "blablabla" caption and ask you to place them
> > together, would you go "Hey, this caption is AQLL wwrong for this
> > picture! I can't give any general comments on this at all!"?
> 
> Ofcourse.  Why shouldn't he?  If it's _obvious_ that the caption doesn't
> go with the picture, why should he let you commit that foul?

I am not interested in the caption, I am interested in how he, generally, 
places them with pictures.

> It seems to be that you're trying to separate comments from code and vice
> versa.  To me that seems wrong, because sloppy commenting can obfuscate
> the most elegant code, the same way great commenting can't make up for bad
> code.

And I am interested in how commenting is done, in general, not with specific 
examples.

> Or - to use the picture/caption relevance;  It doesn't matter if the
> caption says 'George W. Bush' when it's a picture of Saddam Hussein.  It's
> just wrong.

So it would be impossible for you to use that captioning and that picture to 
show me how you generally place captions? Odd.

-- 
Sandman[.net]


------------------------------

Date: Fri, 21 Feb 2003 13:57:40 +0100
From: Sandman <mr@sandman.net>
Subject: Re: Religious question: commenting
Message-Id: <mr-411CB7.13574021022003@news.fu-berlin.de>

In article <b3366l$o6p$1@nets3.rz.RWTH-Aachen.DE>,
 "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote:

> >> You should focus more on the code and less on the commenting.
> > 
> > In a thread about commenting? Odd.
> 
> Well, what are your priorities? Rather becoming an expert in Perl or in 
> commenting Perl code?

What does my priorities has to do with my questions about how you guys 
comment?

> The time you spent here arguing your point could have been spent better on 
> becoming even more familiar with Perl.

I am familliar with perl. I've already explained that the code was an example 
(and pasted from PHP code at that) and is unimportant.

> This will on the long run reduce the need for comments, too, by increasing 
> the expressiveness and clearity of your programs.

I, obviously, disagree with that notion.

I asked the same question in the PHP group, and those guys all came back with 
some examples on how they comment code. And while there were some guy there 
aswell that focused on the code in the example instead, most of them understodd 
what I wwas asking and answered accordingly.

It's not that hard. How do you comment stuff?

-- 
Sandman[.net]


------------------------------

Date: Fri, 21 Feb 2003 10:39:49 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Retrieving Information
Message-Id: <3E5601F5.A5E6A187@bbsrc.ac.uk>

Smiley wrote:
> 
> > > I'm looking to retrieve some information from a website that has a nice
> > > searchable database.  This information isn't copyrighted, sensitive, or
> > > exclusive in any way so there's no problem there.
> >
> >
> > Good lad for thinking about that.  I'd suggest checking with the site
> > admins anyway.
> 
> I've sent them an email, but haven't heard any response.  I think it's been
> a while since the site has been updated, so I'm not even sure if anybody's
> checking.  I'm hoping for a response though, it would make things easier :)
> 
> > Well LWP can do a POST also, but it might be alot easier to just contact
> > the site admin and use a direct query to their database without going
> > through their form at all.  If their data is stored in a DBI accessible
> > rdbms, you can use a remote call to it.  If it's stored in a publicly
> > accessible XML, CSV, Fixed width or various other formated file,
> > DBD::AnyData will retrieve it from its remote location.
> 
> Oh good, I didn't know LWP can do a post.  I'll have to look that up - you
> don't happen to know off hand the syntax for that, would you?

Something like...

my $conobj = LWP::UserAgent->new;

$request=HTTP::Request->new('POST','http://www.someurl/script.cgi');

$request->content("var1=something&var2=something_else");

my $doc = $conobj -> request($request) -> as_string;

 ..should get you started, but do read the LWP docs for all the details.


Simon.


------------------------------

Date: Fri, 21 Feb 2003 11:18:24 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Retrieving Information
Message-Id: <3e5607ec.1206967667@news.cis.dfn.de>

On Thu, 20 Feb 2003 21:07:30 -0500, "Smiley"
<smiley@uvgotemail.com> wrote:

>Oh good, I didn't know LWP can do a post.  I'll have to look that up - you
>don't happen to know off hand the syntax for that, would you?

This is handled by the module LWP::UserAgent.

LWP::Simple is simply a wrapper around this module.

'perldoc lwpcook' has lots of recipes for using
the LWP modules, including this one below:

#!perl
use warnings;
use strict;

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
                [ search => 'www', errors => 0 ];
print $ua->request($req)->as_string;
__END__
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 21 Feb 2003 12:00:20 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Switch order of sprintf conversions
Message-Id: <oxo5a.11571$FF4.631989@newsb.telia.net>

Uri Guttman wrote:
>>>>>>"GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> 
> GH> My question is about the Perl function sprintf, i.e. I'm
> GH> wondering if there is any possibility to affect the order in
> GH> which the conversions appear in the string returned by sprintf.
> 
> the simplest method is to provide a different format string for
> different languages. this is how many internatialized systems work. you
> have a list of formats indexed by a key/number for each language. the
> formatting code is passed that key along with the sprintf args. it
> fetches the format and sprintf's it.

Thanks for your advise, Uri.

Applied to my example, I'm considering something along this line:

     $string = gettext("There Is %s Than %s Way To Do It");
     $more = gettext("More");
     $one = gettext("One");
     %reverse = (
         zh => 1,
     );
     printf($string, $reverse{$lang} ? ($one,$more) : ($more,$one));

The program is mature, there are several translations in place already, 
and this is the first time somebody has reported a need to switch the 
order of the arguments, so I don't want to make a great fuzz about it. 
Provided that there is no notation available to tell the sprintf 
function via $string to print the arguments in reverse order, I'm 
thinking of simply hardcoding such %reverse hashes in those few places 
in the program where it proves to be necessary.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Fri, 21 Feb 2003 12:00:26 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Switch order of sprintf conversions
Message-Id: <uxo5a.11572$FF4.631873@newsb.telia.net>

Jay Tilton wrote:
> : I understand from the gettext documentation that if it had been a 
> : C program, $string could have been assigned (the equivalent of) "There 
> : Is %2$s Than %1$s Way To Do It".
> : 
> : Is there a way in Perl to achieve the same thing?
> 
> Yup.
> 
> Do the same thing you would in C.

Can you please expand on that, Jay? I have tried it, but when using the 
above string, the sprintf function just returns:

     "There Is %2 Than %1 Way To Do It"

It would be much appreciated if you could give me some additional guidance.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: 21 Feb 2003 13:34:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Switch order of sprintf conversions
Message-Id: <b359to$a6n$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Uri Guttman wrote:
> >>>>>>"GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> > 
> > GH> My question is about the Perl function sprintf, i.e. I'm
> > GH> wondering if there is any possibility to affect the order in
> > GH> which the conversions appear in the string returned by sprintf.
> > 
> > the simplest method is to provide a different format string for
> > different languages. this is how many internatialized systems work. you
> > have a list of formats indexed by a key/number for each language. the
> > formatting code is passed that key along with the sprintf args. it
> > fetches the format and sprintf's it.
> 
> Thanks for your advise, Uri.
> 
> Applied to my example, I'm considering something along this line:
> 
>      $string = gettext("There Is %s Than %s Way To Do It");
>      $more = gettext("More");
>      $one = gettext("One");
>      %reverse = (
>          zh => 1,
>      );
>      printf($string, $reverse{$lang} ? ($one,$more) : ($more,$one));
> 
> The program is mature, there are several translations in place already, 
> and this is the first time somebody has reported a need to switch the 
> order of the arguments, so I don't want to make a great fuzz about it. 
> Provided that there is no notation available to tell the sprintf 
> function via $string to print the arguments in reverse order, I'm 
> thinking of simply hardcoding such %reverse hashes in those few places 
> in the program where it proves to be necessary.

I'm amazed the need to rearrange arguments hasn't come up earlier.

To be completely general, you may want to allow any permutation, not
only reversal.  You could store a list of small integers in a hash
and use a list slice to do the actual rearrangement:

    if ( exists $permute{$lang} ) {
        printf( $string, ($one, $more)[ @{ $permute{ $lang}}]);
    }

For the simple reversal, you'd set

    $permute{ zh} = [ 1, 0];

That would take care of other cases that may come up in the future.

Anno


------------------------------

Date: Fri, 21 Feb 2003 11:29:44 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: use DBI;
Message-Id: <3e560d61.1208363965@news.cis.dfn.de>

On 20 Feb 2003 23:54:29 GMT, Abigail <abigail@abigail.nl>
wrote:

>Helgi Briem (helgi@decode.is) wrote on MMMCDLX September MCMXCIII in

>&&  So you would approve if people stuck random things
>&&  in their code here and there that didn't do anything?
>
>No, but what does that have to do with 'exit'? I haven't encountered
>a Perl in which 'exit' doesn't do anything.

What does it do here that wouldn't have happened 
anyway?

#!perl
my $in = '/etc/passwd';
open IN, $in or die $!;
while (<IN>)
{
 print;
}
close IN;
exit(0);
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: 21 Feb 2003 04:58:42 -0800
From: hiroki@air.ne.jp (Hiroki Horiuchi)
Subject: Re: When is perl6 expected to be available?
Message-Id: <85c98cd5.0302210458.291e0df1@posting.google.com>

Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnb5bmcl.2fm.mgjv@martien.heliotrope.home>...
> > STRICT TYPE CHECKING FOR OOP:)
>
> And that's a good thing? 
>
> :)

Yes for me.
I love lint, "g++ -W...-Wold-style-cast", "perl -w" and "use strict;"


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.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 V10 Issue 4600
***************************************


home help back first fref pref prev next nref lref last post