[9827] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3420 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 11 17:07:19 1998

Date: Tue, 11 Aug 98 14:00:28 -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, 11 Aug 1998     Volume: 8 Number: 3420

Today's topics:
        ===> Parsing Cobol in Perl (Naji Mouawad)
    Re: attach file to email <webmaster@fccjmail.fccj.cc.fl.us>
    Re: dates in excess of 2037 (A Problem???) <dagon@halcyon.com>
    Re: dates in excess of 2037 (A Problem???) (Craig Berry)
        DB files, flock, pack, tie question tfinney@xxxxbbn.com
    Re: DB files, flock, pack, tie question tfinney@xxxxbbn.com
    Re: Efficient number crunching <matthies@fsinfo.cs.uni-sb.de>
        Help using CGI_lite <hstack@att.com>
        Help with Perl script rao_radha@my-dejanews.com
    Re: HTML & Javascript Tests <rootbeer@teleport.com>
        html arborescence in iso9660 (Jacques Guellec)
        method=GET without CGI.pm ?? (Mike)
    Re: Need to Lock files (NFS) <webmaster@fccjmail.fccj.cc.fl.us>
    Re: Need to Lock files (NFS) <jdporter@min.net>
        Newbie pattern match question (Ian McGowan)
    Re: Newbie pattern match question <mjforder@earthling.net>
    Re: Newbie Question About 'for' <mgregory@asc.sps.mot.com>
    Re: Newbie Question About 'for' (Matt Knecht)
        Reading/parsing my mail spool file with Perl <qcoldiro@deal.unl.edu>
        regex lookbehind <michael@datahost.com>
        removing elements from an array (Scott Stark)
    Re: removing elements from an array (Matt Knecht)
    Re: removing elements from an array (Mike Stok)
    Re: removing elements from an array <rootbeer@teleport.com>
    Re: removing elements from an array (Mike Stok)
    Re: Retrieving the value of a matched pattern <Philip.Bowman@removethisbit.usa.net>
        rounding script? <meehan1@mail.idt.net>
    Re: rounding script? (Nem W Schlecht)
    Re: rounding script? <jim.michael@gecm.com>
    Re: Self-printing code <mgregory@asc.sps.mot.com>
    Re: Self-printing code <mgregory@asc.sps.mot.com>
        system() function <lorenb@interlog.com>
    Re: Test your Javascript and HTML knowledge <jdporter@min.net>
    Re: What is the purpose of Perl <jdporter@min.net>
        Which database to use with Perl for Win32 <sucheta@nmtec.com>
    Re: Which database to use with Perl for Win32 (Steve Linberg)
        Win32::ODBC <sjohns17@uic.edu>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 11 Aug 1998 20:24:09 GMT
From: naji.mouawad@cmpx.saic.com (Naji Mouawad)
Subject: ===> Parsing Cobol in Perl
Message-Id: <35d0a7f5.16533250@news>

I have need to parse cobol modules (about 100 of them) and build a
rather simple symbol table of identifiers.

Anyone has written a cobol parser out there?

On a related issue, anyone has used Perl to do remedial/mitigation
regarding Y2K on Cobol using Perl?

Successs, pitfalls, ideas?

Thanks,

Naji.


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

Date: Tue, 11 Aug 1998 14:46:24 -0400
From: "Bill Jones, FCCJ Webmaster" <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: attach file to email
Message-Id: <35D09180.5B25772D@fccjmail.fccj.cc.fl.us>

c.clark@student.unsw.edu.au wrote:
> 
> Hi,
> 
> Does anyone have some sample script that allows you to attach a file
> to email?  (I'm wanting to create a sort of virtual flowers type
> thing, but where the image is generated and sent to the person).
> 
> Ta,
> 
> Chris.

Search DejaNews for a posting along these lines a few months back;
the author actually posted Perl-only source code as well...

HTH,
-Sneex-  :] 
____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
http://www.fccj.org/cgi/mail?webmaster | http://webmaster.fccj.org/Webmaster


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

Date: 11 Aug 1998 12:24:43 -0700
From: Mark Rafn <dagon@halcyon.com>
Subject: Re: dates in excess of 2037 (A Problem???)
Message-Id: <6qq5pr$8b7$1@halcyon.com>

cberry@cinenet.net (Craig Berry) arranged electrons in a pattern like this:
>Specifically, the type time_t is a 32-bit signed integer count of seconds
>since January 1 1970.  (Why they made it signed is beyond me; were it
>unsigned, we'd have a Y2126 problem instead.)

Of course, then we'd have to jump through hoops to refer to dates prior to
1970, which are hugely more common (for many people, at least) than dates
after 2038.

>calculations.  I presume that we'll see a move to a 64-bit time_t sometime
>in the next decade, though it's going to be a painful conversion given the
>amount of software out their using 32 bits to hold time_t.

Most programmers use a system-dependent definition of time_t, rather than
defining it for their program.  It takes simply a recompile on a system with
a different time_t to change.  The majority of software will automatically
upgrade to 64-bit time_t when ported to an OS that uses it.  

This is much less difficult than the Y2K problem, which was based on EACH
PROGRAM storing and manipulating dates as 2 decimal digits.

>Yes, in all likelihood many more than have Y2K problems. 

No.  Many fewer than Y2K problems, as the vast majority of Y2038 problems
go away when porting to a new platform.

>Conversely, storing time values in the type
>time_t is the officially 'right', sanctioned way to do things.

Because it automatically scales to whatever range of dates the current
system (specifically the compiler and libraries) supports.  No code
needs to change to "fix" the Y2038 problem (except bounds checks to
prevent current implementations from going past 2037).

>Personally, I'd prefer just going to 64-bit ints for the computation if
>you're rolling your own code.  And in this circumstance, I'd also move the
>epoch back (to e.g. 1800 or the like) to keep all dates I might ever want
>to deal with positive.

Ummm.  Going to 64-bit time_t is a pretty easy change (you just need to
get/write libraries that use it).  Changing the epoch is a mistake - it
removes the ability to simply cast a 32-bit time_t to 64 bits and use it
normally.
--
Mark Rafn    dagon@halcyon.com    <http://www.halcyon.com/dagon/>   !G


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

Date: 11 Aug 1998 19:37:47 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: dates in excess of 2037 (A Problem???)
Message-Id: <6qq6ib$2v6$1@marina.cinenet.net>

Larry Rosler (lr@hpl.hp.com) wrote:
: In article <6qpsqm$ic6$3@marina.cinenet.net> on 11 Aug 1998 16:51:34 GMT, 
: Craig Berry <cberry@cinenet.net> says...
: ...
: > Or, rather, cannot hold the number of seconds between 1970 and 2038.  Yes,
: > this is the well-known 'Y2038 problem,' which unlike the Y2K problem is
: > not caused by poor coding practices, but rather by a fundamental
: > limitation of an underlying data type deep in the guts of Unix (and many
: > OSs and languages influenced by Unix).  Specifically, the type time_t is
: > a 32-bit signed integer count of seconds since January 1 1970.  (Why they
: > made it signed is beyond me; were it unsigned, we'd have a Y2126 problem
: > instead.)
: 
: Y2146.  But who's counting?  :-)

2^31 seconds = about  68 years (2038 - 1970)
2^32 seconds = about 136 years
1970 + 136 = 2106

Looks like it's time for *both* of us to put in for an integer processing
unit upgrade. :)

: The signedness of time_t isn't the problem.  One could (in application 
: coding, for example) simply deal with it as unsigned, allowing one to 
: count only forward from the Unix Epoch.  The problem is that most date 
: computations involve *intervals* (the difference between two times), and 
: the difference is inherently signed.

The point is that localtime() et all treat their 32-bit argument as a
signed value, so that (e.g.) localtime(2**32) is the second preceeding
Jan. 1, 1970.  Were that not so, we'd have 68 years of additional headroom
in time_t.

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


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

Date: 11 Aug 1998 14:58:08 -0500
From: tfinney@xxxxbbn.com
Subject: DB files, flock, pack, tie question
Message-Id: <35d3a2f5.23633563@news2.newscene.com>

Hello-

I am working on a script to write to a DB file, with file locking.
It's behaving a bit funny,
and I'd like to bring another set of eyes in on it.   Specifically, I
don't know why the sync and undef are 
failing.  In addition, the filesize for /www/data/testData remains
16384K, regardless of the number of 
items in the database...I it with 2, 3, and 4 items, and there was no
change.   Is this to be expected?  The file
date changes every time I run the script, so I know it's accessing.

 If anyone has any suggestions, or pointers to more information, I'd
be very interested in hearing them.   Postings 
to this group or email are welcome.   

thanks,
Todd Finney
tfinney@XXXXbbn.com
please remove the XXXX when replying.


The script that does the actual writing is part of a module, and it is
called by another script.  
The calling script is:

- testWrite.cgi
-----------------------------------------
#!/usr/bin/perl -w

use testLib;

print "Content-type: text/html\n\n";
$path = "/www/data/databaseTest";

@array = (
"2","2","3","path","realMan","1959","toyMan","1985","VG","station
wagon","blue","ad  Copy","19.95","45" );
&writeItemData ( *array, $path );
print "First Item Done<BR><BR>\n\n";

@array = (
"1","2","3","path","realMan","1959","toyMan","1985","VG","station
wagon","blue","ad  Copy","19.95","45" );
&writeItemData ( *array, $path );
print "Second Item Done<BR><BR>\n\n";

@array = (
"3","2","3","path","realMan","1959","toyMan","1985","VG","station
wagon","blue","ad  Copy","19.95","45" );
&writeItemData ( *array, $path );
print "Third Item Done<BR><BR>\n\n";

1;


The module is:

- testLib.pm
---------------------------------------
package testLib;

require Exporter;
use DB_File;
use SDBM_File;
use Fcntl;
use POSIX;


@ISA = qw(Exporter);
@EXPORT = qw( writeItemData );
#there's some other stuff normally in the EXPORTER line, cut out for
clarity

sub writeItemData {

    local ( *itemData, $path ) = @_ if @_;

    my( $dbObj, $fd, %dataHash );

    sub LOCK_SH { 1 };
    sub LOCK_EX { 2 };
    sub LOCK_NB { 4 };
    sub LOCK_UN { 8 };

    print "Path To Database is = ", $path, "<BR><BR>\n";

    print "itemNumber is = ", $itemData[0], "<BR><BR>\n";

    $dbObj = tie (%dataHash, 'DB_File', $path, O_CREAT|O_RDWR, 0666)
        or print "dbcreat $path - $! <BR> \n";

    print "Database tied<BR>\n";

    $fd = $dbObj->fd or (print "failure<BR>\n");

    print "$$: db fd is $fd<BR>\n";

    open(DB_FH, "+<&=$fd") or ( print "fdopen $!<BR>\n") or (print
"Database Open<BR>\n\n");

    unless ( flock ( DB_FH, LOCK_SH | LOCK_NB )) {
        print "$$:CONTENTION; can't read during write
update!<BR>\nWaiting for read lock ($!) ....<BR>\n";
        unless ( flock (DB_FH, LOCK_SH )) { die "flock: $!<BR>\n";}
    } print "$$: Read lock granted<BR>\n";

    flock( DB_FH, LOCK_UN ) or (print "flock $!<BR>\n");

    unless ( flock ( DB_FH, LOCK_EX | LOCK_NB )) {
        print "$$: CONTENTION; must have exclusive lock!  Waiting for
write lock <$!> ....<BR>\n";
        unless ( flock (DB_FH, LOCK_EX)) { die "flock: $!" }
    } print "$$: Write lock granted<BR>\n";


unless (
    $dataHash{ '$itemData[0]' } = pack('i5fa35a20a30a10a15a10a1024',

@itemData[1..2],$itemData[5],$itemData[7],

$itemData[13],$itemData[12],$itemData[3],
                                 $itemData[4],$itemData[6],
@itemData[8..11])
        ) {print "pack failed<BR>\n"};

    print "Data Packed<BR>\n";

    sleep 5;

    $dbObj->sync() or (print "sync failed<BR>\n");

    flock( DB_FH, LOCK_UN ) or (print "flock failed $!<BR>\n");

    undef $dbObj or (print "undef failed<BR>\n");

    untie %dataHash or (print "untie failed<BR>\n");

    close(DB_FH);

    print "$$: Database Closed<BR><BR>\n";
 
   return 1;
}

When I run this from a bros wer, I get:

Path To Database is = /www/data/databaseTest

itemNumber is = 2

Database tied
2689: db fd is 3
2689: Read lock granted
2689: Write lock granted
Data Packed
sync failed
undef failed
2689: Database Closed

First Item Done

Path To Database is = /www/data/databaseTest

itemNumber is = 1

Database tied
2689: db fd is 3
2689: Read lock granted
2689: Write lock granted
Data Packed
sync failed
undef failed
2689: Database Closed

Second Item Done

Path To Database is = /www/data/databaseTest

itemNumber is = 3

Database tied
2689: db fd is 3
2689: Read lock granted
2689: Write lock granted
Data Packed
sync failed
undef failed
2689: Database Closed

Third Item Done


When I run it inside my shell, I get:

[tfinney@foo cgi-bin]$ perl testWrite.cgi

Content-type: text/html

Path To Database is = /www/data/databaseTest<BR><BR>
itemNumber is = 2<BR><BR>
Database tied<BR>
2735: db fd is 3<BR>
2735: Read lock granted<BR>
2735: Write lock granted<BR>
Data Packed<BR>
sync failed<BR>
undef failed<BR>
2735: Database Closed<BR><BR>
First Item Done<BR><BR>

Path To Database is = /www/data/databaseTest<BR><BR>
itemNumber is = 1<BR><BR>
Database tied<BR>
2735: db fd is 3<BR>
2735: Read lock granted<BR>
2735: Write lock granted<BR>
Data Packed<BR>
sync failed<BR>
undef failed<BR>
2735: Database Closed<BR><BR>
Second Item Done<BR><BR>

Path To Database is = /www/data/databaseTest<BR><BR>
itemNumber is = 3<BR><BR>
Database tied<BR>
2735: db fd is 3<BR>
2735: Read lock granted<BR>
2735: Write lock granted<BR>
Data Packed<BR>
sync failed<BR>
undef failed<BR>
2735: Database Closed<BR><BR>
Third Item Done<BR><BR>





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

Date: 11 Aug 1998 15:53:12 -0500
From: tfinney@xxxxbbn.com
Subject: Re: DB files, flock, pack, tie question
Message-Id: <35d1af74.26832182@news2.newscene.com>

ah-ha!   it appears that it was working correctly all along, and my
debugging error messages were the problem.   undef and sync both
apparently return undefined values, and using them in the context that

I did  ( sync | print error ) caused it to spit out an error message
even when it was working correctly.

It looks good to me...does anyone have any suggestions?

thanks again,
Todd

tfinney@XXXXbbnplanet.com




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

Date: 11 Aug 1998 19:08:00 GMT
From: Niklas Matthies <matthies@fsinfo.cs.uni-sb.de>
Subject: Re: Efficient number crunching
Message-Id: <6qq4qg$o2m$1@hades.rz.uni-sb.de>

In comp.lang.perl.misc, Greg Bacon <gbacon@cs.uah.edu> writes:
> In article <6qpsoj$m8f$1@hades.rz.uni-sb.de>,
> 	Niklas Matthies <matthies@fsinfo.cs.uni-sb.de> writes:
> : I'm calcualting 32-bit CRC checksums of scalars (rather large ones, like
> : a couple of Kbytes each).
> 
> [snip]
> 
> : This is pretty the fastest I've come up with, but still rather slow
> : compared with a C implementation.
> 
> Then use the C implementation that comes with Perl!  From the perlfunc
> entry on unpack:
> 
>     In addition, you may prefix a field with a %E<lt>numberE<gt> to
>     indicate that you want a <number>-bit checksum of the items
>     instead of the items themselves.  Default is a 16-bit checksum.  For
>     example, the following computes the same number as the System V sum
>     program:
> 
>         while (<>) {
>             $checksum += unpack("%16C*", $_);
>         }
>         $checksum %= 65536;

Yes, I know, but this doesn't compute CRC checksums, at least not on my
machine. 'sum' seems to be based on just adding all character up, which
doesn't give you very good hash values with similar-sized files.

-- Niklas


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

Date: Tue, 11 Aug 1998 16:23:02 -0400
From: <hstack@att.com>
Subject: Help using CGI_lite
Message-Id: <6qq93m$9p9@newsb.netnews.att.com>

I have a form that posts a hidden field that includes a text string like the
following
<INPUT TYPE="hidden" NAME="argument_string" value=-user
foofoo -src_master -dst_design 187 ->

The perl that decodes it looks like
************************************************************
use CGI_Lite;
use Cwd;
$cgi = new CGI_Lite ();
%form_data = $cgi->parse_form_data ();
$argument = $form_data{'argument_string'};
print "<BR>$argument<BR>";
*************************************************************
But this perl only gets "-user" from the form, does anyone know another
method to get the string in its entirety.

hstack@ems.att.com




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

Date: Tue, 11 Aug 1998 19:52:57 GMT
From: rao_radha@my-dejanews.com
Subject: Help with Perl script
Message-Id: <6qq7ep$2gn$1@nnrp1.dejanews.com>

Hi I need to write a perl script capable of reading a data file
 and copy everything starting from a sepcific lable to EOF to a new file
 and purge any duplicate lines

 I have the script to do the purge, and I am not able to successfuly add
 the line that starts the copy from a label

 Data file looks as follows:
                             Network:
                               xx.xx.com
                               yy.yy.com
                             Segments:
                                1.1.1
                                2.2.2
                              NODES:
                                10.10.10.10
                                20.20.20.20
                                30.30.30.30
                                10.10.10.10

 Basically, I want the new file to have
                                10.10.10.10
                                20.20.20.20
                                30.30.30.30


 Here is the script for purge; ANy help appreciated to add the label

         (open STDIN, $ARGV[0]);
         (open STDOUT, ">$ARGV[1]");
           while (<STDIN>) {
           unless ($i{$)}++) {
             push (@uniq, $_);
           }
           }
              print (@uniq)

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 11 Aug 1998 20:56:59 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: HTML & Javascript Tests
Message-Id: <Pine.GSO.4.02.9808111356270.10161-100000@user2.teleport.com>

On Tue, 11 Aug 1998, Andrew M. Langmead wrote:

> In comp.lang.perl.misc you write:
> 
> >So, why are you posting this to a newsgroup about Perl? Perl isn't HTML,
> >and Perl isn't JavaScript. Should movie reviews be posted to a newsgroup
> >about Volkswagens merely because there are drive-in theaters? :-) 
> 
> That analogy might work if there were any drive in theaters left
> around.

Well, you can drive TO a theater, at least! :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 12 Aug 1998 05:19:47 GMT
From: jguellec@imaginet.fr (Jacques Guellec)
Subject: html arborescence in iso9660
Message-Id: <6qq8i1$bib$1@news.imaginet.fr>

Hello,

If you need to change an html arborescence for iso9660 standard, the
scripts i wrote in Perl may help you. It of cource a freeware.
 
You can find it at this adress :
Web des lilas : http://www.imaginet.fr/~jguellec

Direct adress : 
http://www.imaginet.fr/~jguellec/program/perl/iso9660.htm

If you find too bad english in the english version, please send me
correction.

Thank you,





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

Date: 11 Aug 1998 19:16:02 GMT
From: schutzmd@SPAMFREEjmu.edu (Mike)
Subject: method=GET without CGI.pm ??
Message-Id: <6qq59i$bps$2@lark.jmu.edu>

On a web site I am working on, we are trying to submit data through links
such as:
   <A HREF="/cgi-bin/search?id=3411"> Search Link </A>

The problem is that on the server, CGI.pm is not enabled, and the only
other way I know to get data from forms is from ENV{'CONTENT_LENGTH'}.
Submitting the data directly in the URL like this won't put it in the
environment variable, though, so how else can I extract this information
in my perl script?

(Please don't tell me I am SOL.  ;)

- mike -


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

Date: Tue, 11 Aug 1998 14:44:31 -0400
From: "Bill Jones, FCCJ Webmaster" <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: Need to Lock files (NFS)
Message-Id: <35D0910F.584E61EC@fccjmail.fccj.cc.fl.us>

Michael A. Jones wrote:
> 
> Have been trying to find a good way to lock a file that an other user
> might try to open while I'm processing it. The user is NFS mounted to
> server and I would like to "Lock" the file. I'm looking for any
> resources that might address such an attempt. I've tried the obvious
> (flock) and have been experimenting with fcntl. Any advice would be
> appreciated.
> Details: file in question is a "pkziped" file created by a user. My
> program watches for the creation of such files, waits until it's closed
> and then does stuff to it. I would like to prevent anyone from opening
> it during my (short) processing just in case. I think that means locking
> it.

You can't, NSF won't allow a reliabl;e lock; but you can copy
it out to a lockable area on your HD, then, when you are done,
copy it back.

Really only way to be sure.

HTH,
-Sneex-  :] 
____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
http://www.fccj.org/cgi/mail?webmaster | http://webmaster.fccj.org/Webmaster


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

Date: Tue, 11 Aug 1998 16:24:07 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Need to Lock files (NFS)
Message-Id: <35D0A867.475E@min.net>

Andre Merzky wrote:
> 
> You can make it atomic.

Um, mind if I trouble you for a precise explanation of how
you can make an arbitrary sequence of operations to behave
an as atomic operation?

>  - filename = test.dbm
>  - look if any file exists with name: 'test.dbm.lock.(\d+)'
>  - if yes, wait, try again etc.
>  - if not: creat one: 'test.dbm.lock.<ipnum(localhost).pid>
>   not atomic til now...
>  - check if only YOUR file exists! :-)
>  - if not: remove your's, wait random time, start from very beginning
>  - if yes: work

Reminds me of the cartoon  "...And then a Miracle occurs..."

-- 
John Porter


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

Date: Tue, 11 Aug 1998 19:57:06 GMT
From: ian@netcom.com (Ian McGowan)
Subject: Newbie pattern match question
Message-Id: <ianExJJF6.H8t@netcom.com>

Gentle-people,

I'm having a problem understanding a simple RE in the following
script.  I can workaround, but I'd really like to know what
I'm missing.  If anyone has a few minutes to aid my perl
skills, my gratitude shall overfloweth.

What I'm trying to do is grab the facility being logged
from syslog and summarize.  1st attempt:

while ($line=<SYSLOG>) {
   # Split the line into chunks based on spaces
   ($a,$b,$c,$d,$_)=split " ",$line;
   # Grab the facility
   /(.*)\[?.*\]?:/;
   $list{$1}.=$line;
   $count{$1}+=1;
}

Aug  9 23:59:00 embarcadero syslogd: restart
$1=syslogd
Aug  9 23:59:00 embarcadero sendmail[52795]: AA52795: message-id ...
$1=sendmail[52795]

the (.*) is too greedy - I want to discard the [52795] part.
however, changing the RE to /(.*)?\[?.*\]?:/ makes no diff and
/(.*?)\[?.*\]?:/ gives

Aug  9 23:59:00 embarcadero syslogd: restart
$1=
Aug  9 23:59:00 embarcadero sendmail[52795]: AA52795: message-id= ...
$1=

I have the feeling that whatever I'm missing is something basic...

any clues, pointers to faq's (already consulted perlre, but
obviously don't understand it :-( ) very welcome.

thanks,
ian

---
(The following is ugly, but has the benefit of working...

while ($line=<SYSLOG>) {
   ($a,$b,$c,$d,$_)=split " ",$line;
   # Grab the facility
   if (/\[/) {
      # If there's a [pid] then ignore the part in parens
      /(.*)\[.*\]:/;
   } else {
      # Otherwise, just grab the command
      /(.*):/
   }
   $list{$1}.=$line;
   $count{$1}+=1;
}

-- 
ian@netcom.com               Practice random lane changes and
                             commit senseless bursts of acceleration


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

Date: Tue, 11 Aug 1998 22:21:16 +0200
From: "Matthew J. Forder" <mjforder@earthling.net>
To: ian@netcom.com
Subject: Re: Newbie pattern match question
Message-Id: <35D0A7BB.7399B2DE@earthling.net>

First, you might try spliting using the whitespace meta-char rather than
just space...if I remember correctly entries in the syslog file are
seperated by tabs as well as spaces:

($a,$b,$c,$d,$_)=split /\s/,$line;

Now you could try a RE likes this:

/^(\w+)/

since the facility name is only made up of alphabetic chars, but don't
quote me on it, this is off the top of my head...;-)

Regards,

Matthew Forder

Ian McGowan wrote:

> Gentle-people,
>
> I'm having a problem understanding a simple RE in the following
> script.  I can workaround, but I'd really like to know what
> I'm missing.  If anyone has a few minutes to aid my perl
> skills, my gratitude shall overfloweth.
>
> What I'm trying to do is grab the facility being logged
> from syslog and summarize.  1st attempt:
>
> while ($line=<SYSLOG>) {
>    # Split the line into chunks based on spaces
>    ($a,$b,$c,$d,$_)=split " ",$line;
>    # Grab the facility
>    /(.*)\[?.*\]?:/;
>    $list{$1}.=$line;
>    $count{$1}+=1;
> }
>
> Aug  9 23:59:00 embarcadero syslogd: restart
> $1=syslogd
> Aug  9 23:59:00 embarcadero sendmail[52795]: AA52795: message-id ...
> $1=sendmail[52795]
>
> the (.*) is too greedy - I want to discard the [52795] part.
> however, changing the RE to /(.*)?\[?.*\]?:/ makes no diff and
> /(.*?)\[?.*\]?:/ gives
>
> Aug  9 23:59:00 embarcadero syslogd: restart
> $1=
> Aug  9 23:59:00 embarcadero sendmail[52795]: AA52795: message-id= ...
> $1=
>
> I have the feeling that whatever I'm missing is something basic...
>
> any clues, pointers to faq's (already consulted perlre, but
> obviously don't understand it :-( ) very welcome.
>
> thanks,
> ian
>
> ---
> (The following is ugly, but has the benefit of working...
>
> while ($line=<SYSLOG>) {
>    ($a,$b,$c,$d,$_)=split " ",$line;
>    # Grab the facility
>    if (/\[/) {
>       # If there's a [pid] then ignore the part in parens
>       /(.*)\[.*\]:/;
>    } else {
>       # Otherwise, just grab the command
>       /(.*):/
>    }
>    $list{$1}.=$line;
>    $count{$1}+=1;
> }
>
> --
> ian@netcom.com               Practice random lane changes and
>                              commit senseless bursts of acceleration
>



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

Date: 11 Aug 1998 13:50:20 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: Newbie Question About 'for'
Message-Id: <r8u33kb14r.fsf@asc.sps.mot.com>

lr@hpl.hp.com (Larry Rosler) writes:

> In article <martimer-1008980812070001@pool-207-205-143-51.rvdl.grid.net> 
> on 10 Aug 1998 13:09:25 GMT, Martin Gallo <martimer@mindspring.com> 
> says...
> > I just started with Perl over the weekend (I have been programming off and
> > on since 1980), and cannot understand why the simple program:
> > 
> > for ($a=1,$a<7, ++$a) {
> > print $a,"\n"
> > }
> 
> Try using semicolons instead of commas.  What you have specified is a 
> "foreach" loop ("for" and "foreach" are synonyms) consisting of the three 
> items $a = 1, $a < 7, ++$a.  These are evaluated before the looping 
> begins, so the value of $a is 2.  This is then printed three times, once 
> for each element of the list.  No surprise, but not what you wanted, 
> either.


I read this and thought "Bah hah - that's funny, but now I get it!"

Then I did this:

  perl -e 'for ($a=1, $a < 7, $a++){print;}'

Then I was confused again.  

Can you predict what this prints?

If you didn't predict it correctly, can you now explain why it does
what it does?

If you can, I'd love to know!

Thanks,

Martin.



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

Date: Tue, 11 Aug 1998 20:18:51 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: Newbie Question About 'for'
Message-Id: <LG1A1.20$5P.190404@news2.voicenet.com>

Martin Gregory <mgregory@asc.sps.mot.com> wrote:
>  perl -e 'for ($a=1, $a < 7, $a++){print;}'
>
>Then I was confused again.  
>
>Can you predict what this prints?

Yes. :)

>If you didn't predict it correctly, can you now explain why it does
>what it does?
>
>If you can, I'd love to know!

Larry Rosler and I got into a discussion about exactly what's going on
here.  If you don't have an aversion to Deja-News check out:

~g comp.lang.perl.misc ~s Reading in multiple lines

Look for message ID's:
<SgJh1.29$qF2.171393@news3.voicenet.com>
<MPG.ff12d44df888a709896bc@nntp.hpl.hp.com>

Only two articles, but Larry's (Or is that Lary? :) ) explains it quite
nicely.

-- 
Matt Knecht - <hex@voicenet.com>


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

Date: Tue, 11 Aug 1998 15:04:59 -0500
From: quinn coldiron <qcoldiro@deal.unl.edu>
Subject: Reading/parsing my mail spool file with Perl
Message-Id: <35D0A3EB.1BFE3B19@deal.unl.edu>

Does anybody know of a perl script that will read a spool file from
sendmail, and parse out the individual messages.  I wrote my own and can
parse out the header into individual cpmonents, but get all screwed up
with the message.  Any ideas?

quinn

--
------------------------------------------
Quinn P. Coldiron
DEAL Lab
03 AG Comm
472-5249
qcoldiro@unlinfo.unl.edu
******* http://citv.unl.edu/linux/ *******
------------------------------------------





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

Date: Tue, 11 Aug 1998 13:47:42 -0700
From: Michael Stearns <michael@datahost.com>
Subject: regex lookbehind
Message-Id: <35D0ADEE.3D81@datahost.com>

How can I form a regex that will match this:

<A

 NAME="Xacy96092"></A>

But not this:

<H3><A

 NAME="Xacy96092"></A>


In other words, it will only matched if the string is not preceded by
<H3>.

thanks,
Michael Stearns


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

Date: 11 Aug 1998 19:12:44 GMT
From: sstark@informix.com (Scott Stark)
Subject: removing elements from an array
Message-Id: <6qq53c$kff2@webint.na.informix.com>

Hi, I looked in the Data: Arrays section of the FAQ and couldn't find the 
answer to this:

How do I remove an element from an array, if it's not the first element? I want 
to test the element and if has a certain value, to remove it from the array.

for example:

	for(@name) {
		if ($_ eq 'smerf') {
			# remove $_;
			}
		}

thanks, and sorry if this is too simple a question.

Scott Stark
sstark@informix.com



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

Date: Tue, 11 Aug 1998 19:47:29 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: removing elements from an array
Message-Id: <ld1A1.58$xK4.619576@news3.voicenet.com>

Scott Stark <sstark@informix.com> wrote:
>How do I remove an element from an array, if it's not the first element? I want 
>to test the element and if has a certain value, to remove it from the array.
>
>for example:
>
>	for(@name) {
>		if ($_ eq 'smerf') {
>			# remove $_;
>			}
>		}

You need to use splice to delete parts of an array.  The problem with
this, however, is that you have to manually keep track of where you are
in the array.

for (my $x = 0; $x < @name; $x++) {
    splice (@name, $x, 1), last if $name[$x] eq 'smerf';
} # Yuck!

Sometimes it's nessacery to use arrays.  Sometimes you'll be served
*much* better with a hash (As I'm sure many people will tell you).

If you have multiple values that you need to check for, perhaps a grep
will work better:

@name = grep { $_ ne 'smerf' } @name;

It's certainly easier to read, and if you're not calling this line of
code that much, you won't even notice the difference.

-- 
Matt Knecht - <hex@voicenet.com>


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

Date: 11 Aug 1998 19:51:59 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: removing elements from an array
Message-Id: <6qq7cv$ge6@news-central.tiac.net>

In article <6qq53c$kff2@webint.na.informix.com>,
Scott Stark <sstark@informix.com> wrote:
>Hi, I looked in the Data: Arrays section of the FAQ and couldn't find the 
>answer to this:
>
>How do I remove an element from an array, if it's not the first element? I want 
>to test the element and if has a certain value, to remove it from the array.
>
>for example:
>
>	for(@name) {
>		if ($_ eq 'smerf') {
>			# remove $_;
>			}
>		}
>
>thanks, and sorry if this is too simple a question.

A way which is not particularly economical might be

  @name = grep {$_ ne 'smerf'} @name;

Another way to do it might be to explicitly use an index into the array
and use splice to chop elements out e.g.

  for ($i = $#name; $i >= $[; $i--) {
    if ($name[$i] eq 'smerf') {
      splice @name, $i, 1;
    }
  }

If the array contains undefined values then you may want to make the tests
a little more complex to avoid -w complaints about using uninitialised
variables e.g.

  @name = grep {!(defined && $_ eq 'smerf')} @name;

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@colltech.com                  |            Collective Technologies (work)


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

Date: Tue, 11 Aug 1998 20:05:54 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: removing elements from an array
Message-Id: <Pine.GSO.4.02.9808111304010.10161-100000@user2.teleport.com>

On 11 Aug 1998, Scott Stark wrote:

> How do I remove an element from an array, if it's not the first element? 

I use splice.

> 	for(@name) {
> 		if ($_ eq 'smerf') {
> 			# remove $_;

But don't tamper with the array while iterating over it! Use grep instead.

    @name = grep { $_ != 'smerf' } @name;

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 11 Aug 1998 20:14:43 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: removing elements from an array
Message-Id: <6qq8nj$h5h@news-central.tiac.net>

In article <Pine.GSO.4.02.9808111304010.10161-100000@user2.teleport.com>,
Tom Phoenix  <rootbeer@teleport.com> wrote:

>    @name = grep { $_ != 'smerf' } @name;
                       ^^
                       ne maybe?

This would usually be caught by using the -w flag...

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@colltech.com                  |            Collective Technologies (work)


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

Date: Tue, 11 Aug 1998 08:10:39 +0100
From: "Philip Bowman" <Philip.Bowman@removethisbit.usa.net>
Subject: Re: Retrieving the value of a matched pattern
Message-Id: <902862439.23601.0.nnrp-06.c2de775f@news.demon.co.uk>


Jason Patton wrote in message ...
>When matching a pattern, where you know the format of the pattern but not
>the actual values therin, what is the best way to retrieve that value??
>
>Example:  You have a program that reads in text that contains a URL
>somewhere within.  You want to determine the exact URL so that you can
>create a valid HREF tag around the text.  Sure you can match the http://
>at the beginning of the string and the .html at the end, but how do you
>determine the value of the text in between?
>
>This seems to be a recurring problem for me.  I always have to come up
>with some bizzarre hack to find the unknown value.  There has got to be a
>sane way to do this - despite the lack of attention to the problem by the
>perl faq and all of the perl books that I own.

What you should need is a pattern referback (See the Camel book, 2e,
pp65/66). The important part is the part of the pattern surrounded in
brackets, e.g. (s?), and the $1 that refers to it. Here's some code that
demonstrates it: Hope this answers your questions.

open INFILE,"<bookmark.htm";

# Choose one of the following lines
while (chop($line = <DATA>)) {
#while (chop($line = <INFILE>)) {

$line =~ m!\"http(s?)://(.+?)/(.*?)\"!;
print "Secure\t" if $1;
print "Site: $2\t" if $2;
print "Page: $3" if $3;
print "\n";
}
__DATA__
"http://www.perl.com/index.html"
"http://www.netscape.com/"
"https://news.bbc.co.uk/today.htm"



Phil Bowman




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

Date: Tue, 11 Aug 1998 15:38:03 +0000
From: Brian Meehan <meehan1@mail.idt.net>
Subject: rounding script?
Message-Id: <35D0655B.3D0DA250@mail.idt.net>

Could anyone point me to a place to find a script that will round
numbers to a to certain digit place.  This is for a a script that is
parsing financial data.

Thank you for your help

Brian



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

Date: 11 Aug 1998 15:08:06 -0500
From: nem@abattoir.cc.ndsu.nodak.edu (Nem W Schlecht)
Subject: Re: rounding script?
Message-Id: <6qq8b6$6m2@abattoir.cc.ndsu.nodak.edu>

[courtesy copy e-mailed to author(s)]

In comp.lang.perl.misc, Brian Meehan  <meehan1@mail.idt.net> wrote:
>Could anyone point me to a place to find a script that will round
>numbers to a to certain digit place.  This is for a a script that is
>parsing financial data.

Your friendly sprintf() call should be able to do the trick:

#!/local/bin/perl
$num1 = "23.58478";
$num2 = "23.58471";
$rnd_num1 = sprintf("%.4f", $num1);	# rounds up
$rnd_num2 = sprintf("%.4f", $num2);	# rounds down
print "Num1: $rnd_num1\n";
print "Num2: $rnd_num2\n";

__END__

Output:

Num1: 23.5848
Num2: 23.5847

-- 
Nem W Schlecht                  nem@plains.nodak.edu
NDUS UNIX SysAdmin        http://www.nodak.edu/~nem/
"Perl did the magic.  I just waved the wand."


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

Date: Tue, 11 Aug 1998 16:12:21 -0400
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: rounding script?
Message-Id: <35D0A5A5.6C75@gecm.com>

Brian Meehan wrote:
> 
> Could anyone point me to a place to find a script that will round
> numbers to a to certain digit place.  This is for a a script that is
> parsing financial data.

perldoc -f sprintf
perldoc perlfaq4


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

Date: 11 Aug 1998 14:28:16 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: Self-printing code
Message-Id: <r8ogtsazdj.fsf@asc.sps.mot.com>

mjd@plover.com (Mark-Jason Dominus) writes:

>From: mjd@plover.com (Mark-Jason Dominus)
>Subject: Re: Self-printing code
>Summary: Trying to establish a reputation as an insane genius

And doing a pretty good job, over the last week or so! ....

> For your amusement and edification, I present the following file,
> which, when installed in /tmp/p and executed by Perl, emits its own
> source code on the standard *error*:
> 
> 
> -------------------------------- BEGIN FILE
> Illegal division by zero at /tmp/p line 1.
> -------------------------------- END FILE
> 
> % perl /tmp/p
> Illegal division by zero at /tmp/p line 1.
> 
> %




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

Date: 11 Aug 1998 14:29:42 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: Self-printing code
Message-Id: <r8n29cazb5.fsf@asc.sps.mot.com>

comdog@computerdog.com (brian d foy) writes:

> In article <6qnf2p$99i$1@nnrp1.dejanews.com>, Robin Houston <robin.houston@guardian.co.uk> posted:
> 
> >Randal Schwartz <merlyn@stonehenge.com> wrote:
> >
> >> Well, there's the old standby:
> >> seek DATA,0,0;print<DATA>__END__
> >
> >Oh, but that's cheating :-)
> >It reads its own source
> 
> okay, let's see if i can trigger Randal's Cat Detector(tm)
> 
>    #!/usr/bin/perl
> 
>    system '/bin/cat', $0;
> 
>    __END__
> 

Who made the rules here?  How come this isn't cheating as well? - It
reads it source (in through ``, out through STDOUT)..



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

Date: 11 Aug 1998 20:06:43 GMT
From: Loren Bandiera <lorenb@interlog.com>
Subject: system() function
Message-Id: <6qq88j$3cu$1@news.interlog.com>

	I've got a WinNT server setup with IIS v4.0, and ActiveState
	Perl 5.005.  In one of my scripts, I attempt to make a system
	call to the NET USER command:

system ("net user test test /expires:never /add");

	This does get executed, but no output comes back after
	running it, and the user isn't created.

	I changed the command to be just 'net user', which will
	list all the users on the computer.  The output I get
	from that is:

User accounts for \\

-------------------------------------------------------------------------------
Administrator            Guest                    IUSR_FEY                 
IWAM_FEY                 lorenb                   
The command completed with one or more errors.

	If I just type either command at a command prompt they
	both work.  If I put them in a Perl program and run it
	from the command line, it also works.

	The only time this fails is when it's run from the web
	server.  I'm using the NT challenge/response access,
	and it's running as an administrator, so access isn't
	the problem.  

	I had this working just fine on other NT machines, running
	IIS 3.0.  So I'm thinking perhaps there is something in
	IIS 4.0 that is causing me problems.

	Does anyone have any ideas on how to fix this?

----------------------------------------------
Loren Bandiera              lorenb@uunet.ca   
Senior Product Developer    UUNET Canada Inc.
---------------------------------------------- 


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

Date: Tue, 11 Aug 1998 16:27:33 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Test your Javascript and HTML knowledge
Message-Id: <35D0A935.3C9B@min.net>

Mike Russiello wrote:
> 
> We have developed separate HTML and JAVASCRIPT tests that will SOMEDAY
> be used to screen job applicants and help employees get rewarded for
> learning (perl is coming soon).  

Evil so pure and unabashed, it defies description.

-- 
John Porter


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

Date: Tue, 11 Aug 1998 16:49:55 -0400
From: John Porter <jdporter@min.net>
Subject: Re: What is the purpose of Perl
Message-Id: <35D0AE73.473B@min.net>

Craig Berry wrote:
> 
> I just had the weird image of the immediately post-big-bang Perlverse
> consisting of undifferentiated typeglobs, then as the energy density
> falls, there's a symmetry break into scalars and composites, then as it
> falls still further, composites subdivide into hashes and lists.
> 
> Now, where does that leave the weird case of file handles?  Perhaps in an
> analogous position to gravitation, resisting all attempts at unification
> with the other three fundamental forces...er, data types. :)

Maybe it's more like this: primordially, there's just "context".
Then differentiation between list context and scalar context; then
boolean and void context split off of scalar context.

I think data types are more like fundamental particles.
Operators are guage interactions.
(And let's not bring up how there are "scalar" and "vector" particles!)

-- 
John Porter


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

Date: Tue, 11 Aug 1998 12:06:37 -0700
From: Sucheta Khot <sucheta@nmtec.com>
Subject: Which database to use with Perl for Win32
Message-Id: <35D0963D.65AC@nmtec.com>

Could anybody please advice me on which database should I use and how
should I use with Perl for Win32.

Thanks,
Sucheta


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

Date: Tue, 11 Aug 1998 15:11:19 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Which database to use with Perl for Win32
Message-Id: <linberg-1108981511190001@projdirc.literacy.upenn.edu>

In article <35D0963D.65AC@nmtec.com>, sucheta@nmtec.com wrote:

> Could anybody please advice me on which database should I use and how
> should I use with Perl for Win32.
> 
> Thanks,
> Sucheta

MS Access is a favorite of many people for lightweight applications; it is
simple and relatively cheap.  SQL Server is a higher-level solution that
is more powerful and much more expensive.

Use Dave Roth's Win32::ODBC package to interface to your databases.

This is one combination of solutions, anyway.  Go to www.activestate.com
and read up.  Good luck!
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Tue, 11 Aug 1998 14:35:52 -0500
From: Seth David Johnson <sjohns17@uic.edu>
Subject: Win32::ODBC
Message-Id: <Pine.SOL.3.96.980811143010.12966A-100000@icarus.cc.uic.edu>

I recently installed the ODBC module for Win32. I have been using release
316 (I think) of ActiveState's port. Since I was getting "parse exception"
errors when I tried to use the module, I decided to downgrade to release
307 of Win32, on which, according to Dave Roth's FAQ, the module should
work fine. It didn't. I then tried release 304. I still get the parse
exception error. Any suggestions?

-Seth Johnson



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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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