[7357] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 982 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 5 14:17:10 1997

Date: Fri, 5 Sep 97 11:00:24 -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           Fri, 5 Sep 1997     Volume: 8 Number: 982

Today's topics:
     Re: "#!/path_to_perl -w" causes shell to be invoked <kipp.e.howard@boeing.com>
     Re: "Odd number of elements in hash list": So? <mthurn@irnet.rest.tasc.com>
     Re: can't run Perl 5.004 on NCR 2.03.01 <mike.wescott@columbiasc.ncr.com>
     Re: Date calculation help (Steffen Beyer)
     Re: Help! Book needed!! <jbolden@math.ucla.edu>
     here docs vs qq <dturley@rocketmail.com>
     Re: here docs vs qq (Craig Berry)
     how do I redirect the output of an existing perl script <peter@preview.org>
     Re: Is Perl for Win32 really as brain damaged as it see <beyoder@raleigh.ibm.com>
     Re: Learning perl (Burt Lewis)
     Re: looking for: Perl MQ Interface <beyoder@raleigh.ibm.com>
     Minimizing Memory Needed for Numbers Read from Binary F <Brett.W.Denner@lmtas.lmco.com>
     Re: perl and XEmacs (Bryan Miller)
     printing in the same place (Intesab N. Siddiqui)
     Problems compiling Perl <webmaster@mid-states.com>
     Re: Shakespearian insult program <jay@rgrs.com>
     Re: Shortest Path Algorithm (Steffen Beyer)
     Re: Simple Question on grep (Terry Michael Fletcher - PCD ~)
     simple Sendmail Question (Newbie) <rhritz@ix.netcom.com>
     Speeding up C preprocessor-like text-substitution subro <Brett.W.Denner@lmtas.lmco.com>
     using LWP to get an ftp:// URL via proxy <pmp@egnetz.uebemc.siemens.de>
     Re: Weighting elements of an array (Terry Michael Fletcher - PCD ~)
     Re: WIN95 server with perl?file.pl <gordon.leslie.mcdorman@sap-ag.de>
     Re: yesterday's date (Steffen Beyer)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 5 Sep 1997 16:12:25 GMT
From: "Kipp E. Howard" <kipp.e.howard@boeing.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: "#!/path_to_perl -w" causes shell to be invoked
Message-Id: <34102F69.73F6@boeing.com>

Tom Phoenix wrote:
> 
> On Thu, 4 Sep 1997, Kipp E. Howard wrote:
> > We installed perl in the following directory structure:
> >
> > /site/sw/perl-5.003/bin
> 
> Be careful that your full path to perl won't exceed 32 characters, if
> that's the limit for the #! line on your system. (Of course, if you can
> make /usr/bin/perl a symlink to the binary, everything should be fine.)

You are correct.  I had counted the number of characters by hand once
or twice and always came up with 32 characters.  When I was sending you
a reply I counted the characters like so and realized there are 33
characters.  QED

#!/site/sw/perl-5.003/bin/perl -w
123456789012345678901234567890123

Thanks for making me look at this again.
 
> Hope this helps!

It did.

-- 
Kipp E. Howard              | Voice: (206) 662-4932 
Boeing Commercial Airplanes | Fax:   (206) 662-4404   
P.O. Box 3707, M/S 19-MH    | Stable: kipp.e.howard@boeing.com
Seattle, WA  98124-2207     | WWW:
http://www.iasl.ca.boeing.com/~keh3985


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

Date: 05 Sep 1997 13:14:58 -0400
From: Kingpin <mthurn@irnet.rest.tasc.com>
Subject: Re: "Odd number of elements in hash list": So?
Message-Id: <eu7mcv3cod.fsf@irnet.rest.tasc.com>

klander@primenet (Kevin) writes:

> >With -w and strict turned on, perl 5.004 warns me that I have an
> >"Odd number of elements in hash list". 
> 
> This happens when you try to assign a list with an odd number of
> elements to a hash

  Unfortunately, it also gives this warning if you assign undef to a
hash.  What's wrong with that?  What's even potentially wrong with that?

%hash = undef;

  Similarly, an array which has been assigned undef shows a length of
1 (versus an empty array, which shows a length of 0):

@a0 = ();     print scalar(@a0);   # prints 0 as expected
@a1 = undef;  print scalar(@a1);   # prints 1!  Why?!?

-- 
 - - Martin "Kingpin" Thurn                    mthurn@tasc.com
     Research Software Engineer           (703) 834-5000 x2926
     The Information Refinery              http://tir.tasc.com
     TASC, Inc.                            http://www.tasc.com


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

Date: Fri, 05 Sep 1997 12:53:43 -0400
From: Mike Wescott <mike.wescott@columbiasc.ncr.com>
Subject: Re: can't run Perl 5.004 on NCR 2.03.01
Message-Id: <34103917.E5DE8312@columbiasc.ncr.com>

Steve Manning wrote:
> I am unable to get any of the latest version of perl to compile on my
> NCR 3000 system.  I'd appreciate any insights.
> 
> OS:     NCR Unix (SVR4) v 2.03.01
> Tools:  gcc 2.7.2.3,
>         GNU binutils v2.7
> 

Unless there is some overriding reason to compile it yourself, I suggest that
you pick up http://ncrinfo.ncr.com/pub/contrib/svr4/perl5-5.004.pkg.gz as well
as the associated README file.

The port was performed on MP-RAS 3.01 and passed all tests. I believe that it
will run just fine on a 2.03.01 system (previous versions passed all tests on
2.03.01) in spite of its 3.01 origins.

-- 
	-Mike Wescott
	 mike.wescott@ColumbiaSC.NCR.COM


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

Date: 5 Sep 1997 14:54:44 GMT
From: sb@en.muc.de (Steffen Beyer)
Subject: Re: Date calculation help
Message-Id: <5up6fk$f3t$2@en1.engelschall.com>

Mark Chaffee <chaffee@cpdmfg.cig.mot.com> wrote:

> I have seen many modules (at CPAN) for Date calculations, but they are
> far more than I need.

Obviously not... :-)

> I am quite a perl newbie and need a simple
> routine to calculate date. I'd prefer something I can write into a
> script or call from another.  Since I don't have the knowledge base to
> use one of the "bigger" modules, would someone have the patience to
> possibly post something?

> Here is what I am trying to do:

> Two dates are currently given in this format: mm/dd/yyyy  I need to
> search a flat text file and print any lines that contain any date
> between and including the two inputed dates.  The format of the dates in
> the text file is also mm/dd/yyyy

> I guess I need to somehow convert the dates to numbers, compare them to
> find the delta, and write a loop to grep the file for each sequential
> number (after converting that number back to it's original formay).  Am
> I making any sense at all?

> I can write the routine to do all the grepping and necessary looping,
> but the date thing just has my undies in a bundle...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That's the very reason why the date modules exist. It's not as easy to write
as one might think...

Also, using modules is much easier than hacking up your own thing:

Just get the module in question from somewhere (for instance, "Date::DateCalc"
from CPAN or http://www.engelschall.com/u/sb/download/), unpack it (with
"gunzip <name>" and "tar -xf <name>") and execute the following steps:

% perl Makefile.PL
% make
% make test
% make install

Thereafter, you can use that module in your scripts by simply adding the
line "use <name>;" to the top of your script.

To see the module's documentation, use "man <name>".

> I really appreciate any help that can be given!  If anyone does choose
> to reply, please email me as well as posting.  Thanks!

> -- 
> - Mark Chaffee
>   chaffee@cpdmfg.cig.mot.com

Yours,
-- 
    Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
     "There is enough for the need of everyone in this world,
      but not for the greed of everyone." - Mahatma Gandhi
   >> Unsolicited commercial email goes directly to /dev/null <<


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

Date: Fri, 05 Sep 1997 09:19:57 -0700
From: Jeffrey Bolden <jbolden@math.ucla.edu>
Subject: Re: Help! Book needed!!
Message-Id: <3410312D.51F8@math.ucla.edu>

Bernhard wrote:
> 
> HI!
> Who knows a good BEGINNER (!!) book for learning perl? It could be in
> english or german language.
> 
> Bernhard
> --
> Bernhard.Streit@gmx.de
> http://home.rhein-zeitung.de/~bstreit/
> RZ-Online-FAQ: http://home.rhein-zeitung.de/~bstreit/faq/

Randal's book is very good.  I personally like the Orwant book "Perl 5
interactive course" as a first book.


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

Date: Fri, 05 Sep 1997 11:21:28 -0600
From: David Turley <dturley@rocketmail.com>
Subject: here docs vs qq
Message-Id: <873475950.25040@dejanews.com>

When returning a block of text to STDOUT is there any diference
between
using:
 print <<HERE;
   some text
HERE

or

print qq!
  some text
qq!;

?

I've gotten in the habit of using qq, but notice that many hackers
seem to
prefer <<HERE. If someone could point out any subtle (or not so
subtle)
reasons for using one over the other, I'd appreciate it.

cheers,

david

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 5 Sep 1997 17:40:09 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: here docs vs qq
Message-Id: <5upg5p$m6i$1@marina.cinenet.net>

David Turley (dturley@rocketmail.com) wrote:
: When returning a block of text to STDOUT is there any diference
: between
: using:
:  print <<HERE;
:    some text
: HERE
: 
: or
: 
: print qq!
:   some text
: qq!;
: 
: ?

The first prints the string "\n   some text\n", the second "   some 
text\n" -- note that extra \n at the beginning of the first one.

Also, the first is less sensitive to its content.  Any unescaped instance
of ! inside the qq version will terminate the string, while the here-doc
version requires a bare HERE in at the left margin to terminate, making it
less error-prone.

: I've gotten in the habit of using qq, but notice that many hackers seem to
: prefer <<HERE. If someone could point out any subtle (or not so subtle)
: reasons for using one over the other, I'd appreciate it.

I tend to use qq for single line strings with internal " chars and 
requiring variable interpolation, and here-docs for multiline strings (in 
order to avoid that pesky initial \n, see above).

Hope this helps!

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Fri, 5 Sep 1997 10:41:39 -0700
From: "Peter Tiemann" <peter@preview.org>
Subject: how do I redirect the output of an existing perl script
Message-Id: <5upg2n$ro6$1@ha1.rdc1.sdca.home.com>

I'd like to redirect the standard output of a perl function that I call.
(Right now it writes on the screen = in a web page in my particular case)
I would like to have that function write to a file to be able to process the
output.

Thank you for helping a beginner -
Peter Tiemann,
peter@preview.org





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

Date: Fri, 05 Sep 1997 11:58:04 -0400
From: Brian Yoder <beyoder@raleigh.ibm.com>
Subject: Re: Is Perl for Win32 really as brain damaged as it seems?
Message-Id: <34102C0C.2F1C@raleigh.ibm.com>

Ron Savage wrote:
> 
> Bart Lateur wrote:
> >
> > jdm@thetics.europa.com (Jessica) wrote:
> >
> > >I tried using backticks to execute the command and it would run the
> > >command correctly and return the correct output to my script, but for
> > >no apparent reason, _it would access a:\ every time the external command
> > >was executed_.
> > [snip]
> 
> I get this too, on Win95. I have WinZip, but have just installed ZipMagic (which is _much_ cleverer), and I
> still get the effect.

For me, de-selecting a few options on the McAfee Virus Scanner
stopped the a: drive access. Particularly the options related to
scanning drives upon access.

This problem isn't Perl's problem, it's Windows 95's problem.
Check out for more ideas the WIndows 95 Annoyances site):
  
    http://www.creativelement.com/win95ann/

-- 
Brian Yoder


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

Date: 5 Sep 1997 17:17:56 GMT
From: burt@ici.net (Burt Lewis)
Subject: Re: Learning perl
Message-Id: <5upes4$nc3$1@bashir.ici.net>

I bought "Perl5 for Dummies and think it's great.  Explanations and examples 
are in good plain simple English.  Highly recommended!

Burt Lewis
www.eastonmass.com

In article <340FA7C7.4A37@flm.mw.tu-muenchen.de>, 
erich@flm.mw.tu-muenchen.de says...
>
>
>I am new to perl programming. Does anyone have a recommendation for
>free available documentation or a good book.
>
>Thanks 
>
>Erich
>-- 
>===========================================================================
===
>      ------- |     | |\  /|     Erich Kreiselmaier  
>         |    |     | | \/ |     TU Muenchen
>         |    |     | |    |     Lehrstuhl fuer Fluidmechanik
>         |    |     | |    |     85747 Muenchen
>         |     \___/  |    |     
>
>      Tel:    (49) 89 289 16125
>      Fax:    (49) 89 289 16151
>      e-mail: erich@flm.mw.tu-muenchen.de
>      WWW:    http://www.flm.mw.tu-muenchen.de/~erich
>===========================================================================
===



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

Date: Fri, 05 Sep 1997 12:55:24 -0400
From: Brian Yoder <beyoder@raleigh.ibm.com>
Subject: Re: looking for: Perl MQ Interface
Message-Id: <3410397C.6201@raleigh.ibm.com>

Free from IBM in Hursley:

   http://www.software.ibm.com/ts/mqseries/txppacs/ma85.html

This is the MQSeries Perl interface SupportPac. I haven't used
it, so this shows my tidbit archival system is in good shape!

-- 
Brian Yoder


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

Date: Fri, 05 Sep 1997 10:54:01 -0500
From: Brett Denner <Brett.W.Denner@lmtas.lmco.com>
Subject: Minimizing Memory Needed for Numbers Read from Binary Files
Message-Id: <34102B19.41C6@lmtas.lmco.com>

I recently tried to develop a Perl script to read the contents of a 
large binary data file into a "multi-dimensional" array.  Say the 
file was about 4 Mb in size.  My approach was something like this:

    open (FH, "< $big_file");

    $string = '';  (I'm not sure it's necessary to pre-set this)

    foreach $j (0 .. 999) {
        foreach $i (0 .. 999) {
            read FH, $string, 4;
            $array[$j][$i] = unpack "f", $string;
        }
    }

This problem with this is that the binary data are converted to a 
string representation before being stored in @array, which vastly
increases the memory required to store the contents of $big_file.

Is there a way to store in an array or scalar only the numeric
(non-textual) value of binary data obtained from a file?

Thanks,

Brett

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Brett W. Denner                                    Lockheed Martin TAS
 Brett.W.Denner@lmtas.lmco.com                      P.O. Box
748            
 (817) 935-1144 (voice)                             Fort Worth, TX 76101
 (817) 935-1212 (fax)                               MZ 9333


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

Date: 5 Sep 1997 16:41:46 GMT
From: millerb@millerb.fc.hp.com (Bryan Miller)
Subject: Re: perl and XEmacs
Message-Id: <5upcoa$q4v@fcnews.fc.hp.com>

Gary D. Foster (Gary.Foster@corp.Sun.COM) wrote:
: >>>>> "I" == I R A Aggie <fl_aggie@hotmail.com> writes:

:     I> Let's see if I got this right: you attribute perl to
:     I> anti-semetic Nazis, and then get miffed when perl users object?

:     I> Ok, maybe I'm humor-impaired. Please explain to me, which part
:     I> of

:     I> + Perl is for nazi's and oppresion.

:     I> is supposed to be funny?

: Ever heard of something called satire?

: Hmm... you appear to be, as dogbert would say, an "Induhvidual".

: Take your sense of humor into the shop for a tuneup, it's overdue.

: Perhaps you would have found it funny if I had reversed "perl" and
: "lisp"?  Or perhaps you should just realize it was all just tongue in
: cheek.  Or perhaps you don't even realize what Godwin's law is, and
: therefore are completely clueless.  If that's the case, read the first 
: line of my reply again, carefully, slowly, and sounding out the big
: words.

: Geez, get a grip.

Geez,  take a deep breath and chill.

Perhaps you could focus your satire on a topic a little less gruesome
and close to home for some of us than the Holocaust.  I don't think it
is your satire that is objectionable - just the topic.  Imagine your
reaction to my satire of one of your deceased family members and you
may begin to get the picture...

Bryan


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

Date: 5 Sep 1997 15:52:36 GMT
From: intesab@bnr.ca (Intesab N. Siddiqui)
Subject: printing in the same place
Message-Id: <5up9s4$rht@crchh327.rich.bnr.ca>



hello,

i would like to know how to print in the same place...

i mean, with the following code (where my_print can 
manipulate the line and column)

my_print (1);
my_print (2);
my_print (3);

the output should be (at the same line and column):
1 (after the first call)
2 (after the second call)
3 (after the third call)

at the end the user would see 3, and 1 and 2 would not be visible,
since they were over-written with 3...

thanks in advance,
saab


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

Date: Fri, 05 Sep 1997 10:14:23 -0400
From: Jeremy Finke <webmaster@mid-states.com>
Subject: Problems compiling Perl
Message-Id: <341013BF.3F71AA7A@mid-states.com>

Hello-

I am having problems compiling Perl for my machine.  It is a SCO 3.4v4.2
running on a 486/66.  I am using all of the default values for the 'sco'
hint.  I had been using a precompiled version that I downloaded
somewhere, but i could not get this to work with any modules.  I also
had problems installing the modules.

Anyways, I get through the Configure script alright, but when I run make
I get an error about 7 mins into the compiling.

        `sh  cflags libperl.a pp_sys.o`  pp_sys.c
          CCCMD =  cc -DPERL_CORE -c -DDEBUGGING
pp_sys.c
/usr/include/utime.h(46) : warning C4028: parameter 2 declaration
different
pp_sys.c(710) : error C2079: 'timebuf' uses undefined struct/union
'timeval'
pp_sys.c(711) : warning C4049: 'initializing' : indirection to different
types
pp_sys.c(762) : error C2224: left of '.tv_sec' must have struct/union
type
pp_sys.c(763) : error C2224: left of '.tv_sec' must have struct/union
type
pp_sys.c(764) : error C2224: left of '.tv_usec' must have struct/union
type
pp_sys.c(822) : error C2224: left of '.tv_sec' must have struct/union
type
pp_sys.c(823) : error C2224: left of '.tv_usec' must have struct/union
type
*** Error code 6

I am not running gcc.  I am using the c compiler that came with the
system.  I really do not have the room to install gcc, i do not think.
Any hints and/or help would be greatly apprecitated!  TIA!

Jeremy Finke



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

Date: 05 Sep 1997 13:37:01 -0400
From: Jay Rogers <jay@rgrs.com>
To: Eric Anderson <eric@semaphore.com>
Subject: Re: Shakespearian insult program
Message-Id: <823enjoe6a.fsf@shell2.shore.net>

Eric Anderson <eric@semaphore.com> writes:
> A friend emailed me a shakespearian insult kit. With it, you choose one
> word from each of three columns, put them together with a 'Thou' on the
> front of it, and you have a fully functional shakespearian insult. I've
> turned it into a small perl program. I have it set to run in my .bashrc
> file so I have the pleasure of a quality insult every time I login.
> Please feel free to use/misuse it however you see fit.

I really like your Shakespearian insult program Eric, even if it is
kinda high browed.  :-)

Now who's going to be the first to come up with a Bevis and Butthead
insult program?

--
Jay Rogers
jay@rgrs.com
Thou mangled rump-fed codpiece!


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

Date: 5 Sep 1997 14:23:01 GMT
From: sb@en.muc.de (Steffen Beyer)
Subject: Re: Shortest Path Algorithm
Message-Id: <5up4k5$efl$1@en1.engelschall.com>

In article <5u2qkq$g5v$1@newbabylon.rs.itd.umich.edu>,
Matthew Scott Britt <msbritt@ren.us.itd.umich.edu> wrote:

> Does anyone know of a shortest path algorithm written in perl?
> I searched CPAN with no luck...

> The algoithm would depend on whether you want depth-first or
> breadth-first searching done, I would have thought..

I'm not sure about what you want exactly.

But depending on wether you want the shortest path in a graph for
just TWO particular nodes or between ALL nodes, you should implement
Dijkstra's algorithm for shortest paths or use the "Graph::Kruskal"
module (written in Perl, available from
http://www.engelschall.com/u/sb/download/), respectively.

Hope this helps.

Yours,
-- 
    Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
     "There is enough for the need of everyone in this world,
      but not for the greed of everyone." - Mahatma Gandhi
   >> Unsolicited commercial email goes directly to /dev/null <<


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

Date: 5 Sep 1997 16:04:51 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: Simple Question on grep
Message-Id: <5upaj3$rvq$2@news.fm.intel.com>

Devon Caines (devonc@inetnebr.com) so eloquently and verbosely pontificated:
> 	simple question that confusing me.
> 
> 	foreach (@new) {
> 		chop;
> 		@removed = grep(!/$_/,@old);
> 	}
> 
> 	isnt the above supposed to place everything from  @new 
> 	thats not in @old in @removed?

doh!  grep assigns each element of its list to $_, so it overwrites the $_
you expect from the foreach loop.

> 	this never seems to work.. even when I test both lists 
> 	just before the loop to ensure that they do contain
> 	slightly dissimilar info.

sure it works!  @removed contains a list of every item in @old that doesnt
match itself :)

try:

foreach $new_item (@new) {
	chop;
	@removed = grep !/$new_item/, @old;
}

but $new_item better not contain RE special characters.  then you would
need a "\Q" (quotemeta).
hope that helped.

-- 
#!/usr/local/bin/perl -w
print   "J"                      ."u".        #    -- Terry Fletcher
        "s"    ."t".    " A",     "n"         # tfletche@pcocd2.intel.com
   .    "o"   ,""."".   "the",    "r ","P".   #  Views expressed....not
   "e"."rl"   ." Ha",   "c",''    .""  ."".   #  INTeL's....yadda yadda
      ""            ,   "k".      "e"  ."r"  ;#          yadda....



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

Date: Fri, 05 Sep 1997 13:48:32 -0700
From: Ronald Hritz <rhritz@ix.netcom.com>
Subject: simple Sendmail Question (Newbie)
Message-Id: <34107020.3161@ix.netcom.com>

I am attempting to send e-mail from an HTML form to a Fax gateway
through Formmail.pl 1.6. I need to alter the From field to my
personal e-mail address so the fax server will process the message.
Currently, the e-mail header is "nobody@mimas.domain.com"
I've alter the PRINT MAIL From: my email address command in Formmail
but it doesn't work. Our webmaster says to change the Sendmail command
using the -f parameter. What would be the correct syntax ?

Currently the cammand is set as :
OPEN(MAIL,"|$mailprog -t");

Thanks for any help.

Ronald Hritz


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

Date: Fri, 05 Sep 1997 11:49:34 -0500
From: Brett Denner <Brett.W.Denner@lmtas.lmco.com>
Subject: Speeding up C preprocessor-like text-substitution subroutine
Message-Id: <3410381E.167E@lmtas.lmco.com>


I have a Perl subroutine that does text substitution in a way that is
similar to the C preprocessor.  Namely, it looks for lines of the form:

OLD := new

and replaces every appearance of OLD on subsequent lines with the text
'new'.  This, of course, is analagous to the way cpp searches for
lines like:

#define OLD new

and replaces OLD with 'new' later in the file.

The problem is that the way I've implemented this is very slow on a
Cray computer (Crays are great for vectorized numerical code, but lousy
for scalar code).  Here's what I'm trying:

#----------------------------------------------------------------------
# note: @file contains the contents of a text file

foreach (@file) {
    # substitute for each defined variable in current line

    foreach my $old (@old_text) {
        s/\b$old\b/$new_text{$old}/;
    }

    # search for lines like: OLD := new

    if ( /^\s*([a-zA-Z_]\w*)\s*:=\s*(.*)/ ) {
        ($old, $new) = ($1, $2);

        # add to an array of old text
        push (@old_text, $old) unless defined $new_text{$old};
          
        # add to a hash of new text
        $new_text{$old} = $new;
    }
}
#----------------------------------------------------------------------

The problem is that the foreach loop is incredibly slow, attempting many
subsitutions on every line in my file.  Is there any way I can speed up
this subroutine?

Thanks,
Brett
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Brett W. Denner                                    Lockheed Martin TAS
 Brett.W.Denner@lmtas.lmco.com                      P.O. Box
748            
 (817) 935-1144 (voice)                             Fort Worth, TX 76101
 (817) 935-1212 (fax)                               MZ 9333


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

Date: Fri, 05 Sep 1997 19:01:02 +0200
From: Bernard Weiler <pmp@egnetz.uebemc.siemens.de>
Subject: using LWP to get an ftp:// URL via proxy
Message-Id: <34103ACE.1F0F@egnetz.uebemc.siemens.de>

Maybe this will help somebody...

I tried to use CPAN.pm but failed due to our proxy:
we have no ftp proxy, but only a http one (Netscape-Proxy/2.52)
and all CPAN have ftp URLs.

After a long search I found the problem:
 ./lib/site_perl/LWP/Protocol.pm used a ftp request for this URL (good
idea, but invalid for my proxy)

so I made these changes (currently hardcoded):
 ./lib/site_perl/LWP/Protocol.pm:
48:    if (1){#berni(defined $proxy) {
50:     $host = 'sbsproxy';#berni$proxy->host;
51:     $port = 8080;#berni$proxy->port;
 ./lib/site_perl/LWP/Protocol.pm 
111:    $scheme = 'http';#berni$1; # untaint



-- 
--------------------
Name:		Bernard Weiler
Org.:		OeN TR HW A1, Mch-H, Siemens AG
Keywords:	MCATS;Asic;SDH;Perl
Tel:   		office 722-28374, private 089-7901737
email: 		pmp@egnetz.uebemc.siemens.de 
		or Bernard.Weiler@oen.siemens.de 
Snailmail:  	Siemens AG, OeN TR HW A1, Mch-H, Postfach 700071, D-81359
Munich
Intranet: 	http://susi.oen.siemens.de/~pmp
PGP:		the public key may be downloaded from
pgp-public-keys@uni-paderborn.de
		with Subject 'get Bernard Weiler <Bernard.Weiler@oen.siemens.de>'


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

Date: 5 Sep 1997 15:50:51 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: Weighting elements of an array
Message-Id: <5up9or$rvq$1@news.fm.intel.com>

Tom Phoenix (rootbeer@teleport.com) so eloquently and verbosely pontificated:
> On 4 Sep 1997, Terry Michael Fletcher - PCD ~ wrote:
> 
> > but now, say i want ~60% of the commands to be cmd1, ~30% to be cmd2,
> > and ~10% to be cmd3,
> 
>     $commands = [
> 	# Each one is a weight followed by a coderef
> 	[ 60 =>	\&cmd1 ],
> 	[ 30 =>	\&cmd2 ],
> 	[ 10 => sub { sleep 5 } ],	# Inline if you wish
>     ];

hmmm.  thats a pretty interesting way of declaring the array.  i like
that.

>     sub get_random_action {

oops.  i probably should have pointed out that i wasnt asking for a
subroutine, since i already had one.  i was looking for an easy way to
weight arrays upon declaration to teach to beginners in a "tips and
tricks" session.  i think i would get nothing but glazed stares on the
above one :)

> 	# Given an arrayref as above, picks one action by weight.
> 	# The total weight need not be known in advance.
> 	my $commands = shift;
> 	my $sum = 0;
> 	my $act;
> 	for (@$commands) {
> 	    $act = $_->[1] if rand($sum += $_->[0]) < $_->[0];
> 	}
> 	$act;
>     }

neat.  the last "$act" wins :)
i took a different approach.
i declare a hash, with the keys as the weighted items, and the values as
the weights:

%colors = (
	'red' => 1,
	'white' => 2,
	'blue' => 3,
	'black' => 4,
);

# then this subroutine returns one of the keys of the weighted hash that
# was passed to it.  

sub wrand (\%) {
	my %table = @_;
	my $cum = 0;
	my ($elem, $index);
	for (values %table) { # whee!  i like "values" :)
		map { $elem = $$_[0]; $cum += $$_[1] } [each %table];
		$table{$elem} = $cum;
	}
	$index = rand($cum);
	foreach (keys %table) {
		($index <= $table{$_}) && return $_;
	}
}

# now just call it:
print "a random weighted color is ",wrand(%colors),"\n";
__END__

the "for" and "map" combination in the sub turned out to be much more
efficient that using a "while" loop with the "each" assignment as the
condition.  that could be important when doing a lot of wrand calls.  its
important that the hash is iterated through in the same order for both
loops (appears to be true).  to make this more efficient, both loops could
iterate over (reverse sort {$a<=>$b} values %hash) so that the most likely
occurence happens first, but this seems fine.

>               Ask me about Perl trainings!

hey!  so how 'bout those Perl trainings!!!!   :)

--
#!/usr/local/bin/perl -w
@"=(qw; P ;,q*e*,qq,r,,q;l;);$_=<<'/\<<$_; :-) \' ^/<\'<>/\'$!=0/\'/<&@_';
^[^a-i*#,k-z@&]u[s,*]t$ ^[]/$%a!&]*not*\(anything\)*here*$ ^p[$_r%,.]i*nt$
[^hi]?[]MOM!#]$ #  tfletche@pcocd2.intel.com  # ^h*[^b$d-j%/,l-z(]\{3\}er$
/\<<$_; :-) ' ^/<'<>/'$!=0/'/<&@_
for(split){map{s;print;join"",@";eg;chop;print}q& &.qx;look -r '$_';}# TMF



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

Date: Thu, 4 Sep 1997 16:12:48 GMT
From: Gordon McDorman <gordon.leslie.mcdorman@sap-ag.de>
Subject: Re: WIN95 server with perl?file.pl
Message-Id: <ulo1d2h33.fsf@sap-ag.de>


>>>>> "jk" == jeff knot <jknot@hotmail.com> writes:

    jk> we can replace http://www.somewhere.com/cgi-bin/prog.pl with
    jk> http://www.somewhere.com/cgi-bin/perl.exe?prog.pl How do we
    jk> replace http://www.somewhere.com/cgi-bin/prog.pl?something
    jk> along with the same approach?  I do not suppose it is
    jk> http://www.somewhere.com/cgi-bin/perl.exe?prog.pl?something

Do not do this. See http://language.perl.com/info/security.html

Do the following:

1. Configure your web server to properly execute perl programs.
See:
http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html

2. Use cgi.pm. See:
http://www-genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html

-- 
-------------------------------------------------------------- 
The opinions expressed above are mine, not my employer's.
      
gordon.leslie.mcdorman@sap-ag.de                               


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

Date: 5 Sep 1997 14:45:03 GMT
From: sb@en.muc.de (Steffen Beyer)
Subject: Re: yesterday's date
Message-Id: <5up5tf$f3t$1@en1.engelschall.com>

Jeremy Finke <webmaster@mid-states.com> wrote:
> Hello all-

> I have a question that I am having difficulty with.  I have a script
> that parses through a group of files that have date formats in them.  I
> have this working all right.  My problem now comes from the fact that
> one of the fields has the previous day's date.  Is there an easy way to
> get yesterday's date from the system.  I was subtracting one from
> today's date, but the problem there is that if it is the first of the
> month then I get a result of zero of the same month.  Also I really do
> not want to hard code in all of the months with which ones have 30 or 31
> days as well as February and all of the leap year problems.

> TIA!!

> Jeremy Finke

Get the module "Date::DateCalc" from CPAN or
http://www.engelschall.com/u/sb/download/ and then write:

use Date::DateCalc qw(calc_new_date);
use Date::DateCalcLib qw(parse_date);

@today = parse_date(`/bin/date`);
@yesterday = calc_new_date(@today,-1);

Then @yesterday contains the date of yesterday (numerically!) in the order

$yesterday[0] = year
$yesterday[1] = month
$yesterday[2] = day

Hope this helps!

Yours,
-- 
    Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
     "There is enough for the need of everyone in this world,
      but not for the greed of everyone." - Mahatma Gandhi
   >> Unsolicited commercial email goes directly to /dev/null <<


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

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

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