[8707] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2324 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 15 01:07:37 1998

Date: Tue, 14 Apr 98 22:00:27 -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, 14 Apr 1998     Volume: 8 Number: 2324

Today's topics:
    Re: Blat question <mhchau@cse.cuhk.edu.hk>
    Re: Can someone give me an example of rounding! <rootbeer@teleport.com>
    Re: editing /etc/group file <rootbeer@teleport.com>
    Re: Four asses!? (Mark-Jason Dominus)
    Re: Four asses!? (Tad McClellan)
    Re: Four asses!? <jdf@pobox.com>
    Re: going to a specific line number in a file <rjk@coos.dartmouth.edu>
    Re: greed <rjk@coos.dartmouth.edu>
    Re: Hide or Encrypt perl source code (Chris Adams)
    Re: how to parse a "this", "that", "and the ", "other"  <gwynne@utkux.utk.edu>
    Re: how to parse a "this", "that", "and the ", "other"  <gwynne@utkux.utk.edu>
    Re: info on cookies (Abigail)
    Re: info on cookies <ljz@asfast.com>
        metasearch cgi script (Brycejamz)
    Re: Perl Library Woes <rootbeer@teleport.com>
    Re: Perl utility to surf through 'syslog' files........ <jdf@pobox.com>
    Re: Perl, HP-UX, and memory ... <rootbeer@teleport.com>
    Re: Perl, HP-UX, and memory ... (Ilya Zakharevich)
        Question? <skaipa@leland.stanford.edu>
    Re: RFC: Adding Commands in Filehandles... <repost> <rootbeer@teleport.com>
    Re: Tip: How to selectively quiet warnings <rootbeer@teleport.com>
    Re: Tip: How to selectively quiet warnings <jdf@pobox.com>
    Re: trying to use grep to give an exact match <rjk@coos.dartmouth.edu>
    Re: URGENT: Tracking down a spammer!! <rootbeer@teleport.com>
    Re: using perl scripts from C++ <rootbeer@teleport.com>
    Re: Wanted: Perl Trainer (David Adler)
    Re: Weird Truncate Behavior <rjk@coos.dartmouth.edu>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 15 Apr 1998 11:16:04 +0800
From: Sleep <mhchau@cse.cuhk.edu.hk>
Subject: Re: Blat question
Message-Id: <Pine.SOL.3.91.980415110839.19013A-100000@sparc53.cs.cuhk.hk>



On Tue, 14 Apr 1998, Hakon Stein=F8 wrote:

>   Invoke blat with the "- " switch. This produces some garbage at the end=
 of
> file, and I haven't found a way to get rid of that. I prefer using the
> file-way.
> Do something like `blat - -server xxx -f xxx.....`;
>     - Hakon
>=20

Have u every tried a "-q" switch ? etc 'blat - -server xxx ... -q' .

btw , I have another question :
how to set a variable (scalar) become a stdin ? or just send mail (using=20
blat) with scalar as it's content ?


Regards,
Chau.


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

Date: Wed, 15 Apr 1998 03:45:55 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Gwynne <gwynne@utkux.utk.edu>
Subject: Re: Can someone give me an example of rounding!
Message-Id: <Pine.GSO.3.96.980414204226.6195I-100000@user2.teleport.com>

On Tue, 14 Apr 1998, Bob Gwynne wrote:

> Subject: Re: Can someone give me an example of rounding!
> 
> $num = int(100 * $num) / 100;  # getscha to 2 places.

Not to flame you too badly, but this answer is markedly inferior to the
one in the FAQ, even if you discount the fact that this one doesn't
properly round. If you must answer a question which is answered in the
FAQ, please make sure that your answer is so much better that it should
replace the FAQ's. :-)

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



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

Date: Wed, 15 Apr 1998 04:15:57 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: jtaylor@snet.net
Subject: Re: editing /etc/group file
Message-Id: <Pine.GSO.3.96.980414211426.6195L-100000@user2.teleport.com>

On Tue, 14 Apr 1998 jtaylor@snet.net wrote:

>  This does help and thank you, only now I can't figure out how to write it
> out to replace the old group line. I thought I would try:
>     $gfile = "/etc/group";
>     open(GFILE, "+<$gfile");

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.


>     while (<GFILE>) {
>            s/$old_line/$new_line/ or die "Can't do substitue: $!\n";
>            # where $old_line = getgrnam($_)[0..3];
>            # $old_line =~ tr/ /,/;
>     }

Perl is magical, but it's not _that_ magical. You should check out the
magic $^I variable, though. Hope this helps!

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



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

Date: 14 Apr 1998 23:12:48 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Four asses!?
Message-Id: <6h18jg$5ug$1@monet.op.net>
Keywords: ersatz integrand menu saturate


In article <8790p7hosz.fsf@phaedrus.uchicago.edu>,
stephen farrell  <sfarrell+usenet@farrell.org> wrote:
>	foreach $tmp (@$l_ref) {
>		$tmp = "ass";
>	}

>So I'm very confused about the variable $tmp in that first example.
>Somehow it's not really it's own variable, but rather a pointer into
>$l_ref's list. 

Yup.

Documented to work that way, too.  If you look up the for/foreach loop
in `perlsyn', it says:

     If LIST is an actual array (as opposed to an expression returning
     a list value), you can modify each element of the array by
     modifying VAR inside the loop.  That's because the foreach loop
     index variable is an implicit alias for each item in the list
     that you're looping over.

     Examples:

	 # Replace foo with bar in every element of @ary
         for (@ary) { s/foo/bar/ } 

	 # Multiply every element by 2
         foreach $elem (@elements) {
             $elem *= 2;
         }

>I assumed everything was call-by-value unless a reference is used
>explicitely.

Well, you're confused, because there is no call in the example you
showed, so there's no call-by-value.  But Perl functions never use
call-by-value anyway; they're FORTRAN-style, with
call-by-value-return, which means that the elements of @_ are aliases
for the actual arguments, so that

	sub set_to_57 {
	  $_[0] = 57;
	}

	$a = 23;
	set_to_57($a);

really does set $a to 57.  It says that in the manual also.  C++ and
Pascal also have (optional) calling semantics like this.

> f I do:
>
>	sub listfunc {
>		return (1, 2, 3);
>	}	
>
>	join ("\n", listfunc());
>
>does the list (1, 2, 3) get copied, or does join just get a (magic,
>internal) reference to it?

It doesn't matter in that case.



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

Date: Tue, 14 Apr 1998 22:11:31 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Four asses!?
Message-Id: <3h81h6.53h.ln@localhost>

stephen farrell (sfarrell+usenet@farrell.org) wrote:

: I was very surprised to see four asses as the output of the following
: code:

[ snip using a foreach alias to set values in an array reference ]

: I was under the impression that ONLY the following construct (or some
: variation) would bring about these results:

: 	for (0..$#$l_ref) {
: 		$l_ref->[$_] = "ass";
: 	}

: So I'm very confused about the variable $tmp in that first example.
: Somehow it's not really it's own variable, but rather a pointer into
: $l_ref's list.  


'perlsyn' to the rescue:

 ------------------------------
=head2 Foreach Loops

The C<foreach> loop iterates over a normal list value and sets the
variable VAR to be each element of the list in turn.  If the variable
is preceded with the keyword C<my>, then it is lexically scoped, and
is therefore visible only within the loop.  Otherwise, the variable is
implicitly local to the loop and regains its former value upon exiting
the loop.  If the variable was previously declared with C<my>, it uses
that variable instead of the global one, but it's still localized to
the loop.  (Note that a lexically scoped variable can cause problems
with you have subroutine or format declarations.)

The C<foreach> keyword is actually a synonym for the C<for> keyword, so
you can use C<foreach> for readability or C<for> for brevity.  If VAR is
omitted, $_ is set to each value.  If LIST is an actual array (as opposed
to an expression returning a list value), you can modify each element of
the array by modifying VAR inside the loop.  That's because the C<foreach>
loop index variable is an implicit alias for each item in the list that
you're looping over.
 ------------------------------

Note in particular those last two sentences.


: Well, to be more accurate, I think this leaves me very 
: confused about variables in perl in general.  


Don't worry. Be happy. Your understanding works *nearly* all the time   ;-)

There are only a few places where this aliasing happens.

grep() does it too...


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


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

Date: 14 Apr 1998 23:46:59 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Four asses!?
Message-Id: <btu3n130.fsf@mailhost.panix.com>

stephen farrell <sfarrell+usenet@farrell.org> writes:

> I was very surprised to see four asses as the output of the following
> code:

> 	my $tmp;
> 	foreach $tmp (@$l_ref) {
> 		$tmp = "ass";
> 	}
> 	warn join("\n", @$l_ref);

Hmm.  Reading perlsyn reveals that

   If LIST is an actual array (as opposed to an expression returning a
   list value), you can modify each element of the array by modifying
   VAR inside the loop. That's because the foreach loop index variable
   is an implicit alias for each item in the list that you're looping
   over.

> I assumed everything was call-by-value unless a reference is used
> explicitely.

Well, the magic you're experiencing in the above code is not related
to the concept of "calling by" anything, since subroutines are not
involved.  But, while we're on the subject, you should read about sub
prototypes, which can force call-by-reference (read perlsub).

It sounds to me like you're ready to enjoy the wonders of the Camel
book, _Programming Perl_.  Buy it; you won't regret it.  Whether or
not you buy the Camel, check out the following man pages: perlsyn,
perlsub, perlmod, perldata.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Wed, 15 Apr 1998 00:55:54 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: Pratima Easwar <pratima@synopsys.com>, 2easwar@worldnet.att.net
Subject: Re: going to a specific line number in a file
Message-Id: <35343DDD.1D9DAE9D@coos.dartmouth.edu>

[posted and mailed]

Pratima Easwar wrote:
> 
> The problem I am having is I dont know how to go to say line 25 in File 2
> directly - if there is a way. I could reset to the beginning of the file
> and keep reading in lines until I get to line 25, but I feel there must be
> a more efficient way.

If the lines in file 2 are all the same length, the seek() function would be
useful.  If not, you could create an index of line numbers to byte offsets for
file 2, and seek() would be useful that way too.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 15 Apr 1998 00:41:43 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: greed
Message-Id: <35343A8A.5B4924AB@coos.dartmouth.edu>

Scott Stark wrote:
> 
> BTW, I've looked through both of the Schwartz books and found them so poorly
> indexed I couldn't find anything useful about greediness.

Look up 'greedy matching' in the Camel book, 2nd ed.  Flip to the first
reference, and then turn the page.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 15 Apr 1998 03:43:50 GMT
From: cadams@ro.com (Chris Adams)
Subject: Re: Hide or Encrypt perl source code
Message-Id: <6h1adm$uis$1@news.ro.com>

According to Mark Kaehny  <kaehny@execpc.com>:
>Chris Adams wrote:
>> According to Tom Christiansen  <tchrist@mox.perl.com>:
>> >I can't see any danger with 755.  It's 777 that has naughtiness.
>> >Being able to read something is no danger.  In fact, it enhances
>> >security by avoiding the oxymoronic security-through-obscurity myth.
>> 
>> Well, there are some scripts that it would be nice to not have world
>> readble.  For example: our modem login system logs access to a MySQL
>> database.  I want users to be able to check their usage but not
>> anyone else's usage.  The database requires a username and password
>> to connect, but then I have to put them in the perl script that
>> checks usage.  How
<quoted text below reformated because of long/short unreadable lines>
>Here is where the trouble starts. Why in the world do you have to or
>want to put them in the source code of the script? Here are three
>options all of which are better than just compiling the script - if you
>do that I'll just used 'strings' or the equivalent to get the
>login/password if I want. Compiling provide negative security against
>serious threats since it provides a false sense of security. If the
>level of security is just that a person can't get a non-encrypted
>string out of a binary, that is essentially zero. I am always amazed
>when people think this actually helps.

Well, if you can't read the binary, you can get the strings.  Go back
and read the thread you are responding in.  With a binary, you can
remove read permissions and someone can't read the binary (there are
still ways to get the wanted info), where a script must be readable to
be run.

The only safe way to have a program use a hidden value and not let the
user find it is to make the program set-uid.  I know under Linux (and I
assume the same is more or less true on other Unix systems) that one a
program is set-uid, the user running the program can no longer see into
the memory space (to trace it, look at environment, etc.).  And, since
suidperl is set-uid to root, all of the information in the /proc
filesystem is not even available to the set-uid user the program runs as
(because perl goes set-uid root first and then switches to the user).

In other words, if "burdell" runs "script.pl" that is owned by "george"
and has the set-uid bit set, "burdell" can't trace or in any way look
into the running of "script.pl", and neither can "george" because the
/proc files are owned by "root".

>1) Have the script read a file with the
>   login and password, and you can put the file in a safe place. 

Absolutely no safer - anyone who can figure out how to look in a script
for a password can look for the location.

>2) Have the script connect to some other secure machine and ask for the
>login/password.  Do this if you don't want the login accessible on the
>machine at all.

Safe, but can be a paid to setup and keep working.

>3) Encrypt the string in the source. This will give the level of
>security that compiling does. Use one of the filter modules, or just
>xor some strings into yours, and do that in your script - then you
>won't "expose" the information directly.   The user willhave to do a
>little more work then just using strings or such.

Again, if the user has access to the binary, they can just go through it
with a debugger or trace the system calls (if the password is passed to
something else like a socket).

You said "I am always amazed when people think this actually helps.",
but your solutions 1 and 3 are no better.
-- 
Chris Adams - cadams@ro.com
System Administrator - Renaissance Internet Services
I don't speak for anybody but myself - that's enough trouble.


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

Date: Tue, 14 Apr 1998 23:07:30 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: how to parse a "this", "that", "and the ", "other" file
Message-Id: <6h18cb$9cr$1@gaia.ns.utk.edu>

You most likely want to use the Text::ParseWords module.  It's explained in
perldoc, Mastering Regular Expressions (p207), and Programming Perl p.510.

Bob Gwynne
University of Tennessee


scott@md.hscbklyn.edu wrote in message <6h0033$94m$1@nnrp1.dejanews.com>...
>I have an ascii database with an arbitrary number of comma delimited,
>possibly double-quote enclosed fields that I would like to parse using
split
>(). One record per line.
>
>e.g.
>
>"red", 4, "38", large, *
>"blue", 4, "22", small,
>"green,blue", 3, "2", small, *
>
>Can someone help me come up with an appropriate regex?
>
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/   Now offering spam-free web-based newsreading




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

Date: Wed, 15 Apr 1998 00:44:46 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: how to parse a "this", "that", "and the ", "other" file
Message-Id: <6h1e2l$ddc$1@gaia.ns.utk.edu>

This must be a class assignment.  It's the second VERY similar question
posted today.

Bob Gwynne

scott@md.hscbklyn.edu wrote in message <6h0033$94m$1@nnrp1.dejanews.com>...
>I have an ascii database with an arbitrary number of comma delimited,
>possibly double-quote enclosed fields that I would like to parse using
split
>(). One record per line.
>
>e.g.
>
>"red", 4, "38", large, *
>"blue", 4, "22", small,
>"green,blue", 3, "2", small, *
>
>Can someone help me come up with an appropriate regex?
>
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/   Now offering spam-free web-based newsreading




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

Date: 15 Apr 1998 04:04:18 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: info on cookies
Message-Id: <6h1bk2$rqv$2@client2.news.psi.net>

Lloyd Zusman (ljz@asfast.com) wrote on MDCLXXXVIII September MCMXCIII in
<URL: news:ltu37vlu2m.fsf@asfast.com>:
++ abigail@fnx.com (Abigail) writes:
++ 
++ > Gilles Chong (glchy@csah.com) wrote on MDCLXXXVII September MCMXCIII in
++ > <URL: news:35332C56.7433130D@csah.com>:
++ > ++ Hi,
++ > ++ im playing with cookies for the moment. Generating them with a
++ > ++ javascript is very simple. But im stuck when it comes to getting the
++ > ++ cookie and reading it in Perl. It seems that there is NOT an env
++ > ++ variable which corresponds to the cookie.
++ > 
++ > Then that's a problem you have to take up with your server, not with Perl.
++ 
++ ... although this question is also relevant to Perl, since there's a
++ Perl module called "CGI" which provides a method to access cookies.
++ Furthermore, this method doesn't require you to directly access any
++ environment variables, so you don't need to be concerned about this
++ detail.

Really? Then how does the CGI module know which cookie is set?
It calls the psychic hotline?


Bottomline is, if there's no environment variable, not even the CGI
module will help you. Take it up with your server.

In a server group.



Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


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

Date: 15 Apr 1998 00:41:38 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: info on cookies
Message-Id: <ltpvijlmrh.fsf@asfast.com>

abigail@fnx.com (Abigail) writes:

> Lloyd Zusman (ljz@asfast.com) wrote on MDCLXXXVIII September MCMXCIII in
> <URL: news:ltu37vlu2m.fsf@asfast.com>:
> ++ abigail@fnx.com (Abigail) writes:
> ++ 
> ++ > Gilles Chong (glchy@csah.com) wrote on MDCLXXXVII September MCMXCIII in
> ++ > <URL: news:35332C56.7433130D@csah.com>:
> ++ > ++ Hi,
> ++ > ++ im playing with cookies for the moment. Generating them with a
> ++ > ++ javascript is very simple. But im stuck when it comes to getting the
> ++ > ++ cookie and reading it in Perl. It seems that there is NOT an env
> ++ > ++ variable which corresponds to the cookie.
> ++ > 
> ++ > Then that's a problem you have to take up with your server, not with Perl.
> ++ 
> ++ ... although this question is also relevant to Perl, since there's a
> ++ Perl module called "CGI" which provides a method to access cookies.
> ++ Furthermore, this method doesn't require you to directly access any
> ++ environment variables, so you don't need to be concerned about this
> ++ detail.
> 
> Really? Then how does the CGI module know which cookie is set?
> It calls the psychic hotline?

The Perl CGI module accesses the environment variable for you.  That's
why I said (quoted above) that accessing cookies via the CGI module
doesn't require "you" to directly access any environment variables.
The word "you" referred to the original poster, not the CGI module
itself.

> Bottomline is, if there's no environment variable, not even the CGI
> module will help you. Take it up with your server.

Of course.  I never said there was no environment variable.

By the way, if the original poster wants to access the enviroment
variable directly instead of using the `cookie()' convenience method
of the CGI module, this variable's name is "HTTP_COOKIE".

> In a server group.

 ... or in the Perl CGI module man pages ... or in the Perl CGI::Cookie
module man pages ... or for some real detailed information about the
structure of cookies, one can go to the following URL, which is also
mentioned in the Perl CGI::Cookie man pages:

  http://www.ics.uci.edu/pub/ietf/http/rfc2109.txt

-- 
 Lloyd Zusman
 ljz@asfast.com


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

Date: 15 Apr 1998 03:19:29 GMT
From: brycejamz@aol.com (Brycejamz)
Subject: metasearch cgi script
Message-Id: <1998041503192900.XAA18319@ladder03.news.aol.com>

does anybody know where I can find a script to search many search engines at
once?


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

Date: Wed, 15 Apr 1998 04:10:35 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: new_user@email.msn.com
Subject: Re: Perl Library Woes
Message-Id: <Pine.GSO.3.96.980414210920.6195J-100000@user2.teleport.com>

On Wed, 8 Apr 1998 new_user@email.msn.com wrote:

> Can't locate Aw.pm in @INC at dbtest.pl line 1.

Have you seen what perldiag has to say about this message? And don't miss
lib.pm, either. Hope this helps!

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



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

Date: 15 Apr 1998 00:44:03 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Perl utility to surf through 'syslog' files........
Message-Id: <af9nmyfw.fsf@mailhost.panix.com>

"Steven J. Hill" <sjhill@plutonium.net> writes:

I hope you'll find the following comments helpful.

> #!/usr/bin/perl

Mumble mumble -w mumble mumble mumble use strict mumble.

> # Hash table for months.
> %months = ("Jan",1,

Hmm.  You might want to look into some of the existing modules for
date manipulation.  Date::Manip, for example, though there are
others.  You might choose *not* to use them, but at least it should be
a choice.

> # Define numeric sort subroutine.
> sub by_number {
>   if($a < $b) {
>     return 1;
>   }
[snip etc.]

Oof!  The builtin operator <=> (the spaceship operator) does just
that.  See perlop, and the examples in perlfunc under sort.

> # Parse the command line.
> if(@ARGV > 0) {
>   while(@ARGV > 0) {
[snip etc.]

You might consider the use of the various modules that accompany perl,
which automate parsing command-line options.

>   open(SYSLOG,$ifname) || die "ERROR: Unable to open log file.\n";

If you're only reading $ifname, it might be good to say so explicitly,
as in  open(SYSLOG, "<$ifname") etc.


>   split(/ {1,}/);

Do you intend to split on whitespace?  If so, then simply

   @fields = split;  # which splits $_ on /\s+/ by default

Notice that the implicit split into @_ is deprecated; you shouldn't do
it, as it will go away someday, maybe soon.

>   # Parse the line and collect statistics.
>   $_[4] =~ s/\[\w*\]://;
>   $statistics{$_[4]}++;

The meaning of $_[4] is obscure; perhaps a mnemonic name would serve
you better, especially when you want to tweak this script in a few
weeks...

> close(SYSLOG);

or die.

> if($interactive == 0) {

or how about

   unless ($interactive) { #just a matter of style.  Ignore to taste.

>   unlink($ofname);

That could fail for obscure reasons.  Wouldn't you like to know if it
does?

> # Get parsing start date from user.
> $valid = 0;
> while($valid == 0) {

A cleaner (IMHO) idiom for validating user input goes something like
this

   GET_INPUT:
     {
       print "prompt: ";
       chop(my $input = <STDIN>);
       if (not_valid($input)) {
	  print "You suck.  Try again.\n":
	  redo GET_INPUT;
       }
     }

That's an example of a named block.  Again, it's a matter of style,
and therefore eminently ignorable if you don't like it.

If you're going to be prompting a lot, you might want to write a
subroutine that takes a prompt and some validating code... hmm...

   sub prompt (&;$) {
     my ($valid,$prompt) = @_;
     $prompt ||= '> ';
    GET_INPUT:
     {
       print "$prompt";
       chop (my $input = <STDIN>);
       return $input if &$valid($input);
       redo GET_INPUT;
     }
   }
   my $num = prompt {shift =~ /^\d+$/} "Enter a whole number: ";
   my $string = prompt { 1 } "Enter some arbitrary string: ";

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Wed, 15 Apr 1998 04:20:23 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: gold_bag@yahoo.com
Subject: Re: Perl, HP-UX, and memory ...
Message-Id: <Pine.GSO.3.96.980414211705.6195M-100000@user2.teleport.com>

On Tue, 14 Apr 1998 gold_bag@yahoo.com wrote:

> You say Linux on HP's PA-RISC?? Is linux ported to PA-RISC??

To quote Foghorn Leghorn, that wuz a joke, son. But I'm serious when I
suggest that, if your vendor's kernel won't do what you need, and if the
vendor won't let you work on the source, you should consider the
possibility of porting Linux to your hardware. Even if you don't get it
running, you might scare your vendor in a good direction.

Cheers!

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



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

Date: 15 Apr 1998 04:41:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl, HP-UX, and memory ...
Message-Id: <6h1dq8$jmr$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to 
<wvw@fred.net>],
who wrote in article <6gufhv$nnu$1@news.fred.net>:
> Greetings,
> 
> I'm running perl 5.04-1 on an HP-UX platform, with a script that reads
> in a 1.3 meg file.  The script does massive 
> string substitutions and the virtual memory  usage peaks at about 60 meg
> VM.  I have been very careful to "my" all 
> variables and "undef" the rest.  The problem is that near the end of the
> script it is necessary to do a :
> 
> system("tar -cf  ...")
> 
> Even though Perl has lots of memory to work with, the OS evidently can't
> get enough to create a subshell and the 
> "system" fails.  
> 
> Does anyone know how to REALLY get Perl to release memory to the kernel???

This is very simple.  Volunteer to be the next "pumpking", and include
the current Jumbo-malloc-patch.

In puzzlement, the author of the patch will have no alternative but to
improve the patch to return the memory back to your system.

Ilya


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

Date: Tue, 14 Apr 1998 20:53:04 -0700
From: "Sam P. Kaipa" <skaipa@leland.stanford.edu>
Subject: Question?
Message-Id: <35342F1F.6F1093AF@leland.stanford.edu>

How do I do a GetLine in perl?




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

Date: Wed, 15 Apr 1998 04:49:54 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Tanstaafl <Tanstaafl@geocities.com>
Subject: Re: RFC: Adding Commands in Filehandles... <repost>
Message-Id: <Pine.GSO.3.96.980414212158.6195N-100000@user2.teleport.com>

On Tue, 14 Apr 1998, Tanstaafl wrote:

> 	I'm currently reading the book on Perl 5 and I'm learning it
> from scratch, so please forgive my ignorance. 

Everyone, even Larry, learned Perl from scratch. (Of course, Larry already
knew a few dozen programming languages when he started learning Perl...
:-)

> I've copied and run many scripts that were in the book,

Which book? (If it's relevant.)

> but I wanted to see if I could create something from scratch. This is my
> first attempt, please correct any mistakes. I don't understand what's
> going wrong... 

> 	Basically I wanted to write a standard script I could add to any
> program that I created that would handle any commands I used. 

Huh? I don't understand that. But it sounds as if you might want to make a
module rather than a "standard script".

> To this purpose and because I haven't gotten very far in the book I'm
> trying it with file handles. (IOW, with $#ARGV.) 

Oops. $#ARGV isn't a file handle. It's one smaller than the number of
command line arguments passed to your program (by default).

> #! /usr/local/bin/perl

If your code doesn't work for you, ask Perl to help by warning about
anything suspicious it sees. To do that, use the -w invocation argument on
the #! line. (Also, some systems don't allow a space between the #! and
the path to perl.)

> if ($#ARGV < 1)
>         {
>         print << "end_tag";
>         # Checks for at least one filehandle
> 
> end_tag

Now, you know that that's not a comment in there, right?

>         exit (1);
>         }
> 
>         # Now it should call the correct sub-routine to handle the
>         # command.
> 
> if ($ARGV[0] = "?")

You don't usually want an assignment within an if clause. You may wish to
use one of the modules which are designed to handle command-line
arguments. 

>                 open ($ARGV[1])

Do you know what open does with one argument? Also, you should always
check the return value of open - although, maybe, you thought you were
doing so.

You should probably read the Llama book before going further. Hope this
helps!

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



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

Date: Wed, 15 Apr 1998 03:41:29 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Denis Goddard <dgoddard@us.oracle.com>
Subject: Re: Tip: How to selectively quiet warnings
Message-Id: <Pine.GSO.3.96.980414203946.6195H-100000@user2.teleport.com>

On Tue, 14 Apr 1998, Denis Goddard wrote, quoting me:

> > Don't obfuscate; write out a real if statement!
> Nah, I preferred to inflict the following pain:
> 
> /Created user "[^"]*" with password "[^"]*"/ && do {

That's no the clearest way to code it, but if you know what that means,
then you may do that. But remember, the wise programmer always codes as if
his maintenance programmer is a homicidal maniac who knows where he lives. 

:-)

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



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

Date: 15 Apr 1998 00:49:23 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Tip: How to selectively quiet warnings
Message-Id: <90p7my70.fsf@mailhost.panix.com>

Tom Phoenix <rootbeer@teleport.com> writes:

> But remember, the wise programmer always codes as if his maintenance
> programmer is a homicidal maniac who knows where he lives.

But since we very often must maintain our own code, think of the
maintenance programmer as a *suicidal* maniac who knows where he
lives.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Wed, 15 Apr 1998 00:25:23 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: trying to use grep to give an exact match
Message-Id: <353436B5.47A0F642@coos.dartmouth.edu>

Andrew M. Langmead wrote:
> 
> Ronald J Kimball <rjk@coos.dartmouth.edu> writes:
> 
> >grep(/^$c$/o, @string)
> 
> Shouldn't this be:
> 
> grep(/^\Q$c\E$/o, @string);

Yes, it should.

But to be exactly precise, it should really be:

grep(/\A\Q$c\E\Z(?!\n)/o, @string);

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 15 Apr 1998 04:55:07 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Mick Knutson <mknutson@websolution.com>
Subject: Re: URGENT: Tracking down a spammer!!
Message-Id: <Pine.GSO.3.96.980414215157.6195O-100000@user2.teleport.com>

On Tue, 14 Apr 1998, Mick Knutson wrote:

> Subject: URGENT: Tracking down a spammer!!

It may be urgent for you, but saying URGENT doesn't make it urgent for the
rest of us. Please check out this helpful information on choosing good
subject lines. It will be a big help to you in making it more likely that
your requests will be answered. 

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> I perform a check prior to allowing anyone to use my system.

That's a good idea.

> I check:
> 
> $ENV{'REMOTE_ADDR'};
> $ENV{'REMOTE_HOST'};
> $ENV{'REFFERRER'};

Hmmm... This smells suspiciously unlike a Perl question.

> The problem is that the remote addr and remote host many times give the 
> same value (I.e. 199.222.44.90 for both)
> 
> Is this an alias?
> How do I identify a user correctly?
> How else can I identify a user to ban them?

I do believe that these are (or should be) answered in the CGI FAQ. In
particular, it's not a Perl question, since identifying and authenticating
the remote user of a webserver is done in the same way whether in Perl or
in any other language. Hope this helps! 

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



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

Date: Wed, 15 Apr 1998 04:12:50 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Michael Badt <mibadt@rafael.co.il>
Subject: Re: using perl scripts from C++
Message-Id: <Pine.GSO.3.96.980414211149.6195K-100000@user2.teleport.com>

On Tue, 14 Apr 1998, Michael Badt wrote:

> Does anyone know where I can get information, or sample programs for
> calling perl scripts from code writtem in C++, and what setups do I
> have to make in my C++ project for activating it ?

Typically, you find out how to get your C++ programs to run shell scripts,
then activate Perl scripts the same way. If that doesn't work on your
system, check your system's docs. Hope this helps! 

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



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

Date: 15 Apr 1998 03:29:41 GMT
From: dha@panix.com (David Adler)
Subject: Re: Wanted: Perl Trainer
Message-Id: <6h19j5$mm2@news1.panix.com>

On Tue, 14 Apr 1998 04:50:49 GMT, Roland Stone <rstone@eagle.ais.net> wrote:
>
>We are looking for experienced Perl consultants to deliver Perl
>training courses on a contract basis.  We want to talk to you if:

Check out <http://www.perltraining.com>.

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Chicken Wire?" - Lou Marini


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

Date: Wed, 15 Apr 1998 00:50:31 -0400
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Weird Truncate Behavior
Message-Id: <35343C9A.B170F7AB@coos.dartmouth.edu>

Art Cohen wrote:
> 
> What the heck? Is there any known reason why truncate would fail on the
> statement
>         truncate (HANDLE, 0)
> 
> but succeed on the statement
>         truncate (OUT, 0)

Could you provide more of the code?  Say, a brief example using HANDLE which
shows the weird behavior you described.

-- 
 _ / '  _      /         - aka -             rjk@coos.dartmouth.edu
( /)//)//)(//)/(    Ronald J. Kimball           chipmunk@m-net.arbornet.org
    /                                   http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

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

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