[25387] in Perl-Users-Digest
Perl-Users Digest, Issue: 7632 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 12 00:05:44 2005
Date: Tue, 11 Jan 2005 21:05:12 -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 Tue, 11 Jan 2005 Volume: 10 Number: 7632
Today's topics:
Re: [OT] ISO book on CGI design <socyl@987jk.com.invalid>
Best way to build up XHTML <bart@NOSPAM.tvreclames.nl>
Re: Best way to build up XHTML <spamtrap@dot-app.org>
Re: Best way to build up XHTML <abigail@abigail.nl>
Re: Best way to build up XHTML <bart@NOSPAM.tvreclames.nl>
Re: Best way to build up XHTML <wcooley@nakedape.cc>
Re: cgi-bin script not printing output on html <vikram.keshavamurthy@gmail.com>
Re: cgi-bin script not printing output on html <sbryce@scottbryce.com>
Re: cgi-bin script not printing output on html <vikram.keshavamurthy@gmail.com>
Re: cgi-bin script not printing output on html <1usa@llenroc.ude.invalid>
Re: complex numbers <rkern@ucsd.edu>
Re: complex numbers <itsme@yahoo.com>
Re: CPAN troubles again <kalinaubears@iinet.net.au>
Re: CPAN troubles again <jkeen_via_google@yahoo.com>
Deleting newlines in a text file toomanyjoes@mail.utexas.edu
Re: Deleting newlines in a text file <jurgenex@hotmail.com>
Re: Deleting newlines in a text file <matternc@comcast.net>
Re: Deleting newlines in a text file (Jay Tilton)
Re: GLOB vs IO::Handle <kalinaubears@iinet.net.au>
Print question <edgrsprj@ix.netcom.com>
Re: Print question <spamtrap@dot-app.org>
Re: Print question <jl_post@hotmail.com>
Re: Print question <spamtrap@dot-app.org>
Three questions: UTF-8, DBM, hash of lists, ... <groleau+news@freeshell.org>
Re: Three questions: UTF-8, DBM, hash of lists, ... <jkeen_via_google@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 Jan 2005 02:36:38 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: [OT] ISO book on CGI design
Message-Id: <cs22fm$elm$1@reader2.panix.com>
In <etowtujr3n1.fsf@wilson.emschwar> Eric Schwartz <emschwar@fc.hp.com> writes:
>kj <socyl@987jk.com.invalid> writes:
>> For some reason that I can't quite figure out, my CGI projects are
>> far less readable and maintainable than the rest of my coding
>> projects. I've developed several awful, unmaintainable,
>> for-internal-use-only CGI projects (using Perl, CGI.pm, and JavaScript
>> exclusively) over the last 4 years now, and it's about time I
>> learned to do it right.
>The #1 rule of All Time, when doing web-based apps, is:
>1) Use templates to generate your HTML!
>I don't care if you use Template Toolkit, Mason, Amrita (a very nifty
>templating system in Ruby), or what, but if you use a templating
>solution, you will be happy, and babies will smile when you walk by,
>women will want to be you, men will want to be with you (or
>vice-versa). If not, then it will be chaos and insanity! Dogs and
>cats living together! Madness, I tell you, MADNESS!!!
Madness pretty much describes my code, and I agree that it has
something to do with generating all the HTML dynamically with
CGI.pm.
So the consensus (of 2) seems to be "templates". I'll look into
them.
(Any recommendations?)
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Wed, 12 Jan 2005 00:12:05 +0100
From: "Bart van den Burg" <bart@NOSPAM.tvreclames.nl>
Subject: Best way to build up XHTML
Message-Id: <cs1mpa$hqf$1@reader13.wxs.nl>
Hi
I showed my code to someone a while ago, and he said that it's rather
unclean to have XHTML code within the Perl code. I must agree with this,
because it doesn't really look al that nice, but I don't really know how to
do it better.
I've been playing around with XML::Smart, only to find out it's not really
going to work, because it's rather hard to make constructions like <div>text
<a href="something">link</a> more text</div>, without putting each piece in
it's own element (i.e.: <div><span>text</span> <a
href="something">link</a><span>more text</span></div>). AFAIK, it's not even
possible.
Then I started to play a little with XML::DOM. Nice as well, but it seems to
miss out some important functions for use with XHTML, for example:
getElementById(), since this, of course, is only from (X)HTML, and not for
XML.
I'm wondering what the best way is. I'm not necessarily looking for a
module. Some other way might be nice as well, but it would be cool to be
able to change, for example, the <title>, or add some <meta> tags.
Any ideas?
Thanks!
------------------------------
Date: Tue, 11 Jan 2005 18:30:55 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Best way to build up XHTML
Message-Id: <duGdnUYx8Pgy_HncRVn-og@adelphia.com>
Bart van den Burg wrote:
> I showed my code to someone a while ago, and he said that it's rather
> unclean to have XHTML code within the Perl code. I must agree with this,
> because it doesn't really look al that nice, but I don't really know how
> to do it better.
The most common approach is to use a "template" - an external file that
contains mostly (X)HTML, with a few placeholders that indicate where the
dynamic content goes. Your Perl script reads the template, replaces the
placeholders with the appropriate values, and sends the result to the
browser.
Search CPAN for "template" - there are many modules you can use. I've often
used Text::Template, because I like its simplicity. Mason does a lot more,
but by the same token it might be overkill for your needs.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 11 Jan 2005 23:44:08 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Best way to build up XHTML
Message-Id: <slrncu8p68.ucb.abigail@alexandra.abigail.nl>
Bart van den Burg (bart@NOSPAM.tvreclames.nl) wrote on MMMMCLI September
MCMXCIII in <URL:news:cs1mpa$hqf$1@reader13.wxs.nl>:
-- I'm wondering what the best way is.
Asking for the "best way" is better not done on Usenet. Finding the
"best way" is a long, complex traject, which starts by defining what
the "best way" for you is. "Best way" usually involves optimizing (or
otherwise finding a trade-off) one or more of the following issues:
- speed,
- memory usage,
- disk usage,
- disk I/O,
- network I/O,
- cache hits,
- ease of maintainance,
- code size,
- dependencies on third party software,
- ease of installation,
- portability,
- total development costs,
- total operational costs,
- something else.
If you are looking for "the best" way to solve a problem, hire a
consultant, to whom you can explain your wishes and resources.
Abigail
--
A perl rose: perl -e '@}>-`-,-`-%-'
------------------------------
Date: Wed, 12 Jan 2005 01:19:12 +0100
From: "Bart van den Burg" <bart@NOSPAM.tvreclames.nl>
Subject: Re: Best way to build up XHTML
Message-Id: <cs1qn6$jet$1@reader13.wxs.nl>
"Sherm Pendley" <spamtrap@dot-app.org> schreef in bericht
news:duGdnUYx8Pgy_HncRVn-og@adelphia.com...
> Bart van den Burg wrote:
>
> > I showed my code to someone a while ago, and he said that it's rather
> > unclean to have XHTML code within the Perl code. I must agree with this,
> > because it doesn't really look al that nice, but I don't really know how
> > to do it better.
>
> The most common approach is to use a "template" - an external file that
> contains mostly (X)HTML, with a few placeholders that indicate where the
> dynamic content goes. Your Perl script reads the template, replaces the
> placeholders with the appropriate values, and sends the result to the
> browser.
>
> Search CPAN for "template" - there are many modules you can use. I've
often
> used Text::Template, because I like its simplicity. Mason does a lot more,
> but by the same token it might be overkill for your needs.
>
> sherm--
HTML::Template looks great actually! Mason is, as you say, a little
overkill.
I'll try out HTML::Template, thanks!
Bart
------------------------------
Date: 11 Jan 2005 16:55:59 -0800
From: Wil Cooley <wcooley@nakedape.cc>
Subject: Re: Best way to build up XHTML
Message-Id: <slrncu8u1b.v1m.wcooley@rheingold.nakedape.priv>
On 2005-01-12, Bart van den Burg <bart@NOSPAM.tvreclames.nl> wrote:
> HTML::Template looks great actually! Mason is, as you say, a little
> overkill.
> I'll try out HTML::Template, thanks!
You might also look at Template Toolkit:
http://www.template-toolkit.org/
It's the favorite of some of the web designers I work with.
Wil
--
Wil Cooley wcooley@nakedape.cc
Naked Ape Consulting http://nakedape.cc
* * * * Linux, UNIX, Networking and Security Solutions * * * *
------------------------------
Date: 11 Jan 2005 18:03:44 -0800
From: "Vikram" <vikram.keshavamurthy@gmail.com>
Subject: Re: cgi-bin script not printing output on html
Message-Id: <1105495424.372615.19240@f14g2000cwb.googlegroups.com>
I am sorry not to have shown the entire script, however the script is
very simple, right now and is as follows:
#!c:/Perl/bin/perl.exe
#
# Use the following modules
#
use CGI qw(:standard);
use strict;
use warnings;
#
# Define variables and create an array
#
my
$DIR=q(E:\BackUp\BACKUP-FROM-W2K\ps\Digital-Multimedia\Images\2004\test);
my @array=split(/\n/,`dir $DIR /B`);
#
# Start printing the html page
#
print header;
print "<html><body><head><title>test</title></head>";
print "<table>";
for(my $i=0;$i<@array;$i++) {
print "<tr><td>$array[$i]</td></tr>";
}
print "</table></form></body></html>";
If I look at the source of the html page, I see everything else
printed, except
print "<tr><td>$array[$i]</td></tr>"; line
I have the script in the location http://127.0.0.1/cgi-bin/ and it has
required permission, I have other cgi-bin scripts in there which work
fine....
Vikram
------------------------------
Date: Tue, 11 Jan 2005 19:11:31 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: cgi-bin script not printing output on html
Message-Id: <356dndmdUbPUGnncRVn-pA@comcast.com>
Vikram wrote:
> #!c:/Perl/bin/perl.exe
> #
> # Use the following modules
> #
> use CGI qw(:standard);
> use strict;
> use warnings;
> #
> # Define variables and create an array
> #
> my
> $DIR=q(E:\BackUp\BACKUP-FROM-W2K\ps\Digital-Multimedia\Images\2004\test);
I assume this directory is on your hard drive.
> my @array=split(/\n/,`dir $DIR /B`);
> #
> # Start printing the html page
> #
> print header;
> print "<html><body><head><title>test</title></head>";
> print "<table>";
> for(my $i=0;$i<@array;$i++) {
> print "<tr><td>$array[$i]</td></tr>";
> }
> print "</table></form></body></html>";
>
> If I look at the source of the html page, I see everything else
> printed, except
>
> print "<tr><td>$array[$i]</td></tr>"; line
Could it be because it didn't find the directory on the server, so the
array was empty?
------------------------------
Date: 11 Jan 2005 18:16:45 -0800
From: "Vikram" <vikram.keshavamurthy@gmail.com>
Subject: Re: cgi-bin script not printing output on html
Message-Id: <1105496205.582481.191740@c13g2000cwb.googlegroups.com>
The directiry is pretty much there, I am able to print the array on the
command line as I said before, it's only that this doesn't show up on
the web page. Infact, it even works fine on an unix machine ( FreeBSD
4.7, running apache2.0), but not in this scenario - as I already
mentioned I am using active perl on a windows xp.
Thanks
Vikram
------------------------------
Date: 12 Jan 2005 03:21:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: cgi-bin script not printing output on html
Message-Id: <Xns95DBE35DF91C4asu1cornelledu@132.236.56.8>
"Vikram" <vikram.keshavamurthy@gmail.com> wrote in
news:1105495424.372615.19240@f14g2000cwb.googlegroups.com:
> my @array=split(/\n/,`dir $DIR /B`);
dir is an internal command. Try:
my @array=split(/\n/,`cmd /c dir $DIR /B`);
You should also check if your system command succeded:
C:\Home> set path=c:\perl\bin;
C:\Home> type mydir.pl
#! perl
use strict;
use warnings;
my @dir = `dir`;
print "$!\n";
C:\Home> mydir
Bad file descriptor
C:\Home> type mydir2.pl
#! perl
use strict;
use warnings;
my @dir = `c:\\windows\\system32\\cmd.exe /c dir`;
print @dir[0..10];
C:\Home> mydir2
Volume in drive C is HD
Volume Serial Number is F882-4E55
Directory of C:\Home\asu1
2005/01/11 10:18 PM <DIR> .
2005/01/11 10:18 PM <DIR> ..
2004/12/04 11:22 AM <DIR> .cpan
2005/01/11 05:56 PM <DIR> .gimp-2.0
2004/09/10 12:10 PM <DIR> .links
2003/01/30 01:10 PM <DIR> .ncftp
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Tue, 11 Jan 2005 15:16:56 -0800
From: Robert Kern <rkern@ucsd.edu>
Subject: Re: complex numbers
Message-Id: <cs1mp9$sg9$1@news1.ucsd.edu>
It's me wrote:
> You are focusing on computational type applications of complex numbers. For
> those, you can do it with any languages - including machine language. It's
> just a matter of how much headache you want.
>
> For instance, when constructing "software lego parts" (such as the
> Matlab/Simulink type), it's very annoying that you need to know what kind of
> signal comes in and goes out. In Malab/Simulink, for instance, you specify
> that the signal is of the "inherit" type (meaning you don't care what type
> it is - just process it). In Python, it's of type "duck", just pass it
> on...I don't need to care if it's real or complex. I don't need to devise
> yet another overloaded operator or function whenever I encounter a situation
> where the native language doesn't handle.
I'm not sure what you're talking about here. Python's complex numbers
are implemented with operator overloading. Python's integers are
implemented with operator overloading for that matter.
The only difference between having complex numbers in the standard
library (analogous to Math::Complex, if I'm reading these posts
correctly; I don't use Perl) and having complex numbers in the language,
per se, is the syntactical support:
>>> 5.0+1.j
versus
>>> complex(5, 1)
That's *it*.
Okay, on reflection, there's a little bit more to it: since complex
objects come as part of the interpreter, writing C extensions that use
complex objects is a little simpler. You don't have to include special
header files and make sure the correct module is imported before using
complex objects in the C code (like you have to do with Numeric, for
example).
--
Robert Kern
rkern@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
------------------------------
Date: Wed, 12 Jan 2005 04:22:00 GMT
From: "It's me" <itsme@yahoo.com>
Subject: Re: complex numbers
Message-Id: <IB1Fd.10566$5R.10225@newssvr21.news.prodigy.com>
"Robert Kern" <rkern@ucsd.edu> wrote in message
news:cs1mp9$sg9$1@news1.ucsd.edu...
>
> That's *it*.
So, how would you overload an operator to do:
With native complex support:
def twice(a):
return 2*a
print twice(3+4j), twice(2), twice("abc")
Let's presume for a moment that complex is *not* a native data type in
Python. How would we implement the above - cleanly?
------------------------------
Date: Wed, 12 Jan 2005 00:05:05 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: CPAN troubles again
Message-Id: <41e47931$0$27229$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Jim Keenan wrote:
> Arkady Zilberberg wrote:
>
>>Hello all,
>>a few days ago I posted a message describing my problems installing
>>a module from CPAN (namely, Win32::SerialPort).
>
>
> [snip]
>
>
>>I will try to debug the problem but it still doesn't answer my first
>>question "Why Win32::SerialPort doesn't create the Makefile?"
>
It's not intended to create a Makefile. The intention is that you run
(in succession):
perl Makefile.PL
perl test.pl
perl install.pl
That's the way the author set it up. Hard to see that such a procedure
is going to fit very well with CPAN and CPANPLUS requirements :-)
>
> It fails because it's a failure as a module. Go to
> http://testers.cpan.org/show/Win32-SerialPort.html#Win32-SerialPort-0.19
> and note that the module failed the one test it needed to pass, viz.,
> the test on Win32.
Yes - but it did pass 5 of the 7 test scripts - and on those 2 scripts
it did fail, it failed *all* tests, which looks (to me) suspiciously
like it could be a bug in those 2 scripts, rather than a problem with
the actual module.
> Go further to
> http://search.cpan.org/~bbirth/Win32-SerialPort-0.19/ and note that the
> module was last updated on 05 Nov 1999.
>
> In other words, it's dead.
>
I'm not so sure that's correct ..... it *may* be ..... I'm just not sure :-)
I think people are still getting good mileage out of this module.
> But to return to your original question: How to set the baud rate on a
> serial port (Perl under cygwin)? Why Cygwin? My impression is that
> Cygwin is primarily used to provide a Unix-like command interface in a
> Win32 environment, i.e., it's primarily for the programmer's
> convenience rather than for ongoing production. But your problem
> sounds like a production problem. What prevents you from solving this
> problem in a "regular" Win32 environment and perhaps using, say,
> ActivePerl, a Perl distribution fine-tuned for Win32?
>
No arguments there. What you say makes perfect sense. In any case,
installing the Win32-specific modules on Cygwin is always liable to be
difficult.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Wed, 12 Jan 2005 02:37:05 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: CPAN troubles again
Message-Id: <l30Fd.9790$eb.7754@trndny01>
Sisyphus wrote:
> Jim Keenan wrote:
>
[snip]
>
> It's not intended to create a Makefile. The intention is that you run
> (in succession):
> perl Makefile.PL
> perl test.pl
> perl install.pl
>
> That's the way the author set it up. Hard to see that such a procedure
> is going to fit very well with CPAN and CPANPLUS requirements :-)
>
Agreed.
>>
>
> Yes - but it did pass 5 of the 7 test scripts - and on those 2 scripts
> it did fail, it failed *all* tests, which looks (to me) suspiciously
> like it could be a bug in those 2 scripts, rather than a problem with
> the actual module.
>
Ah, you read farther than I did.
>> Go further to
>> http://search.cpan.org/~bbirth/Win32-SerialPort-0.19/ and note that the
>> module was last updated on 05 Nov 1999.
>>
>> In other words, it's dead.
>>
>
> I'm not so sure that's correct ..... it *may* be ..... I'm just not sure
> :-)
>
> I think people are still getting good mileage out of this module.
>
Rob Rothenberg, who's knowledgeable on Windows, reviewed this module at
http://cpanratings.perl.org/d/Win32-SerialPort. I think he would tend
to agree with your last statement.
Jim Keenan
------------------------------
Date: 11 Jan 2005 17:33:52 -0800
From: toomanyjoes@mail.utexas.edu
Subject: Deleting newlines in a text file
Message-Id: <1105493632.706298.217210@f14g2000cwb.googlegroups.com>
Hello,
I'm brand new to perl. I need to delete newlines from a text file but
only in the case that the line does not begin with a number. Then write
the results into a new text file.
For instance my text file looks like this.
1sampletextsampletextsamplet22tsampletextsampletextsampletext
2sampletextsampletextsampletextsam56etextsampletextsampletext
3sampletextsampletextsampletextsampletextsampletextsampletext
8sampletextsampletextsampletex765mpletextsampletextsampletext
9sampletextsampletextsampletextsampletextsampletextsampletext
15sampletextsampletextsampletextsampletextsampletextsampletext
sampletextsampletextsampletextsample324tsampletextsampletext
18sampletextsampletextsampletextsampletextsampletextsampletext
sampletextsampletextsampletextsampletextsampletextsampletext
sampletextsampletext566pletextsampletextsampletextsampletext
22sampletextsampletextsampletextsampletextsampletextsampletext
1sampletextsampletextsamplete467ampletextsampletextsampletext
As you can see I would like every line to START with a number.
Also after this is done I need another script that will grab the number
at the beginning and put it in a database field and then grab all the
"sampletext" up until the next number and put that in another database
field. This taking into account that there could be numbers within the
sampletext that are not found at the beginning of a line. These numbers
should be taken as part of the sample text and not confused with the
numbers at the beginning of the line.(A little harder I'm sure) Any
questions you guys can help me with I'll appreciate.
Thanks!
Joe
------------------------------
Date: Wed, 12 Jan 2005 01:44:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Deleting newlines in a text file
Message-Id: <0i%Ed.11578$F97.960@trnddc06>
toomanyjoes@mail.utexas.edu wrote:
> I'm brand new to perl. I need to delete newlines from a text file but
> only in the case that the line does not begin with a number.
> [...]
Just chomp() the line iff it starts with a digit
chomp if (/^\d/);
jue
------------------------------
Date: Tue, 11 Jan 2005 21:09:48 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Deleting newlines in a text file
Message-Id: <4uCdnQbFRc9wG3ncRVn-1g@comcast.com>
Jürgen Exner wrote:
> toomanyjoes@mail.utexas.edu wrote:
>> I'm brand new to perl. I need to delete newlines from a text file but
>> only in the case that the line does not begin with a number.
>> [...]
>
> Just chomp() the line iff it starts with a digit
>
> chomp if (/^\d/);
>
No, that doesn't do what he wants. What he wants to do is
chomp iff the *next* line does *not* begin with a digit.
my $last_line = <>;
while (<>) {
chomp ($last_line) if (/^\D/);
print $last_line;
$last_line = $_;
}
print $last_line;
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Wed, 12 Jan 2005 04:05:36 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Deleting newlines in a text file
Message-Id: <41e4a074.98283554@news.erols.com>
toomanyjoes@mail.utexas.edu wrote:
: I'm brand new to perl. I need to delete newlines from a text file but
: only in the case that the line does not begin with a number.
[snip]
: As you can see I would like every line to START with a number.
"...only in the case that the _next_ line does not begin with a number"
seems a more accurate description.
perl -pe "chomp;print $/ if $.>1 and /^\d/" file1 > file2
(Alter quotes to suit your shell, naturally.)
------------------------------
Date: Wed, 12 Jan 2005 00:47:58 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: GLOB vs IO::Handle
Message-Id: <41e4833d$0$27264$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Anno Siegel wrote:
>
>>By this point I get the distinct feeling that I just don't know
>>enough about this wheel to mess around with reinventing it. What's
>>the tried-and-true idiom for doing what I want to do?
>
>
> if ( defined fileno $x ) {
> # it's an open file handle
> }
>
> Anno
from 'perldoc -f fileno':
(Filehandles connected to memory objects via new features of
"open" may return undefined even though they are open.)
I don't know if/how that impacts on the OP's requirements - or on Anno's
solution, for that matter.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Tue, 11 Jan 2005 23:11:33 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Print question
Message-Id: <F2ZEd.4034$KJ2.1086@newsread3.news.atl.earthlink.net>
Print question
Is there a way to get Perl to print information on the display screen line
at the same time that it is generated?
I need to have a word etc. print and then have the cursor move to the right
for the next word to be printed etc. without a new line ( print "\n";) being
executed until later in time.
------------------------------
Date: Tue, 11 Jan 2005 18:33:08 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Print question
Message-Id: <duGdnUEx8Pio_3ncRVn-og@adelphia.com>
edgrsprj wrote:
> I need to have a word etc. print and then have the cursor move to the
> right for the next word to be printed etc. without a new line ( print
> "\n";) being executed until later in time.
Have a look at "perldoc -q buffer".
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 11 Jan 2005 15:46:13 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Print question
Message-Id: <1105487173.522425.191990@z14g2000cwz.googlegroups.com>
edgrsprj wrote:
>
> I need to have a word etc. print and then have
> the cursor move to the right for the next word
> to be printed etc. without a new line
> ( print "\n";) being executed until later in time.
Normally, a print() statement in Perl won't print a newline
unless you tell it to. Therefore, the following code:
#!/usr/bin/perl
use strict;
use warnings;
print "H";
print "i";
print "!";
print "\n";
__END__
will print:
Hi!
all on one line. However, if the "-l" switch is used in your
first line, like this:
#!/usr/bin/perl -l
then all your print() statements will print an extra newline.
Removing the "-l" switch will prevent the extra newline from
being printed, leaving it up to you to explicitly add them in
your print() statements.
I hope this helps.
-- Jean-Luc
------------------------------
Date: Tue, 11 Jan 2005 21:38:10 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Print question
Message-Id: <S8WdnR2SsY0IEHncRVn-iw@adelphia.com>
jl_post@hotmail.com wrote:
> Normally, a print() statement in Perl won't print a newline
> unless you tell it to.
Quite correct, but that doesn't answer the question. The OP is asking how to
unbuffer output, so it appears immediately, rather than a line at a time.
To illustrate this, insert a sleep(2) between each of the prints in your
example:
> #!/usr/bin/perl
> use strict;
> use warnings;
> print "H";
sleep(2);
> print "i";
sleep(2);
> print "!";
sleep(2);
> print "\n";
> __END__
You'd think this would print one letter at a time, with a pause in between -
but that's not what happens. What usually happens is a six second pause,
and then "Hi!" printed all at once, because output is buffered. (I say
"usually" because it's an OS feature, not a Perl feature, so it may not
apply to everyone. In particular, I don't know if it's true on Windows.)
The FAQ I mentioned addresses the buffering question. In brief - the FAQ
gives much more detail - you set $| to a true value to disable buffering.
So if you add:
$| == 1;
To your example, you get what the OP presumably wants from the sleep(2)
calls above - a two-second pause between each letter.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 11 Jan 2005 23:05:24 -0500
From: Wes Groleau <groleau+news@freeshell.org>
Subject: Three questions: UTF-8, DBM, hash of lists, ...
Message-Id: <X9qdnUVMy7Z1PHncRVn-2Q@gbronline.com>
I've been rooting around in perlutf8, perlencoding, perlunicode,
and other such things. I think I follow most of it, but there
are some contradictions. Or I thought there were.
1. At the moment, my source is pure ASCII, but I want to
treat it as UTF-8 because the text I work with is UTF-8
and my editor is configured accordingly. (And data
can easily become literals in source). I put -CSD on
my bang-line, which one man page said covers everything
(except -CL which I did not want for some reason). But
another man page seemed to say that "use utf8;" covered
something that -CSD did not, so I put that in, too. Is
either one interfering with the other in any way?
2. One of my applications is reading in a large file, finding
certain patterns, and using them as keys to store everything
else in a DBM hash (use DBM_File; dbmopen %hash, etc.)
The input is 99.5% ASCII--only a few French diacritics, one
copyright symbol, and two Polish characters. Yet adding
the utf-8 constructs to the script and regenerating the DBM
made a HUGE difference in the size of the file. Why is
that?
3. Say an input file contains key and value pairs, BUT
there is more than one possible value for a key.
For example, occupations.
Key Value
----------- ---------
firefighter Fred
chef Charlotte
firefighter Felicia
Can I store a list at the key, or do I have to append
to a string and split on output?
If I can store a list, what is the syntax? The following
is not allowed:
push (@the_hash{$the_job}, $the_name);
If the hash is tied with
use DBM_File;
dbmopen %the_hash .......
does that change the answer?
OK, more than three. :-)
--
Wes Groleau
In any formula, constants (especially those obtained
from handbooks) are to be treated as variables.
------------------------------
Date: Wed, 12 Jan 2005 04:31:19 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Three questions: UTF-8, DBM, hash of lists, ...
Message-Id: <rK1Fd.9829$eb.4142@trndny01>
Wes Groleau wrote:
>
> 3. Say an input file contains key and value pairs, BUT
> there is more than one possible value for a key.
>
> For example, occupations.
>
> Key Value
> ----------- ---------
> firefighter Fred
> chef Charlotte
> firefighter Felicia
>
> Can I store a list at the key, or do I have to append
> to a string and split on output?
>
> If I can store a list, what is the syntax? The following
> is not allowed:
>
>
> push (@the_hash{$the_job}, $the_name);
>
>
But wouldn't this be appropriate?
push @{$the_hash{$the_job}}, $the_name;
> If the hash is tied with
>
> use DBM_File;
> dbmopen %the_hash .......
Shouldn't that be ...?
use DB_file;
Jim Keenan
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7632
***************************************