[19180] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1375 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 25 09:05:33 2001

Date: Wed, 25 Jul 2001 06:05:10 -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: <996066310-v10-i1375@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 25 Jul 2001     Volume: 10 Number: 1375

Today's topics:
        Any way to export a Perl/Tk Canvas to an image file (darrin)
    Re: Apple Quicktime Module <dradul@yahoo.com>
    Re: call a sub defined in a script from the command lin <paul.johnston@dsvr.co.uk>
    Re: CGI -> Apache Problem <georg@vassilopulos.de>
        Email Question <blnukem@hotmail.com>
    Re: Email Question <tschmelter@statesman.com>
        FAQ: How can I take a string and turn it into epoch sec <faq@denver.pm.org>
    Re: Frustrated people (not) answering questions (Jacqui caren)
        how to clean a text file (need to cut some spaces) [qui (George)
    Re: how to clean a text file (need to cut some spaces)  (Ronald Blaschke)
    Re: how to clean a text file (need to cut some spaces)  <ilya@martynov.org>
        is there Online Unzip Webtool in perl? (~CKD~)
    Re: is there Online Unzip Webtool in perl? <bart.lateur@skynet.be>
        Java applet in perl? <angenent@kabelfoon.nl>
        Multi tuple hashes (Paul)
    Re: Multi tuple hashes <paul.johnston@dsvr.co.uk>
    Re: Newbie problem: if(<STDIN> =~ /^[yY]/) control stru (prabu)
    Re: regex question - sort of - how to count if the stri (David Gurney)
    Re: regex question - sort of - how to count if the stri <paul.johnston@dsvr.co.uk>
        regex question - sort of - how to count if the string h (David Gurney)
        Regular Expression Need Help (Andrew Evans)
    Re: Regular Expression Need Help <tschmelter@statesman.com>
    Re: Regular Expression Need Help <paul.johnston@dsvr.co.uk>
        Regular expression question. (Markku Hirvonen)
    Re: Regular expression question. <ilya@martynov.org>
    Re: Regular expression question. (Ronald Blaschke)
    Re: Running the same scripts of different platforms <ilya@martynov.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Jul 2001 05:52:56 -0700
From: dthusma@balsasoft.com (darrin)
Subject: Any way to export a Perl/Tk Canvas to an image file
Message-Id: <525a9ea2.0107250452.19b8b735@posting.google.com>

I know you can render the canvas as postscript 
            $canvas->postscript(-file=>"ps.out");

My question is:
      "How can you change that to a GIF or JPG?"

I would be inclined to think Image::Magick , like on pg 334 of the CGI 
programming book, but I would like to hear from others that might have
done this task already to see what works.

Cheers

Darrin Husmann


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

Date: Wed, 25 Jul 2001 07:33:29 -0500
From: P. Alejandro Lopez-Valencia <dradul@yahoo.com>
Subject: Re: Apple Quicktime Module
Message-Id: <9jme85$24sd$1@ID-99513.news.dfncis.de>

In article <6rsolt8mchpai6kisjpre299midg9g6fsr@4ax.com>, 
rachel@lspace.org says...
>On Sat, 21 Jul 2001 17:03:25 -0500, "Jason Jenkins"
><foo@northwestern.edu> wrote:
>
>>I am just curious if there is a quicktime module, and if possible where this
>>could be obtained?
>
>2 min work at CPAN (http://search.cpan.org) finds no matches for
>"quick time", "quicktime" or "QuickTime" on either 'Module' or
>'Documentation'.
>
>So I'd guess the answer is 'No'.

The answer is yes, but with serious caveats. It only works in the MacOS 
port of perl and therefore it is only included in the source distribution 
of such port (see http://www.macperl.org/ for details). If you want to 
port it to Windows, you'll have to look into the SDK for WinQT at 
http://www.apple.com/developer/, yet I don't think you can get your hands 
on the QT4 or QT5 SDKs unless you explicitly subscribe to the Apple 
Developer's program.

-- 
Alejandro Lopez-Valencia

Kenkon Itteki       ---       Heaven and Earth at one stroke



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

Date: Wed, 25 Jul 2001 12:42:12 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: call a sub defined in a script from the command line
Message-Id: <3B5EB094.C574C8AF@dsvr.co.uk>

Hi,

> I am trying to write a script that takes as its first argument the
> name of a subroutine and then a list of arguments to be passed to the
> subroutine.

You can take advantage of a useful, but rarely used feature of perl:

sub beg { }
sub speak { }
$func = "beg";
$func->("for", "food");

To add a bit of protection against people calling your internal
functions, I'd rename the functions:

sub cmd_beg { }
sub cmd_speak { }
$func = "beg";
"cmd_$func"->("for", "food");

Paul


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

Date: Wed, 25 Jul 2001 12:51:58 +0200
From: "Georg Vassilopulos" <georg@vassilopulos.de>
Subject: Re: CGI -> Apache Problem
Message-Id: <9jm8cf$rlb$01$1@news.t-online.com>

THANKS a lot!
The mapped drive hint solved my Problem!!!

God did hear my pearl problem question :-))))
Georg

"Eric Bohlman" <ebohlman@omsdev.com> schrieb im Newsbeitrag
news:9jkvu6$sqg$1@bob.news.rcn.net...
> Thomas Bätzler <Thomas@baetzler.de> wrote:
> >>my $command = "p:/tools/wni/unzip.exe $myFile";
> >>system ($command) or print "Fuck the system command:$!";
> > [...]
>
> > I bet that P: is a mapped drive and that the Apache runs as a service
> > under a special user account on your Server. So from the Apache's POV,
> > there probably is no P: drive as drive mappings are only active for
> > the currently logged in account.
>
> Furthermore, the command processor is pretty much the one place in Win32
> where you *have* to use backslashes rather than forward slashes as path
> separators, and the single-argument form of system() invokes the command
> processor.
>




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

Date: Wed, 25 Jul 2001 12:22:28 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Email Question
Message-Id: <8Sy77.142209$qs5.23053019@news02.optonline.net>

Hi Group
     I wrote a script that allows the user to upload a report and then send
emails a retrieval link to some recipients for viewing it works great.
Except in AOL the hyperlink in the mail body shows up as regular text not as
a link any ideas? I've tried adding "print MAIL "Content-type:text/html\n";"
But that kills the link in all the browsers here is the mail portion of the
script:

foreach (@mail_list){

open(MAIL, "|$mail_path -t");
        print MAIL "To: $_\n";
        print MAIL "From: $returnemail ($from)\n";
        print MAIL "Subject: $subject\n";
        print MAIL "$body\n";
        print MAIL "Please click the link below to retrieve your report:\n";
        print MAIL "$url/$cgi_path/retrieve.pl?showme=$random_num\n\n";
        print MAIL "";

close(MAIL);
}




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

Date: Wed, 25 Jul 2001 12:53:59 GMT
From: Tim Schmelter <tschmelter@statesman.com>
Subject: Re: Email Question
Message-Id: <3B5EC164.3A47D908@statesman.com>

Blnukem wrote:

> Hi Group
>      I wrote a script that allows the user to upload a report and then send
> emails a retrieval link to some recipients for viewing it works great.
> Except in AOL the hyperlink in the mail body shows up as regular text not as
> a link any ideas? I've tried adding "print MAIL "Content-type:text/html\n";"
> But that kills the link in all the browsers here is the mail portion of the
> script:
>
> foreach (@mail_list){
>
> open(MAIL, "|$mail_path -t");
>         print MAIL "To: $_\n";
>         print MAIL "From: $returnemail ($from)\n";
>         print MAIL "Subject: $subject\n";
>         print MAIL "$body\n";
>         print MAIL "Please click the link below to retrieve your report:\n";
>         print MAIL "$url/$cgi_path/retrieve.pl?showme=$random_num\n\n";
>         print MAIL "";
>
> close(MAIL);
> }

Well, two problems, neither related to Perl:

1) Your url is being written as text, so why would you expect it to render as
HTML? If you want an link, then write an anchor tag:
        print MAIL qq(<a ref="$url/$cgi_path/retrieve.pl?showme=$random_num">
$url/$cgi_path/retrieve.pl?showme=$random_num</a>\n\n);

If other email clients have been giving you a hyperlink resulting from that
text, that's just something they're doing as a convenience, not because you've
written an honest-to-goodness link.

2) AOL doesn't fully support HTML email. I think it may support <A> tags, but
I'm not sure. A Google search for "AOL HTML email" returned 1.7 million hits.
You can probably find something useful there.

--
Tim Schmelter
Public Key available from http://www.keyserver.net
CAD7 2ABB 05A4 2F00 4CAE 7D2F 127C 129A 7173 2951




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

Date: Wed, 25 Jul 2001 12:16:46 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I take a string and turn it into epoch seconds?
Message-Id: <OMy77.43$os9.170721280@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How can I take a string and turn it into epoch seconds?

    If it's a regular enough string that it always has the same format, you
    can split it up and pass the parts to "timelocal" in the standard
    Time::Local module. Otherwise, you should look into the Date::Calc and
    Date::Manip modules from CPAN.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.13
-- 
    This space intentionally left blank


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

Date: Wed, 25 Jul 2001 10:39:39 GMT
From: Jacqui.Caren@ig.co.uk (Jacqui caren)
Subject: Re: Frustrated people (not) answering questions
Message-Id: <90E97ECECJacquiCarenigcouk@195.8.69.73>

comdog@panix.com (brian d foy) wrote in <comdog-B305AB.01333004062001
@news.panix.com>:

>In article <9ff1ig$vp2$3@agate.berkeley.edu>, Ryan Travis Tate 
><ryantate@OCF.Berkeley.EDU> wrote:
>
>> brian d foy <comdog@panix.com> wrote:
>>  | you'd have to go a long way to support either of those.  Outlook
>>  | cost the business sector billions of dollars in damages last
>>  | year said the New York Times.  that doesn't sound like a better
>>  | world.
>
>> of course, your statement could be rewritten, "Apache cost the business
>> sector billions of dollars in damages last year." 
>
>no it couldn't.  the NYT reported no such thing.  indeed, the
>Economist has said on many occasions just the opposite.

See
http://dailynews.yahoo.com/h/zd/20010723/tc/it_bugs_out_over_iis_security_
1.html

and find out what IIS is an acronym for :-)

Jacqui
 


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

Date: 25 Jul 2001 03:47:35 -0700
From: argeo@4u.net (George)
Subject: how to clean a text file (need to cut some spaces) [quite newbie ;]
Message-Id: <a42827b0.0107250247.609ce4a9@posting.google.com>

Hello alltogether!
I have a text file (say: output.txt) that looks like the 
following:

 ...
668~subheader~1~Coffee Machines interacts with employees.}  
668~header~1~New Agents for Coffee Machine}              
669~date~1~18.07.2001}                                  
 ...

The end of each line is indicated by the '}' character,
each new lines begins with a number.
Unfortunately, there are spaces between the '}' and the
number, and I need to cut these out, so that there is
only the '}', a line break and the new line begines
with the number.

Do you have any idea how I can accomplish that ?

Thanks for any ideas !

George


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

Date: 25 Jul 2001 11:29:34 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: how to clean a text file (need to cut some spaces) [quite newbie ;]
Message-Id: <9jmaiu$20ol$1@ID-57488.news.dfncis.de>

On 25 Jul 2001 03:47:35 -0700, George <argeo@4u.net> wrote:
> ...
> 668~subheader~1~Coffee Machines interacts with employees.}  
> 668~header~1~New Agents for Coffee Machine}              
> 669~date~1~18.07.2001}                                  
> ...
> 
> The end of each line is indicated by the '}' character,
> each new lines begins with a number.
> Unfortunately, there are spaces between the '}' and the
> number, and I need to cut these out, so that there is
> only the '}', a line break and the new line begines
> with the number.
> 
> Do you have any idea how I can accomplish that ?

You might try:
$str = "  some string  ";
$str =~ s/^\s+//g;  ## remove whitespaces at beginning of string
$str =~ s/\s+$//g;  ## remove whitespaces at at of string

-- 


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

Date: 25 Jul 2001 15:39:56 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: how to clean a text file (need to cut some spaces) [quite newbie ;]
Message-Id: <87k80xs0dv.fsf@abra.ru>


G> Hello alltogether!
G> I have a text file (say: output.txt) that looks like the 
G> following:

G> ...
G> 668~subheader~1~Coffee Machines interacts with employees.}  
G> 668~header~1~New Agents for Coffee Machine}              
G> 669~date~1~18.07.2001}                                  
G> ...

G> The end of each line is indicated by the '}' character,
G> each new lines begins with a number.
G> Unfortunately, there are spaces between the '}' and the
G> number, and I need to cut these out, so that there is
G> only the '}', a line break and the new line begines
G> with the number.

G> Do you have any idea how I can accomplish that ?

If you need to strip spaces at end of each line you can use this one-liner:

    perl -i -pe 's/\s*$/\n/' output.txt

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Wed, 25 Jul 2001 05:54:34 -0500 (CDT)
From: tvckd@webtv.net (~CKD~)
Subject: is there Online Unzip Webtool in perl?
Message-Id: <457-3B5EA56A-1@storefull-622.iap.bryant.webtv.net>

Request:
Do any of PerlMasters have a generic (open-source) script for a online
unzipper utility that i can use. 


better yet,.. is there someone who has a hosted demo of a Unzip (using
perl) that will allow Zipped (urls) files to be Unziped online??

Please post or email me

~CKD~



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

Date: Wed, 25 Jul 2001 11:53:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: is there Online Unzip Webtool in perl?
Message-Id: <3sctltce2fmgr54k2iogi5m62v442058un@4ax.com>

~CKD~ wrote:

>Do any of PerlMasters have a generic (open-source) script for a online
>unzipper utility that i can use. 

Using Archive::Zip, you can write your own.

-- 
	Bart.


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

Date: Wed, 25 Jul 2001 15:02:37 +0200
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Java applet in perl?
Message-Id: <9jmg0d$1u7q$1@news.kabelfoon.nl>

Hello there,  a short question..

does anybody know how to run a java applet in perl?


thanks in advance

chris




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

Date: 25 Jul 2001 05:01:24 -0700
From: pa_watts@hotmail.com (Paul)
Subject: Multi tuple hashes
Message-Id: <e6007a72.0107250401.2fd57272@posting.google.com>

The following code produces FooBar

$areas{1}{A} = 1;
$areas{2}{A} = 1;
		
$areas{1}{A}{2} = "Foo";
print $areas{1}{A}{2};
$areas{2}{A}{2} = "Bar";
print $areas{1}{A}{2};

I expected FooFoo (why should $areas{2} have any bearing on {1}?). If
anyone can explain, I would be very grateful.

Thanks,
    Paul


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

Date: Wed, 25 Jul 2001 13:29:39 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Multi tuple hashes
Message-Id: <3B5EBBB3.D942D287@dsvr.co.uk>

Hi,

> $areas{1}{A} = 1;
> $areas{2}{A} = 1;

If you omit these two lines it produces FooFoo as expected.

> $areas{1}{A}{2} = "Foo";
> print $areas{1}{A}{2};
> $areas{2}{A}{2} = "Bar";
> print $areas{1}{A}{2};

If you add this at the end:

print $areas{1}{A};

You get HASH(0x80ff3e0) if the first two lines are omitted, but 1 if
they're included.
I don't understand exactly what's going on, but you get some idea from
these results.

Paul


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

Date: 25 Jul 2001 03:18:41 -0700
From: prabuanand@excite.com (prabu)
Subject: Re: Newbie problem: if(<STDIN> =~ /^[yY]/) control structure returns  true if i type y-How
Message-Id: <9fa34cc5.0107250218.791f0945@posting.google.com>

Thanks to everyone who corrected me.
I'm extremely sorry making multiple mistakes in a single post.(this is
my first post!!)
I think now i have got the answer.Thanks again

prabu
==================

Paul Boardman <peb@bms.umist.ac.uk> wrote in message news:<3B5D87A6.7C934A36@bms.umist.ac.uk>...
> prabu wrote:
> > Hello Geeks,
> 
> Not a good way to start a question if you want some help is it?
> 
> > I'm a perl newbie.I'm using llama book to learn.In the perl regular
> > expressions unit i learnt that "^" is a negation operator.--pg.79 in
> > 2nd edition
> > Then in pg 85 i foud the above control structure
> > " if (<STDIN>=~ /[^yY]/) "
> > returns true as return value if i type anything starting with y or Y.
> 
> re-read pages 84 and 85 and you'll find that the '^' character outside
> of the square brackets anchors the pattern to the beginning of the
> string.
> 
> HTH
> 
> Paul


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

Date: Wed, 25 Jul 2001 12:28:51 GMT
From: david_gurney@hotmail.com (David Gurney)
Subject: Re: regex question - sort of - how to count if the string has more than  25 words in it
Message-Id: <3b5eb7dd.11864470@news.dircon.co.uk>

On Wed, 25 Jul 2001 11:43:13 +0100, Paul Johnston
<paul.johnston@dsvr.co.uk> wrote:

>Hi,
>
>>                 while ($ttxts[$i]){
>
>The condition in this while statement will always be true, so your
>program will go into an infinite loop - no wonder it seems slow.
>However, your general method seems quite reasonable, so I suggest:
>
>>                 $match = 0 ;
>>                 while ($ttxts[$i] =~ /(\w+)/g){
>>                          $match++ ;
>>                          $tshrt .= "$1 ";

Thanks for the help,

subsidiary question - how do I modify the regex to allow for HTML or
words ?

	Dave



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

Date: Wed, 25 Jul 2001 11:43:13 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: regex question - sort of - how to count if the string has more than  25 words in it
Message-Id: <3B5EA2C1.EC10A305@dsvr.co.uk>

Hi,

>                 while ($ttxts[$i]){

The condition in this while statement will always be true, so your
program will go into an infinite loop - no wonder it seems slow.
However, your general method seems quite reasonable, so I suggest:

>                 $match = 0 ;
>                 while ($ttxts[$i] =~ /(\w+)/g){
>                          $match++ ;
>                          $tshrt .= "$1 ";
>                 }
>                 if ($match <= 25){
> ##                      do stuff
>                 }

If this isn't fast enough, there are a number of approaches you could
take on this. Yours will be a relatively good one though, as it pushes
most of the work into Perl's efficient RE engine, avoiding things like a
bounds check for every character in the string.

Paul


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

Date: Wed, 25 Jul 2001 10:10:19 GMT
From: david_gurney@hotmail.com (David Gurney)
Subject: regex question - sort of - how to count if the string has more than 25 words in it
Message-Id: <3b5e9a1d.4248829@news.dircon.co.uk>

hi,

I'm trying to count the number of words in a string repeatedly. If the
number is greater than 25 then the string is shortened and the entire
string written to another file. The problem seems to be that the way
I'm doing the count is very slow. can anyone show me a faster way than

		$match = 0 ;
		while ($ttxts[$i]){
			if ($ttxts[$i] =~ /(\w+)/g){
				$match++ ;
				$tshrt .= "$1 ";
			}
		}
		if ($match <= 25){
##			do stuff
		}



cheers

Dave Gurney


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

Date: 25 Jul 2001 05:35:09 -0700
From: andyevs@hotmail.com (Andrew Evans)
Subject: Regular Expression Need Help
Message-Id: <bcb09cf7.0107250435.7f53f6d1@posting.google.com>

I am trying to remove all tags in an HTML string apart from the ones I
specify in a list.

I have a regular expression:

<[^(P|STRONG|UL|OL|A|EM|BR)]([^>]*)>

where I want to match everything BUT those in the list and then
replace it with nothing.
However the problem is it also matches <M> <SPAN> tags etc.

Thanks in advance

Bye
Andy


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

Date: Wed, 25 Jul 2001 12:46:40 GMT
From: Tim Schmelter <tschmelter@statesman.com>
Subject: Re: Regular Expression Need Help
Message-Id: <3B5EBFAE.B2C6828D@statesman.com>

Andrew Evans wrote:

> I am trying to remove all tags in an HTML string apart from the ones I
> specify in a list.
>
> I have a regular expression:
>
> <[^(P|STRONG|UL|OL|A|EM|BR)]([^>]*)>
>
> where I want to match everything BUT those in the list and then
> replace it with nothing.
> However the problem is it also matches <M> <SPAN> tags etc.
>
> Thanks in advance

Try HTML::Parser or HTML::TokeParser. That way, you won't experience
frustration later when you realize that a simple regular expression won't
accomplish what you want.

--
Tim Schmelter
Public Key available from http://www.keyserver.net
CAD7 2ABB 05A4 2F00 4CAE 7D2F 127C 129A 7173 2951




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

Date: Wed, 25 Jul 2001 13:58:03 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Regular Expression Need Help
Message-Id: <3B5EC25B.1501B2E9@dsvr.co.uk>

Hi,

> I am trying to remove all tags in an HTML string apart from the ones I
> specify in a list.
> 
> <[^(P|STRONG|UL|OL|A|EM|BR)]([^>]*)>

That won't work as you can't use alternatives like P|STRONG inside a
character class like [^>].
My solution may appear a little obfuscated:

@keep_tags{qw(p strong ul ol a em br)} = 1;
$str = "<p valign=top> <crap> crap";
$str =~ s/(<\/?(\w+)[^>]*>)/$keep_tags{lc($2)} ? $1 : ""/eg;
print $str;   

The regular expression strings out the complete contents of each tag as
$1, and the first word as $2. I then use the e flag on the regex so the
replacement is evaluated as perl code. If the first word is in
%keep_tags then the whole tag is kept, otherwise it's replaced by "".
Note I've used lc to make the comparison case insensitive, and note that
@keep_tags on the first line is correct, as I'm taking a hash slice.

Paul


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

Date: Wed, 25 Jul 2001 11:34:17 GMT
From: markku@huilustudio.fi (Markku Hirvonen)
Subject: Regular expression question.
Message-Id: <3b5ead85.3931827@uutiset.saunalahti.fi>

Hi!

I'm working on a message board and i need to find a way to filter out
certain amount of same letters in a string like this:
mmmmmmmmmmmmmmmm --> mm.

I'm looking for a regular expression that can do it.


Markku Hirvonen


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

Date: 25 Jul 2001 15:46:24 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Regular expression question.
Message-Id: <87g0bls033.fsf@abra.ru>


MH> Hi!
MH> I'm working on a message board and i need to find a way to filter out
MH> certain amount of same letters in a string like this:
MH> mmmmmmmmmmmmmmmm --> mm.

MH> I'm looking for a regular expression that can do it.

$text =~ s/(.)\1{10,}/$1$1/g;

will convert 11 and more same letters into two of them

$text =~ s/(.)\1{11,}/$1$1/g;

will convert 12 and more same letters into two of them

$text =~ s/(.)\1{15,}/$1$1/g;

will convert 16 and more same letters into two of them

I think you've got idea.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 25 Jul 2001 11:53:25 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: Regular expression question.
Message-Id: <9jmbvl$2i0p$1@ID-57488.news.dfncis.de>

On Wed, 25 Jul 2001 11:34:17 GMT, Markku Hirvonen <markku@huilustudio.fi> wrote:
> Hi!
> 
> I'm working on a message board and i need to find a way to filter out
> certain amount of same letters in a string like this:
> mmmmmmmmmmmmmmmm --> mm.
> 
> I'm looking for a regular expression that can do it.

I am not sure about what you are trying to do in detail.
Still, this might give you an idea:

$str = "aaabbbbccccccccccdef";

$str =~ s/(\w)\1+/\1/g;
print $str, "\n";

##prints: abcdef


If you want to limit that, say 'only for 5 or more characters':
$str = "aaabbbbccccccccccdef";

$str =~ s/(\w)\1{5,}/\1/g;
print $str, "\n";

##prints: aaabbbbcdef

Hope you know where this is going.  This is my best shot 
without further details.
-- 


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

Date: 25 Jul 2001 15:34:30 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Running the same scripts of different platforms
Message-Id: <87ofq9s0mx.fsf@abra.ru>


>> #!/usr/bin/env perl
>> "perl" should be in your path variable and  is "/usr/bin/env" always
>> true ?
>> that I am not sure.

DF> This works, except it doesn't like having the -w switch on the top line. 
DF> Can't be having that! Seems that:

DF> #!/usr/bin/env perl
DF> use diagnostics;
DF> disable diagnostics;

DF> gives me the behaviour I'm used to. Thanks!

If you are using Perl 5.6.0 or later you can use

    use warnings;

instead of -w switch

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

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


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