[6819] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 444 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 7 08:07:26 1997

Date: Wed, 7 May 97 05:00:36 -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           Wed, 7 May 1997     Volume: 8 Number: 444

Today's topics:
     Re: [++] Re: Question: regexp reduction? (Eric Bohlman)
     Re: CGI help! <proton@iii.org.tw>
     Re: clever coding required (Tad McClellan)
     Re: data type request (Kyzer)
     Gratification at bargain prices!!! <Angel@TripleXtra.com>
     help the newbie??? please? (Dave Murray)
     Re: How to safely and properly update an ASCII text dat Martin Mathis
     Re: How to safely and properly update an ASCII text dat (Lack Mr G M)
     Re: In-line editing help? (Tad McClellan)
     Re: informix and perl (Clay Irving)
     looking for a script like this.. <vacdepot@flash.net>
     Re: Moving a file <a.aitken@unl.ac.uk>
     Re: Need To Access Unix Database <santiago@gambito.com>
     Re: Notice to antispammers - is there a list of spammer (Jeremy Anderson)
     Re: program for perl? <ajohnson@gpu.srv.ualberta.ca>
     Re: program for perl? (Mike Stok)
     Re: REGEXP HELP, PLEASE! <ajohnson@gpu.srv.ualberta.ca>
     Re: REGEXP HELP, PLEASE! (Mike Stok)
     replacing escape characters in a text file. <cedric=tio%design%eng=sin@bangate.compaq.com>
     Re: scalar holds compiled code <a.aitken@unl.ac.uk>
     Re: Script runs fine from shell, but browser doesn't re (Tad McClellan)
     Re: split returns erroneous value on a line beginning w <nyxcu@ny.ubs.com>
     Re: using modules in a different branch of the sub (Honza Pazdziora)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 7 May 1997 09:12:52 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: [++] Re: Question: regexp reduction?
Message-Id: <ebohlmanE9t09G.D3n@netcom.com>

Ying Chen (yingchen@fir.fbc.com) wrote:

: For the original question.. I was wondering more about perl regexp
: (I suppose I am not very familiar with unix tools that uses similar
: regexp..) - but..your posting made me look into the issue of DFA
: (actually - first finding out what it is and then look for/read info)
: As I browse the FAQ again... I came upon what perl regexp is suppose
: to be more like NFA - (therefore the back-refencing features)
: I suppose - to keep this simple - we can stick to DFA - but I suppose
: using perl-backreferencing features the regexp can be reduced furthur?

Actually (though it's counter-intuitive), NFAs recognize the exact same 
set of languages as DFAs.  Any NFA can be algorithmically converted into 
a DFA (though an N-state NFA may turn into a DFA with up to 2**N states).

There was a thread about a month ago regarding exactly what kinds of 
languages can be recognized by Perl regexps.  They seem to straddle 
several levels of Chomsky's hierarchy, since they can recognize all 
regular languages, not all context-free languages, and some 
context-sensitive languages (e.g. they can't recognize balanced 
parentheses (context-free) but can recognize overstrike-bolded text 
(context-sensitive)).

: and - thanks again -

: Ying (new - and learning ^_^ )

Telling me that your having read my post led you to go out and study 
something you were unfamiliar with is one of the highest compliments you 
could pay me.



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

Date: Wed, 07 May 1997 17:00:50 +0800
From: Proton Kao <proton@iii.org.tw>
Subject: Re: CGI help!
Message-Id: <337044C2.4799@iii.org.tw>

Andrew Lin wrote:
> 
> Hi,
> 
> I've been messing around with PERL and CGI's for a while now and have
> been tripping over all sorts of problems.
> 
> I downloaded an experimental Form written in PERL but everytime I try it
> out I get the error:
> 
> HTTP/1.0 501 Not Supported

  Does your Form/CGI using any feature beyond HTTPD or browser?
  This message is generated by HTTPD not by CGI Program?

> 
> I've already set all the permissions correctly as far as I know.
> I would really appreciate it if someone here could either:
> 
> A. offer a suggestion as to what the problem is
> 
>          or
> 
> B. redirect me to a more accurate newsgroup.  I know this is a perl
> newsgroup but I figured someone here must know something since perl is
> such a popular CGI language.
> 
> Please e-mail me if you can.
> Thanks
> 
> Andrew     lin.293@osu.edu


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

Date: Wed, 7 May 1997 00:02:32 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: clever coding required
Message-Id: <8d2pk5.h11.ln@localhost>

alex (alex99@ozemail.com.au) wrote:

: I've spend hours upon hours trying to cleverly deal with data of the form
: a field   |  some more stuff   | another field  | field4  | hello mum
: (dumped from a rdbms)


You're gonna kick yourself when you see how easy it is...


: Field are separated by the pipe char |   Each field may have trailing and
: leading whitespace.     I need to "split" the fields  
: ($aField, $another, $foo)=split(/\|/),  but then I have to trim each field
: $aField =~ remove leading spaces
: $aField =~ remove trailing spaces
: FOR each field ..... blah blah blah   *too many lines*

: If the leading and trailing whitespace can be consumed before the split, 
: the split would be nicer,  each field would be ready to go.
: I know (deep down in my bones) that there is a more eligant solution,  but
: I don't find it  ... grrrrh!!!


Here it is ;-)

@parts = split /\s*\|\s*/; # separators get deleted by split(), so
                           # make the spaces part of the separator


: I naively thought I coulde do a  s/xxx/yyy/g type sub *followed* by the
: split, hence get the job done on 2 lines.   But the "s///" is to hard to
: work out

: Could anyone thing of a better way.   Thanks in advance

You're welcome.

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


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

Date: 7 May 1997 07:59:01 GMT
From: junkmail@sysa.abdn.ac.uk (Kyzer)
Subject: Re: data type request
Message-Id: <5kpco5$nm9@info.abdn.ac.uk>

>From the lips of brian d foy sprang:
: i suppose that printf() or sprintf() would do what you want, but
: i'd have to check the perlfunc manpage to be sure.

Subtle reference to RTFM: -check-

: btw, where are all of those quarter cents going?  into the
: programmers bank account? ;)

Programming quip: -check-

By all means, it's starting to look like a reply in c.l.p.m
Good grief, what is the world coming to? :)

--
Stuart 'Kyzer' Caie - Kyzer/CSG |undergraduate of Aberdeen University |100%
http://www.abdn.ac.uk/~u13sac   |My opinions aren't those of Aberdeen |Amiga -
kyzer@4u.net kyzer@hotmail.com  |University or AUCC, thankfully.***** |always!

-- 
Random sig of the day:
This sig is under arrest! It has the right to remain silent!


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

Date: 6 May 1997 16:44:10 GMT
From: Angel<Angel@TripleXtra.com>
Subject: Gratification at bargain prices!!!
Message-Id: <5knn4q$33m@sequoia.idir.net>

Want the hottest sex on the web but don't want to spend a fortune for it? Cum on over and check out our thousands of 
hot women, nude celebrities, bondage, asians, interracial couples, orgies, STAR TREK STARS NUDE, Big Beautiful Women, spanking, masturbation, shemales,
movies (avi's, quicktimes, mpegs and vivo!) and more with the lowest access fee going! 
Head on over to http://www.triplextra.com and get some right now!


----------------------------------------------------------------------
This message is being brought to you by Dynamic Mail software - the powerful 
online marketing tool to explode your business easier and faster. For more 
information please visit our web site at : http://www.australia.net.au/~apexpi/dynamail.htm
----------------------------------------------------------------------



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

Date: Wed, 07 May 1997 08:06:03 GMT
From: makepono@hawaiian.net (Dave Murray)
Subject: help the newbie??? please?
Message-Id: <337037c4.3906115@news.hawaiian.net>

Aloha all,
I've decided to take the plunge into Perl, as I have heard it is the
mother of all scripting languages.  I have downloaded and installed
the win32 perl install in my windows 95 machine.  I extracted the
files into the directory D:\Program Files\perl5

Well, I can't get a simple script to work from the command prompt.
It's the "hello world" one line script that is suggested for new users
to try in the "ReadMe" file.

>From the C:\> I key in:
perl d:\cgi\hello.pl
-Also tried 
c:\>perl5 d:\cgi\hello.pl
and
d:\>perl d:\cgi\hello.pl

The hello.pl file is in my d:\cgi folder, and as the readme says, I
copied that file into the d:\Program Files\perl5\bin directory.

Now,
1.   should I uninstall and install directly to D:\perl5  ????
2.  Is there something to do w/ long file names???
3.  Can this interpreter run from the D:\ drive????

If I can get this "hello world" file to run, I'm all set to invest
$40.00 in the "Camel Book".
Please help me.
Respond by email if you would please
Mahalo for your time,

David Murray
makepono@hawaiian.net
www.hawaiian.net/~makepono/
Aloha....<*{{{><


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

Date: 6 May 1997 22:01:00 -0700
From: Martin Mathis
Subject: Re: How to safely and properly update an ASCII text database?
Message-Id: <336ff791.69186935@news.primenet.com>

On Tue, 06 May 1997 11:50:26 +0100, Alastair Aitken
<a.aitken@unl.ac.uk> wrote:

Hi Alastair,

thanks for the response. I'd open the database for read but actually
want to prevent append writes while doing so. Does an exlusive flock
work on both read and write at the same time?

The database contains entries about people wanting to host/join a
networkable game. The IP addresses are stored and are searchable, so
there is db access from a "host a game" entry form and a "find a game"
search form. After 30 minutes a game entry shall become inactive (no
longer found on searches).
Host_a_game appends to the database. When someone does a search, I
want to first run the "older than 30 mins" maintenance. Having a
physical "inactive" flag would make my search easier, otherwise I have
to read the timestamp each time and calculate the 30-min offset.
Alternatively, I could just delete the record from the db rather than
flag it. 

I'm worried about someone appending a record while I write the db out
to temp but also two searching users initiating the maintenance in the
same time window.

I'd have to read through every record and determine if the record
needs to be deactivated then rewrite the entire database (I figure I
could either write to a temp file record by record or store in an
array and overwrite the data file?). Maybe an array would be the
solution? Open read/write and flock, maintain db in memory, seek to
beginning of file and rewrite every record (though if my record count
is now smaller, old records at the end would remain) ? That'd all be
within one open/close. If I'd delete old records, the number of
records at any given time should be quite small.

But I guess it's be more conventional to have a time-limited manual
lock file. Or you might be right about not storing the determinable
flag. I'd never maintain the db, I could always grep the matching
records out of the db and check only those for active status. And for
now every once in a while delete the old junk manually when traffic is
low.

Thanks, you have helped me rethink the problem with fresh and new
aspects :) 

>I have been through this and considered a variety of things including
>locking on read with a timeout if the (expected) write was not returned
>within five minutes.  Unfortunately in a web environment there is always
>a danger that the script will cancel for one reason or another before
>the lock is removed.  Is the flock you seek a read or a write flock?  If
>only write then the method as for single user is relatively safe as
>there will only be a very brief moment (when the database is renamed
>back to the original) when conflicts could occur.  Flocking just before
>this and unflocking immediately after would cut the window of
>opportunity for a premature script exit.  If the flock is a read flock
>then the window will be much longer and then applying a time out might
>also be in order in case the script crashes before unflocking.
>
>In my case, I considered how many people might use the update facility
>(on ndbm database) - only about 4 and then about twenty to forty updates
>per day and decided to take the risk that their might be a concurrent
>write that would crash the database.  I also installed an on disk backup
>routine that saved the files each day of the week so that, if a crash
>occured I could retrieve a recent version of the file in a matter of
>moments.
>
>No crashes yet over a year later.
>
>Anyway - if the flag is determinable then it shouldn't be stored.  It
>isn't "normal".
>
>Alastair.

-Martin
______________________________________________________________
mmathis@primenet.com


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

Date: Tue, 06 May 1997 13:27:55 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: How to safely and properly update an ASCII text database?
Message-Id: <1997May6.132755@ukwit01>

In article <336F0CF2.7FFD@unl.ac.uk>, Alastair Aitken <a.aitken@unl.ac.uk> writes:
|> Martin, Mathis wrote:
|>...
|> > 
|> > I have an ASCII text database with e.g. addresses for an example, one
|> > record per line. Each record contains an "active" flag ("Y" or "N").
|> > Based on some criteria I want to change some flags from Y to N.
|>...
|>                       Is the flock you seek a read or a write flock?  If
|> only write then the method as for single user is relatively safe as
|> there will only be a very brief moment (when the database is renamed
|> back to the original) when conflicts could occur.  Flocking just before
|> this and unflocking immediately after would cut the window of
|> opportunity for a premature script exit.  If the flock is a read flock
|> then the window will be much longer and then applying a time out might
|> also be in order in case the script crashes before unflocking.

   Since the request is to edit an ASCII text file you will need to lock
it for ALL of the editing time.  There is no point user1 reading in a
copy followed by user2 doing the same.  user1 would then write back a
modified version, but so would user2.  Unfortunately user2's write back
would be a modification of the original, not of user1's edited version.

   When updating the read, modify and write must be a single atomic
operation.

---
----------- Gordon Lack ----------------- gml4410@ggr.co.uk  ------------
The contents of this message *may* reflect my personal opinion.  They are
*not* intended to reflect those of my employer, or anyone else.


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

Date: Wed, 7 May 1997 00:36:40 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: In-line editing help?
Message-Id: <8d4pk5.o51.ln@localhost>


[ emailed, posted ]


GuideQueue Master (quemast@bvsd.k12.co.us) wrote:

: 	I'm just barley getting my feet wet w/ perl, 


Well then, you need to get yourself a copy of the Perl FLAX, uh,
I mean the Perl FAQs. See part 5, which has this Frequently
Asked Question in it:

=head2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?


: and I've run into a
: snag.  I need to edit the passwd file and change a specific field.  How
: can I do this without appending a new entry or overwriting the existing
: passwd file?  


You can't. Unless the new passwd is exactly the same length as
the old one.


: Specifically I need to change the passwd field to a new
: password (which is copied from yet another password field -- but I
: already have that part ;-).

: 	I've used PERL's in-line editing from the prompt using reg-exps.
: How do I do this sort of thing from within a perl script?


As a new perl programmer, you probably want to get all the help you
can with debugging your scripts, so you are already familiar with:

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

to have perl help you with debugging.

You can use other command line switches on the shebang line too
(see the perlrun man page):

#!/usr/bin/perl -wi.bak


: Thanks in advance for any help!  Please e-mail me (at least a copy) of
: your reply.  I do not have newsgroups available at my work (yet).

OK.


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


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

Date: 7 May 1997 07:49:20 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: informix and perl
Message-Id: <5kpq80$lh@panix.com>

In <33701BD1.508@calweb.com> "Frank S. (Lpage)" <frank@calweb.com> writes:

>has anyone accessed informix databases using perl?
>i'd love to know how. thanks.

I'd recommend DBD::Informix -- See:

	http://www.hermetica.com/technologia/DBI/

You'll need ESQL/C to build it, though.

In lieu of DBD::Informix, you can always do something like:

@cust_name = `echo 'select cust_name from cust where customer=\"$cust_code\"
 ' | $dbaccess database -`;
$cust_name = $cust_name[4];

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Wed, 07 May 1997 00:21:25 -0700
From: The Sales And Info Staff <vacdepot@flash.net>
Subject: looking for a script like this..
Message-Id: <33702B17.3D21@flash.net>

Looking for a script that would allow me to do the following:

interactive form using aprox  10 questions, with 3 radio boxes per
question( only 1 check/answer  per question)

once passed to the script, could be checked aginst a "data" file to find
highest relevancy. This is a way of making a sugestion on which
"product" would be right for the form user, based on their response to
the form. I am working with a list of over 80 products, and would like
the results printed to the client in a " linked list" to my associated
product sales sheets.

I am not asking for a script, but if you know of a starting point, or
parts I could borrow, or just your thought, I would appreciate it
deeply!

marym@flash.net


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

Date: Wed, 07 May 1997 10:24:07 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: Moving a file
Message-Id: <33704A37.7B7D@unl.ac.uk>

Jonas J. Schlein wrote:
> 
> PERL doesn't seem to have a "move" or "copy" operator for files.  The
> "Learning Perl" book does suggest that you may 'move' a file by using
> the rename command, however this does not appear to work across file
> systems.  I guess I'd have to blame this on the way UNIX implements the
> underlying "rename" function.

I think rename is just mv by any other name.  If you check your /usr/bin
directory for ln, cp and mv you may find, as I did, that they are all
the same file.  It's behaviour depends how the file is called (by what
name) at invocation time.
 
> Anyway what is the best work around for this? Calling 'mv' would certainly,
> work, but it's not 100% portable to non-UNIX systems. I'd really rather
> not write my own copy function although this seems like the best way
> off the top of my head followed by an unlink call.

Copying can be easily achieved by opening the original for read and the
new for write and streaming the one into the other:

open (IN, "/path/to/old.file");
open (OUT, "> path/to/new.file");
while ( <IN> ) {
    print OUT $_;
}
close (IN);
close (OUT);

A move is then achieved by deleting the original after the copy.

This was tested with a copy of the cp program, an ELF 32-bit stripped
executable.

unlink "/path/to/old.file";

Alastair.


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

Date: 7 May 1997 08:04:12 GMT
From: "Santiago Alvarez Rojo" <santiago@gambito.com>
Subject: Re: Need To Access Unix Database
Message-Id: <01bc5abd$323e6540$7131a8c0@sg059pcs>

Check out DBI module at
	http://www.hermetica.com/technologia/DBI/

	"DBperl is a database access Application Programming 
	Interface (API) for the Perl Language. The DBperl API 
	Specification defines a set of functions, variables 
	and conventions that provide a consistent database 
	interface independent of the actual database being 
	used." -- Tim Bunce

I hope this helps.
Santiago
+------------------------------------------------------------------+
| Santiago Alvarez Rojo                                            |
|    santiago@gambito.com                                          |
|    http://www.gambito.com/santiago                               |
|                                                                  |
| PGP public-key: http://gambito.com/santiago/pgp.txt              |
|   fingerprint = D2 BB 9F DD 48 84 9F 5B  80 41 50 D2 28 12 1C 59 |
+------------------------------------------------------------------+

Jerry Smith <jerry@ocfelections.com> escribis en artmculo
<01bc54b9$d46987a0$6281f3cf@jerry>...
> I need to access my Unix Database (Oracle) from the Internet. I am using
> Windows NT as my Internet Server. 
> 
> Can I use Oraperl to access the Oracle Database, or does anybody have any
> other Solutions.
> 
> PS The Oracle Database is not using ODBC
> 


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

Date: 7 May 1997 10:39:18 GMT
From: jeremy@blackbox.ylasia.com.tw (Jeremy Anderson)
Subject: Re: Notice to antispammers - is there a list of spammers to pluginto procmail?
Message-Id: <5kpm4m$q1l@netnews.hinet.net>

Dave Regan (regan@ao.com) wrote:
: In article <336f1c67.116909796@news.diac.com>,
: 	sitaram@diac.com (Sitaram Chamarty) writes:
: 
: >My question, for Nathan or Tom or anyone else who knows, is: is there
: >a frequently updated list of spammers that I can periodically plug
: >into my procmail recipe as an include file?  (I do use procmail, but I
: >got tired of constantly adding addresses to it, hence this question).
: >
: >If there was, I'd delete the no-spam junk in my email address.  I
: >don't mind having to download something once a week (using LWP) (and
: >that takes care of making this post on-topic for c.l.p.m :-).
: 
: There is a list that AOL maintains.  It isn't necessarily in a format
: for directly plugging into procmail.  See:
: 	http://www.idot.aol.com/preferredmail/
: 
: With a short Perl program I'm sure you can remove the HTML wrapping
: and get straight to the addresses.  From there it should be easy
: to add the wrapping to make it fit into procmail.  Then you can fire
: the whole mess off with cron and not have to worry about it anymore
: (except for when AOL changes the format of the file. :))
: 
: Once done, you can advertise your hack in all of the appropriate places.
: 
: The version I am looking at was updated on 5 May 1997, so it
: appears that they keep it up to date.  AOL is also the target of
: lots of spammers so they probably get notified promptly when there
: is abuse.

Paul Vixie also keeps a rather nice web site chock full of info (including 
a list of spam domains) at http://spam.abuse.net/

Claus ABmann also has a set of hacks to sendmail 8.8.* which allow you to 
reject mail from known spammers or spam domains at the sendmail level. (i.e.
they never get near your mail box, but rather get auto-bounced back to the 
sender)  His page is at 

http://www.informatik.uni-kiel.de/~ca/  

The anti-spam patches to Sendmail (in the form of macros that can be put into
your cf "source" tree) are at:

http://www.informatik.uni-kiel.de/~ca/email/check.html

Does someone have a good resource for Stupid Procmail Tricks?  I've read
procmailrc(5) and procmailex(5) until I'm blind, and _still_ don't get
the hang of rules which are dependent on previous rules.

And yes, this has NOTHING to do with perl.  I'll stop now.  Sorry.


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

Date: Wed, 07 May 1997 02:34:19 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: program for perl?
Message-Id: <3370307B.79BB8C8@gpu.srv.ualberta.ca>

Craig Berry wrote:
> 
> Michael J Gebis (gebis@purcell.ecn.purdue.edu) wrote:
> : }Ah, yes, there IS a program needed to write in perl.
> : }It's called "perl" :)
> :
> : Technically, that's the program needed to run perl.  You can write in
> : perl using almost anything, from emacs to antelope blood on a cave wall.
> 
> Wow, I thought I was the only one doing that!  Do you find gazelle blood
> works as well, or do you really need antelope?  I'm experimenting with
> ibexes (ibices?), too.
> 

I believe its general enough to use the life-blood of
most any mammal, so long as you keep the faith and
refrain from sacrificing dromedaries for every little
one-liner or JAPH script  ;-)

regards
andrew


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

Date: 7 May 1997 11:15:20 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: program for perl?
Message-Id: <5kpo88$eqc@news-central.tiac.net>

In article <5kp9kq$2tm$1@marina.cinenet.net>,
Craig Berry <cberry@cinenet.net> wrote:

>Wow, I thought I was the only one doing that!  Do you find gazelle blood 
>works as well, or do you really need antelope?  I'm experimenting with 
>ibexes (ibices?), too.

That's fine, unless you want to see what would happen under VMS.  In that
case you had better be careful to use the correct plural - ibexen :-)

Mike


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Wed, 07 May 1997 02:03:35 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: REGEXP HELP, PLEASE!
Message-Id: <33702947.465AE9E4@gpu.srv.ualberta.ca>

Samson Melamed wrote:
> 
> Hello,
>   I'm working on a project, and I've stumbled in my fluency in Regexpese.
> ;-)  I need three subroutines, each to parse the following lines as
> described through a '$var =~ /regexp/'  If anyone can send me the regexps
> to do that, I would be very greateful.
> 
[snip]
you don't give people much to go on...one would
assume that all three lines constitute a single record
but you don't specify this (otherwise you might
want a method to extract 17 distinct fields per record,
and read in one record at a time)

so:

line1:
/(\w+)\s+(\w+), (\w+)\s+LIC ISU (\d+)-(\w+)-(\d+)/i;
line2:
/(\w+)\s+(.*?)\s+LIC EXP (\d+)-(\w+)-(\d+)/i;
line3:
/\s*(\w+\s*\w*)\s+(.*?)\s*(\w+)\s+LST UPD (\d+)-(\w+)-(\d+)/i;

regards
andrew


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

Date: 7 May 1997 10:57:58 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: REGEXP HELP, PLEASE!
Message-Id: <5kpn7m$do7@news-central.tiac.net>

In article <Pine.LNX.3.96.970503202957.1012A-100000@redfox.org>,
Samson Melamed  <samson@otterspace.com> wrote:
>Hello,
>  I'm working on a project, and I've stumbled in my fluency in Regexpese.
>;-)  I need three subroutines, each to parse the following lines as
>described through a '$var =~ /regexp/'  If anyone can send me the regexps
>to do that, I would be very greateful.

It might be worth looking at unpack as well as regexes as this looks like
some kind of fixed format record:

>N3TJU              MELAMED, SAMSON                       LIC ISU 15-FEB-1997
>
>I'd like it so:
>$1 = "N3TJU"
>$2 = "MELAMED"
>$3 = "SAMSON"
>$4 = "15"
>$5 = "FEB"
>$6 = "1997"

I know that this doesn't unpack into $1 etc., but it might be useful, and
as usual in perl there's more than one way to do it...

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

use strict;
use vars qw/@template $line/;

@template = ('A19 A38        x8 A2 x A3 x A4',
             'A19 A38        x8 A2 x A3 x A4',
             'x19 A21 A4 A13 x8 A2 x A3 x A4',
            );

for ($line = 0; <DATA>; $line++) {
  my @fields = unpack $template[$line], $_;

  if ($line == 0) {
    print "item '$fields[0]', ";
    my ($last, $fore) = split /,\s+/, $fields[1], 2;
    print "$fore $last, ", join ('/', @fields[2 .. 4]), "\n";
  }
  elsif ($line == 1) {
    print "$fields[0], $fields[1], ", join ('/', @fields[2 .. 4]), "\n";
  }
  elsif ($line == 2) {
    print "$fields[0], $fields[1] $fields[2], ",
          join ('/', @fields[3 .. 5]), "\n";
  }
}

__END__
N3TJU              MELAMED, SAMSON                       LIC ISU 15-FEB-1997
GENERAL            10422 BURNT EMBER DR                  LIC EXP 19-SEP-2004
                   SILVER SPRING        MD  20903        LST UPD 15-FEB-1997

produces:

item 'N3TJU', SAMSON MELAMED, 15/FEB/1997
GENERAL, 10422 BURNT EMBER DR, 19/SEP/2004
SILVER SPRING, MD 20903, 15/FEB/1997

when it's run.  If you are matching inside a subroutine please remember
about the scoping of $1, $2 etc.:

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

use strict;

&match ("foo bar");
print "1 and 2 are '$1', '$2'\n";

sub match {
  my $string = shift;

  if ($string =~ /(\S+)\s+(\S+)/) {
    print "matched '$1', '$2'\n";
  }
}

__END__

produces:

matched 'foo', 'bar'
Use of uninitialized value at ./try.pl line 6.
Use of uninitialized value at ./try.pl line 6.
1 and 2 are '', ''

on my machine.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Wed, 7 May 1997 09:03:30 GMT
From: "cedric tio" <cedric=tio%design%eng=sin@bangate.compaq.com>
Subject: replacing escape characters in a text file.
Message-Id: <01bc5ac5$87121e60$5378238a@pc1.asia.compaq.com>

Dear Perl users,
	I need to replace escape characters (^[)  in a text file with asterixs. I
tried doing s/\^\[/*/g; but it doesn't work.
	Can someone help me with this?

Thanx.


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

Date: Wed, 07 May 1997 10:41:28 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: scalar holds compiled code
Message-Id: <33704E48.63FA@unl.ac.uk>

Tom Vaughan wrote:
> 
> Alastair Aitken (a.aitken@unl.ac.uk) wrote:
> : Tom Vaughan wrote:
> : >
> : > Abigail (abigail@fnx.com) wrote:
> : > : Look up in the manual or the Camel:
> : > :    system, qx, backticks and exec.
> : >
> : > Unfortunately no. The functions you've mentioned involve file access.
> : > In my case, $STUFF already holds the contents of what could be considered a
> : > file. What I need is a way to execute not a file but a location in memory.
> 
> : eval ("$STUFF");
> : Alastair.
> 
> Nope. Eval only works on perl code.

oops - it wasn't clear to me that this wasn't perl.  Then how about:

$stuff = 'cp file1 file2';
$return = `$stuff`;		# note - this is not perl code, its a simple UNIX
move command.

And no file access.  Worked for me, as Abigail predicted.  I'd recommend
not using uppercase for variable names, filehandles sure, variable names
no.  I also tried ths which worked fine:

$stuff = 'mv cp al';
eval `$stuff`;			# note - this is not perl code, its a simple UNIX move
command.

and this:

$stuff = 'mv cp al';
`$stuff`;			# note - this is not perl code, its a simple UNIX move
command.

Which also worked.  Either you are not making your problem clear enough
or you are not doing enough of your own testing.

Alastair.


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

Date: Wed, 7 May 1997 00:05:50 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Script runs fine from shell, but browser doesn't receive variables ::SIGH::
Message-Id: <ej2pk5.h11.ln@localhost>

Clay Irving (clay@panix.com) wrote:
: ::SIGH::

: Hmm? I believe your module namespace is incorrect in the above example...
: Perhaps you meant:

: CGI::SIGH


I thought it was a JAPH kinda thing:

So I Go Hacking?


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


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

Date: Wed, 30 Apr 1997 10:53:14 -0400
From: Glen Culbertson <nyxcu@ny.ubs.com>
Subject: Re: split returns erroneous value on a line beginning with '#'
Message-Id: <33675CDA.7BCD88A1@ny.ubs.com>

Terrence, I cannot replicate your results. When I try it, I get $#els
equal to 46 (which is what it should be from your data line--you
probably meant to split on /\s+/ instead of /\s/, which gives me 5 for
$#els).

Terrence M. Brannon wrote:
> 
> The following simple script
> 
> #!//usr/bin/perl
> 
> unless ($#ARGV == 0) {
>     print ("usage: $0 filename\n");
>     exit;
> }
> 
> $file = shift(@ARGV);
> 
> open(F,"<$file") || die "couldn't open $file \n";
> 
> while (<F>) {
>     @els = split(/\s/);
>     print $#els+1 . ": $_";
> }
> 
> indicates that the first line of the file opened (listed below) has 1
> column, even though it obviously has 6
> #P              0.000007        0.000037        0.000047        0.000057        0.000067
> 0.000000        4.05880000000001e-06    2.75638999999999e-05    3.32321999999999e-05    3.99671000000001e-05
> 0.100000        4.14739999999998e-06    2.84536999999998e-05    3.26403e-05     3.97491000000001e-05
> 
> --
> o============o Sending  unsolicited commercial e-mail (UCE) to this address
>  Legal Notice  is indication of your consent to pay me $120/hour for 1 hour
> o============o minimum for professional proofreading & technical assessment.
> terrence brannon * brannon@rana.usc.edu * http://rana.usc.edu:8376/~brannon


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

Date: Wed, 7 May 1997 08:26:34 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: using modules in a different branch of the sub
Message-Id: <adelton.862993594@aisa.fi.muni.cz>

neil@marikit.iphil.net (Neil Quiogue) writes:

> Greetings,
> 
> Some have criticized me for not reading the documents in my previous post.
> I have read them even before I placed my post.  It is just that my question
> is a bit vague.  So let me clarify it a bit.

I did not catch your previous postings, so I will answer from
beginning.

> Thus, I wanted to use the "use" construct but I'm having problems with the
> object not found in @INC array.  My problem cannot be directly solved with
> the "use SubDir::Object" construct since one module is using another module
> in another branch of the subdirectory.
> 
> e.g.,
> /home/branch1/object1.pm
> /home/branch2/object2.pm
> 
> where object1.pm is using object2.pm
> 
> My current workaround is to create a symbolic link and use the "use SubDir::
> Object" construct.  Is there any better way to do this?  I would have
> liked to use a variable as the "SubDir" but it isn't possible or is it?

First, its a bad idea to think about objects as SubDirs. If you really
need subobjects (which is not clear now to me), then its no more use
SubDir::Object but use Object::Subobject.

But, let's assume first, you have just plain objects: Cats, Dogs and
Camels.  You create directory (/home/modules eg.) and put the Cats.pm,
Dogs.pm and Camels.pm into that directory. Then, you have to tell perl
via @INC, that it should look for perl modules in directory /home/modules.

Then, whenever you do use Cats, it will search your @INC path and find
file /home/modules/Cats.pm. Great.

Then, let's say you have a lot of modules and you do not want them in
one directory, you want them to be sorted by their meaning. You can do
directories /home/birds and /home/nonbirds (I do not know better word
in English) and put Cats.pm etc to nonbirds and Sparrow.pm Swan.pm
into /home/birds. Then, you set up your @INC path to include both this
directories.

And since you may want to create more complex objects and make objects
Bird::Sparow, NonBirds::Cats, NonBirds::Dogs, etc. Such objects are
stored in subdirectories, for example NonBirds/Cats.pm. Then you would
set up directory /home/modules and into this directory put both plain
objects like Beer (/home/modules/Beer.pm) and complex ones like
Bird::Swan (/home/modules/Bird/Swan.pm). The @INC path will point to
/home/modules.

This way there is no need for links or so. Bird/Swan.pm will define
package Bird::Swan. If you just have plain object Swan, put it into
/home/modules or somewhere where @INC point.

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

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

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