[10753] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4352 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 3 13:07:31 1998

Date: Thu, 3 Dec 98 10:00:21 -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           Thu, 3 Dec 1998     Volume: 8 Number: 4352

Today's topics:
    Re: CGI-Scripts <theduck90@hotmail.com>
        Compiling Perl on Win32 keydet89@yahoo.com
        DB handles, best approach? frogsmock@my-dejanews.com
    Re: Dynamic loading Modules (EXCHANGE:MTL:1T83)
        Embedded ?: operators <mike@obfuscated.net>
    Re: File with Sendmail <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: free perl interpreter (David M. Miller)
        interpreting binary?/hex?/cryptic? socket data <kak@cisco.com>
        Net::FTP get problem harkal@rainbow.cs.unipi.gr
        newbie file open question <nospam23_skidoo@geocities.com>
    Re: newbie file open question (Tad McClellan)
    Re: newbie file open question <jc@eddie.mit.edu>
        NT won't return anything <corder@email.com>
    Re: NT won't return anything <Allan@due.net>
    Re: PC to Unix Problem (EXCHANGE:MTL:1T83)
        Perl Extensions (generated with swig) <Piotr.Martyniuk@softax.com.pl>
    Re: perlshop 3.1 <metalmd@earthlink.net>
    Re: Question about =~ (David M. Miller)
        Regex question <dmarti81@ford.com>
        Strange setpgrp()/root interaction? (Karlon West)
    Re: Substitute <jc@eddie.mit.edu>
    Re: variable inside variable <r28629@email.sps.mot.com>
    Re: variable inside variable <r28629@email.sps.mot.com>
    Re: variable inside variable <qcoldiro@unlinfo.unl.edu>
    Re: Why is "... @foo ..." occasionally a syntax error? (Andrew M. Langmead)
        wwwboard crash prevention (i hope) <nospam23_skidoo@geocities.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 03 Dec 1998 16:07:49 GMT
From: "www.indexfinger.com" <theduck90@hotmail.com>
Subject: Re: CGI-Scripts
Message-Id: <3666B6DF.F0F1495B@hotmail.com>

I use www.albany.net. Unix, telnet, ftp....

Heiko wrote:

> I4m working on my own CGI-Scripts but I can4t find a server on which I can
> freely execute my own scripts. So, are there any servers like that
> available?

 -----------------------------------------------------------------------------

Index Finger - http://www.indexfinger.com
Did you know Yahoo will make over $200 million this year?
Isn't it time your visitors used your site to find what they are looking for?




------------------------------

Date: Thu, 03 Dec 1998 17:16:09 GMT
From: keydet89@yahoo.com
Subject: Compiling Perl on Win32
Message-Id: <746h0m$7ga$1@nnrp1.dejanews.com>

I know about DemoBuilder's perl2exe and I use ActiveState's
pl2exe, but does perlcc run on Win32?  I am looking for a way
to get a smaller executable...and one that is truly stand-alone.
By this I mean that even using pl2exe, the system still needs to
have pertCRT.dll in the Winnt\system32 dir...

Carv

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Thu, 03 Dec 1998 16:56:52 GMT
From: frogsmock@my-dejanews.com
Subject: DB handles, best approach?
Message-Id: <746fsi$6dh$1@nnrp1.dejanews.com>

Folks,

I am setting up a site that uses Apache, mod_perl, and PostgreSQL (I am using
the DBI module to talk to PostgreSQL).	My question is, what is the most
efficient approach to use in creating/tearing down the database handles? 
Should I create them in each perl script that make SQL calls, or should I
create a database handle during httpd startup that all the scripts can use? 
It will be a data-oriented site, so most pages will make SQL calls.  PROs and
CONs would be appreciated, along with any other tips for improving the
performance of a site that makes frequent SQL calls using mod_perl and DBI.

Sorry for the somewhat open-ended nature of this post . . .

Thanks!

Jim

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Thu, 03 Dec 1998 11:26:51 -0500
From: "Yao, Hsin (EXCHANGE:MTL:1T83)" <hsinyao@americasm01.nt.com>
Subject: Re: Dynamic loading Modules
Message-Id: <3666BBCB.78F2D67E@americasm01.nt.com>

> "Can't load module XXX, dynamic loading not available in this perl."
> 
> How must I recompile my perl to support dynamic loading ???
> 

The answer is NO, you don't have to. Check the document

http://www.binary.net/support/man/man.phtml?title=perlembed

You'll see that you need to set the function xs_init() when you call
perl_parse

- Hsin Yun -


------------------------------

Date: Thu, 03 Dec 1998 11:39:36 -0500
From: Michael Conlen <mike@obfuscated.net>
Subject: Embedded ?: operators
Message-Id: <3666BEC8.4588AEE4@obfuscated.net>

I do not recall ever seeing a definition for embedded ?: operators. I
have an example of what appears to work on my system, but I'm curious as
to whether or not it's defined to work, so that I can count on being
able to use it in future obfuscated perl code contests.

The example is 

http://mike.obfuscated.net/99.html

You should also check this out if you just want a beer or are interested
in a new way to do a switch statment.


Michael Conlen


------------------------------

Date: 03 Dec 1998 17:13:08 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: File with Sendmail
Message-Id: <83ogplcigb.fsf@vcpc.univie.ac.at>

Re: File with Sendmail, Daniel <daniel@boksjo.com> said:

Daniel> Hi, I'm writing a script that is supposed to send me
Daniel> a certain file on my e-mail. I'm using sendmail to
Daniel> do this, since I have used sendmail before in
Daniel> another script. The thing is that now I want to
Daniel> redirect a file to sendmail, not only a certain
Daniel> text. What syntax do I use in a Perl program for
Daniel> this?  Maybe:

Use the modules Luke

    perldoc Mail::Send
    perldoc MIME::Tools   (for attachments)

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien,  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>


------------------------------

Date: 03 Dec 1998 10:46:08 -0500
From: dmmiller@pandora.i-did-not-set--mail-host-address--so-shoot-me (David M. Miller)
Subject: Re: free perl interpreter
Message-Id: <rax1zmhgren.fsf@pandora.i-did-not-set--mail-host-address--so-shoot-me>

Um, excuse me?

Why don't you check www.perl.com for links that will get you a copy of perl to run on
you own machine (either UNIX-flavored or Windows 95/98/NT).

And yes, it's free.

dmm


------------------------------

Date: Thu, 03 Dec 1998 10:51:09 -0500
From: Keith Kaple <kak@cisco.com>
Subject: interpreting binary?/hex?/cryptic? socket data
Message-Id: <3666B36D.5FC2B9E4@cisco.com>

Thanks to Greg, Erik and Andrew for the answer to my child pid question.

My perl script plays man-in-the-middle between some networking devices,
listens to socket data coming from one device, tweaks it, and send it to
a socket on another networking device.  When I go to "look" at the data
recieved on the socket with:

 while (defined ($buf = <$new_sock>))    {
                        #$buf=~s/2222/5555/;
                        print $sock "$buf";
                        print "Sent: $buf to otherside";
                }

It looks something like this --->
(cb?@#le?+1111pe?+2222~|?J`a%3~Mc&c\Tb?o~xtermxterm term

What seems even more strange (to me) is that the above is different in
the xterm that I pasted it from !  I'm sure it's a clue to what is going
on, but right now, I'm CLUELESS.

Anybody know what's going on here?  I just want to know how to code so
when I see "#le?", I can say, "oh, that  was 00011010110101, or 
whateever it really was when it came in on the socket before my xfont
map or whatever got a hold of it...

Any advice is muchly appreciated.

  BTW, I'm using linux and perl 5.004_04


-- 
Keith Kaple x25759 -----------------------
| New distribution, $40.  Linux compatible
| sound card, $89.  Three button mouse, $18.
| Nuking windows partitions....priceless.


------------------------------

Date: Thu, 03 Dec 1998 16:52:02 GMT
From: harkal@rainbow.cs.unipi.gr
Subject: Net::FTP get problem
Message-Id: <746fjg$67n$1@nnrp1.dejanews.com>

 Hi, i have a little problem with the "get" of the Net::FTP.
If the link fails while the file transfer the "get" is not timeing out.
How can I make it time out, or to inform me about the situation...

Thanks in advance...

Harry Kalogiroy

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: Thu, 03 Dec 1998 15:59:47 +0000
From: 23_skidoo <nospam23_skidoo@geocities.com>
Subject: newbie file open question
Message-Id: <3666B55B.5CE0@geocities.com>

i'm writing a test program to figure out the open command. i can open
and read a file no problems, i can also open and create/write to or
append a file. i want to be able to open a file, read it and write back
to it based on what i just read. is this possible? what i have written
(below) seems to open the temp.dat file and empty it. i get a 'document
contains no data' error from the browser.


#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse(*input);

open (STDERR, ">&STDOUT");

$basedir = "/home/web9399/website/cgi/franki/black_ops";

print "Content-type: text/html\n\n";

open (FILE, "+>$basedir/temp.dat") || print "couldn't open
$basedir/temp.dat<br>\n";

@lines = <FILE>;
foreach $line (@lines) {
	print "$line<br>\n";
	$line++;
	print FILE "$line\n";
}
close (FILE);

if this worked, i'd like it to open a txt file with a number in it, read
the number, increment it and write it back to the file ready for next
time (currently the temp.dat file is a list of numbers, 1\n to 10\n) the
idea being that noone else will be able to access the script
simultaneously and read the same number from the file. if i'm barking up
the wrong tree please tell me (or shoot me) now :)

-23


------------------------------

Date: Thu, 3 Dec 1998 11:19:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie file open question
Message-Id: <u6h647.so1.ln@metronet.com>

23_skidoo (nospam23_skidoo@geocities.com) wrote:
: i'm writing a test program to figure out the open command. i can open

   Did you read about open() in the perlfunc man page?


: and read a file no problems, i can also open and create/write to or
: append a file. i want to be able to open a file, read it and write back
: to it based on what i just read. is this possible? what i have written
: (below) seems to open the temp.dat file and empty it. i get a 'document
: contains no data' error from the browser.


: #!/usr/bin/perl


   You should enable warnings on (*all* of your perl scripts:

      #!/usr/bin/perl -w


: open (FILE, "+>$basedir/temp.dat") || print "couldn't open


   The description of open() in the perlfunc man page says:

   "'+<'> is almost always preferred for read/write updates--the 
     '+>'> mode would clobber the file first."

   You are clobberring the file first...



: if this worked, i'd like it to open a txt file with a number in it, read
: the number, increment it and write it back to the file ready for next
: time


   Perl FAQ, part 5:

   "I still don't get locking.  I just want to increment the 
    number in the file.  How can I do this?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 03 Dec 1998 11:54:41 -0500
From: John Chambers <jc@eddie.mit.edu>
Subject: Re: newbie file open question
Message-Id: <3666C251.8500C135@eddie.mit.edu>

23_skidoo wrote:
> 
> i'm writing a test program to figure out the open command. i can open
> and read a file no problems, i can also open and create/write to or
> append a file. i want to be able to open a file, read it and write back
> to it based on what i just read. is this possible? what i have written
> (below) seems to open the temp.dat file and empty it. i get a 'document
> contains no data' error from the browser.
 ... bad code deleted ...
> if this worked, i'd like it to open a txt file with a number in it, read
> the number, increment it and write it back to the file ready for next
> time (currently the temp.dat file is a list of numbers, 1\n to 10\n) the
> idea being that noone else will be able to access the script
> simultaneously and read the same number from the file. if i'm barking up
> the wrong tree please tell me (or shoot me) now :)

If you really want to overwrite a small chunk of the file,
you will need to use the seek function to return the file's
"current position" pointer to the start of the record, and
you'll probably need to first call tell to find that pointer.
It can't be done as simply as you're trying.

In your case, it appears that you want to be able to do
something like replace 9\n with 10\n, which entails shifting
the rest of the file over by one byte.  This can't be done
with an overwrite at all; you have to rewrite the tail end
of the file.

A much simpler approach is to open a second file for output,
and copy the original to it, making changes as you go. Then,
if any changes were made, use the link function to replace
the old file with the new, and unlink to get rid of the second
file.

In some special cases, perl can do this for you.  Check out
the -i command-line option in "man perlrun".  This is only 
useful for fairly small, specialized scripts that only read
from <>, but when it works, it is very useful.

Alternatively, if the file isn't very many megabytes, you
can slurp its contents into an array in memory, modify that
array, and then write it back to the same file.  Your code
was close to this.  Instead of writing inside the loop, just
rewrite $line (which is a reference to the current line in
@lines), and then at the very end, write the data back:
	print @lines;
This is a very useful technique in perl (when you have the
memory to hold the entire file), and is probably the best
solution in your case.

One problem:  Your code did this:
	foreach $line (@lines) {
		...
		$line++;

This probably won't work right, because $line contains both
the number and a newline, so (strictly speaking) it's not a
number, and who know what ++ will do to it?  It's a bit more
code, but it'd be safer to pull the number out:
		if (($num,$rest) = ($line =~ /^(\d+)(.*)/)) {
			$line = ++$num . $rest;
		}
This will increment the first number if $line starts with
a number, and leave the rest of the line unchanged.

<insert perl mantra "There's more than one way to do it" here>


------------------------------

Date: Thu, 03 Dec 1998 10:16:22 -0600
From: corder <corder@email.com>
Subject: NT won't return anything
Message-Id: <3666B956.47BD4B56@email.com>

This is really upsetting me.  I wrote a little snippet to test it out.

$version = `ver`;
print "Content-type: text/html\n\n";
print "Version: $version\n<br>";
print "Error code: $?<br>";

If I run this from the DOS prompt it returns the version just fine and
error code of 0.
However, if I call it from a browser like:
http://abc.com/cgi-bin/vers.pl
I only get

Version:
Error Code: 0

I have set the permissions to pretty much give any and everybody full
access to the script so I don't see where permissions would prevent it
from working properly.  Can someone please shed some light on this
situation.

Thanks
Cliff Corder



------------------------------

Date: Thu, 3 Dec 1998 12:04:12 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: NT won't return anything
Message-Id: <746gao$qij$1@camel29.mindspring.com>

corder wrote in message <3666B956.47BD4B56@email.com>...
>This is really upsetting me.  I wrote a little snippet to test it out.
>$version = `ver`;
>print "Content-type: text/html\n\n";
>print "Version: $version\n<br>";
>print "Error code: $?<br>";
>If I run this from the DOS prompt it returns the version just fine and
>error code of 0.
>However, if I call it from a browser like:
>http://abc.com/cgi-bin/vers.pl
>I only get
>Version:
>Error Code: 0
>I have set the permissions to pretty much give any and everybody full
>access to the script so I don't see where permissions would prevent it
>from working properly.  Can someone please shed some light on this
>situation.


    I know this really does not illuminate the problem too much but your
code runs just fine, and displays correctly, under Apache for windows and
Win95 (except I don't think your error message does what you think it does).
    I would suggest that you might want to post a question in your servers
newsgroup as it is likely that the problem's resolution will be found there.

AmD

[posted and mailed]




------------------------------

Date: Thu, 03 Dec 1998 11:38:58 -0500
From: "Yao, Hsin (EXCHANGE:MTL:1T83)" <hsinyao@americasm01.nt.com>
Subject: Re: PC to Unix Problem
Message-Id: <3666BEA2.D2CE5BAA@americasm01.nt.com>

oleynikl@geocities.com wrote:
> 
> I've been learning Perl 5.0 for 2 days now. I'm trying to use Perl to solve a
> problem. Whenever I create an ascii file in a PC environment and upload it to
> a UNIX account, what I get is newline characters appearing everywhere. (ie: I
> get ^M in vi and <cr> in nedit).
> 

In vi , you can try :
:1,$s/<ctrl-v><ctrl-m>//g
the command will appear as:
:1,$s/^M//g
and it should get rid of all the ^M .


------------------------------

Date: Thu, 03 Dec 1998 17:26:46 GMT
From: "Piotr Martyniuk" <Piotr.Martyniuk@softax.com.pl>
Subject: Perl Extensions (generated with swig)
Message-Id: <qRz92.3548$m6.545987@news.tpnet.pl>

Hello.
I have an important question.
Does anybody know how to map C++ type "reference to pointer" for example
"SimpleClass *&class" to Perl type using SWIG. I'm using SWIG shadow classes
feature to generate extension for Perl. It usualy works fine, SWIG handles
pointers and references to classes just fine, but there is a problem with
references to pointers.
I wont to write something like this:

$obj = new Object;

# another object should be created in C++ and returned by reference
# MakeNewObject is method in C++
$obj->MakeNewObject($another);

# it should print itself out
$another->Print();

I don't know if it even could work, written like this.
Maybe there are other ways to handle this situation.

I've tried passing argument by Perl reference, like this \$a, but it didn't
work.
I want to avoid explicit typemap.

I would appreciate every advice.

Piotr Martyniuk.




------------------------------

Date: Thu, 03 Dec 1998 08:43:53 -0800
From: Marc <metalmd@earthlink.net>
Subject: Re: perlshop 3.1
Message-Id: <3666BFC9.20FE36F2@earthlink.net>

vivekvp@hotmail.com wrote:

> anyone have any luck installing perlshop 3.1???
> i have tried but still get problems:
> i downloaded and try to install perlshop on a unix server.  i am running into
> the folowing error:
>
> "Invalid Transmission #3 received from: 192.58.194.69
> If your connection was interrupted, you must Enter the shop from the beginning
> again."
>
> i am not using ssl, and have cookies turned off.  can you give me any idea why
> this is happening?
>
> thanks!!
>

And I am getting the same exact problem.  I have tried for days, changing
varibles, moving directories, but to no avail.  Help would be greatly appreciated

Thanks - Marc




------------------------------

Date: 03 Dec 1998 11:13:36 -0500
From: dmiller@fullwave.net (David M. Miller)
Subject: Re: Question about =~
Message-Id: <raxzp95fbkf.fsf@fullwave.net>

Keppy Boone <finkeppy@finaid.indstate.edu> writes:

> I am having some difficulty getting a search to work given a string.
> 
> ex.
> 
> $_ =~ /look/i;    # works fine.
> 
> $search = "/look/i";
> $_ =~ $search;    #Doesn't work.
> 
> Any Ideas will help.
> Please email me at ccboone@amber.indstate.edu
> 
> Charles Boone

Okay, so try this:

$search = "look";
$_ =~ /$search/i;

OR, this:

$search = "/look/i";

my $rc = eval("\$_ =~ $search");	# need to quote the $_ so it
is '$_' in eval().

But this might not work, since the eval'ed code has a localized copy of $_.


------------------------------

Date: Thu, 03 Dec 1998 16:43:27 +0000
From: Duncan Martin <dmarti81@ford.com>
Subject: Regex question
Message-Id: <3666BFAF.A6BC9413@ford.com>

Hello all,
  I've tried to work this out, but it's starting to make my head hurt...

I'm reading in a plain text file where each line needs to be split into
fields.  Each field is either alphanumeric and has " around it or
numeric without the quotes.

e.g, possible lines are
1,2,"camel",4,"book"
"a","b",4,"c"

previously I was doing it in three stages,
$rawline =~ s/(\",|,\")/\n/gso;
$rawline =~ s/([0-9]),([0-9])/$1\n$2/go;
$rawline =~ s/\"//go;

then splitting on the \n, unfortunately the new data contains fields
like :
"123 45,67" which gets turned into two fields, and
1,   2,3,4
where the white space is confusing the whole thing.

If anyone can suggest a way of doing this without (Sharp intake of
breath) having to scan left->right counting quotes, I'd be very
grateful.

Duncan


------------------------------

Date: 3 Dec 1998 16:05:22 GMT
From: karlon@bnr.ca (Karlon West)
Subject: Strange setpgrp()/root interaction?
Message-Id: <746cs2$929$1@crchh14.us.nortel.com>


I tried c.l.p.moderated, and got one response, so I was
hoping I could get more responses here. 

=======================
I'm not sure what question to ask, only that the perl program
is dieing, and I can't tell why.

If I run the following code as a normal user on a Solaris or HPUX box,
all three lines are printed, which is what you'd expect.

If I run it as root on a Solaris box (I don't have root password on the
HP) only the first two lines are printed, and I get a strange exit code.
Any ideas?  Is it perl related?  Is it OS related?

This is just the smallest reproducible code.  The real program has
several hundred lines, function calls, loops, updates of other
filehandles, etc between the setpgrp and the read from STDIN, and they
are all executed normally, but something strange is happening when
trying to read from STDIN AFTER I do a setpgrp() as "root".

Here's the code: "This is perl, version 5.004_01"
It's a solaris 2.5, sun4m sparc SUNW,SPARCstation-20
---------------------------------------
#!/usr/bin/perl -w
use diagnostics;
use strict;

print "this is printed\n";
$a=<STDIN>;
setpgrp(0,$$);
print "this is printed...\n";
$a=<STDIN>;
print "i guess it worked\n";
--------------------------------------

If run as a normal user:
==============================
% ./aa.pl
this is printed
a
this is printed...
a
i guess it worked
% echo $?

0
==============================

If run as root:

++++++++++++++++++++++++++++++
% su
Password:
# ./aa.pl
this is printed
a
this is printed...
# echo $?
154
#
++++++++++++++++++++++++++++++

By the way, I wrote a quick C program, testing both "setpgrp()" and
"setsid()" and both worked as root and normal users.  This makes
me think it might be a perl problem.

And one last piece of info, here's the program run
through the debugger:
************************************************
# perl -d aa.pl
Loading DB routines from perl5db.pl version 1
Emacs support available.

Enter h or `h h' for help.

main::(aa.pl:5):        print "this is printed\n";
  DB<1> s
this is printed
main::(aa.pl:6):        $a=<STDIN>;
  DB<1> s
a
main::(aa.pl:7):        setpgrp(0,$$);
  DB<1> s
main::(aa.pl:8):        print "this is printed...\n";
  DB<1> #
#
*********************************************


Notice the prompt comes back even before the second "this is printed"
gets flushed out.


Also, based on the response from c.l.p.m, I tried running the script
not as root, but as setuid root, and got a different outcome from 
either of the above:

So, I just wrote a one line shell script, chmodded 4755 as root:

=====================================
% cat rootme
#!/bin/ksh

 ./aa.pl
# chmod 4755 ./rootme
# ls -l rootme
-rwsr-xr-x   1 root     other         20 Dec  3 09:34 rootme
# exit
% ./aa.pl
this is printed
a
this is printed...
a
i guess it worked
am I printed??
% ./rootme
this is printed
a
this is printed...
a
a
a
a
^C
^C
^D
^Z
zsh: suspended  ./rootme
%

i.e. it locked up and wouldn't die at all.  But, since it works with
your perl 5.005, I guess I'm hoping it's a perl 5.004 bug, or maybe
that I'm still running an acient, but patched-up Soalris 2.5, and not
2.5.1


Looking for any ideas, or if others can try it on their system and 
verify or dispute the above results.

Karlon



------------------------------

Date: Thu, 03 Dec 1998 11:17:15 -0500
From: John Chambers <jc@eddie.mit.edu>
Subject: Re: Substitute
Message-Id: <3666B98B.DB9A9927@eddie.mit.edu>

Mark Mark Dominus Dominus Weatherby George Dupree wrote:
> 
> In article <366572F7.7BACB2E0@eddie.mit.edu>,
> John Chambers  <jc@eddie.mit.edu> wrote:
> >#!/usr/bin/perl
> >open(F,$0);while(<F>){print}
> >
> >I don't think I've seen one smaller.
> 
> The empty program is smaller, and doesn't have the caveats you mentioned.

You're right, of course.  I don't know how I could have missed that one!

> Among nontrivial programs,
> 
>         open+0;print<0>

That's wonderful!  I think I'll spend some time trying to decode how
it works.

> works on the same principle as yours, and is the smallest I know of.
> It also has the benefit of depending on an obscure and little-used
> feature.  I wish I could remember who invented it.
> 
> Also, see http://www.plover.com/~mjd/perl/quine.html.
> It is probably quite different from others you have seen before.

You're right.  Talk about twisted minds ...

> >But it's a nice example, and not even obscure.
> 
> Sometimes obscure is a virtue.

It certainly can have entertainment value.


------------------------------

Date: Thu, 03 Dec 1998 10:00:53 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: quinn coldiron <qcoldiro@unlinfo.unl.edu>
Subject: Re: variable inside variable
Message-Id: <3666B5B5.F13CFB5B@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]
 
quinn coldiron wrote:
> 
> I'm working on a database with a table of names and a table of form
> letters.
> What I want to do is place variables in the form letter like this:
> 
> ------------------------------------------
> $fname $lname
> $address
> 
> Dear $fname,
> 
> blah blah blah
> 
> Thank you,
> 
> Quinn
> ------------------------------------------
> 
> I read the formletter into $formletter, set the variables from the table
> and print,
> but I dont get the data, just the variable names.  Can I do this?

Have you try 'here doc', or format?

-TK


------------------------------

Date: Thu, 03 Dec 1998 10:11:36 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Tad McClellan <tadmc@metronet.com>
Subject: Re: variable inside variable
Message-Id: <3666B838.B3C841E9@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]

Tad McClellan wrote:
> 
> quinn coldiron (qcoldiro@unlinfo.unl.edu) wrote:
> : I'm working on a database with a table of names and a table of form
> : letters.
> : What I want to do is place variables in the form letter like this:
> 
> : Dear $fname,
> 
> : but I dont get the data, just the variable names.  Can I do this?
> 
>    Perl FAQ, part 4:
> 
>       "How can I expand variables in text strings?"

the faq suggested using s///, but I find using eval is more
straight-forward (not sure about effeciency, yet). Anything hiding from
me ?

-TK


------------------------------

Date: Thu, 03 Dec 1998 11:28:08 -0600
From: quinn coldiron <qcoldiro@unlinfo.unl.edu>
Subject: Re: variable inside variable
Message-Id: <3666CA27.92CFA051@unlinfo.unl.edu>

Thanks for the suggestion.  I found the answer in the Perl FAQ.  Here is
what I did:
---------------------------------------------------------------
 $day = `date +%A`;
 $mo = `date +%B`;
 $dom = `date +%d`;
 $year = `date +%Y`;
 $fname = $confield[3];
 $lname = $confield[1];
 $add1 = $confield[5];
 $add2 = $confield[6];
 $add3 = $confield[7];
 $city = $confield[8];
 $state = $confield[9];
 $zip = $confield[10];
 $country = $confield[11];
 $date = "$day, $mo $dom $year";

 $field[0] =~ s/\$(\w+)/${$1}/g;  #this makes it so we can read
variables out of the text string;
 print"<HTML>\n";
 print"<HEAD>\n";
 print"<TITLE></TITLE>\n";
 print"<body BGCOLOR=\"\#cccccc\" text=\"\#000000\">\n";
 print"<table border=0>\n";
 print"<TR><TD align=justify>$field[0]\n";
 print"</table>\n";
---------------------------------------------------------

I am pulling form letters out of a database and wanted the users to be
able to design the letters themselves, placing a variable where the name
and address goes.  I found that since I am reading the document into a
variable, I needed to run that variable through this reg exp:
$field[0] =~ s/\$(\w+)/${$1}/g;
which allows access to the variables in the document.  The users then
can place the above listed variables anyplace in the document to have
the desired values placed at that location.

I don't understand why it works, just that it does.

Quinn






------------------------------

Date: Thu, 3 Dec 1998 16:46:36 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <F3EELo.HGJ@world.std.com>

mjd@plover.com (Mark Dominus) writes:

>In perl3, Larry decided it ould be good to allow interpolation of
>arrays (and array and hash elements and slices) inside of
>double-quoted strings.  But if the rule were as simple as that, it
>would have broken a lot of pre-existing code such as

>	print "From: mjd@plover.com";

Since Programming Perl says that Perl was invented to create code for
a distributed bugtracking system based on a modified Netnews system, I
would think that the "@" change would have broken some of the oldest
perl scripts. They probably had lots of e-mail address in double quoted
strings.

-- 
Andrew Langmead


------------------------------

Date: Thu, 03 Dec 1998 17:06:03 +0000
From: 23_skidoo <nospam23_skidoo@geocities.com>
Subject: wwwboard crash prevention (i hope)
Message-Id: <3666C4E0.5590@geocities.com>

as mentioned earlier, i found that i could crash wwwboard by getting
three people to submit a message at the same time. one of the things
that we noticed was that two of us got given the same message number on
the feedback screen although only one of them survived the process the
other presumably overwritten or never created in the first place.

looking at the list of subs that are called, the &get_number call comes
at the top, then everything else is done and _then_ &increment_number is
called. i don't know if this will fix it, time will tell (or an older +
wiser perl hacker), but it makes sense to me to delete the
&increment_number sub and the call to it and include elements of the sub
into &get_number. like so:

############################
# Get Data Number Subroutine

sub get_number {
   open(NUMBER,"$basedir/$datafile");
   $num = <NUMBER>;
   open(NUMBER,">$basedir/$datafile");
   if ($num == 99999)  {
      $num = "1";
   }
   else {
      $num++;
   }
   print NUMBER "$num";
   close(NUMBER);
}


hopefully this will stop people getting assigned the same message number
+ might solve the crashing problem. 

any feedback? has anyone else done this, am i stating the blindingly
obvious?

-23

p.s. remove nospam from my address to reply via email


------------------------------

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 4352
**************************************

home help back first fref pref prev next nref lref last post