[7925] in Perl-Users-Digest
Perl-Users Digest, Issue: 1550 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 30 06:07:41 1997
Date: Tue, 30 Dec 97 03:00:24 -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, 30 Dec 1997 Volume: 8 Number: 1550
Today's topics:
Re: 100.90 NOT 100.90000000000000568 HELP (William R. Ward)
[Q ] What is wrong with @INC ???? Help please! (Augusto Cardoso)
Re: Bug: 30 chars of perl uses 269MB! <a@b.c.d>
Re: Bug: 30 chars of perl uses 269MB! (brian d foy)
Re: CGI: system "cat... (brian d foy)
Re: chomp ($&) to remove specific \n <ebohlman@netcom.com>
Re: chomp ($&) to remove specific \n <joseph@5sigma.com>
Re: Compilation error with Format <robm@transmeta.com>
Re: Date parsing (William R. Ward)
Re: directory tree <joseph@5sigma.com>
Re: extract using reg. expr <smills@lewiston.com>
Re: Fast Suggestions for this string manipulation probl (William R. Ward)
Re: Finding the TITLE to a HTML page <joseph@5sigma.com>
Re: How do I pass objects from Perl to Javascript? (William R. Ward)
Re: How to check files exists and if it does then? (William R. Ward)
Re: Newbie frustration (William R. Ward)
Re: Newbie frustration <joseph@5sigma.com>
Passing short int arrays between Perl and C <robm@transmeta.com>
Re: PERL URL-Encoding (brian d foy)
Re: Starting a Daemon in a CGI script (William R. Ward)
Tech writer lifts burden from programmers <tdsjms@ix.netcom.com>
UNINITIALIZED VALUE at TIE (%HASH.... <vidals@etica-entertainment.com>
Re: Wanna get the Week Day for a specified date (William R. Ward)
Re: Which language pays most 17457 -- C++ vs. Java? <gdrumm@ix.netcom.com>
Re: Which language pays most? Smalltalk, not C++ nor Ja <pats@acm.org>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 Dec 1997 19:31:14 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: 100.90 NOT 100.90000000000000568 HELP
Message-Id: <waasorbpkvx.fsf@ese.UCSC.EDU>
Craig <design@kiwi.net> writes:
> Sometimes when I make a calculation with Perl, it will do funny things
> with the numbers. It will make a long decimal.
>
> I tried the int() function, but that's no good, because I need the two
> decimals (money value)
>
> I tried multiplying by 100, then int(), and then dividing by 100. But
> that doesn't solve it.
>
> Does anyone know a function, or something, that will return my decimal
> number "100.90000000000000568" back to "100.90" without using the printf
> command ?
If you want to round to the hundredths use this:
my $rounded = int (( $orig * 100 ) + .5 ) / 100;
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Mon, 29 Dec 1997 22:34:31 GMT
From: cardoso.a@mail.telepac.pt (Augusto Cardoso)
Subject: [Q ] What is wrong with @INC ???? Help please!
Message-Id: <34a81abe.263310@news>
when I try to run Perl programs I get a message stating that PM files
can not be found.
@INC is displayed and it refers to the right LIB...
Here is the error message:
Can't locate Pod/Text.pm in @INC <@INC contains:
c:/perl/lib/os2/5.00455 c:/perl/lib c:/perl/lib/site_perl/os2
c:/perl/lib/site_perl .> at c:\perl\bin/pod2text.cmd line 6.
File Text.pm is located in c:\perl\lib
Would appreciate any good suggestions
Thanks
------------------------------
Date: 30 Dec 1997 00:09:07 -0500
From: Myles Barrett Williams <a@b.c.d>
Subject: Re: Bug: 30 chars of perl uses 269MB!
Message-Id: <lcbtxze7t8.fsf@duncan.cs.utk.edu>
[E-mail address in signature]
nick@zeta.org.au (Nick Andrew) writes:
> While playing with embedding quotes in strings I hit a combination which
> causes Pel 5.003 to run out of memory.
> I shortened my program to 30 characters. It only tries to mmap 269 megs
> now, but at least it is instructive:
>
> $i='(\\'x\\''
This is not a perl bug, merely a piece of code with undesirable
effects. You're taking the two-character string '(\\' [a parenthesis
followed by a single backslash] and repeating it \\'' times. \\'' is
a reference to a reference to the constant string ''. In an integer
context, it will evaluate as a machine address and will vary from
system to system.
It just happens that on my Linux box, the code
printf "%d\n", \\'';
produces 134653096, so I would expect an allocation of twice that, or
269M. I think that solves the mystery. BTW the correct way to escape
single quotes in a single-quote string is \', not \\'
------------------------------
Date: Tue, 30 Dec 1997 05:50:02 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Bug: 30 chars of perl uses 269MB!
Message-Id: <68aj7t$i74@mtinsc05.worldnet.att.net>
In article <689a6o$ros$1@gidora.kralizec.net.au>, nick@zeta.org.au (Nick Andrew) wrote:
> While playing with embedding quotes in strings I hit a combination which
> causes Pel 5.003 to run out of memory. In fact an strace showed it trying
> to mmap() 1.2 gigs.
sounds like a good excuse to upgrade :)
> I shortened my program to 30 characters. It only tries to mmap 269 megs
> now, but at least it is instructive:
>
> #!/usr/bin/perl
> $i='(\\'x\\''
hmmm. what were you *trying* do? let's expand that last expression:
$i = '(\\' x \\''
a literal string followed by the x operater followed by some characters.
in this case, the following characters looks like a double reference to
an empty string. evaluated in a scalar context this gives some large
number. thus, the x operator juxtaposes the first string a large
number of times, which takes up a lot of memory.
not a bug, just more than enough rope with which to hang yourself. :)
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Tue, 30 Dec 1997 05:53:25 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: CGI: system "cat...
Message-Id: <68aje8$i74@mtinsc05.worldnet.att.net>
In article <Pine.OSF.3.96.971229151337.8406D-100000@becker1.u.washington.edu>, "B. Bell" <maximill@u.washington.edu> wrote:
> i want to include a file in my cgi output. I'm trying to use the system
> function call to just 'cat' the file.
> I suspect there's a far simpler solution?, but can anybody tell me why
> this doesn't work:
avoid system calls when possible. simply open the file yourself. :)
but for the answer to your question, and many others, consult the
Perl FAQ, which can be found through <URL:http://www.perl.com>.
good luck :)
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Tue, 30 Dec 1997 04:00:33 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: chomp ($&) to remove specific \n
Message-Id: <ebohlmanELzHsx.4JI@netcom.com>
Joe Marler <joema @nospam.microsoft.com> wrote:
: I tried this:
: s/matchpattern.*\n/chomp($&)/egi
: However chomp() returns the no. of characters removed, not
: the string minus \n, so that won't work. I tried chop(), but
: got an error saying "modification of a read-only value attempted".
: I ultimately used something like this, which worked but seems
: unwieldy:
: m/matchpattern.*\n/i;
: $matchedstring = $&;
: chomp($matchedstring);
: s/matchpattern.*\n/$matchedstring/gi;
: print;
It's best to avoid using $& if you can; using it greatly slows down *all*
regex matching in your script. Fortunately, there's a simple way to do
what you want:
s/(matchpattern.*)\n/$1/i;
if $_ contains only one newline. If it contains more than one newline,
use the g and s modifiers as well and put a ? after the *.
This makes uses of the $n facility for remembering matched portions of a
string; you can find out more about it by reading perlre.
------------------------------
Date: Tue, 30 Dec 1997 00:50:57 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: chomp ($&) to remove specific \n
Message-Id: <34A8A7CA.5C29C17C@5sigma.com>
Geez, and I thought chomp returned the character chomp-ed.
$& is read-only. You canna chomp 'er, cap'n, she'll fly apart!
-joseph
Joe Marler wrote:
>
> I'm using Perl 5.001 on Win32. I need to strip out selected \n
> characters from a text file using inplace editing, where the \n is
> preceded by a specific match pattern.
>
> I tried this:
>
> s/matchpattern.*\n/chomp($&)/egi
>
> However chomp() returns the no. of characters removed, not
> the string minus \n, so that won't work. I tried chop(), but
> got an error saying "modification of a read-only value attempted".
------------------------------
Date: Mon, 29 Dec 1997 23:32:35 -0800
From: Rob Maniatis <robm@transmeta.com>
To: Randy <randx@imagin.net>
Subject: Re: Compilation error with Format
Message-Id: <34A8A393.4874@transmeta.com>
Sorry this comes a bit late....I'm not sure what editor you use but if
it's emacs you can add:
;;Offer to put a newline after last line in file
(setq require-final-newline 0)
to your .emacs file and it will offer to put the final CR in for you
when you forget.
--Rob
------------------------------
Date: 29 Dec 1997 23:29:19 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Date parsing
Message-Id: <waa90t3nvao.fsf@ese.UCSC.EDU>
Justin Banks <justinb@ebony.cray.com> writes:
> Does one of the modules enable me to find the number of
> business days between two dates? I've looked at Date::DateCalc,
> and it doesn't appear to do what I want, but before I roll my own,
> I figured I'd make sure someone else hadn't already done so
> (apparently I possess at least one of the programmer's virtues).
Try Date::Manip. It does that, and the kitchen sink too.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Tue, 30 Dec 1997 01:40:35 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: directory tree
Message-Id: <34A8B36A.289CFFF3@5sigma.com>
I'll part with a code snippet from the book here (sorry for
any formatting ugliness ... due to copy/paste from Acrobat).
Hopefully it dinna get garbled in transmission:
sub count_recurse {
local *DIRH;
my ($file_ct_ref, $dir_ct_ref, $dir_name) = @_;
$$dir_ct_ref++;
opendir DIRH, $dir_name or die "couldn't open $dir_name: $!";
my @dir = readdir DIRH;
closedir DIRH;
for $file (@dir) {
next if $file eq '.' or $file eq '..';
if (-f "$dir_name/$file") {
$$file_ct_ref++;
next;
};
next unless -d "$dir_name/$file";
next if -l "$dir_name/$file";
count_recurse($file_ct_ref,
$dir_ct_ref, "$dir_name/$file");
}
}
$file_ct = $dir_ct = 0;
count_recurse \$file_ct, \$dir_ct, ".";
print "$file_ct files, $dir_ct dirs\n";
-joseph
http://www.effectiveperl.com
take_five@hotmail.com wrote:
>
> Does anyone have a snippet of perl coding that will create a list of
> subdirectories under a given directory (walk the directory tree)?
------------------------------
Date: Tue, 30 Dec 1997 01:35:07 -0800
From: Steve Mills <smills@lewiston.com>
Subject: Re: extract using reg. expr
Message-Id: <34A8C04A.2737@lewiston.com>
This is probably way below the current level of conversation, but...
{your telnet prompt}: man grep
can be enlightening on the subject if you can't figure out what all
those <expletive deleted> ?.*] thingies are all about. But then I'm
still nearly as befuddled by the able answers to these questions as I am
by the questions themselves. :o)
Most discussion on REs in (free) perl resources seems to start with the
assumption that you understand what all those frightening metacharacters
mean, and what's re-ally goin' on with those abstruse s/// 'n' split //
lines, rendering such resources less than useful for ignorant hacks like
I'm 'n' u r not.
I read somewhere (in perlre or perlfunc, probably) recently that REs in
perl behave more like egrep (grep -E, sort of - "e" for "extended."),
but that the difference doesn't matter for GNUnix.
------------------------------
Date: 29 Dec 1997 20:13:18 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Fast Suggestions for this string manipulation problem
Message-Id: <waaoh1zpixt.fsf@ese.UCSC.EDU>
Rhodri James <rhodri@wildebst.demon.co.uk> writes:
> if (/\.demon\.co\.uk$/)
> {
> # Do demon summoning stuff
> }
> elsif (/\.co\./)
> {
> # National companies -- do something despite the management
> }
> elsif (/\.mil/)
> {
> # US Military -- do something, sir
> }
These regular expressions are pretty inefficient. They should be
anchored. I suggest /\.co\.??$/ and /\.mil$/ respectively, instead.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Mon, 29 Dec 1997 21:49:38 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Finding the TITLE to a HTML page
Message-Id: <34A87D4F.3F02111@5sigma.com>
A theoretical answer to a pragmatic question. That is
the dichotomy.
-joseph
Abigail wrote:
>
> Joseph N. Hall (joseph@5sigma.com) wrote on 1581 September 1993 in
> ++ A comment inside <TITLE></TITLE> is a counterexample? Well,
> ++ get rid of it then.
>
> That's a nice way of dealing with programming issues. Just get rid
> of any situation in which your program doesn't run.
[...] Only a very few
> ++ applications need to deal with *any possible* HTML file.
> ++ Others have simpler requirements.
>
> That's a cause and result argument. Many HTML files have to be simple,
> because the tools out are written by brainless programmers. If programmers
> dealing with HTML would bother to think half a minute, we could have
> fully used the potentials of HTML. But as long as we have simplistic
> programmers, we'll have simplistic HTML documents.
------------------------------
Date: 29 Dec 1997 13:11:47 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: How do I pass objects from Perl to Javascript?
Message-Id: <waawwgnq2gc.fsf@ese.UCSC.EDU>
snailgem@aol.com writes:
> Let me ask the opposite question: is there any way to pass a JS
> generated page (say the content of a page generated by a call to
> window.open from another page) to Perl? Given the fact that this happens
> on the client, the answer is probably: 'no way', but I'm willing to
> learn otherwise).
You could certainly generate an HTML form and submit it to a Perl CGI
script. If you are clever about the use of hidden fields, you can
probably achieve whatever you need to get done.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: 29 Dec 1997 23:13:02 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: How to check files exists and if it does then?
Message-Id: <waabtxznw1t.fsf@ese.UCSC.EDU>
Mark Worsdall <shadowweb@worsdall.demon.co.uk> writes:
> Ok say there are directory's and files looking like this:-
>
> ipww01.proxy.aol.com/16December1997-Tuesday.txt
>
> ipww04.proxy.aol.com/16December1997-Tuesday.txt
> ipww04.proxy.aol.com/17December1997-Wednesday.txt
>
> ipww05.proxy.aol.com/16December1997-Tuesday.txt
> ipww05.proxy.aol.com/17December1997-Wednesday.txt
> ipww05.proxy.aol.com/19December1997-Thursday.txt
>
> ipww61.proxy.aol.com/16December1997-Tuesday.txt
> ipww61.proxy.aol.com/19December1997-Thursday.txt
>
>
> I am trying to merge the directory's into one directory but the problem
> comes when the files already exist, so I am trying to end up with the
> following:-
>
> proxy.aol.com/16December1997-Tuesday.txt
> proxy.aol.com/16December1997-Tuesday-a.txt
> proxy.aol.com/16December1997-Tuesday-b.txt
> proxy.aol.com/16December1997-Tuesday-c.txt
> proxy.aol.com/17December1997-Wednesday.txt
> proxy.aol.com/17December1997-Wednesday-a.txt
> proxy.aol.com/19December1997-Thursday.txt
> proxy.aol.com/19December1997-Thursday-a.txt
>
> I hope this explains it all better, this also is part of a previous
> problem about removing the 1st word ie ipww05. which is now working.
Then why not do something like this:
$file = "ipww01.proxy.aol.com/16December1997-Tuesday.txt";
$file =~ s/^([^\.]+)\.(.*)\.txt$/$2-$1.txt/;
Then $file contains "proxy.aol.com/16December1997-Tuesday-ipww01.txt"
which is probably more useful anyway....
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: 29 Dec 1997 23:47:16 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Newbie frustration
Message-Id: <waa7m8nnugr.fsf@ese.UCSC.EDU>
dongood@ibm.net (Don) writes:
> Well, thanx to this ng I now know that I can use ctrl-z as an EOF in
> win 95. Problem is when I use ctrl-z, it ignores the next command!
> Checked the FAQ's but found nothing about this. So I'm thinking that
> maybe I should just run a unix OS.
Yes, Linux would be better. But first, do you realize that the EOF in
Micro$oft OS's is actually C-z RET? In other words everything
between ^Z and the next time you hit Enter is ignored. Is that what
you are describing here? If so, that's how it's supposed to be. Type
CTRL+Z and then ENTER immediately after and you should find everything
to be OK.
> Can I run a unix OS(linux) on my win 95 box without removing win 95?
> (This would allow me to code according to the book and make learning
> PERL much easier)
Yes there are several ways you can do this. You can repartition your
hard drive, and install Linux in the new partition. You can get
another disk drive, and install Linux on that. (A basic Linux system,
including Perl, can fit in under 40MB -- I have a 40MB disk on my desk
here that has Debian 1.2 (2.0.27 kernel) and the bare minimum for
networking and Perl installed, including a tiny swap partition.) Or
you can even use "UMSDOS" and install Linux using your Windows
filesystem!
An even easier route is to get an ISP that lets you have shell access
and use that for Perl programming.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Tue, 30 Dec 1997 01:34:55 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Newbie frustration
Message-Id: <34A8B217.CA0258F4@5sigma.com>
I'm not sure, but suspect, that you can accomplish this using
cygwin, or whatever it's called these days. Well, after a quick
look, I guess it's ftp://ftp.cygnus.com/pub/gnu-win32/. You
can definitely run bash on win 95, which is at least somewhat
like running unix.
Haven't tried compiling Perl under gnu-win myself, but I imagine
someone's done it. That would be an Ilya or Guru thing I guess ....
-joseph
> dongood@ibm.net (Don) writes:
> > Can I run a unix OS(linux) on my win 95 box without removing win 95?
------------------------------
Date: Tue, 30 Dec 1997 00:08:20 -0800
From: Rob Maniatis <robm@transmeta.com>
Subject: Passing short int arrays between Perl and C
Message-Id: <34A8ABF4.46B@transmeta.com>
Hello all,
I have recently written a small C-library that I would now like to bring
into perl. I am having a problem, however, when I attempt to pass
arrays of short int's back and forth between the C library call and
Perl.
The C function expects three arguments--two pointers to arrays
(C-arrays) of short ints (and it assumes that the calling function has
taken care of the space allocations) and a length argument (an int).
One array contains the input to the function while the other is used for
the output. On the Perl side I use 'pack' to create a "string"
containing all the data. I then make a copy of this string (which I
figure makes a nice template for the output array from C) and pass
pointers to the scalar strings to the C routine along with a length
argument (both arrays will always be the same size). C happily does its
thing. The problem is that when I get back to perl if the returned
array happened to contain a 0 within the array the output string in perl
ends at the embedded . (I smell strlen from C somewhere here). Instead
of me babbling more let me include some code snippits:
CALL FROM PERL:
@data = 1, 2, 3;
$input = pack("s$length", @data);
$output = $input; #allocate space for output.
&mypackage::c-library-call($input, $length, $output);
(Eventually I'd like to hide the packing and space allocation in a perl
wrapper in mypackage).
C-LIBRARY CALL:
int c-library-call(short int input*, int length, short int *output)
XS CODE:
int
c-library-call(arg0, arg1, arg2)
short * arg0
int arg1
short * arg2
OUTPUT:
arg2
TYPEMAP:
short * T_PV
C-WRAPPER PRODUCED BY XS COMPILER:
XS(XS_c-library-call)
{
dXSARGS;
if (items != 3)
croak("Usage: mypackage::c-library-call(arg0, arg1, arg2)");
{
short * arg0 = (short *)SvPV(ST(0),na);
int arg1 = (int)SvIV(ST(1));
short * arg2 = (short *)SvPV(ST(2),na);
int RETVAL;
RETVAL = c-library-call(arg0, arg1, arg2);
sv_setpv((SV*)ST(2), arg2);
ST(0) = sv_newmortal();
sv_setiv(ST(0), (IV)RETVAL);
}
XSRETURN(1);
}
I've tried a few variations on the XS file playing around with various
(writing some of my own code via CODE: and PPCODE:) but have had no luck
so far.
I really appreciate any help you folks can provide.
Thanks,
--Rob
------------------------------
Date: Tue, 30 Dec 1997 05:58:58 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: PERL URL-Encoding
Message-Id: <68ajoo$i74@mtinsc05.worldnet.att.net>
In article <34A80745.14F83A7@hub.ofthe.net>, dustin@hub.ofthe.net wrote:
> Could anyone email me the line(s) of PERL that would re-URLencode a
> string
> of text
have you tried the URI::Escape module?
someone could mail you the lines, but then you would never get
to experience CPAN [1] :)
[1]
Comprehensive Perl Archive Network
<URL:http://www.perl.com>
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: 29 Dec 1997 20:58:49 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Starting a Daemon in a CGI script
Message-Id: <waalnx3pgty.fsf@ese.UCSC.EDU>
maverner@hotmail.com writes:
> I have a perl script in my cgi-bin file which is supposed to start a
> daemon and then return a simple message.
>
> My script is essentially:
>
> if (!daemonRunning)
> {
> system("runDaemon.pl &");
> }
> print htmlHeader();
> print "I'm back";
> return 1;
>
> The problem is my perl script never comes back from starting runDaemon.pl
> The daemon does get started and the next time I run the script, it returns
> a nice html page since the daemon is already running.
>
> Is the "system" command the right way to launch a job asynchronously?
> The Camel book seems to suggest this should work as far as I can tell.
This should work, except for one problem. Many web servers will not
consider your CGI script to be done until the STDIN/STDOUT/STDERR
filehandles that were used by your CGI script are closed.
When you run system("runDaemon.pl &") this is what happens:
1. Perl scans the string to see if it contains shell metacharacters.
2. It does (&), so it forks and execs /bin/sh, giving it the command.
3. /bin/sh finds the file runDaemon.pl and notices that it is a Perl
script by its #! line, so it forks and execs the command
"/path/to/perl runDaemon.pl" backgrounded, then exits.
Child processes inherit all open filehandles of their parents, so even
though the parent is done, the child (the grandchild actually: perl
again) has the same filehandles still open, and thus the webserver
waits.
The solution is to close those filehandles explicitly (you wouldn't
want to write or read them anyway, since they refer to a particular
CGI session which should have long since finished). You can do that
either in the calling CGI script, or in runDaemon.pl.
However since your daemon is running as a Perl script, you might
consider avoiding the fork of /bin/sh (however you'll still have to
fork twice). Have your CGI script fork; the parent should wait() for
the child to exit. The child forks and the grandchild is
runDaemon.pl; the intermediate child exits. I believe the double-fork
will prevent zombie processes, which can be a problem in situations
like this. However it's been a while since I had to work with this
problem, so I could be wrong... it's a Unix guru type problem, though,
not a Perl one, ask in comp.os.unix.whatever.
HTH.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Tue, 30 Dec 1997 10:05:19 GMT
From: James C. Hoffman <tdsjms@ix.netcom.com>
Subject: Tech writer lifts burden from programmers
Message-Id: <68agul$gq4@dfw-ixnews9.ix.netcom.com>
Hi-I'm a technical writer that can help you with your online help systems and
end-user documentation needs. E-mail me back at tdsjms@ix.netcom.com if
interested. You can see a sample of my work on my home page at
http://www2.netcom.com/~tdsjms/hofftek.html
It is under construction, but the programming and documentation pages are
available. I have experience in just about any system. Thanks.
Joan
------------------------------
Date: Mon, 29 Dec 1997 22:12:23 -0800
From: Gil Vidals <vidals@etica-entertainment.com>
Subject: UNINITIALIZED VALUE at TIE (%HASH....
Message-Id: <34A890C7.429AD7AF@etica-entertainment.com>
The following line generates an "uninitialized value" error when
compiling with "use strict" and "perl -w" in Perl 5.004.
tie (%HTML, "GDBM_File", $dbfilename, O__RDONLY, undef)
or die "Can't open $dbfilename $!";
$dbfilename is defined as a string constant. I guess that leaves %HTML
to initialize. I tried "%HTML = ();" but it was no help. How can I stop
those pesky "uninitalized value" error when dealing with database file
handles?
Gil
------------------------------
Date: 29 Dec 1997 19:52:40 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Wanna get the Week Day for a specified date
Message-Id: <waara6vpjw7.fsf@ese.UCSC.EDU>
tony buono <tony@buono.demon.co.uk> writes:
> I am using the timelocal.pl to get Todays week day, time date and Year
> with no problem using this:
> $the_first = 1;
> $now_string= localtime;
>
> $if ($now_string =~ m/(\w+)( +)(\w+)( +)(\w+)( +)(\d+)\:(\d+)\:(\d+)(
> +)(\d+)$/)
> {
> ($wkday,$month,$date,$year) = ($1,$3,$5,$11);
> $mon_start = &timegm(undef,undef,undef,$the_first,$month,$year);
> }
>
> Okay, that all works for me (once I changed the timelocal to timegm that
> is). When all is done, I get the proper day of the weel for the first
> day of the month. I then throw it through a script that will output a
> calendar for THIS month where the first of the month is on the proper
> week day...
First off, don't use timelocal.pl; that's old fashioned Perl4 stuff.
If your ISP is stuck on Perl4 and won't upgrade, then get a new ISP.
At a minimum, use Time::Local instead (it's equivalent, but more
Perl5-ish); you might also want to consider Date::Manip as another
method. It has some supremely handy (though maybe not as fast)
methods for manipulating dates.
use Date::Manip;
my $wday = UnixDate($now_string, '%w');
That should do the trick nicely, and you don't have to sweat about the
regexp for the date format, either. You should process $now_string so
it contains just the date, however.
> Now what I want to do is make $month more of a variable so that Any
> month that I choose will come up with the proper 1st = Weekday
> relationship. I am getting the month from the title of a file (i.e.
> Decfile.txt) which I then throw into a substr to get "Dec"
Use my above example, only instead of $now_string, use "$month 1
$year". Remember to use 4 digit years with this stuff; 2000 is not
far off now!
> open (TEXTFILE, "$FORM{url}/$next_element};
> $calMonth = substr($next_element, 0,3);
> $mon_start = &timegm(undef,undef,undef,$the_first,$calMonth,$year);
>
> But this throws my server into some kinda loop that is really p*ssing of
> the guys in charge.
>
> I am running this as a cgi, so I know this should be elsewhere, but it
> really is a question about timelocal.pl... and I am more than willing to
> trash this whole series of statements if someone knows an easier way to
> equate the weekday and date of the month (I prefer to use 0 = Sunday, 1
> = monday...)
That is odd. Try doing the same thing from the command line. Just
excerpt the parts of your code that aren't CGI dependent. Put "warn"
statements before and after the timegm to show the status. See where
it hangs, and it's easy to kill (^C) if it gets away.
BTW, ISO 8601 apparently says that Sunday should be 1, not 0. Same
for days of months. Date::Manip (the most recent versions) uses this
standard; Time::Local uses your preference.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
------------------------------
Date: Tue, 30 Dec 1997 01:07:41 -0600
From: Gary Drummond <gdrumm@ix.netcom.com>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <34A89DBD.7CFC@ix.netcom.com>
Charles F Hankel wrote:
>
> Just to add to this debate, I had to look into the winsock.h file on
> my PC the other day and the first glance showed why COBOL is so much
> more easy to maintain. Anyone with a grain of sense would prefer the
> sheer readability of COBOL to the mess that I saw.
>
> Charles F Hankel
> ------------------------------------------------------------------
> COBOLs: IBM D, E, F, ANS v4, VS, COBOL 2, LE/370, AIX, S/38, OS/2,
> PC/MS-DOS, Honeywell GCOS, Burroughs 7000, Tandem, HP3000
> all to varying degrees over the past 25 years or so.
There was a previous post about the MSN accounting. I wonder if it was
done in C?
------------------------------
Date: Tue, 30 Dec 1997 02:02:52 -0800
From: Patricia Shanahan <pats@acm.org>
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <34A8C6CC.3EC74017@acm.org>
Lawrence Kirby wrote:
>
> In article <34A812F9.C169A703@its.cl> gschwarz@its.cl "Guillermo Schwarz" writes:
...
> >The point is, at least when I studied the good and old K&R, it didn't mention
> >
> >"reserved as identifiers with external linkage", that for me means "don't
> >touch this,
> >or trick"...
>
> K&R2 doesn't define the language. It is an excellent book but there do seem to
> be a few things it doesn't cover properly. The index lists "reserved words"
> but that just seems to refer to keywords. Even though it was revised after
> the standard was released it seems to be based mainly on a draft standard.
...
"good and old K&R" may be K&R1, not K&R2.
------------------------------
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 1550
**************************************