[6604] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 229 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 3 17:16:29 1997

Date: Thu, 3 Apr 97 14:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 3 Apr 1997     Volume: 8 Number: 229

Today's topics:
     !! Ancient Chinese Fortune Reading !! <crystal@fortune.reading.com>
     Re: !! Ancient Chinese Fortune Reading !! (Nathan V. Patwardhan)
     Arithmetic expressions?? <anderson@necsys.gsfc.nasa.gov>
     current dir curiousity <ray@westlake.com>
     Re: current dir curiousity <eryq@enteract.com>
     Re: File Read/Write Problem <tchrist@mox.perl.com>
     fractional second timing <ethan@worldsite.net>
     Re: HELP with perl array (Tad McClellan)
     MultiDimensional Arrays? (Desmond Ng)
     Re: Ousterhout and Tcl lost the plot with latest paper (Alaric B. Williams)
     Re: Perl vs. C/C++ ()
     Perl-5.003 test error <twalker@voyager.cmp.com>
     Re: Perl-5.003 test error (Nathan V. Patwardhan)
     Re: Reading data from _DATA_ <danboo@ixl.com>
     Replacing text <scs@huron.net>
     Re: Running program on a remote machine <mtw@eng.sun.com>
     Re: Simple array question by newbie... (Tad McClellan)
     Re: Simple array question by newbie... <wkuhn@uconect.net>
     Re: Simple array question by newbie... <ciaran@netco.com>
     string comparision jim_shi@franklin.com
     Re: string comparision <eryq@enteract.com>
     Re: String substitution problem (Ted Yee)
     Re: The theoretically fastest way to iterate through al <eryq@enteract.com>
     Re: Usyng the 'system' function from perl. <sdt1@rsvl.unisys.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 03 Apr 1997 15:08:24 -0500
From: CRYSTAL <crystal@fortune.reading.com>
Subject: !! Ancient Chinese Fortune Reading !!
Message-Id: <33440E38.5A55@fortune.reading.com>

        !! Ancient Chinese Fortune Reading !!

There's a 5000 Year Old Fortune Reading Secrets of China that 
Will Reveal Your Whole Life before your own eyes !  
Just by submitting your birth year, month, day and time, you can 
have clear insights on what's ahead of you and what you can do to 
improve your luck and prevent a bad luck.  Unlike other 10 minute 
Fortune readings that tells you a fraction of you life, this 
incredible Ancient Chinese Fortune Readings I have acquired through 
continuous studying covers your whole life leaving you with complete 
satisfaction and comprehension.  It covers Younger years, Middle 
years, and Silver years including subjects on Money, Love, Fortune, 
Misfortune, Off-Springs, Siblings, Career, Success, and your Life 
Expectancy.  It even covers on the disease you are prone to from the 
birth so that you can keep yourself aware and what year it is good 
for you to conceive a child and give birth to.  It also covers your 
children's suitable career and success as well.  So after all, it's 
not just for your benefit to know what to watch out for and what to 
go for.  It's for your family's benefit as well since the reading 
covers generations.   

Just send a check or money order in amount of $19.99 to the address 
below to receive your own copies of a complete and comprehensive 
readings of your life.  Do not miss on this introductory offer!  
You will not be disappointed.  For those of you who do not know the 
time you were born, just submit year month and day anyways to get a 
reading that will change your life forever.

Make your check payable to :

        CRYSTAL 
        P.O.Box 397206, Cambridge, MA 02139-7206
        United State

***** Please include an envelope with return address ***** 



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

Date: 3 Apr 1997 20:43:04 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: !! Ancient Chinese Fortune Reading !!
Message-Id: <5i14oo$6ib@fridge-nf0.shore.net>

CRYSTAL (crystal@fortune.reading.com) wrote:
:         !! Ancient Chinese Fortune Reading !!

: There's a 5000 Year Old Fortune Reading Secrets of China that 
: Will Reveal Your Whole Life before your own eyes !  

I foresee that you will be reported to your systems administrator,
grasshopper.  :-)

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 03 Apr 1997 16:32:45 -0500
From: Ken Anderson <anderson@necsys.gsfc.nasa.gov>
Subject: Arithmetic expressions??
Message-Id: <y7x912zx05e.fsf@necsys.gsfc.nasa.gov>


Hi,

'nother question that i can't seem to find an answer to
in my book (the camel one):

i have 3 file tests to see if there are a sequential set
of files present, i.e. file($n-1),file$n,file($n+1).
The problem is pretty much exactly shown: i can't seem
to get perl to evaluate the arithmetic expressions within
the filetest. in other words, this won't work:


-e "file"$n+1 ...       # barfs
-e "file"($n+1) ...	# barfs
-e file$n+1 ...		# barfs
-e "file$n+1"	...	# of course, barfs

(by barfing i mean it doesn't eval the $n+1)
What i am looking for a ksh-like ability to evaluate the
arithmetic expression on the fly. 

eg.	in ksh one could do this

	if [[ -a file$(($n + 1)) ]]  

i have tried using eval { }
but it is more trouble than simply doing this:

$f1=$n+1; -e $f1 ...

>From a previous discussion in this group, i have developed the
feeling that once Perl has decided on a context, you're stuck.

is there a trick??

thanks!!

ken

-- 

	The earth is spinning madly through space and I
	sit in front of a TV screen all bloody day.
--------------------------------------------------------------------
Kenneth Anderson                |    Code631 Astrophysics Data Facility
Hughes STX                      |    email: anderson@ssvs.gsfc.nasa.gov
Goddard Space Flight Center     |    ph:    301 286 1375
Greenbelt, MD                   |
--------------------------------------------------------------------


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

Date: Thu, 03 Apr 1997 12:10:29 -0500
From: Ray Cromwell <ray@westlake.com>
Subject: current dir curiousity
Message-Id: <3343E485.690@westlake.com>

Recently, I had the problem of trying to obtain the current 
directory. This hadn't been a problem, for years, I used `pwd` on
unix. The problem is, it doesn't work on NT (and `cd` has a side
effect on some shells of sending you to the home directory on NT)

I can't even imagine what I'd do on Mac/VMS/Amiga/OS2/etc

I'm using the Cwd module in perl5 now which works, but when I saw
the code, I felt elegance go out the window ;-)

Why is there no native getwd() or getcwd() function in perl?
Perl has a mapping to just about every other Unix/POSIX call,
but not something basic like getwd()  Was it just an oversight,
was `pwd` assumed "good enough?" Is there a security issue?

I assume that getwd/cwd could be ported to other platforms too.

Just curious,
-Ray


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

Date: Thu, 03 Apr 1997 15:10:19 -0600
From: Eryq <eryq@enteract.com>
To: ray@westlake.com
Subject: Re: current dir curiousity
Message-Id: <33441CBB.32E4AEFF@enteract.com>

Ray Cromwell wrote:

> I'm using the Cwd module in perl5 now which works, but when I saw
> the code, I felt elegance go out the window ;-)

Portable code usually looks a bit ugly.  I had the same reaction
when I first popped the hood of my car (yuk! couldn't this have
been a little smaller and cleaner?).  My car still runs great,
though...

 
> Why is there no native getwd() or getcwd() function in perl?
> Perl has a mapping to just about every other Unix/POSIX call,
> but not something basic like getwd()  Was it just an oversight,
> was `pwd` assumed "good enough?" Is there a security issue?
> 
> I assume that getwd/cwd could be ported to other platforms too.
> 
> Just curious,
> -Ray

I take it:

	use POSIX 'getcwd';

doesn't meet with your approval?  :-)

-- 
  ___  _ _ _   _  ___ _   Eryq (eryq@enteract.com)
 / _ \| '_| | | |/ _ ' /  Hughes STX, NASA/Goddard Space Flight Cntr.
|  __/| | | |_| | |_| |   http://www.enteract.com/~eryq
 \___||_|  \__, |\__, |___/\  Visit STREETWISE, Chicago's newspaper by/
           |___/    |______/ of the homeless: http://www.streetwise.org


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

Date: 3 Apr 1997 21:38:46 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: File Read/Write Problem
Message-Id: <5i1816$5la$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    brian nahas <bnahas@darwin.cc.nd.edu> writes:
:	I need a little help.  I am trying to open a file
:for read and write access.  I am trying to read up to a certain
:point and then write over the rest.  I am opening the file using:
:open(FILEHANDLE,"+<filename");
:This allows me to read up to a certain point, but then when I write
:it appends to the end of the file.  

Mixing reads and writes on the same stdio buffer is awfully
daring.  Don't do it.

:If I use: 
:open(FILEHANDLE,"+>filename");
:I am not able to read from the file.  It is a rather large file
:so I do not want to have to read it all in to an array and then
:do my editing.  Any help would be greatly appreciated.  Thanks.

Of course you can't read it: you just destroyed it: that's what +> does.

What is it with everyone that they can't or won't deal with the obvious
way to update a file: make a temp with the new stuff and move the new
back to the old?  That's what the -i flag does, you know.

Have you read the FAQ about how to insert a line in a file or change a line at
one point?  It's the same thing.

You do not, except under weird cases, actually update a text file.  You
just make a copy with the changes and rename the copy to the original.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
                /* And you'll never guess what the dog had */
                /*   in its mouth... */
        --Larry Wall in stab.c from the v4.0 perl source code


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

Date: Thu, 03 Apr 1997 04:17:54 -0800
From: Ethan Joffe <ethan@worldsite.net>
Subject: fractional second timing
Message-Id: <33439FBD.3223@worldsite.net>

Anyone know how to do sub-second timing in Perl on an SGI?
I need actual time, not processor time ala 'times'.

Ethan Joffe
Director of Technology
WorldSite Networks


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

Date: Thu, 3 Apr 1997 14:46:25 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: HELP with perl array
Message-Id: <1v41i5.uqu.ln@localhost>

anna (anna@water.ca.gov) wrote:
: Hi,
: I was wondering if you could help me.

: I have a large flatfile which I can open in perl.  I would like to set up 
: the data in an array, so I can search the data.  The file has many 
: lines.  Each line has 5 elements separated by tabs.  I would like to 
: search for a particular value in element 2 and then if the value of 
: element 2 is the right one, perform a calculation on element 4.

: The data file has the following format:
: B12345	10/01/95	00:00	2.56	85
: B12345	10/01/95	12:00	4.32	85
: B12345	10/05/95	00:00	5.96	85
: B12345	10/05/95	12:00	3.16	85

: My attempt at building an array doesn't produce the right results.  
: Rather than printing  a singular value, it prints all the values for 
                                             ^^^^^^^^^^^^^^^^^^^^^
: element 4.  See code below.
                  ^^^^^^^^^^

That code below doesn't print all the values for me.

Where does $calc get set to some value?



: I would appreciate any help you can offer.



: _____

: #!/usr/local/bin/perl

Hey! Please don't post to the newsgroup without trying your script
with the -w switch first.

Let perl help you with your debugging...


#!/usr/local/bin/perl -w
#                     ^^


: $infile = B12345.txt
: open(DATA,"$infile") || die "Can't open data file. \n";
: @lines = <DATA>;
: close(DATA);
: foreach $line (@lines) {
:   ($id, $date, $time, $cost, $code) = split(/\t/, $line);
: 	print $calc;
: }


-------------------------------
#! /usr/bin/perl -w

chomp(@lines = <DATA>);

$calc = 0;

foreach $line (@lines) {
   ($date, $cost) = (split(/\t/, $line))[1,3]; # only take what we need

   if ($date eq "10/05/95" ) {
      $calc += $cost;
   }
}

print "total cost for 10/05/95 is \$$calc\n";


__DATA__
B12345	10/01/95	00:00	2.56	85
B12345	10/01/95	12:00	4.32	85
B12345	10/05/95	00:00	5.96	85
B12345	10/05/95	12:00	3.16	85
-------------------------------


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 3 Apr 1997 20:10:41 GMT
From: aspgdng@cmc.doe.ca (Desmond Ng)
Subject: MultiDimensional Arrays?
Message-Id: <5i12s1$fse$1@calvin.risq.qc.ca>

Hello, I am having some trouble with 2D arrays in PERL5.  This is my code
open (OUT, "+> file.out") || die; 
        @input = split (' ', $_);{
        print; 
                for $i (0..$#input)
                                print "i: $i input:  $input[$i]\n";  {
                                if(!defined ( $counter[$i]))
                                                
$counter[$i] = 0;  {
                                
$arr[$i][$counter[$i]] = $input[$i];  }
                                print "counter[i]: $counter[i]\n"; 
                                $counter[$i] = $counter[$i] + 1; 
                                print OUT "array =
"$arr[$i][$counter[$i]]"\n"; 
                close (OUT);} }
                close (DATA);  

at the print to the filehandle OUT, everything is blank. I printed
thecounter and the input and it was fine. Can anyone please tell me what
is wrong here? 

Thanks in advance.  

-Desmond Ng 
desmond.ng@ec.gc.ca



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

Date: Thu, 03 Apr 1997 20:34:18 GMT
From: alaric@abwillms.demon.co.uk (Alaric B. Williams)
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <334412fb.7359993@news.demon.co.uk>

On 02 Apr 1997 15:57:57 +1000, Chris Bitmead
<Chris.Bitmead@alcatel.com.au> wrote:

comp.lang.scheme,comp.lang.scheme.scsh,comp.lang.lisp,comp.lang.tcl,comp.lang.functional,
comp.lang.c++,comp.lang.perl.misc,comp.lang.python,comp.lang.eiffel

(Wince) isn't that a trifle over-crossposted? I'm crossposting it
still myself since I have a statement to make that's really for
everyone who got this... but, lads, can we limit it from now on?
Otherwise, there will be arguments about scheme/TCL in the
Python group, Python/TCL in the C group...

[...]

>NOW LOOK AT TK!!!! It's object oriented!!!!!!! It's based on all the
>principles that Ousterhout is deriding. I must say this makes him look
>like a fool.

[etc]

Ok, everyone has some valid points against JO's paper. I agree, it
does seem somewhat commercialised... but he hasn't had a chance
to respond to our criticisms yet! Therefore, I've mailed him
with a memo to draw his attention, and we'll see what he has to say.

Not that I want to "support" him, it's just that it seems a little
unfair to proclaim our hatred of the guy without hearing what he has
to say. How do we know he won't go "What? That's not my paper! Why,
the little b*****ds have hacked into my account again!"...

Maybe we're all wrong, maybe he's wrong; either way, let's
fight it out rather than merely argue with ourselves about who'd
win the fight :-)

Here's the reply I had:

-----B<-----

To:               alaric@abwillms.demon.co.uk
Subject:          Re: TCL uproar on comp.lang.scheme 
Date sent:        Wed, 02 Apr 1997 13:31:40 -0800
From:             John Ousterhout <ouster@tcl.Eng.Sun.COM>

I've been totally swamped with email the last week so I'm running
way behind on everything, but I'll try to take a look at the
discussion
on comp.lang.scheme and reply.  Thanks for your message.

-----B<-----

Okay... everyone to their trenches...


ABW
--
"Plug and Play support: WfEWAD will autodetect any installed
Nuclear Arsenals, Laser Satellites, Battlefield Control Networks,
Radar Installations, Fighter Squadrons, and other WfEWAD compliant
devices, including the new Macrosoft Unnatural Keyboard, with
full support for the now-famous Big Red Buttom(tm)."

(Windows for Early Warning and Defence User's manual P26)

Alaric B. Williams Internet : alaric@abwillms.demon.co.uk
<A HREF="http://www.abwillms.demon.co.uk/">Hello :-)</A>


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

Date: 3 Apr 1997 20:49:01 GMT
From: scott@lighthouse.softbase.com ()
Subject: Re: Perl vs. C/C++
Message-Id: <5i153t$f86$1@mainsrv.main.nc.us>

Dan Corbett (dcorbett@jcaho.org) wrote:
: I am evaluating languages to use for creating a program to basically
: read in a file, parse out some text, and rewrite the file.

Having used perl and many other languages, I must say I prefer
perl for any type of text file grinding and munging. Also, unless
the program (and sometimes even if) needs to be distributed
as a top-secret trade secret or has to do exotic system 
interfacing, or has to link in to other code, perl can be
written extremely fast. You're still rewriting C memory
management routines by the same point in time you'd be
finished in perl.

: 	1) How easy is it to learn?

IT DEPENDS. (That's the answer to ANY computer related question!)
If you have a strong background in vi, awk, shell languages, and
UNIX in general, and know regular expressions inside and out, and
know C, perl is simple. If you've *NEVER* used regular expressions
before, and aren't well soaked in the UNIX culture, then you're
in for a steep, steep learning curve. Also, if you're not
lazy and don't enjoy writing programs by taking advantage of
language elements and conventions, perl will take some
getting used to! If you enjoy hacks, shortcuts, and speed, perl
is much more fun. (Hint: if the first thing you do when writing
a new program is draw a flow chart, perl is probably not for you.)

If you know perl, it is much, much faster to write things than
in C because perl does so much drudgery like memory management for
you. If you don't know perl well, development may not be faster.

: 	2) How well does it handle files and strings?

Not only those two, but *LISTS*. The missing link in C (if you'll
pardon the pun) is lists. You have data in a file.  You have strings.
The missing link is chopping the records into fields. You can do this
in C via parsing, but in perl, lists are much easier. From file
to string to list of fields in the string is trivial in perl.

Perl handles strings at a much higher level than C! All memory
allocation and management is done for you, and that code
was written to be very efficient by a master hacker. Thus,
all you do is use strings without worrying about them.

Perl handles files better than C does, because it allows you to
read the entire file into an array with one fell swoop, and process
the array. (You don't even have to explicitly define the array! :))

: 	3) What about support and documentation?	

Perl actually works, which makes support less relevant than it
would be for other things. Also, you have the source code, so you
can fix it when it doesn't. (People who use perl tend to be
people who could do that, and the time savings are enormous.)
Perl is copiously documented both online and through the
Camel book.

: 	4) What about all this CGI and webserver stuff, etc. 

This doesn't seem to have any relevancy to your project as
described above. Perl is a good CGI language simply because
CGI involves parsing a heck of a lot of name=value pairs.

Scott



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

Date: Thu, 03 Apr 1997 14:54:26 -0500
From: Terry Walker <twalker@voyager.cmp.com>
Subject: Perl-5.003 test error
Message-Id: <33440AF2.51E9@voyager.cmp.com>

I've successfully compiled perl-5.003 on my Solaris 2.5 system. However,
when I issue the make test command I get the following error for
lib/gdbm:

lib/gdbm.......Can't load '../lib/auto/GDBM_File/GDBM_File.so' for
module GDBM_File: ld.so.1: ./perl: fatal: relocation error: symbofound:
gdbm_sync: referenced in ../lib/auto/GDBM_File/GDBM_File.so at
 ../lib/DynaLoader.pm line 140.
 
 at ../lib/GDBM_File.pm line 81
BEGIN failed--compilation aborted at ./lib/gdbm.t line 14.

Does anyone know how I can get around this?

Thanks!
-- 
-------------------================*================--------------------
Terry Walker                           email:    twalker@cmp.com
Systems Administrator                  www:      http://techweb.cmp.com	
CMP Media Incorporated                 voice:    (516) 562-5754
600 Community Drive                    fax:      (516) 562-7488
Manhasset, N.Y. 1103


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

Date: 3 Apr 1997 21:21:05 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl-5.003 test error
Message-Id: <5i1701$8o9@fridge-nf0.shore.net>

Terry Walker (twalker@voyager.cmp.com) wrote:
: I've successfully compiled perl-5.003 on my Solaris 2.5 system. However,
: when I issue the make test command I get the following error for
: lib/gdbm:

Did you choose dynamic loading (y)?  If so, did you choose the correct
dynamic loading type? (I *think* it should be dldopen, but it's been
awhile since I've built our Solaris 2.5 version, so I'm not sure - this
*is* listed in the Perl install doc, however.)

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Thu, 03 Apr 1997 14:31:18 -0500
From: Dan Boorstein <danboo@ixl.com>
To: "C.D. Tobola" <ctobola@rrnet.com.spam>
Subject: Re: Reading data from _DATA_
Message-Id: <33440586.7CB1@ixl.com>

C.D. Tobola wrote:
> 
> I'm a perl newbie -- hope this question isn't too foolish....
> 
> I'm building a simple database program. The data is stored after the
> program code using the _DATA_ filehandle.
> 
> Can someone tell me how to read the data (one line at a time) into an
> array. I know how to use iteration -- just don't know how to access 

while (<DATA>) {
  s,\n, ,;
  print;
}

__DATA__
this
information
is
available
on
page
44
of
the
latest
camel



Dan Boorstein
danboo@ixl.com


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

Date: 3 Apr 1997 20:54:43 GMT
From: "Stephen Hill" <scs@huron.net>
Subject: Replacing text
Message-Id: <01bc4070$b0b99b40$1b91e9cd@scs>

I have written a script that searches a database and then prints out the
search results. I want the words that were used for the search to be
printed it red. The portion of script below does it, with one PROBLEM. 

If @keywords has one item in it, when the results are printed, the one
keyword that was searched on does not appear!?!
if @keywords has two items, the first word appears in red and the other is
missing
if @keywords has three items......1 & 2 show up and the 3rd is missing
if @keywords has four itmes they ALL appear!!!



@lines[$i] =~ s/@keywords[0]/<FONT COLOR=\"FF0000\">@keywords[0]<\/FONT>/i;
@lines[$i] =~ s/@keywords[1]/<FONT COLOR=\"FF0000\">@keywords[1]<\/FONT>/i;
@lines[$i] =~ s/@keywords[2]/<FONT COLOR=\"FF0000\">@keywords[2]<\/FONT>/i;
@lines[$i] =~ s/@keywords[3]/<FONT COLOR=\"FF0000\">@keywords[3]<\/FONT>/i;
        

@item = split(/\t/,@lines[$i]);
print "<I>Order Number:</I><B>@item[0]</B><BR>";
print "<I>Item:</I> <B>@item[1]</B><BR>";
print "<I>Medium:</I> <B>@item[3]</B><BR>";
print "<I>Company:</I> <B>@item[4]</B><BR>";
print "<I>Retail:</I> <B>\$@item[8]</B><BR><HR>\n";

Please HELP.....Don't be too technical, I am just learning :-)





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

Date: Thu, 03 Apr 1997 13:16:14 -0800
From: Mike Werner <mtw@eng.sun.com>
Subject: Re: Running program on a remote machine
Message-Id: <33441E1E.68C5@eng.sun.com>

I've heard there is a perl library called chat2.pl which will
allow you to do such things.

I'd give you a pointer to some info; however, it was my search
for the same which brought me here.

Typically in the past I have used TCL and Expect for automating
interactive processes; but they have their own limitations.

mtw


Bob Bell wrote:
> 
>         I'm a fairly experienced programmer, but I'm new to Perl, so I appreciate
> your patience.  I am interested in using a Perl program where part of it
> would require running a program on a remote server.  For instance, if you
> were doing it manually, you could telnet to the machine, log in, and run
> the program.  Is there a way to do this in Perl code?  I haven't really
> messed around with Perl modules yet, so it there some prebuilt code I
> should be looking for?  Thanks, it is appreciated.  E-mail replies would
> probably be best, and URLs to sites with the info I need would be excellent
> (save you time and let me learn more in the process).
> 
>                         - Bob Bell
>                         bbell@voicenet.com


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

Date: Thu, 3 Apr 1997 14:48:51 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Simple array question by newbie...
Message-Id: <j351i5.uqu.ln@localhost>

Alan Weiner (alweiner@clark.net) wrote:
: I've written a simple subroutine which inputs a month and returns the 
: next month.  However, it doesn't seem to work :)  

: 1) Is there a better way to do this?
: 2) What am I doing wrong?

: Here's what I've got:


: @months=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","No
: v","Dec","Jan");

: $nxtMonth=getNxtMonth("Mar");
: print "$nxtMonth";

: sub getNxtMonth {
: local($thisMonth)=@_;
: foreach (@months) {
:     if($thisMonth == $_) {
                    ^^

That is for comparing numbers. You are comparing strings with it.

if($thisMonth eq $_) {

:             return ($months[$#months+1]);
:             }
:     }
: }

: Thanx for any help you can provide!  Pls post the answer here...



--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Thu, 03 Apr 1997 16:08:32 -0500
From: Bill Kuhn <wkuhn@uconect.net>
Subject: Re: Simple array question by newbie...
Message-Id: <33441C50.6FF28C21@uconect.net>

You could use a date manipulation package available at a CPAN site that
lets you do a million and one things with dates (formatting,
computation, etc.).  A package like that may be overkill for what you
want to do.

Now, what you are doing wrong is comparing two strings with ==.  You
should use eq or cmp to compare strings.

If the array months is being used for no other reason than to find the
next month, you may consider using an associative array where the key is
a month and the value is the next month:

$month_to_next = ('Jan','Feb',
    'Feb','Mar',
    etc.,etc.,etc.) ;

Then you could just do:
$nxtMonth = $month_to_next{'Mar'} ;

There are probably a dozen other ways to do it...

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Thu, 03 Apr 1997 15:32:06 -0600
From: Ciaran Benson <ciaran@netco.com>
Subject: Re: Simple array question by newbie...
Message-Id: <334421D6.167E@netco.com>

Alan Weiner wrote:
> 
> I've written a simple subroutine which inputs a month and returns the
> next month.  However, it doesn't seem to work :)
> 
> 1) Is there a better way to do this?
> 2) What am I doing wrong?

Hello Alan;

As for #2, foreach is pretty handy when you don't need to keep track of
where you are, but I've never found a good way of extracting 'whereIam'
from inside one.  foreach crawls through the array using it's own
internal order, and what it thinks is 'next' is rarely what you put into
it 'next'.

As for #1, I think the most immediate and readable way would be a for
loop.  This maintains the basic structure of the script you posted, and
should work in all cases.  I like to avoid for loops 'cause they remind
me too much of Fortran, but hey - this is the kind of work that for
loops were made for.

  print &getNxtMonth("Mar")."\n";
  exit 0;

  sub getNxtMonth {
    my ($thisMonth)=@_;
    my $count;
    my @months =
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct",
                  "Nov","Dec","Jan");
    #  count through the months
    for ($count=0 ; $count < 12 ; $count++) {
      if($thisMonth eq $months[$count]) {
        return ($months[$count+1]);
      }
    }
  }

But ... you do can also do this:

  print &parseNextMonth("Mar")."\n";
  exit 0;

  sub parseNextMonth {
    my ($now)  = @_; my $months =
("JanFebMarAprMayJunJulAugSepOctNovDecJan");
    return substr($months, (index $months,$now,0)+3, 3);
  }

Perl rocks.

-- 
Ciaran Benson                                     Network Programmer
ciaran@netco.com                       Wam!Net, Netco Communications
'No, Zathros not understand, but Zathros do. Zathros good at doings'


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

Date: Thu, 3 Apr 1997 20:25:44 GMT
From: jim_shi@franklin.com
Subject: string comparision
Message-Id: <5i14ju$56l@hideout.emanon.net>

Hi, how to compare two string in unsigned order, ie. treat them as strings of unsigned
characters. Thanks.

jim



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

Date: Thu, 03 Apr 1997 15:35:55 -0600
From: Eryq <eryq@enteract.com>
To: jim_shi@franklin.com
Subject: Re: string comparision
Message-Id: <334422BB.429DF349@enteract.com>

jim_shi@franklin.com wrote:
> 
> Hi, how to compare two string in unsigned order, ie. treat them as strings of unsigned
> characters. Thanks.

If you meant "strings of unsigned bytes"... then 'eq' works 
fine. 

If you meant to say "case-insensitive", so that "AbC" is equal
to "ABC" and "abc", then:

    sub ci_eq { lc($_[0]) eq lc($_[1]) }

    if (ci_eq("abc", "AbC")) {...

should do the trick.

-- 
  ___  _ _ _   _  ___ _   Eryq (eryq@enteract.com)
 / _ \| '_| | | |/ _ ' /  Hughes STX, NASA/Goddard Space Flight Cntr.
|  __/| | | |_| | |_| |   http://www.enteract.com/~eryq
 \___||_|  \__, |\__, |___/\  Visit STREETWISE, Chicago's newspaper by/
           |___/    |______/ of the homeless: http://www.streetwise.org


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

Date: Thu, 03 Apr 1997 20:05:01 GMT
From: ted@qp.com (Ted Yee)
Subject: Re: String substitution problem
Message-Id: <33440b8b.1273083@nntp.netcruiser>

On 2 Apr 1997 11:28:37 GMT, dblack@icarus.shu.edu (David Alan Black)
wrote:

>I can't duplicate your error:
>
>candle:~$ perl -w
>$string = "this is a test";
>$term = "is";
>$string =~ s/$term/replace with this/gi;
>print "$string\n";
>^D
>threplace with this replace with this a test

Sorry, I tried to make it as generic as possible in case it might be
of use to other people. (I guess I made a mistake) Anyways, here's the
exact code snippet:


    $idx = 0;
    while ($idx <= $#terms) {
        $line =~ s/($terms[$idx])/<FONT COLOR="#FF3333">$1<\/FONT>/gi;
        $idx++;
    }

The problem comes up if you use "o" as a search term or anything that
will match FONT COLOR.



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

Date: Thu, 03 Apr 1997 14:00:38 -0600
From: Eryq <eryq@enteract.com>
To: Tom Grydeland <tom@eiscat.uit.no>
Subject: Re: The theoretically fastest way to iterate through all bytes in a string...?
Message-Id: <33440C66.7265478A@enteract.com>

Curiously, no-one suggested the one that seems to beat the
others hands down, "for/vec" in my example below:

----------------------------------
#!/usr/local/bin/perl -w

use Benchmark;
 
timethese(20, {
    'while'      => '$tot = 0;$_ = "12345" x 20000;
                    while(/(.)/g) {$tot += $1}',
    'for/unpack' => '$tot = 0;$_ = "12345" x 20000;
                    for (unpack "C*", $_) {$tot += $_}',
    'for/vec'    => '$tot = 0;
		     $_ = "12345" x 20000;
	             $len = length($_);
		     for ($i=0;$i<$len;$i++) {$tot += vec($_,$i,8)}',
});
----------------------------------


*** With "12345" x 200, I get: 

   for/vec:  0 secs ( 0.22 usr  0.00 sys =  0.22 cpu)
            (warning: too few iterations for a reliable count)
for/unpack:  0 secs ( 0.30 usr  0.05 sys =  0.35 cpu)
            (warning: too few iterations for a reliable count)
     while:  2 secs ( 1.84 usr  0.06 sys =  1.90 cpu)


*** With "12345" x 2000, I get: 

   for/vec:  2 secs ( 2.32 usr  0.01 sys =  2.33 cpu)
for/unpack:  4 secs ( 3.23 usr  0.41 sys =  3.64 cpu)
     while: 21 secs (18.49 usr  0.10 sys = 18.59 cpu)


*** With "12345" x 20000, I get: 

   for/vec: 25 secs (23.39 usr  0.13 sys = 23.52 cpu)
for/unpack: 44 secs (33.27 usr  3.75 sys = 37.02 cpu)
     while: [forget it...]


Is it just too "unhip" to use such an approach, with its
boring for() loop and no regular expressions?  :-)

-- 
  ___  _ _ _   _  ___ _   Eryq (eryq@enteract.com)
 / _ \| '_| | | |/ _ ' /  Hughes STX, NASA/Goddard Space Flight Cntr.
|  __/| | | |_| | |_| |   http://www.enteract.com/~eryq
 \___||_|  \__, |\__, |___/\  Visit STREETWISE, Chicago's newspaper by/
           |___/    |______/ of the homeless: http://www.streetwise.org


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

Date: Thu, 03 Apr 1997 13:20:21 -0800
From: Steve Thatcher <sdt1@rsvl.unisys.com>
To: Afgin Shlomit <vshlomit@wishful.weizmann.ac.il>
Subject: Re: Usyng the 'system' function from perl.
Message-Id: <33441F15.22C2@rsvl.unisys.com>

Afgin Shlomit wrote:
> 
> Hi
> 
> I tried to use the system function in a perl script with no success.
> my system line look like:
> system("sort -r group1.sum > group1tmp.sum");
> but the file group1tmp.sum is empty, not contain the sort output.
> ofcourse the file group1.sum contain lines.
> 
> Please reply to vshlomit@wishful.weizmann.ac.il.
> Thanks,
> --
> 
>         Shlomit.Your server probably does not have write access to the directory you are 
re-directing to


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

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

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