[9175] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2793 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 2 22:07:19 1998

Date: Tue, 2 Jun 98 19:00:23 -0700
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, 2 Jun 1998     Volume: 8 Number: 2793

Today's topics:
    Re: [Q] system using grep (Michael J Gebis)
    Re: [Q] system using grep <rootbeer@teleport.com>
    Re: A problem with [\d]+ (Shaun Sides)
    Re: Best tool? (Shaun Sides)
    Re: Counter or Pause function in Perl? (Shaun Sides)
    Re: Counter or Pause function in Perl? (Larry Rosler)
    Re: Eerie Explorer error on Randal's site <rootbeer@teleport.com>
    Re: HELP: Parsing quoted strings <bowlin@sirius.com>
    Re: map in void context regarded as evil - suggestion chris+usenet@netmonger.net
    Re: map in void context regarded as evil - suggestion <zenin@bawdycaste.org>
    Re: map in void context regarded as evil - suggestion (Charles DeRykus)
    Re: More double standards out of the FSF (Christopher Browne)
        Net::Telnet without timeout <beske@worldnet.att.net>
        Perl and Javascript <vgopinat@cisco.com>
    Re: Perl and Javascript (Martien Verbruggen)
    Re: Perl on Windows32 (Ethan H. Poole)
    Re: Perl terminology <ask@netcetera.dk>
    Re: Programming Problems for Win NT <metcher@spider.herston.uq.edu.au>
    Re: reading (lots of) files in perl ? (Andrew Arensburger)
        Sendmail from CGI bug <noels@ozinet.zip.com.au>
    Re: Sendmail from CGI bug <rootbeer@teleport.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 3 Jun 1998 00:25:12 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: [Q] system using grep
Message-Id: <6l2558$d0m@mozo.cc.purdue.edu>

"Dave M. Lent [I]" <lentdm@cig.mot.com> writes:

}The following line is putting my Perl program into an infinite loop.  
}system("grep -i -l -w $keyword $filename");

}When I use this line the code works though:
}system("grep -i -l -w Technical $filename");

}Does anyone know why "system" will not accept the variable $keyword?   

What is in $keyword?  Whatever you answer, my next question is: are
you absolutely certain?  You might want to check it.

You might also want to run a "ps -deaflllll" or "ps -augxwwwww" to see what
arguments grep thinks it got.  This assumes grep fails to terminate,
and you run ps while grep is still going.

You might also want to try:
  system("echo -i -l -w $keyword $filename");
and see how that does.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Wed, 03 Jun 1998 01:21:04 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: [Q] system using grep
Message-Id: <Pine.GSO.3.96.980602181904.15370F-100000@user2.teleport.com>

On Tue, 2 Jun 1998, Dave M. Lent [I] wrote:

> The following line is putting my Perl program into an infinite loop.  
> system("grep -i -l -w $keyword $filename");

If you're right, that sounds like a bug in Perl. But I don't think you're
right. :-)  What's in $keyword and $filename? Any chance either one could
contain a shell metacharacter, such as a newline? 

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 3 Jun 1998 00:49:03 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: A problem with [\d]+
Message-Id: <slrn6n8l90.7jd.arch@abts.net>

Original message by: Walid ALSAQAF <e78199@ceng.metu.edu.tr>
Date: Tue, 02 Jun 1998 23:29:36 +0300
Subject: A problem with [\d]+


> Is there a difference between [\d] and \d. I have many occurrences of
> [\d] in my code, and I am worried that they might have to change all of
> them to \d .

 ...

This may be one more newbie thing on my part, but I can't see why you'd
use [\d].  I can see why you'd use [^\d], but I don't understand the
need for brackets if you're only placing one token in them.  Wouldn't
/^(\d+)/ work?  ::shrug, I'm probably wrong again ;-)::

-- 
==============================================================================
	   Shaun L. Sides	    | Hey!  CyberGold |     arch@abts.net
Free Randal Schwartz and Ric Flair! | wastes yer time | arch@sara.mmlc.nwu.edu
==============================================================================
	   The time for desperation is upon us.  Let's play.
		  First Wizard Zeddicus Zu'l Zorander
==============================================================================	


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

Date: 3 Jun 1998 00:52:37 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: Best tool?
Message-Id: <slrn6n8lfn.7jd.arch@abts.net>

Original message by: Abigail <abigail@fnx.com>
Date: 1 Jun 1998 15:49:22 GMT
Subject: Re: Best tool?


> ++ Probably a good web server and a good web browser. I'd use apache and
> ++ navagator.                       ^^^^^^^^^^^^^^^^
>    ^^^^^^^^^
> 
> Why don't you practise what you preach?

What's your choice in browsers?

I use Lynx 2.8.2.

-- 
==============================================================================
	   Shaun L. Sides	    | Hey!  CyberGold |     arch@abts.net
Free Randal Schwartz and Ric Flair! | wastes yer time | arch@sara.mmlc.nwu.edu
==============================================================================
	   The time for desperation is upon us.  Let's play.
		  First Wizard Zeddicus Zu'l Zorander
==============================================================================	


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

Date: 3 Jun 1998 00:58:29 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: Counter or Pause function in Perl?
Message-Id: <slrn6n8lqm.7jd.arch@abts.net>

Original message by: rickr <rickr@mail.net>
Date: Mon, 1 Jun 1998 10:56:36 -0700
Subject: Counter or Pause function in Perl?


> Is there a counter or pause function built into Perl?  I am currently
> achieving the pause effect by using
> 
> $count = 1;
> while (count < 500000) {
> $count ++;
> }
> 
> It's kind of a pain to have to keep using this.  I suppose I could build my
> own module, but I thought surely there is something like this already
> available, I just dont know what it's called.  Also, is there a clr or clear
> screen function?

For the first item:

	sleep n;	# where n = number of second to sleep

For the second item:

	system clear;	# would be one way to do it

hth. ;-)

-- 
==============================================================================
	   Shaun L. Sides	    | Hey!  CyberGold |     arch@abts.net
Free Randal Schwartz and Ric Flair! | wastes yer time | arch@sara.mmlc.nwu.edu
==============================================================================
	   The time for desperation is upon us.  Let's play.
		  First Wizard Zeddicus Zu'l Zorander
==============================================================================	


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

Date: Tue, 2 Jun 1998 18:32:28 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Counter or Pause function in Perl?
Message-Id: <MPG.fde4782ad86d5a5989690@hplntx.hpl.hp.com>

In article <slrn6n8lqm.7jd.arch@abts.net>, arch@abts.net says...
 ... 
> 	system clear;	# would be one way to do it
 ... 

 	system 'clear';	# would be the way to do it

assuming the 'clear' command is defined and accessible, of course.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Tue, 02 Jun 1998 23:54:51 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Eerie Explorer error on Randal's site
Message-Id: <Pine.GSO.3.96.980602164714.15370A-100000@user2.teleport.com>

On 2 Jun 1998, Neil Kandalgaonkar wrote:

> Subject: Eerie Explorer error on Randal's site

Eerie Explorer - it's kind of like MSIE, but every so often the
disembodied head of Bill Gates appears and moans scary things like
"Ohhh.... Federal meddling in free commerce! Whooooo.... Natural
monopoly... Windows '98... Buahahahaha!" :-)

> In MS Explorer I tried to load the page on www.stonehenge.com that allows
> you to donate to the Randal Schwartz defense fund.
> 
> Explorer threw up an error message saying:
> 
> "performed an illegal operation... will be terminated immediately". Eeek!

Don't worry. It's true that Randal was convicted of performing an illegal
operation, but he is in no danger of being terminated immediately. We all
hope he'll be around for years to come.

> Then there was the helpful message suggesting I contact the vendors of
> Explorer if the problem persists...

Why? Do they know how to fix problems? :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 02 Jun 1998 17:30:50 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: Mario D'Alessio <dalessio@manatee.cig.mot.com>
Subject: Re: HELP: Parsing quoted strings
Message-Id: <3574993A.B7B43003@sirius.com>

Mario D'Alessio wrote:
> 
> dalessio@manatee.cig.mot.com (Mario D'Alessio) writes:
> 
> >I writing a simple parser and I need to be able to parse quoted
> >strings. For example, let's say I want read the following line and
> >grab each quoted string: [snip]

> I'm following up on my own post. I did this as a possible solution:
> 
>     $line =~ s:\\":<QUOTE>:g;
>     @strings = $line =~ /"([^"]*?)"/g;
>     map( s:<QUOTE>:\\":g, @strings );
> 
> and my output is just what I wanted:
> 
>     STRINGS: a word%another word%word is \"help\"%third word
> 
> However, I'd really like a solution (if possible) in the
> RE itself since it will help me learn more about REs.

Try:

@strings = $line =~ m/"((?:[^"\\]|\\.)*?)"/g;

-- Jim Bowlin


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

Date: 3 Jun 1998 00:42:22 GMT
From: chris+usenet@netmonger.net
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <6l265e$n1o$1@schenectady.netmonger.net>

In article <wk3edno5du.fsf@turangalila.harmonixmusic.com>,
Dan Schmidt  <dfan@harmonixmusic.com> wrote:
> Tom Christiansen <tchrist@mox.perl.com> writes:
> 
> | I can't see why people use
> | 
> |     map  { s/foo/bar/ } @list;
> |     grep { s/foo/bar/ } @list;
> | 
> | when they could more clearly write:
> | 
> |     for (@list) { s/foo/bar/ } 
> | 
> | Put the important thing first.
> 
> Sometimes it is more convenient or idiomatic to phrase your statement
> in the form "perform this action on these objects" rather than "take
> these objects, and perform this action on them."  It's a matter of
> taste to me.

That's one of the reasons the next version of Perl will have

  s/foo/bar/ for @list;

which is a rather logical extension of the syntax.  Yay Chip.
-- 
	    Christopher Masto <chris+usenet@netmonger.net>
	Director of Operations, NetMonger Communications, Inc.

		     "Behold the Power of Cheese"


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

Date: 3 Jun 1998 00:57:42 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <896835969.843546@thrush.omix.com>

Russ Allbery <rra@stanford.edu> wrote:
: It's less intrusive.  Count the number of characters of markup per amount
: of text.  If HTML were as light-weight as POD, I doubt anyone would
: complain about it.
	>snip<

	When <insert a shell newsreader here> can handle POD, sure.

	Hmm...maybe I should add it to my hacked up tin, it couldn't be to
	hard to do the simple highlight tags.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Wed, 3 Jun 1998 01:07:15 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <EtyB43.5AM@news.boeing.com>

In article <slrn6n7tkf.opj.Tom.Grydeland@mitra.phys.uit.no>,
Tom Grydeland <Tom.Grydeland@phys.uit.no> wrote:
>
>Many OPs in Perl know what context they're called in and modify their
>behaviour to fit the requirement.  For instance, C<scalar keys %hash>
>will not need to create the list of keys in %hash and then count it; it
>will simply grab the number of keys from somewhere.
>
>The major complaint about using C<map> in void context is that it
>creates a (possibly large) return value which is then discarded.
>
>Wouldn't it be possible to make C<map> recognise when it's called in
>void context and *not* create the return list in these cases?
>

Maybe, there's some real design ambiguities that could occur
but I've always wondered why map (grep and sort too for that
matter) couldn't have a slight semantic frill: 

   @items = map { s/foo/bar/ };  # elided RHS list defaults to LHS 

instead of the tautological looking:

   @items = map { s/foo/bar/  } @items; 

or, similarly:

   @items = sort { $a <=> $b };   
   @items = grep(/condition/);


Lots of void context people could quietly slip out of the closet 
and back into the pews of righteousness.  Procedural programmers 
could get a good night's sleep. Laziness would be vindicated... 

:)


--
Charles DeRykus


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

Date: 3 Jun 1998 00:58:41 GMT
From: cbbrowne@news.hex.net (Christopher Browne)
Subject: Re: More double standards out of the FSF
Message-Id: <6l2741$jui$5@blue.hex.net>

On Tue, 2 Jun 1998 01:08:00 GMT, robert havoc pennington <hp@pobox.com> wrote:
>Because he posted a flame titled "GPL == unspeakable evil." I don't
>want to get into "he started it," but it is indeed the case that
>everyone was happily letting TC do whatever he wanted until he
>randomly posted some very inflammatory material. The much-cited
>gnu.org comment simply didn't merit this. Thus he got
>flamed. Basically an unsurprising outcome.
>
>Nonetheless, the thread appears to have died, and undoubtedly Tom
>C. and the FSF will both continue doing the same things they were
>doing before, e.g. working on their respective projects and ignoring
>each other.

And I was quite pleased to see, late in the discussions, some comments
by both TC and RMS that suggested resolution of at least *some* of the
issues on both sides. 

- RMS suggested that it would be a good idea for documentation to
explicitly indicate that readers may freely use the code found therein.

- TC responded indicating that this seemed to be a good idea to him. 

This may not mean that TC adopts the GPL or that RMS adopts the
"Artistic License," but there certainly did not seem to be rancor on
either side. 
-- 
As usual, this being a 1.3.x release, I haven't even compiled this
kernel yet.  So if it works, you should be doubly impressed. (Linus
Torvalds, announcing kernel 1.3.3 on the linux-kernel mailing list.) 
cbbrowne@hex.net -  <http://www.hex.net/~cbbrowne/lsf.html>


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

Date: Tue, 02 Jun 1998 21:46:10 -0400
From: Bryan Beske <beske@worldnet.att.net>
Subject: Net::Telnet without timeout
Message-Id: <6l29uq$lt@bgtnsc03.worldnet.att.net>

How to you construct a cmd() call that will
wait forever and not timeout?

Thanks

Bryan



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

Date: Tue, 02 Jun 1998 17:25:53 -0700
From: Gopinath Venkataramanan <vgopinat@cisco.com>
Subject: Perl and Javascript
Message-Id: <35749810.6CEFDFF9@cisco.com>

I am a novice to Javascript and am trying the following code

when the while loop returns one row from oracle, the javascript
functions work, whereas if there are multiple records, they don't, u
know why?

while (($product_id,$list_price,$std_cost) = &ora_fetch($csr))
{
 print "<INPUT TYPE=text NAME=\"p_id\" value=$product_id SIZE=20>\n";
 print "<INPUT TYPE=text NAME=\"l_price\" value=$list_price SIZE=5>\n";
 print "<INPUT TYPE=text NAME=\"s_cst\" value=$std_cost SIZE=5
onChange=\"compute(this.form)\">\n";
 print "<INPUT TYPE=text NAME=\"s_test\" SIZE=5
onChange=\"form1.s_test1.value=this.value*10\">\n";
 print "<INPUT TYPE=text NAME=\"s_test1\" SIZE=5>\n";
 print "<BR>";
 $counter++;
}

thanx for ur time
regds.



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

Date: 3 Jun 1998 00:49:11 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl and Javascript
Message-Id: <6l26i7$8ho$1@comdyn.comdyn.com.au>

In article <35749810.6CEFDFF9@cisco.com>,
	Gopinath Venkataramanan <vgopinat@cisco.com> writes:
> I am a novice to Javascript and am trying the following code
> 
> when the while loop returns one row from oracle, the javascript
> functions work, whereas if there are multiple records, they don't, u
> know why?

Who is "u"?

What does "don't work" mean in this context?

This most likely has nothing to do with perl. Have a look at the HTML
this piece of perl produces, and see what is wrong with that, if
anything.

You might then go to one of the comp.infosystems.www.* groups and ask
there.

> while (($product_id,$list_price,$std_cost) = &ora_fetch($csr))
> {
>  print "<INPUT TYPE=text NAME=\"p_id\" value=$product_id SIZE=20>\n";
>  print "<INPUT TYPE=text NAME=\"l_price\" value=$list_price SIZE=5>\n";
>  print "<INPUT TYPE=text NAME=\"s_cst\" value=$std_cost SIZE=5
> onChange=\"compute(this.form)\">\n";
>  print "<INPUT TYPE=text NAME=\"s_test\" SIZE=5
> onChange=\"form1.s_test1.value=this.value*10\">\n";
>  print "<INPUT TYPE=text NAME=\"s_test1\" SIZE=5>\n";
>  print "<BR>";
>  $counter++;
> }

This will work fine as far as perl is concerned.  It will neatly print
out a bit of HTML for each returned row line. Of course, the HTML
might confuse the hell out of anything that has to work with those
form elements, including the Javascript, because you have multiple
elements with the same name.

> thanx for ur time

I didn't give you any "ur" time. How confusing.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.       | cynical. It's perfectly easy to be
NSW, Australia                      | cynical.


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

Date: 3 Jun 1998 01:42:02 GMT
From: ehp@gte.net (Ethan H. Poole)
Subject: Re: Perl on Windows32
Message-Id: <6l29la$shu$1@gte2.gte.net>

In article <357400ff.0@208.192.224.3>, andy@interactive.net says...
>
>go.  If you are unlucky enough to be forced into using IIS, get IIS
>and write for it.  IIS for requires that you modify (ie. rewrite
>almost completely) your script if you are coming from unix or Apache
>if you do anything except for plain http.

As an individual who has ported *many* scripts from various Unix environments 
to Windows NT IIS servers, I can say from experience that the above line is 
literally typical Unix vs. Windows BS.

A simple modification to @INC is typically the most that is required to get all 
of the "require" statements in a given script to function properly.  I can 
hardly call the addition of a few lines of code a "rewrite almost completely" 
type job.

Just add:

BEGIN
{
    push (@INC, '/the/path/with/the/requires');
}

Before the first "use" or "require" statement, and all will once again be well 
with the world.

-- 
Ethan H. Poole            | Website Design and Hosting,
                          | CGI Scripting...
========Personal========= | ============================
* ehp @ gte . net *       | --Interact2Day--
http://home1.gte.net/ehp/ | http://www.interact2day.com/



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

Date: 03 Jun 1998 02:57:11 +0200
From: Ask Bjoern Hansen <ask@netcetera.dk>
Subject: Re: Perl terminology
Message-Id: <m3wwazti8o.fsf@balder.netcetera.dk>

Bill Anderson <recon@cavalry.com> writes:

> For reference, I use "The Perl 5 Programmer's Reference".
> 
> Not sure of the technical accuracy of *all* of it, but works well for
> me.
> I do reccomend it for beginners, because it provides ane asy way to look
> up a given perl command without having to look through how-to-do-this
> chapters when all you really want is the syntax and what it *does*.

$ perldoc -f function

works for me.


ask


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

Date: Wed, 03 Jun 1998 11:12:33 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Programming Problems for Win NT
Message-Id: <3574A301.A088CF56@spider.herston.uq.edu.au>

EEE Computing Lab wrote:
> 
> I need to write a Perl Script for a program to scan files on a drive
> to detect :
> 
> 1. which version of the windows NT is being run

$version = `ver`;

> 2. any service packs/hot fixes installed

Use the Win32::Registry module, or spawn a command line registry editor,
and look at the appropriate keys (HKLM\Software\Microsoft\Windows
NT\CurrentVersion might be a good place to start).

> 3. illegal software installed in the system(e.g. "back door", trojan
> horse,
> etc)

Use the File::Find module to rummage through your hard disk.  It's up to
you to decide what you think is a suspicious file.  Maybe you'd like to
keep a snapshot of all .exe and .dll filenames, and compare against
that.

> 
> The program may be web-based and has to run on Win NT 4.0
> 

You'll need a web server.  You'll need to know enough HTML to set up a
form.  The CGI module will help your program interact with the form. 
There are various FAQs about how to set up perl to work with various web
servers.  A good starting point to find the FAQs is http://www.perl.com.

> My problem is that i dont know how to set about doing this since my
> experience in Perl is pretty basic. Any idea how to go about
> it, or are there such scripts available anywhere on the web?
> 

If you're starting from scratch, you've bitten off a big one.  This will
be a great learning experience!  But if your intention is to cobble
something together and never use the skills again, forget it.  The only
way this will be worth it will be if you use what you learn again.

Forgive me if I'm assuming that you know less than you really do, but
you'll need to learn about:
1. Running a web server.  On NT server, IIS can be an easy way to start
(but don't beleive everything Microsoft tells you about ASP or ISAPI. 
If you go down that route, you're stuck with IIS).
2. CGI programming (lots of FAQs on the web, but remember that CGI.pm
does most of the work for you).
3. Perl (http://www.perl.com, and buy "Programming Perl" by Larry Wall,
Tom Christiansen and Randal Schwartz).
4. HTML (lots of FAQs on the web).

> Hope that you will reply soon.. thanks.. your help would be very much
> appreciated...
> 
> Problem Child
> please email to: bn770521@ntu.edu.sg


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

Date: 3 Jun 1998 01:37:19 GMT
From: arensb@umiacs.umd.edu (Andrew Arensburger)
Subject: Re: reading (lots of) files in perl ?
Message-Id: <6l29cf$2fn$2@walter.cs.umd.edu>

scottse@my-dejanews.com wrote:
> What I'm trying to do is read a large number of files and then create a final
> variable from the contents of the files joined with some data from another
> source.

	If I understood correctly, you have a directory with a bunch
of files:
		header
		question1
		question2
		...
		question999

and you want to print out the contents of
		header
		question1
		header
		question2
		...
		header
		question999
Is this correct?

> #!/usr/local/bin/perl

> $primary_so = 12345;

> @question_html_array = ('question_header.html','question_body1.html');

	A word about identifiers: it's good that you're using long
identifiers. However, conciseness can also be good: all of these
variable names begin with "question_" or "question_html_", and start
to look the same after a while.
	I'd have written this line as:

@filenames = (
	'question_header.html',
	'question_body1.html',
#	...
#	'question_body999.html',
);

> %question_html_file_array =
> ("question_header.html","question_header","question_body1.html","question_bod
> y1");

	Just for esthetics, I'd have written this as
%question_html_file_array = (
	"question_header.html"	=> "question_header",
	"question_body1.html"	=> "question_body1",
);

> $question_html_files = @question_html_array;

	This looks weird (at least to me). Assigning an array to a
scalar? If I remember correctly, Larry Wall said in the manual that
there's no obvious interpretation for this, so he settled for making
it mean "size of the array", but I wouldn't use it.
	Instead, you can use Perl's "last-element" syntax:

$question_html_files = $#question_html_array + 1;

> for ($question_html_count = 0; $question_html_count != $question_html_files;
> $question_html_count++) {
> 	$FILE_HANDLE =
> ($question_html_file_array{$question_html_array[$question_html_count]});
> 	$INPUT_FILE = ("/opt/local/http/ifsdoc-cgi-bin/html/" .
> $question_html_array[$question_html_count]);
> 	open (FILE_HANDLE,INPUT_FILE) || die ("Error reading : $!;");
> };

	Okay, this is confusing. It looks as if you want to open a
whole bunch of files simultaneously, in order to read them later
(except that there appear to be a few syntax errors).
	One programming rule that I try to follow is, once you've
written the open(), immediately write the corresponding close() [1].
Here, you have an open(), but no close(). And inside a loop, yet. So
if you have a thousand files in your directory, you're going to have a
thousand file handes to keep track of at once. Gah!

[1] This is derived from the C adage, "Once you've written a malloc()
statement, immediately write the corresponding free(). If you're not
sure where to put it, then you've almost certainly introduced a memory
leak."

> @question_header = <question_header>; # is there any way to do this in
> @question_body1 = <question_body1>;   # the for loop ?

	Here, you're slurping all of the text in the file into an
array. In other words, you're storing the whole file in memory.
Presumably, in your real code (as opposed to the trimmed-down version
that you posted), you're slurping a thousand files into memory all at
once. This is inefficient, and I believe I've managed to make Perl
dump core this way in the past.

> $question_string = join (@question_header,$primary_so,@question_body1);

> print $question_string;

	Okay, here you're joining the contents of the files, printing
them, and throwing away the results. In short, all you wanted to do in
the first place was just print out the contents of those files.

	Let's rewrite this a bit:

#!/usr/local/bin/perl

# $DATADIR: the directory where all of the files are located.
# This is the sort of thing that might change from one site to the
# next, and as a rule, it's a good idea to make this a configuration
# variable and put it at the top of the script.
$DATADIR = "/opt/local/http/ifsdoc-cgi-bin/html";

# $header
# This is the name of the file that contains the header that should go
# at the top of each file. Alternately, if the header is reasonably
# short and never varies, you may want to use
#	$head_text = <<EndOfHeader;
#	This text will appear at
#	the top of each file.
#	EndOfHeader
$header = "question_header.html";

# @filenames
# The list of files that you want to print out. These files are all in
# $DATADIR. If this list is likely to change a lot, you may want to
# read @filenames from a file.
@filenames = (
	"question_body1.html",
	"question_body2.html",
	"question_body3.html",
#	...
#	"question_body999.html"
);

# main loop:
# Go through the list of files; print the header and the contents of
# the file.
foreach $filename (@filenames)
{
	# Print the header
	open(HEADER, "$DATADIR/$header") or
		die("Can't open $DATADIR/$header: $!\nDying");
	# Read each file and print it.
	while (<HEADER>)
	{
		print;
	}
	close(HEADER);			# When writing, write the open(),
					# then write the close(), and only
					# then write what goes in between.

	# Print the body of the file
	open(INFILE, "$DATADIR/$filename") or
		die("Can't open $DATADIR/$header: $!\nDying");
	while (<INFILE>)
	{
		print;
	}
	close(INFILE);
}


Hope this helps.

--
Andrew Arensburger, Systems guy		Center for Automation Research
arensb@cfar.umd.edu			University of Maryland
	     Computers work in weird and marvelous ways,
		  their wonders to avoid performing.


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

Date: Wed, 3 Jun 1998 09:51:25 +1000
From: "Noel Sampol" <noels@ozinet.zip.com.au>
Subject: Sendmail from CGI bug
Message-Id: <6l235o$h2$1@the-fly.zip.com.au>

Hi...

I have a perl CGI script that sends mail thru sendmail - it seems to work
with most e-mails but when I use my alias e-mail it processes it but doesn't
seem to send the mail to the alias address.  I have the follwoing code
fragment:

Please help.

Thanks

Noel Sampol
noels@69ozinet.zip.com.au

NOTE: Remove '69' from address when replying

$mailprog = "/usr/bin/sendmail";
$owner_name = "Noel Sampol";
$owner_email = 'noels@zip.com.au';  # this is my real address

$email = 'noels@ozinet.zip.com.au'; # this is from HTML form and it's an
alias address

# Send confirmation e-mail to owner
#open (MAIL, "|$mailprog $owner_email");
#open (MAIL, '|$mailprog -n $owner_email');
#$command = "$mailprog \-n $owner_email";
#open (MAIL, "|-") || exec ($command) || die "Can't open $mailprog!\n";
open (MAIL, "| $mailprog -n -oi -t");

if ($email) {
        print MAIL ("From: $first_name $surname <$email>\n");
} else {
        print MAIL ("From: $first_name $surname\n");
}
print MAIL ("To: $owner_email\n");
print MAIL ("Subject: Visitor Feedback\n\n");
print MAIL ("$first_name $surname has sent you some feedback.\n\n");
print MAIL ("The feedback follows:\n\n");

print MAIL ("$first_name $surname\n");
if ($email) {
   print MAIL ("$email\n");
}
if ($comments) {
   print MAIL ("$comments\n");
}
close(MAIL);

# Send confirmation e-mail to visitor
#open (MAIL, "|$mailprog $email");
#open (MAIL, '|$mailprog -n $email');
#$command = "$mailprog \-n $email";
#open (MAIL, "|-") || exec ($command) || die "Can't open $mailprog!\n";
open (MAIL, "| $mailprog -n -oi -t");

print MAIL ("From: $owner_name <$owner_email>\n");
print MAIL ("To: $email\n");
print MAIL ("Subject: Visitor Feedback - Thank You\n\n");
print MAIL ("$first_name $surname,\n\n");
print MAIL ("Thank you for sending us your feedback!  ");
print MAIL ("Your details will be kept strictly confidential.\n\n");
print MAIL ("Thanks again ;-)\n\n");
print MAIL ("$owner_name\n\n");
#print MAIL ("$owner_email\n\n");
close(MAIL);

print ("Content-Type: text/html\n\n");
print ("<html><head><title>Thank You</title></head>\n");
print ("<body><center><h1>Thank You For Your Input</h1><hr>\n");
print ("Thank you for sending us your feedback.\n");
print ("Here is what you sent:<br><br>\n");
print ("<b>$first_name $surname</b><br>\n");
if ($email) {
        print ("<b>$email</b><br>");
}
if ($comments) {
        print ("$comments<br>");
}
print ("</center></body></html>\n");

exit;





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

Date: Wed, 03 Jun 1998 01:24:45 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Sendmail from CGI bug
Message-Id: <Pine.GSO.3.96.980602182144.15370G-100000@user2.teleport.com>

On Wed, 3 Jun 1998, Noel Sampol wrote:

> I have a perl CGI script that sends mail thru sendmail - it seems to work
> with most e-mails but when I use my alias e-mail it processes it but doesn't
> seem to send the mail to the alias address.  

Sounds as if it's a problem with sendmail, rather than with Perl. 

If you're using the proper commands to run another program from perl, but
the other program doesn't cooperate, then it's the other program's fault.
If you're not using the proper commands, then it's your fault. If you
aren't sure about the proper commands, you should read the program's
documentation. If you've read it and you're still not sure, you should ask
in a newsgroup about the program.

Hope this helps!

> NOTE: Remove '69' from address when replying

> From: Noel Sampol <noels@ozinet.zip.com.au>

Hmmm... Looks as if you already did. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

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

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