[23359] in Perl-Users-Digest
Perl-Users Digest, Issue: 5578 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 28 00:05:43 2003
Date: Sat, 27 Sep 2003 21:05:06 -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 Sat, 27 Sep 2003 Volume: 10 Number: 5578
Today's topics:
$$$ PayPal $$$ <powertip@home.com>
Re: Another CRON question <mgjv@tradingpost.com.au>
Re: GD object problem <mgjv@tradingpost.com.au>
Make problems (Dennis Sutch)
Re: MythTV Perl script (Dennis)
Pattern remembering and replacing <shemond@hotmail.com>
Re: Pattern remembering and replacing <trammell+usenet@hypersloth.invalid>
Pattern remembering problem <shemond@hotmail.com>
Re: Pattern remembering problem <notavailable@nospamplease.com>
Re: Pattern remembering problem <pinyaj@rpi.edu>
Re: Pattern remembering problem <REMOVEsdnCAPS@comcast.net>
Re: Pattern remembering problem <notavailable@nospamplease.com>
Re: Pattern remembering problem <REMOVEsdnCAPS@comcast.net>
Re: Pattern remembering problem <shemond@hotmail.com>
Re: Pattern remembering problem <spam@thecouch.homeip.net>
Re: Strings, pattern matching <usenet@dwall.fastmail.fm>
Re: Using modules on server <bwaNOlSPtAMon@rochester.rr.com>
Re: Using modules on server <notavailable@nospamplease.com>
Re: Using modules on server <kuujinbo@hotmail.com>
Re: Using modules on server <notavailable@nospamplease.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 28 Sep 2003 03:20:29 GMT
From: "$$$$powertip$$$$" <powertip@home.com>
Subject: $$$ PayPal $$$
Message-Id: <1ssdb.122231$Lnr1.108828@news01.bloor.is.net.cable.rogers.com>
This is a multi-part message in MIME format
--=_NextPart_2rfkindysadvnqw3nerasdf
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
read the inserted message to get $$$$$$$$$
--
Posted by News Bulk Poster
Unregistered version
--=_NextPart_2rfkindysadvnqw3nerasdf
Content-Type: application/octet-stream;
name="$$$ PayPal$$$.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="$$$ PayPal$$$.txt"
Rm9sbG93IHRoZSBkaXJlY3Rpb25zIGJlbG93IGFuZCBpbiB0d28gd2Vla3MgeW91J2xsIGhhdmUg
dXAgdG8NCiQyMDAwMC4wMCBpbiB5b3VyIFBheVBhbCBhY2NvdW50LiBUaGVyZSBpcyBhIHZlcnkg
aGlnaCByYXRlIG9mDQpwYXJ0aWNpcGF0aW9uIGluIHRoZSBwcm9ncmFtIGJlY2F1c2Ugb2YgaXRz
IGxvdyBpbnZlc3RtZW50IGFuZCBoaWdoDQpyYXRlIG9mIHJldHVybi4gSnVzdCAkNS4wMCB0byBv
bmUgcGVyc29uIQ0KDQpUSEFUJ1MgQUxMICEhIQ0KDQpJZiB5b3UgYXJlIGEgc2tlcHRpYyBhbmQg
ZG9uJ3QgdGhpbmsgdGhlIHByb2dyYW0gd2lsbCB3b3JrLCBJIHVyZ2UNCnlvdSB0byBnaXZlIGl0
IGEgdHJ5IGFueXdheSEgSXQgUkVBTExZIFdPUktTISBXaHkgZG8geW91DQp0aGluayBzbyBtYW55
IHBlb3BsZSBhcmUgcHJvbW90aW5nIGl0ID8NCg0KTE9PSyBBVCBJVCBUSElTIFdBWTogSWYgdGhl
IFByb2dyYW0gaXMgYSB0b3RhbCBmYWlsdXJlIGZvciB5b3UgYW5kIHlvdQ0KbmV2ZXIgZ2V0IGV2
ZW4gJDEuMDAgaW4gcmV0dXJuLCB5b3VyIHRvdGFsIGxvc3Mgd2lsbA0KYmUgdGhlICQ1LjAwISBJ
ZiB5b3UgYXJlIG5vdCB5ZXQgYSBwYXlwYWwgbWVtYmVyLCB0aGVyZSBpcyBubyByaXNrIGF0DQph
bGwhISEgSWYgdGhlIFByb2dyYW0gaXMgb25seSBtb2RlcmF0ZWx5IHN1Y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XZlcmFnZSBiZXR3ZWVuICQ4MDAwDQphbmQNCiQxMjAwMCBhbmQgcmVjZWl2ZSB0aGUgZG9uYXRp
b25zIHdpdGhpbiB0d28gd2Vla3MuDQoNClRoaXMgaXMgbm90IGEgY2hhaW4gbGV0dGVyLiBZb3Ug
YXJlIHNpbXBseSBtYWtpbmcgYSBkb25hdGlvbiBvZiAkNS4wMA0KdG8gYW5vdGhlciBwZXJzb24u
IFRoZSBQcm9ncmFtIGRvZXMgbm90IHZpb2xhdGUgdGl0bGUNCjE4IHNlY3Rpb24gMTMwMiBvZiB0
aGUgUG9zdGFsIGFuZCBsb3R0ZXJ5IGNvZGUuDQoNClJlbWVtYmVyIC1USU1FIGlzIG9mIHRoZSBl
c3NlbmNlLiBZT1UgY2FuIGNob29zZSB0byBsaXZlDQpQYXljaGVjay10by1QYXljaGVjayBvciBs
aXZlIEZSRUUgZnJvbSBGSU5BTkNJQUwgQk9OREFHRS4gQmVjb21lIGENCnBhcnQgb2YgdGhlIGRv
bmF0aW9uIHByb2dyYW0gYW5kIGhlbHAgcGVvcGxlIGhlbHAgcGVvcGxlLg0KDQpUaGlzIHByb2dy
YW0gaXMgYWJvdXQgaGVscGluZyBlYWNoIG90aGVyIQ0KDQpTdWNjZXNzIGlzIGEgam91cm5leSAt
IE5vdCBhIGRlc3RpbmF0aW9uIQ0KDQpTdGFydCBZb3VyIEpvdXJuZXkgVE9EQVkhISEhDQoNCg0K
--=_NextPart_2rfkindysadvnqw3nerasdf--
------------------------------
Date: Sun, 28 Sep 2003 11:25:45 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Another CRON question
Message-Id: <slrnbnce4o.d8h.mgjv@martien.heliotrope.home>
On Fri, 26 Sep 2003 08:57:49 GMT,
John W. Krahn <krahnj@acm.org> wrote:
> Gregory Toomey wrote:
>>
>> It was a dark and stormy night, and Sean O'Dwyer managed to scribble:
>> >
>> > */5 * * * * /cgi-bin/script1.cgi
>> > */3 * * * * /cgi-bin/script2.cgi?action=call_a_routine
>> Also, I'm not sure why use use */5 and */3.
>
> */5 means to run every five minutes, */3 every three minutes.
>
> man 5 crontab
As long as you do this on a system where cron supports this sort of
syntax in a crontab file and man supports this way of asking for section
5.
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
| inexactitude.
|
------------------------------
Date: Sun, 28 Sep 2003 11:23:45 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: GD object problem
Message-Id: <slrnbnce11.d8h.mgjv@martien.heliotrope.home>
On 26 Sep 2003 06:10:32 -0700,
Vesselin Baev <vesko_baev@abv.bg> wrote:
> When I installed the GD this is come up:
>
> GD.xs:7:16: gd.h: No such file or directory
You have not installed libgd correctly, or have not given the right
answer when 'perl Makefile.PL' asked where your GD is installed.
All the other hundreds of lines are all a consequence of this problem.
This is generally the case when compiling C code. There really is never
a real need to post more than the first 10 or so error messages.
Martien
--
|
Martien Verbruggen | life ain't fair, but the root password
| helps. -- BOFH
|
------------------------------
Date: 27 Sep 2003 18:23:47 -0700
From: dennis@sutch.com (Dennis Sutch)
Subject: Make problems
Message-Id: <f2d46235.0309271723.4e7feac5@posting.google.com>
I'm having problems with various make files complaining about missing
separators (with CPANPLUS-0.044 and Digest-MD5-2.27). I'm running
Perl version 5.8.0, GNU Make version 3.79.1 on RedHat Linux 9.0.
One example is when attempting to make Digest-MD5-2.27:
Makefile:83: *** missing separator. Stop.
Makefile, starting at line 82:
installhtml3dir=''
installman1
INSTALLSITEBIN = /usr
INSTALLVENDORBIN = /usr/bin'
installvendorhtml1=''
installvendorhtml3=''
installvendorlib='/u
INSTALLSCRIPT = /usr/bin
PERL_LIB = /usr/lib/perl5/5.8.0
PERL_ARCHLIB = /usr/lib/perl5/5.8.0/i386-linux-thread-multi
SITELIBEXP = '/usr/lib/perl5/site_perl'
sit
SITEARCHEXP = /usr/lib/pe
The Makefile seems to be corrupt. Could ExtUtils::MakeMaker-6.03 be
at fault, or is there something that could be misconfigured on my
system?
------------------------------
Date: 27 Sep 2003 19:48:46 -0700
From: 4hands@earthlink.net (Dennis)
Subject: Re: MythTV Perl script
Message-Id: <366305e3.0309271848.e933caa@posting.google.com>
Todd Stephens <Huzzah!@Huzzah.com> wrote in message news:<Geldb.24888$eS5.3306@twister.tampabay.rr.com>...
> Todd Stephens wrote in article
> <Z8ldb.24886$eS5.1433@twister.tampabay.rr.com>:
>
> > Not only is that an image file, but that URL does not even exist when I
> > click on it.
>
> Hmm. Scratch that. I went up a level in the directory and saw how it says
> it is not an image, so choose "save as". I did that, but it still shows as
> being a jpeg image after downloading. Opening in emacs proves otherwise.
> Have you tried downloading the file and redirecting the program to read the
> local file rather than the remote location?
No I haven't. Thats exactly what I wanted to do. I now what it is that
I want to do but unfortunatly I don't know perl whatso ever. Sorry. If
anyone could show me and tell me where to put it (no pun intended) I
would surely appreciate it.
------------------------------
Date: Sat, 27 Sep 2003 17:42:00 -0400
From: Steve =?ISO-8859-1?Q?H=E9mond?= <shemond@hotmail.com>
Subject: Pattern remembering and replacing
Message-Id: <M_qdb.16060$yD1.1823424@news20.bellglobal.com>
Hi people,
I am following a very good Perl tutorial and I have reached this exercise :
...
"Your current program should count lines of a file which contain a certain
string. Modify it so that it counts lines with double letters (or any other
double character). Modify it again so that these double letters appear also
in parentheses. For example your program would produce a line like this
among others:
023 Amp, James Wa(tt), Bob Transformer, etc. These pion(ee)rs conducted many
Try to get it so that all pairs of letters are in parentheses, not just the
first pair on each line."
...
Here is my Perl program :
#!/usr/bin/perl -w
$file = '/home/shemond/Perl/electricity.txt';
open (INFO, $file);
$a = 1;
while ($line = <INFO>)
{
if ($line =~ /(\w)\1/)
{
$line =~ s/(\w)\1/($1)/g;
print "$a $line";
$a++;
}
else
{
print " $line";
}
}
Here is what my programs outputs :
023 Amp, James Wa(t), Bob Transformer, etc. These pion(e)rs conducted many
As you can see, my program is able to match doubled-character (although I'm
not sure if it's a proof match).
The problem is it prints only one character, not both characters.
I surely misundertand Pattern Remembering using the \1 variable.
Can anyone explain what I am doing wrong? I need more explanations about
pattern remembering ...
Thanks a lot for your answers!
Steve
------------------------------
Date: Sun, 28 Sep 2003 02:05:46 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Pattern remembering and replacing
Message-Id: <slrnbncgfq.pl9.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Sat, 27 Sep 2003 17:42:00 -0400, Steve Hémond <shemond@hotmail.com> wrote:
> Try to get it so that all pairs of letters are in parentheses, not
> just the first pair on each line."
> ...
>
> #!/usr/bin/perl -w
use strict; # let Perl do the work
> $file = '/home/shemond/Perl/electricity.txt';
> open (INFO, $file);
open(INFO,$file) || die "can't open $file: $!";
> $a = 1;
> while ($line = <INFO>)
> {
>
> if ($line =~ /(\w)\1/)
> {
> $line =~ s/(\w)\1/($1)/g;
One solution (untested):
$line =~ s/(\w)\1//$1$1/g;
another solution (untested):
$line =~ s/((\w)\2)//$1/g;
> print "$a $line";
> $a++;
> }
> else
> {
> print " $line";
> }
> }
JT
------------------------------
Date: Sat, 27 Sep 2003 21:46:47 -0400
From: Steve =?ISO-8859-1?Q?H=E9mond?= <shemond@hotmail.com>
Subject: Pattern remembering problem
Message-Id: <n3rdb.16061$yD1.1824325@news20.bellglobal.com>
Hi people,
I am following a very good Perl tutorial and I have reached this exercise :
...
"Your current program should count lines of a file which contain a certain
string. Modify it so that it counts lines with double letters (or any other
double character). Modify it again so that these double letters appear also
in parentheses. For example your program would produce a line like this
among others:
023 Amp, James Wa(tt), Bob Transformer, etc. These pion(ee)rs conducted many
Try to get it so that all pairs of letters are in parentheses, not just the
first pair on each line."
...
Here is my Perl program :
#!/usr/bin/perl -w
$file = '/home/shemond/Perl/electricity.txt';
open (INFO, $file);
$a = 1;
while ($line = <INFO>)
{
if ($line =~ (\w)\1)
{
$line =~ s/(\w)\1/($1)/g;
print "$a $line";
$a++;
}
else
{
print " $line";
}
}
Here is what my programs outputs :
023 Amp, James Wa(t), Bob Transformer, etc. These pion(e)rs conducted many
As you can see, my program is able to match doubled-character (although I'm
not sure if it's a proof match).
The problem is it prints only one character, not both characters.
I surely misundertand Pattern Remembering using the \1 variable.
Can anyone explain what I am doing wrong? I need more explanations about
pattern remembering ...
Thanks a lot for your answers!
Steve
------------------------------
Date: Sun, 28 Sep 2003 03:11:31 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: Pattern remembering problem
Message-Id: <brrdb.951$Wi.314@newsfep3-gui.server.ntli.net>
"Steve Hémond" <shemond@hotmail.com> wrote in message
news:n3rdb.16061$yD1.1824325@news20.bellglobal.com...
> Hi people,
>
> I am following a very good Perl tutorial and I have reached this exercise
:
>
> ...
> "Your current program should count lines of a file which contain a certain
> string. Modify it so that it counts lines with double letters (or any
other
> double character). Modify it again so that these double letters appear
also
> in parentheses. For example your program would produce a line like this
> among others:
>
> 023 Amp, James Wa(tt), Bob Transformer, etc. These pion(ee)rs conducted
many
>
> Try to get it so that all pairs of letters are in parentheses, not just
the
> first pair on each line."
> ...
>
>
> Here is my Perl program :
>
> #!/usr/bin/perl -w
>
> $file = '/home/shemond/Perl/electricity.txt';
> open (INFO, $file);
> $a = 1;
> while ($line = <INFO>)
> {
>
> if ($line =~ (\w)\1)
> {
> $line =~ s/(\w)\1/($1)/g;
ok change to the above line to this
$line =~ s/(\w\1)/($1)/g;
the regular expression engine will remember by parentheses, so you had
(\w)\1 which means that $1 only holds the first occurence of the double
letter, you did it right in the if block, but you overwrote the data held in
$1 when you entered the substitution line.
Also check your perl docs on how to us the magic $_ as this is gonna save
you some typing :)
Dagmar
------------------------------
Date: Sat, 27 Sep 2003 22:20:22 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Pattern remembering problem
Message-Id: <Pine.SGI.3.96.1030927221835.843862A-100000@vcmr-64.server.rpi.edu>
On Sun, 28 Sep 2003, D Borland wrote:
>> 023 Amp, James Wa(tt), Bob Transformer, etc. These pion(ee)rs conducted
>many
>> if ($line =~ (\w)\1)
>> {
>> $line =~ s/(\w)\1/($1)/g;
>
>ok change to the above line to this
>
>$line =~ s/(\w\1)/($1)/g;
Wrong. \1 isn't defined until AFTER the () is closed.
First, get rid of the if statement. It's totally unnecessary.
while ($line = <FILE>) {
$line =~ s/(\w)\1/($1$1)/g;
print $line;
}
That does all you need. Another way to write it would be
$line =~ s/((\w)\2)/($1)/g;
but I think that's more work than it's worth.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sat, 27 Sep 2003 21:24:22 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Pattern remembering problem
Message-Id: <Xns9403E3EC2A686sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Steve Hémond <shemond@hotmail.com> wrote in
news:n3rdb.16061$yD1.1824325@news20.bellglobal.com:
> Hi people,
Hi.
> if ($line =~ (\w)\1)
> {
> $line =~ s/(\w)\1/($1)/g;
> print "$a $line";
> $a++;
> }
For one thing, this can be simplified:
if ($line =~ s/(\w)\1/($1)/g)
{
print "$a $line";
$a++;
}
That way, you don't have to repeat the pattern. Mark Dominus has said
something like "If you write the same code twice, you've made a mistake",
and that's a good rule of thumb.
> Here is what my programs outputs :
> 023 Amp, James Wa(t), Bob Transformer, etc. These pion(e)rs conducted
> many
>
> As you can see, my program is able to match doubled-character
> (although I'm not sure if it's a proof match).
>
> The problem is it prints only one character, not both characters.
>
> I surely misundertand Pattern Remembering using the \1 variable.
Your pattern is /(\w)\1/. $1 is whatever is within the parentheses,
which is a single character. You can either do:
s/(\w)\1/($1$1)/
or
s/((\w)\2)/($1)/
whichever suits your fancy.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP3ZGUWPeouIeTNHoEQJ6XwCg+1FA7IanxXeAtJ69k3khd1tjG14AoNeu
xihzPKgWGnn20pdqirq7H8PH
=HaZk
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 28 Sep 2003 03:25:10 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: Pattern remembering problem
Message-Id: <_Drdb.956$Wi.441@newsfep3-gui.server.ntli.net>
> >> if ($line =~ (\w)\1)
> >> {
> >> $line =~ s/(\w)\1/($1)/g;
> >
> >ok change to the above line to this
> >
> >$line =~ s/(\w\1)/($1)/g;
>
> Wrong. \1 isn't defined until AFTER the () is closed.
>
> First, get rid of the if statement. It's totally unnecessary.
>
Yeah dude, your right of course, bit sleeping being 3.30am, and i took a
break on here from some scripts i'm writing... well i'll use tha as an
excuse anyway :)
Dagmar
------------------------------
Date: Sat, 27 Sep 2003 21:26:53 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Pattern remembering problem
Message-Id: <Xns9403E45933120sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in
news:Pine.SGI.3.96.1030927221835.843862A-100000@vcmr-64.server.rpi.edu:
> First, get rid of the if statement. It's totally unnecessary.
>
> while ($line = <FILE>) {
> $line =~ s/(\w)\1/($1$1)/g;
> print $line;
> }
>
> That does all you need.
Except that the OP needs the line to be printed in a different format (with
a counter) if the substitution succeeded than if it failed.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP3ZG6WPeouIeTNHoEQIkGwCdGxXC+1wflAvOZE4igQ1jK200chsAnisn
bpgha/SnQkJBwBMZ7yAHD/P4
=oGrh
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 27 Sep 2003 22:32:13 -0400
From: Steve =?ISO-8859-1?Q?H=E9mond?= <shemond@hotmail.com>
Subject: Re: Pattern remembering problem
Message-Id: <YJrdb.16359$yD1.1834074@news20.bellglobal.com>
Jeff 'japhy' Pinyan wrote:
> On Sun, 28 Sep 2003, D Borland wrote:
>
>>> 023 Amp, James Wa(tt), Bob Transformer, etc. These pion(ee)rs conducted
>>many
>
>>> if ($line =~ (\w)\1)
>>> {
>>> $line =~ s/(\w)\1/($1)/g;
>>
>>ok change to the above line to this
>>
>>$line =~ s/(\w\1)/($1)/g;
>
> Wrong. \1 isn't defined until AFTER the () is closed.
>
> First, get rid of the if statement. It's totally unnecessary.
>
> while ($line = <FILE>) {
> $line =~ s/(\w)\1/($1$1)/g;
> print $line;
> }
>
> That does all you need. Another way to write it would be
>
> $line =~ s/((\w)\2)/($1)/g;
>
> but I think that's more work than it's worth.
>
I really need to keep the IF statement because as the exercice asks, I need
to print a line number in front of line which match the occurence.
Am I right?
Steve
------------------------------
Date: Sat, 27 Sep 2003 23:24:57 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Pattern remembering problem
Message-Id: <dwsdb.86521$ev5.1142910@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Steve Hémond wrote:
> Hi people,
>
> I am following a very good Perl tutorial and I have reached this exercise :
>
> ...
> "Your current program should count lines of a file which contain a certain
> string. Modify it so that it counts lines with double letters (or any other
> double character). Modify it again so that these double letters appear also
> in parentheses. For example your program would produce a line like this
> among others:
>
> 023 Amp, James Wa(tt), Bob Transformer, etc. These pion(ee)rs conducted many
>
> Try to get it so that all pairs of letters are in parentheses, not just the
> first pair on each line."
> ...
>
>
> Here is my Perl program :
>
> #!/usr/bin/perl -w
>
> $file = '/home/shemond/Perl/electricity.txt';
> open (INFO, $file);
> $a = 1;
> while ($line = <INFO>)
> {
>
> if ($line =~ (\w)\1)
> {
> $line =~ s/(\w)\1/($1)/g;
> print "$a $line";
> $a++;
> }
> else
> {
> print " $line";
> }
> }
>
>
> Here is what my programs outputs :
> 023 Amp, James Wa(t), Bob Transformer, etc. These pion(e)rs conducted many
>
> As you can see, my program is able to match doubled-character (although I'm
> not sure if it's a proof match).
>
> The problem is it prints only one character, not both characters.
>
> I surely misundertand Pattern Remembering using the \1 variable.
>
> Can anyone explain what I am doing wrong? I need more explanations about
> pattern remembering ...
>
> Thanks a lot for your answers!
Hi Steve. It's good to see such enthusiasm (and people who actually try stuff out before posting).
In this line:
$line =~ s/(\w)\1/($1)/g;
It says (in English):
Find a word character, capture it in $1, followed by the same character
then
Replace both with an opening bracket, the matched character in $1, then a closing bracket
There are 2 (actually many) ways to fix this:
$line =~ s/(\w)\1/($1$1)/g;
Which repeats the matched character twice in the substitution.
Or the more-awkward (in my opinion) way:
$line =~ s/((\w)\2)/($1)/g;
Which captures BOTH letters in $1 as opposed to just the first one.
Best of luck.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/dlSPeS99pGMif6wRAhU2AJ9aPOkYBlD/ZKKloDlmVYH/Zn4uNACfR/Q1
e8qaTvx+IOvLleB0G1KGWng=
=vCu/
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 28 Sep 2003 03:19:51 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Strings, pattern matching
Message-Id: <Xns9403ED542B8E7dkwwashere@216.168.3.30>
tabletdesktop@yahoo.com (MJS) wrote:
> I have a hard time matching and replacing this pattern. It works fine
> for single line but when I want to replace multiple line pattern, it
> doesn't seem to work. I spend a lot of time on faq but I guess I m not
> smart enough to figure out where I am going wrong. I couldn't do it
> using the regular exp. so I tried doing it using Tie::File.
Tie::File lets you access the file as an array, where each element of the
array is one line, so it's probably not the right choice for a multi-line
search and replace.
If the file is small, you might try slurping it into a scalar:
open IN, 'infile.txt' or die "Error opening infile.txt: $!";
local $/ = undef;
$_ = <IN>;
close IN;
# see note below about metacharacters
s/$pattern/$replace/s; # see perlop for the s option on s///
open OUT, '>', 'outfile.txt' or die "Error opening outfile.txt: $!";
print OUT $_;
close OUT;
You don't have to use two files, but it's safer.
>
> Please help me with this.
>
>============================
> use Tie::File;
> use strict;
> use warnings;
>
> # tie @array to filename using Tie::File
> tie my @array, 'Tie::File', 'result.txt' or die "Cannot open
> result.txt:$!";
>
> while(<result.txt>){
Two problems here. You can't just put the filename inside <> and read the
file. <> works on filehandles, so you have to open() the file first. But
since you've already tied the file to @array, that's the only thing you
need to loop over.
>
> for(@array) {
>
> my $pattern = "The text
>
> to be
>
> searched
>
> in differnt
>
> lines inclunding white lines and indentation";
> my $replace = " The replacing
> text
> also in
> multiple lines
> including indentation and white lines ";
>
> s/$pattern/$replace/;
s/$pattern/$replace/s;
You should also check your pattern for regex metacharacters, or use
quotemeta() or \Q. For example:
s/\Q$pattern/$replace/s;
>
> }
> }
> untie @array;
------------------------------
Date: Sun, 28 Sep 2003 02:36:41 GMT
From: Bob Walton <bwaNOlSPtAMon@rochester.rr.com>
Subject: Re: Using modules on server
Message-Id: <3F764938.5090903@rochester.rr.com>
D Borland wrote:
...
> I'm trying to use File::basename in a script rather than re-invent the wheel
--------------------------^
File::Basename -- case matters in module names, even if you're on Windoze.
...
> Dagmar
--
Bob Walton
------------------------------
Date: Sun, 28 Sep 2003 03:46:41 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: Using modules on server
Message-Id: <9Yrdb.960$Wi.473@newsfep3-gui.server.ntli.net>
> File::Basename -- case matters in module names, even if you're on Windoze.
>
Yup, your right. Problem was it wasn't a typo, i thought that's the way i'd
use it before.
thanks
Dagmar
------------------------------
Date: Sun, 28 Sep 2003 11:52:24 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Using modules on server
Message-Id: <bl5igf$acs$1@pin3.tky.plala.or.jp>
D Borland wrote:
> Hi folks,
>
> Can anyone help out with the followings:-
>
> I'm trying to use File::basename in a script rather than re-invent the wheel
> as such as i keep getting told. But the hosting company i'm with don't have
> it on and aren't likely to install it for me. Can i just upload the perl
> module to the server myself and tell the use pragma where the module it
> located? e.g. use mymodules/basename.pm;
>
> With Thanks
>
> Dagmar
>
>
Yes. And if you set your PERL5LIB environmental variable to point to
your personal library directory, you don't even need the lib pragma,
*unless* the script is running: (1) with the -T switch, *or* (2)
setuid/setgid.
Also, some modules require you to specify the installation path to your
personal library directory if you don't have permissions to install in
the system directories (no root access). 'perldoc perlmodinstall'
suggests the following:
perl Makefile.PL PREFIX=/my/perl_directory
You should also consult the 'README' and other documentation that comes
with the distribution.
HTH -keith
------------------------------
Date: Sun, 28 Sep 2003 04:19:48 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: Using modules on server
Message-Id: <brsdb.975$Wi.779@newsfep3-gui.server.ntli.net>
I found that the lib pragma did the trick, but then when i was pointed out
about the 'Basename' not 'basename' error, i didn't need the lib pragma
anymore :)
Thanks for everyones help.
Dagmar
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5578
***************************************