[7682] in Perl-Users-Digest
Perl-Users Digest, Issue: 1308 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 12 20:16:23 1997
Date: Wed, 12 Nov 97 17:00:23 -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 Wed, 12 Nov 1997 Volume: 8 Number: 1308
Today's topics:
Re: Block comments in Perl? (brian d foy)
Re: Calling a Perl script from a Perl script CAN YOU HE (brian d foy)
Re: Calling a Perl script from a Perl script CAN YOU HE (brian d foy)
Re: carriage returns (brian d foy)
Catching System Error from command line execution <jdubois@keane.com>
Re: Catching System Error from command line execution (brian d foy)
combining 2 images(gif or jpg)? <skang@granax.dot.com>
Re: COMPILED PERL CODE???POSSIBLE? (brian d foy)
Re: File name problem when using PERL to send binary fi (brian d foy)
Re: How do I create a random number with Perl? <seay@hol.fr>
Re: How to create a timeout for connect() ? <markm@nortel.ca>
Re: How to create a timeout for connect() ? <jhi@alpha.hut.fi>
htpasswd help! PLEASE! (Me)
Re: Initiating Write from a CGI (brian d foy)
Re: Newbie Question (brian d foy)
Re: Open, File-handle problems. <markm@nortel.ca>
Re: Open, File-handle problems. (brian d foy)
passing C structure to syscall() function in perl??? (Salman Mughal)
Re: Passing variables (brian d foy)
Q: Wierd argument passing, bug? (Henry Gabryjelski)
Re: Q: Wierd argument passing, bug? (brian d foy)
Re: Recursive Search and Replace question <seay@hol.fr>
Re: Tainting Question (Faust Gertz)
Re: Tainting Question (brian d foy)
Re: type casting (brian d foy)
What's wrong w/this picture? <quetzl@earthlink.net>
win32 Perl and NFS (Matthew H. Gerlach)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 Nov 1997 17:49:20 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Block comments in Perl?
Message-Id: <comdog-ya02408000R1211971749200001@news.panix.com>
In article <64crls$ncl1@quest.lmtas.lmco.com>, turnerj@cliffy.lmtas.lmco.com (Jim Turner ) wrote:
> I just have to add my 2 cents worth also:
this has no sense:
> goto RESUME;
>Type anything you want here, this will
>all be commented out.
>RESUME:
no - don't try that. Perl already has built in constructs for this
sort of thing. why use a method that is not only ugly, but actually
produces extra instructions? comments should not take up processor
time or confuse a code reviewer.
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 12 Nov 1997 17:16:58 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Calling a Perl script from a Perl script CAN YOU HELP??
Message-Id: <comdog-ya02408000R1211971716580001@news.panix.com>
In article <34689917.48130AD8@ait.acl.ca>, gdoucet@ait.acl.ca wrote:
>Either it comes back with the
>message "Contains no data" or that the script worked. There may be an
>error log somewhere but ...
but what?
>Out of curiousity, where do the others run their perl scripts that they
>can actually see Perl errors coming back to their screen?
i use the command line, but i also check the error log.
>Anyway, I was wondering if there was a way to call a Perl CGI script
>from another Perl CGI script. Currently I'm having the first script
>write an HTML page with javascript which is instructed to call the next
>Perl Script.
it sounds like you simply need a reference to the next CGI script in
the HTML. was there some other way that you needed to call the
second CGI script?
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
$RTFM_post{'brian d foy'}++;
------------------------------
Date: Wed, 12 Nov 1997 17:21:58 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Calling a Perl script from a Perl script CAN YOU HELP??
Message-Id: <comdog-ya02408000R1211971721580001@news.panix.com>
In article <slrn66hq4d.qg9.wkc@amanda.dorsai.org>, wkc@dorsai.org (Wesley) wrote:
>Just a little off topic but I bet there will be a couple people just post
>"READ THE FAQ!" without any pointers to where or which FAQ to read.
>Sometimes, it's true. Read the FAQ and the answers are there. I found
>this CGI.pm thing in the FAQ, too.
>Before I reponse to this question, I tried to look for the CGI.pm FAQ's
>address so that I can point the person who asked this question to read
>more about it. I couldn't find the FAQ even I read it before. So,
>whoever just want to post "READ THE FAQ!", please also consider there are
>MANY FAQs out there. At least try to point to which FAQ to read.
read the relevant one, or all of them :)
well, you could always bookmark the CGI Meta FAQ which has references
to every FAQ you mentioned. personally, i got tired of typing the
references to everything to which i referred.
you might also consider looking at the periodic postings or using a
search engine, not to mention that site about perl that Tom C. does,
although i can't remember the address.
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 12 Nov 1997 17:54:41 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: carriage returns
Message-Id: <comdog-ya02408000R1211971754410001@news.panix.com>
In article <64cqt0$3de$5@info.uah.edu>, gbacon@adtran.com (Greg Bacon) wrote:
>In article <3469E823.67CA@cpdmfg.cig.mot.com>,
> Mark Chaffee <chaffee@cpdmfg.cig.mot.com> writes:
>: I have a variable that contains a text string with carriage returns. Is
>: there a way to strip them out?
>:
>: $var = "This is^Ma text string^Mwith unwanted^Mcarriage returns."
>
> $var =~ s/\s+/ /g;
but that leaves the carriage returns since they don't
necessarily match that pattern.
if you want to strip carriage returns, just say so in the pattern:
# the \c lets us match control characters
s/ \cM / /xg; #eXtended and Global
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 12 Nov 1997 17:23:17 -0500
From: Joseph DuBois <jdubois@keane.com>
Subject: Catching System Error from command line execution
Message-Id: <346A2C55.A5F@keane.com>
Well met,
I am trying to write a perl interface to SCCS (running on solaris)
and what to check when a file is already checked out. If
I run it from the command line
`sccs edit filename`
I get back an error message, When I run it from within a perl
program I am unable to catch the error message. How can I call
the above command from within perl to catch the system error.
Note:
@errors = `sccs edit filename`;
does not catch the errors as the system sends it to STDERR.
Thanks
--
-------------------------------------------------------
Joseph DuBois (Internet/Intranet Specialist)
mailto:jdubois@keane.com (Work) http://www.keane.com/
------------------------------
Date: Wed, 12 Nov 1997 19:19:59 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Catching System Error from command line execution
Message-Id: <comdog-ya02408000R1211971919590001@news.panix.com>
In article <346A2C55.A5F@keane.com>, jdubois@keane.com wrote:
> I am trying to write a perl interface to SCCS (running on solaris)
>and what to check when a file is already checked out. If
>I run it from the command line
>`sccs edit filename`
>I get back an error message, When I run it from within a perl
>program I am unable to catch the error message. How can I call
>the above command from within perl to catch the system error.
there is a FAQ [1]:
How can I capture STDERR from an external command?
good luck :)
[1]
<URL:http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq8.html>
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
$RTFM_post{'brian d foy'}++;
------------------------------
Date: Wed, 12 Nov 1997 18:52:28 -0600
From: shaolin <skang@granax.dot.com>
Subject: combining 2 images(gif or jpg)?
Message-Id: <346A4F4C.921D8FDA@granax.dot.com>
does anyone know where can i get a perl program that can combine 2 images into
1?
any simple example?
any pointer to any url is appreciated.
-----------------------------------------------------------------------------
Kang Soon Lai skang_at_granax.com | "If there is any religion that would
http://www.granax.com/~skang/ | cope with modern scientific needs
(913) 385 5481 | it would be Buddhism."
Software Engineer | --Albert Einstein
------------------------------------------------------------------------------
`When you say "I wrote a program that crashed Windows", people just stare at
you blankly and say "Hey, I got those with the system, *for free*".'
--Linus Torvalds
------------------------------
Date: Wed, 12 Nov 1997 17:30:24 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: COMPILED PERL CODE???POSSIBLE?
Message-Id: <comdog-ya02408000R1211971730240001@news.panix.com>
In article <64an9u$298$1@goanna.cs.rmit.edu.au>, exalter@yallara.cs.rmit.edu.au (Hafeezhussein Hatimabana ) wrote:
>Is is possible it write perl scripts scuh that your code is not visible?
depends on your definition of visibility. compiling source doesn't
necessarily mean that your code is invisible. however, your next
question's answer answers this question:
>I would also like to know where the FAOS for this news group and anyother perl rnews groups are kept,
you can check the periodic postings to this newsgroup,
<URL:http://www.perl.com>, or use a search engine. TMTOWTDI :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Virgina law mandates that you consume alcohol in this area.
------------------------------
Date: Wed, 12 Nov 1997 17:04:39 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: File name problem when using PERL to send binary files over CGI
Message-Id: <comdog-ya02408000R1211971704390001@news.panix.com>
In article <01bcef17$73e36560$511e09a8@weixiao>, "David" <mysun@mbox2.singnet.com.sg> wrote:
>I want to use a perl script to send different kinds of files, such as
>*.exe,*.txt,*.doc etc, to a browser and this browser can open or save it.
>The following is my perl scripts:
>Print <<EOF;
>Content-Type: application/x-unknown
>Content-Tranfer-Encoding: binary
>But when I use a browser to access this script, the browser asks me to save
>file as script name Send.???,not actual file name(aa.exe, bb.doc or
>cc.txt).
DejaNews [1] is your friend. search in the
comp.infosystems.www.authoring.cgi group for lots of good answers.
good luck :)
[1]
<URL:http://www.dejanews.com/>
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
i've answered this question too many times i think.
------------------------------
Date: Wed, 12 Nov 1997 23:40:07 +0100
From: Douglas Seay <seay@hol.fr>
Subject: Re: How do I create a random number with Perl?
Message-Id: <346A3047.6FDF276F@hol.fr>
shiva mantri wrote:
>
> have to use srand and rand functions.
>
> #!where_perl_is -w
> srand;print int(rand 10);
True enough, but srand() isn't needed with modern perl implementations.
This is an excerpt from the entry on rand() in perlfunc
Returns a random fractional number between 0 and the value of EXPR.
(EXPR should be positive.) If EXPR is omitted, returns a value between
0 and 1. Automatically calls srand() unless srand() has already been
called. See also srand().
- doug
------------------------------
Date: 12 Nov 1997 17:15:19 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: How to create a timeout for connect() ?
Message-Id: <lq1g1p1yd1k.fsf@bmers2e5.nortel.ca>
Frederic GILLES <gilles@tls-cats.sps.mot.com> writes:
> When the connection to a server with the function connect() doesn't
> work, it doesn't give me an answer.
> I want to define a timeout alarm to stop the connect() and to continue
> the program?
> How can I do that?
Here's a nice and simple way... assuming you don't need the SIGALRM
for something else :-)
local $SIG{ALRM} = sub { die "Timeout.\n" };
alarm(10);
eval {
connect(...) || die "connect failed: $!\n";
};
alarm(0);
if ($@ =~ /^Timeout.$/) {
# Stuff to do if connect timed out...
} elsif ($@) {
# Some other error occurred... propagate it up...
die;
}
NOTE: The above code is... untested... :-)
hope this helps,
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: 13 Nov 1997 01:54:36 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: How to create a timeout for connect() ?
Message-Id: <oeesot1brcz.fsf@alpha.hut.fi>
Jozsef Hollosi <hollosi@sbcm.com> writes:
> Third answer: you can set the socket to non-blocking mode:
> $F_SETFL = 4; # lazy, you should use config here
> $O_NDELAY = 4; # lazy, you should use config here
You mean "use Fcntl;". See perldoc Fcntl.
> fcntl($filedesc, $F_SETFL, $O_NDELAY);
> and then you can monitor it with regular select()
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Wed, 12 Nov 1997 23:00:26 GMT
From: Me@home.sleeping (Me)
Subject: htpasswd help! PLEASE!
Message-Id: <64dcbk$a0f$1@goblin.uunet.ca>
I'm currently trying to figure out how the heck
I can re-create or at least emulate the
htpasswd command in perl.
essentially I want to be able to configure
an .access file, without having to telnet
into the server everytime.
Does anyone know exactly how servers
salt their crypt of the password?
I know the comman basically loogks like
$encrypted_password = crypt ($unencrypted_password,$salt);
but what is the proper salt sequence?
Is the unencrypted password a combination of the
unencrypted password and login?
I just caan't figure it out.
HELP!
anyone?
please e-mail me at
hector@csgm.com
------------------------------
Date: Wed, 12 Nov 1997 17:59:18 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Initiating Write from a CGI
Message-Id: <comdog-ya02408000R1211971759180001@news.panix.com>
In article <34696740.41D2@mediacity.com.sg>, patrick@mediacity.com.sg wrote:
>I can write a new file using a command-line driven script with the
>following:
>
>#test file
>print "Content-Type: text/html\n\n";
>print "printing file...";
>open(FILE, ">afile.txt");
>print FILE "some text";
>close(FILE);
>
>However, when I try to run this as a CGI it will not write!
>Why?
you did not check the return value of open or try to trap its error.
use CGI::Carp qw(fatalsToBrowser);
open FILE, $file or die "$!\n";
then your script will tell you what is wrong.
good luck :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 12 Nov 1997 17:34:43 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Newbie Question
Message-Id: <comdog-ya02408000R1211971734430001@news.panix.com>
In article <01bcef71$adb82280$2d4678c7@warrensm>, "Warren Smith" <warren5@earthling.net> wrote:
>I am creating a script for the net on a foreign server. I don't know the
>physical path of my directory. How do I get the actual path of the script I
>am running?
perhaps there is a solution that doesn't require you to know the path, or
one that allows you to configure it without modifying the script?
also, depending on the problem and the situation, something like $0 might
be useful.
good luck :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 12 Nov 1997 17:03:57 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: Open, File-handle problems.
Message-Id: <lq1iutxydki.fsf@bmers2e5.nortel.ca>
kajhoej@kom.auc.dk (Thomas Kajhoej) writes:
> I'm running perl 5.003 on a pc running linux (redhat 4.3).
> I'm trying to create a perlprogram that starts the program "passwd".
> I want to be able to change my password from within a perl program.
> I do the following:
> ...
> open PW, "|passwd";
> print PW "my_current_password\n";
> print PW "my_new_password\n";
> print PW "my_new_password\n";
> close PW
> ...
> But it does not work !?
> I found out that when i open the "passwd" command it asks for my curren
> password, and thats fine, but when i type in my current_password
> "print PW "my_current_password\n"
> it does not prompt me for my new password. When i close PW then it just says
> that my new password is too short!
> What am i doing wrong?
Perhaps /bin/passwd is totally ignoring STDIN and STDOUT. /bin/passwd could
be opening /dev/tty to communicate to your terminal to "ensure" that it is
speaking to a person. The way to get around this would be to use an expect
like script that opens a pty to communicate with the program. expect is
a tcl extension. perl has a similar interface using chat2.pl in the standard
distribution, i'm note sure if a new perl5 type module exists. Anybody?
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: Wed, 12 Nov 1997 19:25:05 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Open, File-handle problems.
Message-Id: <comdog-ya02408000R1211971925050001@news.panix.com>
In article <lq1iutxydki.fsf@bmers2e5.nortel.ca>, Mark Mielke <markm@nortel.ca> wrote:
> I'm trying to create a perlprogram that starts the program "passwd".
> I want to be able to change my password from within a perl program.
> I do the following:
> ...
> open PW, "|passwd";
> print PW "my_current_password\n";
> print PW "my_new_password\n";
> print PW "my_new_password\n";
> close PW
remember that passwd also prints to STDOUT (its own that is), so
you need to do something about that. you might want to look into
using IPC::Open3.
you might also consider that Perl is not the hammer for every screw.
good luck :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
if this is leading towards the web, turn back.
------------------------------
Date: 13 Nov 1997 00:26:28 GMT
From: msm6@Ra.MsState.Edu (Salman Mughal)
Subject: passing C structure to syscall() function in perl???
Message-Id: <64dhfk$a4i$1@NNTP.MsState.Edu>
Hi there!
I am trying to call setitmer() routine from a perl script:
syscall(&SYS_setitmer, ......);
C prototype looks like this:
int setitimer(int which, const struct itimerval *value,
struct itimerval *ovalue);
Passing integer is not a problem ofcourse but it's the itmerval
structure which has me baffled. The typedef for it looks:
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
How do I pass a pointer to itimerval structure in syscall() ?
Thanks for any help!
Regards
--
Salman Mughal System Administrator/Webmaster Aerospace Engineering MSU
Email: msm6@Ra.MsState.Edu WWW: http://www2.msstate.edu/~msm6
------------------------------
Date: Wed, 12 Nov 1997 18:08:33 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Passing variables
Message-Id: <comdog-ya02408000R1211971808330001@news.panix.com>
In article <64agqu$g5k$2@ausnews.austin.ibm.com>, thartman@nospam.dontuse.this_email_addr (Todd "Waxahachiefortudinouslyexportitionismistically" Hartman) wrote:
>Doug (dougw@dbis.ns.ca) wrote:
>: I am designing an html form which asks for data from the user. I will then
>: e-mail the results to my address. However, before I e-mail the data I want
>: to give the user another page to 'confirm' they want to mail this
>: infomation. I am using the cgi-lib.pl library and need to pass the
>: variables from one cgi to another. Any ideas......
>
>On the confirm page, you could put all the data in modifiable input objects,
>like textfields, selection boxes or whatever they were in originally, or
>you could pass them through
> <input type=hidden name="var1" value="var1_value">
when you do this, be very careful about what that value is! embedded
metacharacters like " and > can cause lots of problems. you'll need to
encode your data apart from the CGI then decode it after the CGI to
handle such a thing.
the best solution is probably the CGI.pm multi-stage form support though.
good luck :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 12 Nov 1997 22:46:13 GMT
From: henryg@ernie.WPI.EDU (Henry Gabryjelski)
Subject: Q: Wierd argument passing, bug?
Message-Id: <64dbjl$v6o$1@bigboote.WPI.EDU>
Okay, I have a question that needs more than JAPH to understand...
I am passing in a localized variable (my'd) to a subroutine twice and
using the autoincrement (++) on one or both of them. I have included
a simple script that shows the non-obvious behavior (esp. case 6!)
that I am trying to understand.
my $key = 'lab1'; # prefix to any below statement
TestArgs( $key, $key ); # Case 0
TestArgs( $key++, $key ); # Case 1
TestArgs( $key, $key++ ); # Case 2
TestArgs( ++$key, $key ); # Case 3
TestArgs( $key, ++$key ); # Case 4
TestArgs( ++$key, ++$key ); # Case 5
TestArgs( $key++, $key++ ); # Case 6
Try guessing the values the subroutine gets before running the code.
Take case 1 and case 2: how are arguments evaluated when passed?
Case 3, case 4, and case 5 I can understand, potentially.
But what is going on in case 6?!
Help? Tom? Larry?
Henry Gabryjelski
Waiting to see a discussion of this one...
--- SNIP! <save as badperl.pl> ---
#!/usr/local/bin/perl -w
use diagnostics;
$| = 1;
sub TestArgs($$) {
my $arg1 = shift or die "Need two args to TestArgs";
my $arg2 = shift or die "Need two args to TestArgs";
print "*\t\$arg1 = '$arg1'\n";
print "*\t\$arg2 = '$arg2'\n";
}
my $key0 = 'lab1'; my $key1 = 'lab1'; my $key2 = 'lab1';
my $key3 = 'lab1'; my $key4 = 'lab1'; my $key5 = 'lab1';
my $key6 = 'lab1';
print "Testing Case 0: ( \$key0 , \$key0 )\n";
TestArgs( $key0, $key0 );
print "Testing Case 1: ( \$key1++, \$key1 )\n";
TestArgs( $key1++, $key1 );
print "Testing Case 2: ( \$key2 , \$key2++ )\n";
TestArgs( $key2, $key2++ );
print "Testing Case 3: ( ++\$key3 , \$key3 )\n";
TestArgs( ++$key3, $key3 );
print "Testing Case 4: ( \$key4 , ++\$key4 )\n";
TestArgs( $key4, ++$key4 );
print "Testing Case 5: ( ++\$key5 , ++\$key5 )\n";
TestArgs( ++$key5, ++$key5 );
print "Testing Case 6: ( \$key6++, \$key6++ )\n";
TestArgs( $key6++, $key6++ );
------------------------------
Date: Wed, 12 Nov 1997 19:16:50 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Q: Wierd argument passing, bug?
Message-Id: <comdog-ya02408000R1211971916500001@news.panix.com>
In article <64dbjl$v6o$1@bigboote.WPI.EDU>, henryg@ernie.WPI.EDU (Henry Gabryjelski) wrote:
>Okay, I have a question that needs more than JAPH to understand...
how about JANYPH?
>I am passing in a localized variable (my'd) to a subroutine twice and
>using the autoincrement (++) on one or both of them. I have included
>a simple script that shows the non-obvious behavior (esp. case 6!)
>that I am trying to understand.
>
>my $key = 'lab1'; # prefix to any below statement
>TestArgs( $key, $key ); # Case 0
>TestArgs( $key++, $key ); # Case 1
>TestArgs( $key, $key++ ); # Case 2
>TestArgs( ++$key, $key ); # Case 3
>TestArgs( $key, ++$key ); # Case 4
>TestArgs( ++$key, ++$key ); # Case 5
>TestArgs( $key++, $key++ ); # Case 6
let me start by saying that i think it is very poor style to this
sort of thing. something like
$value_1 = $key++;
$value_2 = $key;
function( $value_1, $value_2 );
has much clearer behaviour and will be much easier for a code
reviewer to understand.
with that said, i don't know what rules you are following to parse
these in your mind, but they do as i expect since i follow this
path of thought (which might be unrelated to the actual perl
internals):
* any proceesing that needs to be done on any argument
before its value can be used happens before any values
are added to the argument list.
* as soon as the argument is reduced to a value, that value
is added to the argument list (in the proper position).
* processing occurs left to right.
with these rules:
* all pre-increments and pre-decrements are done before
any values are added to the argument list.
* post-increments and post-decrements can occur as soon as
the value is used (as normal) - meaning that as soon as
the value is added to the argument list, it can be
modified.
so if we go through your test cases (see the same code ultra
simplified at the end of the message).
0. no processing. both values immediately go into the
list.
1. $key is added to the list and then post incremented. it
has a value immediately because the post-increment is post
:) then the next argument is $key, which is now the
incremented value.
2. $key is post-incremented in the second argument, which
had an immediate value of zero. the first argument is then
the incremented value.
3. $key is pre-incremented, so the value of the first
argument is the incremented version. same for the second
argument.
4. same as 3.
5. $key is pre incremented, but there is still processing
to do, and $key is pre incremented again. then the values
in $key are added to the argument list.
6. $key has a value of zero immediately since it is a post
increment. that value is added to the argument list. the
second argument has a value of 1 immediately, and then is
post incremented. the value of $key afterwards is 2.
however, let's go insane:
#!/usr/bin/perl -w
my $k = 0;
print $k--, $k++, ++$k, --$k, "\n";
__END__
0-100
does this follow the rules which i developed? sure it does.
a. $k is pre-incremented, but there is still some pre-
processing to do, and $k is pre-decremented. now the
last two arguments can be assigned values - both of
which are zero since they undo each other.
b. the first argument now has an immediate value of 0, and
is post-decremented.
c. the second argument has an immediate value of -1 which
was the result of the previous post-decrement.
so now i have something even more evil for you to consider. try
these two return statements :)
#!/usr/bin/perl
$k = 0;
print $k, &deep_reach(\$k), "\n";
sub deep_reach
{
my $ref = shift;
#return ++$$ref;
return $$ref++;
}
__END__
>Help? Tom? Larry?
they don't live here anymore.
*****
here's a simplified version of your test code:
#!/usr/bin/perl -w
my ($k0,$k1,$k2,$k3,$k4,$k5,$k6) = qw(0 0 0 0 0 0 0);
print $k0, $k0 , "\n";
print $k1++, $k1 , "\n";
print $k2, $k2++ , "\n";
print ++$k3, $k3 , "\n";
print $k4, ++$k4 , "\n";
print ++$k5, ++$k5 , "\n";
print $k6++, $k6++ , "\n";
__END__
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
this should look good on that OCR thingy
------------------------------
Date: Wed, 12 Nov 1997 23:17:53 +0100
From: Douglas Seay <seay@hol.fr>
To: Drake Cleary <killbell@peterboro.net>
Subject: Re: Recursive Search and Replace question
Message-Id: <346A2B11.1A39B00A@hol.fr>
[posted and mailed]
Drake Cleary wrote:
>
> Is there any way to make the following command
> exclude one or more specific directories???
>
> find . -name '*.html' | xargs perl -pi -e
> 's/searchtext/replacetext/gm;'
Use File::Find.pm instead of /usr/bin/find. This gives you all the
flexibility you could want.
- doug
------------------------------
Date: Wed, 12 Nov 1997 22:29:40 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Tainting Question
Message-Id: <346a2d8b.584566@news.wwa.com>
On Wed, 12 Nov 1997 14:51:23 -0600, vwilding@mib.nbs.gov (Vince
Wilding) wrote:
>I have a CGI-script that needs to allow users to generate a file in a
>world-writable directory and write to it. When I run with -T, it
>complains, I would suppose, about the world-writable directory. Is there
>a way around this, i.e. WRITING to a world writable directory and still
>pass the taint check?
Yes.
HTH
Faust Gertz
Philosopher at Large
Sting once asked Elvis Costello, "Why don't you stop singing in that
fake American accent?" Costello replied, "I will, as soon as you stop
using the fake Jamaican one."
------------------------------
Date: Wed, 12 Nov 1997 17:45:34 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Tainting Question
Message-Id: <comdog-ya02408000R1211971745340001@news.panix.com>
In article <879366984.32217@dejanews.com>, vwilding@mib.nbs.gov (Vince Wilding) wrote:
>I have a CGI-script that needs to allow users to generate a file in a
>world-writable directory and write to it. When I run with -T, it
>complains, I would suppose, about the world-writable directory. Is there
>a way around this, i.e. WRITING to a world writable directory and still
>pass the taint check?
what does it really complain about (there is no need to guess).
make sure that you are using -w and checking the error log. when you
find about what -T is complaining, post the specific message and perhaps
someone can help :)
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 12 Nov 1997 18:04:58 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: type casting
Message-Id: <comdog-ya02408000R1211971804580001@news.panix.com>
In article <64acnp$1noq$1@news.gate.net>, dsiebert@gate.net (David Siebert) wrote:
>I type case a variable to be a byte in perl?
Perl doesn't have byte type (remember that Perl is also loosely typed).
perhaps you could explain what you need to do...
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 12 Nov 1997 16:01:05 -0800
From: Kenneth McNamara <quetzl@earthlink.net>
Subject: What's wrong w/this picture?
Message-Id: <346A4341.5E7B@earthlink.net>
Am I way off or what?
I want to open the @ARGV directory, put the files in @files and print
out the first three lines of each file. (My assignment is to use define
to include files named 0, but I haven't got to that yet).
I beseech the Perl Gods to enlighten me.
(Start Mangle-O-Script)
=======================================================
#!/usr/local/bin/perl5.00401
$dirname = shift;
opendir(DIR, $dirname);
@files = readdir(DIR);
closedir(DIR);
while (@files) {
$files = chomp;
print $files;
open(FILENAME, $files) || die "No way, Jose! because: $!";
@lines = <FILENAME>
print $lines[0..2], "\n";
close(FILENAME);
}
========================================================
(End Mangle-O-Script)
--
Kenneth McNamara Quetzl Internet Construction (213)221-4661
webmaster@quetzl.com -----HTML Writers Guild-----
http://www.quetzl.com ---Internet Developer's Association---
------------------------------
Date: Wed, 12 Nov 1997 23:43:35 GMT
From: gerlach@netcom.com (Matthew H. Gerlach)
Subject: win32 Perl and NFS
Message-Id: <gerlachEJK4Kn.92M@netcom.com>
Hi,
We are using Activeware's perl 5.003_07 under Windoze 95. We are having
problems making perl scripts read files that NFS mounted. The open()
fails with the error, "Not enough space". We are using FTP's NFS client
software.
Has anyone had luck reading NFS mounted files from perl scripts under
win95? Which perl and which NFS?
Matthew
------------------------------
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 1308
**************************************