[25794] in Perl-Users-Digest
Perl-Users Digest, Issue: 8033 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 30 14:05:18 2005
Date: Sat, 30 Apr 2005 11:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 30 Apr 2005 Volume: 10 Number: 8033
Today's topics:
a regex question .. <geoff.cox@notquitecorrectfreeuk.com>
Re: a regex question .. <pilkowsk@informatik.uni-marburg.de>
Re: a regex question .. <lists@nihil.ch>
About formatting <hackeras@gmail.com>
Re: About formatting <sbryce@scottbryce.com>
Re: About formatting <john@castleamber.com>
Re: About formatting <noreply@gunnar.cc>
Re: About formatting <hackeras@gmail.com>
Re: About formatting <hackeras@gmail.com>
missing the boat <mdetomaso@bak.rr.com>
Re: multiples ifs <hackeras@gmail.com>
Re: multiples ifs <sbryce@scottbryce.com>
Re: multiples ifs <john@castleamber.com>
Re: multiples ifs <hackeras@gmail.com>
Re: Perfecting index.pl some more! <tassilo.von.parseval@rwth-aachen.de>
Re: Perfecting index.pl some more! <hackeras@gmail.com>
Re: Perfecting index.pl some more! <hackeras@gmail.com>
Performance question with a string concat <mail@xanthos.de>
Re: Performance question with a string concat <1usa@llenroc.ude.invalid>
Re: Performance question with a string concat <mikeh@perusion.net>
Re: Performance question with a string concat <notvalid@email.com>
Re: Performance question with a string concat <spamtrap@dot-app.org>
Re: Performance question with a string concat xhoster@gmail.com
POST data with XMLHttpRequest to CGI (Mozilla) <jarsonk@nospam.com>
Re: POST data with XMLHttpRequest to CGI (Mozilla) <andy@andyh.co.uk>
Re: POST data with XMLHttpRequest to CGI (Mozilla) <mahotrash@yahoo.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 30 Apr 2005 17:20:53 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: a regex question ..
Message-Id: <6bf771l756pr1u3nctc61bf4ngeisp664s@4ax.com>
Hello
I am trying to rename a list of files by changing any single digits in
the names to a zero and the digit, eg 7 -> 07.
Problem is there may be 2 instances in the name and the code below
only works for the first single digit - how can I deal with both
instances?
if ($name =~ /^(.*?)\-(\d{1})\D(.*?)$/ ) {
my $num = $2;
rename ($name, "new-" . $1 . "-" . "0" . $num . "-" . $3);
I have tried using tr/// but cannot see how to do it.
My guess would be that the above is not the best way to go about this!
Cheers
Geoff
------------------------------
Date: Sat, 30 Apr 2005 19:45:24 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: a regex question ..
Message-Id: <3dhufoF6riahmU1@individual.net>
* Geoff Cox schrieb:
> Hello
>
> I am trying to rename a list of files by changing any single digits in
> the names to a zero and the digit, eg 7 -> 07.
>
> Problem is there may be 2 instances in the name and the code below
> only works for the first single digit - how can I deal with both
> instances?
>
>
> if ($name =~ /^(.*?)\-(\d{1})\D(.*?)$/ ) {
> my $num = $2;
>
> rename ($name, "new-" . $1 . "-" . "0" . $num . "-" . $3);
>
> I have tried using tr/// but cannot see how to do it.
> My guess would be that the above is not the best way to go about this!
Yes, it isn't. Try to use s/// instead.
my $name = 'aaa2bbb3';
( my $newname = $name ) =~ s/(\d)/0$1/g;
# results in: $newname = 'aaa02bbb03'
Be aware of the /g-modifier at the end of s///. Read `perldoc perlop` to
learn more about this substitution operator.
regards,
fabian
------------------------------
Date: Sat, 30 Apr 2005 19:49:31 +0200
From: Elvis Cehajic <lists@nihil.ch>
Subject: Re: a regex question ..
Message-Id: <d50ggf$v4q$1@news.hispeed.ch>
Hi
Fabian Pilkowski wrote:
> Yes, it isn't. Try to use s/// instead.
>
> my $name = 'aaa2bbb3';
> ( my $newname = $name ) =~ s/(\d)/0$1/g;
> # results in: $newname = 'aaa02bbb03'
Just keep in mind that this will change 'aaa11bbb12' to 'aaa0101bbb0102'
which is probably not what the OP wants. But right now i can't think of
a solution myself...
>
> Be aware of the /g-modifier at the end of s///. Read `perldoc perlop` to
> learn more about this substitution operator.
>
> regards,
> fabian
Elvis
--
Elvis Cehajic
http://www.nihil.ch
perl -e '$_="(o_\n//\\\x0AV_/_\x20\u\x6C\x69\x6E\x75\x78\n";print'
------------------------------
Date: Sat, 30 Apr 2005 18:20:23 +0300
From: Nikos <hackeras@gmail.com>
Subject: About formatting
Message-Id: <d507nj$3e4$1@nic.grnet.gr>
print start_form(-action=>'index.pl');
print p( {-align=>'center'}, span( {class=>'tip'}, "ÄéÜëåîå Ýíá
áðü ôá êåßìåíá ãéá íá äéáâÜóåéò => " ),
popup_menu( -name=>'select',
-values=>\@display_files ),
submit('ÅðéëïãÞ'));
print end_form;
This is non-Perl question but i really must understand why its not working:
inside styles.css i have:
td.tip {
font: 18px times;
color: cyan;
}
But i cant see thes quotes text in "big centered lime colored text"
Sorry for asking this. I googles but i got general stuff not answer to
this specific question.
------------------------------
Date: Sat, 30 Apr 2005 09:30:20 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: About formatting
Message-Id: <FI2dndZnMIoXOe7fRVn-hg@comcast.com>
Nikos wrote:
> This is non-Perl question but i really must understand why its not
> working:
Post the resultng HTML (not the Perl that produces it) to an HTML
newsgroup and ask there.
------------------------------
Date: 30 Apr 2005 15:42:09 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: About formatting
Message-Id: <Xns96486CDD2C7A4castleamber@130.133.1.4>
Nikos wrote:
> Sorry for asking this. I googles but i got general stuff not answer to
> this specific question.
alt.html
comp.infosystems.www.authoring.stylesheets
comp.infosystems.www.authoring.html
Don't apoligise for posting in the wrong group on purpose, most people
don't accept this. If you keep doing it, some kill file you. Also, if you
*have to know* you *have to learn*.
Oh, and don't post your perl script in those groups, save your HTML to a
file, look at the source, remove all that is not needed to show the
problem, and then ask (same for css).
Don't crosspost to those groups, just pick the *right* one. But first, look
at the HTML *source*, and try to pin down the problem. Sometimes closing
your browser, and opening it again might help.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sat, 30 Apr 2005 17:38:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: About formatting
Message-Id: <3dhnc0F6lb5h7U1@individual.net>
Nikos wrote:
> print start_form(-action=>'index.pl');
> print p( {-align=>'center'}, span( {class=>'tip'}, "ÄéÜëåîå Ýíá
> áðü ôá êåßìåíá ãéá íá äéáâÜóåéò => " ),
> popup_menu( -name=>'select',
> -values=>\@display_files ),
> submit('ÅðéëïãÞ'));
> print end_form;
>
> This is non-Perl question but i really must understand why its not working:
So what? It doesn't justify in any way that you keep asking off topic
questions in a Perl newsgroup!
> inside styles.css i have:
>
> td.tip {
> font: 18px times;
> color: cyan;
> }
>
> But i cant see thes quotes text in "big centered lime colored text"
Using the 'align' attribute in a p element is deprecated. Here is a
place to go to learn and look up things about HTML:
http://www.w3.org/TR/html4/
As regards basic CSS, go here: http://www.w3.org/TR/1999/REC-CSS1-19990111
If you encounter difficulties when reading those documents, but only
then, please ask for help in forums that deal with HTML and CSS. Not here!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 30 Apr 2005 19:10:47 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: About formatting
Message-Id: <d50am3$62u$1@nic.grnet.gr>
Scott Bryce wrote:
> Nikos wrote:
>
>> This is non-Perl question but i really must understand why its not
>> working:
>
>
>
> Post the resultng HTML (not the Perl that produces it) to an HTML
> newsgroup and ask there.
ok.
------------------------------
Date: Sat, 30 Apr 2005 19:26:57 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: About formatting
Message-Id: <d50bkd$dbo$1@nic.grnet.gr>
Gunnar Hjalmarsson wrote:
> Using the 'align' attribute in a p element is deprecated. Here is a
> place to go to learn and look up things about HTML:
> http://www.w3.org/TR/html4/
>
> As regards basic CSS, go here: http://www.w3.org/TR/1999/REC-CSS1-19990111
>
> If you encounter difficulties when reading those documents, but only
> then, please ask for help in forums that deal with HTML and CSS. Not here!
Thank you, i just though that becausing it was consernign cgi.pm i could
be justified if i could ask a little, but its ok from now and and on i wont.
------------------------------
Date: Sat, 30 Apr 2005 17:49:57 GMT
From: "Michael De Tomaso" <mdetomaso@bak.rr.com>
Subject: missing the boat
Message-Id: <9zPce.15457$R46.3867@tornado.socal.rr.com>
10:21 AM 4/30/2005 ... http://paste.wizbit.be/?i=1380022146&t=t
------------------
Q: given a text file: "arp.txt" as follows:
contents of "arp.txt"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
D:\study\perl\WIP>type arp.txt
Interface: 192.168.1.100 --- 0x2
Internet Address Physical Address Type
192.168.1.107 00-01-02-7c-94-47 dynamic
192.168.1.109 00-50-ba-a2-90-86 dynamic
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I'd like to pull out a specific mac address: "00-50-ba-a2-90-86 "
here is my simple program:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!perl -w
print "where is mdtFRIENDS:\n";
print `grep "00\-50\-ba\-a2\-90\-86" arp.txt`;
print "test over\n";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Q: why don't get the line with the mac address on the screen?
I can pull it out without perl like this:
D:\study\perl\WIP>grep "00\-50\-ba\-a2\-90\-86" arp.txt
192.168.1.109 00-50-ba-a2-90-86 dynamic
Q: where am I missing the boat???
-----
- thanks & take care M.D.
<aka>
_ _
| |_ ___ _ __ ___ __ _ | |_ ___ ___
| __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/
\__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
------------------------------
Date: Sat, 30 Apr 2005 17:39:39 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: multiples ifs
Message-Id: <d505b8$166$1@nic.grnet.gr>
Brian McCauley wrote:
>
>
> Scott Bryce wrote:
>
>> Nikos wrote:
>>
>>> I think there must me a smarter way of writing this.
>>
>>
>>
>> I think it is fine. I would probably do something very similar if I
>> wrote it.
>
>
> Yes, I largely agree with Scott. But I'd change the line
>
> exit 0 if ($i!=0);
>
> To the more ideomatic
>
> exit 0 if $error_found;
>
> (Condister the "read it aloud" test).
>
> I'd also make $error_found a counter using ++ rather than a flag using
> =1. It's not necessary and it's actually slightly slower but I find it
> more idomatic.
>
> Also since you (Nikos) do the same thing four times to four variables
> ($name,$pray,$remark,$email) you may want to consider makeing those a
> hash. I general if you find you are doing very similar things to a
> series of descrete scalars you probably really wanted an agregate.
>
> But rewriting the chain of unless() statements as a loop would probably
> only pay off in the short term until you got above four. Of course in
> the longer term getting into the habit of always abstracting out anthing
> you do _three_ times is good and I see that you (Nikos) sense that.
>
> Does it matter the order in which the tips appear? If not you can put
> them in a hash and loop over it. (But only if the fields are in a hash
> too).
>
> On a non-Perl issue I suspect the <span> HTML tag would be more
> appropriate than the deprocated <font> one. Actually you appear to have
> misunderstood what <p> means in HTML. You are confusing it with <br>. It
> is illegal (an hense undefined what would happen) to put a <p> inside a
> <font> or <span>.
Thank you for pointing out this non-Perl issuse because it troubles on
what concerns to print correctly the output from the database:
while( $row = $sth->fetchrow_hashref )
{
print table( {class=>'user_form'},
Tr( {-align=>'center'},
td( {-width=>'25%'}, font( {class=>'name'},
$row->{name} )),
td( {-width=>'50%'}, font( {class=>'host'},
$row->{email} )),
td( {-width=>'25%'}, font( {class=>'date'},
$row->{date} ))
),
Tr(
td( {-align=>'center'}, font( {class=>'host'}, "
" )),
td( {colspan=>2}, font( {class=>'host'},
$row->{pray} ))
),
Tr(
td( {-align=>'center'}, font( {class=>'host'},
" " )),
td( {colspan=>2}, font( {class=>'host'},
$row->{remark} ))
),
Tr( {-align=>'center'},
td( {colspan=>3}, font( {class=>'host'},
$row->{host} )))
),
br() x 2;
}
Perhaps can you suggest me a better way of writing this?
why font is deprecated? does span acts the same?
------------------------------
Date: Sat, 30 Apr 2005 09:26:55 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: multiples ifs
Message-Id: <FI2dnddnMIojPu7fRVn-hg@comcast.com>
Nikos wrote:
> Perhaps can you suggest me a better way of writing this?
> why font is deprecated? does span acts the same?
Those are questions for a different newsgroup.
------------------------------
Date: 30 Apr 2005 15:37:36 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: multiples ifs
Message-Id: <Xns96486C1786011castleamber@130.133.1.4>
Nikos wrote:
> why font is deprecated?
Because it's visual markup. The idea behind HTML was that it provides
*structure* to a document, and that the user agent does the visual work.
CSS is now the recommended way to give the user agent visual hints.
> does span acts the same?
With proper CSS, yes. If you want a different visual representation of text
in your table, the best way is to use CSS to define the font of the table.
If you want your td's to have a different font, use
<td class="name">...</td><td class="email">...</td><td class="date"></td>
There is no need to introduce a span.
You can also decide to make the class you use the most the default of td.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sat, 30 Apr 2005 19:17:06 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: multiples ifs
Message-Id: <d50b1v$b0j$1@nic.grnet.gr>
John Bokma wrote:
> There is no need to introduce a span.
>
> You can also decide to make the class you use the most the default of td.
I hope you mean something like the following i was trying at the moment:
while( $row = $sth->fetchrow_hashref )
{
print table( {class=>'user_form'},
Tr(
td( {-width=>'25%'}, {class=>'name'}, $row->{name}
),
td( {-width=>'50%'}, {class=>'email'},
$row->{email} ),
td( {-width=>'25%'}, {class=>'date'}, $row->{date}
)
),
Tr(
td( {class=>'host'}, "Åõ÷Þ ôïõ
Éçóïý" ),
td( {colspan=>2}, {class=>'tip'}, $row->{pray}
)
),
Tr(
td( {class=>'tip'}, "ÐñïóùðéêÞ
ÏñèïäïîïðíåõìáôéêÞ Åìðåéñßá" )),
td( {colspan=>2}, {class=>'remark'},
$row->{remark} )
),
Tr(
td( {colspan=>3}, {class=>'host'}, $row->{host}
)
),
br() x 2;
}
and the style.css like:
Tr {
text-align: center;
border: 2px inset blue;
}
td {
border: 1px inset yellow;
}
td.tip {
font: 18px times;
color: cyan;
}
td.host {
font: 18px comic;
color: lime;
}
td.date {
font: 18px comic;
color: yellow;
}
td.passage {
font: 18px orange;
color: lime;
}
td.counter {
font: 18px comic;
color: cyan;
}
ps. Scott tole me not to post formating issued here but since you
answered lets finish it please.
------------------------------
Date: Sat, 30 Apr 2005 16:03:19 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Perfecting index.pl some more!
Message-Id: <slrnd77417.ql.tassilo.von.parseval@localhost.localdomain>
Also sprach Nikos:
> Tassilo v. Parseval wrote:
You should use quotation marks to indicate which parts I wrote and which
were yours.
> Also i didnt quite understand what are you tryign to say here!
> Can you please clarify it to em some more?
[quotations inserted for clearity]
>> As you want shorter code, here's one way:
>>
>> s/\n/\\n/g,
>> s/"/\\"/g ,
>> tr/\cM//d ,
>> for $data;
This is functionally equivalent to what you've written, which was:
$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
By using 'for $data', $data gets aliased to $_ which is the default
variable that s/// and tr/// act upon. By using 'for' as a
statement-modifier (that is: in postfix notation) no block is needed
which would normally be the case if you wrote:
for ($data) {
s/\n/\\n/g;
s/"/\\"/g;
tr/\cM//d;
}
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: Sat, 30 Apr 2005 17:54:34 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perfecting index.pl some more!
Message-Id: <d50676$1vt$1@nic.grnet.gr>
Brian McCauley wrote:
{snip]
Thanks Brain, i applied your suggestions and now its more straighforward
and clear to the eye!
--
I knew UNIX before it was spelled L I N U X
and
I knew INTERNET before it was spelled W W W
------------------------------
Date: Sat, 30 Apr 2005 18:27:33 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Perfecting index.pl some more!
Message-Id: <d50851$3s8$1@nic.grnet.gr>
Tassilo v. Parseval wrote:
> By using 'for $data', $data gets aliased to $_ which is the default
> variable that s/// and tr/// act upon. By using 'for' as a
> statement-modifier (that is: in postfix notation) no block is needed
> which would normally be the case if you wrote:
>
> for ($data) {
> s/\n/\\n/g;
> s/"/\\"/g;
> tr/\cM//d;
> }
Aaah, now i get it! This i can understnad thank you.
The reason iam writing this is because i have to pass the variable $data
to the upcoming javascript code:
print <<ENDOFHTML;
<html><head><title></title>
<script type='text/javascript'>
var textToShow = "$data";
{snip more code]
$data is supposed to hold all the contents of the user_selected_file
that he previously choosed to see from a drop down menu:
If i dont then substitune that chars then js wont work and the file will
not be displayed at all.
you can see how js is functioning at my home webpage http://www.nikolas.tk
With your help the index.pl script is getting better & better and i
thank you all for that. :-)
------------------------------
Date: Sat, 30 Apr 2005 16:21:16 +0200
From: Simon von Janowsky <mail@xanthos.de>
Subject: Performance question with a string concat
Message-Id: <42739430_1@news.arcor-ip.de>
Hello,
I want to let grow a string variable within a loop.
A non-interpolated string '' is said to be faster than the usual "" string.
Disadvantage of the non-interpolated string is that \n is not recognized.
Now, what would be faster?
a.)
my $out;
for (my $c = 0; c < 100; c++)
{
$out .= "variable=\"value\" \n";
}
oder b.)
my $out;
for (my $c = 0; c < 100; c++)
{
$out .= 'variable="value"' . "\n";
}
And what if interpolation is needed?
c.)
my $out;
for (my $c = 0; c < 100; c++)
{
$out .= "variable=\"$value\" \n";
}
oder d.)
my $out;
for (my $c = 0; c < 100; c++)
{
$out .= 'variable=" . $value . '"' . "\n";
}
Thanks a lot.
--
Viele Gre || Greetings || Saludos,
Simon von Janowsky.
------------------------------
Date: Sat, 30 Apr 2005 14:37:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Performance question with a string concat
Message-Id: <Xns96486BFA82197asu1cornelledu@127.0.0.1>
Simon von Janowsky <mail@xanthos.de> wrote in
news:42739430_1@news.arcor-ip.de:
> Now, what would be faster?
You can measure it, you know.
> a.)
...
> oder b.)
...
>
...
> c.)
...
> oder d.)
perldoc Benchmark
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 30 Apr 2005 14:44:29 -0000
From: Mike Heins <mikeh@perusion.net>
Subject: Re: Performance question with a string concat
Message-Id: <slrnd776ec.apk.mikeh@bill.heins.net>
On 2005-04-30, Simon von Janowsky <mail@xanthos.de> wrote:
> Hello,
> I want to let grow a string variable within a loop.
> A non-interpolated string '' is said to be faster than the usual "" string.
Not by much.
> Disadvantage of the non-interpolated string is that \n is not recognized.
>
> Now, what would be faster?
>
Why not try the Benchmark module and see?
use Benchmark;
my $code1 = sub {
my $out = '';
for(1 .. 1000) {
$out .= 'variable="value"' . "\n";
}
return $out;
};
my $code2 = sub {
my $out = '';
for(1 .. 1000) {
$out .= qq{variable="value"\n};
}
return $out;
};
use Benchmark;
timethese ( -5, {
SQUOTE => $code1,
DQUOTE => $code2,
});
Benchmark: running DQUOTE, JOIN, SQUOTE for at least 5 CPU seconds...
DQUOTE: 6 wallclock secs ( 5.34 usr + 0.00 sys = 5.34 CPU) @ 3495.51/s (n=18666)
SQUOTE: 6 wallclock secs ( 5.31 usr + 0.00 sys = 5.31 CPU) @ 3513.37/s (n=18656)
Benchmark: running DQUOTE, SQUOTE for at least 5 CPU seconds...
DQUOTE: 5 wallclock secs ( 5.26 usr + 0.00 sys = 5.26 CPU) @ 3484.22/s (n=18327)
SQUOTE: 6 wallclock secs ( 5.27 usr + 0.00 sys = 5.27 CPU) @ 3477.61/s (n=18327)
Looks like there is not a great difference. Perl has really gotten better
at string concats over the years -- at one point pushing the strings onto
an array and later doing a join() was competittive, and now it is not.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
Be patient. God isn't finished with me yet. -- unknown
------------------------------
Date: Sat, 30 Apr 2005 14:53:29 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Performance question with a string concat
Message-Id: <JZMce.2952$zu.2566@newssvr13.news.prodigy.com>
Simon von Janowsky wrote:
> Hello,
> I want to let grow a string variable within a loop.
> A non-interpolated string '' is said to be faster than the usual "" string.
> Disadvantage of the non-interpolated string is that \n is not recognized.
>
> Now, what would be faster?
If you are concerned about the speed of single-quoted vs. double-quoted
strings, then you should not be programming in Perl. Any difference will
be miniscule.
If your app is slow and you want to speed it up, then use the Benchmark
module and try to figure out which section of your code takes the most
time, and optimize that.
--Ala
------------------------------
Date: Sat, 30 Apr 2005 11:12:41 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Performance question with a string concat
Message-Id: <sKKdnW9hM5_3Pe7fRVn-sg@adelphia.com>
Ala Qumsieh wrote:
> If your app is slow and you want to speed it up, then use the Benchmark
> module and try to figure out which section of your code takes the most
> time
I think you might mean Devel::DProf here, although both it and Benchmark
are useful to the overall process.
After using Devel::DProf to find out which subroutine takes the most
time, you can then use Benchmark to compare alternative implementations
of that subroutine against one another.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 30 Apr 2005 18:03:44 GMT
From: xhoster@gmail.com
Subject: Re: Performance question with a string concat
Message-Id: <20050430140344.525$1O@newsreader.com>
Simon von Janowsky <mail@xanthos.de> wrote:
> Hello,
> I want to let grow a string variable within a loop.
> A non-interpolated string '' is said to be faster than the usual ""
> string. Disadvantage of the non-interpolated string is that \n is not
> recognized.
>
> Now, what would be faster?
>
> a.)
> my $out;
> for (my $c = 0; c < 100; c++)
> {
> $out .= "variable=\"value\" \n";
> }
>
> oder b.)
> my $out;
> for (my $c = 0; c < 100; c++)
> {
> $out .= 'variable="value"' . "\n";
> }
Those seem to compile down to the same thing (except that one has
a space before the \n and the other doesn't) so they should have the same
speed.
>
> And what if interpolation is needed?
Try it and see.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Sat, 30 Apr 2005 12:55:08 -0400
From: "Jarson" <jarsonk@nospam.com>
Subject: POST data with XMLHttpRequest to CGI (Mozilla)
Message-Id: <RLOce.16634$BW6.1394314@news20.bellglobal.com>
My JavaScript is trying to POST data to a CGI script (Perl) using
XMLHttpRequest. My CGI server gets different data from IE than Mozilla
Firefox.
// For Mozilla, req = new XMLHttpRequest();
// For IE req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = requestHandler ; // function to handle async
response
req.open('POST', myURL, true); // use POST
req.send('foo=11&bar=22') ;
A Perl CGI script prints the parameters passed to it.
$q = new CGI ;
foreach my $param ($q->param) {
print "$param: " . $q->param($param) . "\n" ;
}
The data received by the CGI script is inconsistent, depending if the client
is IE or Mozilla (Firefox)
Server result from IE client:
foo: 11
bar: 22
Server result from Mozilla Firefox client:
POSTDATA: foo=11&bar=22
It seems that the POST data IE sends is more correct than the Mozilla data.
Is there another way to send the data in Mozilla so the CGI script will give
the same results. I could easily adjust the CGI script, but I think the
problem is at the client.
Jarson (jarson from sygration, that's a dot com company if you need to send
an email)
------------------------------
Date: Sat, 30 Apr 2005 18:34:38 +0100
From: Andy Hassall <andy@andyh.co.uk>
Subject: Re: POST data with XMLHttpRequest to CGI (Mozilla)
Message-Id: <g9g7715il6genr0kbv7fjkf2mrncig5id7@4ax.com>
On Sat, 30 Apr 2005 12:55:08 -0400, "Jarson" <jarsonk@nospam.com> wrote:
>My JavaScript is trying to POST data to a CGI script (Perl) using
>XMLHttpRequest. My CGI server gets different data from IE than Mozilla
>Firefox.
>
>// For Mozilla, req = new XMLHttpRequest();
>// For IE req = new ActiveXObject("Microsoft.XMLHTTP");
> req.onreadystatechange = requestHandler ; // function to handle async
>response
> req.open('POST', myURL, true); // use POST
> req.send('foo=11&bar=22') ;
>
>A Perl CGI script prints the parameters passed to it.
> $q = new CGI ;
> foreach my $param ($q->param) {
> print "$param: " . $q->param($param) . "\n" ;
> }
>
>The data received by the CGI script is inconsistent, depending if the client
>is IE or Mozilla (Firefox)
>Server result from IE client:
> foo: 11
> bar: 22
>Server result from Mozilla Firefox client:
> POSTDATA: foo=11&bar=22
>
>It seems that the POST data IE sends is more correct than the Mozilla data.
>Is there another way to send the data in Mozilla so the CGI script will give
>the same results. I could easily adjust the CGI script, but I think the
>problem is at the client.
Aren't you missing setting the content-type for your request, that is, using:
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
Perhaps one browser fills in the blanks whereas the other doesn't; either way
you ought to explicitly state it when POSTing data.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
------------------------------
Date: Sat, 30 Apr 2005 19:31:52 +0200
From: Martin Honnen <mahotrash@yahoo.de>
Subject: Re: POST data with XMLHttpRequest to CGI (Mozilla)
Message-Id: <4273c110$0$7534$9b4e6d93@newsread2.arcor-online.net>
Jarson wrote:
> My JavaScript is trying to POST data to a CGI script (Perl) using
> XMLHttpRequest. My CGI server gets different data from IE than Mozilla
> Firefox.
>
> // For Mozilla, req = new XMLHttpRequest();
> // For IE req = new ActiveXObject("Microsoft.XMLHTTP");
> req.onreadystatechange = requestHandler ; // function to handle async
> response
> req.open('POST', myURL, true); // use POST
First make the open call, then set the onreadystatechange handler and
then before you send the data set the HTTP request header e.g.
if (typeof req.setRequestHeader != 'undefined') {
req.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
}
> req.send('foo=11&bar=22') ;
as that seems to be the content type of the data you want to post.
--
Martin Honnen
http://JavaScript.FAQTs.com/
------------------------------
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 8033
***************************************