[7741] in Perl-Users-Digest
Perl-Users Digest, Issue: 1366 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 25 17:11:48 1997
Date: Tue, 25 Nov 97 14:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 25 Nov 1997 Volume: 8 Number: 1366
Today's topics:
Re: [Q] Can't Listen w/ IO::Socket under GlibC <gbarr@ti.com>
Re: [Q] Why does this behave this way? (Brendan O'Dea)
Re: File test operators do not work as advertised!! <qdtcall@esb.ericsson.se>
Re: Finding the longest common prefix over a list of st (Abigail)
Re: getting output from system <rootbeer@teleport.com>
Re: GUID bit <doug@tc.net>
Re: Help me!!! In Win NT 4.0 Don't work but in Unix it <$_=qq!fearless\@NOSPAMio.com!;y/[A-Z]//d>
Re: help with macperl... <c..bojswbo@86.usenet.us.com>
Re: How can I hide the Query string in the URL? <founder@pege.org>
Re: How can I hide the Query string in the URL? (Toutatis)
Re: How can I hide the Query string in the URL? (Jeremy D. Zawodny)
Re: How do you export a variable from module? (Jason Gloudon)
Re: How to determine if a value is "readonly"? <rootbeer@teleport.com>
Re: How to: push (condition ? @this : @that),$value; (B <devnull@nvg.org>
Re: Lock File <rootbeer@teleport.com>
Re: maintain unique elements in an array? no duplicates (Eric Bohlman)
Re: max size of cookie? <rjk@coos.dartmouth.edu>
Re: passing more than 1 variable in a href <prosser@ewa.net>
Re: referring to a hash in a package, proper scope <zenin@best.com>
Searchengine-project: Volunteers wanted (Andreas Steffan)
Re: security questions <nick@webthing.com>
SIZE OF PROGRAM. Are there limits?? <gdoucet@ait.acl.ca>
Re: Sorting an array (Eric Bohlman)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 24 Nov 1997 11:43:17 -0600
From: Graham Barr <gbarr@ti.com>
To: nicholas@neko.binary9.net
Subject: Re: [Q] Can't Listen w/ IO::Socket under GlibC
Message-Id: <3479BCB5.F30B83CD@ti.com>
nicholas@neko.binary9.net wrote:
>
> After redesigning my Linux system to use Glibc 2.0.5c, I've found that
> I can no longer use IO::Socket to create & listen to a udp(or tcp) socket.
>
> When I strace my program, I see something like:
>
> bind(3, ....) = 0
> listen(3,1) = -1 EOPNOTSUPP (Operation Not Supported)
>
> A simple program like:
>
> #!/usr/bin/perl
>
> use IO::Socket;
>
> $sock=new IO::Socket::INET(Listen=>1,Proto=>'udp',LocalAddr=>'neko',
> LocalPort=>2122);
>
You are creating a 'udp' port, and listen cannot be called
on such a port. In fact you do not need to call listen for
a udp port. man listen reports
To accept connections, a socket is first created with
socket(3N), a backlog for incoming connections is specified
with listen() and then the connections are accepted with
accept(3N). The listen() call applies only to sockets of
type SOCK_STREAM or SOCK_SEQPACKET.
A udp port is of type SOCK_DGRAM not SOCK_STREAM or SOCK_SEQPACKET,
that is because a udp port does not require a connection.
Remove the Listen=>1 from your code and whenever someone sends
a udp packet IO::Select will tell you there is data to be read()
Graham.
--
Originality is the ability to conceal your source.
------------------------------
Date: 24 Nov 1997 03:19:13 GMT
From: bod@compusol.com.au (Brendan O'Dea)
Subject: Re: [Q] Why does this behave this way?
Message-Id: <65arnh$ke$1@diablo.compusol.com.au>
In article <Pine.GSO.3.96.971122083826.15389G-100000@usertest.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Fri, 21 Nov 1997 lm@binary9.net wrote:
>
>> @a=qw ( Hello );
>> $a=sprintf @a;
>
>The first argument to sprintf should be a format string. In this case,
>it's not. Hope this helps!
True, although it is a little surprising that the behavior of sprintf
is inconsistent with that of printf in this regard:
$ perl
@args = ("%d\n", 10);
printf @args;
print sprintf @args;
^D
10
2$
The perltrap document notes this discrepancy under
_Context Traps - scalar, list contexts_
o _(list, builtin)_
and suggests that it is ``Probably a bug''.
I would hazard a guess that it could be a result of sprintf being a
prototyped builtin as opposed to printf which is an object method (and
hence can't be prototyped).
The simplest solution is simply to shift the first element into a
temporary variable, which works consistently for both:
$ perl
@args = ("%d\n", 10);
$fmt = shift @args;
printf $fmt, @args;
print sprintf $fmt, @args;
^D
10
10
$
Regards,
--
Brendan O'Dea bod@compusol.com.au
Compusol Pty. Limited (NSW, Australia) +61 2 9809 0133
------------------------------
Date: 24 Nov 1997 11:54:50 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: File test operators do not work as advertised!!
Message-Id: <ishg92ftol.fsf@godzilla.kiere.ericsson.se>
daveisdead@aol.com (DaveIsDead) writes:
> As far as I can figure
>
> opendir DIR, '/home/foo';
> @dirs = grep -d, readdir DIR;
>
> should load up @dirs with all of the directories in /home/foo,
> without the full path name.
No, it shouldn't. You're reading filenames from /home/foo but testing
files in whatever the current working directory happens to be. This is
clearly spelled out in the documentation for readdir:
If you're planning to filetest the return values out
of a readdir(), you'd better prepend the directory
in question. Otherwise, because we didn't chdir()
there, it would have been testing the wrong file.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: 24 Nov 1997 18:23:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Finding the longest common prefix over a list of strings
Message-Id: <slrn67jhjt.b3.abigail@betelgeuse.wayne.fnx.com>
Tushar Samant (scribble@shoga.wwa.com) wrote on 1545 September 1993 in
<URL: news:65aacm$qus@shoga.wwa.com>:
++ abigail@fnx.com writes:
++ >Tushar Samant (scribble@shoga.wwa.com) wrote on 1545 September 1993 in
++ ><URL: news:65877a$39f@shoga.wwa.com>:
++ >++ kfox@ford.com writes:
++ >++ >For everybody else, here's my implementation of Ilya's algorithm:
++ >++
++ >++ How about benchmarking with some kind of check here?
++ >
++ >How about trying to *analyze* both algorithms?
++
++ I agree with the analysis.
Well, I don't. Even with the chop() there, the algorithm is
still O (k * (N + k)) due to the test. Here's an optimal version:
my @words = ("word1", "word2", "word3", ...., "wordN");
my $end = length $words [0] - 1;
foreach my $w (1 .. $#words) {
$end = length $words [$w] - 1 if $end >= length $words [$w];
foreach my $i (0 .. length $words [$w] - 1) {
if (substr ($words [$w - 1], $i, 1) ne
substr ($words [$w], $i, 1)) {
$end = $i - 1;
last;
}
}
last if $end < 0;
}
$prefix = substr $words [0], 0, $end + 1;
Let word [i] have length k_i; define K = Sum_i k_i.
Let N be the number of words; assuming we have no empty
words, N <= K.
It's easy to see each letter gets involved into a comparison
at most twice. Hence, we have at most O (K) iterations of
the inner loop, which all take O (1). We have O (N) iterations
of the outer loop, each iteration takes O (1) + plus time
we already charged to the inner loop.
Hence the total running time is O (K), which is linear in
the input size.
++ The reasons for suggesting benchmarking
++ are different.
++
++ The check I suggested will make a difference depending on what the
++ specific sample of inputs is. If the "typical" sample consists of
++ words where the first two or three already have no common prefix,
++ then the loop will abort regardless of the size of the list. Bench-
++ marking is one way of getting a hold on this kind of statistical
++ characteristic.
++
++ We could make further refinements -- for instance, if you get a
++ word which is shorter than the prefix so far, you chop the prefix
++ down by several characters at once, OR for instance you make a
++ pass (still linear) and start with the shortest word -- etc etc,
++ but it becomes less and less clear just how much these refinements
++ accomplish for an input population we don't know much about.
Hey! In the previous paragraph you come with "typical samples",
but now you say you don't much about the input...
++ Agreed, the regex restarts the "loop" every time the prefix gets
++ smaller, and the prefix gets smaller only in steps of 1. So in bad
++ cases (e.g. a list of 101 words which are the decreasing substrings
++ of a 100-letter word) it will do a horrible job getting to the
++ common prefix "".
++
++ But that brings up two points: 1) what are all these constants--we
++ are imagining that the regex engine is going through a loop similar
++ to ours, but surely a "single operation" in that "loop" doesn't cost
Ah, but the problem isn't constants. The problem is that the number
of operations the regex solution is of a different *order* then the
number of operations of Ilya's solution.
++ the same. 2) Once again, what sort of population is it being sicked
++ on--if all it ever did any one time was about 20 words of length 7
++ on average, benchmarking becomes pretty much the only method of
++ comparison.
++
++
++ BTW I suggested "chop" not because I think substr is more expensive
++ (I have no idea if it is), but because it's easier to read:
The substr was an assignment, so you had to copy the string; which
is clearly at least linear in the length of the string. A chop only
needs to decrease the length of the string, which is just a variable
in the structure for that variable.
++
++ $len = length($string); $len--;
++ $string = substr($string, 0, $len);
++
++ vs
++
++ $len = length($string); $len--;
++ chop $string;
Well, wouldn't the following even be more readable:
chop $string;
$len = length ($string);
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Mon, 24 Nov 1997 10:27:31 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: "Michael R. Harper" <mikihasa@worldnet.att.net>
Subject: Re: getting output from system
Message-Id: <Pine.GSO.3.96.971124102433.24464I-100000@usertest.teleport.com>
On Sun, 23 Nov 1997, Michael R. Harper wrote:
> Newsgroups: comp.lang.perl.misc, <comp.lang.perl.misc>
That's an interesting list of newsgroups. :-)
> I would like to capture (save as a variable) the output (STDOUT) from a
> program that I execute (using the system command) during a Perl script.
Yes; read the docs for the system function where it begins "This is NOT
what you want to use to capture the output from a command". If your docs
don't contain that phrase, try getting a more recent version of Perl which
should come with newer docs. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 24 Nov 1997 13:12:15 -0500
From: Douglas McNaught <doug@tc.net>
To: Jason Varsoke <jjv@caesun.msd.ray.com>
Subject: Re: GUID bit
Message-Id: <m2ra86nou8.fsf@ono.tc.net>
[mailed and posted]
Jason Varsoke <jjv@caesun.msd.ray.com> writes:
> So this is only partially a Perl question, but I'm having the problem
> only in perl. I don't have the problem in my C code. So here it goes.
> I've got a program which needs to run with the GUID bit set so it can
> create a file with the correct group, which the user may not belong to.
> When I run the program I get the following error message:
>
> Insecure dependency in open while running setgid at /dev/fd/3 line 206.
>
> There are two strange things about this
> 1) I'm supplying an argument on the command line which tells me which
> file to write (There are some database calls to find out the filename
> from the input). But when Hardcode the argument in the program, as it
> would be in from the command line, the program doesn't produce the
> error. if @ARGV = (ID=10); works, but ./foo.pl ID=10 does not
Working As Designed. Perl views data coming from the command line as
'tainted'. To find out why, and to see what options you have, see the
'perlsec' manpage.
> 2) the second part that makes this unusual is that I have another
> perl program with the exact same function (the one that creates the
> file) and it works all the time, taking stuff from the command line and
> all.
It's not running setgid, I'm guessing.
> Please e-mail me with any suggestions: jjv@caesun.msd.ray.com
Well, OK. Since you didn't mangle your From: address.
-Doug
--
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";
------------------------------
Date: Mon, 24 Nov 1997 10:05:53 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/[A-Z]//d>
Subject: Re: Help me!!! In Win NT 4.0 Don't work but in Unix it is working
Message-Id: <65cfr5$vtj@news.microsoft.com>
Unfortunately we can't help you for two reasons:
1. You have only told us you have a problem but we don't know what the
problem is. All we have is one error message, "CGI error."
2. The error message leads me to believe that the problem may not be in your
Perl script, but rather in how it tries to talk to the CGI server. It could
be something as simple as using "\" to separate files like
"directory\filename" rather than "directory/filename" which Unix would
expect, or it could be something as complicated as setting up the CGI server
in question to accept Perl scripts for CGI. But without more information
there's no way of knowing.
Hopefully your web administrator or someone at your site can give you a hand
with this. Sorry.
JungWon LEE wrote in message <65cc8n$drp$1@newstmp1.bora.net>...
>Hi~
>
>I have some headache about this situation.
>
>In Unix it's fine. no problem.
>
>But Windows NT 4.0, it reports "Can't locate...CGI error..."
>
>I have known...the Perl nice working in any platform...Unix, Windows NT,
>etc.
>
>What makes this happen ?...
>
>Immediately anwser me, please!
>
>I have a important demonstration in front of my boss!!!
>
>This situation must fix...get the solution...
>
>I wait your nice answer...Thanks...
>
>P.S: Reply to my e-mail address, I very much appreciate!
>
>
>
------------------------------
Date: 24 Nov 1997 07:46:07 GMT
From: Anirvan Chatterjee <c..bojswbo@86.usenet.us.com>
Subject: Re: help with macperl...
Message-Id: <65bbbv$rq9$1@samba.rahul.net>
MrPc <tjbiuso@redrose.net> wrote:
: i recently made some scripts for my school's web server assuming it ran
: unix when i learned that it was a mac (i hate those things) running
: webstar. i looked for sites that gave tutorials on macperl but found
: nothing helpful. can ne1 tell me the major differences between unix
: perl and macperl? thanks in advance =+}...
Poke around <http://www.ptf.com/macperl/>. There's also a file called
"macperl.pod" in the MacPerl distribution that'll help out. I love
Macs to death (they're fabulous for interactive work), but I just
can't stand them as servers or scripting environments...
_____________________________________________________________________
Anirvan Chatterjee . anirvan @ chatterjee.net . PGP 2048/0xE2D13BA9
Fast & free new/used multi-bookstore searching @ http://www.mxbf.com/
Version: 2.6.2
iQEVAwUBNHkwkvxRqGfi0TupAQHhXAf+J1808LM42Av6AASv6MT05b7mBqnMSJOC
HffZNIwqzXUKOa8kVrpPuM60kHHZNU/Gb5hjCM7VQWv5bnoNdxd1NdA6jKjIxXKA
iQl4xASVoth/HNaeu8gI1AMPMfr6Trl176YgpsJ0DZex3cX5Anmomc8HafzV22j/
b/Drh2kDAGAv8CLx69YhuXyE5Cwfx2cSO29BncKoOD9jfeRK7Q5ovAra9bgWZ9A2
knfPqnzbcqPKFRNdgOTAAyBxwCEgjAnaAdea+mIUsCcYBl090bTf1gIzsdhSUk3m
443MHeGhNgqnSUg9VQxVfEitfj0l3w8vpbCmTB0dyplf5mAPpMZwnw==
=LePR
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 23 Nov 1997 23:45:56 +0100
From: "Mosl Roland" <founder@pege.org>
Subject: Re: How can I hide the Query string in the URL?
Message-Id: <65atqo$ihl$1@orudios.magnet.at>
gonzalo@interimagen.com wrote in message
<880189320.28539@dejanews.com>...
>Hi everybody,
>
> Please help me to handle this. I have a script that works with
forms;
>it works, but I want to know how can I remove the data sent to the
script
>from the URL, it means:
>
>
http://xxx.xxx.xxx/cgi-bin/mu.cgi?name=blah&email=blah&address=blah
>
> I want this
>
> http://xxx.xxx.xxx/cgi-bin/mu.cgi
maybe @splited=split(/?/,$the_string);
Will contain 2 elemants.
I am programer since 1976. Now I am webdesigner.
So my profession is it to make information about
my customers easy to find by search engines.
I find it always very difficult to find information about
perl on the web.
Perl programers like always to be very confusing.
So what's about a project to find every question
about perl answered by Altavista or infoseek.
For example, I started perl without any documentation
and did not find out how to add 2 strings together.
When my project will be ready, You can ask infoseek
"how can I add to strings together in perl"
and infoseek will give You the right answer.
Search engines are wonderfull, when they have the
right information :-).
For example I did not know 8 month what a SSI is.
Now try to ask infoseek
"How can I call a program on the server from inside my html page"
or some similar queries. You will find on top my page about SSI.
Some month ago, I wanted to bring my words on the top of the
search results. But now, the art is to make a page findable for
persons not knowing the right word for something.
For persons only having an idea what they search.
Got the idea of my project?
The idea is to design together many pages answering
every question about perl in a way, that a beginer can
understand it and find it easy by a search engine.
Most perl pages contain only examples, where an
advanced perl programer wants to show every reader,
that the reader is a idiot.
How wants to work with me together in this project?
Make perl a easy to learn language.
Chevalier Mvsl Roland founder@pege.org
http://pege.org - clear targets for a confused civilization
get 2mb free homepage -> http://yi.com/yimmi.php?yimmi=Pege
Callback ohne Anmeldegeb|hren und 5%
f|r die Sonnenenergie -> http://pege.org/utelco/
------------------------------
Date: 24 Nov 1997 11:57:34 GMT
From: toutatis@no.mail.please (Toutatis)
Subject: Re: How can I hide the Query string in the URL?
Message-Id: <toutatis-ya023180002411971257360001@news.euro.net>
Mosl Roland <founder@pege.org> wrote:
[...]
> For example, I started perl without any documentation
> and did not find out how to add 2 strings together.
[...]
> Search engines are wonderfull, when they have the
> right information :-).
>
> For example I did not know 8 month what a SSI is.
Most search engines are as good as the person querying it.
Almost every popular searchengine has advanced functions.
Ask a stupid question, get a stupid answer.
> Now try to ask infoseek
> "How can I call a program on the server from inside my html page"
> or some similar queries. You will find on top my page about SSI.
Yeah.
--
Toutatis
------------------------------
Date: Mon, 24 Nov 1997 05:19:29 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: How can I hide the Query string in the URL?
Message-Id: <34790cb7.191310840@woody.wcnet.org>
[original author automagically cc'd via e-mail]
On Sun, 23 Nov 1997 23:45:56 +0100, "Mosl Roland" <founder@pege.org>
wrote:
>I find it always very difficult to find information about
>perl on the web.
Really? You must be looking in all the wrong places.
http://www.perl.com/ is one heck of a place to start.
>Perl programers like always to be very confusing.
Be careful with such generalizations. They're rarely true.
>So what's about a project to find every question
>about perl answered by Altavista or infoseek.
As opposed to getting the answers into the Perl docs and the FAQ?
>For example, I started perl without any documentation
>and did not find out how to add 2 strings together.
Whose fault is that?
>When my project will be ready, You can ask infoseek
>"how can I add to strings together in perl"
>and infoseek will give You the right answer.
What if I ask "How does one concatenate scalars in Perl?" Will it work
then, too?
Do you plan on creating every reasonable way of phrasing a Perl
question and then indexing the resulting questions?
I'm a bit puzzled.
>Search engines are wonderfull, when they have the
>right information :-).
So are programmers.
>For example I did not know 8 month what a SSI is.
You never looked in web server documentation? Consulted any of the
FAQs which might have been related?
>Now try to ask infoseek
>"How can I call a program on the server from inside my html page"
>or some similar queries. You will find on top my page about SSI.
>Some month ago, I wanted to bring my words on the top of the
>search results. But now, the art is to make a page findable for
>persons not knowing the right word for something.
>For persons only having an idea what they search.
>
>Got the idea of my project?
Sort of.
>The idea is to design together many pages answering
>every question about perl in a way, that a beginer can
>understand it and find it easy by a search engine.
Okay.
>Most perl pages contain only examples, where an
>advanced perl programer wants to show every reader,
>that the reader is a idiot.
Huh? I don't suppose you can prove that, can you?
>How wants to work with me together in this project?
>Make perl a easy to learn language.
I believe that the documentation that ships with Perl, as well as the
O'Reilly Books already do that. Thousands of people have learned from
them...
Rather than begin a whole new effort, why not try and add to one of
the existing ones? If there are things missing from the Perl FAQ, why
not submit additions to the maintainer. If the information is unclear,
submit a re-written version.
Jeremy
--
Jeremy D. Zawodny jzawodn@wcnet.org
Web Server Administrator www@wcnet.org
Wood County Free Net (Ohio) http://www.wcnet.org/
------------------------------
Date: 24 Nov 1997 18:03:20 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: How do you export a variable from module?
Message-Id: <65cfh8$k7o$1@daily.bbnplanet.com>
Alexander Farber (eedalf@eed.ericsson.se) wrote:
: Hi,
: i am trying to write a simple module, and it works fine
: with functions, but i cant figure out, how do i also export
: a global variable. What i am trying to use is:
: package EED;
: require Exporter;
Being picky, you should say use Exporter.
: @ISA = Exporter;
You got the following line correct. How did you miss it for the previous one ?
If you ran this with perl -w it will tell you what's wrong.
: @EXPORT = qw(eed_p);
Jason Gloudon
------------------------------
Date: Mon, 24 Nov 1997 10:24:09 -0800
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: How to determine if a value is "readonly"?
Message-Id: <Pine.GSO.3.96.971124101859.24464H-100000@usertest.teleport.com>
On 24 Nov 1997, Toutatis wrote:
> For a function, I want to determine if the 1st element
> in @_ is readonly (hardcoded in the program) or passed
> as a variable.
It may be read only without being hardcoded in the program. Or, for that
matter, it may be a "variable" and yet be read only. I'm not sure what you
really want.
> Debug($thisvalue,$thatvalue);
> Debug(1,$thisvalue,$thatvalue);
Maybe you really want to determine the number of elements in the parameter
list? But it sounds as if you want to do this.
sub debug { do_debug(0,@_) }
sub debugF { do_debug(1,@_) }
debug($thisvalue,$thatvalue);
debugF($thisvalue,$thatvalue);
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 24 Nov 1997 18:25:08 GMT
From: Salve J Nilsen <devnull@nvg.org>
Subject: Re: How to: push (condition ? @this : @that),$value; (Bug?)
Message-Id: <65cgq4$bku$1@due.unit.no>
And then, Toutatis suddenly uttered...
> Salve J Nilsen <devnull@nvg.org> wrote:
> > what about....
> >
> > push(($condition ? @this : @that), $value);
> try it
I stand corrected! To be honest, what I tried wasn't THAT much
different. Here's what I did:
------------
#!/usr/bin/perl
my @this = qw(a b c d e f);
my @that = qw(1 2 3 4 5 6);
my $value = "foo";
# my $condition = 1;
## Doesn't work!
# push(($condition?@this:@that), $value);
# print "variable:\n this = @this\n that = @that\n";
push((1?@this:@that), $value);
print "scalar :\n this = @this\n that = @that\n";
push((true?@this:@that), $value);
print "sub :\n this = @this\n that = @that\n";
sub true { return 1; }
------------
I tried the 'scalar' version, and thought that the 'variable' version
also would work... Oh well.
Is this a bug?
(I'm running perl 5.004_02)
- Salve Nilsen
(email address in .sig)
--
#!/usr/local/bin/perl
$_ = 'Sometimes I have dreams, dreams where I wish my email address was
president@whitehouse.gov
but, alas - it is only...'; s/.*?ent/sjn/s; s/whi.*/pvv.org\n/s; print;
------------------------------
Date: Mon, 24 Nov 1997 10:38:13 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Stacy Hunter <synex@snx.com>
Subject: Re: Lock File
Message-Id: <Pine.GSO.3.96.971124103751.24464L-100000@usertest.teleport.com>
On Mon, 24 Nov 1997, Stacy Hunter wrote:
> cgi-lib
Use CGI.pm instead.
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Mon, 24 Nov 1997 11:43:05 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: maintain unique elements in an array? no duplicates?
Message-Id: <ebohlmanEK5F7t.4Dq@netcom.com>
Jon Turner (jt@cs.pdx.edu) wrote:
: Is it possible to maintain an array that will always have non-redundant
: elements in it? If a new element is to be added, it doesn't get added
: if there is already an identical element in the array. Suppose I wanted
: to keep an array of people's names that are being read from various
: files, I don't want a persons name duplicated in the list. So, Is
: there a method to prevent redundant entries? or a method to remove
: redundancies? I guess a 'set' datatype is what I'm thinking of.
As others have pointed out, a hash is the best way to do this if you're
not concerned about the order of the elements. If you have to preserve
order of insertion, you could look into tie'ing an array name to a
package that will implement dupe-elimination. Unfortunately, the support
for tie'ing arrays (as opposed to scalars and hashes) is still quite
limited. The easiest solution in that case might be to maintain both an
array *and* a hash; you would check the hash to see if a name existed and
if not, you'd insert the name into both the array and the hash.
------------------------------
Date: Mon, 24 Nov 1997 02:23:08 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: max size of cookie?
Message-Id: <34792B5A.6029@coos.dartmouth.edu>
kim slack wrote:
>
> How much data can you fit in a cookie? Geoff
Twenty-seven.
Chipmunk
------------------------------
Date: Sun, 23 Nov 1997 22:13:14 -0800
From: "Peter Rosser" <prosser@ewa.net>
Subject: Re: passing more than 1 variable in a href
Message-Id: <65b5vv$jg2@snews1.zippo.com>
--SNIP--
>I pick up the first variable in my script no problem using the following:
--CODE SNIPPED--
>I can't seem to pick up that 2 variable. What am I doing wrong?
>
When the string is passed to your script from the web, the entire string
following the "?" is passed as a single variable. If you want to get to it
using @ARGV (which I don't recommend, but more on that later) you will have
to @vars=split(/&/"@ARGV") it.
However... I would recommend using the $ENV{'QUERY_STRING'} vars set by the
web server. RTFM on that one...
Peter Rosser
prosser@ewa.net
------------------------------
Date: 24 Nov 1997 18:00:39 GMT
From: Zenin <zenin@best.com>
Subject: Re: referring to a hash in a package, proper scope
Message-Id: <880394578.856629@thrush.omix.com>
[ posted & mailed ]
John Dubchak <jdubchak@mb.sympatico.ca> wrote:
: I have a package called 'John' (for instance). I create the package with a
^^^^^^^ ^^^^^^^
You're creating an "object" from the "class" called "John" that is
defined in the "package" "John". Semantics is my life. :-)
: new() is defined as a sub-routine like so:
: sub new {
: my $type = @_;
: my $hash = {section => {key => value} };
: return bless %hash, $type;
: }
A couple problems. First you're putting this into the class "1" (or
higher) by accident. This is because you're calling @_ in scalar
context which returns the number of elements in the array, not the
actual elements. This should be written as:
my $class = shift;
By perl convention, $class is normally used, however you're $type
will work too, if you must.
Next problem. Where was %hash defined? FYI, it is NOT related
in anyway to $hash. You're return statement needs to be:
return bless $hash, $type;
Again however, since $hash is your object, perl convention also
normally used $self for this. I'd write this as:
sub new {
my $class = shift;
$class = ref $class || $class; ## allow $new = $obj->new to
## work as well.
my $self = {};
$self->{section} = { key => 'value' };
return bless $self, $class;
}
: So, when I want to invoke another function within this package, do I code a
: call like this (assuming function is "something")?
: $rc = $pkg_ref->something();
Yes. However, as an "object" you normally would just store the $rc
data inside the object, depending on what $rc was.
: If I wanted to populate the anonymous hash defined in new(), how is that
: done? I believe I can put values into the hash, but I cannot retrieve based
: on any supplied keys that "should" be in the hash.
Whenever you call a method you will always get your "object" passed
implicitly as the first element:
sub putSomething {
my $self = shift; ## Same $self we made in new()
my $key = shift;
my $value = shift;
$self->{section}{$key} = $value;
}
sub getSomething {
my $self = shift;
my $key = shift;
if (exists $self->{section}{$key}) {
return $self->{section}{$key};
} else {
return undef;
}
}
use John; ## Hehe, I love that line of code. :-)
my $john = new John;
$john->putSomething ('This', 'dung');
print $john->getSomething ('This');
Prints "dung".
Hope this helps!
--
-Zenin
zenin@best.com
------------------------------
Date: 24 Nov 1997 13:53:48 -0000
From: deas@dont.spam.me.rrz.uni-hamburg.de (Andreas Steffan)
Subject: Searchengine-project: Volunteers wanted
Message-Id: <65c0tc$157$1@mortimer.deas.org>
Looking for information can be quite a pain.
I got the idea to create ONE Searchtool to find (almost) any
information (local and remote).
This is the idea:
All local information (manpages, infopages, newsspool, mail, html,
plaintext, wwwcache ...) are indexed and queried by glimpse
(http://glimpse.cs.arizona.edu/).
A HTML-Page serves as the frontend. It should contain ONE textfield
for the searchstring, a few checkboxes for the indexes and external
search-engines to be queried and certain options.
The local queries should be performed via CGI (Perl, mod_perl, apache)
There is a perl-module (http://www.isi.edu/lsam/tools/WWW_SEARCH/)
which should be quite usable to perform remote queries
(Alta-Vista, Hot-Bot, Deja-news, ftpsearch ...)
Regarding infopages, manpages and HTML, I found that there are quite
good starting points (info2www, vh-man2html, webglimpse).
I already started development, and a few components are usable now.
If you want to help me, please send me a mail.
Suggestions are of course welcome.
--
Andreas
Remove the 'dont.spam.me.' from my adress when replying via mail.
+-----------------------------------------------------------------+
| Andreas Steffan email: deas@rrz.uni-hamburg.de|
| Hamburg, Germany |
+-----------------------------------------------------------------+
finger p25a003@server2.rrz.uni-hamburg.de for PGP-public-key.
------------------------------
Date: Sun, 23 Nov 1997 15:54:21 +0000
From: Nick Kew <nick@webthing.com>
Subject: Re: security questions
Message-Id: <347851AD.1BB2CF93@webthing.com>
Laurel Shimer wrote:
> I have been working on setting up (multiple levels) of security
You might try <URL:http://www.webthing.com/tutorials/login.html>
> Am I'm barking up the wrong tree?
Looks like it. WWW security (is A authorised to see document X or
run script Y?) is orthogonal to system security (keeping the crackers
out from your system). I get the impression you're looking for the
first but have been reading about the second.
Nick Kew.
------------------------------
Date: Mon, 24 Nov 1997 18:04:32 GMT
From: Guy Doucet <gdoucet@ait.acl.ca>
Subject: SIZE OF PROGRAM. Are there limits??
Message-Id: <3479C121.3B53DF55@ait.acl.ca>
Just wondering if there is a maximum size that a Perl script can be.
Currently I have a Perl-5 script of 50kB size. It is running on a Novell
Web Server. I am not having any problems, but wondering if I can add
very much to the script.
Thanks for any info.
Guy Doucet
------------------------------
Date: Sun, 23 Nov 1997 23:18:53 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Sorting an array
Message-Id: <ebohlmanEK4GrH.1Av@netcom.com>
Mark Mielke (markm@nortel.ca) wrote:
: This is a bad answer for reasons of efficiency. sort { } will do this
: compare many times. (i forget the theory... is it n * log(n)?) Anyways...
: If you have 1000+ you WILL notice the difference between using the
: transform described in earlier posts including mine. (namely they are
: exponentially faster? :-) )
Quicksort's general behavior is n * log(n), where log is really log base
2, so sorting a 1000-element array would usually take about 10,000
comparisons.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 1366
**************************************