[18636] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 804 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 30 18:12:55 2001

Date: Mon, 30 Apr 2001 15:10:15 -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: <988668615-v10-i804@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 30 Apr 2001     Volume: 10 Number: 804

Today's topics:
    Re: new to perl <tlav1@mediaone.net>
    Re: new to perl <miltonroad@btinternet.com>
    Re: newbie question <jasonh@colubs.com>
    Re: newbie question nobull@mail.com
    Re: one-line stderr, stdout redirection <dennis.kowalsk@daytonoh.ncr.com>
    Re: one-line stderr, stdout redirection (Logan Shaw)
    Re: Perl compete: Java is dead on server side!! PHP is  <john@art-ave.com>
    Re: pretty-printing perl? <ilya@math.ohio-state.edu>
    Re: re-sizing GIF images on the fly <graham@letsgouk.com>
    Re: re-sizing GIF images on the fly <graham@letsgouk.com>
    Re: re-sizing GIF images on the fly <graham@letsgouk.com>
    Re: re-sizing GIF images on the fly <godzilla@stomp.stomp.tokyo>
    Re: re-sizing GIF images on the fly <mischief@velma.motion.net>
    Re: RegEx optimization assistance (Anno Siegel)
    Re: RegEx optimization assistance <uri@sysarch.com>
    Re: RegEx optimization assistance (Rudolf Polzer)
    Re: RegEx optimization assistance (Craig Berry)
    Re: RegEx optimization assistance (Anno Siegel)
    Re: RegExp Teaser (Greg Bacon)
    Re: RegExp Teaser <ren@tivoli.com>
    Re: Regular expression for zip code (Craig Berry)
    Re: Regular expression for zip code (Craig Berry)
    Re: Regular expression for zip code <uri@sysarch.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 30 Apr 2001 21:31:59 GMT
From: ted <tlav1@mediaone.net>
Subject: Re: new to perl
Message-Id: <3AEE04DD.D6F6D3DE@mediaone.net>

_Learning Perl_ by Randal Schwartz, et. al. is a very good place to start.  It
helps if you have some degree of technical knowledge beforehand, though.  And
http://www.perl.com is also another good starting point.

ted



hanton32@hotmail.com wrote:

> I would like to start learning Perl. Specifically for loading (flat files) and
> unloading from databases (ie. Oracle). can someone recommend a book or site
> where I can start. Is perl DBI the way to go or ????
>
> thanks and any help appreciated
>
>  -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
>   http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
>    NewsOne.Net prohibits users from posting spam.  If this or other posts
> made through NewsOne.Net violate posting guidelines, email abuse@newsone.net



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

Date: Mon, 30 Apr 2001 23:03:25 +0100
From: Milton Road <miltonroad@btinternet.com>
Subject: Re: new to perl
Message-Id: <KilH6.150055$HR6.16935427@nnrp4.clara.net>

> I would like to start learning Perl. Specifically for loading (flat files)
> and unloading from databases (ie. Oracle). can someone recommend a book or
> site where I can start. Is perl DBI the way to go or ????

Depends really.  If Oracle is your only DB then its SQLLOADER program is 
quite fast for inserts.

If your original text files aren't SQL statements ( likely ) then Perl's 
text-handling proficiency will enable you to create the required INSERT 
statements easily.

If you're going to be accessing other DBMSes, you probably want to use the 
Perl DBI, which will enable you to use common SQL to access numerous 
databases.

Book recommendations :-
  Learning Perl ( a tutorial on Perl )
  Programming Perl ( a rather comprehensive book on Perl )
  Programming the Perl DBI ( specifically for the DBI stuff )

All of the books are published by O'Reilly.  Programming Perl is actually 
quite a funny read too, although I am not aware of any plans to turn it 
into a romantic comedy.

I'd also advocate reading the documentation that comes with your Perl 
installation.  In general, the documentation is excellent and ( hurrah! ) 
isn't afraid to use personal pronouns.  Come to that neither are the books.

Milton

 
> thanks and any help appreciated
> 
>  -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web 
>  -----
>   http://newsone.net/ -- Free reading and anonymous posting to 60,000+
>   groups
>    NewsOne.Net prohibits users from posting spam.  If this or other posts
> made through NewsOne.Net violate posting guidelines, email
> abuse@newsone.net




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

Date: Mon, 30 Apr 2001 11:25:39 -0700
From: "Jason Hurst" <jasonh@colubs.com>
Subject: Re: newbie question
Message-Id: <3aedae1a$0$144@wodc7nh1.news.uu.net>

"cjam" <webdaddy@delete.operamail.com> wrote in message
news:zqeH6.7467$wO6.1310116@news2-win.server.ntlworld.com...
> Hi, this hopefully isn't too stupid of a question......
>
> I have a guestbook script i got from elsewhere. On my website it works
> perfectly in the given cgi-bin.
> My question is:
> I'm running Windows2k with IIS5.0 webserver and want to run my scripts on
> http://localhost.
> What do i need to do to make a cgi-bin??
> I have set the paths correctly in the perl script to point to my test
> cgi-bin (on the path of localhost)
> and I've set the permissions on it to be ReadWriteExecute for both the
> folder and in the IIS properties....
> when i try to click on that script from a browser, it justs asks me
whether
> I want to save or open it. (in an editor)
> ...By the way, I do have Perl installed!
>
> What else do i need to do??
> thanks,
> cjam
>
>

In iis you have to set up the .pl extension as well.  its on the properties
tab of your cgi-bin directory, then configure. Note that if your using the
perl executable you need a few extra parameters.  It should look like this:
"c:\perl\bin\perl.exe %s %s"  if your using perlis then you don't want to
put the "%s" on there.

And i THINK that activestate's version of perl will configure iis for your
automatically when you install it... but i can't remember.




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

Date: 30 Apr 2001 19:11:00 +0100
From: nobull@mail.com
Subject: Re: newbie question
Message-Id: <u9n18yz2a3.fsf@wcl-l.bham.ac.uk>

"cjam" <webdaddy@delete.operamail.com> writes:

> Subject: newbie question
> Hi, this hopefully isn't too stupid of a question......

Dunno, about the question but the subject line sure is.  It consists
entirely of words that should not be used in subject lines.

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

Try this thought experiment.  Imagine you were looking for the answer
to your question using a Usenet search engine.  (I realise that it is
possible that you may be too lazy/selfish/ignorant/stupid, but even if
this is the case, just for the sake of the experiment let's pretend
that you are not).

Now imagine that your search found a thread with the subject line
you've used.  Would you stand a fair chance of being able to recognise
that the thread was on the same subject?

Clearly the answer is "no".  This means your subject line is not good
enough.

> I'm running Windows2k with IIS5.0 webserver and want to run my scripts on
> http://localhost.
> What do i need to do to make a cgi-bin??

This is a question about IIS configuration.  It is in no way related
to Perl.  It should be fairly clear that the answer does not depend on
the language that you use to write scripts.  (OK, to be fair there is
a slight dependance on language, when you get the the point when you
enter the script interpreter path you enter the path to PERL.EXE).

This is a newsgroup for discussing things that are in some way related
to Perl.  Please take your question to a newsgroup where configuration
of IIS is discussed.  For example:
comp.infosystems.www.servers.ms-windows

Note: In my experience it is more common to configure IIS to recognise
executable file types by extension rather than by putting them in
special directory, but like I say this is off-topic here.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 30 Apr 2001 16:39:30 -0400
From: "Dennis Kowalski" <dennis.kowalsk@daytonoh.ncr.com>
Subject: Re: one-line stderr, stdout redirection
Message-Id: <3aedcd80$1@rpc1284.daytonoh.ncr.com>

Try this

open(LOG,">$filename");
*STDERR = *LOG;

Gerald Shuman <nospam@newsranger.com> wrote in message
news:BrgH6.4149$SZ5.335582@www.newsranger.com...
> What's the perl equivalent of "exec 2> stderr.txt" in a shell script?
>
>




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

Date: 30 Apr 2001 16:50:15 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: one-line stderr, stdout redirection
Message-Id: <9ckmmn$6kr$1@flask.cs.utexas.edu>

In article <m1g0eqb9t1.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Gerald" == Gerald Shuman <nospam@newsranger.com> writes:
>
>Gerald> What's the perl equivalent of "exec 2> stderr.txt" in a shell script?
>
>open STDERR, ">stderr.txt" or die "Cannot reopen STDERR: $!";

Just out of curiousity, does this reuse file numbers?  I.e. does it
cause STDERR to be associated with file #2 and file #2 to be opened to
stderr.txt?  Or does it potentially (say) file #7, open that to
stderr.txt and re-associate STDERR with file #7 instead of #2?

The reason this matters is if somebody does this:

	system ("echo abcdef 1>&2");

If the former, the output will go to stderr.txt, but if the latter,
it'll go to file #2, which may be something else.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Mon, 30 Apr 2001 16:14:38 -0400
From: "JohnB" <john@art-ave.com>
Subject: Re: Perl compete: Java is dead on server side!! PHP is 4 times faster than JSP,CF,ASP!!
Message-Id: <9vjH6.5513$R2.3707179@newsrump.sjc.telocity.net>

CNN says the CDC announced an outbreak of ASS es
Please do your part and turn this one in dead or alive!

BTW,  your wrong.

Al Dev <alavoor@yahoo.com> wrote in message
news:3AE989C9.15E45560@yahoo.com...
> Perl competetion: Java is dead on server side!! PHP is 4 times faster
> than JSP,CF,ASP!!
>
> PHP is born from "Perl + Java" and is the fastest growing language in
> the world!!
> PHP is object oriented. Analogy is perl is "C" and PHP is "C++" !!
>
> PHP is the fastest web-scripting language and is 4 times faster than
> JSP(Java
> Server Pages). PHP is becoming new "Java language", it is getting all
> the Java
> keywords like class, extends, implements, interface, inner classes etc..
>
> What is the purpose of java on server side programming if PHP is
> java-like
> and is 4 times faster???
>
> The benchmark says PHP is faster than ASP and ASP faster than
> ColdFusion..
> The order is : PHP > ASP > CF > JSP
> The JSP is the worst!! It is the slowest of all technology!!
>
> Read the benchmarks in "PHP howto" given at
>   http://aldev.8m.com
> and due to heavy traffic go to mirror sites at
>   http://aldev.webjump.com
>   http://www.angelfire.com/nv/aldev
>   http://www.geocities.com/alavoor/index.html
>   http://aldev.virtualave.net
>   http://aldev.bizland.com
>   http://members.theglobe.com/aldev/index.html
>   http://members.nbci.com/alavoor
>   http://aldev.terrashare.com
>   http://members.fortunecity.com/aldev
>   http://aldev.freewebsites.com
>   http://members.tripod.lycos.com/aldev
>   http://members.spree.com/technology/aldev
>   http://www3.bcity.com/aldev
>
> Go to one of these sites and click on PHP howto.
>




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

Date: 30 Apr 2001 21:29:27 GMT
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: pretty-printing perl?
Message-Id: <9cklfn$t5d$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Rudolf Polzer
<eins@durchnull.de>], who wrote in article <slrn9eqak8.nd5.eins@www42.t-offline.de>:
> > >    perldoc -q pretty-printer
> > > 
> > >       "Is there a pretty-printer (formatter) for Perl?"
> > 
> > Is there any reason to trust the Perl FAQ?
> > 
> > No.
> > 
> > See the menu in cperl-mode.
> 
> You will have to undo some changes, however. Only perl can parse Perl.
> 
> Try (I did not check it): This should confuse your formatter.

LOL!  And you should stop beating your grandchilds.  (I did not check it.)

Ilya


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

Date: Mon, 30 Apr 2001 19:39:05 +0100
From: Graham Stow <graham@letsgouk.com>
Subject: Re: re-sizing GIF images on the fly
Message-Id: <Zl2w4IAJFb76EwYp@letsgouk.com>

>> Now what's dumb about that?
>
>Because you're requiring the browser to download the full-size image and
>then rescale it down (something, BTW, the browsers tend to do an
>esthetically *ugly* job of).  You're simply shifting effort; you've made
>your job as a designer easier by making your users go to extra effort
>(consider an image gallery of 20 downloadable images, each of which is 50K
>full size.  If you dumbnail the images, the user has to download the full
>meg worth of images just to see all the thumbnails.  That means he has to
>wait several minutes before he can see all the thumbnails, and once again,
>the thumbnails will be ugly and distorted).

Whoops. Sorry. Not thinking straight.

This seems to leave only one option - have my ISP install ImageMagick
(assuming they'll play ball) then use the Image::Magic module to
properly re-size the GIF and store the resultant thumbnail (as opposed
to "dumbnail") on the server.

Could somebody confirm?
-- 
Graham Stow


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

Date: Mon, 30 Apr 2001 19:43:46 +0100
From: Graham Stow <graham@letsgouk.com>
Subject: Re: re-sizing GIF images on the fly
Message-Id: <SVMyUWAiJb76Ewb8@letsgouk.com>

>However, if you really do want to do this, you may not even need
>to know the image size. I am fairly sure that most browsers, if you
>specify just the height or width tag, will automatically resize and
>keep the proper aspect ratio. So you could just use:
>
>print "<IMG SRC=\"$imagefile\" HEIGHT=\"$height\"
>HSPACE=10 BORDER=0 ALIGN=\"RIGHT\" ALT=\"Thumb\">\n";
>
>Give it a try.
>
>cheers,
>
>-*-
>Charles M. Kozierok (mailto:ixl@PCGuide.com)

Thanks Charles, but Eric & Randal are very anti-this and I quite see
their point. Guess its ImageMagick and the Image::Magick module, or
nothing.
-- 
Graham Stow


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

Date: Mon, 30 Apr 2001 19:45:35 +0100
From: Graham Stow <graham@letsgouk.com>
Subject: Re: re-sizing GIF images on the fly
Message-Id: <dF3xggAPLb76Ewa4@letsgouk.com>

>
>Graham> use Image::Size;
>Graham> ($x, $y) = imgsize ("$imagefile");
>Graham> $standardheight=80;     # all thumbnails to be rendered 80 pixels high
>Graham> $height=$standardheight;
>Graham> $width=$standardheight*($x/$y);
>Graham> print "<IMG SRC=\"$imagefile\" WIDTH=\"$width\" HEIGHT=\"$height\"
>Graham> HSPACE=10 BORDER=0 ALIGN=\"RIGHT\" ALT=\"Thumb\">\n";
>
>That's not a thumbnail.  That's a "dumbnail".  Please don't do that.
>
OK. Got the message. Won't do it.
-- 
Graham Stow


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

Date: Mon, 30 Apr 2001 12:25:26 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: re-sizing GIF images on the fly
Message-Id: <3AEDBC26.F93F6197@stomp.stomp.tokyo>

Graham Stow wrote:

(various attributes snipped by others and not noted)
 
> >> Now what's dumb about that?

(snipped)

(regarding full file size thumbnails)

> > Because you're requiring the browser to download the full-size image 
> > and then rescale it down....


> Whoops. Sorry. Not thinking straight.
 
> This seems to leave only one option - have my ISP install ImageMagick
> (assuming they'll play ball) then use the Image::Magic module to
> properly re-size the GIF and store the resultant thumbnail (as opposed
> to "dumbnail") on the server.
 
> Could somebody confirm?


I can confirm you have a superior option
available; do it right.

Thumbnails most often appear to be smudged
postage stamps which are near impossible to
view. This is very annoying and a reflection
of lack of pride which serves as a strong hint
the remainder of a site is of poor quality.

Pride will motivate you to create thumbnails
by hand, by eye, using a graphics program.
This only requires a little time and effort.
Those who take pride in their sites will select
a portion of a larger picture to create a
thumbnail which is actually viewable, without
a magnifying glass.


  _____________
  |           |
  | A         | 
  |  _______  |
  |  |     |  |
  |  |  B  |  |
  |  |_____|  |
  |           |
  |           |
  |___________|


Crop your graphic down to main content,
as shown by B in my example diagram,
then create a high quality thumbnail
using that area or appropriate area.
This is quality, this is the right
way to do it.

Godzilla!


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

Date: Mon, 30 Apr 2001 20:04:09 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: re-sizing GIF images on the fly
Message-Id: <terh9p131c662d@corp.supernews.com>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Graham Stow wrote:

> (various attributes snipped by others and not noted)
>  
>> >> Now what's dumb about that?

> (snipped)

> (regarding full file size thumbnails)

>> > Because you're requiring the browser to download the full-size image 
>> > and then rescale it down....

[snip some detail about doing the following by hand]

>   _____________
>   |           |
>   | A         | 
>   |  _______  |
>   |  |     |  |
>   |  |  B  |  |
>   |  |_____|  |
>   |           |
>   |           |
>   |___________|


> Crop your graphic down to main content,
> as shown by B in my example diagram,
> then create a high quality thumbnail
> using that area or appropriate area.
> This is quality, this is the right
> way to do it.

For many cases, I agree that what Kira says here is the absolute best
way to handle thumbnails. If you must have a smaller version of the
whole picture, that's another story. However, Kira's point about
making a presentable portion of the picture full aspect but cropped
is a good one. Now, if only we can figure out a good way to figure
the crop programmatically, in Perl of course. This would be much
more difficult than what the OP in this thread is asking.

Chris

P.S. Did I just agree with Godzilla! for once? Yes, I did.
     Deal with it. :-)

-- 
Get real!  This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental. -- nobull, clp.misc



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

Date: 30 Apr 2001 18:29:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegEx optimization assistance
Message-Id: <9ckav7$r76$2@mamenchi.zrz.TU-Berlin.DE>

According to Andrew <andrew@mvt.ie>:
> 
> "Drew" <nospam@newsranger.com> wrote in message
 
> It looks from the data originally provided that it may have been tab
> delimited, rather than space delimited.
> 
> Trying this might work;
> 
> my @keys = split /\t|\s+/;
> @stats{ @keys } = split /\t|\s+/, <DATA>;

\t is one of the characters matched by \s, so /\t|\s+/ matches exactly
what /\s+/ does.

Anno


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

Date: Mon, 30 Apr 2001 18:42:17 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: RegEx optimization assistance
Message-Id: <x766fmfcv9.fsf@home.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> According to Andrew <andrew@mvt.ie>:
  >> 
  >> "Drew" <nospam@newsranger.com> wrote in message
 
  >> It looks from the data originally provided that it may have been tab
  >> delimited, rather than space delimited.
  >> 
  >> Trying this might work;
  >> 
  >> my @keys = split /\t|\s+/;
  >> @stats{ @keys } = split /\t|\s+/, <DATA>;

  AS> \t is one of the characters matched by \s, so /\t|\s+/ matches exactly
  AS> what /\s+/ does.

well, not exactly, if it sees a "\t\t" it will split them whereas it
won't split "\n \n"

if the alternations were in the other order, then the \s+ would always
work and \t would never be tried.

i dunno how this affects the OP since i haven't followed the thread
closely.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Mon, 30 Apr 2001 20:39:55 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: RegEx optimization assistance
Message-Id: <slrn9ercbq.156.eins@www42.t-offline.de>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to Andrew <andrew@mvt.ie>:
> > 
> > "Drew" <nospam@newsranger.com> wrote in message
>  
> > It looks from the data originally provided that it may have been tab
> > delimited, rather than space delimited.
> > 
> > Trying this might work;
> > 
> > my @keys = split /\t|\s+/;
> > @stats{ @keys } = split /\t|\s+/, <DATA>;
> 
> \t is one of the characters matched by \s, so /\t|\s+/ matches exactly
> what /\s+/ does.

Not exactly.

split (/\s+/,    "a\t b  \t  c") == ('a',     'b', 'c')
split (/\t|\s+/, "a\t b  \t  c") == ('a', '', 'b', 'c')

But I do not think the latter one is what Andrew wanted, so you did not
save bytes, you fixed a (probably not severe) bug.

-- 
#!/usr/bin/perl -W -- WARNING: This will print 22,307 bytes! <strictsafe!>
use strict;for(my$y=-1;$y<1;$y+=.1){for(my$x=-1.9;$x<.4;$x+=.03){print'+';
my$X=my$Y=0;for(0..99){($X,$Y)=($X*$X-$Y*$Y+$x,2*$X*$Y+$y);print"\b "if$X*
$X+$Y*$Y>9;}}print"\n"};print''.reverse"\nHPAJ \a!rezloP .R yb torblednaM"


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

Date: Mon, 30 Apr 2001 19:45:37 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: RegEx optimization assistance
Message-Id: <terg718tcsg414@corp.supernews.com>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: \t is one of the characters matched by \s, so /\t|\s+/ matches exactly
: what /\s+/ does.

They will both succeed in matching on the same strings, but what is
matched will differ.  Specifically, a single initial \t will terminate the
match, but any other initial whitespace character will match the entire
consecutive string of whitespace characters.  Note that + binds more
tightly than |.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: 30 Apr 2001 20:04:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegEx optimization assistance
Message-Id: <9ckggr$2t6$2@mamenchi.zrz.TU-Berlin.DE>

According to Craig Berry <cberry@cinenet.net>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
> : \t is one of the characters matched by \s, so /\t|\s+/ matches exactly
> : what /\s+/ does.
> 
> They will both succeed in matching on the same strings, but what is
> matched will differ.  Specifically, a single initial \t will terminate the
> match, but any other initial whitespace character will match the entire
> consecutive string of whitespace characters.  Note that + binds more
> tightly than |.

Quite.  I decided not to mention that, but then ignored the "+"
altogether.  Thanks to all who caught that.

Anno


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

Date: Mon, 30 Apr 2001 19:13:15 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: RegExp Teaser
Message-Id: <tereabj54ophee@corp.supernews.com>

In article <9ck8ul$ic2$1@plutonium.btinternet.com>,
    S Warhurst <bigusAT@btinternetDOT.com> wrote:

: You regulars must be getting fed up of regular expression questions.
: [...]

I like the regular expression questions, but I'm also interested in the
broader field of formal languages.

: I have a text file containing the following kind of text (a listserv catalog
: file in case anyone recognises it):
: 
: * preamble
: *
: * more preamble
: *
: -#-file1.txt
: * File 1 description
: -#-file2.htm
: * File 2 description
: * some file descriptions have more than one line
: -#-file3.xls
: * File 3 description-#-
: 
: Now, I converted the array holding the file contents into a scalar & added
: the "-#-" in order to make the regexp easier. Here is the one I came up
: with:
: 
: $tmp = $filecontents = ~ /-#-.+-#-/sg

Why aren't you using split?

    % cat try
    #! /usr/local/bin/perl -w

    use strict;

    $/ = undef;

    my $data = <DATA>;
    $data =~ s/^.*?-#-//s;

    for (split /-#-/, $data) {
        next unless /\S/;
        $_ .= "\n" unless /\n\z/;
        print "CHUNK:\n$_";
    }

    __DATA__
    * preamble
    *
    * more preamble
    *
    -#-file1.txt
    * File 1 description
    -#-file2.htm
    * File 2 description
    * some file descriptions have more than one line
    -#-file3.xls
    * File 3 description-#-
    % ./try
    CHUNK:
    file1.txt
    * File 1 description
    CHUNK:
    file2.htm
    * File 2 description
    * some file descriptions have more than one line
    CHUNK:
    file3.xls
    * File 3 description

Hope this helps,
Greg
-- 
WARNING! In the considerations of safety, you should NEVER let a male
dolphin attempt anal sex with you. 
    -- http://www.dolphinsex.org/


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

Date: 30 Apr 2001 13:41:59 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: RegExp Teaser
Message-Id: <m3y9sinsaw.fsf@dhcp9-172.support.tivoli.com>

On Mon, 30 Apr 2001, bigusAT@btinternetDOT.com wrote:

> I have a text file containing the following kind of text (a listserv
> catalog file in case anyone recognises it):

[Data moved to __DATA__ below...]

Is that last "-#-" at the end of the line special in some way?  Is it
only there on the last file description?

> Now, I converted the array holding the file contents into a scalar &
> added the "-#-" in order to make the regexp easier. Here is the one
> I came up with:

Ah... maybe you added the "-#-" on the end.  Or maybe all of them?

> $tmp = $filecontents = ~ /-#-.+-#-/sg

Aside from the typo "= ~", a global match in a scalar context is going
to return the number of matches, which doesn't seem like it's going to
be that useful.

> Now that works to a point, but what it returns (I'm going by memory
> here, but I think you will get the point) is:

Ah... "going by memory".  It's usually much more useful if you post
the actual code that you are using.

> -#-file1.txt * File 1 description -#-
> -#-file3.xls * File 3 description -#-

Right, you're missing the second file because you are matching the
"-#-" as part of the first hit and it isn't there to match the second.

> What it's doing is it's including the ending "-#-" delimiter
> thingy. How can I get it not to include the end "-#-".. (the
> character before that could be any character).

Well, a simple way would be: "(?=-#-)" which would match if "-#-"
comes next, without actually matching the "-#-".

Here's my quick-and-dirty solution:

#!/usr/bin/perl
use warnings;                  
use strict; 
my %desc;    
my $filename;  
while(<DATA>) {                 
  /^-#-(.*)/ and $filename = $1;                
  /^\*/ && $filename and $desc{$filename} .= $_;
}                                               
for (keys %desc) {     
  print "$_:$desc{$_}";
}                      
__DATA__               
* preamble
*
* more preamble
*
-#-file1.txt
* File 1 description
-#-file2.htm
* File 2 description
* some file descriptions have more than one line
-#-file3.xls
* File 3 description-#-
__END__

Even better would probably be to set $/ = "\n-#-".

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 30 Apr 2001 20:20:52 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regular expression for zip code
Message-Id: <teri941ptems96@corp.supernews.com>

xris (xris@dont.send.spam) wrote:
: and on a side note, isn't the 'o' operator supposed to speed things up a 
: bit because it compiles the pattern once rather than every time? I 
: haven't noticed ANY change in speed when doing benchmarks, no matter how 
: complex the pattern is.

/o only makes a difference if the pattern contains interpolated variables,
like

  $foo = 'abc';

  while (<>) {
    @matches = /prefix\s$foo\ssuffix/go;
    ...
  }

In the absence of /o, the regex engine assumes that the variable may have
changed from iteration to iteration, so reinterpolates and recompiles the
regex on each iteration.  /o is how you tell the regex engine that the
interpolation and compilation should be done just once, saving time on
future iterations.  Of course, if $foo gets changed in the loop, the /o
means that the regex pattern will not change to use the new value.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Mon, 30 Apr 2001 20:23:03 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regular expression for zip code
Message-Id: <terid744hfqic1@corp.supernews.com>

xris (xris@dont.send.spam) wrote:
: ah, ok...  the wording in the Perl book made me think that the 
: compiler/optimizer did something special to regex patterns besides just 
: interpreting variables, such that all patterns could benefit from this 
: option.

If all patterns could benefit, they'd probably just make it part of the
regex engine.

: guess it's good to know it doesn't, though I'd hope it wouldn't 
: hurt to include the 'o' anyway...

It has effectively no impact on static patterns.  For dynamic patterns,
using /o improperly can result in the patterns not being dynamic enough,
or conceivably being too dynamic. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Mon, 30 Apr 2001 21:24:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regular expression for zip code
Message-Id: <x73daqf5d2.fsf@home.sysarch.com>

>>>>> "CB" == Craig Berry <cberry@cinenet.net> writes:

  CB> In the absence of /o, the regex engine assumes that the variable may have
  CB> changed from iteration to iteration, so reinterpolates and recompiles the
  CB> regex on each iteration.  /o is how you tell the regex engine that the
  CB> interpolation and compilation should be done just once, saving time on
  CB> future iterations.  Of course, if $foo gets changed in the loop, the /o
  CB> means that the regex pattern will not change to use the new value.

the regex is recompiled only if any of its interpolated variables have
changed since it last was compile. this is why /o is so rarely needed
anymore (along with qr// which gives the program control over regex
compilation).

the only time /o makes a difference now is if you have a regex and you
want it to compile only the first time and not again even if the vars
have changed. it is not easy to come up with many uses for /o that
aren't better solved with qr// or the normal way regexes are compiled.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 804
**************************************


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