[29229] in Perl-Users-Digest
Perl-Users Digest, Issue: 473 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 31 11:14:18 2007
Date: Thu, 31 May 2007 08:14:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 31 May 2007 Volume: 11 Number: 473
Today's topics:
How to find and replace something that is nested inside alainfri@gmail.com
Re: How to find and replace something that is nested in <xicheng@gmail.com>
Re: How to find and replace something that is nested in alainfri@gmail.com
Re: most active perl discussion forum <bik.mido@tiscalinet.it>
Re: Multiple Line Pattern Match problem <aukjan@vanbelkum.no.spam.nl>
Re: Multiple Line Pattern Match problem <samuelzhng@gmail.com>
Re: Multiple Line Pattern Match problem <baxter.brad@gmail.com>
Re: Multiple Line Pattern Match problem <aukjan@vanbelkum.no.spam.nl>
Re: SendMail.pm: smtp and gmail Davidcollins001@gmail.com
stumped by graphics display problem... <socyl@987jk.com.invalid>
Re: Using CPAN to install Mail::Box module <Michael.Yxf@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 May 2007 05:57:34 -0700
From: alainfri@gmail.com
Subject: How to find and replace something that is nested inside something else?
Message-Id: <1180616254.016929.64780@u30g2000hsc.googlegroups.com>
I am not sure if this group is the right place for this question but
what I need is as follows. There is a piece of html. Throughout the
html there are a lot of <br> tags. The task is to replace all these
<br> tags with \n\r. The replacement must be performed only within
<pre> blocks. I can do this using VBScript in the following way:
Option Explicit
dim path2folder : path2folder = "D:\"
dim path2file : path2file = path2folder & "test.htm"
dim fileResults : fileResults = path2folder & "test-results.txt"
dim text
dim regex
Set regex = New RegExp
regex.Global = True
Dim regex1
Set regex1 = New RegExp
regex1.Pattern = "<[Bb][Rr][\/r]{0,1}>"
regex1.Global = True
Dim matches, match, tmp, tmp1
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim dfile : Set dfile = FSO.OpenTextFile( path2file, 1)
If dfile.AtEndOfLine <> True Then
text =dfile.ReadAll
dfile.Close
'///////////////////////////////////////////
' START OF RELEVANT CODE
regex.Pattern = "<pre>.*?<\/pre>"
Set matches = regex.Execute(text)
For Each match In matches
tmp = Match
regex1.Pattern = "<[Bb][Rr][\/r]{0,1}>"
tmp1 = regex1.Replace(tmp,vbCrlf)
text = Replace(text,tmp,tmp1)
Next
' END OF RELEVANT CODE
'///////////////////////////////////////////
Dim outfile : Set outfile = FSO.CreateTextFile(fileResults, True)
outfile.WriteLine text
outfile.Close
MsgBox "OK"
End If
The question is how to achieve the same results using one call of
regex.Replace, like
'THIS DOES NOT WORK
regex.Pattern = "(<pre>[.\n\r]*)(<[Bb][Rr][\/r]{0,1}>)([.\n\r]*</
pre>)"
text = regex.Replace(text, "$1" & vbCrlf & vbCrlf & "$3")
Than you.
------------------------------
Date: 31 May 2007 06:43:35 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: How to find and replace something that is nested inside something else?
Message-Id: <1180619015.838352.3270@q75g2000hsh.googlegroups.com>
On May 31, 8:57 am, alain...@gmail.com wrote:
> I am not sure if this group is the right place for this question but
> what I need is as follows. There is a piece of html. Throughout the
> html there are a lot of <br> tags. The task is to replace all these
> <br> tags with \n\r. The replacement must be performed only within
> <pre> blocks. I can do this using VBScript in the following way:
>
If you are asking for Perl solutions, then here is one way to go:
$string =~ s{<pre>(.*?)</pre>}{ mkCrtl($1) }egs;
sub mkCrtl {
my $str = shift;
$str =~ s{<br>}{\n\r}g;
return "<pre>$str</pre>";
}
Regards,
Xicheng
------------------------------
Date: 31 May 2007 07:40:40 -0700
From: alainfri@gmail.com
Subject: Re: How to find and replace something that is nested inside something else?
Message-Id: <1180622440.352832.248100@k79g2000hse.googlegroups.com>
On May 31, 4:43 pm, Xicheng Jia <xich...@gmail.com> wrote:
> On May 31, 8:57 am, alain...@gmail.com wrote:
>
> > I am not sure if this group is the right place for this question but
> > what I need is as follows. There is a piece of html. Throughout the
> > html there are a lot of <br> tags. The task is to replace all these
> > <br> tags with \n\r. The replacement must be performed only within
> > <pre> blocks. I can do this using VBScript in the following way:
>
> If you are asking for Perl solutions, then here is one way to go:
>
> $string =~ s{<pre>(.*?)</pre>}{ mkCrtl($1) }egs;
>
> sub mkCrtl {
> my $str = shift;
> $str =~ s{<br>}{\n\r}g;
> return "<pre>$str</pre>";
>
> }
>
> Regards,
> Xicheng
Thank you for the fast reply, Xicheng. Actually I need a solution that
would allow me to do this using the regular expressions provided by
Windows Script Host or by .NET Framework.
------------------------------
Date: Thu, 31 May 2007 11:53:02 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: most active perl discussion forum
Message-Id: <u06t53dmejgks020rmqlk7kes8eds82rag@4ax.com>
On Wed, 30 May 2007 21:35:06 -0700, fishfry
<BLOCKSPAMfishfry@your-mailbox.com> wrote:
>The generally snotty tone of this forum is not because it's a newsgroup.
>It's because people on this forum like to feel superior to others and
>just don't like to be helpful to people asking innocent but somewhat
>off-topic questions.
I think you're too mild: we're a crowd of f**king b**tards who like to
humiliate people asking about webserver configuration by sending them
to newsgroups where people is likely to know better. I can tell you
it's a real pita when some of those idiots accidentally asks a
*perfectly* on topic, *perfectly* clear, *perfectly* polite question:
you may even feel compelled to provide real help and you start
thinkering hard how you could bash him or her anyway, without ever
finding a way. Eventually, they even *thank* you: believe me, it's a
really disgusting sensation...
>It's a real turnoff. That's why the message volume is plummeting here,
>and to some extent, it's why Perl is dying as a viable commercial
>language.
Oh yeah, baby! clpmisc and the decline of Perl...
In fact the untold secret is that none of the regulars here is really
a Perl programmer: Java, Python, Ruby, whatever... but not Perl.
Indeed they tried it a few years ago, learnt one or two things and got
to hate it so much as to conjure up joining in clpmisc to actively
work against it!
>I've been coding in Perl since 1992 and reading these newsgroups since
>1995; so flame away if it makes you feel better.
Yep: you peni^Wtext editor is shorte^Wuglier than mine!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 31 May 2007 11:40:28 +0200
From: Aukjan van Belkum <aukjan@vanbelkum.no.spam.nl>
Subject: Re: Multiple Line Pattern Match problem
Message-Id: <e57f1$465e980c$c2abfc64$16944@news2.tudelft.nl>
samuel wrote:
> Hi All,
>
> Now I need to analyze a file which is composed of several blocks ,
> which is defined as below :
>
>
> Start
> <content>
> <content>
> ......
> <content>
> End
>
This can be matched as follows
# open file, don't read as a whole
while (<IN>){
## Read all blocks starting with Start and end at first End
if ( /^Start/ .. /^End/ ){
print if /dma/;
}
}
Check for more info 'man perlop' => look for the range operator.
Aukjan.
------------------------------
Date: 31 May 2007 06:25:01 -0700
From: samuel <samuelzhng@gmail.com>
Subject: Re: Multiple Line Pattern Match problem
Message-Id: <1180617901.009622.220330@i13g2000prf.googlegroups.com>
On May 31, 5:40 pm, Aukjan van Belkum <auk...@vanbelkum.no.spam.nl>
wrote:
> samuel wrote:
> > Hi All,
>
> > Now I need to analyze a file which is composed of several blocks ,
> > which is defined as below :
>
> > Start
> > <content>
> > <content>
> > ......
> > <content>
> > End
>
> This can be matched as follows
>
> # open file, don't read as a whole
>
> while (<IN>){
>
> ## Read all blocks starting with Start and end at first End
> if ( /^Start/ .. /^End/ ){
> print if /dma/;
> }
>
> }
>
> Check for more info 'man perlop' => look for the range operator.
>
> Aukjan.
Thanks Aukjan,
This did work and can print out all the lines where there are keyword
dma in.
But How to do if the block is like below :
Start
<content_without_keyword_dma>
......
<content_with_keyword_dma>
......
<content_without_keyword_dma>
End
And I need to print out both all the contents (both lines w and w/o
keyword dma) for the block where there are <content_with_keyword_dma>
there ?
Samuel
------------------------------
Date: 31 May 2007 06:31:19 -0700
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: Multiple Line Pattern Match problem
Message-Id: <1180618279.827135.206230@p77g2000hsh.googlegroups.com>
On May 31, 9:25 am, samuel <samuelz...@gmail.com> wrote:
> But How to do if the block is like below :
>
> Start
> <content_without_keyword_dma>
> ......
> <content_with_keyword_dma>
> ......
> <content_without_keyword_dma>
> End
>
> And I need to print out both all the contents (both lines w and w/o
> keyword dma) for the block where there are <content_with_keyword_dma>
> there ?
my $x = do { local $/; <DATA> };
while ( $x =~ /^Start(.*?)^End/smg ) {
defined and /dma/ and print for my $y = $1;
}
__DATA__
Start
cpu
End
Start
dma
End
Start
<content_without_keyword_dma>
......
<content_with_keyword_dma>
......
<content_without_keyword_dma>
End
--
Brad
------------------------------
Date: Thu, 31 May 2007 16:26:33 +0200
From: Aukjan van Belkum <aukjan@vanbelkum.no.spam.nl>
Subject: Re: Multiple Line Pattern Match problem
Message-Id: <1e07e$465edb1a$c2abfc64$2629@news2.tudelft.nl>
samuel wrote:
> On May 31, 5:40 pm, Aukjan van Belkum <auk...@vanbelkum.no.spam.nl>
> wrote:
>> samuel wrote:
>>> Hi All,
>>> Now I need to analyze a file which is composed of several blocks ,
>>> which is defined as below :
>>> Start
>>> <content>
>>> <content>
>>> ......
>>> <content>
>>> End
>> This can be matched as follows
>>
>> # open file, don't read as a whole
>>
>> while (<IN>){
>>
>> ## Read all blocks starting with Start and end at first End
>> if ( /^Start/ .. /^End/ ){
>> print if /dma/;
>> }
>>
>> }
>>
>> Check for more info 'man perlop' => look for the range operator.
>>
>> Aukjan.
>
> Thanks Aukjan,
>
> This did work and can print out all the lines where there are keyword
> dma in.
>
> But How to do if the block is like below :
>
> Start
> <content_without_keyword_dma>
> ......
> <content_with_keyword_dma>
> ......
> <content_without_keyword_dma>
> End
>
> And I need to print out both all the contents (both lines w and w/o
> keyword dma) for the block where there are <content_with_keyword_dma>
> there ?
So you have:
Start
bla bla
dma
bla bla
End
Start
bla bla
bla bla
End
etc ...
You could catch all data of for the block, and check on the 'End' if you
want to keep the block
e.g.
while ( <IN> ){
my @block;
my $dma = 0;
if ( /^Start/ .. /^End/ ){
push @block, $_;
$dma = 1 if m/dma/;
if ( /^End/ ){
print @block if $dma;
$dma = 0;
}
}
}
Aukjan
------------------------------
Date: 31 May 2007 01:08:01 -0700
From: Davidcollins001@gmail.com
Subject: Re: SendMail.pm: smtp and gmail
Message-Id: <1180598881.368719.58240@k79g2000hse.googlegroups.com>
Hi Martien, I have tried both, initially without using the Host label
(I thought it might need it since that would seem logical) but I still
get a cannot connect.
Hi Tad, I deleted the rest of the message because it only says what
line the error is on, which is the line of code containing
Net::SMTP::SSL
------------------------------
Date: Thu, 31 May 2007 13:53:27 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: stumped by graphics display problem...
Message-Id: <f3mk0m$e36$1@reader2.panix.com>
I need to generate and view a large number of data plots. My plan
for this was to have a loop that at each iteration would generate
the plot, display it, and wait for keyboard input before proceeding
to the next iteration. (FWIW, this code is to run on a remote
Linux system, and the display should take place on a local Mac OS
X workstation running an X11 server.)
The code I've written succeeds in displaying the graph, but somehow
the displaying of the graph the script's execution, so the script
does not get to request for keyboard input to move on to the next
iteration.
The relevant portion of the code is shown below. (In this snippet
I have omitted all error checking and other such details for clarity;
still, I confirmed that this simplified version of the code displays
the behavior I described above.) The place where the problem occurs
is indicated with "###".
# unbuffer selected output handle (STDOUT)
$| = 1;
for my $data ( @data ) {
my $chart = GD::Graph::lines->new( 400, 300 );
$chart->set( transparent => 0 );
# next line produces a GD::Image object
my $gd = $chart->plot( $data );
open my $IMG, '|-', 'display';
print $IMG $gd->png;
# display won't happen without this line!
close $IMG;
### script stalls before executing the next line
print "Press any key to continue... ";
ReadMode 'cbreak';
ReadKey( 0 );
ReadMode 'normal';
print "\n";
}
If someone could explain to me why this snippet is not behaving as
I expect it to I'd be most thankful.
BTW, I found it surprising that I needed to close the $IMG handle
for the display to appear; turning on autoflush on the handle was
not enough.
Maybe the problem with the code above has more to do with a
peculiarity of the 'display' command (from the ImageMagick suite)
than with the Perl code? If so, is there a better way to achieve
what I trying to do?
Any suggestions or comments would be much appreciated.
TIA!
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: 31 May 2007 00:28:15 -0700
From: Michael Yang <Michael.Yxf@gmail.com>
Subject: Re: Using CPAN to install Mail::Box module
Message-Id: <1180596494.917767.62080@z28g2000prd.googlegroups.com>
On May 31, 2:14 pm, "Sisyphus" <sisyph...@nomail.afraid.org> wrote:
> "Michael Yang" <Michael....@gmail.com> wrote in message
>
> news:1180582247.735060.325790@d30g2000prg.googlegroups.com...
> .
> .
>
> > "execute_tests" is not exported by the Test::Harness module
>
> Looking at %prereq in the Mail::Box Makefile.PL you'll see that version 2.62
> (or later) of Test::Harness is required.
> I suspect you have an earlier version of Test::Harness that doesn't export
> "execute_tests" - as is the case with the version (2.56) of Test::Harness
> that I have.
>
> Updating Test::Harness should fix the problem.
>
> I would have thought that CPAN.pm would have detected this and first
> installed the latest version of Test::Harness before proceeding with
> building Mail::Box - but I don't use CPAN, so I don't really know what has
> happened there.
>
> Perhaps the latest version of Test::Harness *did* get installed, but into a
> different location than the old version, and the old version is still being
> found first ? (Dunno ... just speculating.)
>
> Cheers,
> Rob
Terrific!
Thanks a lot, Rob!
After I updated the Test::Harness module, the Mail::Box is installed
successfully.
Thanks again!
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 473
**************************************