[8970] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2588 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 13 20:10:30 1998

Date: Wed, 13 May 98 17: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, 13 May 1998     Volume: 8 Number: 2588

Today's topics:
    Re: "if" statement help <qumsieh@colba.net>
    Re: Bug/Feature wrt write/my? (Martien Verbruggen)
    Re: Compiling perl with static libc (Martien Verbruggen)
    Re: Does Perl have a IDE?I don't like command line. (Michael J Gebis)
    Re: Does Perl have a IDE?I don't like command line. <jsd@gamespot.com>
    Re: getting the modem to dial out (Martien Verbruggen)
    Re: Help with building GD for perl (Martien Verbruggen)
    Re: How can you break out of a 'while... ' loop in a fu <igor.k@usa.net>
    Re: How can you break out of a 'while... ' loop in a fu (Martien Verbruggen)
    Re: How can you break out of a 'while... ' loop in a fu <tchrist@mox.perl.com>
    Re: How can you break out of a 'while... ' loop in a fu (John Moreno)
    Re: Is if ($a="something") a bad style? (John Moreno)
        module "manifest" <walton@kodak.com>
    Re: module "manifest" <rootbeer@teleport.com>
    Re: Modules:  why doesn't this work? (Martien Verbruggen)
        Need discussion group script pkbk@badger.tds.net
    Re: Nuclear bombing of NEW YORK! Small countries can ta <sowmaster@juicepigs.com>
    Re: Please help w/ form mailing <rootbeer@teleport.com>
        program cannot run in CGI but in Perl on NT <kliou@ichat.com>
    Re: Question: Finding which element of a list a string  (Martien Verbruggen)
    Re: Really Basic Questions (Martien Verbruggen)
    Re: Reg Expr convert one string to another <jstern@world.northgrum.com>
    Re: Reg Expr convert one string to another (Tad McClellan)
    Re: Regular Expression Question <lr@hpl.hp.com>
    Re: resolving IP addresses on WinNT <rootbeer@teleport.com>
    Re: run against a list <rootbeer@teleport.com>
    Re: Stumped on opening file to print. (Martien Verbruggen)
    Re: Trouble w/CPAN.pm and MD5 - catch22 errors! <rootbeer@teleport.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 13 May 1998 19:15:29 -0700
From: Ala Qumsieh <qumsieh@colba.net>
Subject: Re: "if" statement help
Message-Id: <355A53C1.6BD4FAA4@colba.net>

Reginald Johnson wrote:

> <snip>

> if ($dbh = Msql->Connect(defiant,"cs495")){
>     print "<body bgcolor=#3300cc text=white link=yellow vlink=green>";

  if ($dbh == ...)

= is an assignment .. == is a comparison.



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

Date: 13 May 1998 23:11:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Bug/Feature wrt write/my?
Message-Id: <6jd9bt$d6k$7@comdyn.comdyn.com.au>

In article <qylvhraidpp.fsf@ubu.enst.fr>,
	Akim Demaille <demaille@inf.enst.fr> writes:

> I'm a newbie to perl, but got a problem I'd like to consider as a bug.
> If it is not, then, hell, can somebody give me a good reason for this
> script not to do what one expects (i.e., the same behavior as print
> has).

What is the version of perl you're running? perl 5.004_04 does it
fine. I seem to recall that a few versions ago there was an issue with
my variable scoping, that was fixed.

> ubu /tmp \$ cat test.pl 

Odd prompt :)

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd.       | inexactitude.
NSW, Australia                      | 


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

Date: 13 May 1998 23:27:26 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Compiling perl with static libc
Message-Id: <6jda8u$dj6$1@comdyn.comdyn.com.au>

In article <3559cece.3120330@nntp.netcom.net.uk>,
	tom@NOSPAMeborcom.com (Tom Hukins) writes:

> I've tried several variations of config.sh, compiled with "make
> realclean", "Configure -S", "make depend", then "make". Every
> time "ldd ./perl" shows that I have created a dynamic executable,
> with libm, libc and libcrypt linked. "./perl -V:usedl" sometimes
> suggests shared libraries are enabled, but sometimes not. In
> fact, "./perl -V" can sometimes be quite different to my
> config.sh. I have deleted and re-installed the Perl source, but
> this still happens. Is it possible Perl is taking variables from
> elsewhere?

You don't mention trying Configure -Uusedl as documented in INSTALL
(at the first mention of the string 'static').

The -S option to Configure does something totally different.

# ./Configure -h
[snip]
  -S : perform variable substitutions on all .SH files (can mix with -f)
[snip]

Martien

PS. I don't _know_ wether doing this will statically link libc. It
does compile perl to be static though.
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Inside every anarchy lurks an old boy
Commercial Dynamics Pty. Ltd.       | network - Mitchell Kapor
NSW, Australia                      | 


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

Date: 13 May 1998 21:53:28 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jd4oo$k2@mozo.cc.purdue.edu>

gbacon@cs.uah.edu (Greg Bacon) writes:

}In article <6jctr4$r7i@mozo.cc.purdue.edu>,
}	gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:
}: It's time to stop trying
}: to fight a battle you lost a long time ago.  Instead, it's time to do
}: whatever is necessary to spoon-feed the documentation to them so they stop
}: wasting time and bandwidth."

}I'm surprised you don't munge your posts' From: header too.  I don't
}generally take such defeatist attitudes.  If someone were to come along
}and piss in my sandbox, I wouldn't encourage them (whether or not they
}were into alt.sex.watersports).  I'd probably ask them to stop or find a
}new sandbox, perhaps both.  Perhaps comp.lang.perl.moderated's
}description should be ``The new sandbox''.

I'm doubtful that this is wise, but to go along with the peeing
analogy:

After dozens of folks kept peeing in my sandbox day after day, I'd gladly
provide them instructions on the local customs in any format that they
would understand.

}I wonder whether Ken or Larry or Rob or dmr or bwk use IDEs.  I would be
}shocked to learn that they do.

So if everyone was as good a programmer as Ken or Larry or Rob or dmr
or bwk, we would have no problem.  I agree with you on this.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Wed, 13 May 1998 16:15:31 -0700
From: Jon Drukman <jsd@gamespot.com>
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <355A2993.A5F3EB23@gamespot.com>

Greg Bacon wrote:
> IRIX is a special kind of suck.  It ships without document formatting
> tools (troff, nroff, eqn, etc.).  Configure detects the absence of these
> tools and doesn't run pod2man.

(although this post sounds like an IRIX apology, let me just state up
front that i am no irix-lover.  i just happen to have been forced to use
it for a few years now so i've learned a few tricks for getting along
without too much hair-pulling.)

you can get ports of groff/eqn/everything you every needed to format a
perl pod into man from sgi's on the freeware CD or from
http://www.sgi.com/TasteOfDT/public/freeware1.0/fw_GNUgroff/

in fact, if you are going to even THINK about progamming on IRIX, you
should probably get the freeware CD.  it has just about every GNU util
plus useful-for-perl stuff like Berkeley DB.  emacs and samba too...

if you install berkeley DB and groff (and set up your paths correctly)
before installing perl, you will be WAY ahead of the game.

signed,
irix: i'm livin' it but i ain't lovin' it.

-- 
Jon Drukman                                            jsd@gamespot.com
-----------------------------------------------------------------------
Plan: Eat right, exercise regularly, die anyway.


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

Date: 13 May 1998 23:06:10 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: getting the modem to dial out
Message-Id: <6jd912$d6k$6@comdyn.comdyn.com.au>

In article <35596FC6.228520CC@was.net>,
	Samuel King <samk@was.net> writes:
> How or where would I even start this task.?
> Is there anyway to get perl to initialize and connect to my isp with my
> modem?

You forgot to mention a few things: What platform are you on? What
sort of connection do you want to establish? How do you do it now? 
etc. etc.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd.       | thing but mean your mother.
NSW, Australia                      | 


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

Date: 13 May 1998 22:27:50 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help with building GD for perl
Message-Id: <6jd6p6$d6k$1@comdyn.comdyn.com.au>

In article <1998051310472201.GAA21845@ladder01.news.aol.com>,
	wercrb@aol.com (WercRB) writes:
> please? do you not know or something?

Don't beg. People would have answered if they knew.

>>come on, someone help me out here.
>>
>>>I have been unable to install GD (1.18) for perl because
>>>the make file halts and says it can't find perlio.h.
>>>The file in question actually exists in several
>>>directories including the perl dir.
>>>
>>>The docs for GD say:
>>> (Please do not complain to me if your build fails with an
>>>  error about not finding perlio.h.  This file is part of more
>>>  recent versions of Perl.  You will need a recent version of
>>>  Perl to compile and install this package).
>>>
>>>But I have the most recent official version (perl5.004_04) and
>>>it is still not working.

I suggest you check your installation of perl. Have you looked for
perlio.h? Is it where it should be? I mean.. I don't know...

What happens when you try to compile other modules that have XS stuff?

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd.       | make a better idiot.
NSW, Australia                      | 


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

Date: Wed, 13 May 1998 15:46:51 -0700
From: "Igor Krivokon" <igor.k@usa.net>
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jd7mh$6fm$1@news.ncal.verio.com>

Tom Christiansen wrote in message <6jcu6m$c3k$5@csnews.cs.colorado.edu>...
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, "Igor Krivokon" <igor.k@usa.net> writes:
>:Afair, Pascal *has* next, break and return. No redo, though.
>
>It certainly never used to.  You must be talking about one 
>of the non-standard Pascals, or a new standard.


Oops, you are right. Last time I encountered pascal about 5 years ago on 
a SGI computer, and it was quite non-standard pascal, indeed. 
Those words are not part of Pascal standard; there's only "goto" there.

Igor Krivokon
<igor.k@usa.net>





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

Date: 13 May 1998 22:32:25 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jd71p$d6k$2@comdyn.comdyn.com.au>

In article <35596dd5.2863968@news.demon.co.uk>,
	stu-w@usa.net.remove.everything.after.net (Stuart Wright) writes:

> Incidentally I *did* buy the 'learn Perl in a week' book by somebody
> or other.  It's crap - there's no language reference.

I'd believe it's crap. The title gives it away.

For a list of good books, and some reviews of them:

http://language.perl.com/info/documentation.html
http://language.perl.com/critiques/index.html

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Inside every anarchy lurks an old boy
Commercial Dynamics Pty. Ltd.       | network - Mitchell Kapor
NSW, Australia                      | 


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

Date: 13 May 1998 22:56:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <6jd8f2$qn4$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, "Igor Krivokon" <igor.k@usa.net> writes:
:Those words are not part of Pascal standard; there's only "goto" there.

How unreassuring.  :-)

--tom
-- 
	  "And I don't like doing silly things (except on purpose)."
		--Larry Wall in <1992Jul3.191825.14435@netlabs.com>


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

Date: Wed, 13 May 1998 23:24:43 GMT
From: phenix@interpath.com (John Moreno)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <1d8zell.1s71kwx16w0lkwN@roxboro0-035.dyn.interpath.net>

Tom Christiansen <tchrist@mox.perl.com> wrote:

>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, "Igor Krivokon" <igor.k@usa.net> writes:
> :Those words are not part of Pascal standard; there's only "goto" there.
> 
> How unreassuring.  :-)

Well leave and exit are pretty common (can't remember whether or not
they are standard) and as long as you don't need to leave a subroutine
goto can (with care) do the job just fine.

And whichever one of you wrote the bit about it being bunk - you're
right, but it's good bunk to start with (reminds me of the bit in a
separate thread about good teachers lying to the students).

-- 
John Moreno


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

Date: Wed, 13 May 1998 23:03:50 GMT
From: phenix@interpath.com (John Moreno)
Subject: Re: Is if ($a="something") a bad style?
Message-Id: <1d8zdcz.1hr8zu916ib8juN@roxboro0-035.dyn.interpath.net>

Bart Lateur <bart.mediamind@tornado.be> wrote:

> John Moreno wrote:
> 
> >That's why I want to know if this is thought of as
> >> neat in Perl too.
> >
> >I understood what you meant - but that's NOT neat in C and it's not neat
> >in Perl.  It works (in both) and can occasionally be useful, but
> >generally it's just a opportunity for a mistake to happen.
> >
> >So to answer the subject - yes it's a bod style.
> 
> <Huge big grin>. Do you realize that THE Perl idiom is actually a
> variation to this theme?
> 
> Yes, I'm talking about:
> 
>   while(<>){
>       ...
>   }
> 
> and friends. Which is an assignment plus a test in one.

LOL.

No, I hadn't thought of that - I KNOW that's what going on, but that's
not how I think of it.  It's "loop while reading the current input file
and setting $_ as long as the file still has data" all as one idea.

I still say in the general case that it's bad style.

-- 
John Moreno


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

Date: Wed, 13 May 1998 17:58:50 -0400
From: Bob Walton <walton@kodak.com>
Subject: module "manifest"
Message-Id: <355A179A.1AC4@kodak.com>

While attempting to install various perl modules (first time I have
tried this, using perl for win32, version 5.003_07), I get an error
"Can't locate ExtUtils/Manifest.pm in @INC at (eval 5) line 374.", for
example.  I have looked all over CPAN for Manifest.pm, with no success. 
Is there somewhere where I can get module Manifest.pm?  Thank you.
-- 
Bob Walton
walton@kodak.com


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

Date: Wed, 13 May 1998 23:03:31 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Walton <walton@kodak.com>
Subject: Re: module "manifest"
Message-Id: <Pine.GSO.3.96.980513160215.21974E-100000@user2.teleport.com>

On Wed, 13 May 1998, Bob Walton wrote:

> While attempting to install various perl modules (first time I have
> tried this, using perl for win32, version 5.003_07), I get an error
> "Can't locate ExtUtils/Manifest.pm in @INC at (eval 5) line 374.", for
> example.  I have looked all over CPAN for Manifest.pm, with no success. 
> Is there somewhere where I can get module Manifest.pm?  

It comes with Perl. You should be able to get a newer version than
5.003_07, too, so if you simply install Perl again, you should be fine.
Hope this helps!

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



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

Date: 13 May 1998 23:03:49 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Modules:  why doesn't this work?
Message-Id: <6jd8sl$d6k$5@comdyn.comdyn.com.au>

In article <erik-1305980710320001@pool029-max10.mpop2-ca-us.dialup.earthlink.net>, erik@earthlink.net (Erik Y. Adams) writes:

> So, how do I use a module that isn't in lib?

# perldoc perlfaq8
/How do I keep my own module/library directory?

use lib '/wherever/your/module/directory/is';

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.       | Gates?
NSW, Australia                      | 


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

Date: Wed, 13 May 1998 22:30:45 GMT
From: pkbk@badger.tds.net
Subject: Need discussion group script
Message-Id: <6jd6um$i6l$1@nnrp1.dejanews.com>

I'm trying to find a discussion group or message forum script similar to the
one in Matt's script archives or the WeBBS message board.  An example of the
kind of message forum I'm talking about is at http://www.mtdaily.com.

My web host is using a Windows NT inforamtion server, ISAPI and Perl5.

The discussion group is going to be used by people who have Factor V Leiden, a
blood clotting disorder and it's not connected with any medical facility.
It's just us patients who need to talk to each other for support.

Can anybody provide leads to someone who has the script we need or can you
direct me to where to look.  If there's anybody out there willing to donate
your service to setting this thing up, you'd make a whole lot of us patients
very happy.

Barb Krultz
pkbk@badger.tds.net



-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Wed, 13 May 1998 19:31:30 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: John Porter <jdporter@min.net>
Subject: Re: Nuclear bombing of NEW YORK! Small countries can target with nukes!
Message-Id: <355A2D52.755C@juicepigs.com>

John Porter wrote:
> 
> On Tue, 12 May 1998 17:28:57 -0500,
> in article <3558CD29.12CB@yahoo.com>,
> gdw@yahoo.com (gdw) wrote:

> > You are living, sleeping and walking on a planet which is a
> > LIVE ATOM BOMB and a HUGE BAR MAGNET!!
> 
> The LIVE ATOM BOMB part is spooky, but the HUGE BAR MAGNET part totally
> scares the sh*t out of me.  What can we do, who can we call?

Relax. If it wasn't for the "HUGE BAR MAGNET" all of our favorite bars
would be floating up into space.

-- 
Bob Trieger               |  Titanic: big boat, bigger
sowmaster@juicepigs.com   |           iceberg, big deal


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

Date: Wed, 13 May 1998 23:01:42 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Jennifer Verk <skydive@megsinet.net>
Subject: Re: Please help w/ form mailing
Message-Id: <Pine.GSO.3.96.980513160050.21974D-100000@user2.teleport.com>

On Wed, 13 May 1998, Jennifer Verk wrote:

> Subject: Please help w/ form mailing

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> I need to know how to add to this to have the logfile emailed. 
> 
> I think I know how to do it for a Unix machine....but I'm using WinNT
> IIS.  

There are some modules on CPAN which may be able to help you with this.
Good luck!

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



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

Date: Wed, 13 May 1998 18:34:01 -0500
From: "kll" <kliou@ichat.com>
Subject: program cannot run in CGI but in Perl on NT
Message-Id: <6jd5n1$jkl$1@nntp.smartdna.com>

I wrote a command line exe by VB.  It runs fine using system in Perl
(NT4.0).  However, if I run (using system) it in Perl/CGI, it just hangs.
Are there special requirements for programs to run in Perl/CGI?
Thanks.

Kan




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

Date: 13 May 1998 22:49:48 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Question: Finding which element of a list a string corilates to
Message-Id: <6jd82c$d6k$4@comdyn.comdyn.com.au>

In article <6jcdfb$33l@hplntx.hpl.hp.com>,
	"Larry Rosler" <lr@hpl.hp.com> writes:

> Is there an answer to this question better than the obvious and
> mundane -- count up a loop?

Maybe.. depending on how many times you have to look up an element. A
hash table, with the array indices as values might be more efficient,
but I'd have to benchmark that to be absolutely sure.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I think I think, therefore I think I
Commercial Dynamics Pty. Ltd.       | am.
NSW, Australia                      | 


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

Date: 13 May 1998 23:35:09 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Really Basic Questions
Message-Id: <6jdand$dj6$2@comdyn.comdyn.com.au>

In article <3559e033.176316655@news.ucdavis.edu>,
	phounsh@ucdavis.edu (Paul Hounshell) writes:
> I have an excellent Perl book (from what I can tell) but it leaves out

excellent? And you have to ask us this question? You might be well
served by having a look at
http://language.perl.com/info/documentation.html and
http://language.perl.com/critiques/index.html

> a couple of fundamental things.  I just need to know what the "not
> equal" comparison operator is, as well as binary And, Or, Not, XOr,
> NAND, and NOr.  Thank you,

Dump the book. Get a better one. Check the documentation that comes
with perl.

# perldoc perlop

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | You can't have everything, where would
Commercial Dynamics Pty. Ltd.       | you put it?
NSW, Australia                      | 


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

Date: Wed, 13 May 1998 22:16:16 GMT
From: "James M. Stern" <jstern@world.northgrum.com>
Subject: Re: Reg Expr convert one string to another
Message-Id: <355A1BB0.D990400C@world.northgrum.com>

Chilton wrote:
> 
> This is an easy one.

It should be.  In fact, if you can't solve this you don't know Perl and
you
are wasting your time if you continue to program without such
knowledge.  This is no flame, just well-meant advice.

I urge you to buy and read _Learning Perl_ ASAP if you plan to continue
using the language.  The Perl FAQ has ordering information.

Anyway, ...

> 
> I want to convert the following string:
> $string1 = "051098.txt";
> 
> into:
> 5/10/98

I'll show you this much.

> 
> and ultimately into:
> 5/10

This should then be obvious.

> 
> I could use a bunch of loops in perl, but I know there's a regular
> expression to do this simple thing.

<snip>
#!/usr/local/bin/perl -w
use strict;
my $string1 = "051098.txt";

# Capture month, day and year
my($m, $d, $y) = ($string1 =~ /(\d\d)(\d\d)(\d\d)/);
warn "Trouble\n" unless defined $y;

$m =~ s/^0//;    # Remove leading 0, if any
</snip>

Now, please get _Learning Perl_.

-- 
James M. Stern -- Views here are my own, not my employer's.  
(Hawthorne, CA)


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

Date: Wed, 13 May 1998 16:24:41 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reg Expr convert one string to another
Message-Id: <p23dj6.j37.ln@localhost>

Chilton (chilton@trag.com) wrote:
: This is an easy one.

: I want to convert the following string:
: $string1 = "051098.txt";

: into:
: 5/10/98

: and ultimately into:
: 5/10

: I could use a bunch of loops in perl, but I know there's a regular
: expression to do this simple thing.


   $string1 =~ s#^(\d\d)(\d\d)(\d\d).txt$#$1/$2/$3#;


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 13 May 1998 15:41:18 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: Regular Expression Question
Message-Id: <6jd7i2$b53@hplntx.hpl.hp.com>

Mike Stok wrote in message <6jcdf4$bpl@news-central.tiac.net>...
 ...
>One way to do it is
>
>  if ($line =~ /^(.*?\()/) {
>    # $1 contains line up to and including the first (
>  }
>
>which uses non-greedy matching, another is to say
>
>  if ($line =~ /^([^(]*\()/) {
>    ...
>  }
 ...
>The Benchmark module might be useful if you want to see how well
various
>methods work on typical data.


Without doing the Benchmarking, one can discard the first way relative
to the second.

As discussed in great detail in Friedl's masterly 'Mastering Regular
Expressions', when you know what character you are looking for to
terminate the match, you should be as specific as possible.  In the
first example, the 'non-greedy' pattern .*? eats up the entire string
(to the new-line, if any) because it matches the pattern.  Then it tries
to match the next pattern \( and reluctantly backtracks, giving up
characters all the way to the beginning, until it finds the *first* left
parenthesis (if any).  The second pattern [^(]* doesn't do any more work
than is needed.  It is much less greedy than the non-greedy .*) .

Note that only the second way is given in Tom Phoenix's response to this
thread.

*Every* use of .* should be viewed with suspicion, greedy or not.

--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com

PS:  Having written this learned analysis, I did what I should have done
in the first place -- measure it.  Here are the Benchmark results.  For
simplicity, I tested only strings with one parenthesis, in the extreme
positions.  Some of the results confirm expectations ('greedy', and the
general slowness of 'substr' -- but why not faster if the match comes
early?).  However, the primary point made above is *not* supported by
the data ('non-greedy' is competitive with 'not_paren').  HELP!!!  LR

#!/usr/local/bin/perl -w
use Benchmark;

$_ = '(' . 'x' x 1000;
$_ = 'x' x 1000 . '(';

timethese (400000, {
    'greedy'     => q{ ($foo) = /(.*)\(/ },
    'non-greedy' => q{ ($foo) = /(.*?)\(/ },
    'not_paren'  => q{ ($foo) = /^([^(]*)\(/ },
    'substr'     => q{ $foo = substr $_, 0, index $_, '(' },
} );
__END__

$_ = '(' . 'x' x 1000;
Benchmark: timing 400000 iterations of greedy, non-greedy, not_paren,
substr...
    greedy:  7 secs ( 3.45 usr  0.06 sys =  3.51 cpu) # Eats it all and
gives it back.
non-greedy:  3 secs ( 3.14 usr  0.02 sys =  3.16 cpu)
 not_paren:  3 secs ( 3.19 usr  0.02 sys =  3.21 cpu) # Succeeds
immediately.
    substr:  5 secs ( 4.78 usr  0.02 sys =  4.80 cpu) # Succeeds
immediately.

$_ = 'x' x 1000 . '(';
Benchmark: timing 400000 iterations of greedy, non-greedy, not_paren,
substr...
    greedy:  2 secs ( 3.06 usr  0.01 sys =  3.07 cpu) # Eats it all and
gives nothing back.
non-greedy:  3 secs ( 3.21 usr  0.03 sys =  3.24 cpu)
 not_paren:  3 secs ( 3.16 usr  0.01 sys =  3.17 cpu) # Succeeds at the
end.
    substr:  7 secs ( 4.80 usr  0.04 sys =  4.84 cpu) # Succeeds at the
end.




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

Date: Wed, 13 May 1998 22:58:01 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: michal <mwallace@abelsolutions.com>
Subject: Re: resolving IP addresses on WinNT
Message-Id: <Pine.GSO.3.96.980513155532.21974B-100000@user2.teleport.com>

On Wed, 13 May 1998, michal wrote:

> here's a fun little routine to resolve ip addresses on an
> NT system...
> 
> now that I've gone and done it, can someone tell me where
> I should have looked to begin with? :)

Maybe Net::DNS?

> sub resolve {
>     $ipaddress = shift;
>     open LOOKUP, "ping -a $ipaddress -n 1|";

Or maybe Net::Ping?

>     while (<LOOKUP>) { /Pinging (.*) (\[.*\]) / && print "$1 = $2" };
>     close LOOKUP;
>     $1;
> }

Of course, a host that you can't ping must not be any good, as everyone
who has tried pinging www.microsoft.com knows. :-) :-) :-)

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



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

Date: Wed, 13 May 1998 22:55:24 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "Bruce J. Downs" <downs.bj.1@pg.com>
Subject: Re: run against a list
Message-Id: <Pine.GSO.3.96.980513155316.21974A-100000@user2.teleport.com>

On Wed, 13 May 1998, Bruce J. Downs wrote:

> I have a perl program that I submit on my NT server and the script comes
> back with info about the server I submitted on.  What I want to do is
> submit the script, the script runs against a list of servers,

I do not know what "run against" means in this context. Do you mean that
it would be run on each of the servers in a list? Maybe you want LWP. Do
you mean that it would poll each server? Maybe you want Net::Ping. 

> on the network, that I have in a file somewhere else. A file that I can
> edit when needed, without touching the perl script.  Is their a way to
> do this? 

Almost certainly Perl can do this, unless you're asking something that's
impossible. :-)  Try asking again, though, if you're still not sure. Good
luck!

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



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

Date: 13 May 1998 22:41:54 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Stumped on opening file to print.
Message-Id: <6jd7ji$d6k$3@comdyn.comdyn.com.au>

In article <35550B03.3D01D834@purco.qc.ca>,
	Leon Stepanian <info@purco.qc.ca> writes:

> I have tried opening files which were in simple html format such as;
> <html> or in perl format such as print"<html>\n"; but in both ways, I am
> getting the code printed on the screen and not the actual html page.
> 
> Files were opened and stored in $array or @array format then printed
> with print<$file> or sequenced through a for($a=0;a<@file;$a++) to
> print"$file[$a]"; but again, I am only getting the actual code printed
> on the screen. Also tried print<@array> but again not good.

Instead of all this pseudo code, you should have posted a few _actual_
snippets of the code you were using. What you are typing here is too
ambiguous to be any help to us, so we can't be of nay help pointing
out what went wrong.

> So, here's the question. How can I use Perl to read in the html code of
> a file and have the html page appear through a Perl script, instead of
> having the print"<html>\n"; type code in my Perl sub-routines. These

This is really very basic, is mentioned in many pages of documentation
that comes with perl, and is mentioned in many articles to this
newsgroup. You really should have done some work yourself.

#
# Here goes the logic of which $file to open
#
open(HTML, $file) || die "Cannot open $file for read: $!";
print <HTML>;
close(HTML);

Of course you will still be responsible to output the right HTTP
headers, as any CGI script must do. You might want some other
behaviour instead of the die, but I'll leave that up to you.

In case you don't know how to get to perl's documentation:

# perldoc perl
# perldoc perldoc
# perldoc perlfunc
# perldoc -f open

[rereading some of your wonderfully confusing post]

> but again, I am only getting the actual code printed
> on the screen. Also tried print<@array> but again not good.

You're not trying to read and print files that have perl code in them,
are you? If you are, have a look at do and require

# perldoc -f do
# perldoc -f require

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I'm desperately trying to figure out
Commercial Dynamics Pty. Ltd.       | why kamikaze pilots wore helmets - Dave
NSW, Australia                      | Edison 


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

Date: Wed, 13 May 1998 23:00:26 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "John V. Martinez" <jvm@ciena.com>
Subject: Re: Trouble w/CPAN.pm and MD5 - catch22 errors!
Message-Id: <Pine.GSO.3.96.980513155905.21974C-100000@user2.teleport.com>

On Wed, 13 May 1998, John V. Martinez wrote:

> [Reader's Digest version: I installed MD5, it passed all the tests ok,
> but some other modules (most recently, Bundle::Tk ->
> GBARR/Mailtools-1.11.tar.gz) do not 'make' properly when I try to
> install them from the shell. They complain about being unable to find
> 'auto/MD5/new.al' anywhere in @INC; I can't find the file anywhere,
> although @INC looks right. So why did MD5 self-tests pass? What's
> missing?]

The test doesn't test the installed module, so a test may pass even though
the module can't be properly installed. That sounds like it may apply in
your case. Try re-installing MD5, and be sure not to skip any steps! :-)

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



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

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

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