[23386] in Perl-Users-Digest
Perl-Users Digest, Issue: 5605 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 2 14:10:39 2003
Date: Thu, 2 Oct 2003 11:10:15 -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 Thu, 2 Oct 2003 Volume: 10 Number: 5605
Today's topics:
Re: Perl Par built exe, sometimes it runs, sometimes it (Jesse Schoch)
Re: question about hash ordering (Tad McClellan)
Re: Saving html form into oracle database <emschwar@pobox.com>
screen output lags behind, or script appears to 'switch <florian265@uboot.com>
Re: screen output lags behind, or script appears to 'sw <nobull@mail.com>
Re: select() on socket <nobull@mail.com>
Re: syntax question (Sam Holden)
Re: Unexpected alteration of array's content <mpapec@yahoo.com>
Re: Unexpected alteration of array's content <spam@thecouch.homeip.net>
Re: Unexpected alteration of array's content <nobull@mail.com>
where am my()? <Ben_Dover@psychiatric-center.Bellevue-Hospital.com>
Re: where am my()? <xx087@freenet.carleton.ca>
Re: where am my()? (Tad McClellan)
Re: WWW::Mechanize .. anyone? <ict@eh.org>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Oct 2003 08:49:42 -0700
From: greenail@yahoo.com (Jesse Schoch)
Subject: Re: Perl Par built exe, sometimes it runs, sometimes it doesn't
Message-Id: <9de9fcb4.0310020749.46c78fb1@posting.google.com>
problem was solved by replacing the perl dll (i was using the tinyperl
dll locally) and compiling with the -d switch to pp. -d helped my
disk usage for my app and utilities considerably. hope this helps
someone.
by the way, there was no error, or print messages shown whatso ever,
perhaps tinyperl isn't tested so well on windows nt 4.
-greenail
------------------------------
Date: Thu, 2 Oct 2003 08:38:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: question about hash ordering
Message-Id: <slrnbnoaji.uri.tadmc@magna.augustmail.com>
John <news2003@wanadoo.es> wrote:
> and I would like to classify the index with the values:
> What will be you approach?
My approach would depend on how I plan to _use_ the data structures,
which you have not shared with us...
If performance really matters (it probably doesn't), then try it
both ways and benchmark them.
------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @arr = qw(ab a b ab ba ba ab ba);
my @array = by_array(@arr);
print Dumper \@array;
my %hash = by_hash(@arr);
print Dumper \%hash;
sub by_array {
my @array;
my %seen;
foreach my $i ( 0 .. $#_ ) {
$seen{$_[$i]} = $i unless exists $seen{$_[$i]};
push @{ $array[$seen{$_[$i]}] }, $i;
}
return @array;
}
sub by_hash {
my %hash;
my %seen;
foreach my $i ( 0 .. $#_ ) {
$seen{$_[$i]} = $i unless exists $seen{$_[$i]};
push @{ $hash{$seen{$_[$i]}} }, $i;
}
return %hash;
}
------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Oct 2003 11:31:04 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Saving html form into oracle database
Message-Id: <etozngja6nb.fsf@wormtongue.emschwar>
Michael Budash <mbudash@sonic.net> writes:
>> Ick. Just save the form parameters and values, and use CGI.pm to
>> re-create the form along with the values you loaded from the
>> database. Why make things so needlessly complicated?
>>
>> -=Eric
>
> here's why:
>
> the o.p. asked to save the _form_. forms are more than simply names and
> values. they involve input methods of indicating those values (text
> boxes, radio button, checkboxes, select's, etc.). your method does not
> allow the o.p. to recreate the form with those methods intact.
Yes it does. That's what the bit about "use CGI.pm to re-create the
form along with the values you loaded from the database" was about.
Of course, CGI.pm isn't necessary, but its sticky form creator will
work as well as any other.
If you generate the form programatically in the first place, then
adding code that looks like
{
no warnings;
my %vals = loadFormValues();
print <<EOFORM
....
<input name="somename" value="$vals{somename}">
....
EOFORM
}
is easy, and *poof*, there's your re-created form, with values
pre-filled from a database.
> admittedly, the o.p. did not specifically say that's what he wanted, but
> i assumed it.
You also assumed that the form is static, and not able to be generated
by a script. Seems a very baroque assumption to make, especially when
it makes the solution much harder.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 02 Oct 2003 17:41:55 +0200
From: Florian von Savigny <florian265@uboot.com>
Subject: screen output lags behind, or script appears to 'switch statements'
Message-Id: <m3wubnfxz0.fsf@uboot.com>
Hi,
I have a very weird problem: I wrote a fairly long script with plenty
of screen messages, and a few prompts for user input. Though the
script does what it is supposed to, a very bizarre error occurs:
At a certain screen message, the script seems to freeze ('ps -a' on
another terminal reveals that the process is sleeping). Only when you
hit the return key, it will continue, and it will regard the next
prompt as already answered (i.e. it seems to have taken the "Enter" as
a newline input from STDIN). In other words, you have to answer the
prompts "in advance", knowing they are due in a few lines.
Extracts from the code and the output may further clarify this:
print "about to invoke cdrecord: Unmounting $image_mountpoint ...";
$status = system("umount -d $image_mountpoint");
print " done.\n";
abort_wisely() if $status;
print "\aIf an empty CD-R of " . $cd_sizes[0] / 1048576 .
"MB (as you announced) is in $cdwriter, press Enter: ";
$go_on = <STDIN>;
$status = system("cdrecord $cdrecord_options $add_options $image");
This is supposed to produce the following screen output (never mind
the actual variable values):
about to invoke cdrecord: Unmounting /mnt/1/ ... done.
[bell]
If an empty CD-R of 650MB (as you announced) is in /dev/scd0, press Enter: _
(I've put an underscore where the cursor should appear). If you now
hit Enter, it should run cdrecord as specified in the system()
functions argument. Right?
But what it actually produces is the following:
about to invoke cdrecord: Unmounting /mnt/1/ ..._
(underscore = cursor) And here the script seems to have
frozen. 'mount' on another terminal reveals that /mnt/1 HAS been
unmounted, but " done.\n" does not appear. Until you hit "Enter":
done.
[bell]
If an empty CD-R of 650MB (as you announced) is in /dev/scd0, press Enter: <which is immediately followed by cdrecords screen messages>
IOW, after "..., press Enter: ", no keyboard input is waited for; the
program just goes on.
I think this is very bizarre behaviour. Although it appears as though
perl executes the
$go_on = <STDIN>;
statement BEFORE the
print " done.\n";
statement, I personally favour the hypothesis that screen output
somehow suffers a delay. I.e. I suspect the program HAS arrived at the
statement "$go_on = <STDIN>;", and it certainly HAS executed the
preceding statements and is now duly waiting for keyboard input, but
it is somehow on the way to the screen that those messages are held
back.
This seems to be substantiated by the fact that after this error, ALL
prompts are printed AFTER having been answered (even one which was
correct before that). And if I am on the right track, it needn't even
be the lines of code I have printed here who are to blame, it could be
anything else. It needn't even be the script - however, it has only
happened with this script so far.
Does anyone have a clue what kind of problem this could be, and where
it typically arises?
--
Florian v. Savigny
If you are going to reply in private, please be patient, as I only
check for mail something like once a week. - Si vous allez répondre
personellement, patientez s.v.p., car je ne lis les courriels
qu'environ une fois par semaine.
------------------------------
Date: 02 Oct 2003 17:39:33 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: screen output lags behind, or script appears to 'switch statements'
Message-Id: <u91xtvh9ve.fsf@wcl-l.bham.ac.uk>
Florian von Savigny <florian265@uboot.com> writes:
> I have a very weird problem:
> print "\aIf an empty CD-R of " . $cd_sizes[0] / 1048576 .
> "MB (as you announced) is in $cdwriter, press Enter: ";
> $go_on = <STDIN>;
> I personally favour the hypothesis that screen output
> somehow suffers a delay. I.e. I suspect the program HAS arrived at the
> statement "$go_on = <STDIN>;", and it certainly HAS executed the
> preceding statements and is now duly waiting for keyboard input, but
> it is somehow on the way to the screen that those messages are held
> back.
You are so close to getting to your answer. You have figured out that
some sort of buffering is going on.
perldoc -q buffer
Pay particular note to "Serial devices (e.g. modems, terminals) are
normally line- buffered, and stdio sends the entire line when it gets
the newline."
Note also that a newline that's echoed while reading STDIN does not go
via STDOUT so does not count for this purpose.
You probably want to put STDOUT->flush() before reading from STDIN.
(flush is in IO::Handle).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 02 Oct 2003 18:02:06 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: select() on socket
Message-Id: <u9k77nfu9d.fsf@wcl-l.bham.ac.uk>
vorxion@fairlite.com (Vorxion) writes:
> I'm having a problem with select() on a socket. I'm setting the bits, and
> it's really strange, because even when there's -nothing- to be read,
> vec($rout,fileno(DATA) comes back as 0 instead of 1. The bits come back
> 0 1 0 in order of $rout $wout $eout.
>
> Okay, so exactly how do you tell when the remote end is sitting there with
> nothing to say? I've used select(2) in C, and there appears to be no ready
> equivalent of FD_ISSET() in perl.
Eh?
> If someone can tell me how to do this properly, or what I'm doing wrong (I'm
> checking for $rout to be set back to 0 (via vec) after the select().
> select($rout=$rin,$wout=$win,$eout=$ein,${timeout_select});
You are not checking if the return value of select().
It is possible that it's failing.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 2 Oct 2003 14:20:12 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: syntax question
Message-Id: <slrnbnod0s.s6c.sholden@flexal.cs.usyd.edu.au>
On Thu, 02 Oct 2003 12:31:14 +0100, JS <vervoom@hotmail.com> wrote:
> Anno Siegel wrote:
[some stuff which I trimmed]
>> JS <vervoom@hotmail.com> wrote in comp.lang.perl.misc:
[some stuff which I also trimmed]
>>>Sam Holden wrote:
>>>>
>>>>You can use operators like , to turn multiple expressions into
>>>>one expressions, and functions or do to turn arbitrary
^^
>>>>statments into an expression.
>
> Thanks for that Anno. So you can do it with a do {block}. I don't mean
> to blame the "group" but if someone had just said that in the first
> place it would have been a lot easier :)
I did.
--
Sam Holden
------------------------------
Date: Thu, 02 Oct 2003 15:44:52 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Unexpected alteration of array's content
Message-Id: <kraonv0kg6n5aqung2jrbllktv1tnn98ah@4ax.com>
On Thu, 2 Oct 2003 17:02:57 +1000, "Peter Hill" <phill@modulus.com.au>
wrote:
>for my $line (@lines){
> $line =~ s/w/x/g;
>}
>print "@lines\n";
>
>#output is "one txo three"
>
>
>Am I wrong in expecting the array not to be modified when I'm only modifying
>a local variable derived from it? Apologies if this is a commonly known
>effect, I've just returned to Perl programming.
It is a documented feature, to avoid it try,
for my $line (map $_, @lines){
------------------------------
Date: Thu, 02 Oct 2003 09:48:53 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Unexpected alteration of array's content
Message-Id: <b1Web.13818$1M6.48583@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Peter Hill wrote:
> The following program gives an output which I didn't expect with Perl 5.8
> #! /usr/bin/perl -w
> use strict;
> my @lines = ('one','two','three');
> for my $line (@lines){
> $line =~ s/w/x/g;
> }
> print "@lines\n";
>
> #output is "one txo three"
>
>
> Am I wrong in expecting the array not to be modified when I'm only modifying
> a local variable derived from it? Apologies if this is a commonly known
> effect, I've just returned to Perl programming.
> tia
From perldoc perlsyn, "Foreach Loops" section:
"If any element of LIST is an lvalue, you can modify it by modifying VAR inside the loop.
Conversely, if any element of LIST is NOT an lvalue, any attempt to modify that element will fail.
In other words, the foreach loop index variable is an implicit alias for each item in the list that
you're looping over."
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/fCzHeS99pGMif6wRArTwAJ9RYoxngFkl7oVcTMsH4zlNm1YE6gCeMvNK
5hyeajRWju7geYhzy/0B4lU=
=PPqE
-----END PGP SIGNATURE-----
------------------------------
Date: 02 Oct 2003 17:44:17 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unexpected alteration of array's content
Message-Id: <u9wubnfv32.fsf@wcl-l.bham.ac.uk>
Matija Papec <mpapec@yahoo.com> writes:
> On Thu, 2 Oct 2003 17:02:57 +1000, "Peter Hill" <phill@modulus.com.au>
> wrote:
>
> >for my $line (@lines){
> > $line =~ s/w/x/g;
> >}
> >print "@lines\n";
> >
> >#output is "one txo three"
> >
> >
> >Am I wrong in expecting the array not to be modified when I'm only modifying
> >a local variable derived from it? Apologies if this is a commonly known
> >effect, I've just returned to Perl programming.
>
> It is a documented feature, to avoid it try,
> for my $line (map $_, @lines){
Personally I'm supprised that works. But even though it does (on at
least one version of Perl I've tried) I still prefer:
for my $line (@{[@lines]}){
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 02 Oct 2003 11:55:26 -0400
From: Ben Dover - Mental Patient 0057 <Ben_Dover@psychiatric-center.Bellevue-Hospital.com>
Subject: where am my()?
Message-Id: <3F7C4A6E.24C29214@psychiatric-center.Bellevue-Hospital.com>
where am my()?
@db=some db file;
sub test {
foreach $list ($file1,$file2,$file3){
foreach (@db){
my($var); <--if my defined here
if ($countTD > $linesPerColumn){
if ($countTR > $columnsPerPage){
$var=1234; <---and used here
}
print "<td valign=\"top\"><u><b>$var</b></u>\n"; <--why won't it show
up here?
}
if ($_ =~ m/category:/){
}
if ($_ =~ m/;;/){
}
}
}
}
isn't my defined at a broad enough location?
------------------------------
Date: 2 Oct 2003 16:12:54 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: where am my()?
Message-Id: <slrnbnojl6.jb8.xx087@smeagol.ncf.ca>
Ben Dover - Mental Patient 0057 <Ben_Dover@psychiatric-center.Bellevue-Hospital.com> wrote:
> my($var); <--if my defined here
> if ($countTD > $linesPerColumn){
> if ($countTR > $columnsPerPage){
> $var=1234; <---and used here
> }
> print "<td valign=\"top\"><u><b>$var</b></u>\n"; <--why won't it show
> up here?
$countTR is not greater than $columnsPerPage
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Thu, 2 Oct 2003 11:37:39 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: where am my()?
Message-Id: <slrnbnol2j.vig.tadmc@magna.augustmail.com>
Ben Dover - Mental Patient 0057 <Ben_Dover@psychiatric-center.Bellevue-Hospital.com> wrote:
> where am my()?
>
> @db=some db file;
> sub test {
> foreach $list ($file1,$file2,$file3){
> foreach (@db){
> my($var); <--if my defined here
> if ($countTD > $linesPerColumn){
> if ($countTR > $columnsPerPage){
> $var=1234; <---and used here
> }
> print "<td valign=\"top\"><u><b>$var</b></u>\n"; <--why won't it show
> up here?
Maybe because $countTR <= $columnsPerPage ?
Do you have warnings enabled?
> isn't my defined at a broad enough location?
$var will be in scope for the print().
Maybe you are printing undef or the empty string though...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Oct 2003 23:09:07 +1000
From: Iain Truskett <ict@eh.org>
Subject: Re: WWW::Mechanize .. anyone?
Message-Id: <slrnbno9bg.tqk.ict@dellah.org>
* Ryan <cent@optushome.com.au>:
> anyone here used this module before? I really need to stop
> it from downloading images .... it's eating up all my bw
> and I cant find a way to stop it from doing so ....... not
> that i know if it is or not, but it's downloading
> something
It fetches exactly what you tell it to. If you don't want
it to download images, then don't tell it to download
images.
If you tell it to fetch a page, it fetches the page. It
does not fetch images on the page unless you then tell it
to.
cheers,
--
Iain. <http://eh.org/~koschei/>
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5605
***************************************