[10764] in Perl-Users-Digest
Perl-Users Digest, Issue: 4365 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 5 18:07:19 1998
Date: Sat, 5 Dec 98 15: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 Sat, 5 Dec 1998 Volume: 8 Number: 4365
Today's topics:
Re: "insecure" variables? (123) (Andrew M. Langmead)
Re: clearing the screen in perl? (Andrew M. Langmead)
Re: clearing the screen in perl? (Mark-Jason Dominus)
Comparing STRING variables in an IF statement (Cybernetic Bear)
Re: Comparing STRING variables in an IF statement <jhi@alpha.hut.fi>
Re: Comparing STRING variables in an IF statement (Ronald J Kimball)
Re: How to disallow fields to input puncuations excepts (Tad McClellan)
Re: Is it possible to run a web server on Win95? (Woofy)
Is Tcl/Tk better than Perl ? <fichou@clubintnet.fr>
Re: Is Tcl/Tk better than Perl ? <rick.delaney@shaw.wave.ca>
Re: Is Tcl/Tk better than Perl ? (Juergen Heinzl)
Location of a file modifiable by a CGI Script <rvaliani@ricochet.net>
Re: Location of a file modifiable by a CGI Script <rootbeer@teleport.com>
Re: Location of a file modifiable by a CGI Script <gellyfish@btinternet.com>
Re: Missing warning on '23foo'++ (Tad McClellan)
Re: Need help editing a script <gellyfish@btinternet.com>
Offline Database viewer <darrensweeney@eswap.co.uk>
Perl Cookbook, Tom and Nathan, Thanks! <postmaster@castleamber.com>
Re: Please Help where can i download perl - (Woofy)
Re: Problem with seek..... <rainman@dustyhoffman.com>
Some questions <markrame@hotmail.com>
Re: Some questions (Sean McAfee)
Re: Some questions <rick.delaney@shaw.wave.ca>
Re: Some questions <rick.delaney@shaw.wave.ca>
Re: Some questions (Juergen Heinzl)
Re: Some questions <rick.delaney@shaw.wave.ca>
Re: sub refs not working <rootbeer@teleport.com>
Re: Tool to reverse engineer perl code <samuel.patton@wichita.boeing.com>
Re: trouble passing value of variable <rootbeer@teleport.com>
using GDBM_File <ajou2@hitel.net>
Re: wantarray() question. <r28629@email.sps.mot.com>
Re: wantarray() question. <rick.delaney@shaw.wave.ca>
Re: When does CLOSE not FLUSH? (Andrew M. Langmead)
Re: Win32::OLE newbie (Erland Sommarskog)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 5 Dec 1998 16:44:57 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: "insecure" variables? (123)
Message-Id: <F3I3ux.Bq8@world.std.com>
Nick Halloway <snowe@rain.org> writes:
>The environment variables are set in a shell script which calls the
>perl script. Is that insecure in reality, rather than in the eyes
>of perl? if not, can perl be called with tainting turned off?
Tainting can't be turned off, but it is fairly simple to use the
recipe given in the perlsec man page to untaint data before you use
it.
Given loose enough un-tainting patterns you can get an environment
very close to having tainting off. (except for file globbing) But
since you are untainting anyway, you would probably be best off using
a pattern that close describes the data that you are expecting.
--
Andrew Langmead
------------------------------
Date: Sat, 5 Dec 1998 17:14:14 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: clearing the screen in perl?
Message-Id: <F3I57r.IH@world.std.com>
syran@shell1.ncal.verio.com (Jim Matzdorff) writes:
>Is there a way to clear the screen in perl? Such as "clear" in a shell? I
>can't backtick it and run clear, since that clears the shell's screen, not the current
>screen.
Unfortunately, I can't understand what you mean by the "shell's
screen" vs. "current screen". A process has "controlling tty", which
traditionally was attached to a terminal. When one process spawns a
child process, by default, it inherits it "controlling tty". Spawning
a process to send the proper terminal commands to tell the teminal to
clear, should be dealing with the same tty.
But there is one thing about your message that may explain your
troubles. You say "backtick" and a more generic "run". When you run a
program with the backtick operator, you redirect its standard output
to a pipe that perl reads to pass back to your program. The "clear"
command sends the screen clearing escape sequences to standard output.
So
print `clear`;
works but is somewhat wasteful.
system('clear');
will works too.
But as someone else said, the Term::Cap module allow you to clear the
screen without a separate process.
--
Andrew Langmead
------------------------------
Date: 5 Dec 1998 15:31:21 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: clearing the screen in perl?
Message-Id: <74c56p$hf0$1@monet.op.net>
In article <74a10r$mem$1@shell1.ncal.verio.com>,
Jim Matzdorff <syran@shell1.ncal.verio.com> wrote:
>So, I have looked around at perl.com, couldn't find an answer.
print "\n" x 100;
:-)
------------------------------
Date: Sat, 05 Dec 1998 15:22:41 GMT
From: cybear_x[nospam]@geocities.com (Cybernetic Bear)
Subject: Comparing STRING variables in an IF statement
Message-Id: <36694dda.240284461@news.webhart.net>
I am trying to write a PERL script that will print a response to the
screen based on a user-inputed name. I have a list of names in a
standard array. I only want to print the response that corresponds to
the user-inputed name and none of the others.
I am using Netscape Fasttrak server on a Netware 4.11 box.
The code I am trying to work with is just a tool for my learning PERL.
What it is supposed to do is only print the name to the screen if it
matches the user inputed name.
my code for this is as follows:
require("cgilib.pl");
&ReadParse;
# print &PrintHeader;
$username = ("$in{NAME}" || "DAVE");
#fill array
$name[0]='DAVE';
$name[1]='STEVE';
for ( $i=0 ; $i<=2 ; $i++ ) {
if ($name[$1] == $username){print("$name[$i]");}
}
I call the script from my browser using this syntax:
http://server.name/perl/play.pl?NAME=DAVE
Logically, at least in my mind, this should work, but it consistantly
prints out both names. I am new with coding in PERL. Any help would be
greatly appreciated
Thanks,
Dave
------------------------------
Date: 05 Dec 1998 18:15:08 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: Comparing STRING variables in an IF statement
Message-Id: <oeeiufqva43.fsf@alpha.hut.fi>
> if ($name[$1] == $username){print("$name[$i]");}
> }
>
> I call the script from my browser using this syntax:
> http://server.name/perl/play.pl?NAME=DAVE
>
> Logically, at least in my mind, this should work, but it consistantly
It works beautifully. Zero is equal to zero.
> prints out both names. I am new with coding in PERL. Any help would be
> greatly appreciated
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Sat, 5 Dec 1998 13:30:05 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Comparing STRING variables in an IF statement
Message-Id: <1djkej5.17fk9zf1ntyiquN@bos-ip-1-99.ziplink.net>
[posted and mailed]
<cybear_x> wrote:
> if ($name[$1] == $username){print("$name[$i]");}
To compare numbers in Perl, use ==, !=, <, >, <=, >=, and <=>.
To compare strings in Perl, use eq, ne, lt, gt, le, ge, and cmp.
perldoc perlop
--
_ / ' _ / - aka - rjk@linguist.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: Sat, 5 Dec 1998 12:09:53 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to disallow fields to input puncuations excepts
Message-Id: <htsb47.v11.ln@metronet.com>
[ This has nothing to do with servers or linux.
Please do not make off-topic posts.
Followups set.
]
targetmailinfo@yahoo.com wrote:
: Dear perl and cgi experts,
: If I want to disallow my visitors to input all puncuations and blank
: space EXCEPT HYPHEN ( - ) and A to Z , 0 to 9 at my form's field "company"
^^^^^^
^^^^^^
: how can I do that??
: The following will disallow all puncuations , blank spaces and hyphen as
: well (only allow a-z and 0-9).
: How to enable the hypens , a-z , 0-9 but disable blank space and other
^^^
^^^
: puncuations at the company??
So which is it?
a-z or A-Z?
I'll assume it's both:
if ($form{company} !~ /^[a-zA-Z0-9-]+$/)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 05 Dec 1998 22:10:34 GMT
From: chrisWoofy@epix.net (Woofy)
Subject: Re: Is it possible to run a web server on Win95?
Message-Id: <3669aed7.25079558@newsserver.epix.net>
I think there are 2 kinds of PWS.
One that is included with Frontpage and one that is called, "Microsoft
Personal Web Server" that you can download (I think) from the
Microsoft site.
There are differences between the 2.
Can't remember what those differences are.
That's what happends when you keep shiftng from VB to Access to HTML
to Javascript to C to Corel Draw to Acrobat to Frontpage and now to
Perl.
C
------------------------------
Date: Sat, 5 Dec 1998 22:54:26 +0100
From: "Patrick Fichou" <fichou@clubintnet.fr>
Subject: Is Tcl/Tk better than Perl ?
Message-Id: <74ca51$h7r$1@front3.grolier.fr>
Hi to you all,
I woul *really* know what you think of Tcl/Tk ! I mean, do I have to learn
Perl instead of Tcl ? Is Perl somewhat out of date ?
Is it a correct choice I do if I choose Tcl ? ...and so on !
Thank you !
Patrick
------------------------------
Date: Sat, 05 Dec 1998 22:25:27 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Is Tcl/Tk better than Perl ?
Message-Id: <3669B48E.75D8E769@shaw.wave.ca>
[posted & mailed]
Patrick Fichou wrote:
>
> Hi to you all,
>
> I woul *really* know what you think of Tcl/Tk ! I mean, do I have to
> learn Perl instead of Tcl ? Is Perl somewhat out of date ?
> Is it a correct choice I do if I choose Tcl ? ...and so on !
Do you really think you will get a useful answer from this newsgroup
(where the contributors are generally Perl enthusiasts)? Besides, your
question is a FAQ:
How does Perl compare with other languages like Java, Python, REXX,
Scheme, or Tcl?
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sat, 05 Dec 1998 22:40:29 GMT
From: juergen@monocerus.demon.co.uk (Juergen Heinzl)
Subject: Re: Is Tcl/Tk better than Perl ?
Message-Id: <slrn76jdia.fr.juergen@monocerus.demon.co.uk>
In article <74ca51$h7r$1@front3.grolier.fr>, Patrick Fichou wrote:
[....]
>I woul *really* know what you think of Tcl/Tk ! I mean, do I have to learn
>Perl instead of Tcl ? Is Perl somewhat out of date ?
... out of WHAT !!?? ... well, now after having taken care of your life not
becoming too long ... it depends (as usual).
>Is it a correct choice I do if I choose Tcl ? ...and so on !
Yes ... if it solves your problems. I like Perl more and it helps me, aside
from other languages, to get things done. Take a look on both (some beginners
books for example). Tcl/Tk is probably more often used if you want some
kind of GUI too. while Perl is very often used for CGI programming (although
much much more can be done with it).
Much more to say about both languages but you really must make up your mind
yourself, since both are powerful tools.
Bye, Juergen
--
\ Real name : J|rgen Heinzl \ no flames /
\ EMail Private : juergen@monocerus.demon.co.uk \ send money instead /
\ Phone Private : +44 181-332 0750 \ /
------------------------------
Date: Sat, 05 Dec 1998 18:49:27 +0000
From: Rahim Valiani <rvaliani@ricochet.net>
Subject: Location of a file modifiable by a CGI Script
Message-Id: <36698037.6C5B06CD@ricochet.net>
I was wondering.... Where would one typically keep a file that may be
modified by a perl script?
in the ../cgi-bin? In ../html ? What kind of permissions would one set
for such a file?
Thanks...
P.S.
I would appreciate it if you could CC: the response to
rvaliani@ricochet.net
------------------------------
Date: Sat, 05 Dec 1998 20:37:02 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Location of a file modifiable by a CGI Script
Message-Id: <Pine.GSO.4.02A.9812051235510.16394-100000@user2.teleport.com>
On Sat, 5 Dec 1998, Rahim Valiani wrote:
> I was wondering.... Where would one typically keep a file that may be
> modified by a perl script?
The same place you would keep a file that may be modified by a C program.
But if you're asking about CGI programs, the docs, FAQs, and newsgroups
about CGI programming may help. Or you could ask your system
administrator. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 5 Dec 1998 21:43:05 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Location of a file modifiable by a CGI Script
Message-Id: <74c9d9$192$1@gellyfish.btinternet.com>
On Sat, 05 Dec 1998 18:49:27 +0000 Rahim Valiani <rvaliani@ricochet.net> wrote:
> I was wondering.... Where would one typically keep a file that may be
> modified by a perl script?
> in the ../cgi-bin? In ../html ? What kind of permissions would one set
> for such a file?
> Thanks...
>
For myself I would, if the namespace of the server allow, place files
outside of the HTTP servers reach - lest someone should discover tha name
of such file. Of course if ones server is correctly configured then a file
in some cgi-bin directory should be inaccesible *to the average web user* -
but then again I could introduce you to people who really wouldnt care
that you had done that. Permissions of course should be set so that only
the owner of the HTTP process can read it.
Anyhow I think that you would properly be better asking this kind of question
in a group concerned with CGI or server configuration.
> P.S.
> I would appreciate it if you could CC: the response to
> rvaliani@ricochet.net
>
Oh bollocks I didnt read that before I started this reply .. ;-}
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 5 Dec 1998 12:17:31 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Missing warning on '23foo'++
Message-Id: <rbtb47.v11.ln@metronet.com>
Ilya Zakharevich (ilya@math.ohio-state.edu) wrote:
: [A complimentary Cc of this posting was sent to Daniel Grisinger
: <dgris@moiraine.dimensional.com>],
: who wrote in article <m3af1354dh.fsf@moiraine.dimensional.com>:
: > The auto-increment operator has a little extra builtin magic to
: > it. If you increment a variable that is numeric, or that has
: ....
: > This is one of those silly things that useful sometimes (in fact I
: > actually have a lot of code that uses this), but that is somewhat
: > surprising. I'd guess that it belongs on your list of perl gotchas
: > and Ilya's list of things that use pedantic will fix.
: What should it fix?
: >perl -wle "$a='23foo'; $a++; print $a"
: 24
: Should produce a warning without any additional pragma.
"Learning Perl" (2nd ed) says on pp39-40:
..., so " 123.45fred" (with a leading space) converts to
123.45 with nary a warning*
...
* Unless you turn on the -w option...
So did perl used to warn about this and doesn't now?
Or is this errata in the Llama?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Dec 1998 22:11:11 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Need help editing a script
Message-Id: <74cb1v$19c$1@gellyfish.btinternet.com>
On Thu, 03 Dec 1998 23:18:03 GMT Martien Verbruggen <mgjv@comdyn.com.au> wrote:
> Have you been eating suspicious looking mushrooms?
>
Oh my word, you havent lurking on the London.pm mailing list have you ;-}
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 5 Dec 1998 10:27:59 -0800
From: "Darren" <darrensweeney@eswap.co.uk>
Subject: Offline Database viewer
Message-Id: <74btvg$sbp@dfw-ixnews10.ix.netcom.com>
Hi all
I am using SDBM databases on my site, which I know are FTPable.
Does anyone know of a viewer for this type of database which allow me to
view/modify it offline and then FTP it back up to the web?
Thanks
Darren
------------------------------
Date: 5 Dec 1998 22:11:38 GMT
From: "John Bokma" <postmaster@castleamber.com>
Subject: Perl Cookbook, Tom and Nathan, Thanks!
Message-Id: <01be209b$ea2d2740$02521e0a@tschai>
Thanks for writing *the* companion to "Programming Perl".
I've only browsed the book, but am already convinced that this
is a *must have* for every Perl programmer!
I used the "first" edition of Programming Perl a lot (besides the
2nd edition) because it has some nice code snippets. No need
anymore, PC has many more (and updated to Perl 5) snippets.
And last, but not least, Thanks to O'Reilly for being one of the
best publishers.
John
--
------------------------------------------------------------------
C A S T L E A M B E R Software Development (Java/Perl/C/CGI)
http://www.castleamber.com/ john@castleamber.com
http://www.caiw.nl/~jbokma/
http://www.binaries.org/ Guide to Program Binaries and Pictures
------------------------------
Date: Sat, 05 Dec 1998 22:13:25 GMT
From: chrisWoofy@epix.net (Woofy)
Subject: Re: Please Help where can i download perl -
Message-Id: <3669aff2.25362545@newsserver.epix.net>
On Tue, 24 Nov 1998 01:19:20 GMT, alastair@calliope.demon.co.uk
(Alastair) wrote:
>>>MarcoPolo <nic_azzuri@compuserve.com> wrote:
>>>>I am new to perl and am trying to locate it to install onto a sparc 10
>>>>any answers would be excellent
>>>>
>>>>Please Help where can i download perl
>>>
>>>Many years of internet experience have honed my search skills to a remarkable
>>>level and I suggest trying ;
>>>
>>>http://www.perl.com
>>>or
>>>http://www.perl.org
>>>
>>>Who'd have thought?
>>>
>>>--
>>>
>>>Alastair
As in Alastair Sim?
You know, Scrooge.
>>>work : alastair@psoft.co.uk
>>>home : alastair@calliope.demon.co.uk
------------------------------
Date: Sun, 6 Dec 1998 06:45:28 +1100
From: "bravo" <rainman@dustyhoffman.com>
Subject: Re: Problem with seek.....
Message-Id: <74c7qr$ea9$1@reader1.reader.news.ozemail.net>
Bart Lateur wrote in message <36713d3f.3370033@news.skynet.be>...
>bravo wrote:
>
>>Everything's working fun but the problem is my stuff gets appended to the
>>bottom(as normal).
>>
>>What I want to do is append it to the top so the most recent info is on
top.
>>
>>I am using the following code in my script.
>>
>> open(OUTF,">>data.txt");
>> flock(OUTF, 8) or die "cannot unlock file: $!";
>> seek(OUTF,0,0);
>>
>>But it still appends to the bottom.....
>
>Good thing that it does that, or you would be overwriting what was in
>the file.
>
>You cretae a new file, print to that, and copy everything that was in
>there after that. Finally, copy the new file over the old one.
>
>But that would be slow. Especially if the file gets large, and you do
>this a lot.
>
>So, my advice: don't do it. Keep it as it is. Only when you need a
>report, let the reporting software reverse the order of the lines in the
>file. Something along these lines:
>
> open(IN,'logfile');
> @line = reverse <IN>;
>
> Bart.
OK cool..... ill give that a go.
------------------------------
Date: Sat, 5 Dec 1998 21:43:44 +0100
From: "Martin" <markrame@hotmail.com>
Subject: Some questions
Message-Id: <74c5ue$92d$1@reader3.wxs.nl>
Hi,
I have three questions. I am rather new at this, so please forgive my
ignorance.
1): If I have an array, say @lines, and I wish to do a search and replace on
each element, then is there a better way to do this than like this?
for (0..$#lines) {
@lines[$_] =~ s/$something/$something_else/gi;
}
2): Assuming the existence if @lines again, is there a way to insert an
element into the array? I was thinking of shifting, doing a pop, and then
push two elements at the right location, but that seems rather gross.
3): What do the regexps (?g) and (?i) do? I read something about them here,
but could not make head or tails out of it.
Any light people could shed on these issues would be highly appreciated.
Martin
------------------------------
Date: Sat, 05 Dec 1998 21:13:48 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Some questions
Message-Id: <gmha2.201$4w2.1064616@news.itd.umich.edu>
In article <74c5ue$92d$1@reader3.wxs.nl>, Martin <markrame@hotmail.com> wrote:
>I have three questions. I am rather new at this, so please forgive my
>ignorance.
>1): If I have an array, say @lines, and I wish to do a search and replace on
>each element, then is there a better way to do this than like this?
>for (0..$#lines) {
> @lines[$_] =~ s/$something/$something_else/gi;
>}
TMTOWTDI, of course, but I think this is better:
foreach $line (@lines) {
$line =~ s/$something/$something_else/gi;
}
If you're using Perl 5.005 you can shorten it still further:
s/$something/$something_else/gi foreach @lines;
>2): Assuming the existence if @lines again, is there a way to insert an
>element into the array? I was thinking of shifting, doing a pop, and then
>push two elements at the right location, but that seems rather gross.
Look up the "splice" function in the perlfunc manpage.
>3): What do the regexps (?g) and (?i) do? I read something about them here,
>but could not make head or tails out of it.
For (?i), check the perlre manpage; search for "embedded pattern-match
modifiers". I must confess that I'm stumped about (?g); I can't find any
reference to it in the perl docs (even after grepping them all with the
pattern '(?[^)]*g'), yet Perl compiles the pattern OK, while rejecting
other unknown ones like /(?a)/. I even downloaded Devel::RegExp to try to
examine the pattern more closely, but I encountered many heinous-looking
errors when I tried to compile it. Any gurus want to speak up?
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Sat, 05 Dec 1998 21:31:02 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Some questions
Message-Id: <3669A7BD.A194EC1F@shaw.wave.ca>
[posted & mailed]
Martin wrote:
>
> Hi,
>
> I have three questions. I am rather new at this, so please forgive my
> ignorance.
>
> 1): If I have an array, say @lines, and I wish to do a search and
> replace on each element, then is there a better way to do this than
> like this?
>
> for (0..$#lines) {
> @lines[$_] =~ s/$something/$something_else/gi;
> }
>
for (@lines) { s/$something/$something_else/gi }
perlldoc perlsyn
Also, in your example you would be better to use $lines[$_], not
@lines[$_]. Perl would have told you as much if you invoked it as
perl -w
which you should always do.
perldoc perldata
perldoc perlrun
> 2): Assuming the existence if @lines again, is there a way to insert
> an element into the array? I was thinking of shifting, doing a pop,
> and then push two elements at the right location, but that seems
> rather gross.
You want to use the splice() function documented in perlfunc.
perldoc -f splice
> 3): What do the regexps (?g) and (?i) do? I read something about them
> here, but could not make head or tails out of it.
>
(?g) is something that you shouldn't be using. (?i) is documented in
perlre under (?imsx) but basically it means you can do this:
s/(?i)something/something else/;
instead of this:
s/something/something else/i;
The first is useful if you want to use the same statement to match
different patterns which may or may not be case sensitive.
$string = "CASE\n";
for $pattern ('(?i)case', 'case') {
if ($string =~ /$pattern/) {
print "/$pattern/ matches $string";
}
else {
print "/$pattern/ does not match $string";
}
}
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sat, 05 Dec 1998 21:53:48 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Some questions
Message-Id: <3669AD14.2D29495@shaw.wave.ca>
Sean McAfee wrote:
>
> I must confess that I'm stumped about (?g); I can't find any
> reference to it in the perl docs (even after grepping them all with
> the pattern '(?[^)]*g'), yet Perl compiles the pattern OK, while
> rejecting other unknown ones like /(?a)/.
See the thread, "Bind won't take variables" in dejanews for the most
recent discussion of this. Here is the code I posted in that thread
(WARNING: (?g) is a bug, not a feature, hence its absence from the
documentation):
my $find = 'ABC';
my $replace = 'xyz';
for my $case ('i', "") {
for my $global ('g', "") {
$_ = 'abcabcABCabcABC';
s/(?$case$global)$find/$replace/;
print "$_\n";
}
}
which gives:
xyzxyzxyzxyzxyz
xyzabcABCabcABC
abcabcxyzabcxyz
abcabcxyzabcABC
Weird, eh?
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sat, 05 Dec 1998 22:10:31 GMT
From: juergen@monocerus.demon.co.uk (Juergen Heinzl)
Subject: Re: Some questions
Message-Id: <slrn76jarl.af.juergen@monocerus.demon.co.uk>
In article <74c5ue$92d$1@reader3.wxs.nl>, Martin wrote:
[...]
>I have three questions. I am rather new at this, so please forgive my
>ignorance.
>
>1): If I have an array, say @lines, and I wish to do a search and replace on
>each element, then is there a better way to do this than like this?
>
>for (0..$#lines) {
> @lines[$_] =~ s/$something/$something_else/gi;
>}
You might use map ...
map {
s/$_/blablabla/;
} @lines;
...
>2): Assuming the existence if @lines again, is there a way to insert an
>element into the array? I was thinking of shifting, doing a pop, and then
>push two elements at the right location, but that seems rather gross.
How about ...
@lines = (@lines[0 .. 2], ' been here, done that ', @lines[3 .. $#lines]);
...
>
>3): What do the regexps (?g) and (?i) do? I read something about them here,
>but could not make head or tails out of it.
Can't tell.
Hope it helps a bit,
Juergen
--
\ Real name : J|rgen Heinzl \ no flames /
\ EMail Private : juergen@monocerus.demon.co.uk \ send money instead /
\ Phone Private : +44 181-332 0750 \ /
------------------------------
Date: Sat, 05 Dec 1998 22:47:56 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Some questions
Message-Id: <3669B9D1.7E194393@shaw.wave.ca>
[posted & mailed]
Juergen Heinzl wrote:
>
> In article <74c5ue$92d$1@reader3.wxs.nl>, Martin wrote:
> [...]
> >for (0..$#lines) {
> > @lines[$_] =~ s/$something/$something_else/gi;
> >}
> You might use map ...
> map {
> s/$_/blablabla/;
> } @lines;
Except then you would be using the yucky 'map in a void context'. Plus
I don't think your code is doing what you think it is. What you have
written is equivalent to:
map { $_ = 'blablabla' } @lines;
although it's probably slower.
>
> >2): Assuming the existence if @lines again, is there a way to insert
> >an element into the array?
> How about ...
> @lines = (@lines[0 .. 2],' been here, done that ',@lines[3..$#lines]);
This is for sure slower than splice():
#!/usr/local/bin/perl -w
use strict;
use Benchmark;
timethese(30000, {
SPLICE => sub {
my @lines = qw(I think I've too many times);
splice(@lines, 3, 0, ' been here, done that ');
},
SLICES => sub {
my @lines = qw(I think I've too many times);
@lines = (
@lines[0 .. 2],
' been here, done that ',
@lines[3 .. $#lines]
);
},
CTRL => sub {
my @lines = qw(I think I've too many times);
},
});
__END__
Benchmark: timing 30000 iterations of CTRL, SLICES, SPLICE...
CTRL: 3 secs ( 2.65 usr 0.00 sys = 2.65 cpu)
SLICES: 6 secs ( 5.60 usr 0.00 sys = 5.60 cpu)
SPLICE: 3 secs ( 2.86 usr 0.00 sys = 2.86 cpu)
YMMV, but I doubt that you'll ever get SLICES to run as fast as SPLICE.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sat, 05 Dec 1998 19:34:41 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: sub refs not working
Message-Id: <Pine.GSO.4.02A.9812051128290.16394-100000@user2.teleport.com>
On Tue, 1 Dec 1998, BenJamin Prater wrote:
> my %handler = (
> 'main' => {
> 'date' => sub { date_decode(time, $_[1]->{id}) },
> 'loop' => \&loop1
> },
> 'loop1' => {
> 'heading' => sub { $_[3] },
> 'loop2' => \&loop2
> },
> 'loop2' => {
> 'url' => sub { $data_ref->{ $_[3]->[0] }[ $_[3]->[1] ]{url} },
> 'atitle' => sub { $data_ref->{ $_[3]->[0] }[ $_[3]->[1] ]{atitle} },
> }
> );
> However, and this is the problem, if it encounters the tag <loop1> it
> should call the sub 'loop1' as specified in the original hash.
Was that really what was specified in the hash? Maybe I'm not reading your
message carefully enough, but it doesn't seem that way to me.
Have you tried stepping through your code in the debugger?
> I imagined that => sub { } and => \&sub were the same things when
> called, but perhaps I'm mistaken.
If you think you're mistaken, you're wrong. :-D
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sat, 5 Dec 1998 16:34:32 GMT
From: "Sam Patton" <samuel.patton@wichita.boeing.com>
Subject: Re: Tool to reverse engineer perl code
Message-Id: <F3I3DH.1Js@news.boeing.com>
Sounds like a great op for some enterprising individual or group.
Steve Walsh wrote in message <744g8p$7e7$1@bcarh8ab.ca.nortel.com>...
>Has anyone on this list come across a reverse engineering tool that will
>take perl code as input and generate data diagrams, process diagrams
>(flowcharts), etc. I know that there are lots of software tools available
>that do this for Java, C++, etc but I would like to find one that I can use
>with perl or is customizable to allow me to add perl in as a supported
>language. If you know of such a tool please email with details. Thank you.
>
>Steve Walsh
>swalsh@americasm01.nt.com
>
>
>
------------------------------
Date: Sat, 05 Dec 1998 19:24:19 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: trouble passing value of variable
Message-Id: <Pine.GSO.4.02A.9812051123230.16394-100000@user2.teleport.com>
On Tue, 1 Dec 1998, Dale Haines wrote:
> I am not having any luck passing the value of a variable from my html
> document to a Perl script using JavaScript.
It sounds as if you want your browser or server to do this. Perhaps the
docs, FAQs, and newsgroups about browsers or servers could help you. Good
luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 06 Dec 1998 05:25:21 +0900
From: pds <ajou2@hitel.net>
Subject: using GDBM_File
Message-Id: <366996B0.E55B737B@hitel.net>
Hi~
I need using GDBM_File and try man gdbm, serch mane, cpan, etc... but I
can't find perpect guide.
I have write two source, and run on UNIX, follow source...
source 1
#!/bin/perl
use GDBM_File;
use Fcntl;
tie %h,GDBM_File, "hashed",O_RDWR|O_CREAT,0640;
$h{"apple"} = "orange";
print "exists \n" if $h{"apple"};
untie %h;
source2
#!/bin/perl -w
use GDBM_File;
use Fcntl;
tie %h,GDBM_File,"hashed",O_RDWR,0644;
print $h{apple};
untie %h;
When source1 run, named 'hashed' file is made in same directory and
'exists' is printed.
But, when source1 run, NO change, NO print, NO error message.
What can I do for solving this problem? I want make gdbm data, save gdbm
data and
print saved gdbm data.
I'll wait your NICE answer! :)
------------------------------
Date: Sat, 05 Dec 1998 13:58:52 -0500
From: Tk Soh <r28629@email.sps.mot.com>
To: Uri Guttman <uri@fastengines.com>
Subject: Re: wantarray() question.
Message-Id: <3669826A.5D66AE84@email.sps.mot.com>
[posted to c.l.p.m and copy emailed]
Uri Guttman wrote:
> you have to be careful to return an actual @array variable to get that
> behavior. if you return a list you get the standard scalar evaluation of
> a list which is the last element of the list in a scalar context.
>
> sub array {
>
> my @foo = qw( a b c ) ;
> my @foo2 = qw( w x y z ) ;
>
> return( @foo, @foo2 ) ;
> }
>
> $cnt = array() ;
> @a = array() ;
> print "array cnt = $cnt a = @a\n";
>
> prints:
>
> array cnt = 4 a = a b c w x y z
>
> which may not be what you expect. it is the length of the last element,
> foo2!
Hmm, do I smell conflict with the document?
perlsub:
...
If you return one or more arrays and/or hashes,
these will be flattened together into one large
indistinguishable list.
...
How should I interprete this line above?
-TK
------------------------------
Date: Sat, 05 Dec 1998 22:19:40 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: wantarray() question.
Message-Id: <3669B32A.196F185A@shaw.wave.ca>
Tk Soh wrote:
>
> [posted to c.l.p.m and copy emailed]
>
> Uri Guttman wrote:
> >
> > sub array {
> >
> > my @foo = qw( a b c ) ;
> > my @foo2 = qw( w x y z ) ;
> >
> > return( @foo, @foo2 ) ;
> > }
> >
> > $cnt = array() ;
> > @a = array() ;
> > print "array cnt = $cnt a = @a\n";
> >
> > prints:
> >
> > array cnt = 4 a = a b c w x y z
> >
> > which may not be what you expect. it is the length of the last
> > element, foo2!
>
> Hmm, do I smell conflict with the document?
> perlsub:
> ...
> If you return one or more arrays and/or hashes,
> these will be flattened together into one large
> indistinguishable list.
> ...
>
> How should I interprete this line above?
With the silent, "in a list context. Actually it just returns the same
thing as the expression would without the return()." :-)
There's no reason to not use wantarray(), but now I'm curious--is there
is a nice, clean way to code this:
wantarray() ? (@foo, @foo2) : $foo2[-1];
that doesn't use wantarray()? All I could come up with was:
(@foo, @foo2)[0..(@foo+@foo2-1)];
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sat, 5 Dec 1998 16:58:57 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: When does CLOSE not FLUSH?
Message-Id: <F3I4I9.H7s@world.std.com>
Russ Allbery <rra@stanford.edu> writes:
>> Is there maybe some maximum number of bytes allowed? What is that
>> maximum, or is it implementation dependent?
>I'm pretty sure one call to write(2) is atomic with respect to other
>writes to the same file and that this is handled in the file system I/O
>code in the kernel.
I thought there was a limit for the maximum size of a write, but right
now I can only find one for writes to pipes. (PIPE_BUF in limits.h)
The write(2) man page on this system here specifies a few differences
between writes to pipes and fifos and the non-atomicity of writes
greater than PIPE_BUF is one of them.
--
Andrew Langmead
------------------------------
Date: Sat, 05 Dec 1998 22:11:18 GMT
From: sommar@algonet.se (Erland Sommarskog)
Subject: Re: Win32::OLE newbie
Message-Id: <74cb27$mf5$2@pepsi.tninet.se>
Marquis de Carvdawg (keydet89@yahoo.com) skriver:
>What is the purpose of Win32::OLE programming? What
>capability does the module give a Perl programmer? Yes,
>I am new to Win32 Perl...and I have seen the examples, but
>I just don't see why you would want to use the module for
>programming on the Win32 platform...
If there is one single module beyond the standard library that you
would ever use on Win32, it's Win32::OLE. For Christ's sake, that
gives you access to a wide range of libraries on NT without the
need to writing a single line of XS code.
Just open the nearest Object Browser and look at the list of objects.
All that is yours for free thanks to Win32::OLE. You have data in
an Excel spreadsheet that you want to process in Perl? Win32::OLE
is your friend. Myself, I had the need to get data from Microsoft
Visual SourceSafe, a version control system, and there is an OLE
interface to VSS, so Win32::OLE became my friend.
--
Erland Sommarskog, Stockholm, sommar@algonet.se
This could have been my two cents worth, but alas the Swedish
government has decided that I am not to have any cents.
------------------------------
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 4365
**************************************