[28876] in Perl-Users-Digest
Perl-Users Digest, Issue: 120 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 9 23:26:35 2007
Date: Fri, 9 Feb 2007 20:25:49 -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 Fri, 9 Feb 2007 Volume: 11 Number: 120
Today's topics:
Pretty Format Report Nested Objects Insanity <please@nospam.net>
Re: Pretty Format Report Nested Objects Insanity (NOSPAM)
Re: Pretty Format Report Nested Objects Insanity <please@nospam.net>
Re: Pretty Format Report Nested Objects Insanity anno4000@radom.zrz.tu-berlin.de
Printing strings worlman385@yahoo.com
Re: Printing strings <jurgenex@hotmail.com>
Re: Printing strings xhoster@gmail.com
Re: Printing strings <spamtrap@dot-app.org>
Re: Printing strings anno4000@radom.zrz.tu-berlin.de
Re: problem GD and my package Random->Random::new <dha@panix.com>
Problem with system command <nospam@nospam.com>
Re: Problem with system command <bik.mido@tiscalinet.it>
Re: Problem with system command <rkb@i.frys.com>
Re: Problems dealing with dates in Windows <rvtol+news@isolution.nl>
Re: Problems dealing with dates in Windows <ayaz@dev.slash.null>
questions about RE! <gsuxin@gmail.com>
Re: questions about RE! <1usa@llenroc.ude.invalid>
Re: questions about RE! <spamtrap@dot-app.org>
Re: questions about RE! <gsuxin@gmail.com>
Re: questions about RE! usenet@DavidFilmer.com
Re: questions about RE! <wyzelli@yahoo.com>
Re: questions about RE! <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Feb 2007 21:03:36 -0800
From: Xiong Changnian <please@nospam.net>
Subject: Pretty Format Report Nested Objects Insanity
Message-Id: <please-6B682D.21033502022007@free.teranews.com>
I am handling a number of complex objects -- the best way to build them
seems to be to have some of the HoH values be other objects. On the
other hand, some values just belong to the given object itself -- I call
these "whole-object data". (There is a graph theory slant to this but
it's not all about that. There's a game theory side, too.)
For example, a Map includes both Node and Edge objects. It also has data
that pertains directly to the Map -- for instance, it's NAME. I put all
the whole-object data in a hash with the key SELF. So, the name itself
would be accessed with:
$the_name = $somemap->{SELF}{NAME};
or, by method:
$the_name = $somemap->name;
Of course, the "name" sub uses the first syntax. I actually have only
one such sub; it's defined in the superclass. Every one of my objects
has a second-level hash key {SELF}{NAME}, so one accessor method serves
all.
Going down to an Edge object, it contains, as always, a SELF hash with a
NAME key, a COLOR key, and so forth. All this data pertains to the whole
object. The Edge also contains a primary key (on the same level as SELF)
called MATRIX; this points to an AoA (for reasons I'd hope are obvious).
So far, so fine. I have some accessor methods defined in the superclass
to which both Map and Edge (as well as others) belong, such as methods
to get at NAME and COLOR -- properties common to most of my objects. I
have other accessors defined in their respective
classes/packages/modules/files, such as "between":
$boolean = $someedge->between($i, $j);
which hits:
return $self-->{MATRIX}[$i][$j];
So far, so fine. To save these objects to disk, I use Data::Dumper. It's
not entirely compact but with indent and quotes turned off it's okay.
Best of all, I load back into the object simply by eval-ing the
datafile. Neither my Save nor my Load routine need to know anything at
all about the actual structure, so I can fiddle around with it freely.
It's even possible (though risky) to load a datafile created by an
earlier version of my script.
Data::Dumper works pretty well for this purpose but its output is not
especially readable; I can trade disk space for more readability by
setting Indent = 1 or 2 but matrices span hundreds of file lines that
way. So, I need to build a routine to display my Map object (hopefully
reusably, any of my objects) by printing to a report file in a pretty
format.
Ideally, I don't want to have to rewrite the report routine every time I
upgrade the object! The stupid way would be to have a rigid procedure in
which I took one thing at a time from the object and printed it. This
would depend on the structure of the object never changing -- bad.
My current approach is better. I do this (at several levels):
sub report_sets {
my @keys = sort keys %{ $ref->{SETS} };
foreach (@keys) {
&{"report_" . lc($_)} ($ref->{SETS}{$_})
or die ("No report subroutine for $_.");
};
};
So, I have a bunch of little subs, each of which is able to pretty
format a particular kind of data, each of which is named after the hash
key that points to that kind of data. These dig their way down until
they hit a sub that prints out one small chunk of data.
*THREE* problems:
(1) The sort keys operation puts, for example, MATRIX before SELF. For
readability in the report, I'd prefer a definite, predefined order for
the various subobjects and substructures -- I'd rather see the
whole-object data first before the big matrix. I suppose I can do this
with a custom sort routine.
(2) That there is a call to a subroutine by symbolic reference. To make
it work, I have to permit
no strict "refs";
for the duration of these shenanigans. I feel that's Bad in general; a
risky operation. Twenty years ago, I recall implementing a jump table
(in 8085 assembler) by constructing the destination address and shoving
it directly into the program counter via PCHL. Needless to say, it was
the first thing that broke.
(3) This seems to lead to a great number of very similar subs. This
suggests that I'm doing something stupidly (that is, not lazy enough).
My *thought* is to declare every level in the data structure as a
well-defined object, so Map will consist of a Self object, a Sets object
that contains ( Node objects which each contain a Self object ) and (
Edge objects which each contain a Self object and a Matrix object) and
so on. They all inherit from a superclass and Self, say, has its own
little method for pretty-reporting its own contents.
I don't know if I want to do this. Right now, each object has some
meaning beyond code implementation -- Maps, Nodes, Edges. This *thought*
of mine looks like 8 or more objects that all get rolled up into Map.
Each internal object will have to have its own package, its own file.
Will this be inefficient? Unmaintainable? Is there a better, lazier
approach?
Xiong
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Sat, 03 Feb 2007 01:32:46 -0600
From: "Mumia W. (NOSPAM)" <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Pretty Format Report Nested Objects Insanity
Message-Id: <eq1dhp$4o7$1@aioe.org>
On 02/02/2007 11:03 PM, Xiong Changnian wrote:
> I am handling a number of complex objects -- the best way to build them
> seems to be to have some of the HoH values be other objects. On the
> other hand, some values just belong to the given object itself [...]
>
> Ideally, I don't want to have to rewrite the report routine every time I
> upgrade the object! The stupid way would be to have a rigid procedure in
> which I took one thing at a time from the object and printed it. This
> would depend on the structure of the object never changing -- bad.
> [...]
The conventional wisdom of object-oriented programming is that each
object should know how to take care of itself to a certain extent. In
this case, that means that each object should have a "to_string" method
that returns a string representation of the object's data.
> My current approach is better. I do this (at several levels):
>
> sub report_sets {
> my @keys = sort keys %{ $ref->{SETS} };
> foreach (@keys) {
> &{"report_" . lc($_)} ($ref->{SETS}{$_})
> or die ("No report subroutine for $_.");
> };
> };
>
> So, I have a bunch of little subs, each of which is able to pretty
> format a particular kind of data,
And that suggests that you're not doing it the right OO-way.
> each of which is named after the hash
> key that points to that kind of data. These dig their way down until
> they hit a sub that prints out one small chunk of data.
>
> *THREE* problems:
>
> [ problems snipped ]
> My *thought* is to declare every level in the data structure as a
> well-defined object, [...]
That sounds like the best option for you in the long run.
--
Windows Vista and your freedom in conflict:
http://techdirt.com/articles/20061019/102225.shtml
------------------------------
Date: Sat, 03 Feb 2007 12:17:40 -0800
From: Xiong Changnian <please@nospam.net>
Subject: Re: Pretty Format Report Nested Objects Insanity
Message-Id: <please-EDF475.12173903022007@free.teranews.com>
Maybe (probably) I said too much in last post. Sorry.
Let's just reduce this to: I plan to implement a deeply nested object
such that each level of the "real" object hash is its own little
internal object which contains its own method to report (stringify)
itself.
My concern is that this will require me to write a very large number of
classes, each with its own package and file. I can see how the final
product might comprise 30 or 50 classes, since I plan to have a dozen
different "real" objects, all deeply nested. I can have all the internal
objects inherit, of course, so these need not be large files.
Concerns (sorry if they're basic):
1) Too many files to maintain. The least little change that needs to be
made to all of them and it's not lazy anymore. Too easy to overlook a
file. Unwieldy use block.
2) Don't know exactly how to write the use blocks and base class
statements. Worry about circular weirdness at compile time. Can't decide
to inherit along the same tree as the objects or have all the little
guys inherit from one hub.
Can I write some sort of object manager that at least hides the worst of
this inside one thing? I'd prefer to stay away from Class::Struct and so
forth; they seem too rigid. But if there's a CPAN module I *must* have,
please let me know.
One possibility (?) is to declare multiple classes in one file. Don't
know if this is wise or even doable. Would take pressure off (1) but
might make (2) even worse.
Feel free to direct me to online OO resources. As I browse around, I see
a lot of highly specific, advanced articles, many elementary tutorials,
but very little general discussion of OO Perl beyond the basics.
--
Xiong Changnian
xiong102ATxuefangDOTcom
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 7 Feb 2007 13:39:49 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Pretty Format Report Nested Objects Insanity
Message-Id: <52u355F1qbe5qU1@mid.dfncis.de>
Xiong Changnian <please@nospam.net> wrote in comp.lang.perl.misc:
> Maybe (probably) I said too much in last post. Sorry.
>
> Let's just reduce this to: I plan to implement a deeply nested object
> such that each level of the "real" object hash is its own little
> internal object which contains its own method to report (stringify)
> itself.
>
> My concern is that this will require me to write a very large number of
> classes, each with its own package and file. I can see how the final
> product might comprise 30 or 50 classes, since I plan to have a dozen
> different "real" objects, all deeply nested. I can have all the internal
> objects inherit, of course, so these need not be large files.
>
> Concerns (sorry if they're basic):
>
> 1) Too many files to maintain. The least little change that needs to be
> made to all of them and it's not lazy anymore. Too easy to overlook a
> file. Unwieldy use block.
Put them all in one (or a few) files.
> 2) Don't know exactly how to write the use blocks and base class
> statements. Worry about circular weirdness at compile time. Can't decide
> to inherit along the same tree as the objects or have all the little
> guys inherit from one hub.
Inside the multi-class file you'll have to put "use base 'SomeClass';"
after the definition of "SomeClass". You can also set @ISA directly,
then you don't have that limitation.
Circularities in the @ISA chain are detected by Perl.
How you organize the inheritance tree I must leave to you.
> Can I write some sort of object manager that at least hides the worst of
> this inside one thing? I'd prefer to stay away from Class::Struct and so
> forth; they seem too rigid. But if there's a CPAN module I *must* have,
> please let me know.
>
> One possibility (?) is to declare multiple classes in one file. Don't
> know if this is wise or even doable. Would take pressure off (1) but
> might make (2) even worse.
I think it's the way to go in your case. Multi-class files are standard
and pose no extra problems in a pure OO approach (as opposed to
exporting modules).
Put a bare block around each class definition, so you isolate lexicals
and can re-use variable names. So the structure would be:
{
package Class1;
# definition of Class1
}
# ...
{
package Class9;
use base qw( Class1 Class6);
# definition of Class9
}
# etc.
__END__
Anno
------------------------------
Date: Wed, 07 Feb 2007 18:57:40 -0800
From: worlman385@yahoo.com
Subject: Printing strings
Message-Id: <jb4ls2he6ssqlo7lvnvca1me7ve7krpr0t@4ax.com>
why the follow print statement only print the number$C
$C = 15;
print "Number of C is " + $C +"\n";
------------------------------
Date: Thu, 08 Feb 2007 03:18:27 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Printing strings
Message-Id: <7Ewyh.9130$xu4.1291@trndny04>
worlman385@yahoo.com wrote:
> why the follow print statement only print the number$C
>
> $C = 15;
>
> print "Number of C is " + $C +"\n";
What do you expect to be printed if not the value of $C?
The numerical value of the other two summands in your addition are both 0,
so 0 + 15 + 0 should result in 15, shouldn't it?
jue
------------------------------
Date: 08 Feb 2007 03:05:04 GMT
From: xhoster@gmail.com
Subject: Re: Printing strings
Message-Id: <20070207220531.920$B1@newsreader.com>
worlman385@yahoo.com wrote:
> why the follow print statement only print the number$C
>
> $C = 15;
>
> print "Number of C is " + $C +"\n";
If you turned on warnings, you would know.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 07 Feb 2007 23:02:10 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Printing strings
Message-Id: <m2odo5xpod.fsf@Sherm-Pendleys-Computer.local>
worlman385@yahoo.com writes:
> why the follow print statement only print the number$C
>
> $C = 15;
>
> print "Number of C is " + $C +"\n";
You're using numerical addition. The numeric values of the two strings
are 0, so essentially what you're doing above is:
print 0 + $C + 0;
If you want to concatenate strings, you have to use the right operator
for that - this isn't C++ or Java, where the "+" operator is overloaded
to do everything except make coffee. :-)
The string concatenation operator is "." (without the quotes), so what
you wanted to do is:
print "Number of C is " . $C . "\n";
Another way to do that is what Perl calls "interpolation". When you use
a double-quoted string, you can use variables directly in the string:
print "Number of C is $C\n";
Compare this with the output from single-quoted form, which doesn't do
the interpolation:
print 'Number of C is $C\n';
And finally, concatenating a bunch of strings together just to print the
result isn't the most efficient way to do it. You can also pass a series
of arguments to print(), which will print them one after another:
print "Number of C is", $C, "\n";
To be honest though, you'd have to print a few million strings to notice
the difference in most circumstances.
For details, have a look at:
perldoc perlop
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 8 Feb 2007 09:21:40 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Printing strings
Message-Id: <5308d4F1qcb8kU1@mid.dfncis.de>
Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> worlman385@yahoo.com writes:
>
> > why the follow print statement only print the number$C
> >
> > $C = 15;
> >
> > print "Number of C is " + $C +"\n";
[...]
> The string concatenation operator is "." (without the quotes), so what
> you wanted to do is:
>
> print "Number of C is " . $C . "\n";
[...]
> And finally, concatenating a bunch of strings together just to print the
> result isn't the most efficient way to do it. You can also pass a series
> of arguments to print(), which will print them one after another:
>
> print "Number of C is", $C, "\n";
^^
You want a blank there.
> To be honest though, you'd have to print a few million strings to notice
> the difference in most circumstances.
In my view it isn't efficiency so much as the principle to use the
simplest possible tool. Since print() has concatenation built in,
using the dot operator falls clearly in that category.
Anno
------------------------------
Date: Sun, 4 Feb 2007 05:17:32 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: problem GD and my package Random->Random::new
Message-Id: <slrnesar3c.4ln.dha@panix2.panix.com>
On 2007-01-22, J. Gleixner <glex_no-spam@qwest-spam-no.invalid> wrote:
> john.swilting wrote:
>
>> my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
> [...]
>> '104','105','106','107','108','109','110');
>
> You can make that much shorter..
> push( @liste, 1 .. 110);
Out of curiosity, why the push rather than just an assignment?
Also, the original example used strings, rather than numbers, fwtw.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Perl should only be studied as a second language. A good first
language would be English. - Larry Wall
------------------------------
Date: Thu, 8 Feb 2007 17:36:49 -0000
From: "Vic Russell" <nospam@nospam.com>
Subject: Problem with system command
Message-Id: <eqfn7n$lf2$1$8302bc10@news.demon.co.uk>
Hi,
I am launching an external program as follows (Windows XP OS):-
system 'start', 'notepad.exe';
If I shutdown my program whilst leavin (in this case) Notepad running and
restart it again it exhibits strange behaviour. If I shut down Notepad
before running the program again, all is OK. It is a little difficult to
describe the "strange behaviour" here (it would take a lot of text) but my
simple question is; how do I completely disassociate the system launched
application from my program in order to avoid this problem?
Regards,
Vic
------------------------------
Date: Thu, 08 Feb 2007 23:40:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Problem with system command
Message-Id: <ni9ns2lg7e8uk5ukr7hp6kvejllefegbjt@4ax.com>
On Thu, 8 Feb 2007 17:36:49 -0000, "Vic Russell" <nospam@nospam.com>
wrote:
>If I shutdown my program whilst leavin (in this case) Notepad running and
>restart it again it exhibits strange behaviour. If I shut down Notepad
>before running the program again, all is OK. It is a little difficult to
>describe the "strange behaviour" here (it would take a lot of text) but my
Yet, it would be interesting to know what it is. By any chance, may
this be an instance of the infamous unicode bug also described on np's
page @ Wikipedia:
http://en.wikipedia.org/wiki/Notepad#Unicode_detection
?
>simple question is; how do I completely disassociate the system launched
>application from my program in order to avoid this problem?
I think some Win32 specific module would be a better bet.
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: 9 Feb 2007 09:10:53 -0800
From: "Ron Bergin" <rkb@i.frys.com>
Subject: Re: Problem with system command
Message-Id: <1171041053.803113.220600@s48g2000cws.googlegroups.com>
On Feb 8, 9:36 am, "Vic Russell" <nos...@nospam.com> wrote:
> Hi,
>
> I am launching an external program as follows (Windows XP OS):-
>
> system 'start', 'notepad.exe';
>
[snip]
> simple question is; how do I completely disassociate the system launched
> application from my program in order to avoid this problem?
>
> Regards,
>
> Vic
http://search.cpan.org/~jdb/libwin32-0.26/Process/Process.pm
------------------------------
Date: Sat, 3 Feb 2007 13:02:36 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Problems dealing with dates in Windows
Message-Id: <eq21bu.1kk.1@news.isolution.nl>
Ayaz Ahmed Khan schreef:
> "GGelz":
>> $date = localtime(time);
>> printing $date gives
>> "Fri Feb 2 12:23:11 2007"
>> now, if I split it using
>> ($day, $month, $monthday, $time, $year) = split(/\s/, $date);
>
> You need '\s+' in there to cause split() to split on any number of
> consecuteive whitespaces.
Often the special ' ' does even more what one expects, because it skips
leading whitespace too, see `perldoc -f split`.
$ perl -wle '@x = split /\s+/, q{ a b c }; print scalar @x'
4
$ perl -wle '@x = split q{ }, q{ a b c }; print scalar @x'
3
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 03 Feb 2007 20:07:03 +0500
From: Ayaz Ahmed Khan <ayaz@dev.slash.null>
Subject: Re: Problems dealing with dates in Windows
Message-Id: <pan.2007.02.03.15.06.55.151581@dev.slash.null>
"Dr.Ruud" typed:
> Ayaz Ahmed Khan schreef:
>> You need '\s+' in there to cause split() to split on any number of
>> consecuteive whitespaces.
> Often the special ' ' does even more what one expects, because it skips
> leading whitespace too, see `perldoc -f split`.
>
> $ perl -wle '@x = split /\s+/, q{ a b c }; print scalar @x'
> 4
> $ perl -wle '@x = split q{ }, q{ a b c }; print scalar @x'
> 3
Didn't know that. Thanks.
--
Ayaz Ahmed Khan
A witty saying proves nothing, but saying something pointless gets
people's attention.
------------------------------
Date: 9 Feb 2007 13:21:23 -0800
From: "Flamingo" <gsuxin@gmail.com>
Subject: questions about RE!
Message-Id: <1171056082.706119.63850@a34g2000cwb.googlegroups.com>
hey all,
I'm a perl novice. now I'm studying regular expression. I have 2
questions :
1. 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.
2. For a slightly more interesting program you might like to try the
following. Suppose your program is called countlines. Then you would
call it with
./countlines
However, if you call it with several arguments, as in
./countlines first second etc
then those arguments are stored in the array @ARGV. In the above
example we have $ARGV[0] is first and $ARGV[1] is second and $ARGV[2]
is etc. Modify your program so that it accepts one argument and counts
only those lines with that string. It should also put occurrences of
this string in paretheses. So
./countlines the
will output something like this line among others:
019 But (the) greatest Electrical Pioneer of (the)m all was Thomas
Edison, who
can anyone give me some solutions. thanks a lot.
------------------------------
Date: Fri, 09 Feb 2007 21:56:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: questions about RE!
Message-Id: <Xns98D2AC5FEBC1Casu1cornelledu@127.0.0.1>
"Flamingo" <gsuxin@gmail.com> wrote in news:1171056082.706119.63850
@a34g2000cwb.googlegroups.com:
> hey all,
>
> I'm a perl novice. now I'm studying regular expression. I have 2
> questions :
>
> 1. Your current program should count lines
...
> can anyone give me some solutions. thanks a lot.
It is *your* homework. Do it yourself, or drop the class!
*PLONK*
Sinan
------------------------------
Date: Fri, 09 Feb 2007 17:52:14 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: questions about RE!
Message-Id: <m24ppveyg1.fsf@local.wv-www.com>
"Flamingo" <gsuxin@gmail.com> writes:
> hey all,
>
> I'm a perl novice. now I'm studying regular expression. I have 2
> questions :
>
> 1. Your current program should
...
>
> 2. For a slightly more interesting program you might like to try
...
> can anyone give me some solutions. thanks a lot.
How about you send me your prof's email address, so I can just send it
straight to him instead?
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 9 Feb 2007 15:42:26 -0800
From: "Flamingo" <gsuxin@gmail.com>
Subject: Re: questions about RE!
Message-Id: <1171064546.742223.217710@q2g2000cwa.googlegroups.com>
hey,
I think somebody misunderstand me. this is not course work. I just
teach myself. here is link:
http://www.comp.leeds.ac.uk/Perl/sandtr.html
I just don't know how to do that. I think maybe the tutorials online
is not enough, so I need somebody's help. Is there anyone can give me
some help? thanks a lot!
On Feb 9, 5:52 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> "Flamingo" <gsu...@gmail.com> writes:
> > hey all,
>
> > I'm a perl novice. now I'm studying regular expression. I have 2
> > questions :
>
> > 1. Your current program should
> ...
>
> > 2. For a slightly more interesting program you might like to try
>
> ...
>
> > can anyone give me some solutions. thanks a lot.
>
> How about you send me your prof's email address, so I can just send it
> straight to him instead?
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net
------------------------------
Date: 9 Feb 2007 16:05:26 -0800
From: usenet@DavidFilmer.com
Subject: Re: questions about RE!
Message-Id: <1171065926.284949.282020@v45g2000cwv.googlegroups.com>
On Feb 9, 3:42 pm, "Flamingo" <gsu...@gmail.com> wrote:
> I think somebody misunderstand me. this is not course work. I just
> teach myself
That's fine, but you won't teach yourself anything if WE do the
tutorial examples. Give it a try yourself. If you have problems, post
the code that you've written and somebody will probably give you a
hand.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Sat, 10 Feb 2007 00:19:59 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: questions about RE!
Message-Id: <Pc8zh.5373$sd2.1695@news-server.bigpond.net.au>
"Flamingo" <gsuxin@gmail.com> wrote in message
news:1171056082.706119.63850@a34g2000cwb.googlegroups.com...
> hey all,
>
> I'm a perl novice. now I'm studying regular expression. I have 2
> questions :
>
> 1. 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.
>
>
> 2. For a slightly more interesting program you might like to try the
> following. Suppose your program is called countlines. Then you would
> call it with
>
> ./countlines
>
> However, if you call it with several arguments, as in
>
> ./countlines first second etc
>
> then those arguments are stored in the array @ARGV. In the above
> example we have $ARGV[0] is first and $ARGV[1] is second and $ARGV[2]
> is etc. Modify your program so that it accepts one argument and counts
> only those lines with that string. It should also put occurrences of
> this string in paretheses. So
>
> ./countlines the
>
> will output something like this line among others:
>
> 019 But (the) greatest Electrical Pioneer of (the)m all was Thomas
> Edison, who
>
> can anyone give me some solutions. thanks a lot.
1) s/(..)/(\1)/ig
2) What have you done so far?
P
------------------------------
Date: Sat, 10 Feb 2007 00:32:44 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: questions about RE!
Message-Id: <Mo8zh.44520$Y6.6211@edtnps89>
Peter Wyzl wrote:
>
> 1) s/(..)/(\1)/ig
You probably meant:
s/((.)\2)/($1)/g
Or:
s/(.)\1/($1$1)/g
There are no letters in the pattern for the /i option to ignore case on and \1
should only be used *inside* a regular expression.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
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 120
**************************************