[17158] in Perl-Users-Digest
Perl-Users Digest, Issue: 4570 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 10 14:05:31 2000
Date: Tue, 10 Oct 2000 11:05:14 -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: <971201114-v9-i4570@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 10 Oct 2000 Volume: 9 Number: 4570
Today's topics:
Re: 2 questions <flavell@mail.cern.ch>
Re: 3rd try. Error Message when close (OUTFILE); but it (Martien Verbruggen)
Re: 3rd try. Error Message when close (OUTFILE); but it translancer@my-deja.com
Re: Accessing the values of sub-keys in a multi-dimensi <philipg@atl.mediaone.net>
Re: CGI::Push <ubl@schaffhausen.de>
Compiling Perl with -DMULTIPLICITY <mak@imakhno.freeserve.co.uk>
concatenation operator and high end ascii dmanley@tucows.com
Concurrent access to data <mordkoff@xedia.com>
contatenation operator and high end ascii tubadanm@my-deja.com
Re: ctrl-c signal trap on NT <steve.jones@takethisoutproact.net>
Re: Defining Headers for Module Mail::Mailer <randy@theoryx5.uwinnipeg.ca>
Re: Downloadable reference manual? (Martien Verbruggen)
Re: Downloadable reference manual? <franl-removethis@world.omitthis.std.com>
Re: Downloadable reference manual? <hartleh1@westat.com>
Error message from cgi-lib.pl anmu4141@my-deja.com
Re: foreach (@a) {i++; if ($i = even) {$bg = blue};... <ubl@schaffhausen.de>
Re: foreach (@a) {i++; if ($i = even) {$bg = blue};... <jeffp@crusoe.net>
format() from a variable? belg4mit@mit.edu
Re: format() from a variable? <jeffp@crusoe.net>
Re: How can I add 5 hours to the time my server reports <gmiller@gregmiller.net>
Re: imagename.x and imagename.y confusion (Mark-Jason Dominus)
Insecure $ENV{PATH} while running setuid <cpegbeggar@mail.com>
LWP, URI, HTTP brainfart lim_k@my-deja.com
need help with tie magic in XS <ken@bitsko.slc.ut.us>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Oct 2000 15:48:39 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: 2 questions
Message-Id: <Pine.GHP.4.21.0010101545360.21331-100000@hpplus03.cern.ch>
On Tue, 10 Oct 2000 iamnotananimal@my-deja.com wrote:
> > That's not a Perl-related question.
> >
> I thought print "Content-type: text/html\n\n"; was specific perl
> notation used to display output to browser from a perl script.
That's your problem, then, along with the misguided subject line.
> I was after notation used to clear the screen that is specific to perl.
What?
> I take it there is none.
I take it you are hopelessly confused. Perl is a programming
language. If you know what you want it to output, then it has a
notation for producing that output. It (the programming language)
cares not what the output means or does.
> thanks for trying,
You're the one who's trying.
good luck.
------------------------------
Date: Wed, 11 Oct 2000 00:15:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 3rd try. Error Message when close (OUTFILE); but it works
Message-Id: <slrn8u65k9.2tj.mgjv@martien.heliotrope.home>
On Tue, 10 Oct 2000 12:42:51 GMT,
translancer@my-deja.com <translancer@my-deja.com> wrote:
> How can I check the result of open, and the result of close when doing
> piped opens
_How_ do you check? Like this:
$SIG{PIPE} = 'IGNORE';
open(THING, "| $program")
or die "Can't run $program: $!";
print THING $some_stuff;
close(THING)
or die $! ? "Error closing $program pipe: $!"
: "Exit $? from $program";
# perldoc -f open
# perldoc -f close
# perldoc perlopentut
# perldoc perlipc
> after printing to OutFile or modifying it with splice
> (@data, $line, $record).
I'm terribly sorry, but none of this makes any sense to me. What do you
mean? What are you modifying with splice?
> They work but I get a final error message. How
> can avoid it? Please I need an answer.
If you get an error message, then they don't work correctly, whatever
'they' is. What is the error message you get? You avoid it by fixing the
error.
Maybe, instead of trying to convey your problem in words, which you seem
to have some trouble with, you should show us a suitably small
self-contained piece of code that displays the problem you talk about,
AND the error message.
On second thought: there is no maybe about it. If you want help, you
will have to show us code and error messages. Don't retype. Cut and
paste.
Martien
--
Martien Verbruggen | Since light travels faster than
Interactive Media Division | sound, isn't that why some people
Commercial Dynamics Pty. Ltd. | appear bright until you hear them
NSW, Australia | speak?
------------------------------
Date: Tue, 10 Oct 2000 17:29:15 GMT
From: translancer@my-deja.com
Subject: Re: 3rd try. Error Message when close (OUTFILE); but it works
Message-Id: <8rvjkv$dli$1@nnrp1.deja.com>
In article <slrn8u65k9.2tj.mgjv@martien.heliotrope.home>,
mgjv@tradingpost.com.au wrote:
> On Tue, 10 Oct 2000 12:42:51 GMT,
> translancer@my-deja.com <translancer@my-deja.com> wrote:
> > How can I check the result of open, and the result of close when
doing
> > piped opens
>
> _How_ do you check? Like this:
>
> $SIG{PIPE} = 'IGNORE';
> open(THING, "| $program")
> or die "Can't run $program: $!";
> print THING $some_stuff;
> close(THING)
> or die $! ? "Error closing $program pipe: $!"
> : "Exit $? from $program";
>
> # perldoc -f open
> # perldoc -f close
> # perldoc perlopentut
> # perldoc perlipc
>
> > after printing to OutFile or modifying it with splice
> > (@data, $line, $record).
>
> I'm terribly sorry, but none of this makes any sense to me. What do
you
> mean? What are you modifying with splice?
I'm modifying a comma-delimited database file (OUTFILE) previously
recorded temporarily into @data, this way:
if (! open(OUTFILE,"$dbfile")) { die "Can't open file";}
@data = <OUTFILE>;
close (OUTFILE);
Then, I make a search, find a record in a $line, this way:
$total_lines=@data;
$line=0;
while ($line < $total_lines)
{
if (@data[$line] =~ /$search/i)
{
$record = $data[$count_record_line];
I modify $record and want to modify the database substituting the new
record for the old one with
splice (@data, $line, 1, $record)
I think I need to print the whole database (@data) now modified into
the old database with
print OUPFILE @data;
>
> > They work but I get a final error message.
How
> > can avoid it? Please I need an answer.
>
> If you get an error message, then they don't work correctly, whatever
> 'they' is. What is the error message you get? You avoid it by fixing
the
> error.
>
> Maybe, instead of trying to convey your problem in words, which you
seem
> to have some trouble with, you should show us a suitably small
> self-contained piece of code that displays the problem you talk about,
> AND the error message.
I attach the main part of the script at the end, but in my previous
requests,I was more explicit, really. "They" refers to two pieces of
script, both print statements (for adding new records and for updating
others, which really work, but I get the "Internal Server Error" of
misconfiguration on exit. (see Pedro Sanchez message/article in this
forum on 8.10.2000)
>
> On second thought: there is no maybe about it. If you want help, you
> will have to show us code and error messages. Don't retype. Cut and
> paste.
>
> Martien
> --
> Martien Verbruggen | Since light travels faster than
> Interactive Media Division | sound, isn't that why some people
> Commercial Dynamics Pty. Ltd. | appear bright until you hear them
> NSW, Australia | speak?
>
Here's the main stuff: @list is an array where entries from an HTML
form have been recorded.
open(OUTFILE,">$dbfile");
$record = "";
foreach $to_print (@list) {
if ($dbfile ne "") { $record .= "$fields{$to_print} \,"; }
}
splice(@data, $line, 1, $record);
print OUTFILE @data;
close(OUTFILE);
Thanks very much for your help.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 10 Oct 2000 13:12:36 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Accessing the values of sub-keys in a multi-dimensional hash
Message-Id: <8BEE5.22939$oA2.2991683@typhoon.southeast.rr.com>
Johnno <johnno@nospam.casebook.org> wrote in message
news:39e301eb$0$11616$7f31c96c@news01.syd.optusnet.com.au...
> How can I access the value of a sub-key in a hash?
>
> Take this example:
>
> my %blah = (
> 'Fred' => {
> 'about.html' => 'About Fred',
> 'blah.html' => 'The Ramblings of Fred',
> 'fish.html' => 'Fishing with Fred',
> },
> 'Joe' => {
> 'holiday.html' => 'Around the World with Joe',
> 'garbage.html' => 'Joe the Sanitation Engineer',
> 'blah.html' => 'Et cetera',
> },
> };
>
> A simple foreach(sort(keys(%blah))) will give me 'Fred' and allow me to do
> further processing, but I need to get 'about.html' (etc.) and the
> corresponding values of those sub-keys too.
The value for each first-level key in this hash is a hash reference. So to
get its keys, you need to dereference it. See perldoc perlref for details.
Here's an example using your data above:
foreach my $name (keys %blah) {
print "$name:\n";
foreach my $htmlfile ( keys %{$blah{$name}}) {
print "\t$htmlfile => $blah{$name}{$htmlfile}\n";
}
}
hth,
p
------------------------------
Date: Tue, 10 Oct 2000 17:16:08 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: CGI::Push
Message-Id: <39E332B8.B027BA48@schaffhausen.de>
Troy Rasiah schrieb:
> This example is from the man page. Works fine with Netscape but doesn't work
> with Ie..in that the same data repeats itself. Does anyone know a work
> around for this
>
> Does this work on Internet Explorer?
>
> use CGI::Push qw(:standard);
>
> do_push(-next_page=>\&next_page,
> -last_page=>\&last_page,
> -delay=>0.5);
>
> sub next_page {
> my($q,$counter) = @_;
> return undef if $counter >= 10;
> return start_html('Test'),
> h1('Visible'),"\n",
> "This page has been called ", strong($counter)," times",
> end_html();
> }
>
> sub last_page {
> my($q,$counter) = @_;
> return start_html('Done'),
> h1('Finished'),
> strong($counter),' iterations.',
> end_html;
> }
Internet Explorer does not support Push.
malte
------------------------------
Date: Tue, 10 Oct 2000 18:01:04 +0100
From: "Makhno" <mak@imakhno.freeserve.co.uk>
Subject: Compiling Perl with -DMULTIPLICITY
Message-Id: <8rvi1t$krp$1@news7.svr.pol.co.uk>
Further to my post yesterday, I have been trying to compile Perl 5.3.0 with
the -DMULTIPLICITY flag turned on.
Unfortuanately, this seems to make available a #define called 'stack_base',
which conflicts with another stack_base in my system's headers. I've played
around with the #define's
(
eg:
#undef stack_base
#include <troublesome_header.h>
#define stack_base whatever it was
)
but this doesn't seem to have worked (I got linker errors among other
things, and the compiler (g++) even crashed at one point(!) ). Does anyone
have any ideas?
------------------------------
Date: Tue, 10 Oct 2000 16:37:49 GMT
From: dmanley@tucows.com
Subject: concatenation operator and high end ascii
Message-Id: <8rvgkr$arn$1@nnrp1.deja.com>
(forgive me if this is a double post)
I've found that using the string contatenation operation 'dot' "." and
'dot-equals' ".=" seems to mess up high end ascii (eg. used in Chinese).
I've had to resort to using sprintf(). Because the system I'm working
will potentially deal with many languages, I'm thinking that usage of
perllocale might not be useful. Then again, I'm not sure... does anyone
have any ideas why the string concatenation operator in Perl messes up
high end ascii characters? Is this a known issue/bug?
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 10 Oct 2000 12:33:18 -0400
From: Jeremy Mordkoff <mordkoff@xedia.com>
Subject: Concurrent access to data
Message-Id: <39E344CE.809B55B1@xedia.com>
This is a multi-part message in MIME format.
--------------C890DF738C99C47C99C2AED4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I either need concurrent access to my data or I need to serialize all access. My data is stored in
flat ascii files. Up until now, I have relied on constructs such as that below to "guarantee"
serial access, but every now and then I lose my data file. Is there a better construct to use? Or
should I adopt a package that will allow me concurrent access?
This is a web script, so each invocation of the script actually does relatively little.
JLM
sub UpdateUser {
my ( $u, $up, $p, $l ) = @_; # all values are optional except $u
my ( $userid, $userpass, $pass, $lastupdate );
my $file = "Users.dat";
while ( ! -f $file ) {
if ( $retry++ > 6 ) {
mydie("data file not found");
}
sleep ( 2 );
}
rename ( $file, "$file.$$" ) || mydie ( "UpdateUser: cannot rename $file $file.$$ error $!" );
open ( UF, "<$file.$$" ) || mydie ( "UpdateUser: cannot open $file.$$ for read" );
open ( OF, ">$file" ) || mydie ( "UpdateUser: cannot open $file for write" );
while ( <UF> ) {
chop;
( $userid, $userpass, $pass, $lastupdate ) = split (":" );
if ( $userid eq $u ) {
# save settings that they weren't passed in
$up = $userpass unless $up;
$p = $pass unless $p;
$l = $lastupdate unless $l;
} else {
print OF "$userid:$userpass:$pass:$lastupdate\n";
}
}
print OF "$u:$up:$p:$l\n";
close ( OF );
close ( UF );
unlink ( "$file.$$");
}
--
Jeremy Mordkoff 978-263-0060 x139
AccessPoint Business Unit
Lucent Technologies
(Formerly Xedia Corp)
--------------C890DF738C99C47C99C2AED4
Content-Type: text/x-vcard; charset=us-ascii;
name="mordkoff.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jeremy Mordkoff
Content-Disposition: attachment;
filename="mordkoff.vcf"
begin:vcard
n:Mordkoff;Jeremy
tel;fax:978-263-8386
tel;work:978-263-0060 x139
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:mordkoff@xedia.com
x-mozilla-cpt:;20416
fn:Jeremy Mordkoff
end:vcard
--------------C890DF738C99C47C99C2AED4--
------------------------------
Date: Tue, 10 Oct 2000 16:16:31 GMT
From: tubadanm@my-deja.com
Subject: contatenation operator and high end ascii
Message-Id: <8rvfcl$9ld$1@nnrp1.deja.com>
I've found that using the string contatenation
operation 'dot' "." and 'dot-equals' ".=" seems to
mess up high end ascii (eg. used in Chinese).
I've had to resort to using sprintf(). Because
the system I'm working will potentially deal with
many languages, I'm thinking that usage of
perllocale might not be useful. Then again, I'm
not sure... does anyone have any ideas why the
string concatenation operator in Perl messes up
high end ascii characters? Is this a known
issue/bug?
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 10 Oct 2000 16:21:17 +0100
From: "Steve Jones" <steve.jones@takethisoutproact.net>
Subject: Re: ctrl-c signal trap on NT
Message-Id: <39e3345e_2@nnrp1.news.uk.psi.net>
I can only comment on what I've observed and heard about while using perl on
NT. I don't know how signals work internally, but it seems to be different
to Unix and it does not appear to work properly. I'd love to find out more
about the problem.
First, my version of Perl spawns two tasks in the NT process list when I run
one script. If I launch the program from another Windows program, using
createprocess, and then terminateprocess the returned PID, one of the tasks
is killed, but the other continues to run and still works.
Second, if I put an event handler in a perl script and then 'signal' that
event, one of the tasks handles the event but the other continues to run as
if nothing has happened.
This indicates to me that NT perl cannot deal with signals in the same way
as Unix does. In fact, it seems that two tasks are spawned, one to do the
work and the other to handle 'signals'. They run asynchronously and
independantly and it is not an easy matter to control one task from the
other.
In addition, I've had further information on this from a certain Clinton A.
Pierce as follows:
> Steve Jones wrote:
> Since Monday, I've been messing around with signals on nsPerl (WIN32).
Ok, in a nutshell...signals under Win32 don't and will not work. The
process model for Win32 is such that processes can't be sent a
pre-emptive signal like they can under Unix. The ^C "signal" isn't
really that either. It's Something Else.
To implement signals under Win32 would require having a special kind of
"perl signals" that could be shared between perl processes, and the
interpreter loop would have to be monkeyed with to check for
these...it's ugly and unlikely that anyone will ever do that. It won't
get us INT, ALRM or CHLD handling -- which is what we want.
--
Steve Jones
ProAct International
stevej@proact.net
"CDM" <cdemaeyer1@mmm.com> wrote in message
news:8rufv7$8e5$1@magnum.mmm.com...
> Hi,
> How to trap signal ctrl-c on Windows NT?
>
> Perldoc said:
> $interrupted=0;
> $SIG{INT}= sub {
> $interrupted++;
> syswrite(STDERR,"Ouch!",5);
> }
>
> But above does not work....
>
>
>
>
>
> Opinions expressed herein are my own and may not represent those of my
employer.
>
------------------------------
Date: 10 Oct 2000 16:02:29 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Defining Headers for Module Mail::Mailer
Message-Id: <8rveil$he6$1@canopus.cc.umanitoba.ca>
In comp.lang.perl.misc,
David Highley <dhighley@mail.highley-recommended.com> wrote:
[ ... ]
> After doing more looking at the two modules Mail::Mailer and Mail::Send
> I came to the
> conclusion I should be using Mail::Send instead of Mail::Mailer. Now it
> works for a real
> system, Solaris, but when I try it on a Windows goober I get the
> following error:
> No mailer program specified (and no default available).
The Mail::Mailer module can send things via SMTP:
my $mailer = new Mail::Mailer 'smtp', Server => $server;
Also, on ActiveState's site is a Win32 faq which has an
entry describing various ways to send mail on Win32.
best regards,
randy kobes
------------------------------
Date: Wed, 11 Oct 2000 00:43:42 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Downloadable reference manual?
Message-Id: <slrn8u678e.2tj.mgjv@martien.heliotrope.home>
[Please, next time, put your reply AFTER (or interleaved with) the
suitably trimmed down text you reply to. It makes the posts easier to
follow, and conforms to the quoting style here. Also: fix the broken
wrapping of your newsreader.]
On Tue, 10 Oct 2000 12:51:56 GMT,
Daniel Berger <djberg96@my-deja.com> wrote:
[reordered post and corrected broken wrapping]
> In article <ags5us81oeect200kb4q7nvu8jm9lnnhge@4ax.com>,
> Bart Lateur <bart.lateur@skynet.be> wrote:
> > Siobhan wrote:
> >
> > >I have the some of the FAQ documents for Perl, but is the a complete
> > >reference manual that I can download?
> >
> > The whole Perl documentation, for which "perlfunc" is the most important
> > part IMO (followed by perlop, perlre and perlvar), is part of the
> > standard Perl distribution. And ten large FAQ documents.
> >
> > You probably can find it online as HTML as well, from <www.perl.com>
> > and/or CPAN. Oh yes, there it is:
> >
> > <http://www.perl.com/pub/v/documentation>
> > <http://www.cpan.org/doc/manual/html/index.html>
> >
> I recommend the ActiveState documentation (even if you don't like the
> distribution). It's in nicely formatted and arranged HTML. Has all the
> FAQ's, etc.
Every Perl distribution has all the documentation and all the FAQ's. A
perl distribution that doesn't have all of it is broken, and should be
fixed.
activeState's distribution has all documentation as HTML (as well), yes,
but the HTML is not decently searchable. Rather than relying on HTML,
get yourself acquainted with the pod documentation, and more
importatnly, the perldoc tool.
# perldoc perldoc
# perldoc -f function
# perldoc -q 'FAQ keyword'
Also, get yourself a good text searching tool, like grep so that you can
search the pod files decently.
HTML is only good for display. grepping HTML documents is horrible.
The pod documentation is part of every perl distribution, HTML isn't.
HTML is mainly bloat for no good reason.
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Tue, 10 Oct 2000 16:54:18 GMT
From: Francis Litterio <franl-removethis@world.omitthis.std.com>
Subject: Re: Downloadable reference manual?
Message-Id: <m3n1gcprgl.fsf@franl.andover.net>
Bart Lateur <bart.lateur@skynet.be> writes:
> You probably can find it online as HTML as well, from <www.perl.com>
> and/or CPAN. Oh yes, there it is:
>
> <http://www.perl.com/pub/v/documentation>
Anyone know if that Web page documents 5.6 or an earlier version? It
isn't clear from perusing the contents.
------------------------------
Date: Tue, 10 Oct 2000 13:18:39 -0400
From: hartley_h <hartleh1@westat.com>
Subject: Re: Downloadable reference manual?
Message-Id: <39E34F6F.72ECFAF2@westat.com>
Francis Litterio wrote:
>
> Bart Lateur <bart.lateur@skynet.be> writes:
>
> > You probably can find it online as HTML as well, from <www.perl.com>
> > and/or CPAN. Oh yes, there it is:
> >
> > <http://www.perl.com/pub/v/documentation>
>
> Anyone know if that Web page documents 5.6 or an earlier version? It
> isn't clear from perusing the contents.
I don't know the general answer but the Perl Release History page linked
to from there
<http://www.perl.com/pub/doc/manual/html/pod/perlhist.html> only shows
releases up through 5.005 so that document, anyway, is an older version.
--
Henry Hartley
------------------------------
Date: Tue, 10 Oct 2000 15:07:30 GMT
From: anmu4141@my-deja.com
Subject: Error message from cgi-lib.pl
Message-Id: <8rvbbc$5qu$1@nnrp1.deja.com>
I have a problem with the cgi-lib.pl (I have
taken V 2.18).
In a local area of my homepage I have a
possibility to upload a file with a web - form.
But some users have after the upload an error
message: "cgi-lib.pl: reached end of input while
seeking boundary of multipart. Format of CGI
input is wrong.". This message is posted two
times! (Why? It could only one time written,
because with CgiDie the Skript should ended?!).
I have tried many uploads, but I can't see the
error message. I have a screenshot of the (two)
message(s), it is happend. Whats wrong?
Here the code:
Website:
<FORM METHOD=POST enctype='multipart/form-data'
ACTION=/cgi-bin/1/upload.pl>
<TABLE BORDER=0 CELLSPACING=0
CELLPADDING=1><TR><TD><FONT
FACE="Arial,Helvetica"
SIZE=2>Dateiname:</FONT></TD><TD><input type=file
name=upfile></TD></TR>
<TR><TD><FONT FACE="Arial,Helvetica"
SIZE=2>Beschreibung:</FONT></TD><TD><input
maxlength=50 size=40 name="dattext"
VALUE=""></TD></TR>
<TR><TD> </TD><TD><INPUT TYPE=submit
VALUE="Speichern"></FORM></TD></TR>
</TABLE>
---
The part of the script "upload.pl":
require "/daten/cgi-bin/cgi-lib.pl";
...
$cgi_lib'maxdata = 2000000;
$cgi_lib'writefiles = "/tmp";
$cgi_lib'filepre = "file";
$ret = &ReadParse;
&CgiDie("Error in reading and parsing of CGI
input") if !defined $ret;
...
---
Please answer me. I have tried many times to see
the error, but I cant see it.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 10 Oct 2000 17:25:04 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: foreach (@a) {i++; if ($i = even) {$bg = blue};... }
Message-Id: <39E334D0.19AD7552@schaffhausen.de>
andrew339@my-deja.com schrieb:
> I am printing out the lines of an array. Each line is a <tr> in an
> html table and I want the background color to alternate like a
> checkbook register. This is kind of kludgy and still doesn't work
> correctly. Can someone fix
>
> $i = 0;
> foreach (@match) {
> (@array) = (split /\^/,$_);
> $i++;
> if ($i ne ('0'||'2'||'4'||'6'||'8'||'10'||'12')) {
> $bg = "ffffcc";
> } else {
> $bg = "ccffcc";
> }
> print "<tr>\n<td bgcolor=$bg>\n";
> print "<input type=radio name=key value=$array[0]></td>\n";
> print "<td bgcolor=$bg>$array[2]</td>\n";
> print "<td bgcolor=$bg>$array[3]</td>\n";
> print "<td bgcolor=$bg>$array[4]</td>\n</tr>\n";
> }
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
I know nicer solutions for this have been posted but I always do this
because it goes
straighter into my mind:
$i = 0;
foreach (@array) {
if($i/2 == int($i/2)) { # if $i is even
# do stuff
} else {
# do other stuff
}
$i++;
}
There's more than one way to it,
malte
------------------------------
Date: Tue, 10 Oct 2000 13:15:50 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: foreach (@a) {i++; if ($i = even) {$bg = blue};... }
Message-Id: <Pine.GSO.4.21.0010101307571.14163-100000@crusoe.crusoe.net>
On Oct 10, Malte Ubl said:
> if($i/2 == int($i/2)) { # if $i is even
From an efficiency standpoint, it would be smarter to evaluate $i/2 just
once.
$div = $i/2;
if (int($div) == $div) { ... }
But I'd stick with
if ($i % 2) { odd }
or even the slightly faster
if ($1 & 1) { odd }
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Tue, 10 Oct 2000 14:09:28 GMT
From: belg4mit@mit.edu
Subject: format() from a variable?
Message-Id: <8rv7ui$2p3$1@nnrp1.deja.com>
So I've searched deja, TPC, the web, perlfaq, etc. And nothing...
I'm not asking for much, really all I want to do is assign some value to
a variable,
and use this variable's value as my format.... Any ideas?
Neither:
format T = '@<<<<<< @>>>>>';
$~ = 'T';
$a = "123";
$b = "xyz";
write();
nor:
$_ = '@<<<<<< @>>>>>';
format T =
@{[$_]}
.
$~ = 'T';
$a = "123";
$b = "xyz";
write();
had any success....
I see that I can resort to formline, but is there another way?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 10 Oct 2000 13:07:19 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: format() from a variable?
Message-Id: <Pine.GSO.4.21.0010101302570.14163-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 10, belg4mit@mit.edu said:
>I'm not asking for much, really all I want to do is assign some value to
>a variable, and use this variable's value as my format.... Any ideas?
>
>I see that I can resort to formline, but is there another way?
Well, if you're more than desperate (and have something against using
formline()...) then you could use eval. But I don't see a strong argument
against formline().
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Tue, 10 Oct 2000 13:57:00 -0400
From: Greg Miller <gmiller@gregmiller.net>
Subject: Re: How can I add 5 hours to the time my server reports?
Message-Id: <d1m6usctnj63mqo2h46dt92gddim00un3v@4ax.com>
On Mon, 9 Oct 2000 23:31:55 +0100, "Ben Graves"
<ben.graves@virgin.net> wrote:
>My server reports a time exactly 5 hours behind GMT.
>
>How do I add five hours to the time it reports in a way that also changes
>the date?
Pass (time()+60*60*5) to localtime.
----
Greg Miller (gmiller@nospam gregmiller.net)
http://www.customprogrammer.com
http://www.gregmiller.net
http://www.net-chess.com
------------------------------
Date: Tue, 10 Oct 2000 13:34:39 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: imagename.x and imagename.y confusion
Message-Id: <39e31aee.6a2c$fc@news.op.net>
Keywords: Ababa, Parke, Seton, impinge
In article <39E2AFAD.AAD2343D@onebox.com>,
John Tulabing <jtulabing@onebox.com> wrote:
>After I parse the form, I notice that there is an ImageName.x and
>ImageName.y. Can I do anything with these variables?
Those are the x and y coordinates of the exact spot in the image at
which the user clicked.
Suppose you had an image that displayed a map of your city, and you
wanted to know what street the user had clicked on, so you could tell
them about that street. You would need to know where they had
clicked. The browser enables applications like this by reporting the
X and Y coordinates of the click.
(This application explains why it's called an image'map'.)
In your case, you need to ignore the X and Y information and just have
your program focus on the fact that ImageName.x is present in the input.
>All I'm trying to do is add the ImageName info to the form.
Your program needs to know which form controls are clickable images.
Then you can preprocess the form data like this:
for $image (@images) {
if (exists $FORM{"$image.x"}) {
delete $FORM{"$image.x"};
delete $FORM{"$image.y"};
$FORM{$image} = 'clicked';
}
}
------------------------------
Date: Wed, 11 Oct 2000 00:20:32 +0800
From: Beggar <cpegbeggar@mail.com>
Subject: Insecure $ENV{PATH} while running setuid
Message-Id: <39E341D0.35EE37E4@mail.com>
I get this messsage when I try to run a program
having the suid bit set.
How to solve the problem ? is that need to disable some
security check first?? I really need to do so.
Thanks for any help!!
please reply to "cpegbeggar@mail.com"
Hei
------------------------------
Date: Tue, 10 Oct 2000 15:03:35 GMT
From: lim_k@my-deja.com
Subject: LWP, URI, HTTP brainfart
Message-Id: <8rvb42$5n3$1@nnrp1.deja.com>
I'm needing to create a script which connects to a authenticated web
site. I had created a script in the past for this but I had forgotten
which mod and the format of the mod I used. I'm pretty sure I used
LWP::Simple, but I wouldn't be my job on it. Any assistance is greatly
appreciated!
Thanks!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 10 Oct 2000 17:19:48 GMT
From: Ken MacLeod <ken@bitsko.slc.ut.us>
Subject: need help with tie magic in XS
Message-Id: <x5zokc62bq.fsf@bitsko.slc.ut.us>
I am creating a module that connects Perl to a C library, where the C
library exposes all of it's data via hashes. The C hashes need to
stay "live" (I can't just copy their values back and forth into a Perl
copy of the hash). Perl's tied hashes are the answer, but I'm having
some trouble implementing.
I started out copying *DBM_File, which lets Perl create a C object
pointer, store it in an SV (sv_setref_pv), and implement FETCH, STORE,
etc. against that C object. That works nicely, for C objects *created
and hooked up via the Perl tie() call*.
The problem I'm facing is that I've got lots of C objects that already
exist, and various Perl->C functions that will return references to
these objects back to Perl. I need to be able to "wrap" the existing
C objects as a tied object and then pass them back to Perl. That's
where I'm stuck.
What I'm trying now is creating the Perl HV, associating it with my
object, and adding tie magic to the HV so that my routines will be
called:
MyObject *my_object; // Initialized elsewhere
MGVTBL vtbl_TieTest = { 0, 0, TieTest_len, TieTest_clear, 0 };
MGVTBL vtbl_TieTestelem = { TieTest_get, TieTest_set, 0, 0, 0 };
MODULE = TieTest PACKAGE = TieTest
HV *
get_my_object()
CODE:
MAGIC *mg;
RETVAL = newHV();
sv_setref_pv((SV*)RETVAL, "TieTest", my_object);
hv_magic(RETVAL, NULL, 'P');
hv_magic(RETVAL, NULL, 'p');
mg = mg_find((SV*)RETVAL, 'P');
mg->mg_virtual = &vtbl_TieTest;
mg = mg_find((SV*)RETVAL, 'p');
mg->mg_virtual = &vtbl_TieTestelem;
OUTPUT:
RETVAL
I'm doing something wrong here because none of TieTest_len,
TieTest_clear, TieTest_get, or TieTest_set ever get called, and yet
the program segfaults. vtbl_TieTest and vtbl_TieTestelem are
patterned after vtbl_pack and vtbl_packelem.
I'd welcome links to tutorials, how-tos, or examples of modules that
implement ties this way.
Thanks,
-- Ken
------------------------------
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 4570
**************************************