[17093] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4505 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 3 11:10:26 2000

Date: Tue, 3 Oct 2000 08:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970585814-v9-i4505@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 3 Oct 2000     Volume: 9 Number: 4505

Today's topics:
        how to split text by number of words? <theebh@yahoo.com>
    Re: how to split text by number of words? <yanick@babyl.sympatico.ca>
    Re: how to split text by number of words? <jeffp@crusoe.net>
    Re: how to split text by number of words? <jeffp@crusoe.net>
    Re: Installing CPAN module on UNIX <elaine@chaos.wustl.edu>
        Need the best Perl Tutorial -- bar none <01031149@3web.net>
    Re: Need the best Perl Tutorial -- bar none <elaine@chaos.wustl.edu>
    Re: Need the best Perl Tutorial -- bar none <jim@inatos.com>
        Needed: Script for file tree delete and file tree move <Barry_Turner@Grayson.com>
    Re: Needed: Script for file tree delete and file tree m (Clay Irving)
    Re: Needed: Script for file tree delete and file tree m <bcaligari@my-deja.com>
    Re: Needed: Script for file tree delete and file tree m <elaine@chaos.wustl.edu>
        Net::SMTP problem <alexh1@optusnet.com.au>
    Re: Newbie can't handle the "true"th...  explanation de <ren.maddox@tivoli.com>
    Re: perl as a browser <nospam@david-steuber.com>
    Re: Proving the greatness of mod_perl <brian+usenet@smithrenaud.com>
        recursing ldap groupOfPersons (Björn Nilsson)
    Re: Regex: Perl5 to Perl4 Problem <bart.lateur@skynet.be>
    Re: Regex: Perl5 to Perl4 Problem <01031149@3web.net>
    Re: Regex: Perl5 to Perl4 Problem <01031149@3web.net>
    Re: Regex: Perl5 to Perl4 Problem <bart.lateur@skynet.be>
    Re: Regex: Perl5 to Perl4 Problem <flavell@mail.cern.ch>
    Re: Regex: Perl5 to Perl4 Problem <ren.maddox@tivoli.com>
    Re: Reverse by paragraphs - NOT! <ren.maddox@tivoli.com>
    Re: Testing for numeric integer (Keith Calvert Ivey)
    Re: This post should be a bit easier to answer <flavell@mail.cern.ch>
    Re: XML::Simple and not well-formed error <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 03 Oct 2000 10:37:08 GMT
From: Firestar <theebh@yahoo.com>
Subject: how to split text by number of words?
Message-Id: <8rccsk$ep7$1@nnrp1.deja.com>

Hi, i need to break a long chunk of text into a few paragraphs, each
paragraph not more than 300 characters, for example. can i use regexp
for this? TIA.

regards,
firestar


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 03 Oct 2000 13:41:20 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: how to split text by number of words?
Message-Id: <4mlC5.288104$Gh.8107483@news20.bellglobal.com>

Firestar <theebh@yahoo.com> wrote:
: Hi, i need to break a long chunk of text into a few paragraphs, each
: paragraph not more than 300 characters, for example. can i use regexp
: for this? TIA.

Yup.

$long_string = ( 'Hi, i need to break a long chunk of text into a few '.
                 'paragraphs, each paragraph not more than 300 '.
                 'characters, for example. can i use regexp for '.
                 'this? TIA. ' ) x 60;
 
$long_string =~ tr/\n//;  # just to be sure...
 
push @paragraphs, $1 while $long_string =~ /(.{0,299}([,.;:]|\b))/g; 
 
foreach( @paragraphs )
{
        print "paragraph is ", length( $_ ), " chars long\n";
        print "\n\n$_\n\n";
}

Of course, you will have to fine-tune the regex to match exactly what
you want...

Joy,
Yanick

-- 
($_,$y)=("Yhre lo  .kePnarhtretcae\n",   '(.) (.)'  );
$y=~s/\(/(./gwhile s/$y/$2$1/xg;print;       @      !; 
                                     "     `---'    ";


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

Date: Tue, 3 Oct 2000 10:26:43 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: how to split text by number of words?
Message-Id: <Pine.GSO.4.21.0010030945010.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 3, Firestar said:

>Hi, i need to break a long chunk of text into a few paragraphs, each
>paragraph not more than 300 characters, for example. can i use regexp
>for this? TIA.

This is a super use of formats.  Formats come in handy when you want to do
line-wrapping type things.  I'm about to show you how you can break your
text up with a function called formline() and the $^A variable.

(Suggestion: look at the 'perlform' documentation.)

First, we will use formline() to work with your text 300 characters at a
time (at most).  Of important note: the $: variable holds the characters
on which format will break your text -- it's usually "- \n", but you may
want to make it just " \n".  The $format variable in this function holds a
string that looks like

^<<<<<<<<<<<<<<<<<<<~

which, to Perl formats, means "left-justify this string, display 20
characters of it", and the ~ at the end is VERY important -- it means that
it should remove the characters it displays from the front of the variable
it's displaying.  That means, the NEXT time I use that variable and this
format, it'll display the NEXT 20 characters, and so on.

  @paragraphs = breakup(300, $string);

  sub breakup {
    my ($len, $text) = @_;
    my $format = '^' . ('<' x --$len) . "~\n";
    my @return;
    local $^A;  # this is where formline() puts its content
    while (length $text) {
      formline($format, $text);
      push @return, $^A;
      $^A = "";  # clear it
    }
    return @return;
  }

That will set your paragraphs up.  Now, if you want them formatted so that
they're each wrapped at 70 characters, you can call a second function.
This function is very similar to the other, but notice it takes a length
and a LIST of strings, and there is a SECOND ~ in the $format variable.
This second ~ means that the format should continually do what we ask with
the text until all the text is gone.

  @wrapped = linewrap(70, @paragraphs);

  sub linewrap {
    my $len = shift;
    my $format = '^' . ('<' x --$len) . "~~\n";
    my @return;
    local $^A;  # this is where formline() puts its content
    for (@_) {
      formline($format, $_);
      push @return, $^A;
      $^A = "";  # clear it
    }
    return @return;
  }

For more info, check the perlform documentation.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 3 Oct 2000 10:35:52 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: how to split text by number of words?
Message-Id: <Pine.GSO.4.21.0010031035200.14163-100000@crusoe.crusoe.net>

On Oct 3, Jeff Pinyan said:

>which, to Perl formats, means "left-justify this string, display 20
>characters of it", and the ~ at the end is VERY important -- it means that
>it should remove the characters it displays from the front of the variable
>it's displaying.  That means, the NEXT time I use that variable and this
>format, it'll display the NEXT 20 characters, and so on.

Err, the ^<<<<<<<<<< does that on its own.  The ~ here is not needed.  My
bad. ;)

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 03 Oct 2000 13:37:45 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: Installing CPAN module on UNIX
Message-Id: <B5FF596E.7472%elaine@chaos.wustl.edu>

in article 8rc797$arp$1@nnrp1.deja.com, paul_a_long@my-deja.com at
paul_a_long@my-deja.com quoth:
 
> I thought the PREFIX statement was all I needed. Is there anything else?
> 
> Unfortunately, my UNIX skills are a little rusty. Any help would be much
> appreciated.

Nope, you did the right thing. It will give you the error about permissions,
but did you look in the directory you specified to see if it had, indeed,
installed it? It should be there, if not you should do an 'ls -ald' from the
root of your home dir to make sure you have the correct permissions, such as
write, to your own dir. Also, make sure that you do a 'use lib 'my datecalc
location';' in your programs to make sure that it the programs can find it.

e.



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

Date: Tue, 3 Oct 2000 07:02:43 -0600
From: "Duke Normandin" <01031149@3web.net>
Subject: Need the best Perl Tutorial -- bar none
Message-Id: <JKkC5.3262$Jd4.25566@jekyl.ab.tac.net>

This newbie is in dire need of the *best* Perl Tutorial
available on the 'net!! I've got close to a dozen
so-so ones already. Any suggestions?

-- 
tia....duke



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

Date: Tue, 03 Oct 2000 13:21:05 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: Need the best Perl Tutorial -- bar none
Message-Id: <B5FF5587.7470%elaine@chaos.wustl.edu>

in article JKkC5.3262$Jd4.25566@jekyl.ab.tac.net, Duke Normandin at
01031149@3web.net quoth:

> This newbie is in dire need of the *best* Perl Tutorial
> available on the 'net!! I've got close to a dozen
> so-so ones already. Any suggestions?

There are a few listed at
http://www.cpan.org/misc/cpan-faq.html#Where_find_Perl_training though, as
always, YMMV.

e. 




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

Date: Tue, 3 Oct 2000 15:43:49 +0100
From: "Jim Wright" <jim@inatos.com>
Subject: Re: Need the best Perl Tutorial -- bar none
Message-Id: <pfmC5.1749$RB1.14124@NewsReader>

Buy a book - I picked up Perl through web tutorials and asking people on
here, I spent more time doing that than if I bought a good book (like the
Camel (one)), if your time is worth anything to you, its cheaper to buy a
book! Otherwise, if you insist, I started at cgi101.com, it gets you on the
road and using netpedia.com/coding/cgi as a refernce manual.

Jim

PS if you get to any advanced level you'll, need a good book anyway!


"Duke Normandin" <01031149@3web.net> wrote in message
news:JKkC5.3262$Jd4.25566@jekyl.ab.tac.net...
> This newbie is in dire need of the *best* Perl Tutorial
> available on the 'net!! I've got close to a dozen
> so-so ones already. Any suggestions?
>
> --
> tia....duke
>




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

Date: Tue, 03 Oct 2000 08:32:31 -0400
From: "Barry G. Turner" <Barry_Turner@Grayson.com>
Subject: Needed: Script for file tree delete and file tree move
Message-Id: <39D9D1DF.D9F9D377@Grayson.com>

I'm looking for a script to delete all files and subdirectories under a given
directory and also a script to move files and subdirectories between a known
source and target directory.

Any help is appreciated,

Thanks,

Barry


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

Date: 3 Oct 2000 12:50:07 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Needed: Script for file tree delete and file tree move
Message-Id: <slrn8tjlfv.lp2.clay@panix3.panix.com>

On Tue, 03 Oct 2000 08:32:31 -0400, Barry G. Turner <Barry_Turner@Grayson.com> 
wrote:

>I'm looking for a script to delete all files and subdirectories under a given
>directory and also a script to move files and subdirectories between a known
>source and target directory.
>
>Any help is appreciated,

File::Find  -  Traverse a file tree
File::Copy  -  Copy files or filehandles
unlink      -  Deletes a list of files
rename      -  Changes the name of a file
               (will usually not work across file system boundaries)

-- 
Clay Irving <clay@panix.com>
I'm interested in the fact that the less secure a man is, the more likely
he is to have extreme prejudice. 
- Clint Eastwood 


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

Date: Tue, 03 Oct 2000 12:56:11 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Needed: Script for file tree delete and file tree move
Message-Id: <8rcl18$knd$1@nnrp1.deja.com>

In article <39D9D1DF.D9F9D377@Grayson.com>,
  Barry_Turner@Grayson.com wrote:
> I'm looking for a script to delete all files and subdirectories under
a given
> directory and also a script to move files and subdirectories between
a known
> source and target directory.
>
> Any help is appreciated,
>
> Thanks,
>
> Barry
>

on unixes:
  man mv
  man rm

on win2k
  move /?
  del /?

from perl you can system() the commands

Brendon




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 03 Oct 2000 13:24:48 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: Needed: Script for file tree delete and file tree move
Message-Id: <B5FF5666.7471%elaine@chaos.wustl.edu>

in article 39D9D1DF.D9F9D377@Grayson.com, Barry G. Turner at
Barry_Turner@Grayson.com quoth:

> I'm looking for a script to delete all files and subdirectories under a given
> directory and also a script to move files and subdirectories between a known
> source and target directory.
> 
> Any help is appreciated,

File::Find is what you are looking for
http://theoryx5.uwinnipeg.ca/CPAN/perl/File/Find.html

enjoy.

e.



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

Date: Mon, 2 Oct 2000 22:37:42 +1000
From: "Alex Harvey" <alexh1@optusnet.com.au>
Subject: Net::SMTP problem
Message-Id: <39d9bcb8$0$12434$7f31c96c@news01.syd.optusnet.com.au>

I am finding that when I use Net::SMTP to send a simple email to myself I
receive an error "The system cannot find the path specified". (I am using
Windows 2000.) I have turned on use diagnostics and run the script using
the -w option and the error looks like it is in the module itself rather
than in my code. I've been unable to find any clear answers using deja. Has
anyone solved this problem?

Here is the code

use Net::SMTP;
use diagnostics;

Send_Mail()
        || die "Send_Mail: $!";

sub Send_Mail {
    my $smtp;

    $smtp = Net::SMTP->new('mail.pacificgaming.com.au');
    $smtp->mail( 'alexh' );
    $smtp->to( 'alexh' );
    $smtp->data();

    $smtp->datasend("To: alexh\@pacificgaming.com.au\n");
    $smtp->datasend("From: alexh\@pacificgaming.com.au\n");
    $smtp->datasend("\n");

    $smtp->datasend("Hello, World!\n");
    $smtp->dataend();
    $smtp->quit;

    return $!;
}

And here is the output:

c:\perl> perl -w sendmail_eg.pl

The system cannot find the path specified.
Use of uninitialized value in scalar assignment at
        C:/Perl/site/lib/Net/Domain.pm line 191 (#1)

    (W uninitialized) An undefined value was used as if it were already
defined.
  It was interpreted as a "" or a 0, but maybe it was a mistake.  To
suppress this
    warning assign a defined value to your variables.

Use of uninitialized value in pattern match (m//) at
        C:/Perl/site/lib/Net/Domain.pm line 215 (#1)
Use of uninitialized value in split at C:/Perl/site/lib/Net/Domain.pm line
219 (
#1)




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

Date: 02 Oct 2000 22:10:37 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Newbie can't handle the "true"th...  explanation desired
Message-Id: <m3hf6u8vrm.fsf@dhcp11-177.support.tivoli.com>

ilya@math.ohio-state.edu (Ilya Zakharevich) writes:

> 
>   undef WHATEVER
> 
>     - clears the memory buffers associated for WHATEVER
> 
>   $var = undef;
> 
>     - marks the memory buffers as unapplicable;
> 
> So there is no difference from the Perl side.  All the difference is
> in performance.  Using $var = undef keeps the buffers ready for the
> next time something is going to be assigned to $var, so is a speed
> optimization.  Using undef $var free()es memory used by buffers, so it
> is a space optimization.
> 
> Your choice - but only if the situation is so bad that you need
> microoptimizations.  Otherwise they are synonyms.

OK, in the same vein, how 'bout:

undef @array;

versus:

@array = ();

?

(and the same for hashes if it makes any difference....)

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 03 Oct 2000 14:37:40 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: perl as a browser
Message-Id: <m3em1yxa6h.fsf@solo.david-steuber.com>

Has anyone written an actual browser (like Netscape) in Perl/Tk?

-- 
David Steuber | Perl apprentice, Apache/mod_perl user,
NRA Member    | and general Internet web wannabe.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Tue, 03 Oct 2000 10:34:01 -0400
From: brian d foy <brian+usenet@smithrenaud.com>
Subject: Re: Proving the greatness of mod_perl
Message-Id: <brian+usenet-C5C4D6.10340103102000@news.panix.com>

In article <8rar0b$7nm$1@nnrp1.deja.com>, cmalcolm@my-deja.com wrote:

> Is there a list of major web sites that are using mod_perl
> succesfully?  

see http://perl.apache.org

> The people assessing us seem to think that Perl is no good for these
> reasons:

> 1)  It is good for prototyping, but is bad for a site that must be
> highly scalable.

perhaps you can point them to Perl Succces Stories:

    http://perl.oreilly.com/news/success_stories.html

> 2)  It is too slow.

mod_perl is really speedy.

> 3)  It is not object-oriented (They listen for words like "Java"
> and "C++" to decide if something is object-oriented).

neither of those languages are truly object oriented either.
Perl can 

> 4)  They have not heard of mod_perl before.

they hadn't heard of C++ or Java at one point either.

> 5)  They say you can't employ 'Perl certified engineers'!!!

you can't.  of course, certification doesn't mean anything but
that is a different flame war.

 
> So, I have a choice:
> 
> A) Abandon Perl with mod_perl and start using Java
> B) Try and educate these guys.

the better option, rather than put up a fight, is to 
try both and let them pick the one that they like better.
give them the blind taste test. :)

-- 
brian d foy
Perl Mongers <URL:http://www.perl.org>
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


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

Date: Tue, 03 Oct 2000 14:15:27 GMT
From: bjorn.nilsson@bct.ericsson.se (Björn Nilsson)
Subject: recursing ldap groupOfPersons
Message-Id: <39d9e6dc.428476807@news.ericsson.se>

Hi!

I have a little problem with a LDAP script I'm dveloping. The purpose
is to extract users from mailing-lists and insert them into another
database, grouped by the specified mailing-list.
The problem is that after doing the first search, I get a number of
members to a group. I loop through these. If there are no sub-groups
I'm home dry, but if there are sub-lists I cannot get the recursion to
work as it should.

From the first ldap->search I get an array of members, which I send,
item by item, to a &detail_search($username, $newdn)
If there are no attributes called "member" in the detail_search() I
simply do an insertion into the database of some values. If there are
attributes called "member" I loop that particular array with calls to
detail_search() with a split of each member-attribute as attributes to
the call.. 
It is in this sub-call things get messy. I do get the first sub-list
member, but not the rest, even though there are e.g. 5 members to that
list. It seems like the $member[1 - n] values disappear.

Cheers

Björn


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

Date: Tue, 03 Oct 2000 10:19:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regex: Perl5 to Perl4 Problem
Message-Id: <udcjts0oc21qf2m50nhbm626qcsuvscjj4@4ax.com>

Duke Normandin wrote:

>I'm a newbie to Perl & regex.
>
>I need to get the following Perl5 code working in Perl4:
>
>$email =~s/^.*?(From|Received|Sender|Return-Path|Date):/$:/s;
>
>Would someone please interpret what's going on in the above
>code so that I can learn something; and show me what changes
>are needed to get it working with Perl4?

".*?" indicates nongreedy matching. It means it wants to find the first
instance of either "From", "Received", ... and eliminate everything in
front of it.

If you're doing this in Perl4, you might just as well use the
inefficient but easy path, and rely on $`.

	if($email =~ /(From|Received|Sender|Return-Path|Date):/) {
	    substr($email, 0, length $`) = "";
	}


Oh, I think the '$:' on the RHS should really have been '$1:'.

-- 
	Bart.


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

Date: Tue, 3 Oct 2000 06:57:10 -0600
From: "Duke Normandin" <01031149@3web.net>
Subject: Re: Regex: Perl5 to Perl4 Problem
Message-Id: <PFkC5.3260$Jd4.25620@jekyl.ab.tac.net>


Bart Lateur wrote in message ...
>Duke Normandin wrote:
>
>>I'm a newbie to Perl & regex.
>>
>>I need to get the following Perl5 code working in Perl4:
>>
>>$email =~s/^.*?(From|Received|Sender|Return-Path|Date):/$:/s;
>>
>>Would someone please interpret what's going on in the above
>>code so that I can learn something; and show me what changes
>>are needed to get it working with Perl4?
>
>".*?" indicates nongreedy matching. It means it wants to find the first
>instance of either "From", "Received", ... and eliminate everything in
>front of it.


I've DLed a dozen Perl tutorials and did get *that* far -- however I
can't see how Perl4 would puke on that?

>If you're doing this in Perl4, you might just as well use the
>inefficient but easy path, and rely on $`.
>
> if($email =~ /(From|Received|Sender|Return-Path|Date):/) {
>     substr($email, 0, length $`) = "";
> }


What would be the hard but efficient path in Perl4?

>Oh, I think the '$:' on the RHS should really have been '$1:'.


I saw my typo *after* I hit the "send" button -- sorry and thanks!!

-duke



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

Date: Tue, 3 Oct 2000 06:58:31 -0600
From: "Duke Normandin" <01031149@3web.net>
Subject: Re: Regex: Perl5 to Perl4 Problem
Message-Id: <NGkC5.3261$Jd4.25607@jekyl.ab.tac.net>

Randal L. Schwartz wrote in message ...
>>>>>> "Duke" == Duke Normandin <01031149@3web.net> writes:
>
>Duke> I need to get the following Perl5 code working in Perl4:
>
>My spider sense is tingling.


Meaning....??

-duke



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

Date: Tue, 03 Oct 2000 13:13:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regex: Perl5 to Perl4 Problem
Message-Id: <9qmjtskb323d0otb94u2449fj5kq4h2top@4ax.com>

Duke Normandin wrote:


>>".*?" indicates nongreedy matching. It means it wants to find the first
>>instance of either "From", "Received", ... and eliminate everything in
>>front of it.
>
>I've DLed a dozen Perl tutorials and did get *that* far -- however I
>can't see how Perl4 would puke on that?

Because that was new in Perl5?

>>If you're doing this in Perl4, you might just as well use the
>>inefficient but easy path, and rely on $`.
>>
>> if($email =~ /(From|Received|Sender|Return-Path|Date):/) {
>>     substr($email, 0, length $`) = "";
>> }
>
>What would be the hard but efficient path in Perl4?

It's not THAT inefficient. I don't think that any manual emulation would
be any faster.

-- 
	Bart.


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

Date: Tue, 3 Oct 2000 15:36:24 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Regex: Perl5 to Perl4 Problem
Message-Id: <Pine.GHP.4.21.0010031514190.19286-100000@hpplus03.cern.ch>

On Tue, 3 Oct 2000, Duke Normandin wrote:

> Randal L. Schwartz wrote in message ...
> >>>>>> "Duke" == Duke Normandin <01031149@3web.net> writes:
> >
> >Duke> I need to get the following Perl5 code working in Perl4:
> >
> >My spider sense is tingling.
> 
> Meaning....??

I suspect you're down some kind of hole.  The best thing you could do
is decide to stop digging, climb out, and tackle the real problem,
instead of trying to dig yourself further in with a way-obsolete
version with many known and serious problems.

Almost whatever the question: Perl4 is not the answer, but is part of
the problem.  If you'd done even a little research on the question,
e.g at Deja, before asking, it's hard to believe you wouldn't already
know that.

If the resident troll tells you otherwise, then let that serve as a 
further warning...



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

Date: 02 Oct 2000 23:04:45 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Regex: Perl5 to Perl4 Problem
Message-Id: <m3em1y8t9e.fsf@dhcp11-177.support.tivoli.com>

"Duke Normandin" <01031149@3web.net> writes:

> Don't ask -- Perl5 to Perl4 ?????
> 
> I'm a newbie to Perl & regex.
> 
> I need to get the following Perl5 code working in Perl4:
> 
> $email =~s/^.*?(From|Received|Sender|Return-Path|Date):/$:/s;

I would think that something is missing after that dollar sign,
because it doesn't seem very likely that the special variable $: is
intended.  I'm going to assume that "$1:" is what is meant.

> Would someone please interpret what's going on in the above
> code so that I can learn something; and show me what changes
> are needed to get it working with Perl4? The code is from
> some utility I DL'ed off the 'net.

This regex doesn't seem quite correct to me.  I mean that I assume I
understand the point, but using ".*?" to chew up whatever comes before
any of the desired headers seems overly permissive.  For example, it
would change something like "Original-Sender:" to "Sender:", which
just doesn't seem desirable.  Being more strict about what is allowed
before one of these headers would probably make the conversion
trivial.  If only whitespace should be allowed, then just use "\s*".
The ".*?" piece is the only non-Perl4 piece, but in this instance it
is tough to emulate.

Oh, here is the break-down of what it is doing:

$email =~                 # Apply the following regex to $email
          s/              # The regex is a substitution
            ^             # Starting at the beginning of the value...
            .             # Match any character...
             *            # Any number of times...
              ?           # But as few times as will allow the rest to match
            (             # Save what follows (also groups it)
             From         #   Match "From"
             |            #  OR
             Received     #   Match "Received"
             |            #  OR
             Sender       #   Match "Sender"
             |            #  OR
             Return-Path  #   Match "Return-Path"
             |            #  OR
             Date         #   Match "Date"
            )             # End of save grouping
            :             # Match ":"
           /              # End of pattern match, start of replacement
            $1            # The value of the first (and only) saved group
            :             # A literal ":"
           /sx            # end of substitution regex
                          # "s" allows "." to match newlines
                          # "x" is simply to allow this explanation


Anyway, here is a Perl4 version:

$email =~ /(From|Received|Sender|Return-Path|Date):/;
$email = $& . $';         # $& is what matched and $' is what came after it
                          # this simply throws away $`, which is what came
                          # before the match

Note that this is not a general replacement for the non-greedy
quantifiers, but takes advantage of the fact that regexes are
naturally non-greedy at the beginning.  Also, there is a relatively
severe performance hit on every regex in a script that includes any of
these three special variables ($`, $&, $').  But I wouldn't worry
about it too much.  Actually, there are ways to avoid them and still
solve this problem.  Here is one:

($before, $match, $after)
   = split(/(From|Received|Sender|Return-Path|Date):/, $email, 2);
$email = "$match:$after";

-- 
Ren Maddox
ren@tivoli.com


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

Date: 03 Oct 2000 00:09:51 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <m38zs68q8w.fsf@dhcp11-177.support.tivoli.com>

ollie_spencer@my-deja.com writes:

> Hi and thanks for your reply.
> I found it necessary to read-in the file line-by-line, rather than
> "slurping" it into an array, so I could rid it of the header data.

In case you didn't realize it, you can change $/ on-the-fly after
reading part of the file.  So, read the header data line-by-line, then
change $/ to read the rest of the file a paragraph at a time.

> However, in an experiment, I "slurp"ed it in (@Array=<INFILE>;) and
> attempted to process it, with the same results as I posted. That of
> course may simply mean I don't know yet how to do it...

Did you change $/ when you pulled it into @Array?  If not, then I
wouldn't expect any different results.

I think you want something along the lines of:

while(<INFILE>) {
   # Done with the header yet?
   last if /^----/;   # Or however you detect the end of the header
}

$/ = "";   # or "\n\n" if you don't want to ignore extra blank lines
print reverse <INFILE>;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 03 Oct 2000 13:16:13 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Testing for numeric integer
Message-Id: <39d9db98.48036709@news.newsguy.com>

Graham Daniell <gdaniell@wt.com.au> wrote:

>Can anyone tell me how I test that a field contains ONLY a number,
>without any decimal point in it?  ie: a number like 1 or 2 or 199?  Or
>where to look to find the answer?
>
>It is for a web product ordering application and I want to ensure that
>the user has entered a valid number of products, so I can multiply by
>the unit price to get the total price.

I think you'll want a stricter test than that, since "0" and
"99999999999999999" are presumably not valid inputs.  Anyway,
see perlre, perlop, and perlfaq, along with the answers others
have given.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Tue, 3 Oct 2000 12:04:00 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: This post should be a bit easier to answer
Message-Id: <Pine.GHP.4.21.0010031202220.19286-100000@hpplus03.cern.ch>

On Mon, 2 Oct 2000, James Bengard wrote:

> Subject : This post should be a bit easier to answer

Certainly is.  Just one look at the subject header suffices.

Why _do_ usenauts harm themselves in this way?



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

Date: Tue, 03 Oct 2000 10:14:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: XML::Simple and not well-formed error
Message-Id: <pcbjts0ooqqflh933ovcuf9iu2q2bkelmv@4ax.com>

Thomas Åhlen wrote:

>Hi i have generated an XML file with a perl script and a template package.
>When i try to parse the XML file i get an error but i can't see what is
>wrong.

I guess that there's some unacceptable character in there. XML::Parser
is very picky about that. Yes, it says "not well-formed" in such a case.

XML::Parser has an option for that: ProtocolEncoding. Give it a value
'ISO-8859-1', and it will treat your XML file as ISO-Latin-1.

I don't know if and how XML::Simple inherits that option. Oh, there it
is. You need to set it inside parseropts.

    XMLin($xml, parseropts => [ ProtocolEncoding => 'ISO-8859-1' ])

I have not tested it, though. Only read the docs.

If your source contains strange characters but is not ISO-Latin-1, you
need a character encodings file, which resides in the
XML/Parser/Encodings directory, and have the ".enc" extension. Use the
bare filename without the extension. And no, oddly enough, Windows
(slightly different from ISO-Latin-1) and Macintosh text are not there
by default. I can mail you encoding files for those, if you wish.

-- 
	Bart.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V9 Issue 4505
**************************************


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