[12685] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 94 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 9 15:07:15 1999

Date: Fri, 9 Jul 1999 12:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 9 Jul 1999     Volume: 9 Number: 94

Today's topics:
    Re: 3 virtues of a Programmer <cassell@mail.cor.epa.gov>
        <STDIN> with password? chenlg@my-deja.com
    Re: apache webserver question (brian d foy)
    Re: array stuff.. <marshalc@americasm01.nt.com>
    Re: array stuff.. (Larry Rosler)
    Re: array stuff.. <uri@sysarch.com>
    Re: can perl run overnight? <marshalc@americasm01.nt.com>
    Re: can perl run overnight? <martin@adoma.se>
    Re: can perl run overnight? (John Stanley)
    Re: cgi question, can you help me? (Bart Lateur)
    Re: Chatpro 2.5 glitch... Help (John Stanley)
    Re: checking Perl offline earthangel78@my-deja.com
        creating stock charts (baga@gmx.net)
    Re: Deleting everything after a pattern? (I R A Aggie)
    Re: Deleting everything after a pattern? <cassell@mail.cor.epa.gov>
        File Upload that only works if you repost data <nick.sanders@lineone.net>
    Re: fork() in Win32 <David.Boyce@fmr.com>
    Re: I need to hide the source <mgoelz@efn.org>
    Re: long long in perl? <sugalskd@netserve.ous.edu>
    Re: long long in perl? <cassell@mail.cor.epa.gov>
    Re: long long in perl? (I R A Aggie)
    Re: Newbie: Upgrade from 5.004_04 to 5.005_03 earthangel78@my-deja.com
    Re: open+0 <emschwar@rmi.net>
        Pattern Matching Question <mykkam@krypton.mankato.msus.edu>
    Re: Q:a simple update to index (Larry Rosler)
    Re: Random Numbers (Larry Rosler)
        Script will not work <pgrech@uoguelph.ca>
    Re: single instance log file <cassell@mail.cor.epa.gov>
    Re: Sorting hash of Arrays now drops duplicate keys. <cassell@mail.cor.epa.gov>
    Re: Too late for "-T" option at init.cgi line 1. <emschwar@rmi.net>
        UserAgent chenlg@my-deja.com
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Fri, 09 Jul 1999 11:42:04 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: 3 virtues of a Programmer
Message-Id: <3786427C.BB77F214@mail.cor.epa.gov>

elaine ashton wrote:
> [snippage of some nice links]
>
> > 3. Hubris.
> 
> It is not mentioned in the Camel, the Llama or the Nutshell as far as I
> recall.

Just look in the glossary of the Camel.  Page 607 in my edition.
So you don't need that old pink camel after all.  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 09 Jul 1999 18:54:42 GMT
From: chenlg@my-deja.com
Subject: <STDIN> with password?
Message-Id: <7m5ghb$hrh$1@nnrp1.deja.com>




I have a simple perl program (runing on the SUN)
which ask the user for password by using the
<STDIN>, my question is how to turn off the echo
on the system so that when the user typing the
password on the command line, the password would
not be shown explicitly.

Thanks

LGCHEN
chen@dalek.ucsd.edu


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 09 Jul 1999 13:54:41 -0500
From: brian@pm.org (brian d foy)
Subject: Re: apache webserver question
Message-Id: <brian-0907991354410001@128.5.32.84>

In article <MPG.11effb6991c0c369989b24@news-server>,
e-lephant@b-igpond.com (elephant) wrote:

> Gene Dolgin writes ..
> >Is it possible to setup apache in a way, that when any file from a
> >specific dir is accessed, the request is forwarded to a perl program?
> 
> yes .. but the answer has nothing to do with perl and everything to do 
> with apache .. a product that comes with copious amounts of documentation 
> .. read it

you only think it has nothing to do with Perl.  this sounds like a 
question about a PerlTransHandler.  this can be answered by taking a
look at www.modperl.com, which is all about Apache *and* Perl.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>


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

Date: Fri, 09 Jul 1999 13:07:17 -0500
From: Marshall Culpepper <marshalc@americasm01.nt.com>
Subject: Re: array stuff..
Message-Id: <37863A54.59A94655@americasm01.nt.com>

>
> The gurus can correct me, but I don't think there is an operator
> that does that. You have to step through it one at a time.
>
> use strict;
> my $str = "a";
> my @test = ('0'..'5');
> foreach (@test) {$_ = $str . $_}
>
> HTH  Matt
> --
> Matthew Zimmerman            http://www.people.virginia.edu/~mdz4c
> Interdisciplinary Biophysics Program        University of Virginia
> ------------------------------------------------------------------
> "You got to be very careful if you don't know where you're going,
> because you might not get there."                    -- Yogi Berra

Ya...that sounds pretty much like what i did but i was wandering if there
was any sort of simple function that does it for you in 1 line of somethin
(somthin like prepend($str,@array)), guess not :)

~marshall



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

Date: Fri, 9 Jul 1999 11:19:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: array stuff..
Message-Id: <MPG.11efdd0c1fb2a743989c81@nntp.hpl.hp.com>

In article <x7908pspj4.fsf@home.sysarch.com> on 09 Jul 1999 13:26:23 -
0400, Uri Guttman <uri@sysarch.com> says...
> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
> 
>   LR> [Posted and a courtesy copy sent.]
>   LR> In article <378615A6.8736FB08@americasm01.nt.com> on Fri, 09 Jul 1999 
>   LR> 10:30:46 -0500, Marshall Culpepper <marshalc@americasm01.nt.com> says...
>   >> hey kind of an intermediate skill level on perl..
>   >> is there any quick function to add a certain string to every element of
>   >> an array
>   >> i.e;
>   >> $str="a";
>   >> @test=('0'..'5');
>   >> and test would return as ('a0'..'a5')? any help would be greatly
>   >> appreciated :)
> 
>   LR> $_ = "$str$_" for @test;
> 
> TIMTOWTDI
> 
> 	substr($_, 0, 0, $str) for @test ;
> 
> it doesn't win perl golf but i like 4 arg substr. and i have seen lvalue
> substr be faster than interpolation in some cases. larry will now run
> his autobenchmark module and post results in 3.4ms. :-)

No, I won't.

Why is 4-arg substr better in this case than 'substr($_, 0, 0) = $str'?

"An alternative to using substr() as an lvalue is to specify the 
replacement string as the 4th argument. This allows you to replace parts 
of the EXPR and return what was there before in one operation, just as 
you can with splice()."

Here we know what was there before, the null string.  :-)

In any event, substr didn't occur to me, though maybe it should have.  
But what did occur to me is the 'need' (;-) for a reverse-concatenation 
operator:

    $_ ..= $str; 

Then we can add a reverse-division operator //=; a reverse-mudulus 
operator %%=; a reverse-subtraction operator --= (parsing problems with 
post-decrement???); ...

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


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

Date: 09 Jul 1999 15:03:09 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: array stuff..
Message-Id: <x7673tsl1u.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <x7908pspj4.fsf@home.sysarch.com> on 09 Jul 1999 13:26:23 -
  LR> 0400, Uri Guttman <uri@sysarch.com> says...
  >> 
  >> substr($_, 0, 0, $str) for @test ;

  LR> Why is 4-arg substr better in this case than 'substr($_, 0, 0) = $str'?

well, 4 arg beats that in perl golf (assuming normal use of white
space). and as i said, i like 4 arg substr. 

substr($_, 0, 0, $str)
substr($_, 0, 0) = $str

  LR> In any event, substr didn't occur to me, though maybe it should have.  
  LR> But what did occur to me is the 'need' (;-) for a reverse-concatenation 
  LR> operator:

  LR>     $_ ..= $str; 


  LR> Then we can add a reverse-division operator //=; a reverse-mudulus 
  LR> operator %%=; a reverse-subtraction operator --= (parsing problems with 
  LR> post-decrement???); ...

i hear the sounds of worms leaving the can.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Fri, 09 Jul 1999 13:09:27 -0500
From: Marshall Culpepper <marshalc@americasm01.nt.com>
Subject: Re: can perl run overnight?
Message-Id: <37863AD6.8527CF47@americasm01.nt.com>

Jeff Isenhart wrote:

> I have a perl script I want ran each night. (It reads web pages and
> updates my own) Is there anyway to make this run on it own or am I stuck
> with running it myself daily?
>
> Jeff

Jeff..one way you could do it is if you have a dedicated connection (or if
you stay connected alot) you could run in it on the crontab of your
computer(providing it's unix-based)...just my thoughts, there's probably a
better way :)

~marshall




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

Date: Fri, 09 Jul 1999 19:58:22 +0100
From: Martin Quensel <martin@adoma.se>
Subject: Re: can perl run overnight?
Message-Id: <3786464E.48AE3D15@adoma.se>



Jeff Isenhart wrote:
> 
> I have a perl script I want ran each night. (It reads web pages and
> updates my own) Is there anyway to make this run on it own or am I stuck
> with running it myself daily?

take a look at cron and crontab

Martin Quensel


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

Date: 9 Jul 1999 18:37:09 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: can perl run overnight?
Message-Id: <7m5fgl$dcr$1@news.NERO.NET>

In article <37863A4A.AE4D1F35@inreach.com>,
Jeff Isenhart  <jeffisen@inreach.com> wrote:
>I have a perl script I want ran each night. (It reads web pages and
>updates my own) Is there anyway to make this run on it own or am I stuck
>with running it myself daily?

"cron" is your friend. "at" is your friend. Loops are your friend.



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

Date: Fri, 09 Jul 1999 18:58:37 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: cgi question, can you help me?
Message-Id: <378845bf.886105@news.skynet.be>

geofox wrote:

>I have written a cgi script to get
>some information about the statistics of 
>the web site....
>However, it takes some time to output 
>the result.
>My Question is:
>can I write something such "pls wait" or "the result is coming" etc.
>to indicate the request is processing before the result comes out
>in the page?

Your tet is very strangely formatted. But, that aside: go to Randal's
WebTechniques' pages. See column 20.
http://www.stonehenge.com/merlyn/WebTechniques/

	Bart.


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

Date: 9 Jul 1999 18:35:23 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Chatpro 2.5 glitch... Help
Message-Id: <7m5fdb$dcd$1@news.NERO.NET>

In article <7m58uh$cu2@enews2.newsguy.com>,
John Curry <kuzzero@nconnect.net> wrote:
>I have tried several approaches myself, but I am an amatuer at perl
>programing, I am including the access_control.pl and the main chat.pl and
>please, don't just give me hints how to fix it, actually type out the fix
>and show me where to insert it, and what language to replace.
>----------------------------------------------------------------------------

It is very unwise, in this group, to post 1666 lines of code and ask
people to tell you where to insert it.




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

Date: Fri, 09 Jul 1999 18:34:16 GMT
From: earthangel78@my-deja.com
Subject: Re: checking Perl offline
Message-Id: <7m5fb8$ha9$1@nnrp1.deja.com>

In article <1999070817175566754@zetnet.co.uk>,
  Stephen Aze <stephen.aze@zetnet.co.uk> wrote:
> This would seem to me to be the first question for anyone wanting to
> give Perl a try, but I can't find the answer anywhere...
>
> I want to give Perl a try, and would like to do all my mistakes
off-line.
> So how do I run my Perl/CGI applications locally, in a simulated
> 'Net environment, rather than uploading to my server etc?  Solutions
> not requiring the expenditure of money preferred.
>
> Thanks in advance.
>
> --
> stephen.aze@zetnet.co.uk
>
> How about downloading the free Apache server onto your desktop?
http://www.apache.org
Then you’ll have a fully self-contained Web environment on your machine
to test your scripts.  For more resources and tutorials on Perl, check
out:
 http://www.opensourceit.com/subjects/perl.html


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 09 Jul 1999 18:33:55 GMT
From: baga@gmx.net (baga@gmx.net)
Subject: creating stock charts
Message-Id: <37863e66.2655718@news.techfak.uni-kiel.de>

Hello,

I want to write a program that takes my saved data and create charts
out of it. Does someone know if there are already perl programs/moduls
available which I can use to start? I want to use that for stocks.

Thanks a lot!

  Hans
baga@gmx.net


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

Date: 9 Jul 1999 18:19:19 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Deleting everything after a pattern?
Message-Id: <slrn7ocfdh.ktr.fl_aggie@thepentagon.com>

On Fri, 09 Jul 1999 16:00:07 GMT, Bart Lateur <bart.lateur@skynet.be>, in
<37861ba4.31529806@news.skynet.be> wrote:

+ >my $text = 'a'. ('x' x 1000) . 'b';

+ 	$text = 'ab' . ('x' x 1000);

These aren't the same, are they? If my ESP::PerlParse module is installed
in my head correctly, the first is 'ax...(1000 x's)...xb', and the second
is 'abx...(1000 x's)'.

Is that not the reason you get such a radical flip in "efficeincies"?

James


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

Date: Fri, 09 Jul 1999 11:37:41 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Deleting everything after a pattern?
Message-Id: <37864175.6F045233@mail.cor.epa.gov>

Bart Lateur wrote:
> Abigail wrote:
> [both benchmarks snipped]
> 
> Conclusion? Eh...

The usual conclusion.  That knowing how the regex engine
works, it's easy to gen up special cases which make either
option look better.  So the real question becomes "how do
these work with the real data that would be appearing in
this particular case?"

The answer to that is also obvious.  You can't get there
from here.  Not enough info was supplied by the original
poster.

Now if you're going to use Benchmark, at least try to pick 
examples which aren't so *obviously* contrived to beat the
other case.  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 08 Jul 1999 11:11:53 +0100
From: Nick Sanders <nick.sanders@lineone.net>
Subject: File Upload that only works if you repost data
Message-Id: <37847969.A3034AB6@lineone.net>

I'm running Apache locally on windows and am trying to upload a file
using CGI.pm when I submit the form I get a internal server error and
the error log says -
'Premature end of script headers: d:/msd/cgi-bin/newsletter.pl'
When I refresh the page and repost the data, the file is uploaded and
everything works fine.

Here is the file upload code

  open (FILE,">".$full_filename);
  binmode (FILE);

  while ($bytes_read = read($upload_file, $buffer, 65536)){
  print FILE $buffer;
  $total += $bytes_read;
  }

 close FILE;

Has any one any ideas ?

Thanks

Nick



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

Date: Fri, 09 Jul 1999 14:37:30 -0400
From: David Boyce <David.Boyce@fmr.com>
Subject: Re: fork() in Win32
Message-Id: <3786416A.A5883AEF@fmr.com>

"John M. Dlugosz" wrote:
> 
> Question:  I suppose the "indirect object" of 1 is to cause system to
> directly load the program, instead of running the command-line shell to
> launch the program.  So, what becomes of the value?  The docs say that it's
> used to "lie about the name".

No, this is not the "indirect object" syntax, as that's documented to be
used _without a comma_. It's apparently a hack specific to the WIN32
port. Note that this command:

	perl -we 'system 1, qw(ls /tmp)'

gives a syntax error on Unix (5.005_54) while the equivalent on &^@#
Windows (5.005_03):

	perl -we "system 1, q(dir), qq(\"C:\\Program Files\")"

succeeds. It's not documented in the standard (perldoc -f {system,exec})
places; I stumbled over it following perl-porters IIRC.

Also, note from the above quoting mess that cmd.exe is still used to
launch the program. I've never found a way to get system to avoid using
the shell on Windows, in direct contravention of perldoc -f exec. But
then I'm not a Windows programmer, just a Unix guy with a need to write
code that will run on lesser systems too.

-David Boyce


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

Date: Fri, 09 Jul 1999 11:08:44 +0100
From: MLG <mgoelz@efn.org>
Subject: Re: I need to hide the source
Message-Id: <3785CA2C.EAA10025@efn.org>

Although I agree in principle that medical records should be kept private the
reality is that these records are seen by a significant number of people whose
behavior cannot readily be controlled. I work in behavioral mental health and I
have witnessed breaches of confidentiality by  staff whose access to the
records is a matter of necessity. How can you keep data entry staff, insurance
authorization and billing staff (both in house and with the carrier), medical
receptionists, clinical line staff, and the physicians and nurse practitioners
from violating confidentiality other than by the expectation that they will
adhere to professional standards of behavior and imposing consequences if they
don't comply with those expectations? The same applies to sysops and
developers, who, despite the impression of some, are actually probably not less
ethically inclined than your average medical line staff.

Jürgen Exner wrote:

> Clive Newall <crn@itga.com.au> wrote in message
> news:v5pv22ct3r.fsf@lightning.itga.com.au...
> > "Jürgen Exner" <juex@my-dejanews.com> writes:
> >
> > > Abigail <abigail@delanet.com> wrote in message
> > > news:slrn7o7lb6.ued.abigail@alexandra.delanet.com...
> > > > rdosser@my-deja.com (rdosser@my-deja.com) wrote on MMCXXXVI September
> > > > MCMXCIII in <URL:news:7m09vd$m44$1@nnrp1.deja.com>:
> > > > ``
> > > > `` I should have explained more: I'm trying to conceal a decryption
> > > > `` algorithm for confidential data.
> > > >
> > > > And you don't trust root? Buhahhahhahahhahaa. That's stupid.
> > > > Find a root who you can trust.
> > >
> > > Although I have to aggree that security by obsfucation is not the right
> way
> > > to go, still the administrator of e.g. a hospital network has no
> business
> > > reading my medical records.
> > >
> > > So not trusting root for confidential data is a very valid case.
> >
> > No. You cannot prevent root from breeching your security by technical
> > means. Your *only* hope is to enforce such security by other means.
> > Like hiring a good professional sysadmin.
> > Like ensuring all staff understand your security policies & how they
> > relate to confidential data.
> >
> > If you don't trust root there is only one solution: dismissal.
>
> I still disagree on both accounts:
> - You can protect you confidential data even from malicious sys-admins by
> good encryption. Yes, even that can be breeched provided you employ enough
> computation power, but usually even a sysadmin doesn't have the required
> computer power available (unless he works for the CIA ;-) .
> - And in e.g. Germany by law you must protect e.g. medical data in such a
> way, that unauthorized persons don't have access to that data. Unauthorized
> means the janitor for the file cabinet (which  must be locked) just as well
> as the sysadmin for online records.
>
> jue
> --
> Jürgen Exner





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

Date: 9 Jul 1999 18:31:54 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: long long in perl?
Message-Id: <7m5f6q$avi$1@news.NERO.NET>

ahornbeck@yahoo.com wrote:
: Is there an 8-byte integer type in perl?  Or a package that supports
it?

5.006 should support long longs if the compiler you build it with supports
them. Long doubles too, hopefully.

					Dan


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

Date: Fri, 09 Jul 1999 11:33:16 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: long long in perl?
Message-Id: <3786406C.1C8CB68D@mail.cor.epa.gov>

ahornbeck@yahoo.com wrote:
> 
> Is there an 8-byte integer type in perl?  Or a package that supports it?

Perl is not a strongly-typed language.  So I'm not quite sure
what you're after.  Do you really need that exact specification?

If you just want to do integer arithmetic, check out the
'use integer' pragma.  But there are other possibilities.
This is, after all, Perl.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 9 Jul 1999 18:24:54 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: long long in perl?
Message-Id: <slrn7ocfo1.ktr.fl_aggie@thepentagon.com>

On Fri, 09 Jul 1999 15:40:28 GMT, ahornbeck@yahoo.com <ahornbeck@yahoo.com>, in
<7m555a$d5p$1@nnrp1.deja.com> wrote:

+ Is there an 8-byte integer type in perl?  Or a package that supports it?

You'll want to look at BigInt. Hmmm...looks like there is a choice
available:

Module          Math::BigInt    (CHIPS/perl5.004_05.tar.gz)
Module          Math::BigInteger (GARY/Math-BigInteger-1.0.tar.gz)

The first one is bundled in with perl, and is available to
you. According the second's README 'This BigNum library is based on
Eric Young's BigNum C library.'

HTH.

James



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

Date: Fri, 09 Jul 1999 18:30:03 GMT
From: earthangel78@my-deja.com
Subject: Re: Newbie: Upgrade from 5.004_04 to 5.005_03
Message-Id: <7m5f2p$h6k$1@nnrp1.deja.com>

In article <Pine.SOL.3.96.990708115914.27724C-100000@thale>,
  Jamie Kincaid <jamie@thale.nott.ac.uk> wrote:
>
> Hi,
>
> In the INSTALL notes for 5.005 it says about recompiling extensions:
>
> If you have dynamically loaded extensions
> that you built under perl 5.003 or 5.004, you can continue to use them
> with 5.004, but you will need to rebuild and reinstall those
extensions
> to use them 5.005.
>
> Can I therefore just tar up and move all the stuff into the new
site_perl
> directory ie /usr/local/lib/perl5/site_perl/5.005
>
> I don't understand what is meant by dynamically loaded extensions.
>
> Jamie
>
>
------------------------------------------------------------------------
-------
> Jamie Kincaid
> Nottingham Arabidopsis Stock Centre
> School of Biological Sciences
> University Park
> The University of Nottingham
> Nottingham
> NG7 2RD
>
> Office: 0115 951 3091
>
> NASC website:	nasc.nott.ac.uk
>
>

Have you checked out the new perl tutorials on
http://www.opensourceit.com/subjects/perl.html?  They address a lot of
issues with Perl 5.005, free at Open Source IT
(http://www.opensourceit.com)  from “The Perl Journal.”


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 09 Jul 1999 12:08:24 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: open+0
Message-Id: <xkf1zehg0h3.fsf@valdemar.col.hp.com>

abigail@delanet.com (Abigail) writes:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCXXXVIII
> September MCMXCIII in <URL:news:7m3mdh$6vl$1@lublin.zrz.tu-berlin.de>:
> {} 
> {} He forgot to mention we all start counting at zero.
> 
> Hah! Except me. I always start my programs with $[ = 7.

Yes, but shouldn't we leave Advanced Evil as an excercise for the
student, instead of providing ready-made answers like that?  You have to
let them learn *something* for themselves, after all.

-=Eric


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

Date: Fri, 9 Jul 1999 13:11:46 -0500
From: Mark Mykkanen <mykkam@krypton.mankato.msus.edu>
Subject: Pattern Matching Question
Message-Id: <Pine.OSF.3.96.990709131054.7268B-100000@krypton.mankato.msus.edu>

How do I match everything up to the last '/' in the line?

open(INPUT,'passwd');
while(chomp($line = <INPUT>))
{
 $line =~ /.+\//;
 print "$line\n";
}

							    *
---BEGIN passwd---
haglin:*:1005:103:David J. Haglin:/users/faculty/haglin:/bin/bash
---END passwd---



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

Date: Fri, 9 Jul 1999 11:04:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Q:a simple update to index
Message-Id: <MPG.11efd976289178db989c80@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <Pine.GSO.4.10.9907091122470.17973-100000@ux12.cso.uiuc.edu> 
on Fri, 9 Jul 1999 11:24:25 -0500, milan andric <m-
andric@students.uiuc.edu> says...
> i'm still fairly a newbie at programming and perl..  

Evidently new enough not yet to have learned to use the '-w' flag, which 
would have pointed out immediately the major bug in your code.  You 
should also start out right by adding 'use strict;' as the second line 
of the program.

> i'm writing a program that makes additions to an index page of links..
> basically i want to keep the file's contents alphabetized, so i'm
> using a string compare of existing lines with the new
> line i'm adding to the index.  my plan of attack looks something like
> this (psuedocode):

It is better to post real code rather than pseudocode, especially when 
your pseudocode looks so much like the real thing.
 
> $newline="<p><a href=\"\L$trunc/$csvfiles[$m].html\"><strong>$org</strong></a>";

OK, but some would prefer to eliminate those backslashes:

  $newline =
qq{<p><a href="\L$trunc/$csvfiles[$m].html"><strong>$org</strong></a>};

or to use single-quotes for the HTML delimiters:

  $newline = 
"<p><a href='\L$trunc/$csvfiles[$m].html'><strong>$org</strong></a>";

I assume you know that $org will be lower-cased also.  Use \E if that's 
not what you want.
 
> 	open (INDEXIN, "<indexes/\L$trunc.html") || die ...;
>         open (INDEXOUT, ">indexes/new/\L$trunc.html") || die ...; 

The '...' must be the pseudocode.  Good!  Just remember to include $! in 
the error message.
 
> 	   while ($_=<INDEXIN>) {

The '$_ = ' is unnecessary.  That is the default.
 
> 		  if (/<p><a href=.*><strong>.*</strong>/) { #look for the right line to take action on

Stick that comment ahead, on a line by itself, rather than creating such 
a humongous line.  Neither your text editor nor our newsreaders 
appreciate it.

> 			$test = ($_ cmp $newline);#compare returns 1 or 0 

Actually, it returns 1 or 0 or -1.  I assume you mean to use 'eq'.  But 
there is a newline on $_ and none on $newline (despite its name :-).  
Either use chomp or append a newline to $newline.  And having done 
either of those, why bother with the regex and setting the flag at all?

> 		  }
> 		  if ($test=0){

The real bug is there, as what you have written always fails.  '=' is an 
assignment operator, not a comparison operator.

> 			print INDEXOUT $newline;
> 			print INDEXOUT $_;

Printing $_ is the default.

>  	          }
>   	  		  else {print INDEXOUT $_;}
> 		  }

Whenever you have identical code in each branch of a decision, factor it 
out if possible.

> i'm having some problems with the regular expression because it doesn't
> seem like the best approach.  do you have a better method or idea? 

Ultimately, the loop seems to boil down to this (assuming a "\n" 
appended to $newline):

  	   while (<INDEXIN>) {
  			print INDEXOUT $newline unless $_ eq $newline;
  			print INDEXOUT;
         }

Look Ma, no regex! 

And now for the inevitable one-liner, using my favorite idiom:

	print INDEXOUT $_ ne $newline && $newline, $_ while <INDEXIN>;

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


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

Date: Fri, 9 Jul 1999 11:35:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Random Numbers
Message-Id: <MPG.11efe0ab6b0e1f1d989c84@nntp.hpl.hp.com>

In article <378638DB.1C12D9C2@mail.cor.epa.gov> on Fri, 09 Jul 1999 
11:00:59 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
 ...
> Math::TrulyRandom may not be random anyway, merely chaotic.
> I haven't seen an adequate analysis of it.

Hello!  There are no random-number algorithms, by definition.  Special 
hardware (such as a radioactive-decay detector) is required.  See Knuth, 
Vol. 2, Ch. 3, 'Random Numbers' and especially the rubric:

"Anyone who considers arithmetical methods of producing random digits 
is, of course, in a state of sin.  John von Neumann (1951)"

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


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

Date: Fri, 09 Jul 1999 14:50:20 -0400
From: Paul <pgrech@uoguelph.ca>
Subject: Script will not work
Message-Id: <3786446C.CF4B04B9@uoguelph.ca>

Can anyone tell me why this program will not work.  Is supposed to use
modules and these are supposedly called from the
perl5 library.  On my machine it says it does not recognize the command
use.
'

Thanks any help would be greatly appreciated.

Paul


#!/usr/bin/perl

use Time::localtime;

printf "Today is %02d/%02d/%d\n", localtime->mon()+1, localtime->mday(),
localtime->year()+1900;




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

Date: Fri, 09 Jul 1999 11:28:53 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: single instance log file
Message-Id: <37863F65.F4421E16@mail.cor.epa.gov>

sskinner@cloud9.net wrote:
> 
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> 
> >>#!/usr/local/bin/perl
> > Where's the -w?
> 
> Not necessary for posting purposes.

No it *is* needed for posting purposes.  It is essential
so that the readers can tell what you're doing and
what level of expertise you're at.  It tells us whether
you have gotten the errors that -w prints out.  Otherwise,
you'll get a lot of useless directions about using -w, 
when you in fact have a more interesting problem.
 
> >>open (FILEHANDLE, "+>> $myPath"); # read/append mode
> > Where's the check for success?
> 
> I'm an optimist.

Come on, be fair.  Lots of times the poster has failed
to check this, and it is in fact the real problem!
Particularly when issues of CGI or directory movement
or file permissions come up.  Check the return, or
expect to get hammered on this every time you post here.
Ditto for your flock().  There's no point in using
flock() if you're not going to check that it worked.
 
> [snip]

> >>@items = <FILEHANDLE>; # read the entire file;
> >>if (not ??? ) { # does the file contain an occurance of this
> > See perldoc -q contains
> 
> Thank you for this clever suggestion! Actually, I have tried various
> incarnations of =~ and !~ to no avail. If you have some solution in mind,
> just say it. No need to be shy here.

You didn't even bother to look at Anno's suggestion, did you?
He pointed you right at a couple pages of code for several
different cases.  That's the best source.

> One problem seems to be in comparing scalars to arrays. I'm thinking along
> the lines of...
> 
> if ("@items" !~ chomp ($ENV{'HTTP_USER_AGENT'}) ) {
> 
> or something to that effect.

Except that this won't work, will it?  Read the FAQ answer that
Anno's comment pointed you toward.  You're more likely to
want grep() and a hash.  One doesn't compare a scalar and an
array the way you're thinking.  Besides, is there a *good*
reason for parsing the HTTP_USER_AGENT [which can be spoofed
anyway]?  You're surely not going to write pages which differ
depending on the user's browser, are you?  That's considered
poor web coding around here.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 09 Jul 1999 11:12:49 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: John Hennessy <john@hendigital.com.au>
Subject: Re: Sorting hash of Arrays now drops duplicate keys.
Message-Id: <37863BA1.9404304A@mail.cor.epa.gov>

[courtesy cc also mailed to poster]

John Hennessy wrote:
> 
> Thanks to all who responded to the previous post.
> I was aware of the Alpha versus Numeric sort functionality but the method I
> had used was ineffective.
> 
> My problem now is that the sort on group drops any duplicate keys. (Of
> course).
> ie. I only end up with one user displayed for each group ID.

Uh-oh.  Then you're doing something wrong in there.  Perhaps it's
not the sort() that is doing this.

> Ultimately what I need to achieve is to read in the login name, group and
> real name, produce output
> sorted by login name, real name (preferably surname) and each group
> numerically sorted with it's members alpha sorted.
> 
> Not asking much of Perl just of my ability.
> 
> Help would be appreciated.

You're in luck.  Help is already on your hard disk.  Look in 
the FAQ, and you'll find two answers, both of which show ways
to sort on multiple fields.  If you want more than that, go to
CPAN and snag a copy of Tom Christiansen's "FMTEYEWTK: Sorting".

Quick answer which should encourage you to go read those 
pieces - your code could look something like this bit, lifted
out of the FAQ:

 @sorted = sort { field1($a) <=> field1($b) ||
                  field2($a) cmp field2($b) ||
                  field3($a) cmp field3($b)
                }     @data;

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 09 Jul 1999 12:18:02 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Too late for "-T" option at init.cgi line 1.
Message-Id: <xkfyagpelgl.fsf@valdemar.col.hp.com>

mike cardeiro <mikecard@my-deja.com> writes:
>      Too late for "-T" option at init.cgi line 1.
> 
> why is it too late and am i barking up the wrong tree by using taint

perldoc perldiag

Congratulations, by the way, on asking about an actual Perl error
message, instead of a "500 Server Error" or something.

-=Eric


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

Date: Fri, 09 Jul 1999 18:54:41 GMT
From: chenlg@my-deja.com
Subject: UserAgent
Message-Id: <7m5gha$hrg$1@nnrp1.deja.com>

In  what format should I use to provide a username
and password pair to query a password protected
web page, I try this:

	my $ua = new LWP::UserAgent;
$ua->agent ("Mozilla/4.02 [en] (Win95;I)");
$self->{ua} = $ua;
$self->{jsWritten} = 0;
$self->{modified} = 0;
$self->{userName} = 'myname';
$self->{password} = 'mypassword';
return $self;

it does not work, any idea??


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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 V9 Issue 94
************************************


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