[6937] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 562 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 3 06:11:27 1997

Date: Tue, 3 Jun 97 03:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 3 Jun 1997     Volume: 8 Number: 562

Today's topics:
     Re: *NOT SPAM* Apprentice Perl Hacker, Summer Work Offe (Mark Mills)
     Announcement: GroupLens Recommendation Service has Star (Jon Herlocker)
     dbi and informix <areeves@goodnet.com>
     Re: Desparately Seeking Assistance - Numbers Calculatio (Mark Mills)
     Re: Embed perl script in HTML <jason@spewww.com>
     Re: filter out uids below 100 <keys@babylon5fan.com>
     Help for "date" (Jun Zhuang)
     Re: inconsistent opendir behaviour in Perl for win32 (Simon Oosthoek)
     Re: Isdigit(), isalpha()  in Perl <jbokma@caiw.nl>
     leading zeroes <mariana.wuerz@fernuni-hagen.de>
     most *robust* DBD::DBI/database combination ( <1M recor (Linux_User)
     pack template that packs like 'a' but unpacks like 'A' <uwe@ptc.spbu.ru>
     pipes , tail, and buffering? (M Melick)
     printing a hash in order? (Andrew Starr)
     Re: problem searching fielded data (David S. April)
     reading and writing from/to the same file <thordur@eunet.no>
     Re: Reading Comma delimited, Quoted String records (O'Shaughnessy Evans)
     Recursive include in parsed file (Sandy Herring)
     Re: Server side includes to run Perl scripts from web p <keys@babylon5fan.com>
     Re: Slices of lists (Mark Mills)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 03 Jun 1997 06:17:08 GMT
From: mark@ntr.net (Mark Mills)
Subject: Re: *NOT SPAM* Apprentice Perl Hacker, Summer Work Offered
Message-Id: <3394b30d.12764996@news.ntr.net>

On Thu, 29 May 1997 19:26:30 -0400, "Robert S. Kissel"
<kissel@kissel.spicerack.ibm.com> wrote:

>I have suitable work for an apprentice Perl hacker (college student,
>or even high-school, if you're real good).  The location is Westchester
>County, just north of the Tappan Zee bridge.
[snippage]
>Lunatics preferred.  You won't need a tie, and you'll be reporting to
>other lunatics.

*NOT SPAM* Apprentice Perl Hacker, Summer Work Offered

Hmm... 

I looked all over Kentucky and Indiana maps trying to find out where
you county is.

My friends in Florida, California, Nebraska, and Colorado looked for
it on their maps.

My pal in Weisbaden Germany looked for it all over Europe.

Finally my friend in New Jersey reported back that it was in New York
State.

You just announced, to the _WHOLE WORLD_, that you have _ONE_ job
available north of a locally famous tourist attraction...

*IS SPAM*

Don't take this too harshly but your note is right, you are a lunatic.

(OK, I admit, I knew where it was...  Historical Rivertowns blah blah
blah. Still.  HUNDREDS of servers all over the world now have your
_LOCAL_ job offer and my sarcastic reply.  At least someone in Germany
might be amused at mine, but yours...  No wonder my friends in Europe
think we're all ego-centric, you didn't even list the _STATE_!)
-- 
[Hopper, Dennis]: There's mines over there, there's mines over 
there, and watch out those goddam monkeys bite, I'll tell ya.
==Apocalypse Now==


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

Date: 3 Jun 1997 03:48:33 GMT
From: herlocke@caesar (Jon Herlocker)
Subject: Announcement: GroupLens Recommendation Service has Started!
Message-Id: <5n046h$fm4@epx.cis.umn.edu>
Keywords: Collaborative Filtering, information overload, recommendaton service

The GroupLens Recommendation Service is now available to
the public. We encourage everyone to go to the GroupLens
web page (http://www.cs.umn.edu/Research/GroupLens) to register
a pseudonym and to download a GroupLens-enhanced news client.

The GroupLens system is a personalized recommendation system for
Usenet news that helps you find the good articles fast, and to avoid
the trash.  To help you determine the quality of an article, a
GroupLens-enhanced newsreader displays a prediction of quality next to
the subject of an article. Based on this prediction you can chose
whether or not to spend the time to read the article. 

For more detailed information on how the GroupLens service works,
please please see the original announcement attached to the end of
this article. The GroupLens service is a research project from the
University of Minnesota and is available completely free of charge.

Currently, the GroupLens recommendation service is in what we
call a "beta" state. We are calling this a beta release for
three reasons:
        1. We are still tuning the system, and we may have to
                occasionally bring the server down for short
                periods of time.
        2. There are only a small number of GroupLens-enhanced
                newsreaders.
        3. There may be further releases of the currently
                available GroupLens-enhanced newsreaders.

Beta does not mean that the service is unstable or untested! The
server has been tested, and has been working non-stop for several
weeks already.

All of your personalization information will be carried over when we
move from the beta stage to the final release stage, so there is not
reason not to start taking advantage of GroupLens immediately.

This article is being posted in all newsgroups that will fully support
personalized predictions from the GroupLens server.

Note that recommendations will be provided for all newsgroups! However
in most newsgroups, the predictions will not be personalized, as the
prediction will just be an average of all ratings given for an
article. Currently we will be providing personalized predictions for
approx. 30 different diverse newsgroups, which are listed at the end
of this news article.  Note that the average predictions will still be
extremely valuable in handling the information overload in Usenet
news, they just won't be as accurate as the personalized predictions.

When you first enter a newsgroup, you may find that there are no
predictions. You will not receive predictions until there is at least
one other person using a GroupLens-enhanced newsreader in the
newsgroup. The best solution is to encourage other people in the
newsgroup to use GroupLens-enhanced newsreaders.

If you have any questions whatsoever, please feel free to contact me.
        Jon Herlocker
        GroupLens Coordinator
        herlocke@cs.umn.edu

----

Announcement: GroupLens Usenet News Recommendation Service
------------------------------------------------

Beginning in May 1997, the University of Minnesota will make Usenet
useful again with the GroupLens(TM) Research collaborative
recommendation system. Finding articles of interest and filtering out
noise in Usenet newsgroups will no longer be taxing. The GroupLens
system will advise you as to which articles have interesting content
and which ones should be ignored. The recommendation service will be
free to the general public, but limited to 10,000 users.

How does GroupLens help you?
------------------- 
Internet newsgroups can carry hundreds of new postings every day.
Many of these articles are off the newsgroup topic, and many more are
not personally interesting to you. It is no longer feasible to read
every article posted to a newsgroup in order to find interesting
content. The GroupLens system makes reading Internet news productive
again by highlighting articles of likely interest and warning against
articles that will not be interesting. Using the GroupLens system, you
won't miss the good articles and you won't waste your time on the bad
ones.

How does it work?  
------------------- 
When you first see an article in a newsgroup, chances are that it has
already been read by lots of other people. Each of these people formed
an opinion of how interesting the content of that article is. Imagine
you could talk to each of these people and could ask them for their
opinions of the quality of the article. Based on these
recommendations, you would determine if it was worth your time to read
the article. Of course you can't talk to all those people, but the
GroupLens system can, and all you have to do is tell GroupLens your
opinion on articles you read. Users of the GroupLens service are asked
to rate each article on a scale of 1 to 5, based on how interesting
they found the article. The GroupLens system takes everybody's ratings
and matches people who agree frequently.  When you first see a new
article, the recommendation system uses the ratings of people who
agree with you to generate a prediction of your interest in the
content of the article.

How do I use it?
--------------------
It's simple! First you must register to become a user of the GroupLens
recommendation system through the GroupLens Research web page at
http://www.cs.umn.edu/Research/GroupLens. When the service trial
begins in May, make sure that you are using a GroupLens-enabled
newsreader (see next question). You will immediately begin seeing
predictions for articles. After reading each article, make one
keystroke to rate it on a scale of 1 to 5.

In the beginning, the predictions will be an average of everybody's
ratings, but as you rate articles the GroupLens system will be able to
provide predictions that are more tuned to your personal interests.

Can I use my favorite newsreader?  
--------------------- 
Yes! You can take advantage of the GroupLens system no matter what
newsreader you are using. However, to get the full utility of the
GroupLens service, you must use a newsreader that has been outfitted
to support the GroupLens protocol. The University of Minnesota has
added support to several popular, freely available newsreaders,
including Gnus, XRN, tin, and WinVN. However, if you use a newsreader
that is not supported, do not despair! We will be providing an
additional service which should allow any newsreader to take advantage
of the recommendation service.  To learn more or find out if your
favorite newsreader is supported, please see the GroupLens Research
web page at http://www.cs.umn.edu/Research/GroupLens.

What newsgroups will be supported?
--------------------
We haven't yet chosen the newsgroups that we are going to support,
but we hope to support any newsgroup that has readers who want to
use the GroupLens system. As a service to the Usenet community, we
will also provide average ratings to many of the groups that we do not
support. We hope to cover all of comp.* and rec.* with either personalized
predictions or average ratings. If you have a newsgroup that you would
like supported, please feel free to send us email at
<grouplens-info@cs.umn.edu>.

How long will this service be available?
---------------------
We are committed to provide provide this service for at least three
years. So you can count on GroupLens being there to help you to find
the information important to you through the end of the century.

What about privacy and censorship?
---------------------
Creating interest profiles of readers is an important part of the 
GroupLens recommendation system. Readers protect their privacy
by submitting ratings under a pseudonym instead of their real name.

The GroupLens recommendation system provides advice, not censorship.
When using GroupLens-enabled newsreaders, the reader is shown all
available articles together with predictions of the interest. No
articles are filtered out entirely.

Where can I go for more information?
---------------------
More information on the GroupLens recommendation system, including
published research papers is available on the GroupLens Research web
page at http://www.cs.umn.edu/Research/GroupLens. There is also a
mailing list for discussion of GroupLens technology. See the web page
for more information. If you have any questions or comments, you can
email them to <grouplens-info@cs.umn.edu>.

--
Jon Herlocker			herlocke@cs.umn.edu
Research Assistant              Home: (612) 288-9795 
Computer Science Department     Office: (612) 625-0304
4-192 EE/CS Building
University of Minnesota
Minneapolis, MN 55455


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

Date: Mon, 02 Jun 1997 14:36:43 -0700
From: Tony Reeves <areeves@goodnet.com>
Subject: dbi and informix
Message-Id: <33933CEB.43CC@goodnet.com>

Is anyone using dbi/dbd and informix? 
if so, do you have a source for examples on how to use dbi/dbd? 
I have a need to write some perl code to update a database and I have no
access to the dbi/dbd docs on teh isp were its installed..

-- 
---
Tony Reeves
N7SF - areeves@goodnet.com, tony@toners.com - HF: 14.242Mhz or 7.239Mhz
Homepage: http://www.toners.com - http://www.goodnet.com/~areeves
The secret to imortality: 4A 65 73 75 73


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

Date: Tue, 03 Jun 1997 06:47:31 GMT
From: mark@ntr.net (Mark Mills)
Subject: Re: Desparately Seeking Assistance - Numbers Calculation
Message-Id: <3395b95a.14377866@news.ntr.net>

On Fri, 30 May 1997 00:45:21 +0100, psychic@globalserve.net (Earl
Curley) wrote:

>Boy, do I need a hand.  I'm in a real bind.  I have been trying to
>calculate the following with no success.
>
>I need to reduce two number down to no higher than 10 or -10.  As an
>example if one of the numbers is 178, the number has to be reduced as
>such.  178 - 1 + 7 + 8= 16 =1 + 6= 7  the second number simply is the
>opposite direction -178 so therefore it would be:  -1 + -7 + -8 = -16 = -1
>+ -6 = -7 .  The high number is a maximum of 210.
>
>Thanks in advance.
>

#!/usr/bin/perl
for $x (-210..-195,-178,-16,-1,0,1,16,178,195..210)
        {
        print $x," ",$x-(int($x/9)*9),"\n";
        }

try that...

the trick of reduction you use is called "casting of nines"

and it reduces some integer into the range -8..8 inclusive.

$reduced = $x-(int($x/9)*9)

divides by 9, _truncates_ (not rounding!) value to integer, multiply
by nine, subtract from initial value.

For the whole numbers (0..infinity) it is the same as:
  $x % 9;

and for the negative numbers, the way you want them:
  ($x % 9)-9;

another way to write it would be:

$reduced = ($x/abs($x) * (abs($x) % 9);  # Except 0 kills it :>

or even:

$reduced = $x < 0 ? -(abs($x) % 9) : $x % 9;

I hope one of these makes sense to you.

Good luck.

BTW this is an old trick used by mathematicians, magicians, and human
calculators.  Useful on many an occasion...
-- 
[Hopper, Dennis]: There's mines over there, there's mines over 
there, and watch out those goddam monkeys bite, I'll tell ya.
==Apocalypse Now==


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

Date: Mon, 02 Jun 1997 21:04:14 -0700
From: Jason DeFillippo <jason@spewww.com>
Subject: Re: Embed perl script in HTML
Message-Id: <339397BE.54C2@spewww.com>

etta wrote:
> 
> <IMG SRC="/CGI-BIN/filename.cgi?">
> 
> Hope this helps
> 
> etta
> 
> On Thu, 29 May 1997 17:22:37 -0600, josephn@mail.mcoe.k12.ca.us wrote:
> 
> >I have written a perl counter script. I would like to call it from already
> >written html web pages. How do I go about this? Any comments would be
> >most appreciated. Thanks Joseph.

In a server side include page (.shtml) use <!--#exec
cgi="/cgi-bin/script.pl"-->

J-
Spew - http://www.spewww.com/


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

Date: Mon, 02 Jun 1997 15:03:52 -0600
From: Keys <keys@babylon5fan.com>
Subject: Re: filter out uids below 100
Message-Id: <33933538.3DC@babylon5fan.com>

oh, and you can see the script in action at
http://snafu.ch.uofport.edu/bwarden/users
It's currently under development, but if you want a copy, please feel
free to email me...


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

Date: 2 Jun 1997 18:32:11 GMT
From: jzhuang@ringer.cs.utsa.edu (Jun Zhuang)
Subject: Help for "date"
Message-Id: <5mv3jb$fd@ringer.cs.utsa.edu>

Under UNIX prompt, enter "date" will get : Mon Jun 2 13:45:34 CDT 1997
Is there a similar function in PERL? What if I only want digits of the
date? i.e. I want 970602 instead of Jun 2 1997?
Any help will be appreciated.




Jun Zhuang                         | jzhuang@ringer.utsa.edu
Department of Computer Science     | http://ringer.utsa.edu/~jzhuang
University of Texas                |  
San Antonio, Texas                 |




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

Date: 3 Jun 1997 07:33:12 GMT
From: s.oosthoek@student.utwente.nl (Simon Oosthoek)
Subject: Re: inconsistent opendir behaviour in Perl for win32
Message-Id: <5n0hbo$po6@pandora.cs.utwente.nl>

In a previous article Nathan V. Patwardhan <nvp@shore.net> says...
>
>Simon Oosthoek (s.oosthoek@student.utwente.nl) wrote:
>
>: When the parameter ends in a "\", the opendir function fails the 
first 
>: time:
>
>Hint: don't use \ in your directory names.  Do it this way, and your
>life will be easier:
>
>$dir = 'd:/';
>
>opendir(DIR, $dir) || die("opendir error: $!");
>etc etc

Thanks for the tip, I didn't know perl for windows also accepted the 
normal way of doing directories ;-)

But the problem persists, with the added error information of $!, the 
error is: "No such file or directory". I definately do have a d:\ (or 
d:/), but both give the same error...

Any more clues? or is this a bug???

Thanks,

Simon



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

Date: 3 Jun 1997 09:28:04 GMT
From: "John Bokma" <jbokma@caiw.nl>
Subject: Re: Isdigit(), isalpha()  in Perl
Message-Id: <01bc7000$2c74e320$de0ab2c2@tschai>



ddean@aracnet.net wrote in article <3392F06A.32B8@aracnet.net>...
> Is there a function similar to the C functions isdigit or alpha in
Perl
> 
> Thanks
> Dean
> 

Yes, read a chapter about using the matching operator!

e.g. /\d/ matches a digit
      /[a-z][A-Z]/ matches alpha

etc.

Regards,

John


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

Need a Freelance Software Developer (MSc)? (CGI, Perl, Java, C, C++)

http://www.caiw.nl/~jbokma [Java demo's, Curriculum Vitae and
more...]

email: jbokma@caiw.nl  phone: +31 10 4291827



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

Date: Tue, 03 Jun 1997 09:14:11 +0200
From: Mariana Wuerz <mariana.wuerz@fernuni-hagen.de>
Subject: leading zeroes
Message-Id: <3393C443.67AB@fernuni-hagen.de>

$four=04

How can I get $four=4?


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

Date: 3 Jun 1997 08:49:20 GMT
From: amore@teleport.com (Linux_User)
Subject: most *robust* DBD::DBI/database combination ( <1M records ) ??
Message-Id: <slrn5p7mp3.jj.amore@teleport.com>
Keywords: perl,database,DBD,DBI,cgi,www


After having scanned some www urls, I wonder which combination 
of DBI and database is the most stable and robust? Which has 
been the most time tested (esp. for www work) ?? 

Some of these modules/combinations seem as unstable as many MS
products. Alphas, betas, etc. Help a newbie perl chap out :-)

Any suggestions, or reference articles?

TIA -


Brett





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

Date: 3 Jun 1997 06:04:17 GMT
From: Valeriy E. Ushakov <uwe@ptc.spbu.ru>
Subject: pack template that packs like 'a' but unpacks like 'A'
Message-Id: <5n0c51$g1h@svx1.ptc.spbu.ru>

May be it would be useful to introduce a new pack template that packs
like 'a' (null padded) but unpacks like 'A' (stripping trailing nulls
and spaces).  This will allow for idiomatic code like this, to take
wtmp manipulation as an example (hypothetic template is denoted 'z'):

$struct_utmp = "z8 z8 z16 L";	# BSD style struct utmp
$sizeof_umtp = sizeof $struct_utmp; # where sizeof($) is a simple sub to
                                    # compute struct size from template
read WTMP, $wtmp, $sizeof_utmp;

@wtmp = unpack $struct_utmp, $wtmp; # strips null from line, user and host

# ...

$wtmp = pack $struct_utmp, ($line, $user, $host, $time); # pad with nulls

print WTMP $wtmp;

For now one have to unpack with 'A' and pack with 'a' to get correct
behavior, and that is slightly inconvenient for one have to maintain
two different templates for packing and unpacking.  (Or am I missing
something very basic here?)

PS: Since I'm posting anyway -- one more pack question to perl gurus:
    How to use 'p' and 'P' templates?  Docs are rather terse on the
    point and I'm not as good at perl internals to RTFS.

PPS: Please, CC your followups as my newsfeed is unstable.

SY, Uwe
-- 
uwe@ptc.spbu.ru                         |       Zu Grunde kommen
http://www.ptc.spbu.ru/~uwe/            |       Ist zu Grunde gehen


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

Date: 2 Jun 1997 21:19:01 GMT
From: mmelick@gpu2.srv.ualberta.ca (M Melick)
Subject: pipes , tail, and buffering?
Message-Id: <5mvdc5$mfg$1@pulp.ucs.ualberta.ca>

I asked a similar question, and was told what I want to do
isn't possible.  But now, rather than seeming impossible it
just seems weird.

Note : I am using Linux as the OS, GNU version of tail, and
       perl version 5.003

Everything is based on the following peice of code.
(Simplified from what I am really trying to do, to illustrate
my problem)

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

       $| = 1;
       
       open(PIPE, "tail -f -n 0 A |");
       select(PIPE); $| = 1;
       select(STDOUT);
       
       while(1) {
          $input = <PIPE>;
          print "$input";
       }
--//--

The code as is works.

Changing the open line to include another file named B
is where problems occur. ( Altering the open line to be ) 
       open(PIPE, "tail -f -n 0 A B |");

Executing "tail -f -n 0 A B", from the shell, will print data to STDOUT as 
soon as data is appended into file A or B.

Executing the same command from within the above code is where 
a problem occurs.

The perl program does not print the data as soon as it is 
appended to the file, (The data seems to be buffered somewhere.)
even though the same tail command run from the shell does.  

So, I have a few questions...
1) Why does it make a difference if there is one file or two in the
tail command?
2) Since it doesn't seem to be the tail command buffering the data, 
is there any way to get rid of this buffering? (or what I have labelled
as buffering..)
3) What exactly is going on here?

Any help is appreciated.
Thanks in advance, 
Mike


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

Date: Tue, 03 Jun 1997 04:39:23 -0600
From: atstarr@negia.net (Andrew Starr)
Subject: printing a hash in order?
Message-Id: <atstarr-0306970439240001@max01-03.qni.com>

Am I correct that it is basically impossible, just using a hash, to print
it in order?

I.e. I had a hash consisting of the split pairs, and wished to print
variable name and value for each pair, in order of their appearance in the
input, but at a time in the script later than when the pairs were being
split.

If I used the "foreach" command (I don't have it in front of me, but I
think I did something like 
   foreach $var (keys %hashname) {do stuff with $var and $hashname{$var}}

and, just as the Camel book says, the order is seemingly random.
Yet if I use "sort keys %hashname", I get the sorted order, but this is
NOT what I want; I want the order they are entered, not an alpha sort.

Thus what I did was to create an array of the variable names, by adding 2
lines to the split pair process (1 to add the element to the array, one to
increase the counter variable by one).  Then I just iterate through this
array (using a for loop for the amount of the counter variable) and refer
to $array[forloopcounter] and $hashtable{$array[forloopcounter]}


Forgive me if I've got semicolons and "\n"'s missing*, or other mistakes
in syntax, but am I going about this in a generally reasonable manner to
be able to achieve my goal? (I do see an alternative of just having two
arrays, rather than having an array and a hash table...)

*when does one need to and not need to use \n's when printing? Is it
mandatory for every print? What happens without it?

Please post here and also send a copy to me if your newsreader makes it
easy to do so. (But I will be looking for responses in group as well).

Don't send responses after August 1, 1997. (I really appreciate responses,
but then I find either slow news servers or Dejanews, etc. make it so that
responses can trickle in for months. I'll just post again if I still have
questions...)

Thanks,

Andrew
(have got my project basically working, will post details when I've got it
ready for public viewing -- nothing earth shattering, but it serves the
needs for which I created it.)

-- 
Andrew Starr  atstarr@negia.net
http://www.amherst.edu/~atstarr/eudora has my unoff. Eudora Site
http://www.amherst.edu/~atstarr/eudora/faq.html by Hank Zimmerman
I have no connection to Qualcomm other than being a happy customer!


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

Date: Mon, 02 Jun 1997 23:16:27 -0600
From: april@xnet.com (David S. April)
Subject: Re: problem searching fielded data
Message-Id: <april-0206972316270001@april.xnet.com>

In article <5mo9q8$dbp$1@dartvax.dartmouth.edu>,
Ronald.J.Kimball@dartmouth.edu (Chipmunk) wrote:

:In article <april-2905970206390001@april.xnet.com>
:april@igcom.net (David S. April) writes:
:
:>   $,="\n";
:>   $srchKeys{'last'}="smi";  # only search field defined this time
:> 
:>   @lines=&file2Array($db); # $db is a pipe delimited text database
:>   
:>   foreach $line (@lines) {
:> 
:>    ($first,$mid,$last,$org,$tit,$wkPh,$cellPh,$hmPh,$null,$addr,$city,$stat
:> e,$zip)=
:>      
:>
split('\|',$line);                                                                                                

:> # split into fields
:> 
:>    next unless defined $srchKeys{'last'} and $last =~
:> /$srchKeys{'last'}/io;              # test1
:> 
:>    print $line if /smi/;   # this line will print for the 2 records in the
:> database that have "smith" as the last name for example.
:> 
:>    next unless defined $srchKeys{'first'} and $first =~
:> /$srchKeys{'first'}/io;          # test2
:>    next unless defined $srchKeys{'org'} and $org =~
:> /$srchKeys{'org'}/io;                # test3
:> 
:>    print $line; # this line matches all the search criteria - but I never
:> get here.
:> 
:>    push(@matches,$line);
:>   }
:>   
:>   print @matches;
:
:You've never defined $srchKeys{'first'} or $srchKeys{'org'}.  Did you
:just omit that from the sample code?

No - that is part of the design. If a search field is *not* defined, I
want to skip over that test and try the next field. The search should only
match the fields specified in the query.

:You should check the following things in your script:
:1. Make sure you define all the search keys.

nope. see above.

:2. Make sure you're splitting your input into the right fields ($last
:is really the last name).
:3. Make sure that the lines you expect to match all the search keys
:actually are matched by the regexps.
:
:Chipmunk

The problem I was having (and still don't understand) is that if the test
for a defined search key failed (ie, it was undefined) the next should
fail and the regexp never even needs to get evaluated. It wasn't working
that way.

FWIW, I did come up with a solution. See below. It is a little more
readable now that I made a sub functionto do the test. I just doesn't seem
as compact to me as the other way.

#!/usr/bin/perl5

$srchKeys{'last'}="smi";                   # note that neither middle nor
first are defined as search keys - that's OK. 
                                                         # I only want to
match on last name

@lines=&file2Array("data.txt");       # this function just sucks in a text
database...

foreach $line (@lines) {
 local($first,$middle,$last,$favorite_color)=split(/\|/,$line);
 next if &matchFails($srchKeys{'first'},$first);
 #did not fail field 1 test (note - doesn't say "passed")
 next if &matchFails($srchKeys{'middle'},$middle);
 #did not fail field 2 test
 next if &matchFails($srchKeys{'last'},$last);
 #did not fail field 3 test
 next if &matchFails($srchKeys{'favorite_color'},$favorite_color);
 #did not fail field 4 test

 print "$line\n"; # this line matches all the search criteria

 push(@matches,$line);
}

sub matchFails {
  local($var1,$var2)=@_;
  return 0 if !(defined $var1);        # if $var1 is undefined, try next test.
  return 1 if ($var1 eq "");            # probably don't even need this test...
  return 0 if $var2 =~ /$var1/i;   # match succeeds
  return 1;                                     # match fails
}


Dave

-- 
David S. April               Syclo LLC
april@igcom.net            101 Lions Dr - Suite 118
(847) 842-0320            Barrington, IL 60010

"Paradise is exactly like where you are right now, only much, much *better*."
    - Laurie Anderson


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

Date: Tue, 03 Jun 1997 11:01:13 +0200
From: thordur arnason <thordur@eunet.no>
Subject: reading and writing from/to the same file
Message-Id: <3393DD59.8622944F@eunet.no>

When I open a file with

open(filehandle,"+>foo.dat")

and then traverse the file with

while (<filehandle>)
{
    if ($_ =~ /foo/)
    {
        $_ = join ("","foo",$_);
        print { filehandle } $_;
    }
    else
        { print { filehandle } $_; }
}

the lines in the file I'm traversing matching the pattern I'm looking
for
don't change.

rgrds

Thordur Arnason
"When things are at their worst they tend to get worse" O-



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

Date: 3 Jun 1997 04:33:49 GMT
From: shaug@callamer.com (O'Shaughnessy Evans)
Subject: Re: Reading Comma delimited, Quoted String records
Message-Id: <5n06rd$kl2$1@zinger.callamer.com>

[ Follow-up only sent to c.l.p.m, and cc'd to original poster. ]

In article <01bc6fc2$4805a7c0$fc412b9f@seanhome>,
    "Sean M. McKee" <mckee@misslink.net> writes:
> Does anyone know of a way to read and parse comma delimited string quoted
> records with awk or perl?

In "Mastering Regular Expressions", Jeffrey Friedl suggests this [1]:

    @fields = ();
    push(@fields, $+) while $text =~ m{
        "([^\"\\]*(?:\\.[^\"\\]*)*)",? # standard quoted string, 
                                       # with possible comma
      | ([^,]+),?                      # anything else, with possible comma
      | ,                              # lone comma
    }gx;

    # add a final empty field if there's a trailing comma
    push(@fields, undef) if substr($text, -1, 1) eq ',';

He also mentions that this can be done by using Text::ParseWords, and then 
doing something like this: "@fields = quotewords(',', 0, $text);", but
then qualifies it by saying that quotewords() has some bugs.  Anyhow,
I'm sure this is in the Perl FAQ, or floating about DejaNews somewhere.

[1] Copyright (c) 1997 O'Reilly & Associates, Inc.
    That's practically a character-by-character (except for formatting to 
    fit nicely into an 80-char terminal) quote of the solution provided on
    p. 290 of said book.  Buy the book -- it rules.

-- 
- O'Shaughnessy Evans
- UNIX/Internet Systems Administrator, GST Call America; SLO, Ca
- "I'm about to write you a reality check..." -- The Tick


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

Date: 3 Jun 1997 04:39:16 GMT
From: sandy@herring.org (Sandy Herring)
Subject: Recursive include in parsed file
Message-Id: <5n075k$sap$1@nntp.structured.net>

I'm occasionally getting the following type of error generated by perl
scripts called via SSIs (<!--#include virtual="cgi-bin/counter.cgi"-->)...

[Mon Jun  2 19:28:05 1997] Recursive include of cgi-bin/counter.cgi in
parsed file /home/bigfish/public_html/speech.html

[Mon Jun  2 19:28:05 1997] Recursive include of cgi-bin/ssilog.cgi in
parsed file /home/bigfish/public_html/speech.html

 ...sometimes as many as eight with the same time stamp. As you can see,
it's happening to more than one script - but not consistently, more
like infrequently. The web server is running Apache/1.2b7 and my cgi is
executing under CGIWrap with SUexec. The Perl version is 5.003 with
EMBED and the suidperl security patch applied. Can anyone shed any
light on what I can look for to find/fix the cause of the errors?
[scripts supplied on request]

TIA,
Sandy
-- 
Sandy Herring               Tigard, Oregon           Peck of Pickled Pisces
sandy@herring.org       bigfish@sns-access.com       http://www.herring.org/


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

Date: Mon, 02 Jun 1997 14:57:59 -0600
From: Keys <keys@babylon5fan.com>
Subject: Re: Server side includes to run Perl scripts from web pages
Message-Id: <339333D7.2966@babylon5fan.com>

> : I am trying to execute a Perl script to generate a counter on my web page
> : using the following comment tag in the webpage itself.
> 
> : <!--#exec cgi="http://cep.lse.ac.uk/fm-cgi-bin/counter.pl"-->

SSI won't take a complete URL, only a virtual path, e.g.
	<!--#exec cgi="/fm-cgi-bin/counter.pl"-->
and so it only works for scripts on the same server as the page... 
Also, if you continue to get the [an error occured while processing this
directive] then your server doesn't support the exec cgi command in SSI
and the only other way you could run that script to my knowledge is from
an IMG tag, in which case you can only have graphical output...

> 
> : Where counter.pl is the script I wish to execute and fm-cgi-bin is the
> : virtual location from which I am able to execute such scripts.  (I am able
> : to execute scripts from this location when using forms so I do not think
> : the problem is coming from the setup of the location of the script.)
> 
> : When the webpage comes up on my browser, instead of a counter, I get the
> : message:
> 
> : [an error occurred while processing this directive]


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

Date: Tue, 03 Jun 1997 05:40:29 GMT
From: mark@ntr.net (Mark Mills)
Subject: Re: Slices of lists
Message-Id: <3393ab6e.10813715@news.ntr.net>

On Thu, 29 May 1997 12:34:49 GMT, brian.orpin@gecmX.com (Brian Orpin)
wrote:


>I wish to replace a slice of an array.
>
>@new = @old[$start..$end];
>
>However, how do I replace the slice with a different array e.g. or
>even delete those elements I have identified.
>
>@old = ("one", "two", "three");
>@new = ("twoa", "twob");
>
>to get  an array ("one", "twoa", "twob", "three")

@old = ("one", "two", "three");
@new = ("twoa", "twob");

$start=1;
$stop=2;

#Given $start, $stop as your start and stop indexes...

@newest=@old;
splice @newest, $start, $stop-$start,@new;

print join " ",@old;
print "\n",join " ",@new;
print "\n",join " ",@newest;
print "\n";

gets me...

one two three
twoa twob
one twoa twob three

AND don't give me crap about the prints.  1:40am buddy.  :>


online docs, CPAN is our friend...

splice ARRAY,OFFSET,LENGTH,LIST

Removes the elements designated by OFFSET and LENGTH from an array,
and replaces them with the elements of LIST, if any. Returns the
elements removed from the array. The array grows or shrinks as
necessary. If LENGTH is omitted, removes everything from OFFSET
onward.

ftp://ftp.ou.edu/mirrors/CPAN/doc/manual/html/pod/perlfunc/splice.html

is what I use.  I'd say you'd need something on your side of the ocean
tho...
-- 
[Hopper, Dennis]: There's mines over there, there's mines over 
there, and watch out those goddam monkeys bite, I'll tell ya.
==Apocalypse Now==


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

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

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