[17023] in Perl-Users-Digest
Perl-Users Digest, Issue: 4435 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 26 18:06:11 2000
Date: Tue, 26 Sep 2000 15:05:35 -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: <970005935-v9-i4435@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 26 Sep 2000 Volume: 9 Number: 4435
Today's topics:
Re: /me bangs head agains't brick wall <stephenk@cc.gatech.edu>
An interesting situtation!!! Please help me!!! hsriniv@my-deja.com
Re: Can't print to filehandle while using IO::Socket <uri@sysarch.com>
Re: Can't print to filehandle while using IO::Socket <amonotod@netscape.net>
Re: CD-ROM autorun with Perl??? (Richard J. Rauenzahn)
Re: Controlling line length read by <> <crowj@aol.com>
Re: Controlling line length read by <> <ren.maddox@tivoli.com>
Re: Controlling line length read by <> (Craig Berry)
Cygwin on NT4: IO::File and qx() won't play nice! <mayers@bmc.com>
Re: determine where visitors are "living" <uri@sysarch.com>
Re: determine where visitors are "living" <flavell@mail.cern.ch>
Re: Enviroment Interaction For A Newbie <tim@ipac.caltech.edu>
Re: Enviroment Interaction For A Newbie <ren.maddox@tivoli.com>
Re: field length variation <godzilla@stomp.stomp.tokyo>
floating point numbers on C vs. Perl <ronnie@catlover.com>
Re: floating point numbers on C vs. Perl <newsposter@cthulhu.demon.nl>
foreach two elements at a time? ()
Re: foreach two elements at a time? <chrekh@chello.se>
Re: foreach two elements at a time? (Abigail)
Re: foreach two elements at a time? <mjcarman@home.com>
Re: foreach two elements at a time? <mjcarman@home.com>
Re: foreach two elements at a time? <uri@sysarch.com>
Re: foreach two elements at a time? (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 26 Sep 2000 14:01:05 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: /me bangs head agains't brick wall
Message-Id: <39D0E460.11BE12B@cc.gatech.edu>
CJ Llewellyn wrote:
> I'm having trouble with a script that recurses through directories.
>
> #!/usr/bin/perl -w
>
> read_dir("/usr");
>
> sub read_dir {
> my $dirname = $_[0];
>
> opendir(DIR , $dirname) or die "Unable to open directory : $dirname\n";
> while (defined($file = readdir(DIR))){
> # ignore . and .. directory pointers
> if(! ($file eq '.' || $file eq '..')){
> if(-d "$dirname/$file") {
> $readdir = "$dirname/$file";
> read_dir($readdir);
> } else {
> print "$dirname/$file\n";
> }
> }
> }
> closedir(DIR);
> }
>
> The problem is that when the script reaches the last file in the lowest
> directory the script terminates, any suggestions ?
>
You're using a global dirhandle for each recursive call. Once you close it, there
is no open dirhandle to process, so your subroutine terminates. Two solutions:
1) add "local *DIR" (w/o quotes, of course) to the beginning of the subroutine
(perldoc perlsub).
2) use readdir in list context to read the dir before processing it (perldoc -f
readdir).
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Tue, 26 Sep 2000 17:55:17 GMT
From: hsriniv@my-deja.com
Subject: An interesting situtation!!! Please help me!!!
Message-Id: <8qqnu0$5re$1@nnrp1.deja.com>
Hi everybody,
I have got an interesting situation. Please help me.
The situation is:
I have got a file which looks like this:
ADDACC1 P45 ( .ACCRN( RNBUF), .CK125( CK125), .CKBLKG( CKBLKG), .FULLACC
( FULLACC), .LSDI( DI_0), .LSDO( DO_0), .LSP( P_0), .MSDI( DI_1), .MSDO
( DO_1), .MSP( P_1
), .OVERSAMP( OVERSAMP), .PRESCOUT
( PRESCOUT) );
RCNT8 P43 ( .CK( MXRCB_7), .Q_0( RC_8), .Q_1( RC_9), .Q_2( RC_10), .Q_3
( RC_11), .Q_4( RC_12), .Q_5( RC_13), .Q_6( RC_14), .Q_7( RC_15), .QB_7
( RCB_15
), .RN
( RNBUF) );
RCNT8 P42 ( .CK( PRESCOUT), .Q_0( RC_0), .Q_1( RC_1), .Q_2( RC_2), .Q_3
( RC_3), .Q_4( RC_4), .Q_5( RC_5), .Q_6( RC_6), .Q_7( RC_7), .QB_7(
RCB_7), .RN
( RNBUF
) );
MX2XL P1 ( .A( RCB_7), .B( PRESCOUT), .S0( RC_TSTE), .Y
( MXRCB_7) );
SSREG8 P41 ( .CK( CKSSBUF), .D_0( PREV_8), .D_1( PREV_9), .D_2(
PREV_10), .D_3( PREV_11), .D_4( PREV_12), .D_5( PREV_13), .D_6( PREV_14
), .D_7( PREV_15), .PI_0( RC_8), .PI_1( RC_9), .PI_2( RC_10), .PI_3(
RC_11), .PI_4( RC_12), .PI_5
( RC_13), .PI_6( RC_14), .PI_7( RC_15), .PLOADE( PLOADEBUF
), .Q_0( NEXT_8), .Q_1( NEXT_9), .Q_2( NEXT_10), .Q_3( NEXT_11), .Q_4(
NEXT_12), .Q_5( NEXT_13), .Q_6( NEXT_14), .Q_7
( NEXT_15) );
SSREG8 P40 ( .CK( CKSSBUF), .D_0( PREV_0), .D_1( PREV_1), .D_2(
PREV_2), .D_3( PREV_3), .D_4( PREV_4), .D_5( PREV_5), .D_6(
PREV_6), .D_7( PREV_7
), .PI_0( RC_0), .PI_1( RC_1), .PI_2( RC_2), .PI_3( RC_3), .PI_4(
RC_4), .PI_5
( RC_5), .PI_6( RC_6), .PI_7( RC_7), .PLOADE( PLOADEBUF), .Q_0(
NEXT_0), .Q_1( NEXT_1
), .Q_2( NEXT_2), .Q_3( NEXT_3), .Q_4( NEXT_4), .Q_5( NEXT_5), .Q_6(
NEXT_6), .Q_7
( NEXT_7) );
BUFX2 P63 ( .A( PLOADE), .Y
( PLOADEBUF) );
BUFX4 P64 ( .A( CKSS), .Y
( CKSSBUF) );
BUFX4 P65 ( .A( RN), .Y
( RNBUF) );
endmodule
I will have to get unique occurances of the things in the parantheses
after the ".", FOR EG:
consider this :
ADDACC1 P45 ( .ACCRN( RNBUF), .CK125( CK125), .CKBLKG( CKBLKG), .FULLACC
( FULLACC), .LSDI( DI_0), .LSDO( DO_0), .LSP( P_0), .MSDI( DI_1), .MSDO
( DO_1), .MSP( P_1
), .OVERSAMP( OVERSAMP), .PRESCOUT
( PRESCOUT) );
In this I will have to extract only RNBUF, CK125, CKBLKG, FULLACC,
DI_0, DO_0, P_0, DI_1, DO_1, P_1, OVERSAMP, PRESCOUT
.......... and I will have to continue doing this till i see
the "endmodule"....
But i will print only the unique occurance. FOR EG:
you can see that the RNBUF, occurs twice but it should be printed only
once.
PLEASE HELP ME.
ANY KIND OF HELP IS APPRECIATED.
THANKS IN ADVANCE.
Hari.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 26 Sep 2000 18:06:42 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Can't print to filehandle while using IO::Socket
Message-Id: <x7hf739gel.fsf@home.sysarch.com>
>>>>> "AH" == Adrian Harris <adrian@duual.com> writes:
AH> my $log = new IO::File ">>log.txt";
you don't test for failure there. also don't use indirect object
sytax. you use direct syntax elsewhere and it is safer (and IMO
clearer).
AH> print $log "$bit\n"; # This disappears into "bit heaven"
this is one place you could actually test the result of print. if the
file is not open (my guess) it will fail. also use direct object syntax
as i said above.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 26 Sep 2000 21:21:03 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Can't print to filehandle while using IO::Socket
Message-Id: <8qr3vm$fr3$1@nnrp1.deja.com>
In article <x7hf739gel.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "AH" == Adrian Harris <adrian@duual.com> writes:
>
> AH> my $log = new IO::File ">>log.txt";
>
> you don't test for failure there. also don't use indirect object
> sytax. you use direct syntax elsewhere and it is safer (and IMO
> clearer).
>
> AH> print $log "$bit\n"; # This disappears into
"bit heaven"
>
> this is one place you could actually test the result of print. if the
> file is not open (my guess) it will fail. also use direct object
syntax
> as i said above.
>
> uri
>
OK, but let me play Abagail:
no use strict
no -w
Now that's done with... Would not -w have caught an error with printing
to an invalid file handle?
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 26 Sep 2000 20:25:16 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: CD-ROM autorun with Perl???
Message-Id: <969999914.581551@hpvablab.cup.hp.com>
amonotod <amonotod@netscape.net> writes:
>I can do both... Yes and no. Yes, it can be done, but not as a script.
>You would have to compile it into an .exe file. See the PDK at
>www.activestate.com.
I don't know much about Win32 programming -- but why couldn't the
autorun.inf point to a perl.exe/installation on the cdrom that has the
script name as an argument?
And does this only get messy when trying to load modules, and the cdrom
path isn't known ahead of time?
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Tue, 26 Sep 2000 15:04:02 -0400
From: John Crowley <crowj@aol.com>
Subject: Re: Controlling line length read by <>
Message-Id: <39D0F322.DC2317D1@aol.com>
Bernard El-Hagin wrote:
>
> On Tue, 26 Sep 2000 10:00:02 -0400, John Crowley <crowj@aol.com> wrote:
> >
> >
> >Bernard El-Hagin wrote:
> >>
> >> Hi,
> >>
> >> Is it possible to make the <> ignore lines which contain more than
> >> an arbitrary amount of characters when reading a file (or any other
> >> source of data)?
> >>
> >> Regards,
> >> Bernard
> >> --
> >> perl -le 'open JustAnotherPerlHacker,""or$_="B$!e$!r$!n$!a$!r$!d$!";
> >> print split/No such file or directory/;'
> >
> >my $MAX=1024; # kbyte
> >
> >while (<>) {
> >
> > next if length > $MAX;
> >
> > # otherwise process the line
> >
> >}
>
> Obviously that's not what I'm looking for. I want to entirely skip lines
> which are too long to avoid my program chocking if someone tries to pass
> it 100MB in one line (extreme example, I admit :-)
>
> Cheers,
> Bernard
> --
> perl -le 'open JustAnotherPerlHacker,""or$_="B$!e$!r$!n$!a$!r$!d$!";
> print split/No such file or directory/;'
fine. then "read" one byte at a time appending each into a string until
you hit your max and blow away the string and read and dump bytes until
you hit an newline.
------------------------------
Date: 26 Sep 2000 12:39:28 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Controlling line length read by <>
Message-Id: <m3aecvrr1r.fsf@dhcp11-177.support.tivoli.com>
"Nicolas MONNET" <nico@monnet.to> writes:
> What the fuck was bernard.el-hagin@lido-tech.net (Bernard El-Hagin) trying
> to say:
>
> > Obviously that's not what I'm looking for. I want to entirely skip lines
> > which are too long to avoid my program chocking if someone tries to pass
> > it 100MB in one line (extreme example, I admit :-)
>
>
> Now I understand what you want to do, and it's basically
> impossible: to figure how long a line is, perl has to read
> it before hand. This would be possible, however, with some
> Unicode text format where lines are prefixed with their
> length (if I remember properly); in that case you could
> write a program that would seek to the next line.
While it is true that you will have to read the entire line to know
how long it is (and to get to the next line, for that matter), that
doesn't mean that you have to read it all at once. Fall back on a
more C-like solution, and read the file in preset chunks that are
small enough to handle. Within each chunk, search for the line
terminator (with index). If the line limit is exceeded, you still
keep reading chunks and searching for the line terminator, but you
don't save any of the data. Then when you find the line terminator,
you start over for the next line.
Perl-ish Pseudo-code:
while ($chunk .= read a chunk) {
while (chunk not empty) {
if (line terminator) {
if (flag set) {
throw away line from chunk
unset flag
} else {
extract line from chunk and process line
}
} else {
if (size of chunk > max line size) {
throw away chunk
set flag to ignore this line
}
}
}
}
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 26 Sep 2000 20:52:04 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Controlling line length read by <>
Message-Id: <st233ko50sb7bf@corp.supernews.com>
Bernard El-Hagin (bernard.el-hagin@lido-tech.net) wrote:
: Is it possible to make the <> ignore lines which contain more than
: an arbitrary amount of characters when reading a file (or any other
: source of data)?
It's not really feasible to make <> ignore the lines, but your code can do
so trivially:
while (<SOME_DATA_SOURCE>) {
next if length > 255; # ...or whatever limit you want
# Short-line processing goes here
}
Alternatively, if you're slurping the whole file with <>, you can
post-process away the long lines with grep:
@lines = grep { length $_ <= 255 } <>;
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Quidquid latine dictum sit, altum viditur."
|
------------------------------
Date: Tue, 26 Sep 2000 14:52:39 -0700
From: Mike Ayers <mayers@bmc.com>
Subject: Cygwin on NT4: IO::File and qx() won't play nice!
Message-Id: <39D11AA7.D0CB0C84@bmc.com>
I have discovered the following apparent problem and solution and am
looking for confirmation and/or insight.
Running Cygwin (1.0 commercial) on NT4 (SP5 or SP6a), I find that I can
not use both the IO::File package and qx(), although individually either
works fine. I have used minimalist scripts to verify this. When both
are included in the script (even if only by "use FileHandle", with no
actual instantiations), I get the following:
"C:/progfile/Cygwin/bin/bash.exe"-2.03$ perl -w test.pl
0 0 [main] C:\progfile\Cygwin\contrib\bin\perl.exe 1005
fork_copy: loaded dll data/bss pass 0 failed, 0x14043000..0x1404300C,
done 0, Win32 error 487
0 9979 [proc] perl 1005 wait_subproc: wait failed. nchildren 1,
wait 500, Win32 error 6
5919 15898 [proc] perl 1005 wait_subproc: event[1] 0x6C, Win32 error
6
5021207 5037105 [main] perl 1005 fork_copy: loaded dll data/bss pass 0
failed, 0x14043000..0x1404300C, done 0, Win32 error 487
5037238 10074343 [main] perl 1005 fork_copy: loaded dll data/bss pass 0
failed, 0x14043000..0x1404300C, done 0, Win32 error 487
5037567 15111910 [main] perl 1005 fork_copy: loaded dll data/bss pass 0
failed, 0x14043000..0x1404300C, done 0, Win32 error 487
5026917 20138827 [main] perl 1005 fork_copy: loaded dll data/bss pass 0
failed, 0x14043000..0x1404300C, done 0, Win32 error 487
5027247 25166074 [main] perl 1005 fork_copy: loaded dll data/bss pass 0
failed, 0x14043000..0x1404300C, done 0, Win32 error 487
5037767 30203841 [main] perl 1005 fork_copy: loaded dll data/bss pass 0
failed, 0x14043000..0x1404300C, done 0, Win32 error 487
"C:/progfile/Cygwin/bin/bash.exe"-2.03$
Note that the '"C' is actually '^C', but that's how it printed.
I have found that ActivePerl does not display this problem.
Any advice on this issue would be appreciated.
Thanks,
/|/|Ike
------------------------------
Date: Tue, 26 Sep 2000 18:01:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: determine where visitors are "living"
Message-Id: <x7k8bz9gnf.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@foad.org> writes:
A> Uri Guttman (uri@sysarch.com) wrote on MMDLXXXIII September MCMXCIII in
A> <URL:news:x7pulr9i6m.fsf@home.sysarch.com>:
A> ''
A> '' akamai uses many metrics to 'determine' where you are located, both on
A> '' the net and geographically. and they use a complex set of tables based
A> '' on many things like net cost, time, hops, server load, etc. to select
A> '' which server you get. their system works only because they look at all
A> '' that input and that gives a better download result on average for large
A> '' sites. this can be and is sold to customers. it doesn't have to be 100%
A> '' right or even close as long as it is better then the current situation
A> '' for a customer.
A> But note that determining what the best "site" for you is to download
A> stuff from is quite different from getting a geographical location.
A> The net has its own geometry, and there's no reason useful measurements
A> can't be performed in that geometry. It just isn't homeomorphic with the
A> earth surface.
but akamai does use geographic info as input to their algorithm. they
get it from various sources including whois and other clues. they are
well aware that is it not reliable, but it can make their guess as to
which server to use a little better. as i said, it is only one of the
many metrics they use and it does help some.
i worked there in that group last year so this is not hearsay, but
direct knowledge.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 26 Sep 2000 20:38:52 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: determine where visitors are "living"
Message-Id: <Pine.GHP.4.21.0009262026250.17922-100000@hpplus03.cern.ch>
On Tue, 26 Sep 2000, Craig Berry wrote:
> : But for _that_ kind of application, you couldn't care less where the
> : user is physically located. You're only looking for network-nearness,
>
> Of course; I actually mentioned this in part of my post you didn't quote.
My apologies if you felt that my quoting had been unfair.
I think the point of principle that I was trying to make was something
like this.
Somebody asked how can I get the answer to X.
They get given a method that actually give the answer to Y, which
might be an approximate, but potentially misleading, estimate of X.
We're now discussing a situation where the answer to Y is exactly
the right thing, and if there was a way of getting an accurate answer
to X it would be much less suitable for the purpose!
All's well that ends well.
> You can in turn correlate network position to geography, losing still more
> accuracy in the process.
Yes, but the point was that for this particular purpose, geography is
totally irrelevant. As I found one day when I traced the network
route to a company not half a mile away, and found myself taken
through a congested gateway in London, across the Atlantic to Canada,
down into New York, back across the Atlantic to London and through
a different congested gateway back to this company.
> Yeah, highly interesting but definitely non-Perl from the start.
Yes, I'm sorry, but there is a point of principle, as I say, (my
example was admittedly off-topic for here, but I think serves as a
good illustration of the point I'm trying to make) - and I can't think
of a better place to address it. Call it "elementary problem solving"
if you want, but the key issue is to _ask the right question_. If you
know a better group to discuss that principle, feel free.
--
The solution to "my eye hurts when drinking a cup of tea" is not to
take a painkiller, but to remove the spoon from the cup. - Abigail
------------------------------
Date: Tue, 26 Sep 2000 13:11:33 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Enviroment Interaction For A Newbie
Message-Id: <39D102F5.EA0C8677@ipac.caltech.edu>
Jonathan Klaff wrote:
> I am trying to use an alias I have set up in my .cshrc file from a perl
> script. Unfortunatly I have no idea how to do this!
>
> Please help (even if it is to say that this is not possible).
One *could* do this in perl. However, one almost certainly *should* *NOT* do
this in perl. Rewrite the alias as a shell script or, probably even better,
rewrite it as native perl.
The best I've come up with is something like:
<ILL_ADVISED_CODE>
use IPC::Open2;
open2(my $rfh, my $wfh, "/bin/csh -s");
print $wfh "aliased_command\n" or die "csh/print: $!";
close $wfh or die "csh/wclose: $!";
my @op = <$rfh>;
close $rfh or die "csh/rclose: $!";
print "@op";
</ILL_ADVISED_CODE>
See why you don't want to do this? :-)
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: 26 Sep 2000 14:42:55 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Enviroment Interaction For A Newbie
Message-Id: <m3ya0fq6rk.fsf@dhcp11-177.support.tivoli.com>
"Jonathan Klaff" <jon.klaff@rdel.co.uk> writes:
> Hi,
>
> I am trying to use an alias I have set up in my .cshrc file from a perl
> script. Unfortunatly I have no idea how to do this!
>
> Please help (even if it is to say that this is not possible).
"It's not possible."
That is, it might be possible, but you don't really want to do it that
way.
Show us what the alias is, and we'll probably be able to give you some
good suggestions on alternative ways to do it in Perl.
If you really, really, really need to call the alias, then you will
need to run csh with whatever options it needs to get it to call the
alias. (I'm not a csh guy, so I don't know how to do that.)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 26 Sep 2000 11:57:46 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: field length variation
Message-Id: <39D0F1AA.7BCE91F1@stomp.stomp.tokyo>
Sorry, no references. Original article is missing
from Sucker News.
Nathan D Hiller wrote:
> Does anyone know how to make an input field box the same
> length on both IE and Netscape browsers?
> The input field box for the member login on my web site
> is different lengths depending on which browser you view it with.
> With Netscape the field looks much longer than I want it to be.
Yes, there is a method with Perl requiring some effort on
your part or, effort on your visitor's part. Form text boxes
are adjustable with SIZE= whatever. A variable may be plugged
in, if you are printing your html via a script. In a similar
fashion, you may also plug in a variable if using a template.
You can detect a user agent with $ENV{HTTP_USER_AGENT}
and adjust accordingly. However, this is a tough project.
Adjusting your form action text field boxes based on a
browser type, requires you have many different browsers
installed on your system and, you need to visually inspect
how a form action appears, per specific browser. There is
another challenge with this method; screen resolution.
Each system will have a unique screen resolution setting.
Might be a common one or, a rather uncommon setting. Screen
resolution has a 'big picture' effect on how things look.
In a final analysis, you will discover trying to adjust
your page look per browser and especially screen resolution,
to be a near impossible task. This takes a lot of code
which doesn't always work quite right. Detecting screen
resolution with Perl, is most impossible; you cannot.
A work around for this, is tossing this responsibility
for page look upon your visitor. For an interactive page
this can be worthwhile. For a static page, I would not
bother. This method works fairly well, based on my
observations of visitors and their selections. I provide
three radio buttons for screen size selection. Clearly,
small, medium and large. Each radio button plugs in a
variable value for SIZE= within text field codes.
A visitor selects whatever is most personally pleasing.
Below my signature you will see a partial clip of
this method. Default values are set should a visitor
not select a screen size and, you will note following,
code to plug in values based on radio button selection.
This works well for my use. I also adjust many other
features including selection of rotating background
graphics. Each radio button input creates an url to
background graphics based upon ratios of,
640 X 480
800 X 600
1024 X 768
These are most common but not all available screen
resolution sizes. MAC computers are quite odd but
then it is rare to have a visitor using a MAC. Most
people know better than to buy a MAC computer. For
those with Lynx style browsers, it doesn't matter.
These are people with less sense than MAC owners.
This system works pretty good but not perfectly.
I've have no complaints so far and this does seem
popular. Each of my visitors has an option to save
a lot of information, such as nickname, font sizes,
font colors, font faces, text field size and the such,
along with background graphic size. There are hundreds
of these files at my site, indicating they are being
created, modified and used.
Based on data within these Perl created files, the
most common selection for screen size is medium,
equating to 800 X 600 screen resolution. Top browser
in use, based on my stats, ninety-three percent are
Mozilla 4.x series. Five percent MSIE, remainder being
Con type browsers such as Lynx. It is extremely rare
today to see a Mozilla 3.x series browser.
Rather than struggle and stress over trying to adjust
your page look per browser, give your visitor an option
of selecting a screen size. This is sure a lot easier.
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
I have included only one partial clip of a text
field to save space. Look for $chito3 in this
sample to note how this works.
my ($chito1, $chito2, $chito3);
$chito1 = "65";
$chito2 = "55";
$chito3 = "30";
if ($in{Screen} eq "small")
{
$chito1 = "55";
$chito2 = "45";
$chito3 = "20";
}
if ($in{Screen} eq "medium")
{
$chito1 = "65";
$chito2 = "55";
$chito3 = "30";
}
if ($in{Screen} eq "large")
{
$chito1 = "75";
$chito2 = "65";
$chito3 = "40";
}
<INPUT TYPE=\"text\" SIZE =\"$chito3\" MAXLENGTH=\"30\"
NAME=\"Hochifo_Apaknali\" etc..
------------------------------
Date: Tue, 26 Sep 2000 17:09:48 -0400
From: "Ron Grabowski" <ronnie@catlover.com>
Subject: floating point numbers on C vs. Perl
Message-Id: <8qr38m$ljh$1@news.cis.ohio-state.edu>
This is a school related assignment ( all 10 lines of it! ). In C the
following code works as expected, exiting the loop after 'oldsum' and 'sum'
are equal to each other:
#include <stdio.h>
// I'm not a gifted C programmer yet...
int main ( void )
float sum = 0;
float oldsum = 0;
int counter = 0;
do {
oldsum = sum;
counter++;
sum += 1.0 / counter;
} while ( sum != oldsum );
printf("Sum of 1/N => %.20f, counter => %d\n", sum, counter);
return 0;
}
And the corresponding Perl code is very similiar:
use strict;
my $old_sum = 0.0;
my $sum = 0.0;
my $counter = 0;
do {
$old_sum = $sum;
$counter++;
$sum += 1.0 / $counter;
} while ( $old_sum != $sum );
print "$sum \t $old_sum\n"; # loop never terminates
The Perl code does not terminate ( well it will terminate eventually but I
dion't want to wait a week ). The C code seems to be 'less precise' i.e. the
numbers are far less accurate than Perl's so the loop is able to exit after
about 2million interations ( roughly two or three seconds ). Perl's numbers
are much more exact and causing the loop to run for unacceptably long time.
Is there someway I can make Perl less precise? Some sort of pragma? I've
looked at the POSIX float constants but didn't see anything that caught my
eye. I've tried:
$sum += sprintf("%.4f", 1.0 / $counter);
And playing around with the %g operator for sprintf() but to no avail. I've
searched on CPAN for some sort of module or documentation that might help,
the CD Bookshelf, and my Mastering Algorithms With Perl book. These are some
of my settings:
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
alignbytes=8, usemymalloc=y, prototype=define
Ideas?
Ron
------------------------------
Date: 26 Sep 2000 21:57:03 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: floating point numbers on C vs. Perl
Message-Id: <8qr63f$iqg$1@internal-news.uu.net>
Ron Grabowski <ronnie@catlover.com> wrote:
> } while ( $old_sum != $sum );
When using float/double, never compare for exact equality, always
use a range:
ABS (val1 - val2) > eps
where eps is eg 1e-06
When I modified the C program to use doubles too it ran a long time:
742.61u 0.01s 12:24.37 99.7%
the Perl version has been running for 22 minutes and isn't done yet,
and I'm running out of patience as well ;)
Erik
------------------------------
Date: 26 Sep 2000 19:16:39 GMT
From: kmead@socrates.Berkeley.EDU ()
Subject: foreach two elements at a time?
Message-Id: <8qqsmn$bma$1@agate.berkeley.edu>
What is the perl idiom for traversing an array two elements
at a time?
In tcl, I can say
foreach {a b} $list { ... }
Is there some concise equivalent in Perl?
Thanks
Keith
------------------------------
Date: Tue, 26 Sep 2000 19:25:17 GMT
From: Christer Ekholm <chrekh@chello.se>
Subject: Re: foreach two elements at a time?
Message-Id: <86vgvj6jqk.fsf@jane.localdomain>
kmead@socrates.Berkeley.EDU () writes:
> What is the perl idiom for traversing an array two elements
> at a time?
>
> In tcl, I can say
> foreach {a b} $list { ... }
>
> Is there some concise equivalent in Perl?
As usual you can probably do this in many different ways. One is using splice
While ( ($a,$b) = splice(@list,0,2)) { ... }
/Christer
>
> Thanks
>
> Keith
------------------------------
Date: 26 Sep 2000 19:37:45 GMT
From: abigail@foad.org (Abigail)
Subject: Re: foreach two elements at a time?
Message-Id: <slrn8t1ult.lo9.abigail@alexandra.foad.org>
kmead@socrates.Berkeley.EDU (kmead@socrates.Berkeley.EDU) wrote on
MMDLXXXIII September MCMXCIII in <URL:news:8qqsmn$bma$1@agate.berkeley.edu>:
:: What is the perl idiom for traversing an array two elements
:: at a time?
::
:: In tcl, I can say
:: foreach {a b} $list { ... }
::
:: Is there some concise equivalent in Perl?
while (my ($a, $b) = splice @list => 0, 2) {
...
}
Abigail
--
my $qr = /^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Tue, 26 Sep 2000 15:13:48 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: foreach two elements at a time?
Message-Id: <39D1037C.6CC2ED89@home.com>
kmead@socrates.Berkeley.EDU wrote:
>
> What is the perl idiom for traversing an array two elements
> at a time?
As in elements 0 & 1, then 2 & 3, 4 & 5, etc.? Or 0 & 1, 1 & 2, 2 &
3...?
> In tcl, I can say
> foreach {a b} $list { ... }
>
> Is there some concise equivalent in Perl?
Not to my knowledge. Assuming you wanted the first way of grabbing
pairs, here are some ideas:
my @array = (0 .. 9);
# C-style for loop
for (my $i = 0; $i < $#array; $i += 2) {
my ($x, $y) = @array[$i, $i+1];
print "X: $x Y: $y\n";
}
# while loop
my $i = 0;
while ($i < $#array) {
my ($x, $y) = @array[$i++, $i++];
print "X: $x Y: $y\n";
}
Except that I don't think the order of the autoincrements is defined, so
that may not work (reliably). Here's a safe variation:
# while loop
my $i = 0;
while ($i < $#array) {
my ($x, $y) = @array[$i, $i+1];
print "X: $x Y: $y\n";
$i += 2;
}
And just for fun, here's a kind of tricky way that's more Perlish, but
has some limitations:
my %hashed_array = @array;
while (my ($x, $y) = each %hashed_array) {
print "X: $x Y: $y\n";
}
This makes use of the fact that each() returns two things: a key and a
value. The (serious) limitations of this approach are:
1) Need a copy of array as hash. Very wasteful of memory if array
is large.
2) Must have unique keys, so all the even array elements (at indices
0, 2, 4, etc.) must be unique.
3) Hashes are unordered, so you won't process your pairs in any
particular order (barring use of Tie::IxHash);
So this solution is mostly just for fun. Of course, you didn't tell us
what you're really implementing -- maybe a hash is a better structure to
use than an array anyway.
-mjc
------------------------------
Date: Tue, 26 Sep 2000 15:28:13 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: foreach two elements at a time?
Message-Id: <39D106DD.71065F82@home.com>
Abigail wrote:
>
> kmead@socrates.Berkeley.EDU wrote:
> :: What is the perl idiom for traversing an array two elements
> :: at a time?
> ::
> :: In tcl, I can say
> :: foreach {a b} $list { ... }
> ::
> :: Is there some concise equivalent in Perl?
>
> while (my ($a, $b) = splice @list => 0, 2) {
> ...
> }
>
That's a good Perlish method (and one I hadn't thought of) but the OP
should be warned that this will destroy his array.
-mjc
------------------------------
Date: Tue, 26 Sep 2000 20:57:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: foreach two elements at a time?
Message-Id: <x7aecuan1m.fsf@home.sysarch.com>
>>>>> "MC" == Michael Carman <mjcarman@home.com> writes:
MC> Abigail wrote:
>>
>> kmead@socrates.Berkeley.EDU wrote:
>> :: What is the perl idiom for traversing an array two elements
>> :: at a time?
>> ::
>> :: In tcl, I can say
>> :: foreach {a b} $list { ... }
>> ::
>> :: Is there some concise equivalent in Perl?
>>
>> while (my ($a, $b) = splice @list => 0, 2) {
>> ...
>> }
>>
MC> That's a good Perlish method (and one I hadn't thought of) but the OP
MC> should be warned that this will destroy his array.
for ( my $i = 0 ; $i < @list ; $i += 2 ) {
my( $x, $y ) = @list[ $i, $i + 1 ] ;
note the use of $x and $y instead of $a and $b. abigail should know
better even in simple examples like this.
also this is a rare case of my using a c style for loop.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 26 Sep 2000 21:27:38 GMT
From: abigail@foad.org (Abigail)
Subject: Re: foreach two elements at a time?
Message-Id: <slrn8t253t.lo9.abigail@alexandra.foad.org>
Uri Guttman (uri@sysarch.com) wrote on MMDLXXXIII September MCMXCIII in
<URL:news:x7aecuan1m.fsf@home.sysarch.com>:
@@ >>>>> "MC" == Michael Carman <mjcarman@home.com> writes:
@@
@@ MC> Abigail wrote:
@@ >>
@@ >> while (my ($a, $b) = splice @list => 0, 2) {
@@ >> ...
@@ >> }
@@
@@ MC> That's a good Perlish method (and one I hadn't thought of) but the OP
@@ MC> should be warned that this will destroy his array.
@@
@@
@@ for ( my $i = 0 ; $i < @list ; $i += 2 ) {
@@
@@ my( $x, $y ) = @list[ $i, $i + 1 ] ;
@@
@@ note the use of $x and $y instead of $a and $b. abigail should know
@@ better even in simple examples like this.
Huh? What's wrong with lexical $a and $b?
my @list = "a" .. "h";
while (my ($a, $b) = splice @list => 0, 2) {
print "$a$b\n";
}
__END__
ab
cd
ef
gh
I fail to see a problem here.
Abigail
--
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
. "\162\1548\110\141\143\153\145\162\0128\177" and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}
------------------------------
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 4435
**************************************