[16455] in Perl-Users-Digest
Perl-Users Digest, Issue: 3867 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 1 03:10:28 2000
Date: Tue, 1 Aug 2000 00:10:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965113818-v9-i3867@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 1 Aug 2000 Volume: 9 Number: 3867
Today's topics:
Removing newline chars <troyr@vicnet.net.au>
Re: Removing newline chars <godzilla@stomp.stomp.tokyo>
Re: Removing newline chars (Rafael Garcia-Suarez)
Re: Removing newline chars (Logan Shaw)
Re: Removing newline chars <godzilla@stomp.stomp.tokyo>
Re: Removing newline chars (Logan Shaw)
Re: Running other programs in background ericr@yankthechain.com
simple perl script for Informix jblatz2@my-deja.com
size in bytes of a scalar <thalion@wonderd.com>
Re: size in bytes of a scalar (Logan Shaw)
Re: text file to HTML page <Tyler_L@techie.com>
Re: text file to html (brian d foy)
Re: Variable Interpolation Woes (Mark-Jason Dominus)
Win2000 ActivePerl EXE association grief c741535@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 1 Aug 2000 13:42:33 +1000
From: "Troy Rasiah" <troyr@vicnet.net.au>
Subject: Removing newline chars
Message-Id: <hIrh5.62580$N4.1826140@ozemail.com.au>
hi all,
Does anyone know how to get rid of the newline char (in one line)
when data is posted from a textarea field which contains carriage retuns
ie
$textareafield=~ s/\n//g;
$textareafield=~ s/\r//g;
That seems to work but is there a more easier way?
Troy
------------------------------
Date: Mon, 31 Jul 2000 21:25:24 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Removing newline chars
Message-Id: <39865134.632C2FC3@stomp.stomp.tokyo>
Troy Rasiah wrote:
> Does anyone know how to get rid of the newline char
> (in one line) when data is posted from a textarea
> field which contains carriage retuns
> $textareafield=~ s/\n//g;
> $textareafield=~ s/\r//g;
> That seems to work but is there a more easier way?
One of us knows. Others now know. A bit of deja vu
from several months back. Almost all self-proclaimed
Perl Gods here kept trying to cross plow my rows for
days on end claiming my statement a multiline form
action textbox will always return \r\n if a user
hits his or her carriage return. I am not sure they
have lived this one down. Seems a grudge match here.
You have it right. Just combine your codes into one.
$textareafield=~ s/\r\n//g;
Not so sure you need the global g if you are dealing
with only one line, kinda odd though. Nonetheless,
I believe it would be prudent to leave your g. A bit
of advice going beyond your question, if you don't
mind. You just might discover you will want to replace
those two characters with a space rather than nothing.
Different sentence lines will run together,
I am Dr. Victoria Frankie Einstein\r\n
creator of remarkable robots, Robby and Roberta.
without plugging in a space for \r\n you will get,
...Einsteincreator of....
This would be a better choice, just in case,
$textareafield=~ s/\r\n/ /g;
If you are using your own read and parse
routine, which I hope you are, you may
simply plug this into your read and parse
foreach loop, with an appropriate variable
name, quite often,
$val =~ s/\r\n/ /g;
or sometimes $value. This is an easy and
quick way to take care of business. Keep
in mind plugging this into your read and
parse routine will filter all form action
input, not just a textbox. You cannot do
this with cgi.pm for read and parse. This
is big no-no. Can't have doing your own
code programming.
There is one disadvantage to this method.
If you need to create an array of multiple
lines coming in from your textbox, removing
your \r\n kills this array creation ability
without a bit of fancy footwork. Plan ahead
if you have a need for an array based on
individual input sentence lines terminated
with a \n character.
Be wary of those who will jump in and begin
screaming about DOS characters, Unix characters,
Linux characters, Etch-A-Sketch characters and
Right Funny characters. You have this right.
Godzilla! \r\n
--
print "http://mailto:%63%61ll%67i%72l@3483852801/%7e%63%61ll%67i%72l";
------------------------------
Date: Tue, 01 Aug 2000 06:08:33 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Removing newline chars
Message-Id: <slrn8ocqkj.rvr.rgarciasuarez@rafael.kazibao.net>
Troy Rasiah wrote in comp.lang.perl.misc:
>hi all,
> Does anyone know how to get rid of the newline char (in one line)
>when data is posted from a textarea field which contains carriage retuns
>
>ie
>
>$textareafield=~ s/\n//g;
>$textareafield=~ s/\r//g;
>
>That seems to work but is there a more easier way?
You probably want to replace newlines by a space :
$textareafield =~ tr/\n/ /;
--
Rafael Garcia-Suarez
------------------------------
Date: 1 Aug 2000 01:25:09 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Removing newline chars
Message-Id: <8m5qg5$9rd$1@provolone.cs.utexas.edu>
In article <39865134.632C2FC3@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>One of us knows. Others now know. A bit of deja vu
>from several months back. Almost all self-proclaimed
>Perl Gods here kept trying to cross plow my rows for
>days on end claiming my statement a multiline form
>action textbox will always return \r\n if a user
>hits his or her carriage return.
A textarea doesn't return \r\n if the user is using lynx.
I just wrote a test script and found this out.
So anyway, it would be more in the spirit of defensive programming not
to assume a \r\n combination and instead convert them to spaces
independently:
$var =~ s/[\r\n]+/ /g;
This has the additional effect of converting several consecutive
newlines into a single space. If you do not want that, then it
becomes a little more complex. Something like this:
$var =~ s/(\r\n|\n\r|\r|\n)/ /g;
However, I'm not sure that perl's regular expression greediness will
lead it to use the longest of the alternatives.
- Logan
------------------------------
Date: Mon, 31 Jul 2000 23:39:27 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Removing newline chars
Message-Id: <3986709F.30D53FDE@stomp.stomp.tokyo>
Logan Shaw wrote:
(snipped)
> A textarea doesn't return \r\n if the user is using lynx.
> I just wrote a test script and found this out.
When a user hits Enter, what does an internet site form
action multi-line textbox return to a cgi script under
these circumstances?
Godzilla!
--
print "http://mailto:%63%61ll%67i%72l@3483852801/%7e%63%61ll%67i%72l";
------------------------------
Date: 1 Aug 2000 01:45:10 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Removing newline chars
Message-Id: <8m5rlm$9tk$1@provolone.cs.utexas.edu>
In article <3986709F.30D53FDE@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>Logan Shaw wrote:
>
>(snipped)
>
>> A textarea doesn't return \r\n if the user is using lynx.
>> I just wrote a test script and found this out.
>
>When a user hits Enter, what does an internet site form
>action multi-line textbox return to a cgi script under
>these circumstances?
I entered this string in my multi-line textarea:
lynx
is
such
a
great
browser
and running Data::Dumper on that field's value gave me this:
$VAR1 = "lynx\nis\nsuch\na\ngreat\nbrowser";
Doing the same thing with Netscape gives this:
$VAR1 = "lynx\r\nis\r\nsuch\r\na\r\ngreat\r\nbrowser";
Here is the (hastily-written) CGI I used to test it:
#! /usr/local/bin/perl
use CGI ':standard';
use Data::Dumper;
$Data::Dumper::Useqq = 1;
print header,
start_html ('textarea newline test'),
h1 ('textarea newline test'),
start_form,
"Please enter some text; be sure and hit return",
textarea (-name=>'testtext', -default=>'some text',
-rows=>10, -columns=>60),
p
submit ('candy-like button'),
end_form,
hr;
if (param())
{
print "You entered this text:", p,
pre (Dumper (param('testtext'))),
p;
}
print end_html;
- Logan
------------------------------
Date: Tue, 01 Aug 2000 06:28:54 GMT
From: ericr@yankthechain.com
Subject: Re: Running other programs in background
Message-Id: <8m5qn5$7sk$1@nnrp1.deja.com>
In article <ce6cosofej1cpfd292qp7quer3jia06f78@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
> ericr@yankthechain.com wrote:
>
> >Oy, now how do I close the application?
>
> Are you using ActiveState Perl 5.005 or Perl 5.5? Because you really
> ought to look at the module Win32::Process, but that currently only
> exists precompiled for Perl5.005, and these are not binary compatible.
> The DLL's made for one version will crash the other.
I'm running ActiveState Perl 5.6. Out of curiousity, do you know why
they didn't port Win32::Process to the new version of Perl?
> To make a long story short: this module has a "Kill" method.
I tried $WinExec->Kill();, $WinExec->Kill("data\mplayer2"); and
$WinExec->destroy();, and in all three cases the program froze on me
and I got an "Out of memory!" error and had to cntl-alt-del the
program...
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 01 Aug 2000 01:12:18 GMT
From: jblatz2@my-deja.com
Subject: simple perl script for Informix
Message-Id: <8m585f$rak$1@nnrp1.deja.com>
I just installed DBD::Informix. I have absolutely no clue how to run a
simple test that will give me some output.
Could someone give me a really simple perl script to do a query just so
I can see if the install went well. I'm on a Unix platform. I know
quite a bit about Informix, but not a heck of a lot about perl.
I know I should read my manuals, and I will, but it would really save me
a lot of time if I could just get over this first hurdle.
Thanks very much.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 31 Jul 2000 21:49:56 -0700
From: "HappyHippo" <thalion@wonderd.com>
Subject: size in bytes of a scalar
Message-Id: <8m5ks0$nat$1@nntp9.atl.mindspring.net>
Is there a way in perl5 to determine the size in bytes
of a scalar/array/hash/whatever.
I am filling a scalar with the data from a binary file,
and I need to know the size of this scalar without
looking at the file. :)
any help is greatly appreciated,
thanks!
------------------------------
Date: 1 Aug 2000 01:33:33 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: size in bytes of a scalar
Message-Id: <8m5qvt$9s6$1@provolone.cs.utexas.edu>
In article <8m5ks0$nat$1@nntp9.atl.mindspring.net>,
HappyHippo <thalion@wonderd.com> wrote:
>Is there a way in perl5 to determine the size in bytes
>of a scalar/array/hash/whatever.
I assume what you're asking about is the size of the data stored in
these items, rather than the number of bytes perl uses internally to
represent them.
Anyway, length() tells you size in bytes of a scalar. For the others,
you will need to iterate over the elements and find their sizes
individually. For instance:
$length = 0;
foreach (@my_array) { $length += length; }
The simple way for a hash is this:
$length = 0;
foreach (keys %my_hash, values %my_hash) { $length += length; }
The longer but probably faster way is this:
$length = 0;
while ( ($key, $value) = each %my_hash )
{ $length += length $key + length $value; }
Hope that helps.
- Logan
------------------------------
Date: Mon, 31 Jul 2000 23:47:14 -0700
From: Tyler Larson <Tyler_L@techie.com>
Subject: Re: text file to HTML page
Message-Id: <39867272.7EA657DE@techie.com>
Dr M Hughes wrote:
> Please could someone tell me how to convert the results of a program
> that are in the way of a text file (.txt as i'm on windows) into an HTML file
> that I can return to the browser in my CGI script?
>
> Thanks
> Rich
>
> please reply to r.dobson@microscience.com
I think what you'd need to decide first of all (as the others have hinted at) is
*why* you want to translate a .txt file into HTML. The reason being because your
major difference between HTML and plain text is that HTML is formatted (bold,
underline, colors, links, inserted images, etc.) while plain text
is...well...plain text. In other words, converting straight over to HTML from
plain text doesn't add much... if anything at all. Therefore, a viable
possibility would simply be to preface the output with the string "Content-Type:
text/plain\n\n" instead of "Content-Type: text/html\n\n" which signals to the
browser that the text you're sending should not be interpreted as HTML, but just
displayed as-is. Each browser may have a different way of going about displaying
it, but the result *should* be satisfactory.
Now if you don't like the idea of leaving it up to the browser to decide how to
display your text (as many web authors don't), then you always have the option of
formatting the text in HTML to _look like_ a plain text file. That's the
reasoning behind the:
print "<pre>\n";
print <FILE>;
print "</pre>";
option previously offered. But as Alan pointed out, doing just that overlooks an
important detail: There are specific characters that have special purposes in
HTML that you can't just output as they are. The characters < and > are used to
indicate HTML tags and won't be printed by the browser. Instead you'll have to
substute them with < and > respectively. Also important (though not as
serious), the ampersand (&) sould be translated to & and quote (") to "
And possibly the most important detail to keep in mind is that ALL whitespace is
treated the same, and no matter how many spaces and blank lines you insert, all
consecutive whitespaces will be reduced to one single space when it is
displayed. If you want to go to the next line, you have to specifically say so
with the <br> tag (or with any block-level tag, but that's beside the point).
There are a lot of special characters that are available in HTML that don't exist
in ASCII. So if any of these other characters come in handy for you, you
probably would want to consider using HTML instead of plain text. If you want to
know more about the character set used in HTML, you may want to try looking in
the www.w3c.org site (the w3c is the organization that decides what should--and
should not--be considered HTML. The pages
http://www.w3.org/TR/html401/sgml/entities.html#h-24.2.1 or
http://www.w3.org/TR/html401/charset.html
for example might have something that you'd find useful.
Now if you want to make your page pretty with formatting and such, then you need
to decide what to format-- what to make big or bold or red or gold (you're the
artist). That's why we haven't given you any suggestions in that area. If you
want to know more about HTML tags so you can create it yourself then you might
try looking in http://www.w3.org/MarkUp/ (that's where I learned how to write web
pages so many moons ago)
If you like the idea simply converting your plain text into "plain" HTML-- that
is, changing it so that it looks like plain text without telling the browser that
that's what it is, then I'd say I like Yidao Cai's solution. I tried it out and
I think it works pretty nicely. A couple of things that you might add would be
(and this is imparative) the string "Content-Type: text/html\n\n" at the very
beginning (if this isn't already added elsewhere). And you might want to put in
some header information as well (Page title, text color, background color, etc).
And if you want to use a monospace font, put a <pre> at the beginning of your
text and a </pre> at the end.
I hope I've answered any questions. If something's not clear then let us know.
-Tyler
------------------------------
Date: Tue, 01 Aug 2000 01:57:28 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: text file to html
Message-Id: <brian-ya02408000R0108000157280001@news.panix.com>
In article <sgmh5.63$DT4.2135971@nnrp2.clara.net>, ckeith@clara.net (Colin Keith) posted:
> As someone who writes scripts I write them as though it is my file and I
> know the contents. Since this was a suggestion as to how to the author could
> copy a file and with lack of further evidence I assumed he would control the
> script and the file. Not a huge leap of faith, but...
you assume to much, in both cases.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Tue, 01 Aug 2000 05:37:35 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Variable Interpolation Woes
Message-Id: <3986621e.111a$2ee@news.op.net>
In article <1103_965088960@eratos>, <abliss@mindspring.com> wrote:
>print 'The error '.$dbh->errmsg().' occured.';
print "The error $DBI::errstr occurred.";
------------------------------
Date: Tue, 01 Aug 2000 06:43:45 GMT
From: c741535@my-deja.com
Subject: Win2000 ActivePerl EXE association grief
Message-Id: <8m5rj2$8as$1@nnrp1.deja.com>
Howdy,
I used to run ActivePerl on a WinNT box, no problems. I've just installed the
lastest build (616?) onto a Win2000 Pro server and have found that the IIS
associations for the ISAPI and EXE's for Perl have not been put in by the
install (eg. associate '.pl' files with 'bin\perl.exe') even though the boxes
in the install were ticked (double checked).
I've manually put the ISAPI DLL into the list and that works fine. Only
problem is when I use a '.plx' file and I've got errors they don't go to the
browser so I can't debug 'em. Generally in the past I've always used the
'.pl' (associated with Perl.exe) when building/debuging code cos it gives me
the error text to the browser. Then I move to '.plx' for production to speed
it up.
My problem is that I thought the association for the EXE would be a simple
'bin\Perl.exe' but this isn't working even on a simple 'hello world' script
(the script works fine if I change the extension to '.plx' and run it through
the ISAPI DLL). If I set up the association for Perl.exe the browser just
sits there forever and I can't even kill the Perl process as I get a
'Permission denied' message (reboot is required to kill it). I can run the
perl script from the command line.
So two questions - 1. Is there a way to display the perl debug output if I
use the ISAPI DLL as the interpreter? or 2. Can anyone tell me the correct
IIS association for using the EXE?
One answer to either question would put me in the clear.
Thanks alot for reading this, appreciated!
Regards,
Andy.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3867
**************************************