[9865] in Perl-Users-Digest
Perl-Users Digest, Issue: 3458 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 16 12:04:43 1998
Date: Sun, 16 Aug 98 09:00:27 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 16 Aug 1998 Volume: 8 Number: 3458
Today's topics:
Array element var in a "foreach" loop? or an exhanced g aspeer@my-dejanews.com
Re: Array element var in a "foreach" loop? or an exhanc <sneaker@sneex.fccj.org>
Re: Array element var in a "foreach" loop? or an exhanc (Mark-Jason Dominus)
Re: Array element var in a "foreach" loop? or an exhanc (Ronald J Kimball)
Re: Array element var in a "foreach" loop? or an exhanc (Mark-Jason Dominus)
Re: Benchmark: shift vs. multiply (Larry Rosler)
Re: Docs for CGI.pm! <sneaker@sneex.fccj.org>
Re: Docs for CGI.pm! (Alastair)
Re: Docs for CGI.pm! <maryesme@mail.localaccess.com>
Re: eq and == difference >>Abigail -> You are a LOSER. (Michael J Gebis)
Re: eq and == difference >>Abigail -> You are a LOSER. (Nathan V. Patwardhan)
Re: eq and == difference (Gabor)
Re: here's an implementation of diff in perl <sneaker@sneex.fccj.org>
Re: is there a way to prevent the dos window from closi <ljz@asfast.com>
Kermit =~ /You are a LOSER. Take that stick out of your <sneaker@sneex.fccj.org>
Kermit Speaks (Kermit the frog)
Re: Multi-line regex w/ multi-file loop (Ronald J Kimball)
Re: OLE Perl Excel question scott@softbase.com
Re: OLE Perl Excel scott@softbase.com
Re: Outputting Images & Links in HTML (-)
Re: Perl/CGI Question <sneaker@sneex.fccj.org>
Re: Q: How to read all the file name in a directory (Michael J Gebis)
Re: Q: Missing first user (Ollie Cook)
Reference Confussion ruben@wynn.com
Re: sending variables with a hypertext link (Peter J. Elfman)
Re: sending variables with a hypertext link (Ronald J Kimball)
taint checking seems to slow down my code aspeer@my-dejanews.com
Re: taint checking seems to slow down my code <sneaker@sneex.fccj.org>
Re: taint checking seems to slow down my code (Mark-Jason Dominus)
Re: X-file (?=...), case postponed. (Ronald J Kimball)
Re: X-file (?=...), case postponed. (Ronald J Kimball)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 Aug 1998 09:26:55 GMT
From: aspeer@my-dejanews.com
Subject: Array element var in a "foreach" loop? or an exhanced grep ?
Message-Id: <6r68kt$pua$1@nnrp1.dejanews.com>
This is the second in a series of two questions (See earlier post re:"Taint
checking slows down my code !" and "Cross Dressing possum ran off with my dog
!". Actually cancel that second one - here comes the dog now ... bad boy !)
Anyway, I have been wondering for a while if there is an easy way to
determine where I am up within an arry inside a foreach loop. For example, if
I have some code:
my @temp=qw(Hello World Again);
foreach my $temp (@temp) {
print "$temp\n";
print "array element number here\n"
}
Is the element number I am up to in the array exposed anywhere in perl. I was
sort of hoping there was a (say) $^E variable that incremented with the
foreach loop. I know I can say:
my $i; foreach my $temp (@temp) {
print "$i $temp\n";
$i++
}
$i=undef;
But this has always seemed kind of messy. I am I missing something, or is that
the only way to do it ? If that is the only way to do it, maybe someone could
expose such a variable in a future version of perl ? I wish I could do it, but
I am not much of a 'C' programmer ..
Or am I missing something really obvious ?
While I am on the subject of ungraciously demanding extra functionality in the
perl language, how about a version of grep that returns the *elements* of an
arry that match an expression, rather that the array values. For example:
my @temp=qw(Hello World Again Worldly);
my @match=*my_new_grep_here*(/world/i,@temp);
print join(' ',@match);
would print "1 3". Again, I can do this with a "map", but it seems a bit
clunky to do:
my @temp=qw(Hello World Again Worldly);
my $i; my @match=grep(/.+/,map { $i++;/world/i?$i-1:undef } @temp);
Which *does* give me 1,3 - but looks really bad. Any easier way to do this
with in-built commands ?
Andrew Speer
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sun, 16 Aug 1998 08:52:15 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Re: Array element var in a "foreach" loop? or an exhanced grep ?
Message-Id: <35D6D5FF.AD6C0784@sneex.fccj.org>
aspeer@my-dejanews.com wrote:
>
> my @temp=qw(Hello World Again Worldly);
> my $i; my @match=grep(/.+/,map { $i++;/world/i?$i-1:undef } @temp);
>
> Which *does* give me 1,3 - but looks really bad. Any easier way to do this
> with in-built commands ?
What about $. (dollar sign period combo)?
Hmmm, :]
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: 16 Aug 1998 11:27:00 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Array element var in a "foreach" loop? or an exhanced grep ?
Message-Id: <6r6to4$3d3$1@monet.op.net>
In article <6r68kt$pua$1@nnrp1.dejanews.com>, <aspeer@my-dejanews.com> wrote:
>Is the element number I am up to in the array exposed anywhere in perl.
Nope.
>how about a version of grep that returns the *elements* of an
>arry that match an expression, rather that the array values. For example:
>
>my @temp=qw(Hello World Again Worldly);
>my @match=*my_new_grep_here*(/world/i,@temp);
>print join(' ',@match);
Use grep to select the appropriate indices from a list of numbers:
my @match = grep { $temp[$_] =~ /world/i } (0 .. $#temp);
print "@match";
------------------------------
Date: Sun, 16 Aug 1998 11:34:42 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Array element var in a "foreach" loop? or an exhanced grep ?
Message-Id: <1dduovf.1afpjmr59ksieN@bay2-82.quincy.ziplink.net>
<aspeer@my-dejanews.com> wrote:
> Anyway, I have been wondering for a while if there is an easy way to
> determine where I am up within an arry inside a foreach loop.
This was just answered two days under the subject "Index-Counter in
foreach-Block!?"
Short answer: No. Use a C-style for loop.
Hope that helps!
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 16 Aug 1998 11:38:46 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Array element var in a "foreach" loop? or an exhanced grep ?
Message-Id: <6r6ue6$3f2$1@monet.op.net>
In article <35D6D5FF.AD6C0784@sneex.fccj.org>,
Bill 'Sneex' Jones <bill@fccj.org> wrote:
>What about $. (dollar sign period combo)?
No, that only works for filehandles. I had a sick fantasy that you
could tie a filehandle to your array and read from it to get the
elements and update $., but it doesn't work.
------------------------------
Date: Sun, 16 Aug 1998 07:54:32 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Benchmark: shift vs. multiply
Message-Id: <MPG.104092847a44ad4d9897d1@nntp.hpl.hp.com>
In article <6r6147$6rk$1@mathserv.mps.ohio-state.edu> on 16 Aug 1998
07:18:31 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> says...
> [A complimentary Cc of this posting was sent to Lloyd Zusman
> <ljz@asfast.com>],
> who wrote in article <lt4svdd3wu.fsf@asfast.com>:
...
> > ... As you can see, there is
> > no significant difference in this environment between the use of bit
> > shifts and multiplication/division by the corresponding power of 2:
>
> This is not surprising. Perl's operation dispatcher results in 200x
> time overhead comparing with C code. All the advantages of shift
> vs. multiply will be hidden by this overhead.
Yes. So the goal of the programmer should be the perspicuity of the code
(to borrow a delightful term from Nigel Chapman's book).
I just changed ($year & 3) back to ($year % 4), which emphasizes the
periodicity, not the bit-ness, of the operation; it also looks better
with ($year % 400) if you care about 1900 or 2100.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 16 Aug 1998 08:17:57 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Re: Docs for CGI.pm!
Message-Id: <35D6CDF5.DCC7F837@sneex.fccj.org>
Martin Vorlaender wrote:
>
> powerfactor@hotmail.com wrote:
> : Where can I find some documentation about the CGI.pm?
>
> In CGI.pm itself. It's formatted using a simple ASCII format named POD
> (Plain Old Documentation). You can read it with any ASCII editor (search
> for a line beginning with '=head'), or use the perldoc program supplied
> with the standard distribution (like 'perldoc CGI').
>
> cu,
> Martin
True :]
Also, for those readers who would like a book to hold while
on the potty, try Lincoln's Official Guide:
ISBN: 0-471-24744-8 John Wiley & Sons
by Lincoln Stein (creator of CGI.pm)
HTH, :]
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: Sun, 16 Aug 1998 13:32:25 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Docs for CGI.pm!
Message-Id: <slrn6tdrgs.b1.alastair@calliope.demon.co.uk>
powerfactor@hotmail.com <powerfactor@hotmail.com> wrote:
>Hi,
> Where can I find some documentation about the CGI.pm?
>
You can find a lot of docs at Lincoln Stein's home page at ;
http://stein.cshl.org/~lstein/
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: Sun, 16 Aug 1998 07:55:11 -0700
From: Mark Lybrand <maryesme@mail.localaccess.com>
Subject: Re: Docs for CGI.pm!
Message-Id: <35D6F2CF.59E3@mail.localaccess.com>
Martin Vorlaender wrote:
>
> powerfactor@hotmail.com wrote:
> : Where can I find some documentation about the CGI.pm?
>
> In CGI.pm itself. It's formatted using a simple ASCII format named POD
> (Plain Old Documentation). You can read it with any ASCII editor (search
> for a line beginning with '=head'), or use the perldoc program supplied
> with the standard distribution (like 'perldoc CGI').
Also, the "Official Guide to Programming with CGI.pm" by Lincoln Stein
(the creator of CGI.pm) is also well worth the cost.
Mark :)
------------------------------
Date: 16 Aug 1998 07:31:09 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: eq and == difference >>Abigail -> You are a LOSER. Take that stick out of your ass!
Message-Id: <6r61rt$qug@mozo.cc.purdue.edu>
kermit@sesamestreet.com (Kermit the frog) writes:
}Shit like what this 'Abigail' character dishes out
}gives UNIX people a bad name.
}So, if it's not TOO much to ask, the next time you run across a
}posting that comes from a seemingly 'rudimentary' knowledge level,
}help him/her out instead of dumping your 'rough week at work' mental
}baggage on them.
Abigail is right: this really was a basic question that does
not require the collective mind of comp.lang.perl.misc [1] to solve.
A quick scan of almost any doc (electronic or hardcopy) would have
come up with the answer. Of course, Abigail was overly harsh in
expressing this thought.
But Abigail's message was also carefully crafted to provoke an angry
flame. Kermit, [2] you fell for it and lost your cool. You became
that which you despise--picture the Emperor gleefully grinning as Luke
is about to kill Vader. Don't do it Luke! You'll be as evil as they
are! Don't be seduced by the dark side! Remember Yoda! [3]
So, I'm afraid you loose karma on this one too. The universe has
spoken. [4]
[1] Kept in a 55-gallon drum in a garage in Hemet, California.
[2] If that is your real name.
[3] Kermit, certainly you can relate to Yoda. After all, you are both
green muppets.
[4] Only the universe can apportion karma. I just work here.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: 16 Aug 1998 14:47:42 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: eq and == difference >>Abigail -> You are a LOSER. Take that stick out of your ass!
Message-Id: <6r6ree$4o3@fridge.shore.net>
Kermit the frog (kermit@sesamestreet.com) wrote:
: Typical snobbish behaviour of a UNIX freak. Don't get me wrong,
: there are lots of civil UNIX users out there. Shit like what this
: 'Abigail' character dishes out gives UNIX people a bad name.
Aren't you being a little bit presumptuous here? I happen to know for
a fact that Abigail isn't a Unix user; in fact, Abigail is quite
content when Abigail sits at home with with a TRS-80!
Are you sure that you're in the right group, too? This is a Perl
group; I don't see anything about Unix or *cough* CGI *cough* in the
title, either. :-)
: I agree, perhaps, that there should maybe be a
: comp.lang.perl.misc.newbie group or something, but how would these
: questions get answered?
No. We've been over this a million times (www.dejanews.com), btw. If
you were a beginner who "needed to do something *fast*", would you
seek the newbies group where you probably wouldn't get a complete
answer or would you try to run with the expert pack?
*** Please be honest with yourself when you answer this question ***.
These questions get answered by (a) the person getting a decent book
and reading it from the first page to the last page, (b) the person
not biting off more than they can chew when it comes to working on
projects (for work or clients), (c) the person checking the FAQ for
the group (and no, it's not an elitist expectation for someone to do
so -- it's just been forgotten over time). In other words, the burden
of the work is on the questioner; once they've done a little bit of
research (and you've got to admit that it doesn't take very much work
to find the meaning of 'eq' and '=='), if there's something that they
don't understand, THEN they post to a newsgroup.
: So, if it's not TOO much to ask, the next time you run across a
: posting that comes from a seemingly 'rudimentary' knowledge level,
: help him/her out instead of dumping your 'rough week at work' mental
: baggage on them.
*sigh*
: They probably have other things to think about or else they wouldn't
: be posting the question in the first place.
eh? What things to think about? What are you talking about?
--
Nate Patwardhan|root@localhost
"Fortunately, I prefer to believe that we're all really just trapped in a
P.K. Dick book laced with Lovecraft, and this awful Terror Out of Cambridge
shall by the light of day evaporate, leaving nothing but good intentions in
its stead." Tom Christiansen in <6k02ha$hq6$3@csnews.cs.colorado.edu>
------------------------------
Date: 16 Aug 1998 11:52:09 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: eq and == difference
Message-Id: <slrn6tdi44.a09.gabor@guava.vmunix.com>
In comp.lang.perl.misc, Peter Richmond <peter@richmd.demon.co.uk> wrote :
# Hi,
#
# Is there a difference between eq and == ?
#
# Ive noticed that in some if statements eq works but == does not.
#
# Could someone shine some light on this?
'man perl' will shed light on this. time to read the docs that come
with perl. ;)
------------------------------
Date: Sun, 16 Aug 1998 08:32:16 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Re: here's an implementation of diff in perl
Message-Id: <35D6D14F.28679ABB@sneex.fccj.org>
Ilya Zakharevich wrote:
>
> On the other hand, if we compare each line of the first file with each
> line of the second file, then only O(n) comparisons will coincide, and
> O(n^2) will be different... And there are long common prefixes, as
> the leading whitespace usually is...
>
> Ilya
I always said - look at how things are the same, and the
differences will come out in the wash :]
Obtuse,
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: 16 Aug 1998 09:06:56 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: is there a way to prevent the dos window from closing after running a perl program in win32?
Message-Id: <ltu33daxe7.fsf@asfast.com>
"Mike Ostenberg" <mikeo@stiv.com> writes:
> Hi all,
> forgive my newbie question but I'm running perl under win95. [ ... ]
>
> Is there a way to prevent the dos window from automatically closing after
> running a perl program?
You could put an END block in your program, as follows:
END {
$input = <STDIN>;
}
This block should get invoked as your program is ending, even when
there is a run-time error. Of course, this won't help if there's a
syntax error in your program. Another approach can be used which will
help you in that case ... you can create a .BAT file to run your
program followed by a `pause' command. Here's a simple example:
@echo off
c:\path\to\perl\perl.exe program.pl args ...
pause
Once the program is debugged, you can comment out the `pause'.
> thanks in advance,
I hope this helps.
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: Sun, 16 Aug 1998 08:14:22 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Kermit =~ /You are a LOSER. Take that stick out of your ass!/
Message-Id: <35D6CD1E.C4881022@sneex.fccj.org>
Kermit the frog wrote:
>
> Why are you so fucking bitchy, loser???
The same could be asked about you.
Score:
Abigail's posts: 70% point to a resource.
Kermit's posts: 70% worthless flame.
And, so no one takes inapproriate offense;
Sneex's posts: 50% without a clue.
What really pisses me off is those that flame and try to do it
anonymously... If you have a complaint - stand up and speak your
mind intelligently - not stupidly. Or stand quiet. Abigail is
one who practices what she preaches. Has nothing to do with
good or bad - it is simple the way she wishes to provide, I must
say, considerable support, to the readers of this group.
None of us came here to be 'raised', we should all already
be mature enough to discuss issues calmly. Please accept
my motto below and say to yourself, as I do everyday,
"I am a killer; but I will not kill today."
Worked for Capt. Kirk ;)
HTH, :]
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: Sun, 16 Aug 1998 14:32:49 GMT
From: kermit@sesamestreet.com (Kermit the frog)
Subject: Kermit Speaks
Message-Id: <35d6e68e.838078@enews.newsguy.com>
OK. So I lashed out and perhaps went a bit overboard.
Yes, I made a few pointed remarks to the UNIX community - my apologies
to those in the UNIX community who are willing to step outside of
their little circle to help others. The comments were not directed at
you.
I guess this was prompted by several months of amazement at the nasty
tone this group tends to have, and then this 'Abigail' character came
along and really pissed me off with his/her total lack of flair for
sarcasm.
I have vented my frustrations on this situation and am now ready for
the next 6 months of childishness.
Yes, yes, it is true that some do not use the tools that are at their
fingertips. This includes documentation, internet searches,
bookstores, etc. but the answer that I did offer Peter (the original
poster) took me 2 seconds to enter -- far less time than it took
Abigail to spew the garbage that he/she did, I'm sure.
Here's an interesting experiment: respond with silence to those who
are not worthy of your knowledge...
If you feel that the question posed is below you or is being asked by
someone whom has 'not done their homework', then simply carry on to
the next article.
Hmmm. What a concept.
As for my anonymity, Mr. Gebis, I do not have time to sort through a
thousand emails entitled 'FUCK YOU' that I'm sure I would have
received on this hot little topic. Do you??? My karma is not at stake
here, buddy. There was careful thought put into my commentary.
Oh, and uh, by the way, there is no need for a war of the OSes here.
Ta-Ta.
Kermit
------------------------------
Date: Sun, 16 Aug 1998 11:34:43 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Multi-line regex w/ multi-file loop
Message-Id: <1ddupdk.9evs1g744w1yN@bay2-82.quincy.ziplink.net>
Ashley Tingdale <ash0578@flash.net> wrote:
> I recently saw a solution posted to open one file and assign it to a
> variable as one long string. This allows using a regular expression like
> this --
>
> { local $/; $file = <FILE> }
> $file =~ s/something/somethingelse/is;
>
> This is just what I have been looking for to replace some HTML with a
> server side include statement. But I need to do it on many files.
>
> I don't understand just how the special variable $/ works and why it is
> in a block by itself?.
Have you read the perlvar documentation? The special variable $/, the
input record separator, is documented there. The <FILEHANDLE> operator
reads in blocks of input, ending with the value of $/.
The default value of $/ is "\n", so <FILEHANDLE> usually reads in one
line of input at a time.
If the value of $/ is undefined, as it is in the above example, then
<FILEHANDLE> will read in the entire file.
It is in a block by itself so that the effects of the statement 'local
$/;', which make $/ undefined, will be temporary. This is the safe way
to do it, as there could be other code which depends on the value of $/
being something else.
> Can I just declare this $/ variable once at the
> top of the program, and loop through my files like this:
>
> local $/;
> @file_list; # list of files I search
>
> for (i = 0; i < @file_list; i++) {
> $file_name = $file_list[i];
> system ("cp $file_name $file_name . '.bak'");
> # backup file just in case
If $file_name is "foo", then the string you are passing to system is:
"cp foo foo . '.bak'"
I believe you meant to write:
system ("cp $file_name $file_name.bak");
> open (FILE, "< $file_name") ||
> die "cannot open $file_name file: $!\n;
Don't forget the closing quote...
> $file = <FILE>; # read file as one string
> $file =~ s/html text/SSI statement/is; # make switch
Yes, this bit should work.
> print ($file OUTFILE);
You've got that backwards; the filehandle should be the first argument
to print. :-)
> # assume that I have opened this above to shorten code
> close (FILE);
> close (OUTFILE);
> }
>
> Will this work okay?
If you fixed the few coding errors, I believe this would work, but there
is a *much* easier way to do it. You could use the -i and -p options,
which are documented in perlrun. -i stands for In-place editing, and
will take care of creating backups and editing the original files. -p
takes care of input and output, by putting your entire script in the
following loop:
LINE:
while(<>) {
# your script goes here
} continue {
print;
}
Thus, a complete script which accomplishes your task might look like
this:
#!/usr/local/bin/perl -pi.bak
BEGIN { undef $/ }
s/html text/SSI statement/is;
And you would use it like this:
~> script.pl file1 file2 file3 ...
The BEGIN block is there so that $/ will get undefined once, at compile
time, instead of every time through the loop.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 16 Aug 1998 15:49:29 GMT
From: scott@softbase.com
Subject: Re: OLE Perl Excel question
Message-Id: <35d6ff89.0@news.new-era.net>
olivierh3964@my-dejanews.com wrote:
> Assuming that cell A1 points to cell D5.
Can this be done in Excel? I'm not an expert, but I can't remember ever
seeing a way to make one cell "point" to another. I suppose you could
do it with a formula, in which case you'd have to use the property or
whatever of the cell that contains its formula to get the formula (I've
never done that so I don't know how).
One thing you can look at, *if* you are creating these pointers using a
formula, is Cell.Formula, which is a property of the cell containing
its formula. Cell.FormulaR1C1 has the row/column relative formula.
Suppose A1 has the value 100, and A1 has the formula "=A1" which makes
it "point" to A1. Then, Range("A2").Formula equals "A1".
I don't know if this answers the question or not, because the original
technique for establishing these "pointers" was never explained.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: 16 Aug 1998 15:40:39 GMT
From: scott@softbase.com
Subject: Re: OLE Perl Excel
Message-Id: <35d6fd77.0@news.new-era.net>
brenda_lowe@my-dejanews.com wrote:
>To do all of this stuff, I need to know how to scan excel
> spreadsheets (and access data bases later on) to extract the metrics.
My advice, having played with Automation some with Office 97, is to use
Application.Run to run macros you write in VBA to do whatever you want
to do. The Automation interface for Excel is a mine field, and using
it in a language that's about half-integrated with Automation like Perl
makes it worse. Trying to use Automation in Perl for anything other
than one-liners like opening a workbook and using Application.Run will
be an excercise in frustration and pain. Use the macro recorder as a
tool to record macros that do almost what you want, then use the VBA
editor to polish up the macros. Writing Automation code in Perl itself
is problematic because all the examples and docs are in VBA, and it
just doesn't quite translate. There's also no way to debug it. What you
end up doing is "write, run, fail, change, rewrite" over and over.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: Sun, 16 Aug 1998 13:26:22 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: Outputting Images & Links in HTML
Message-Id: <35d6dd0a.96298026@news2.cais.com>
"bon" <TOWER_DENE_EDU@email.msn.com> Said this:
>Can anyone please show me how I can include images and links in a script
>that I have found?
Same way you would in a normal web page <img src="blah.gif"> and <a
href="there.html">A Link</a>.
>Also, is it possible to have dynamically generated images in CGI output?
Sure. Anything is possible. If you have a program to create the
images, just include those images in a page with, again, <img
src="dynamo_image.cgi"> or whatever.
>__________________________________________
>webmaster@tradingtactics.com
You're a webmaster and you're asking these basic questions? Isn't
that like an airline pilot asking how to get the landing gear down?
------------------------------
Date: Sun, 16 Aug 1998 08:24:41 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Re: Perl/CGI Question
Message-Id: <35D6CF89.ABD645A@sneex.fccj.org>
mark@dboh.com wrote:
>
> I am just starting to write perl/cgi applications, so please excuse my
> ignorance. I have a perl/cgi script that reads a data file into a 2-d
> associative array, and then generates an inventory-item/checklist web-form
> based on the information just read in. As the user submits this form,
> subsequent scripts are run that need access to the same information that was
> stored in the 2-d array created in the original script. I am looking for a
> method to submit the contents of this array to the subsequent forms/scripts.
>
> I am using the &ReadParse subroutine found in the "cgi-lib.pl" library for
> parsing form information, but not sure how pass an entire array via a
> web-form. I could just re-read the data file over and over again in each
> subsequent script, but I was looking for a more efficient method. Any ideas
> or suggestions would be greatly appreciated.
>
> Thanks,
> Mark Brennan
> mark@dboh.com
Didn't I just see this post which Abigail answered?
See her response.
BTW, in case you missed her post, she said just send the file.
Which makes more sense. Or, if you really need to break it
down - see CGI.pm it will handle things for you.
HTH, :]
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: 16 Aug 1998 07:04:17 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Q: How to read all the file name in a directory
Message-Id: <6r609h$qri@mozo.cc.purdue.edu>
abigail@fnx.com (Abigail) writes in messages Message-ID: <6r5p3q$au2$2@client3.news.psi.net> and Message-ID: <6r5pvr$b4i$1@client3.news.psi.net>
}That sure beats asking in 'rec.cycling'
}"I just bought a bike. What do I do next?".
Dear God, you didn't just post that twice, did you?
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Sun, 16 Aug 1998 09:03:08 GMT
From: oliver.REMOVE.cook@bigfoot.DELETE.com (Ollie Cook)
Subject: Re: Q: Missing first user
Message-Id: <35d6a02b.389945@news.ukonline.co.uk>
On Sat, 15 Aug 1998 17:57:49 -0700, lr@hpl.hp.com (Larry Rosler)
wrote:
>[Posted to comp.lang.perl.misc and copy mailed.]
>He is British and likes the date before the month.
Too right!
Thanks to everyone who replied!
Ollie
----
Oliver COOK, Web Site Designer for
Premiere Web Designs - Http://Www.Premiere.Uk.Com/
+
Webmaster of The Audio-Visual Archive
* over 900 images and 700 sounds, free
* Http://Www.Premiere.Uk.Com/ava/
------------------------------
Date: Sun, 16 Aug 1998 15:26:32 GMT
From: ruben@wynn.com
Subject: Reference Confussion
Message-Id: <6r6tn7$hq9$1@nnrp1.dejanews.com>
I'm trying to create a complex data structure using references. But the perl
compiler is giving me an error message I don't understamd.
The code is:
snip ------
%build{ cols => [],
tabs=>[],
where=>[]->{ left_column =>\$where_left,
ops => \$where_ops,
right_values =>\$where_right,
bool => \$where_cont
},
"sort" => \$order
};
snip-------
The error message is:
Can't use subscript on hash deref at ./patients.cgi.1.0.1 line 12, near
"$order }" (Did you mean $ or @ instead of %?)
The Code seemed straight forward enough.
Any clues?
Ruben
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sun, 16 Aug 1998 14:51:37 GMT
From: elf@efga.org (Peter J. Elfman)
Subject: Re: sending variables with a hypertext link
Message-Id: <35d6ebe6.102466936@news.mindspring.com>
On Sun, 16 Aug 1998 04:37:58 +0100, "Daniel Adams" <dan@fearsome.net>
wrote:
>I need to call a perl script from within an html document. Normally, of
...
>However, I need to send some variables to the script when the hypertext link
>is clicked. Is this possible? How do I do this?
...
>yahoo.com/search.cgi?XXX_XXX
You have used the three magic letters C-G-I which when used in in
sequence in this newsgroup causes various people to refuse to talk to
you. You will have to rephrase your question to overcome this
problem.
I had the same questions a few days back. You are asking about how to
read in data from a GET operation. This is passed to Perl as an
Environment variable I suspect. So the code you would want would be
something like
$MyVars = $ENV{whatever the envirnment variableis};
Then you can use the split command or some other way to break them up.
That's beyond what I could explain. You have to ask in the group
without using the dreaded CGI word.
For a POST operation, you can send large amounts of data and you read
this just as you would standard input. Once in Perl your POST data is
input, and anything you "print" goes to the web page.
Decoding this is difficult, and for someone like me who knows so
little about Perl, I just use a library I found called cgi.pl and
recopy the Perl code that makes it work. While I've only read the
messages here (and the FAQ) for about two days, it seems there is
another module most people like called CGI.pm
You can find out more about CGI.pm module at
http://www.cpan.org/CPAN.html#cgi
I can't fill in the details for you, only give you the direction to go
in. You'll have to rephrase your question to how to read the data,
not how to send the data before you can get an answer here.
Get your free email and news posting account from Dragon*Con
http://www.dragoncon.net
------------------------------
Date: Sun, 16 Aug 1998 11:34:45 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: sending variables with a hypertext link
Message-Id: <1dduq6s.x7uflqv3t7z4N@bay2-82.quincy.ziplink.net>
Abigail <abigail@fnx.com> wrote:
> There is no 'cgi' in 'comp.lang.perl.misc'.
^ ^ ^
| | |
Hehe. :-)
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sun, 16 Aug 1998 09:01:19 GMT
From: aspeer@my-dejanews.com
Subject: taint checking seems to slow down my code
Message-Id: <6r674u$o3j$1@nnrp1.dejanews.com>
I have written some CGI code for collating and displaying stats on various log
files, and in doing so they can build fairly large hash tables.
If run from a shell, the code will process about 140 log lines per second. If
I run the program setuid, the speed drops to about 80 log lines per second. I
presume this is because the taint checker is checking *every* hash variable
*every* time I use it.
Let us just assume for the moment that I *have* to run the code setuid,
despite all the good advice about not doing so ! Is there anyway turn taint
checking on/or off by use of a pragma ? Eg I can say "no 'strict'" in some
places of my code, but there seems to equiv for "no 'taint". I know I can
turn it on from the command line using "-T", but I don't see a "--T" !
Don't get me wrong, I think the whole taint checking concept is great, but I
would like to use it as a warning. If I know there are area's of code that
doen't need taint checking, I would like to turn it off. Is there anyway to do
this ?
Thanks,
Andrew Speer
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sun, 16 Aug 1998 08:44:13 -0400
From: Bill 'Sneex' Jones <sneaker@sneex.fccj.org>
Subject: Re: taint checking seems to slow down my code
Message-Id: <35D6D41D.B56E0C5D@sneex.fccj.org>
aspeer@my-dejanews.com wrote:
>
> Let us just assume for the moment that I *have* to run the code setuid,
> despite all the good advice about not doing so !
Let's not, but...
> Is there anyway turn taint
> checking on/or off by use of a pragma ? Eg I can say "no 'strict'" in some
> places of my code, but there seems to equiv for "no 'taint". I know I can
> turn it on from the command line using "-T", but I don't see a "--T" !
>
You can recompile your Perl to assume that your setuid scripts
are 'safe' and forget about taint checking altogether.
Look at -DSETUID_SCRIPTS_ARE_SECURE_NOW flag.
Or you can look for another way around setuid. I have scripts
which do things which only certain users can/should do and they
work great without being setuid.
Who started this whole setuid thing anyways?
Just teasing, :]
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
http://webmaster.fccj.org/cgi/mail?webmaster
------------------------------
Date: 16 Aug 1998 11:22:38 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: taint checking seems to slow down my code
Message-Id: <6r6tfu$3bf$1@monet.op.net>
In article <35D6D41D.B56E0C5D@sneex.fccj.org>,
Bill 'Sneex' Jones <bill@fccj.org> wrote:
>Or you can look for another way around setuid.
I imagine that you could write an xsub which would turn off taint
mode completely.
>Who started this whole setuid thing anyways?
Dennis.
------------------------------
Date: Sun, 16 Aug 1998 10:48:25 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: X-file (?=...), case postponed.
Message-Id: <1dduolv.1p0w33fugxigwN@bay2-82.quincy.ziplink.net>
Patrick Timmins <ptimmins@netserv.unmc.edu> wrote:
> >
> > /(?=(.*))/
> >
> > Regex engine sees '(?=' [or compiled equivalent]
> > Regex engine begins a positive lookahead assertion. Thus,
> > anything matched while in the (?=) will not be saved to the
> > potential $&.
> > Regex engine sees '('
> > Regex engine begins parenthesized subexpression #1. Anything
> > matched while in the () will be saved to the potential $1.
> > Regex engine sees '.*'
> > Regex engine matches a whole bunch of characters. Potential $1
> > now contains the string of characters. Potential $& still
> > contains the null string.
> > Regex engine sees ')'
> > Regex engine ends parenthesized subexpression #1. The value
> > of potential $1 is now available as \1.
>
> Stop right there Ronald (and thank you for illustrating my point).
> Would you please tell me what is in the potential $1 right now if
> the regex is applied to the string "Just another Perl Hacker" ?
> I'll bet you a nickel that what is in the potential $1 is 'Just
> another Perl Hacker', and not 'ust another Perl Hacker' ... Thanks!
Yes, you are absolutely correct about that. However, you are neglecting
one interesting behavior of split when the pattern matches a null
string.
> So, in the original split expression context, we have a matching
> substring in the delimiter (as you point out above) containing 'Just
> another Perl Hacker'. According to the split docs, and I quote:
>
> "If the PATTERN contains parentheses, additional array elements
> are created from each matching substring in the delimiter."
There is another quote which applies in this situation:
A pattern matching the null string (not to be confused with a null
pattern //, which is just one member of the set of patterns matching
a null string) will split the value of EXPR into *separate
characters* at each point it matches that way.
[my emph]
> since the perldocs show the matching substring in the delimiter being
> thrown on to the array where it is encountered, and since we are
> encountering it right off the bat, it should be thrown on to the
> array. But instead it is discarded. This is curious, and illogical.
It is curious, but it is not illogical. The substring is not thrown
into the array because the pattern matches the null string. Thus, there
is no delimiter before the first character.
Here's a sort of Perl psuedocode explanation:
sub split (
($regex, $target, $max) = @_;
$prepos = 0;
while ($target =~ /$regex/g) { # apply regex
if (pos $target == $prepos) { # if pattern matched null string
next
if ((pos $target == 0) or (pos $target == length $target));
# key statement: skip putting anything on the array
# if the pattern matched the nullstring, and the match
# occured at either the beginning or end of the string
pos($target) += 1;
}
push (@result, substr($target, $prepos, pos($target)-$prepos));
foreach (existing_in_regex($1, $2, ... $n)) {
# very psuedocode :-)
push (@result, $_);
}
$prepos = pos $target;
}
}
> But please continue with your analysis:
>
> > Regex engine sees ')'
> > Regex engine ends positive lookahead assertion.
> > Regex engines sees end of regex
> > Regex engine has successfully matched regex. The value of
> > potential $1 is assigned to $1. The value of potential $&
> > is assigned to $&.
> >
>
> So how does $1 now magically become 'ust another Perl Hacker' instead of
> 'Just another Perl Hacker' ? Answer: It doesn't !
That's true.
> For some curious, illogical
> and undocumented reason, Perl throws it out!
That is what happens, but it is not undocumented. This is exactly the
case where the paragraph I pasted above and the key statement in my
psuedocode apply. The pattern matched the null string at the beginning
of the string, so split skips the match.
> So what you're left with is
> what should be the second element as the first element (the 'J' that is
> generated from the actual splitting on null, which, as Ronald documented
> above, occurs after the capture of 'Just another Perl Hacker' in $1).
That is not quite correct. The first element would *never* be 'Just
another Perl Hacker'. If split chose to put 'Just another Perl Hacker'
in the array, then it would also have to put the first delimited
substring in the resulting array. In this case, the first delimited
substring would be '', the null string before 'J'.
According to your suggested behavior, the resulting array would actually
look like this:
'', 'Just another Perl Hacker', 'J', 'ust another Perl Hacker', ...
Perl certainly could have been implemented that way. But instead, with
a pattern that matches the null string, split will not split before the
first character in the string. Thus, the match before 'J' is ignored,
the 'Just another Perl Hacker' matched by (.*) is discarded, and the
first element of the resulting array is actually 'J'.
> Ronald and Abigail, however, persist on saying that all this curious,
> illogical and undocumented behaviour is, in fact, logical and documented
> behavior.
That is no more convincing that my saying:
Patrick, however, persists on saying that all this curious, logical
documented behavior is, in fact, illogical and undocumented behavior.
See? I doubt either of us has changed our minds from that. :-)
> > It's not illogical. Since it is difficult to understand, it should be
> > documented better.
>
> See! I told you so.
Oh, you're so clever!
You seem to be using the premise that you do not understand the behavior
to prove the conclusion that the behavior is illogical and undocumented.
That does not follow. Here is the relevant section of the documentation
(with the example):
A pattern matching the null string (not to be confused with a null
pattern //, which is just one member of the set of patterns matching
a null string) will split the value of EXPR into separate characters
at each point it matches that way. For example:
print join(':', split(/ */, 'hi there'));
produces the output 'h:i:t:h:e:r:e'.
> Well, Ronald is starting to crack a bit on the documented
> part of it, but Abigail is still pushing it hard. Although I haven't heard
> from her lately, so maybe she's cracking on this by now as well!
I started to "crack" because it was apparent that the documentation is
not been clear enough, as you haven't understood its explanation of this
behavior. Therefore, the documentation should be better.
I apologize for being so adamant in this argument with you. It appears
that you do have a firm grasp of how regexes work - I was wrong about
that. It is just the intended behavior of split with certain regexes
that is causing a lack of understanding. If I had not been so forceful
in stating my point, we probably could have resolved this matter more
easily. So, I'm sorry about that.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sun, 16 Aug 1998 11:34:48 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: X-file (?=...), case postponed.
Message-Id: <1dduqlk.59t74i1yeq0q9N@bay2-82.quincy.ziplink.net>
Rick Delaney <rick.delaney@shaw.wave.ca> wrote:
> The part that is left out before this elegant explanation is
>
> Regex sees ''
> Regex matches the null string at the first possible place.
>
> The part you fail to understand is that the first possible place is
> *between* the 'J' and the 'u'. This is a special case with split that
> only applies to patterns that match the null string.
>
> This is not the case with m/(?=(.*))/g, for example, where the first
> possible match would be befor the 'J'.
That is not quite right. Perl can't know whether the regex will match a
null string until it applies the regex. For example:
split / */, "Hi there!";
split / */, " Hi there!";
In the first case, the regex matches the null string at the beginning of
the string, so split ignores the match. That is the special case with
split that only applies to patterns that can match the null string.
In the second case, the regex matches the whitespace at the beginning of
the string, so split puts '' on the array.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3458
**************************************