[25533] in Perl-Users-Digest
Perl-Users Digest, Issue: 7777 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 14 06:05:42 2005
Date: Mon, 14 Feb 2005 03:05:18 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Feb 2005 Volume: 10 Number: 7777
Today's topics:
Directory search eyal.susser@gmail.com
Re: Directory search <tintin@invalid.invalid>
Re: Directory search <toreau@gmail.com>
How to make a regex substitution repeat until there are <sptest@71broadway.info>
Re: How to make a regex substitution repeat until there <abigail@abigail.nl>
Installing a cgi script without shell access (The Duke of Dunstable)
Re: Installing a cgi script without shell access <tintin@invalid.invalid>
Re: Process word occurances in Bible? <see.sig@rochester.rr.com>
Re: Process word occurances in Bible? ioneabu@yahoo.com
Re: Process word occurances in Bible? <dave_frank@hotmail.com>
Record Hash Data Structure (Newbie) rajasekaran.natarajan@gmail.com
Re: Record Hash Data Structure (Newbie) chris-usenet@roaima.co.uk
Re: Record Hash Data Structure (Newbie) rajasekaran.natarajan@gmail.com
Regular expression to match particular lines between ma (MENTAT)
Re: Regular expression to match particular lines betwee (MENTAT)
Re: Regular expression to match particular lines betwee <news@chaos-net.de>
Re: Regular expression to match particular lines betwee (MENTAT)
Re: Regular expression to match particular lines betwee <news@chaos-net.de>
Setting RTS with Win32::SerialPort (Klaus Kleiner)
Re: The Problem with Perl <bart.lateur@pandora.be>
vi "power tools" for Perl coding? <jkrugman345@yahbitoo.com>
Re: vi "power tools" for Perl coding? ioneabu@yahoo.com
Re: vi "power tools" for Perl coding? <news@chaos-net.de>
Re: vi "power tools" for Perl coding? <kim@schulz.dk>
Re: Who can help me write a perl script to extract the <SeaSeagle@hotmail.com>
Re: Who can help me write a perl script to extract the <SeaSeagle@hotmail.com>
Re: Who can help me write a perl script to extract the <kkeller-usenet@wombat.san-francisco.ca.us>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Feb 2005 00:50:21 -0800
From: eyal.susser@gmail.com
Subject: Directory search
Message-Id: <1108371021.337878.283700@c13g2000cwb.googlegroups.com>
Hi,
I'm working on a Fedora Core 3 machine. I am also a perl newbie. I
would like to write a script that iterates through directories and
finds files with specific attributes.
I wrote a subroutine called scan:
sub scan
{
$dirname = shift;
open(DIRAHNDLE , $filename);
@contents = <$dirname . "/*">
close(DIRHANDLE);
foreach $member (@contents)
{
if(-d $member)
print("Dir: " . $dirname . "/" . $member);
else
print("File: " . $member);
}
}
This was just for testing. I ran it on /home/username, and have
several problems:
1. I get a result like /home/username/home/username, probably because
of the . directory
2. I get a list of all the files and directories under / ! Why is
that?
3. So how do I write a script that does what I want? I wanted to use
recursion, but with these wacky results, it would lead to an infinite
loop!
------------------------------
Date: Mon, 14 Feb 2005 22:48:12 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Directory search
Message-Id: <37babfF58a7hjU1@individual.net>
<eyal.susser@gmail.com> wrote in message
news:1108371021.337878.283700@c13g2000cwb.googlegroups.com...
> Hi,
>
> I'm working on a Fedora Core 3 machine. I am also a perl newbie. I
> would like to write a script that iterates through directories and
> finds files with specific attributes.
> I wrote a subroutine called scan:
>
> sub scan
> {
> $dirname = shift;
> open(DIRAHNDLE , $filename);
> @contents = <$dirname . "/*">
> close(DIRHANDLE);
>
> foreach $member (@contents)
> {
> if(-d $member)
> print("Dir: " . $dirname . "/" . $member);
>
> else
> print("File: " . $member);
> }
> }
>
> This was just for testing. I ran it on /home/username, and have
> several problems:
> 1. I get a result like /home/username/home/username, probably because
> of the . directory
> 2. I get a list of all the files and directories under / ! Why is
> that?
> 3. So how do I write a script that does what I want? I wanted to use
> recursion, but with these wacky results, it would lead to an infinite
> loop!
perldoc File::Find
or write it as a shell script using the find(1) command.
------------------------------
Date: Mon, 14 Feb 2005 11:30:41 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: Directory search
Message-Id: <i5%Pd.8617$Sl3.265811@news4.e.nsc.no>
eyal.susser@gmail.com wrote:
> I'm working on a Fedora Core 3 machine. I am also a perl newbie. I
> would like to write a script that iterates through directories and
> finds files with specific attributes.
Use the excellent 'File::Find::Rule' module from CPAN.
--
Tore Aursand <tore@aursand.no>
"Leadership is doing what is right when no one is watching." (George
Van Valkenburg)
------------------------------
Date: Mon, 14 Feb 2005 03:11:31 GMT
From: "David Deutsch" <sptest@71broadway.info>
Subject: How to make a regex substitution repeat until there are no more matches?
Message-Id: <DFUPd.1644$rB3.1417403@twister.nyc.rr.com>
I am trying to write a regular expression that will do a substitution
repeatedly until there are not more matches. Specifically, let's say I want
to convert every <option> tag in a select with name "YYY" into a link. If I
use:
s|(<select name="YYY">)<select.*?>(.*?)</select>|$1<a href =
"$2">$2</a>|gs
it will only change the first select (sorry if my syntax is not quite
correct). Is there a directive I could give in this regex that will do the
substitution over and over until there are no more patterns to substitute?
Thanks,
Dave
------------------------------
Date: 14 Feb 2005 08:11:12 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to make a regex substitution repeat until there are no more matches?
Message-Id: <slrnd10n8v.ov1.abigail@alexandra.abigail.nl>
David Deutsch (sptest@71broadway.info) wrote on MMMMCLXXXV September
MCMXCIII in <URL:news:DFUPd.1644$rB3.1417403@twister.nyc.rr.com>:
[] I am trying to write a regular expression that will do a substitution
[] repeatedly until there are not more matches. Specifically, let's say I want
[] to convert every <option> tag in a select with name "YYY" into a link. If I
[] use:
[]
[] s|(<select name="YYY">)<select.*?>(.*?)</select>|$1<a href =
[] "$2">$2</a>|gs
[]
[] it will only change the first select (sorry if my syntax is not quite
[] correct). Is there a directive I could give in this regex that will do the
[] substitution over and over until there are no more patterns to substitute?
Typically, one uses
s/PATTERN/REPLACEMENT/g
or, if you want to substitute inside your replacements as well:
1 while s/PATTERN/REPLACEMENT/g
However, in your case, that won't work. Your pattern will be different.
Sure, your first option is right after the select (I presume you make
a mistake in your regex, and want options, no selects inside selects),
but your second option sure isn't.
You're much better off parsing the HTML with an HTML parser.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 13 Feb 2005 23:39:47 -0800
From: duke@douglasadams.se (The Duke of Dunstable)
Subject: Installing a cgi script without shell access
Message-Id: <aad0cc48.0502132339.661e49b1@posting.google.com>
Hi
I've downloaded the Meep!board
(http://www.standpipe.com/site/meepboard.html) cgi script. It says you
need telnet access to your cgi-bin directory, but I don't have that.
Is there anyway I can install and configure this without telnet? Can
someone help?
------------------------------
Date: Mon, 14 Feb 2005 21:58:31 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Installing a cgi script without shell access
Message-Id: <37b7e9F5al5dvU1@individual.net>
"The Duke of Dunstable" <duke@douglasadams.se> wrote in message
news:aad0cc48.0502132339.661e49b1@posting.google.com...
> Hi
>
> I've downloaded the Meep!board
> (http://www.standpipe.com/site/meepboard.html) cgi script. It says you
> need telnet access to your cgi-bin directory, but I don't have that.
> Is there anyway I can install and configure this without telnet? Can
> someone help?
Surely the authors of this wonderful script can help out....but then
again...maybe not.
The following code should be a red flag that they don't know Perl that well:
[experienced users should avert their eyes now to avoid potential long term
damage]
-------------
if ($mon < 10) { $mon = "0$mon"; }
if ($mday < 10) { $mday = "0$mday"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
-------------
system("sort -n -r $datafile.bak > $datafile");
flock(NEWDATA,8);
-------------
if ($origpost = $query->param('origpost')) {
$hidden = "<INPUT TYPE=\"hidden\" NAME=\"origpost\"
VALUE=\"$origpost\">";
}
else {
$hidden = "";
}
--------------
s/NAME\=\"title\"/NAME\=\"title\" VALUE\=\"$title\"/io;
s/NAME\=\"contact\"/NAME\=\"contact\" VALUE\=\"$contact\"/io;
s/NAME\=\"email\"/NAME\=\"email\" VALUE\=\"$email\"/io;
--------------
# get starting line number to view from $datafile
$linenumber = $query->param('keywords');
#skip line until $linenumber is reached
if ($linenumber > 1) {
while(<DATABASE>) {
if (--$linenumber <= 1) { last; }
}
}
-------------
# read next $listlength messages
$list = "";
$c = 0;
while(<DATABASE>) {
($ID,$date,$title,$contact,$post) = split(/\t/);
$list = join("\n",$list,"<STRONG>$ID</STRONG> $date <A
HREF=\"view.cgi?$ID\">$title</A> - $contact<BR>");
if (++$c > ($listlength - 1)) { last; }
}
---------------
open(POSTNUM,"$message_number");
while(<POSTNUM>) { $mess_num = $_; }
close(POSTNUM);
---------------
------------------------------
Date: Mon, 14 Feb 2005 02:31:00 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Process word occurances in Bible?
Message-Id: <E3UPd.6817$nC5.3693@twister.nyroc.rr.com>
Anno Siegel wrote:
> Bob Walton <see.sig@rochester.rr.com> wrote in comp.lang.perl.misc:
>
>>Bob Walton wrote:
>>
>>
>>>David Frank wrote:
>>>
>>>...
>>>
>>>
>>>>Can someone translate/process below so that I can post the
>>>>source/results in these 2 newsgroups?
>>>
>>>...
>>
>>Hmmmm...running "ioneabu"'s program (with very slight
>>modifications) shows that line-by-line processing is very much
>>superior to processing a file slurp in a single string like I did
>>(I'm surprised -- I'll have to remember this):
>
>
> The program has a bug and is less efficient than it could be.
...
> Anno
Yep. The following version is a bit faster:
use strict;
use warnings;
use Benchmark;
my $st =new Benchmark;
my $fn = "bible12.txt";
open (INF, $fn) or die "error: $!";
my %words;
my $total;
while(<INF>){
s/'//g;
y/A-Za-z/ /c;
y/A-Z/a-z/;
my @w=split ' ';
$total+=@w;
@words{@w}=1;
}
my $unique=keys %words;
my $t = new Benchmark;
print "Total = $total\n";
print "Unique = $unique\n";
$t=timestr(timediff($t,$st));
print "Seconds = $t\n";
d:\junk>perl junk517a.pl
Total = 789781
Unique = 12691
Seconds = 4 wallclock secs ( 3.97 usr + 0.02 sys = 3.99 CPU)
on a 1 GHz Athlon with 100 MHz memory.
I am still surprised my first slurp-mode program took so
incredibly much longer. Any ideas why?
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 13 Feb 2005 18:54:37 -0800
From: ioneabu@yahoo.com
Subject: Re: Process word occurances in Bible?
Message-Id: <1108349677.656571.97340@f14g2000cwb.googlegroups.com>
Anno Siegel wrote:
> A for-loop also slurps the whole file. Use a while-loop for
line-by-line
> processing.
>
> > {
> > s/'//g;
> > s/[^A-Za-z]+/ /g;
>
> If speed is an issue, prefer tr/// to s///. lc() in the next line is
> called for each word. Another tr/// outside the loop can do the
same.
> I'd also split the line on white space instead of repeatedly
matching.
> What is the /i for?
>
> > $total++ and $words{lc $1}++ while /([a-z]+)/gi;
suppose the first word is Apple. It won't match because the A is not
in a-z unless you have the /i modifier. I guess this would be better:
$total++ and $words{lc $1}++ while /([A-Za-z]+)/g;
> "$total++" and the count in %words should be independent statements,
> not connected by "and". If the first word in the file is a unique
> word, you'll miss it. "$total++" will return 0 when it should be
> counted.
I don't understand this part. Can you give an example. I know you
must be right, but I keep reading it over and over and missing it.
>
> > }
> > my $unique;
> > for (keys %words) {$unique++ if $words{$_}} ;
>
> What on earth is this?
>
> my $unique = keys %words;
Very cool.
>
> The total could also be calculated from the individual counts
(provided
> the counting bug is fixed):
>
> my $total = 0;
> $total += $_ for values %words;
>
wow
> Combining these suggestions should make it noticeably faster.
>
> Anno
I don't know what the OP's motive was, but this kind of thing is fun.
Thank you very much for the expert suggestions and corrections.
wana
------------------------------
Date: Mon, 14 Feb 2005 05:03:01 -0500
From: "David Frank" <dave_frank@hotmail.com>
Subject: Re: Process word occurances in Bible?
Message-Id: <42107751$0$39295$ec3e2dad@news.usenetmonster.com>
"David Frank" <dave_frank@hotmail.com> wrote in message
news:420f700d$0$38924$ec3e2dad@news.usenetmonster.com...
>
>
>
> Impressive,
> however what if further processing is then desired, are the individual
> unique words, counts
> available for searching etc.. in their respective arrays?
> They will be in other language's solutions.
> Can you get a runtime with 4.xx precision?
>
My challenge stated that 2 arrays would be loaded with words and their
counts.
e.g. the #occurances of "god" in the bible appears to be 4446 times.
Cant Perl produce these 2 arrays for further processing (write unique words
and occurances to a file?
------------------------------
Date: 14 Feb 2005 00:58:23 -0800
From: rajasekaran.natarajan@gmail.com
Subject: Record Hash Data Structure (Newbie)
Message-Id: <1108371503.480805.255500@o13g2000cwo.googlegroups.com>
Hi all,
I am trying to write a program which extracts the data feom a text file
and stores it in a data structure. But there is some mistake and I
couldnt able to get over with.
I am a newbie (my 25th program or so) in Perl and I have checked the
oreilly books and perldoc but I have some limitations to understand to
be frank. (i mean unable to get the thing correct after reading)
below I had given my script and if anybody can thorw some light I will
be greatfull. Thanks in advance.
#!/usr/sbin/perl -w
#extracts grid data from test.dat and stores in dataStructure
$file1 = "test.dat";
open(CLIST,"$file1") || die ("Cant open input file \"$file1\", Unable
to Find, Check the file name and path");
while($line= <CLIST>){
if ($line =~ m/^GRID/) {
($gridNo,$cp,$xcor,$ycor,$coor,$cd)= unpack("x8 A8 A8 A8 A8
A8",$line);
$record = {
GRIDNO => $gridNo,
cp => $cp,
xcor => $xcor,
ycor => $ycoor,
zcor => $zcoor,
cd => $cd,
};
$grid{ $record->{GRIDNO} } = $record;
}
while( $gridNo = each %grid) {
printf "%s is grid no\n",$grid->{$gridNo};
}
}
close(CLIST);
------------------------------
Date: Mon, 14 Feb 2005 09:41:23 +0000
From: chris-usenet@roaima.co.uk
Subject: Re: Record Hash Data Structure (Newbie)
Message-Id: <3b86e2-t4o.ln1@moldev.cmagroup.co.uk>
rajasekaran.natarajan@gmail.com wrote:
> I am trying to write a program which extracts the data from a text file
> and stores it in a data structure. But there is some mistake and I
> couldn't able to get over with.
* Have you tried with "use strict", and explicitly declaring the
variables? If not, why not?
* What does your sample data look like?
* What are you expecting to happen?
* What actually happens?
Chris
------------------------------
Date: 14 Feb 2005 03:00:44 -0800
From: rajasekaran.natarajan@gmail.com
Subject: Re: Record Hash Data Structure (Newbie)
Message-Id: <1108378844.812581.180730@l41g2000cwc.googlegroups.com>
I have got the mistake!
------------------------------
Date: 13 Feb 2005 19:34:42 -0800
From: chaitanyag@hotmail.com (MENTAT)
Subject: Regular expression to match particular lines between markers
Message-Id: <5a286c02.0502131934.181ccc0b@posting.google.com>
Hi,
I am trying to write a regular expression that extracts all the
comment lines between two specified markers in a text. An example
snippet is given below. (comments start with ";")
[MRCP_SERVER] ;MRCP server format:
<Server_IP_Address>:<Server_Port>
; <Server_Port> is 554 for Nuance, 4900 for
Speechworks
; Each server should be specified on a separate
line
;123.123.123.1:554 ; server1
tadlir01:4900 ; comment 1
tadlir02:4900 ; comment 2
[DisableVAD] ; Disables VAD in the TX streamer
I want the output to look like:
[MRCP_SERVER] ;MRCP server format:
<Server_IP_Address>:<Server_Port>
; <Server_Port> is 554 for Nuance, 4900 for
Speechworks
; Each server should be specified on a separate
line
;123.123.123.1:554 ; server1
[DisableVAD] ; Disables VAD in the TX streamer
basically, everything between [MRCP_SERVER] and [DisableVAD] that
starts on a line beginning with ";"
I tried using s/(\[MRCP_SERVER\].*)^[^;].*$(\[DisableVAD\])/marker $1
marker $2/ms. But this doesn't seem to work. What am I doing wrong?
isn't ^[^;].*$ the syntax for everything on a line not beginnign with
";"?
Note also that the input could be of the format
[MRCP_SERVER] ;MRCP server format:
<Server_IP_Address>:<Server_Port>
; <Server_Port> is 554 for Nuance, 4900 for
Speechworks
; Each server should be specified on a separate
line
;123.123.123.1:554 ; server1
tadlir01:4900 ; clk_osr_dev
;some other comment can interrupt, but the next line should be caught
tadlir02:4900 ; clk_osr_test
[DisableVAD] ; Disables VAD in the TX streamer
Any help, in the form of heavily commented regular expressions would
be much appreciated.
------------------------------
Date: 13 Feb 2005 22:34:29 -0800
From: chaitanyag@hotmail.com (MENTAT)
Subject: Re: Regular expression to match particular lines between markers
Message-Id: <5a286c02.0502132234.320db5cd@posting.google.com>
chaitanyag@hotmail.com (MENTAT) wrote in message news:<5a286c02.0502131934.181ccc0b@posting.google.com>...
> Hi,
>
> I am trying to write a regular expression that extracts all the
> comment lines between two specified markers in a text. An example
> snippet is given below. (comments start with ";")
>
> [MRCP_SERVER] ;MRCP server format:
> <Server_IP_Address>:<Server_Port>
> ; <Server_Port> is 554 for Nuance, 4900 for
> Speechworks
> ; Each server should be specified on a separate
> line
> ;123.123.123.1:554 ; server1
> tadlir01:4900 ; comment 1
> tadlir02:4900 ; comment 2
>
> [DisableVAD] ; Disables VAD in the TX streamer
>
> I want the output to look like:
>
> [MRCP_SERVER] ;MRCP server format:
> <Server_IP_Address>:<Server_Port>
> ; <Server_Port> is 554 for Nuance, 4900 for
> Speechworks
> ; Each server should be specified on a separate
> line
> ;123.123.123.1:554 ; server1
>
> [DisableVAD] ; Disables VAD in the TX streamer
>
> basically, everything between [MRCP_SERVER] and [DisableVAD] that
> starts on a line beginning with ";"
>
> I tried using s/(\[MRCP_SERVER\].*)^[^;].*$(\[DisableVAD\])/marker $1
> marker $2/ms. But this doesn't seem to work. What am I doing wrong?
> isn't ^[^;].*$ the syntax for everything on a line not beginnign with
> ";"?
>
> Note also that the input could be of the format
>
> [MRCP_SERVER] ;MRCP server format:
> <Server_IP_Address>:<Server_Port>
> ; <Server_Port> is 554 for Nuance, 4900 for
> Speechworks
> ; Each server should be specified on a separate
> line
> ;123.123.123.1:554 ; server1
> tadlir01:4900 ; clk_osr_dev
> ;some other comment can interrupt, but the next line should be caught
> tadlir02:4900 ; clk_osr_test
>
> [DisableVAD] ; Disables VAD in the TX streamer
>
> Any help, in the form of heavily commented regular expressions would
> be much appreciated.
Sorry, formatting error...guess i should have previewed before
posting. To avoid any confusion what i meant was
[MRCP_SERVER] ;MRCP server format:<Server_IP_Address>:<Server_Port>
; <Server_Port> is 554 for Nuance, 4900 for
Speechworks
; Each server should be specified on a separate
line
;123.123.123.1:554 ; server1
tadlir01:4900 ; comment 1
tadlir02:4900 ; comment 2
[DisableVAD] ; Disables VAD in the TX streamer
I want the output to look like:
[MRCP_SERVER] ;MRCP server format:
<Server_IP_Address>:<Server_Port>
; <Server_Port> is 554 for Nuance, 4900
forSpeechworks
; Each server should be specified on a separateline
;123.123.123.1:554 ; server1
[DisableVAD] ; Disables VAD in the TX streamer
------------------------------
Date: Mon, 14 Feb 2005 07:49:13 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Regular expression to match particular lines between markers
Message-Id: <slrnd10if9.djv.news@maki.homeunix.net>
MENTAT wrote :
> Hi,
>
> I am trying to write a regular expression that extracts all the
> comment lines between two specified markers in a text. An example
> snippet is given below. (comments start with ";")
>
This is what I would do.
I'll appreciate any comments an suggestions for improovement, since I'm
rather new to Perl.
--- code start ---
#!/usr/bin/perl
# description=
use warnings;
use strict;
while (my $line = <DATA>) {
print $line and match() if $line =~ /\[MRCP_SERVER\]/;
}
sub match {
while (my $line =<DATA>) {
print $line if $line =~ /^;/;
print $line and last if $line =~ /\[DisableVAD\]/;
}
}
__DATA__
some other line
and still another one
[MRCP_SERVER] ;MRCP server format:
<Server_IP_Address>:<Server_Port>
; <Server_Port> is 554 for Nuance, 4900 for Speechworks
; Each server should be specified on a separate line
;123.123.123.1:554 ; server1
tadlir01:4900 ; comment 1
tadlir02:4900 ; comment 2
[DisableVAD] ; Disables VAD in the TX streamer
some other line
and still another one
--- code end ---
--- outout (long lines wrapped by newsreader) ---
[MRCP_SERVER] ;MRCP server format:
; <Server_Port> is 554 for Nuance, 4900 for
Speechworks
; Each server should be specified on a separate line
;123.123.123.1:554 ; server1
[DisableVAD] ; Disables VAD in the TX streamer
--- end output ---
HTH
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: 13 Feb 2005 22:55:56 -0800
From: chaitanyag@hotmail.com (MENTAT)
Subject: Re: Regular expression to match particular lines between markers
Message-Id: <5a286c02.0502132255.3300539@posting.google.com>
Ok, I can't format it to look just right but what i mean is
[MRCP_SERVER] ;MRCP server ...
; <Server_Port> is 554 for Nuance, ...
; Each server should be specified ...
;123.123.123.1:554 ; server1
tadlir01:4900 ; comment 1
tadlir02:4900 ; comment 2
[DisableVAD] ; Disables VAD in the TX streamer
I want the output to look like:
[MRCP_SERVER] ;MRCP server ...
; <Server_Port> is 554 for Nuance, ...
; Each server should be specified ...
;123.123.123.1:554 ; server1
[DisableVAD] ; Disables VAD in the TX streamer
chaitanyag@hotmail.com (MENTAT) wrote in message news:<5a286c02.0502131934.181ccc0b@posting.google.com>...
> Hi,
>
> I am trying to write a regular expression that extracts all the
> comment lines between two specified markers in a text. An example
> snippet is given below. (comments start with ";")
>
> [MRCP_SERVER] ;MRCP server format:
> <Server_IP_Address>:<Server_Port>
> ; <Server_Port> is 554 for Nuance, 4900 for
> Speechworks
> ; Each server should be specified on a separate
> line
> ;123.123.123.1:554 ; server1
> tadlir01:4900 ; comment 1
> tadlir02:4900 ; comment 2
>
> [DisableVAD] ; Disables VAD in the TX streamer
>
> I want the output to look like:
>
> [MRCP_SERVER] ;MRCP server format:
> <Server_IP_Address>:<Server_Port>
> ; <Server_Port> is 554 for Nuance, 4900 for
> Speechworks
> ; Each server should be specified on a separate
> line
> ;123.123.123.1:554 ; server1
>
> [DisableVAD] ; Disables VAD in the TX streamer
>
> basically, everything between [MRCP_SERVER] and [DisableVAD] that
> starts on a line beginning with ";"
>
> I tried using s/(\[MRCP_SERVER\].*)^[^;].*$(\[DisableVAD\])/marker $1
> marker $2/ms. But this doesn't seem to work. What am I doing wrong?
> isn't ^[^;].*$ the syntax for everything on a line not beginnign with
> ";"?
>
> Note also that the input could be of the format
>
> [MRCP_SERVER] ;MRCP server format:
> <Server_IP_Address>:<Server_Port>
> ; <Server_Port> is 554 for Nuance, 4900 for
> Speechworks
> ; Each server should be specified on a separate
> line
> ;123.123.123.1:554 ; server1
> tadlir01:4900 ; clk_osr_dev
> ;some other comment can interrupt, but the next line should be caught
> tadlir02:4900 ; clk_osr_test
>
> [DisableVAD] ; Disables VAD in the TX streamer
>
> Any help, in the form of heavily commented regular expressions would
> be much appreciated.
------------------------------
Date: Mon, 14 Feb 2005 08:27:21 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Regular expression to match particular lines between markers
Message-Id: <slrnd10kmp.djv.news@maki.homeunix.net>
MENTAT wrote :
[snipped 80 lines of needless repetition]
please read http://learn.to/quote
Regards
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: 14 Feb 2005 01:12:41 -0800
From: Klaus.Kleiner@gmx.net (Klaus Kleiner)
Subject: Setting RTS with Win32::SerialPort
Message-Id: <3394ad07.0502140112.122d197a@posting.google.com>
Hello,
I'm trying to set RTS via Win32::SerialPort. I'm using
Win32::SerialPort on a Windows 2000 PC
and
$PortObj->rts_active(1) or die ("Can't set RTS");
I always get the error message "Can't set RTS" so the
API call did not succeed ?
What do I need to modify RTS via this function ?
I need the RTS signal to control a RS232/RS485 converter,
not for hardware handshake.
Regards
Klaus
------------------------------
Date: Mon, 14 Feb 2005 08:41:39 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: The Problem with Perl
Message-Id: <7so011hem5n1np737q4is6niqaaojmkf37@4ax.com>
Rhugga wrote:
>In C/C++ the function foo(int x) and foo(char *) are 2 completely
>different functions, the names may seem similiar to the human reader,
>but deep down inside the nitty gritty these are basically 2 different
>functions.
I doubt that about C, There's only one foo -- you can't even have a
separate variable foo any more.
But anyway, look at CPAN: Sub::Signatures
<http://search.cpan.org/search?module=Sub::Signatures>
I doubt that it's in its final implementation form already (beta,
currently it's a source filter), but it is precisely for what you
described here.
--
Bart.
------------------------------
Date: Mon, 14 Feb 2005 03:00:12 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: vi "power tools" for Perl coding?
Message-Id: <cup47s$ldl$1@reader2.panix.com>
Let me preface this post by stressing that my intent is NOT to
start a religious vi-vs-emacs flame fest.
I have noticed that vi is *particularly* popular among Perl
programmers, and (as an Emacs enthusiast) I wonder why. I have
edited Perl code with plain ol' vim, and found the experience much
less pleasant than editing Perl with Emacs's cperl mode, but I'm
sure that, in my ignorance, I was not taking advantage of the vi
power tools for Perl coding. So my question really boils down to
what should I do to get a taste of the joys of coding (and debugging?)
Perl with vi?
TIA,
jill
P.S. Yes, I have read perldoc -q editor
P.S.2 What motivated this question was my learning about the handy
little vi sequence
:!perl -cW
for checking the syntax on a buffer of Perl code. The equivalent
in emacs is a bit more long-winded:
C-x h
M-| perl -cW
So I decided to add the following to my .emacs file (probably
re-inventing a thoroughly invented wheel):
(defun check-perl (&optional arg)
"Checks the Perl syntax in current buffer.
If the mark is set and either it is active or transient-mark-mode
is nil, the current region is checked. Otherwise the entire
buffer is checked. With a numeric argument, the check is made under
the strict pragma."
(interactive "P")
(let (start end (strict ""))
(if (and (mark)
(or mark-active
(not transient-mark-mode)))
(progn (setq start (mark ))
(setq end (point)))
(progn (setq start (point-min))
(setq end (point-max)))
)
(if arg (setq strict "-Mstrict "))
(shell-command-on-region
start end (concat "perl " strict "-Mdiagnostics -cW "))))
;; The following binds the F12 key to the check-perl command in
;; the cperl mode
(add-hook 'cperl-mode-hook (lambda ()
(local-set-key [(f12)] 'check-perl)
))
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: 13 Feb 2005 20:06:12 -0800
From: ioneabu@yahoo.com
Subject: Re: vi "power tools" for Perl coding?
Message-Id: <1108353972.352263.82930@o13g2000cwo.googlegroups.com>
J Krugman wrote:
> Let me preface this post by stressing that my intent is NOT to
> start a religious vi-vs-emacs flame fest.
>
> I have noticed that vi is *particularly* popular among Perl
> programmers, and (as an Emacs enthusiast) I wonder why. I have
> edited Perl code with plain ol' vim, and found the experience much
> less pleasant than editing Perl with Emacs's cperl mode, but I'm
> sure that, in my ignorance, I was not taking advantage of the vi
> power tools for Perl coding. So my question really boils down to
> what should I do to get a taste of the joys of coding (and
debugging?)
> Perl with vi?
>
> TIA,
>
> jill
>
I like vi because I have invested some time in learning it and emacs
seems harder to use to me. I don't use any advanced features really.
Someday, I'll get around to playing with emacs. These editors are like
musical instruments. To be useful, your fingers have to have their own
learned intelligence in picking out the commands without any concious
thought. It takes a lot of time and practice to gain that proficiency,
unlike your typical wordpad-type editor.
Asking a vi user like me to take up emacs is like asking a sax player
to take up piano. I like playing my instrument because I know how to
play it, even if you think yours is better.
wana
------------------------------
Date: Mon, 14 Feb 2005 08:18:01 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: vi "power tools" for Perl coding?
Message-Id: <slrnd10k59.djv.news@maki.homeunix.net>
J Krugman wrote :
>
>
>
> Let me preface this post by stressing that my intent is NOT to
> start a religious vi-vs-emacs flame fest.
>
> I have noticed that vi is *particularly* popular among Perl
> programmers, and (as an Emacs enthusiast) I wonder why. I have
> edited Perl code with plain ol' vim, and found the experience much
> less pleasant than editing Perl with Emacs's cperl mode, but I'm
> sure that, in my ignorance, I was not taking advantage of the vi
> power tools for Perl coding. So my question really boils down to
> what should I do to get a taste of the joys of coding (and debugging?)
> Perl with vi?
I have not used emacs enough to really be able to compare those two.
I would not even use vi nowadays but vim.
There are so many "powerfeatures" that one could write a book on it.
One I dicovered these days (I guess emacs can do this, too, however) is
directly editing files on a ftp server.
vim ftp://myserver.domain.tld/dir/file.pl
This is very useful if only some small changes have to be made.
Also you can compile vim to support perl directly within command mode.
To me, vim is something like the swiss army knife of text editing, but I
am sure emacs can also be that.
Finally a little cartoon about vi vs. emacs ;-)
http://www.io.com/~dierdorf/vi-emacs2.jpg
Regards
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: Mon, 14 Feb 2005 11:23:53 +0100
From: Kim Schulz <kim@schulz.dk>
Subject: Re: vi "power tools" for Perl coding?
Message-Id: <20050214112353.78427a4a@lifesuckz.nork.aau.dk>
On Mon, 14 Feb 2005 03:00:12 +0000 (UTC)
J Krugman <jkrugman345@yahbitoo.com> wrote:
>
>
>
> Let me preface this post by stressing that my intent is NOT to
> start a religious vi-vs-emacs flame fest.
>
> I have noticed that vi is *particularly* popular among Perl
> programmers, and (as an Emacs enthusiast) I wonder why. I have
> edited Perl code with plain ol' vim, and found the experience much
> less pleasant than editing Perl with Emacs's cperl mode, but I'm
> sure that, in my ignorance, I was not taking advantage of the vi
> power tools for Perl coding. So my question really boils down to
> what should I do to get a taste of the joys of coding (and debugging?)
> Perl with vi?
>
Besides the simple and nice stuff like indenting, syntax coloring,
autocompletion (tab-completion of known/used words) and folding I use
stuff like:
tag/Function/method/class/define list (tree in sepetate split buffer):
- http://www.vim.org/scripts/script.php?script_id=483
- http://www.vim.org/scripts/script.php?script_id=273
Selection evaluation:
- http://www.vim.org/scripts/script.php?script_id=889
Perl "Compiler":
- http://www.vim.org/scripts/script.php?script_id=56
Debugger integration:
- http://www.vim.org/scripts/script.php?script_id=663
Syntax checker:
- http://www.vim.org/scripts/script.php?script_id=1096
Execute perl:
- http://www.vim.org/scripts/script.php?script_id=281
Automate module generation:
http://www.vim.org/scripts/script.php?script_id=466
just to mention a few.
--
Kim Schulz | Want to know more about The Fundanemt CMS. Join the
Geek by nature | users and developers at linuxforum 2005.
schulz.dk | http://www.linuxforum.dk
------------------------------
Date: Mon, 14 Feb 2005 10:13:41 +0800
From: "Sea Seagle" <SeaSeagle@hotmail.com>
Subject: Re: Who can help me write a perl script to extract the pictures out of this webpage?
Message-Id: <4210081f$1@news.starhub.net.sg>
Thank you Toomey.
I downloaded wget-1.8.2 and it's in my C:\Perl directory now.
How may I install it?
The configure.bat doesn't work.
"Gregory Toomey" <nospam@bigpond.com> wrote in message
news:3790noF581qbsU2@individual.net...
> Glory Regained wrote:
>
> > http://www.pierluigisurace.it/imagerie/aatw0016.htm
> >
> > I like the pictures so much, but my Perl tricks are few.
> >
> > Thanks in advance.
>
> Far easier would be to mirror it using wget:
> http://www.gnu.org/software/wget/wget.html
>
> gtoomey
------------------------------
Date: Mon, 14 Feb 2005 10:32:34 +0800
From: "Sea Seagle" <SeaSeagle@hotmail.com>
Subject: Re: Who can help me write a perl script to extract the pictures out of this webpage?
Message-Id: <42100c8c$1@news.starhub.net.sg>
Done. I just put binary and DLL file in same directory and it worked.
Thank you anyway.
"Sea Seagle" <SeaSeagle@hotmail.com> wrote in message
news:4210081f$1@news.starhub.net.sg...
> Thank you Toomey.
>
> I downloaded wget-1.8.2 and it's in my C:\Perl directory now.
> How may I install it?
> The configure.bat doesn't work.
>
>
>
>
> "Gregory Toomey" <nospam@bigpond.com> wrote in message
> news:3790noF581qbsU2@individual.net...
> > Glory Regained wrote:
> >
> > > http://www.pierluigisurace.it/imagerie/aatw0016.htm
> > >
> > > I like the pictures so much, but my Perl tricks are few.
> > >
> > > Thanks in advance.
> >
> > Far easier would be to mirror it using wget:
> > http://www.gnu.org/software/wget/wget.html
> >
> > gtoomey
>
>
------------------------------
Date: Sun, 13 Feb 2005 20:23:26 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Who can help me write a perl script to extract the pictures out of this webpage?
Message-Id: <5nl5e2x4oj.ln2@goaway.wombat.san-francisco.ca.us>
[TOFU snipped]
On 2005-02-14, Sea Seagle <SeaSeagle@hotmail.com> wrote:
>
> I downloaded wget-1.8.2 and it's in my C:\Perl directory now.
> How may I install it?
> The configure.bat doesn't work.
Installing wget is not related to Perl. I suggest you ask on a wget
mailing list/newsgroup what to do. (Hint: you probably need cygwin,
which is also off-topic for this newsgroup.)
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information
------------------------------
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 V10 Issue 7777
***************************************