[16126] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3538 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 2 18:05:42 2000

Date: Sun, 2 Jul 2000 15:05:18 -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: <962575518-v9-i3538@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 2 Jul 2000     Volume: 9 Number: 3538

Today's topics:
    Re: $query->checkbox_group : Can't modify negate in sca <abuse@localhost>
    Re: ***Do not use this code!*** Re: Perl Help Please! (Bart Lateur)
        ActiveState Perl installation probs. <m@daggins.com>
        bit strings for perms (Neil Kandalgaonkar)
    Re: Can get perl to open doc, but how do I get it to op (Tad McClellan)
    Re: Can get perl to open doc, but how do I get it to op <star@sonic.net>
    Re: change in precedence from 5.00503 -> 5.6.0 ? <gellyfish@gellyfish.com>
    Re: comparison question <gellyfish@gellyfish.com>
    Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Bart Lateur)
        Decimal to Hexadecimal (was: Perl) (Neil Kandalgaonkar)
        delete array (Clemens Hermann)
    Re: delete array <jfisher@epotec.com>
    Re: delete array (Tad McClellan)
    Re: delete array (Malcolm Dew-Jones)
    Re: Examine A Standart Logfile <gellyfish@gellyfish.com>
        finding, checking, replacing <ab@cd.com>
    Re: finding, checking, replacing (Tad McClellan)
    Re: Fun with typos. <iltzu@sci.invalid>
    Re: Fun with typos. <y-o-y@home.com>
    Re: Help: regex for changing NON-absolute urls in a htm <gellyfish@gellyfish.com>
    Re: how to get text enclosed by matching () ? <ronr@my-deja.com>
    Re: how to get text enclosed by matching () ? <ronr@my-deja.com>
    Re: how to get text enclosed by matching () ? <ronr@my-deja.com>
    Re: Interchage the role of key and value in a hash <tina@streetmail.com>
    Re: Newbie question: Sorting a list-of-hashes <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 3 Jul 2000 03:27:53 +0800
From: "multiplexor" <abuse@localhost>
Subject: Re: $query->checkbox_group : Can't modify negate in scalar assignment
Message-Id: <8jo4l8$3mp1@imsp212.netvigator.com>

"Mike Stok" <mike@stok.co.uk>
> In article <8jnnhm$k881@imsp212.netvigator.com>, "multiplexor"
> <abuse@localhost> wrote:
> > Code:
> > ###
> > use strict;  use CGI; my $query = new CGI;
> >
> > print $query->checkbox_group(-name=>'group_name',
> >  -values=>['eenie','meenie','minie','moe'],
> >  -rows=2,-columns=>2);
>
> should the -rows = 2 really be -rows => 2 ?
>
> Hope this helps,
>
> Mike
>

Opps.. I should have noticed that, but perhaps I am sleep... ZZZzzzz.....
Thanks..





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

Date: Sun, 02 Jul 2000 21:01:20 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: ***Do not use this code!*** Re: Perl Help Please!
Message-Id: <3963ac16.1771770@news.skynet.be>

Magic wrote:

>	c) I was stupid enough to assume people actually knew the answer
>and would not attempt to get me to erase my web space.
>
>Evidentally I was wrong. Sorry to have bothered you.

Hackers are anonymous. Holes like this in your code allow hackers to
destroy data on your computer. Some weird people actually enjoy
searching for such holes, and destroy your data. It's vandalism. It's
not our fault. But you better be prepared for them.

Just look up in Dejanews, the discussion here around New Year, with some
Alaskan electrician, I think his name was Gerald something, which people
in this newsgroup warned against using the BBS code from Matt's Script
Archive, because it had such holes in it big enough to let a whale swim
through. He didn't want to believe it. A week later, his BBS was
destroyed. Apparently, some cracker had picked up his URL, maybe even in
this newsgroup, and knew the vulnerabilities of Matt's code. Bang: a few
years of BBS postings all gone.

Gerald even accused us of having done it. Of course we didn't. Stuff
like this is always done by anonymous gits, with silly nicknames like
"Magic". These don't post here, or they wouldn't be anonymous any more.

-- 
	Bart.


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

Date: Sun, 2 Jul 2000 21:53:29 +0100
From: "daggins" <m@daggins.com>
Subject: ActiveState Perl installation probs.
Message-Id: <8joa3i$epn$1@lyonesse.netcom.net.uk>

I only get it with the 611 and 613 releases and i've tried on fresh installs
of both 98SE and W2K. The message i get is the following.
module C:\Perl\bin\PerlMSG.dll failed to register
HRESULT -2147023739

I'm pretty sure i've had it installed before without the problem (611 for
sure) but now i cannot install it no matter what i try.
Any ideas ?

m@





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

Date: Sun, 02 Jul 2000 20:50:02 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: bit strings for perms
Message-Id: <8jo9h9$33a$1@localhost.localdomain>


Slightly neat trick with bit strings. Let's say you can't keep the
octal perms straight in your head, but you are used to the ls -l
output:

-rwxrw-r--    some_file

chmod 0b_111_110_100 => "some_file";    # perl 5.6

I know I could have used this when I was learning perms. Of course
we already have Jeff Pinyan's File::chmod, so this is not so useful.

-- 
Neil Kandalgaonkar <neil@brevity.org>


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

Date: Sun, 2 Jul 2000 13:55:05 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Can get perl to open doc, but how do I get it to open html on  thefly?
Message-Id: <slrn8lv0fp.amr.tadmc@magna.metronet.com>

[ Please do not quote 70 lines to add 2 lines of comment.

  Quote only enough to establish the context for your comment.

  Thanks.
]

On Sun, 02 Jul 2000 17:05:50 GMT, arthur <star@sonic.net> wrote:
>in article slrn8ltb8m.8u0.tadmc@magna.metronet.com, Tad McClellan at
>tadmc@metronet.com wrote on 7/1/00 6:46 PM:
>
>> 
>> [ Please put your comments *following* the quoted text that you
>> are commenting on.


Thanks for taking that last suggestion too.


>> 'perldoc' is a program for looking up stuff in the standard
>> docs that you got along with perl.


>Thanks for the help I just spent 2 hours and could not find perldoc. 


It *comes with* perl.

You _do_ have perl, don't you?

If you have a properly installed perl, then perldoc is also installed.

If you do not have a properly installed perl, get a properly
installed perl  :-)


>I even
>telneted to my server. 


Did perldoc work there?

You don't need to involve a server just to read the standard
Perl docs.

They come with perl, and perl is free. Get and install perl on
your local computer and become document self-sufficient  :-)


> Where can I get them in http form?
                          ^^^^^^^^^

Eh? What is that? Maybe you meant HTML?



If, for some reason, you cannot get perldoc to work, then
you must find some other way of doing the searching.

The docs and FAQs can be found at www.perl.com by clicking
on the appropriate ("DOCUMENTATION" and "FAQs") links there.


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


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

Date: Sun, 02 Jul 2000 20:20:49 GMT
From: arthur <star@sonic.net>
Subject: Re: Can get perl to open doc, but how do I get it to open html on thefly?
Message-Id: <B58448ED.2A57%star@sonic.net>

in article slrn8lv0fp.amr.tadmc@magna.metronet.com, Tad McClellan at
tadmc@metronet.com wrote on 7/2/00 9:55 AM:
>> 'perldoc' is a program for looking up stuff in the standard
>> docs that you got along with perl.


>Thanks for the help I just spent 2 hours and could not find perldoc.


It *comes with* perl.

You _do_ have perl, don't you?

Right now I have MacPerl because I am on a Mac. But I want to ftp my perl
script on to my server and run it from there. Otherwise I think? I will have
to convert the macPerl to Perl so it will work on the WWW

If you have a properly installed perl, then perldoc is also installed.

If you do not have a properly installed perl, get a properly
installed perl  :-)


>I even
>telneted to my server.


Did perldoc work there?

I could not get them but I am no expert on using telnet

You don't need to involve a server just to read the standard
Perl docs.

They come with perl, and perl is free. Get and install perl on
your local computer and become document self-sufficient  :-)

Man if only it were so easy! I am almost there I hope.

> Where can I get them in http form?
                          ^^^^^^^^^

Eh? What is that? Maybe you meant HTML?

Correct, sorry about that -yes HTML


If, for some reason, you cannot get perldoc to work, then
you must find some other way of doing the searching.

The docs and FAQs can be found at www.perl.com by clicking
on the appropriate ("DOCUMENTATION" and "FAQs") links there.
Thanks,
~arthur


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



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

Date: 2 Jul 2000 23:19:33 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: change in precedence from 5.00503 -> 5.6.0 ?
Message-Id: <8jof5l$u1h$1@orpheus.gellyfish.com>

On Fri, 30 Jun 2000 21:17:53 GMT Neil Kandalgaonkar wrote:
> In article <slrn8lp27u.q62.garcia_suarez@rafael.kazibao.net>,
> Rafael Garcia-Suarez <garcia_suarez@hotmail.com> wrote:
> 
>>    + C<not> followed by parentheses behaves like a list operator.  This
> 
> Ok, clearly I am totally blind because there is a HUGE perldelta entry
> about this change... 'Parenthesized not() behaves like a list operator'
> 
> Or Sarathy broke into my computer last night to fix it. Clever guy.
> 

No the really good pumpkings can alter the bits on your disk by telekinesis.

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: 2 Jul 2000 23:06:14 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: comparison question
Message-Id: <8joecm$rgb$1@orpheus.gellyfish.com>

On Sat, 01 Jul 2000 03:20:01 GMT jason wrote:
> James Fisher writes ..
>>I am using the following code in an if statement
>>
>>if ($element eq "QUESTION" && $_{'NUMBER'} == $SearchNumber) {
>>
>>The latter comparison is failing when comparing two variables.  I know
>>you can compare variables...  I have tried using eval to get a result to
>>no avail.  Possibly, is it the module I am using(XML::Parser module).
> 
> there's nothing wrong with the comparison .. my guess is that either 
> $element does not equal 'QUESTION' or the 'NUMBER' member of the %_ hash 
> does not numerically equal $SearchNumber
> 

Or $_ is a hash ref and the OP should be using $_->{NUMBER} who knows ;-}

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 20:54:10 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <3962abc3.1689218@news.skynet.be>

Magic wrote:

>Strikes me that if Perl can't handle a simple task like that simply
>then I might just as well use Javascript, at least client-side JS
>can't delete your site.

It can delete the user's harddisk. Just look at the Loveletter virus for
a simple example.

-- 
	Bart.


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

Date: Sun, 02 Jul 2000 20:36:33 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Decimal to Hexadecimal (was: Perl)
Message-Id: <8jo8o0$32b$1@localhost.localdomain>

In article <%4N75.441$S96.6482@m2newsread.uni2.es>,
Juan Miguel <jumigas@ctv.es> wrote:
>Hello,
>Does anybody know how to change a decimal number into a hexadecimal?
>Thanks.

In perl, scalars don't usually need to be manually converted between
types. You can say  

chmod 0640  => $file;   # octal
chmod 416   => $file;   # dec -- same thing!

However, when you print it, perl assumes you really want decimal:

print 0640, 0x1a0, 416;  # 416416416

For getting a string formatted, use sprintf. To simply print it, 
use printf.

   $var = sprintf "%x", 123;  # %x formats as hex
   printf "%x\n", 123;  

See perldoc -f sprintf for formats.


-- 
Neil Kandalgaonkar <neil@brevity.org>


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

Date: Sun, 02 Jul 2000 19:38:38 GMT
From: haribeau@gmx.net (Clemens Hermann)
Subject: delete array
Message-Id: <395f99f8.453547@news.btx.dtag.de>

Hi,

within a script I need some very large arrays. How can I delete an
array complete after it is no longer nesessary to free the memory it
used?

thanks

Clemens


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

Date: Sun, 02 Jul 2000 19:57:51 GMT
From: James Fisher <jfisher@epotec.com>
Subject: Re: delete array
Message-Id: <395F9E80.18FA1BBE@epotec.com>

Clemens Hermann wrote:
> 
> Hi,
> 
> within a script I need some very large arrays. How can I delete an
> array complete after it is no longer nesessary to free the memory it
> used?
> 
> thanks
> 
> Clemens

To delete an array....

@myArray = ();


JF


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

Date: Sun, 2 Jul 2000 15:10:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: delete array
Message-Id: <slrn8lv4t7.ast.tadmc@magna.metronet.com>

On Sun, 02 Jul 2000 19:38:38 GMT, Clemens Hermann <haribeau@gmx.net> wrote:
>
>within a script I need some very large arrays. How can I delete an
>array complete after it is no longer nesessary to free the memory it
                                                   ^^^^
>used?


   perldoc -q free

You are expected to check the Perl FAQs *before* posting to the
Perl newsgroup you know.



Perl FAQ, part 3:

   "How can I free an array or hash so my program shrinks?"

   "How can I make my Perl program take less memory?"


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


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

Date: 2 Jul 2000 13:14:21 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: delete array
Message-Id: <395fa29d@news.victoria.tc.ca>

Clemens Hermann (haribeau@gmx.net) wrote:
: Hi,

: within a script I need some very large arrays. How can I delete an
: array complete after it is no longer nesessary to free the memory it
: used?

@arrary = (lots of values);

@arrary = ();	# set array back to empty array
undef @array;	# remove the arrary variable
$#array = -1;	# reset last element of array, toss all other elements

 ...etc.


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

Date: 2 Jul 2000 21:18:57 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Examine A Standart Logfile
Message-Id: <8jo83h$6ij$1@orpheus.gellyfish.com>

On Sun, 02 Jul 2000 18:35:25 +0200 Markus Hediger wrote:
> Hello!
> 
> Does anyone know the ultimative regular expression or algorithm to split a
> single line from a standart logfile into its fields?
> 
> A line looking like:
> 
> ad25-175.compuserve.com - - [02/Mar/1997:05:03:49 -0500]
> "GET /selfhtml/tg.htm HTTP/1.0" 200 1788

Looks something like :

   m/(\d+\.\d+\.\d+\.\d+)\s # IP Number of client
     (\S*)\s(\S*)\s         # User ?
     \[(.*)\]\s             # Time
     "([^"]*)"\s            # Request
     (\d{3})\s              # Status
     (\d*)\s*$              # Size of data xfered
    /x;

But you will probably want to read the perlre manpage ...

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 19:23:26 GMT
From: "Blair Heuer" <ab@cd.com>
Subject: finding, checking, replacing
Message-Id: <OEM75.28110$_b3.685750@newsread1.prod.itd.earthlink.net>

I am currently in the planning stages of writing a multi-user message board
script (and yes, I have written one before, but not this complex) that I
want to be extremely flexible and custimizable. In order to do so I plan on
using a template and scripting system. Both will require me to search
through a list and find/check/replace text.

So here's my question. How can I make a script, search through a file for a
certain bit a text, take that text, do some actions based on what it
actually found, and replace it with some other text according to what is in
there. Here is an example:

All text that needs to be replaced will be in the form [var.something] or
[mod.something] or something between '[' and ']'. So the code has to find
that, then take the text from it, 'var.something' or 'mod.something' and
send it to a function that will return the text which needs to go in its
place, and then that gets put where the [] tag was.

I have tried learning about s// and have a slight grasp of it, but it seems
really abstract to me. Any help on how this may be done would be
appreciated.

-Blair Heuer




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

Date: Sun, 2 Jul 2000 15:06:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: finding, checking, replacing
Message-Id: <slrn8lv4lv.as3.tadmc@magna.metronet.com>

On Sun, 02 Jul 2000 19:23:26 GMT, Blair Heuer <ab@cd.com> wrote:

>So here's my question. How can I make a script, search through a file for a
>certain bit a text, take that text, do some actions based on what it
>actually found, and replace it with some other text according to what is in
>there. 

I would recommend a module that searches through a file for a
certain bit a text, take that text, do some actions based on what it
actually found, and replace it with some other text according to what is in
there.

:-)


Most such modules have "Template" in their names.

Look around at CPAN.


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


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

Date: 2 Jul 2000 18:56:51 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Fun with typos.
Message-Id: <962563884.16221@itz.pp.sci.fi>

In article <mB575.24483$A%3.282728@news1.rdc2.pa.home.com>, Andy wrote:
>The next version will optionally replace a character with others within 
>close proximity of it's keyboard location.

That reminds me of one I wrote a year or so ago.  It was originally a
pair of HTML::Mason components that produced a web page with lyrics to
"99 bottles of beer on the wall", but I've removed the HTML-generating
parts and merged it into a single script:

#!/usr/bin/perl -w
use strict;

sub typo {
    my $text = shift;
    my $num = @_ ? shift : 1;
    my $keys = "11234567890poiuytrewqasdfghjklmnbvcxzZXCVBNMLKJHGFDSAQWERTYUIOPP";

    while( --$num > 0 ) {
	my $choice = rand;
	my $pos = int rand(length $text);
	if ( $choice < .4 ) {
	    substr($text,$pos,2) = reverse substr($text,$pos,2);
	} elsif ( $choice < .8 ) {
	    my $idx = index($keys, substr($text,$pos,1), 1);
	    next  if $idx == -1;
	    $idx += ($choice < .6) ? 1 : -1;
	    substr($text,$pos,1) = substr($keys,$idx,1);
	} elsif ( $choice < .9 and length $text > $num ) {
	    substr($text,$pos,1) = '';
	} else {
	    substr($text,$pos,1) x= 2;
	}
    }
    return $text;
}

sub bottles {
    ($_[0] || 'no more') . ' bottle' . ($_[0] != 1 && 's') . ' of beer';
}

my $num = 99;
my $drunk = 0;

while ($num > 0) {
    my $verse = <<"HERE";
${\bottles($num)} on the wall,
${\bottles($num)};
Take one down, pass it along,
${\bottles(--$num)} on the wall!
HERE
    print typo($verse, $drunk++), "\n";
}

__END__

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.




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

Date: Sun, 02 Jul 2000 19:17:20 GMT
From: Andy <y-o-y@home.com>
Subject: Re: Fun with typos.
Message-Id: <4zM75.27485$A%3.311333@news1.rdc2.pa.home.com>

In article <962563884.16221@itz.pp.sci.fi>, Ilmari Karonen 
<usenet11140@itz.pp.sci.fi> wrote:

> In article <mB575.24483$A%3.282728@news1.rdc2.pa.home.com>, Andy wrote:
> >The next version will optionally replace a character with others within 
> >close proximity of it's keyboard location.
> 
> That reminds me of one I wrote a year or so ago.  It was originally a
> pair of HTML::Mason components that produced a web page with lyrics to
> "99 bottles of beer on the wall", but I've removed the HTML-generating
> parts and merged it into a single script:
> 
<snipped for brievity>

Thanks for sharing! That's great!!! LOL!

I love the slow but sure drunken typing decay! LOL!

Best regards,

Andy


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

Date: 2 Jul 2000 22:49:25 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Help: regex for changing NON-absolute urls in a html file.
Message-Id: <8jodd5$o8q$1@orpheus.gellyfish.com>

On Thu, 29 Jun 2000 12:01:51 -0400 Tad McClellan wrote:
> 
> [ removed non-existent newsgroup.
>   removed wasteland newsgroup.
> ]
> 

Unfortunately because of this :

  group=comp.lang.perl.misc
  type=0
  case=0
  score=kill
  xref=alt\.perl

These kind of threads look a little wierd ;-}

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 2 Jul 2000 20:09:54 +0200
From: RonR <ronr@my-deja.com>
Subject: Re: how to get text enclosed by matching () ?
Message-Id: <01HW.B58552120000CB5410F6C6E0@news.planet.nl>

On Sun, 2 Jul 2000 9:54:21 +0200, Neil Kandalgaonkar wrote
(in message <8jms2u$ibg$1@localhost.localdomain>):

> In article <395EC33E.7E47CFE6@rochester.rr.com>,
> Bob Walton  <bwalton@rochester.rr.com> wrote:
>> RonR wrote:
>>> a line: "blabla bla (xyz, abc(n), xyz, abc(n)) etc etc"
>>> I want to get the list enclosed by the matching braces
>>> giving: "( xyz, abc(n), xyz, abc(n) )" or eventually without the braces.
>>> 
>>> Is there an easy way to do this ? The braces are always in pairs (if that
>                                                     ^^^^^^^^^^^^^^^
> 
>> In general, you can't do this a single regular expression. 
> 
> If 
>    1. the parens are known to be in pairs, and 
Yes, they are
>    2. well-balanced (?),
Normally: Yes, they are
>    3. and 'escaped' parens are not allowed, e.g. \)
Normally not present.
>    
> then surely:
> 
>    ($in_parens) = ( $string =~ /(\(.*\))/ );

Thanks for all the input, I'll have to study the code since perl is fairly 
new to me and try it all out. I already had written a bit of code but it did 
not work the way I wanted.

Thanks a lot,
-- 
Ronald.    <  \_ _                     o o
                       | o  \     %-/\//_\\/\-%             
                       '(*)-'---(*)       (*)       
home: http://home.wxs.nl/~ronr/RonR.html
PGP :  http://home.wxs.nl/~ronr/ronr_pgp.key
 The best way to accelerate a computer 'running' windows is by gravitation.



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

Date: Sun, 2 Jul 2000 23:40:40 +0200
From: RonR <ronr@my-deja.com>
Subject: Re: how to get text enclosed by matching () ?
Message-Id: <01HW.B585837800007BCC128E9CF0@news.planet.nl>

On Sun, 2 Jul 2000 9:54:21 +0200, Neil Kandalgaonkar wrote
(in message <8jms2u$ibg$1@localhost.localdomain>):

> In article <395EC33E.7E47CFE6@rochester.rr.com>,
> Bob Walton  <bwalton@rochester.rr.com> wrote:
>> RonR wrote:
>>> a line: "blabla bla (xyz, abc(n), xyz, abc(n)) etc etc"
>>> I want to get the list enclosed by the matching braces
>>> giving: "( xyz, abc(n), xyz, abc(n) )" or eventually without the braces.
>>> 
>>> Is there an easy way to do this ? The braces are always in pairs (if that
>                                                     ^^^^^^^^^^^^^^^
> 
>> In general, you can't do this a single regular expression. 
> 
> If 
>    1. the parens are known to be in pairs, and 
>    2. well-balanced (?),
>    3. and 'escaped' parens are not allowed, e.g. \)
>    
> then surely:
> 
>    ($in_parens) = ( $string =~ /(\(.*\))/ );
> 
> works?
Yes, it works but ...
I forgot to mention that "etc etc" could contain more of these lists enclosed 
by parenthesis. This expression gets all the list at once; it is a little too 
greedy.

$a="create table x (a date,b num(2),c char(3)) storage (ini next) tablespace 
x;";
($cols) = ($a =~ /(\(.*\))/ );

prints "(a date,b num(2),c char(3)) storage (ini next)" where I wanted
"(a date,b num(2),c char(3))"
-- 
Ronald.    <  \_ _                     o o
                       | o  \     %-/\//_\\/\-%             
                       '(*)-'---(*)       (*)       
home: http://home.wxs.nl/~ronr/RonR.html
PGP :  http://home.wxs.nl/~ronr/ronr_pgp.key
 The best way to accelerate a computer 'running' windows is by gravitation.



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

Date: Sun, 2 Jul 2000 23:40:43 +0200
From: RonR <ronr@my-deja.com>
Subject: Re: how to get text enclosed by matching () ?
Message-Id: <01HW.B585837B00007C6D128E9CF0@news.planet.nl>

On Sun, 2 Jul 2000 6:20:08 +0200, Bob Walton wrote
(in message <395EC33E.7E47CFE6@rochester.rr.com>):

> RonR wrote:
>> a line: "blabla bla (xyz, abc(n), xyz, abc(n)) etc etc"
>> I want to get the list enclosed by the matching braces
>> giving: "( xyz, abc(n), xyz, abc(n) )" or eventually without the braces.

> Complete example:
> 
> $bal=make_parenmatching_regex(10); #make pattern
> $string=<DATA>;
> chomp $string;
> $string=~/\(($bal)/; #matches a ( followed by longest balanced string
> print "$1\n";
> #
> ## Given DEPTH, return a regex which will match a string with up
> ## to DEPTH levels of nested parens.
> ##
> sub make_parenmatching_regex {
>     local($depth) = @_;
>     local($nonparen) = '[^()]';
>     "($nonparen|\\(" x $depth . "$nonparen*" . '\))*' x ($depth-1) .
> '\))+';
> }
> __END__
> blabla bla (xyz, abc(n), xyz, abc(n)) etc etc
> 
> 
> prints:
> 
> xyz, abc(n), xyz, abc(n)

Thanks for the input Bob,

this does exactly what I want but I do not understand why ... I gues it just 
means studying mastering regular expressions a bit more.

$a="create table x (a date,b num(2),c char(3)) storage (ini next) tablespace 
x;";

$bal=make_parenmatching_regex(10); #make pattern
$string=$a;
chomp $string;
$string=~/\(($bal)/; #matches a ( followed by longest balanced string
print "$1\n";
#
## Given DEPTH, return a regex which will match a string with up
## to DEPTH levels of nested parens.
##
sub make_parenmatching_regex {
    local($depth) = @_;
    local($nonparen) = '[^()]';
    "($nonparen|\\(" x $depth . "$nonparen*" . '\))*' x ($depth-1) .
'\))+';
}

prints "a date,b num(2),c char(3)"
----------------------------
Only when I include this in my script macperl looses it's brain and crashed 
my mac :-(

Thanks,
-- 
Ronald.    <  \_ _                     o o
                       | o  \     %-/\//_\\/\-%             
                       '(*)-'---(*)       (*)       
home: http://home.wxs.nl/~ronr/RonR.html
PGP :  http://home.wxs.nl/~ronr/ronr_pgp.key
 The best way to accelerate a computer 'running' windows is by gravitation.



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

Date: 2 Jul 2000 19:49:34 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Interchage the role of key and value in a hash
Message-Id: <8jo6ca$10h0n$3@ID-24002.news.cis.dfn.de>

hi,
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Sat, 1 Jul 2000 18:33:51 +0800 multiplexor wrote:
>> 
>> %entity = ('&' , '&amp;' , '>' , '&gt;');
>> 
>> That is, interchange the role of the keys and values of %entity.
>> 
>> I think of using a foreach loop:
>> foreach (keys %entity) {
>>     %code($entity($_)) = $_
>> }

> Thats one way of doing it,

no, it isn't. i get a syntax error. if you want to
use something like the above foreach loop, better write
$code{$entity{$_}} = $_;

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."


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

Date: 2 Jul 2000 22:14:54 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Newbie question: Sorting a list-of-hashes
Message-Id: <8jobce$hks$1@orpheus.gellyfish.com>

On Fri, 30 Jun 2000 14:28:05 -0400 Dr. Retribution wrote:
> Given the following structure:
> 
> %scoredatabase = (
>         [
>         player => "Joe",
>         frame1 => "5",
>         frame2 => "8" ,
>         frame3 => "1" ,
>         total => "14"
>         ]
>     ... more players ...
> ) ;
> 

That doesnt look right - you appear to have a hash here whose first key
is a reference to an array which will be stringified and thus simply
become something like 'ARRAY(0x80ead98)' - do you mean to create a
hash of hashes :

 %scoredatabase = (
                    Joe => { 
                             frame1 => "5",
                             frame2 => "8" ,
                             frame3 => "1" ,
                             total => "14"
                            },
# etc

                    ) ;

I think you ought to post a sample of your real code.

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

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


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