[10051] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3644 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 5 17:06:56 1998

Date: Sat, 5 Sep 98 14:00:20 -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           Sat, 5 Sep 1998     Volume: 8 Number: 3644

Today's topics:
    Re: #!/usr/bin/perl not working? (catPrompt)
    Re: A short question (Mark-Jason Dominus)
    Re: chmod 755 from a cgi output (Alastair)
    Re: chmod 755 from a cgi output <kevinbartz@geocities.com>
        Code to Check for acceptable file type <mhanson@prtel.com>
    Re: Code to Check for acceptable file type <kevinbartz@geocities.com>
    Re: Code to Check for acceptable file type <rootbeer@teleport.com>
    Re: Code to Check for acceptable file type <rra@stanford.edu>
    Re: Code to Check for acceptable file type <jeffp@crusoe.net>
    Re: Code to Check for acceptable file type <kevinbartz@geocities.com>
        Dallas/Ft. Worth Perl Mongers meeting (Brand Hilton)
    Re: Denver/Boulder Perl Mongers <eashton@bbnplanet.com>
    Re: Execute END{} at CGI termination? (Kenneth Herron)
    Re: help with mail sending. <kevinbartz@geocities.com>
        History of Perl - round 1 <eashton@bbnplanet.com>
        Limits on size of hashes and arrays? <aperrin@mcmahon.qal.berkeley.edu>
    Re: Limits on size of hashes and arrays? (Alastair)
        Lost in Database Land... <Bret@1stOrbit.com>
    Re: Newbie OO question (Jonathan Stowe)
        pass on value to subroutine call <jerom@xs4all.nl>
    Re: pass on value to subroutine call <garry@america.net>
    Re: pass on value to subroutine call <dcameron@bcs.org.uk>
    Re: pass on value to subroutine call <dcameron@bcs.org.uk>
    Re: Perl gurus opinion needed. <eashton@bbnplanet.com>
    Re: reading a file backward (Jonathan Stowe)
    Re: reading a file backward (Larry Rosler)
    Re: Tom Phoenix: ANSWERS WANTED! (Norman UNsoliciteds)
    Re: Use Perl to sendmail: open once, send multiple time (Michael Wang)
    Re: Use Perl to sendmail: open once, send multiple time (Greg Andrews)
        writing/retrieving complex data structures (Peter Bismuti)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Sat, 05 Sep 1998 14:51:28 -0400
From: "Mike List(catPrompt)" <troll@net-link.net>
Subject: Re: #!/usr/bin/perl not working?
Message-Id: <35F18830.491F14BE@net-link.net>

Dennis M. Parrott wrote:
> 
> Jeff Pinyan wrote:
> >
> > > Andrew Mulvey <triangle@iinet.net.au> wrote:
> > >
> > > I can easily run perl scripts I have written in Linux (RH5.0) by typing
> > > "perl exename" at the shell prompt but even if i start the script with
> > > #!/usr/bin/perl my script won't run simply by entering its name at the
> > > prompt (and yes i have set the file the script is saved in as executable
> > > by u, g and o). The perl exe is sitting in /usr/bin btw.
> >
> > It might be the curse of the screwy path.
> > Try typing ./exename instead of just exename.  If that works, then that
> > means that for some fruity reason, the . directory is not in your path.
> > It needs to be added to your path.
> >
> 
> depending on who set up the path for Andrew, it *may* have been left
> out on PURPOSE. I don't remember where I read it, but, there are some
> admins who consider having "." in the PATH as a security risk (and I
> may not have the whole story here either -- it may well relate to the
> position of "." in the PATH)
> 
> possibly some of our other more Unix-admin fluent readers could
> confirm this...

Using "." in your path isn't necessarily bad, but adding it first is a
serious softspot, since "." doesn't mean "HOME", more like "PWD". this
means that a miscreant could write a script called ls and put it in a
directory that doesn't usually have a copy of ls in it. This script
could contain any instructions in it, even rebooting or formatting your
drive, sending a copy of your password script, or practically any job
you wouldn't normally associate with ls, including a call to ls, so you
wouldn't get suspicious. The advice I've been given is to put"." last in
the path, so if a real occurrence of that file, ie ls exists anywhere
but inthe PWD, it will be sourced first. You can judge by your own
security priorities whether you need to follow that advice.
> 
> all of this is a long way of saying that leaving "." is probably not
> due to a 'fruity reason'...
> 
> > Jeff Pinyan
> > Crusoe Communications, Inc.
> > 973-882-1022
> > jeffp@crusoe.net
> > ICQ 10222129
> > www.crusoe.net
> 
> --
> 
> -----------------------------------------------------------------------
> Dennis M. Parrott        |            Unix:  dparrott@ford.com
> PCSE Webmaster           |           PROFS:  DPARROTT
> Ford Motor Company       |             VAX:  EEE1::PARROTT
> Dearborn, Michigan USA   | public Internet:  dparrott@ford.com
> -----------------------------------------------------------------------
> Voice: 313-322-4933  Fax: 313-248-1234  Pager: 313-851-2958

-- 


-Mike List


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

Date: 5 Sep 1998 14:07:53 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: A short question
Message-Id: <6srulp$6c9$1@monet.op.net>

In article <35f11fdd.6175272@news.btinternet.com>,
Jonathan Stowe <Gellyfish@btinternet.com> wrote:
>Whilst not shorter this will work whatever the file is called:
>
>seek(DATA,0,0);while (<DATA>){ print };
>__END__

I forget who made this up, but it's incredibly clever, and it's a lot
shorter than yours:

	open 0;print<0>

Other than the empty program, this is the shortest one I've seen.
Although now that I think about it,

	print`cat $0`

is two characters shorter, although far, far less clever.

>You could of course have used $0 instead of an explicit filename.

I'll say!


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

Date: Sat, 05 Sep 1998 18:14:18 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: chmod 755 from a cgi output
Message-Id: <slrn6v33ia.ck.alastair@calliope.demon.co.uk>

jeff2591@my-dejanews.com <jeff2591@my-dejanews.com> wrote:
>Can someone tell me how to make my cgi output
>created from:
>pring Content-type: text/html
>set to where i can use server side includes.

Please choose a 'subject' to your post that has some relevance to your content.

'Server side includes' are a web server configuration issue and you would be
best asking in a news group about web servers. Many programming languages can be
used for CGI - do you have a Perl question?

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Sat, 5 Sep 1998 09:57:03 -1000
From: "Kevin Bartz" <kevinbartz@geocities.com>
Subject: Re: chmod 755 from a cgi output
Message-Id: <6ss5rv$1tm$1@supernews.com>

Anything that you print in a cgi file using the line:

print "Completely and utterly disgusting...";

will be inserted if you use SSI in your HTM page as such:

<!--#exec cgi="disgusting.cgi"-->

Then it would replace the SSI command with "Completely and utterly
disgusting..." in your htm page.

--- Kevin Bartz

jeff2591@my-dejanews.com wrote in message
<6srmo3$e74$1@nnrp1.dejanews.com>...
>Can someone tell me how to make my cgi output
>created from:
>pring Content-type: text/html
>set to where i can use server side includes.
>
>For example,
>at:
>http://www.lifesprings-resources.com/
>index2.html
>you'll notice the random stuff going on using ssi.
>
>But at:
>http://www.lifesprings-resources.com/cgi-bin/
>jsearch.cgi
>you'll notice the ssi stuff doesn't work. The page
>header is the same.
>
>I know it's possible because there are all these
>search engines with ads at the tops of their pages
>but you're actually in the cgi script still.
>
>Is there help out there?
>
>
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




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

Date: Sat, 05 Sep 1998 14:06:09 -0500
From: Mike <mhanson@prtel.com>
Subject: Code to Check for acceptable file type
Message-Id: <35F18BA1.6F00@prtel.com>

@array = ("htm", "html", "shtml"); #array of acceptable file types.
$string = "index.htm"; #Yield acceptable
$string2 = "index2.shtml"; #Yield acceptable
$string3 = "pic.gif"; #yield unacceptable
How would you check to make sure the file extension in the string is an
acceptable file type that is stored in an array?
Thanks.


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

Date: Sat, 5 Sep 1998 10:06:22 -1000
From: "Kevin Bartz" <kevinbartz@geocities.com>
Subject: Re: Code to Check for acceptable file type
Message-Id: <6ss5s5$1tm$3@supernews.com>

Use this code:

($filename,$extension)=split(".",$string);
$good=0;

foreach $disgusto (@array) {
if ($extension eq $disgusto) {
print "Congratualations... you've given me an excellento file extension!";
$good=1;
}
}

if ($good==0) {
print "Uh-oh! Disgusto! You've given me a completely and utterly disgusting
file extension. We ONLY accept these:\n";
foreach $it (@array) {
print "$it\n";
}
}

You will need to repeat this code for every string you need to detect, so
you may want to put the strings in an array and loop through the members.
Hope this helps...

--- Kevin Bartz

Mike wrote in message <35F18BA1.6F00@prtel.com>...
>@array = ("htm", "html", "shtml"); #array of acceptable file types.
>$string = "index.htm"; #Yield acceptable
>$string2 = "index2.shtml"; #Yield acceptable
>$string3 = "pic.gif"; #yield unacceptable
>How would you check to make sure the file extension in the string is an
>acceptable file type that is stored in an array?
>Thanks.




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

Date: Sat, 05 Sep 1998 20:26:23 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Code to Check for acceptable file type
Message-Id: <Pine.GSO.4.02A.9809051325050.8266-100000@user2.teleport.com>

On Sat, 5 Sep 1998, Kevin Bartz wrote:

> Use this code:
> 
> ($filename,$extension)=split(".",$string);

I don't think that does what you think it does. Remember, anything which
matches split's deliminator is discarded. Hope this helps!

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



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

Date: 05 Sep 1998 13:38:38 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Code to Check for acceptable file type
Message-Id: <yln28ejnw1.fsf@windlord.stanford.edu>

Mike <mhanson@prtel.com> writes:

> @array = ("htm", "html", "shtml"); #array of acceptable file types.
> $string = "index.htm"; #Yield acceptable
> $string2 = "index2.shtml"; #Yield acceptable
> $string3 = "pic.gif"; #yield unacceptable

> How would you check to make sure the file extension in the string is an
> acceptable file type that is stored in an array?

First, note that in order to check to see if something's in the array,
you'd have to traverse the array each time.  Whenever you're traversing
arrays in Perl to try to find something, that's usually a clear sign that
you should have used a hash.  So the first suggestion is to use a hash:

        %extensions = map { $_ => 1 } qw(htm html shtml)

(That's just shorthand for building an array of ('htm', 1) pairs to fill
up the hash; it's relatively common shorthand and I use it or something
like it quite a bit.)

Now you need to get the extension of the file name so that you can check
it.  You can either do that with a regular regex match, or you can use
something like File::Basename.  Personally, I prefer to just use a regex
for this:

        ($extension) = ($string =~ /\.([^./]+)$/);

which grabs everything after a period in the filename that doesn't include
another period or a /.

Then you can just check to see if $extensions{$extension} is true.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 5 Sep 1998 16:36:56 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Code to Check for acceptable file type
Message-Id: <Pine.GSO.3.96.980905163239.9531A-100000@crusoe.crusoe.net>

> ($filename,$extension)=split(".",$string);
> $good=0;
> 
> foreach $disgusto (@array) {
> if ($extension eq $disgusto) {
> print "Congratualations... you've given me an excellento file extension!";
> $good=1;
> }
> }
> 
> if ($good==0) {
> print "Uh-oh! Disgusto! You've given me a completely and utterly disgusting
> file extension. We ONLY accept these:\n";
> foreach $it (@array) {
> print "$it\n";
> }
> }

Tom Phoenix said that: ($filename,$extension) = split(".",$string) won't
work.  That's because . is a regex character that matches ANY character
(save newlines... oh, no bother).  So, try this code:


($file,$ext)	= split /\./, $string;
%hash		= map { $_, 1 } qw/ html shtml txt /;

if ($hash{$ext}){ print "'$ext' acceptable...\n"; }
else{ die "'$ext' not acceptable,"; }


Oh, and for the love of whatever it is you love the most, PLEASE INDENT.

Thank you, and have a nice Labor Day weekend.

Jeff Pinyan
Crusoe Communications, Inc.
973-882-1022
jeffp@crusoe.net
ICQ 10222129
www.crusoe.net



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

Date: Sat, 5 Sep 1998 10:48:04 -1000
From: "Kevin Bartz" <kevinbartz@geocities.com>
Subject: Re: Code to Check for acceptable file type
Message-Id: <6ss892$hhp$1@supernews.com>

Sorry, you will have to escape the period. Change the "." to "\."

--- Kevin Bartz

Kevin Bartz wrote in message <6ss5s5$1tm$3@supernews.com>...
>Use this code:
>
>($filename,$extension)=split(".",$string);
>$good=0;
>
>foreach $disgusto (@array) {
>if ($extension eq $disgusto) {
>print "Congratualations... you've given me an excellento file extension!";
>$good=1;
>}
>}
>
>if ($good==0) {
>print "Uh-oh! Disgusto! You've given me a completely and utterly disgusting
>file extension. We ONLY accept these:\n";
>foreach $it (@array) {
>print "$it\n";
>}
>}
>
>You will need to repeat this code for every string you need to detect, so
>you may want to put the strings in an array and loop through the members.
>Hope this helps...
>
>--- Kevin Bartz
>
>Mike wrote in message <35F18BA1.6F00@prtel.com>...
>>@array = ("htm", "html", "shtml"); #array of acceptable file types.
>>$string = "index.htm"; #Yield acceptable
>>$string2 = "index2.shtml"; #Yield acceptable
>>$string3 = "pic.gif"; #yield unacceptable
>>How would you check to make sure the file extension in the string is an
>>acceptable file type that is stored in an array?
>>Thanks.
>
>




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

Date: 5 Sep 1998 19:57:41 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Dallas/Ft. Worth Perl Mongers meeting
Message-Id: <6ss53l$bv7@mercury.adc.com>

The Dallas/Ft. Worth Perl Mongers will be holding our third
sorta-monthly meeting Real Soon Now:

  Wednesday, September 16th
  Juan's Cantina
  (southwest corner of 75 and Belt Line in Richardson)

Depending on whether The Perl Cookbook is in stores by then, I'll
either be giving away a copy of the book, or a Perl Mongers T-shirt.
Don't miss it!

To join our mailing list, just send me email to that effect.

        Brand
-- 
 _____ 
|///  |   Brand Hilton  bhilton@adc.com
|  ADC|   ADC Telecommunications, ATM Transport Division
|_____|   Richardson, Texas


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

Date: Sat, 05 Sep 1998 19:38:05 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Denver/Boulder Perl Mongers
Message-Id: <35F190C6.194D585@bbnplanet.com>

> >It may just be that I'm in Boulder not Denver, but it seems
> >counterproductive to hold a get together at a beer-drinking place
> >when people have to *drive* home. :-(
> 
> Hmm... good thing we started Perl Mongers in New York City, where
> almost *no one* drives home...  Might never have gotten off the ground
> otherwise.  :_)

david, new york is not the center of the universe :) hey, boston has a
'T' and cabs..hotel rooms even! who knew? though i would admit a cab
ride from denver to boulder would be pretty $$$. but cheaper than a dwi.


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

Date: 5 Sep 1998 17:29:30 GMT
From: kherron@campus.mci.net (Kenneth Herron)
Subject: Re: Execute END{} at CGI termination?
Message-Id: <6srsdq$oaq$1@news.campus.mci.net>

In article <MPG.105a0ffb9a335d80989796@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
|-0700, Mooneer Salem <mooneer@earthlink.net> says...
|...
|> Try setting $SIG{PIPE} as well as all of the other signals, like this:
|> 
|> $SIG{PIPE} = $SIG{HUP} = $SIG{INT} = $SIG{KILL} = $SIG{TERM} = sub {
|> &END };
|
|That *did* make a difference.  Now &END gets executed, four times!!!!  (I 
|know this because it appends four messages to the debug file.)  Why????
|
|But still no output to the browser (print STDOUT) from &END.  Netscape 
|Navigator appends a horizontal rule and 'Transfer interrupted!' to the 
|output; MSIE just stops quietly.  Where is the bit-bucket?

You need to understand what pressing the stop button actually does.
The stop button causes the browser to close its connection to the web
server; the web server is notified of the closure and closes the pipe
it's using to read from the CGI app.  The next time the CGI app tries
to write to its stdout/stderr, it receives a sigpipe ("write on a pipe
that has no reader").

The multiple sigpipes are probably due to the program trying to write
something to stdout or stderr as it quits.  Or it may be stdio or
perl repeatedly trying to flush buffered output.
-- 
Kenneth Herron -- kherron@campus.mci.net
"When Microsoft first took control of the Funk & Wagnalls Encyclopedia
product, there was a flattering biography of Bill Gates.  But it said he
was known as a tough competitor.  Now it says that he's known for his
charitable contributions." -- Gary Reback, <http://www.ljx.com/reback/>


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

Date: Sat, 5 Sep 1998 09:59:51 -1000
From: "Kevin Bartz" <kevinbartz@geocities.com>
Subject: Re: help with mail sending.
Message-Id: <6ss5s2$1tm$2@supernews.com>

Ahhh... I think you need to ask your server master what the path to sendmail
is. If you have telnet access you can type "which sendmail," but most people
don't have telnet access so you'll probably just have to ask your disgusto
server master. For now, here are a few other common paths you can try:

/usr/sbin/sendmail
/usr/slib/sendmail
/usr/bin/sendmail
/usr/local/slib/sendmail
/usr/local/sbin/sendmail
/usr/local/bin/sendmail

Hope this helps...

--- Kevin Bartz

Ewgeniy Kartavtchenko wrote in message <35f14f6e.18988370@news.ssau.ru>...
>Hi.
>
>I want to send email from perl-script without any questions and
>notifications. All of scripts, that i've seen, used
>"/usr/lib/sendmail" file. But it isn't work... Certainly, the way to
>solve it is exist, but I don't know it.
>Can anybody help me ? Of course, I'll be very thankful if somebody
>dlows some pl-code in me...
>
>EWG




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

Date: Sat, 05 Sep 1998 20:00:13 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: History of Perl - round 1
Message-Id: <35F195F6.B09A73B@bbnplanet.com>

since someone mentioned doing a history of perl i have taken an interest
in actually doing it. a few others have also expressed an interest in
helping research and write it sooo...the tentative thesis is 'the
history of perl as viewed through the sociological and economic forces
driving its development'. 

this may, or may not be the best approach so i'm open to ideas.  if you
have any fun facts, anecdotes, or anything that may be of interest, do
send them to me. hopefully, we'll do the paper justice.

e.

              -=]) elaine ashton // elaine@cts.wustl.edu ([=-
                     -=]) Do Not Taunt HappyFunBall ([=-


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

Date: Sat, 05 Sep 1998 10:17:15 -0700
From: Andrew Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Limits on size of hashes and arrays?
Message-Id: <35F1721A.55C45F3D@mcmahon.qal.berkeley.edu>

Greetings-

I'm thinking about writing some tools for qualitative data analysis in
Perl, and I'm wondering if there are specs on the maximum number of
elements in hashes and arrays.  Since the hashes/arrays I'll be using
are likely to get really huge (and indeterminately so), I'm hoping the
answer is 'no, based on the size of the machine's memory'.

--
-------------------------------------------------------------
Andrew J. Perrin - NT/Unix/Access Consulting -  (650)938-4740
aperrin@mcmahon.qal.berkeley.edu (Remove the Junk Mail King
http://socrates.berkeley.edu/~aperrin        to e-mail me)
    e-mail wheres-andy@socrates.berkeley.edu to find me!
-------------------------------------------------------------




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

Date: Sat, 05 Sep 1998 18:10:46 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Limits on size of hashes and arrays?
Message-Id: <slrn6v33bl.ck.alastair@calliope.demon.co.uk>

Andrew Perrin <aperrin@mcmahon.qal.berkeley.edu> wrote:
>Greetings-
>
>I'm thinking about writing some tools for qualitative data analysis in
>Perl, and I'm wondering if there are specs on the maximum number of
>elements in hashes and arrays.  Since the hashes/arrays I'll be using
>are likely to get really huge (and indeterminately so), I'm hoping the
>answer is 'no, based on the size of the machine's memory'.

Everything I've ever read suggests you're right.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Sat, 05 Sep 1998 10:17:04 -0700
From: Bret Beresford-Wood <Bret@1stOrbit.com>
Subject: Lost in Database Land...
Message-Id: <35F1720F.26BFAFF4@1stOrbit.com>

I'm looking for a good solution to build a fairly robust database which
can be hosted on a typical $20/month Unix server. I plan on using perl
and a free or relatively cheap RDBMS.

MySQL looks like a fairly good one but then it looks like some people
are just using flat file systems in perl.

My question is: to build good solid web-based databases using perl, what
database format are some of you using and why?

Any directions you can give to make me feel less lost would be very,
very appreciated!



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

Date: Sat, 05 Sep 1998 18:41:32 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Newbie OO question
Message-Id: <35f17753.23517676@news.btinternet.com>

On Sat, 05 Sep 1998 15:42:46 GMT, Randal Schwartz wrote :

>>>>>> "Jonathan" == Jonathan Stowe <Gellyfish@btinternet.com> writes:
>
>Jonathan> sub setSubs() {
>Jonathan>         my @list = ( 
>Jonathan>                 \&subzero,
>Jonathan>                 \&subone,
>Jonathan>                 \&main::subtwo
>Jonathan>         );
>Jonathan>         return \@list;
>Jonathan> }
>
>Although this is probably a snippet of a larger piece of code, I
>would have written this differently if it was intended to produce
>exactly this result:
>
>	sub setSubs() {
>		[
>			\&subzero,
>			\&subone,
>			\&main::subtwo,
>		];
>	}
>
>Much cleaner.  Don't create unnecessary intermediate variables unless
>they greatly add to the readability.
>

Er, yes, but I just took Andrews code and made it work without doing
ought else to it.  I do agree with you though.  

/J\
-- 
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>



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

Date: Sat, 05 Sep 1998 20:33:14 +0000
From: jeroen <jerom@xs4all.nl>
Subject: pass on value to subroutine call
Message-Id: <35F1A00A.3D5E9D13@xs4all.nl>

Hi there.

I could use your help with the following.

I'm trying to call subroutines. The subroutine to be called depends on
the value in an array. This goes fine, until I need to *pass on a value*
when calling a particular subroutine.

This is the code that keeps on troubling me:

for ($field=1; $field < ($#datatype+1); $field++) {
	$test = $datatype[$field];
	&$test;
}

If the datatype[$field] value is e.g. "timefield", the subroutine call
is:
	&timefield; 
and this works perfectly fine: the timefield subroutine is executed
beautifully.

For some types of datatype values I need to pass on a number to the
subroutine. To be specific, if the datatype[$field] value is
"afield(26)", the call needs to be: 
	&afield(26);
where 26 can be any number in the range 0-78.

Whatever I have tried so far, it does not execute the sub.
Now, I suspect it to be a precedence problem, but I cannot figure out
what I should add to have afield(26) be seen as a whole.

Is what I'm trying to do possible, and if so, how?

Any comments are highly appreciated.

Regards,
Jerom


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

Date: Sat, 05 Sep 1998 19:42:43 GMT
From: Garry Williams <garry@america.net>
Subject: Re: pass on value to subroutine call
Message-Id: <35F19477.53382D82@america.net>

Try this instead: 

	for ($field=1; $field < ($#datatype+1); $field++) {
		$test = $datatype[$field];
		$test =~ s/\((.+)\)$//;
		&$test($1);
	}

-Garry Williams

jeroen wrote:
> 
> Hi there.
> 
> I could use your help with the following.
> 
> I'm trying to call subroutines. The subroutine to be called depends on
> the value in an array. This goes fine, until I need to *pass on a value*
> when calling a particular subroutine.
> 
> This is the code that keeps on troubling me:
> 
> for ($field=1; $field < ($#datatype+1); $field++) {
>         $test = $datatype[$field];
>         &$test;
> }
> 
> If the datatype[$field] value is e.g. "timefield", the subroutine call
> is:
>         &timefield;
> and this works perfectly fine: the timefield subroutine is executed
> beautifully.
> 
> For some types of datatype values I need to pass on a number to the
> subroutine. To be specific, if the datatype[$field] value is
> "afield(26)", the call needs to be:
>         &afield(26);
> where 26 can be any number in the range 0-78.
> 
> Whatever I have tried so far, it does not execute the sub.
> Now, I suspect it to be a precedence problem, but I cannot figure out
> what I should add to have afield(26) be seen as a whole.
> 
> Is what I'm trying to do possible, and if so, how?
> 
> Any comments are highly appreciated.
> 
> Regards,
> Jerom


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

Date: 5 Sep 1998 19:54:06 GMT
From: "Duncan Cameron" <dcameron@bcs.org.uk>
Subject: Re: pass on value to subroutine call
Message-Id: <01bdd906$d3791180$0b3c63c3@dns.btinternet.com>

You're dealing with soft references.  Without having tried it, I would
expect something like

&{$afield(26)} to do what you want.

HTH

jeroen <jerom@xs4all.nl> wrote in article <35F1A00A.3D5E9D13@xs4all.nl>...
> Hi there.
> 
> I could use your help with the following.
> 
> I'm trying to call subroutines. The subroutine to be called depends on
> the value in an array. This goes fine, until I need to *pass on a value*
> when calling a particular subroutine.
> 
> This is the code that keeps on troubling me:
> 
> for ($field=1; $field < ($#datatype+1); $field++) {
> 	$test = $datatype[$field];
> 	&$test;
> }
> 
> If the datatype[$field] value is e.g. "timefield", the subroutine call
> is:
> 	&timefield; 
> and this works perfectly fine: the timefield subroutine is executed
> beautifully.
> 
> For some types of datatype values I need to pass on a number to the
> subroutine. To be specific, if the datatype[$field] value is
> "afield(26)", the call needs to be: 
> 	&afield(26);
> where 26 can be any number in the range 0-78.
> 
> Whatever I have tried so far, it does not execute the sub.
> Now, I suspect it to be a precedence problem, but I cannot figure out
> what I should add to have afield(26) be seen as a whole.
> 
> Is what I'm trying to do possible, and if so, how?
> 
> Any comments are highly appreciated.
> 
> Regards,
> Jerom
> 


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

Date: 5 Sep 1998 20:20:45 GMT
From: "Duncan Cameron" <dcameron@bcs.org.uk>
Subject: Re: pass on value to subroutine call
Message-Id: <01bdd90a$797d5840$0b3c63c3@dns.btinternet.com>

Whoops, didn't read your post correctly!

As well as the idea from Gary Williams, using eval should help. Try

eval $test


Duncan Cameron <dcameron@bcs.org.uk> wrote in article
<01bdd906$d3791180$0b3c63c3@dns.btinternet.com>...
> You're dealing with soft references.  Without having tried it, I would
> expect something like
> 
> &{$afield(26)} to do what you want.
> 
> HTH
> 
<Original post snipped>



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

Date: Sat, 05 Sep 1998 19:43:32 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Perl gurus opinion needed.
Message-Id: <35F1920D.5F99ED16@bbnplanet.com>

> What is _wrong_ with Perl guy? (Note my e-mail address :-)

nothing...just lacks a certain je nais sais qois...besides...not _all_
of us are guys :) at least not the last time i checked....

> Hi Elaine!

Hi Brent! 

$         -- Perl Evangelist --     

hmm...fearless leader of the new Perl 700 Club? Heal! i gave the man
perl and He can now walk!....i think i need a beer.

e.


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

Date: Sat, 05 Sep 1998 18:41:34 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: reading a file backward
Message-Id: <35f1810d.26007866@news.btinternet.com>

On Sat, 5 Sep 1998 08:37:21 -0700, Larry Rosler wrote :

[Posted to comp.lang.perl.misc and something different mailed.]

>[Posted to comp.lang.perl.misc and copy mailed.]
>
>In article <35f1383d.9815921@news.btinternet.com> on Sat, 05 Sep 1998 
>13:59:39 GMT, Jonathan Stowe <Gellyfish@btinternet.com> says...
>> On Sat, 05 Sep 1998 10:15:49 +0800, sekchye wrote :
>> 
>> >Hi.  I need to read in a huge log file line by line starting from last
>> >line to the first line.  
>... 
>> However if that is not the case then any solution is going to involve
>> reading the whole file in some way whether into an array or whatever.
>
>Obviously one must read the whole file in order to print it, but I don't 
>think it need all be in memory at once as you imply.  I just tossed the 
>following off:
>
>#!/usr/local/bin/perl -w
>use strict;
>
>my (@offsets, $offset);
>my $file = $0; # for testing
>
>open IN, $file or die "Couldn't open $file. $!\n";
>do { push @offsets, tell IN } while <IN>;
>while (defined ($offset = pop @offsets)) {
>    seek IN, $offset, 0 or die "Couldn't seek to $offset. $!\n";
>    print scalar <IN>;
>}
>__END__
>
>The file is never in memory more than one line at a time!
>

Larry you're barking mad mate.  Brilliant but barking nonetheless.
You obviously had more beer last night than I did.

>I thought I had read about this in perlfaq6 but couldn't find it.  What I 
>*had* read was the following from the Perl Cookbook, 8.4 "Reading a File 
>Backwards by Line or Paragraph":
>
>   You must read the lines into memory, then process them in reverse
>   order.  Needless to say, this requires at least as much available
>   memory as the size of the file.
>
>Now I can think of easy ways of improving my code, for example, by adding 
>logic to do backward seeks from the current position instead of simply 
>seeking from the beginning (which would make an enormous difference if 
>the file were on a sequential medium such as a tape).  But the big 
>question is this:
>

I think this approach must be a candidate for MJD's
IO::Handle::Backwards Idea.  I figured that I would just create a
temporary filehandle which was really the file written out in reverse
(as long as no-one looked under the bonnet they'd be happy).

>Are you and the Cookbook simply wrong about having to store the whole 
>file instead of an array of line offsets, or am I hallucinating?  How is 
>this approach different from indexing a database file to provide speedy 
>random access, except that here the index is created on the fly in 
>memory?
> 

Well there is no reason that you need'nt write this index out to a
file of course - however on a lightly loaded system I guess that all
those little allocations would be no problem - on a more heavily
loaded system (with a lot of swapping going on) however things might
vary to the extent that a bunch of allocations of any size might be
slow. I dunno.

/J\
-- 
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>



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

Date: Sat, 5 Sep 1998 12:57:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: reading a file backward
Message-Id: <MPG.105b2973429f924c98982c@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <35f1810d.26007866@news.btinternet.com> on Sat, 05 Sep 1998 
18:41:34 GMT, Jonathan Stowe <Gellyfish@btinternet.com> says...
 ... 
> Larry you're barking mad mate.  Brilliant but barking nonetheless.
> You obviously had more beer last night than I did.

Better than any alternative.

> I think this approach must be a candidate for MJD's
> IO::Handle::Backwards Idea.  I figured that I would just create a
> temporary filehandle which was really the file written out in reverse
> (as long as no-one looked under the bonnet they'd be happy).

That's one of the problems of open source, isn't it?  Anyone can read 
what you wrote, so you'd better watch out...

In fact, MJD mentioned it to me, and offered ideas about how to do the 
whole job reading the file once only.  I will pursue it as time permits.

> >Are you and the Cookbook simply wrong about having to store the whole 
> >file instead of an array of line offsets, or am I hallucinating?

Beer perhaps, but no hallucination, evidently.

 ...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 06 Sep 1998 05:40:38 +0900
From: No.unsoiliciteds@dead.end (Norman UNsoliciteds)
Subject: Re: Tom Phoenix: ANSWERS WANTED!
Message-Id: <No.unsoiliciteds-0609980540390001@cs11i36.ppp.infoweb.or.jp>

In article <6ska9g$h2$1@trader.ipf.de>, birgitt@hamburg.citde.net wrote:

> What almosts fascinates me, is that there is apparently this zealeous
> belief 
> in a couple of posters here assuming that clpm responses to newbie's
> FAQs
> are something of great importance. They are not. The answers to real
> Perl questions are -and they get always very good responses. 

I think the real issue here isn't the importance of the postings
themselves, _real_ perl questions don't exist - where do you draw the line
for deciding this? Does the posting have to have the word Perl in it, does
it have to ask some pertinent question to the structure of the language?
Does it have to be about a specific platform? One person's meat is
another's poison. What, however does seem to be an issue in this thread,
is the fact that someone actually takes it upon themselves to be helpful
and polite (or not). 

If you meet someone who's illiterate do you treat them like shit because
they don't know how to read? Some people do because they get to feel good
about knowing how to read, some people just pretend they didn't see
anything because it's too much trouble to do otherwise (for them), and a
few people do none of the aforementioned.

Of the three I personally find the first group more objectionable, here and IRL

-- 
It took a learned man to teach me the true meaning 
of ignorance - the willingness to believe learning 
is finite
Norman Unsoliciteds -The Wilderness Years, Boscara Press 1967


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

Date: 5 Sep 1998 16:38:34 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: Use Perl to sendmail: open once, send multiple times?
Message-Id: <6srpea$61l$1@news.ml.com>

Wotan <wotan@databasix.co> wrote:
>Its becuase you are piping each line to sendmail, instead of the
>entire thing at once.  As well as a slight formating error. Try
>something more like this:
>
>open(SENDMAIL, "|/usr/lib/sendmail -oi -t"); 
>      $a="From: <me\@me.com>\n";
>      $b="To: <$someone\@some.site>\n\n";
>      $c="$some_message\n";
>      print SENDMAIL "$a$b$c";

It does not solve of the problem. You still can not open once, mail
twice:

open(SENDMAIL, "|/usr/lib/sendmail -oi -t"); 
      $a="From: <mwang\@ml.com>\n";
      $b="To: <mwang\@tech.cicg.ml.com>\n\n";
      $c="some_message\n";
      print SENDMAIL "$a$b$c";
      $a="From: <mwang\@ml.com>\n";
      $b="To: <mwang\@tech.cicg.ml.com>\n\n";
      $c="some_message\n";
      print SENDMAIL "$a$b$c";
-- 
unix programs: niftp (non-interactive recursive ftp), hide (hide command args), 
submit (replace nohup), etc from ftp://ftp.mindspring.com/users/mwang/unix-prog
Michael Wang, mwang@ml.com, Merrill Lynch, World Financial Center, 212-449-4414


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

Date: 5 Sep 1998 12:14:50 -0700
From: gerg@shell1.ncal.verio.com (Greg Andrews)
Subject: Re: Use Perl to sendmail: open once, send multiple times?
Message-Id: <6ss2ja$jlc$1@shell1.ncal.verio.com>

wotan@databasix.co (Wotan) writes:
>For some reason on 4 Sep 1998 18:42:57 GMT, 
>mwang@tech.cicg.ml.com (Michael Wang) babbled:
>
>>How do I use Perl to sendmail but I want to open once, send multiple times?
>>The following example does not work. Should I directly connect to the 
>>sendmail port, or do mutilple open/close? Thanks.
>>
>>  open(SENDMAIL, "|/usr/lib/sendmail -oi -t") 
>>      print SENDMAIL "From: <me\@me.com>\n";
>>      print SENDMAIL "To: <$someone\@some.site>\n";
>>      print SENDMAIL "$some_message\n";
>>      print SENDMAIL ".\n";
>>#
>>      print SENDMAIL "From: <me\@me.com>\n";
>>      print SENDMAIL "To: <$someoneELSE\@some.site.ELSE>\n";
>>      print SENDMAIL "$some_message_ELSE\n";
>>      print SENDMAIL ".\n";
>>  close(SENDMAIL) or warn "sendmail didn't close nicely";
>
>
>Its becuase you are piping each line to sendmail, instead of the
>entire thing at once.  As well as a slight formating error. Try
>something more like this:
>
>open(SENDMAIL, "|/usr/lib/sendmail -oi -t"); 
>      $a="From: <me\@me.com>\n";
>      $b="To: <$someone\@some.site>\n\n";
>      $c="$some_message\n";
>      print SENDMAIL "$a$b$c";
>
>
>Just shoot me instead of pointing out my syntax errors.  :-D
>

I think you're answering the wrong question.  Michael wants to send
multiple messages, not multiple SMTP commands for a single message.

The key is to use sendmail -bs, which makes Sendmail talk SMTP with
your program.  Then you can feed Sendmail multiple messages in a 
single invocation.  In order to see Sendmail's replies you'll need
to use the IPC::Open2 or IPC::Open3 module.


  -Greg


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

Date: 5 Sep 1998 17:19:07 GMT
From: bismuti@dirac.scri.fsu.edu (Peter Bismuti)
Subject: writing/retrieving complex data structures
Message-Id: <6srrqb$g9a$1@news.fsu.edu>


In Perl you can easily construct complex data structures using 
anonymous arrays which can be nexted arbitrarily deep.  

Example:

	%class = {
		'title'    => 'Algebra'
		'reference => 'math101'
		'students' => [
				{
					'name'   => 'John',
					'social' => '123-45-6789',
					'tests'  => {
							'test1' => 90,
						 	'test2' => 80,
						
and so on, and so on.

My question is, is there an easy way of dumping this data structure
to a file and then recovering it easily?  It used to be that in a FORTRAN77 
extension you could simple say:

	PRINT *, %class

and then at a later time when you needed to read this data in

	READ *, %class

								
I know that this cannot be done in PERL (it can't be done in FORTRAN90
for that matter), but are there any tricks for making this easier
in Perl?

	thanks
 _______________________________________________________________________
 |         Pete Bismuti                                                |
 |         Supercomputer Computations Research Institute               |
 |         Florida State University - Department of Mathematics        |
 |         bismuti@scri.fsu.edu  (904) 644-6263                        |
 |_____________________________________________________________________|
						







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

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

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