[28407] in Perl-Users-Digest
Perl-Users Digest, Issue: 9771 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 26 14:05:57 2006
Date: Tue, 26 Sep 2006 11: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 Tue, 26 Sep 2006 Volume: 10 Number: 9771
Today's topics:
Re: An interactive interpreter/shell? <robb@acm.org>
Re: An interactive interpreter/shell? <robb@acm.org>
Re: both 1 and not-1? <news12@8439.e4ward.com>
Re: both 1 and not-1? <news12@8439.e4ward.com>
Re: both 1 and not-1? (Gary E. Ansok)
Ftp via Perl cron job <bill@ts1000.us>
Re: Ftp via Perl cron job <David.Squire@no.spam.from.here.au>
Re: Ftp via Perl cron job (reading news)
Re: list vs. array <christoph.lamprecht.no.spam@web.de>
Re: list vs. array <robb@acm.org>
Re: list vs. array <christoph.lamprecht.no.spam@web.de>
Re: meaning of "child processes are reaped" anno4000@radom.zrz.tu-berlin.de
Re: meaning of "child processes are reaped" <bew_ba@gmx.net>
Re: passing multiple values into an argument as an arra <DJStunks@gmail.com>
perl -pe for blocks of lines instead of single lines <markus.dehmann@gmail.com>
Re: Reading from standard input <bik.mido@tiscalinet.it>
Re: regular expression pb. with tags <xicheng@gmail.com>
Re: sort with Perl .. <tzz@lifelogs.com>
Re: Splitting and keeping key/value <mr@sandman.net>
Re: Splitting and keeping key/value <mr@sandman.net>
Re: Splitting and keeping key/value anno4000@radom.zrz.tu-berlin.de
Re: WIn32API and keyboard <daveandniki@ntlworld.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Sep 2006 10:22:46 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Re: An interactive interpreter/shell?
Message-Id: <1159291365.842827.89090@k70g2000cwa.googlegroups.com>
Michele Dondi wrote:
> ...I see that you mention yourself psh and others pointed you to
> perl-{based,oriented} *command* shells, but since you talked about
> "Python's interactive interpreter" I thought that the closest thing
> would have been an... interactive Perl interpreter, which is what I
> pointed you to. If you do not find that satisfying, care to say why?
Yes, you're right. I'm sorry about the sarcastic reply earlier.
Here's a description of a few things that the perl interpreter doesn't
do interactively:
http://dev.perl.org/perl6/rfc/184.html
The Python interpreter offers a lot more, though. As a Python
developer, I'm used to being able to start the interpreter, instantiate
some of my new classes I've written, invoke methods, determine the
types of the objects.
The Python interpreter feels a lot like Smalltalk without the graphic
interface.
It's a common development style for Python programmers, and I was
hoping to use it with my Perl development. Here's an example of what I
mean. I'd love to find an environment that provides this kind of
convenient syntax (uses only the syntax of the language itself), plus
has these useful features in Perl. Automatic evaluation of names,
high-level user feedback, etc:
>>> class Dog (object):
... def bark(self):
... print "Woof"
...
>>> Dog
<class '__main__.Dog'>
>>> Dog.bark
<unbound method Dog.bark>
>>> chester = Dog()
>>> chester
<__main__.Dog object at 0x403d7cac>
>>> chester.bark
<bound method Dog.bark of <__main__.Dog object at 0x403d7cac>>
>>> chester.bark()
Woof
>>> type(chester)
<class '__main__.Dog'>
>>> type(Dog)
<type 'type'>
>>>
>>> aString = "This is a string"
>>> aString
'This is a string'
>>> dir(aString)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__',
'__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count',
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index',
'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind',
'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines',
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper',
'zfill']
>>> aString.upper()
'THIS IS A STRING'
>>> type(aString)
<type 'str'>
>>> type(aString.upper)
<type 'builtin_function_or_method'>
------------------------------
Date: 26 Sep 2006 10:28:09 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Re: An interactive interpreter/shell?
Message-Id: <1159291689.401202.129720@e3g2000cwe.googlegroups.com>
robb@acm.org wrote:
> ...As a Python
> developer, I'm used to being able to start the interpreter, instantiate
> some of my new classes I've written, invoke methods, determine the
> types of the objects.
>
And, I didn't get too far using the perl interpreter. Maybe I did
something wrong? But also - it's not clear to me that this kind of
work is supported:
DB<1> print "hello\n";
DB<2> use lib '/home/web/lib/perl';
DB<3> use Trillium::Info;
DB<4> my $info = Trillium::Info->new();
DB<5> $info;
DB<6> $info->is_valid_tld('lclark.edu');
Can't call method "is_valid_tld" on an undefined value at (eval
21)[/usr/local/lib/perl5/5.8.0/perl5db.pl:17] line 2.
DB<7> print $info;
DB<8>
------------------------------
Date: Tue, 26 Sep 2006 11:53:46 -0400
From: Michael Goerz <news12@8439.e4ward.com>
Subject: Re: both 1 and not-1?
Message-Id: <4nt0nvFbvidgU1@uni-berlin.de>
Xicheng Jia wrote:
> Michael Goerz wrote:
>> Okay, maybe I'm getting too tired for tonight, but ... how can
>> add_to_array *possibly* die with a filter violation (which it does)?
>> Certainly, is_filtered doesn't modify $visit -- or does it?
>
> You are right.. it does not modify your $visit.
>
>> sub add_to_array{
>> my $self = shift;
>> my $visit = shift;
>> if ( not $self->is_filtered($visit) ){
>> if ( $self->is_filtered($visit) ){die ("FILTER VIOLATION\n");}
>> }
>> }
>
> The logic is: if it's '1', it will never be '-1' or '0' again, so the
> inner 'if' in your subroutine is redundant, and the related block {die
> ("FILTER VIOLATION\n");} will never be executed.
That's exactly my point! the inner block should never be executed! I put
it in there for debugging only. My point is that the first 'if ( not
$self->is_filtered($visit) ){' should make sure that I'm only dealing
with visits where is_filtered has returned zero. Yet, as I'm puzzled to
find out, I end up with visits inside the block that violate this! I do
get the filter violation printed out, and it's totally unclear to me how
that's even possible. It's like the outer if isn't even executed.
However, sometimes it works, as this code proves (I get both correctly
filtered visits, and filter violations at some point):
if ( not $self->is_filtered($visit) ){
if ( $self->is_filtered($visit) ){die ("FILTER VIOLATION\n");}
else {print "Filtered\n"}
}
Does this explain what's going on? It's entirely incomprehensible to me,
logically.
Maybe I can extract the routine and put it in a full working test
script, to find out what's going on.
Thank you,
Michael Goerz
------------------------------
Date: Tue, 26 Sep 2006 12:47:22 -0400
From: Michael Goerz <news12@8439.e4ward.com>
Subject: Re: both 1 and not-1?
Message-Id: <4nt3sfFbuecsU1@uni-berlin.de>
Michael Goerz wrote:
> Maybe I can extract the routine and put it in a full working test
> script, to find out what's going on.
Interesting, I was able to recreate the faulty behavior in an example
script (see below). If I use generate_test_visit2(), everything works
fine, but with generate_test_visit1(), I get the filter violation. The
only difference between the two is that once $visit is local, and once
it's global. Now this may give a clue to what's going wrong, I have to
look into it, but still, I don't understand how logically the filter
violation can ever occur!!!
Xicheng, by the way, I see what confused you in your first reply: My
subject line was ambiguous. It should be 'both one and not-one', not to
be read as 'both one and not-minus-one'. Sorry about that. I hope it's
clear now what my problem is.
Thanks,
Michael
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $visit = {field1 => 1, field2 => 'foo'};
my $compiled_pattern = qr/1/;
my %excludepatterns = ('field1' => $compiled_pattern);
# Main Program
while (1){
$visit = generate_test_visit1();
print Dumper $visit;
add_to_array($visit);
}
# toggle for testing
sub generate_test_visit1{
my $visit;
if ( not exists($visit->{field1}) ){
warn "field1 doesn't exist\n";
$visit->{field1} = 0;
}
if ($visit->{field1} == 0){
$visit->{field1} = 1;
} else {
$visit->{field1} = 0;
}
return $visit;
}
# toggle for testing
sub generate_test_visit2{
if ( not exists($visit->{field1}) ){
warn "field1 doesn't exist\n";
$visit->{field1} = 0;
}
if ($visit->{field1} == 0){
$visit->{field1} = 1;
} else {
$visit->{field1} = 0;
}
return $visit;
}
sub add_to_array{
my $visit = shift;
if ( not is_filtered($visit) ){
print "accepted value $visit->{field1}\n";
if ( is_filtered($visit) ){
warn ("FILTER VIOLATION, value $visit->{field1} was not
filtered\n");
}
} else {
print "filtered value $visit->{field1}\n";
}
}
# checks if visit has to be filtered out
sub is_filtered{
my $visit = shift;
while ( my ($field, $pattern) = each %excludepatterns ){
if ( exists($visit->{$field}) ){
if ( $visit->{$field} =~ $pattern){
return 1;
}
} else {
warn "Tried to filter non-existing field.\n";
}
}
return 0;
}
------------------------------
Date: Tue, 26 Sep 2006 17:21:19 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: both 1 and not-1?
Message-Id: <efbnif$43f$1@naig.caltech.edu>
In article <4nt3sfFbuecsU1@uni-berlin.de>,
Michael Goerz <news12@8439.e4ward.com> wrote:
[ much snippage ]
>my $visit = {field1 => 1, field2 => 'foo'};
>my $compiled_pattern = qr/1/;
>my %excludepatterns = ('field1' => $compiled_pattern);
># checks if visit has to be filtered out
>sub is_filtered{
> my $visit = shift;
> while ( my ($field, $pattern) = each %excludepatterns ){
> if ( exists($visit->{$field}) ){
> if ( $visit->{$field} =~ $pattern){
> return 1;
> }
> } else {
> warn "Tried to filter non-existing field.\n";
> }
> }
> return 0;
>}
I think the problem is that if any pattern matches, you are leaving
the loop early. So, the next time you enter the function, the
each() will continue the earlier iteration rather than starting over.
There are several possibilities to correct this:
1) Make sure you loop through all the fields -- set a flag if a
pattern matches, but keep going until the while() ends.
2) Reset the internal iterator that each() uses when you enter
is_filtered() -- see perldoc -f each for how to do this.
3) Don't use each(), use keys() instead. This is probably the way
I would find clearest, but maybe that's just me.
forreach my $field (keys %excludepatterns) {
if (exists $visit->{$field}) {
return 1 if $visit->{$field} =~ $excludepatterns{$field};
}
# else as before
}
I'm not sure which would be fastest (if speed is important and this
is a significant part of your code). You might want to benchmark each
and run some tests.
Gary Ansok
--
3M suggests that to obtain the best results, one should make the bond
"while the adhesive is wet, aggressively tacky." I did not know what
"aggressively tacky" meant until I saw a recent notice in the Bboard.
(Mario Barbacci)
------------------------------
Date: 26 Sep 2006 08:44:01 -0700
From: "Bill H" <bill@ts1000.us>
Subject: Ftp via Perl cron job
Message-Id: <1159285441.310962.172780@m7g2000cwm.googlegroups.com>
I have a Perl program that processes a file, saves the results in a new
file and then need to ftp that file to a different server, can anyone
point me to some documentation or a module / source on how I can
accomplish the ftp portion via Perl?
Thanks
Bill H
------------------------------
Date: Tue, 26 Sep 2006 16:47:00 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Ftp via Perl cron job
Message-Id: <efbi1k$2b4$1@gemini.csx.cam.ac.uk>
Bill H wrote:
> I have a Perl program that processes a file, saves the results in a new
> file and then need to ftp that file to a different server, can anyone
> point me to some documentation or a module / source on how I can
> accomplish the ftp portion via Perl?
How about going to search.cpan.org and searching for FTP?
DS
------------------------------
Date: Tue, 26 Sep 2006 17:26:03 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: Ftp via Perl cron job
Message-Id: <LodSg.1638$Y24.82@newsread4.news.pas.earthlink.net>
On 09/26/2006 10:44 AM, Bill H wrote:
> I have a Perl program that processes a file, saves the results in a new
> file and then need to ftp that file to a different server, can anyone
> point me to some documentation or a module / source on how I can
> accomplish the ftp portion via Perl?
>
> Thanks
>
> Bill H
>
You can use Net::FTP to send the file, or you can use the ftp program
from within perl by executing it using the "system" command.
--
paduille.4058.mumia.w@earthlink.net
------------------------------
Date: Tue, 26 Sep 2006 17:42:33 +0200
From: Ch Lamprecht <christoph.lamprecht.no.spam@web.de>
Subject: Re: list vs. array
Message-Id: <efbhp9$cds$1@online.de>
Tad McClellan wrote:
> robb@acm.org <robb@acm.org> wrote:
>
>
>>Is it advisable to think about these issues and consider them when
>>actually doing programming?
>
>
>
> Yes. Much of the time perl's DWIMer will shield you from needing
> to know the difference.
>
> But having to qualify it with "Much" implies that some times the
> distinction is important.
>
> A rather contrived example:
>
> -----------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $numList = nums_list();
> print "list: $numList\n";
>
> my $numArray = nums_array();
> print "array: $numArray\n";
>
> sub nums_list { return 4, 5, 6 }
> sub nums_array {my @nums=(4, 5, 6); return @nums}
> -----------------------------
>
>
This example illustrates context propagation to the return statement and
behaviour of the 'comma' operator in scalar context. There is no list at all.
Christoph
--
perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"
------------------------------
Date: 26 Sep 2006 09:50:37 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Re: list vs. array
Message-Id: <1159289437.207959.87070@i42g2000cwa.googlegroups.com>
Ch Lamprecht wrote:
> There is no list at all.
>
?
------------------------------
Date: Tue, 26 Sep 2006 19:54:17 +0200
From: Ch Lamprecht <christoph.lamprecht.no.spam@web.de>
Subject: Re: list vs. array
Message-Id: <efbpg9$prf$1@online.de>
robb@acm.org wrote:
> Ch Lamprecht wrote:
>
>>There is no list at all.
>>
>
>
> ?
>
Why did you snip the context you were replying to?
The expression (4,5,6) does not produce a list out of its own. It is dependent
on the context it's evaluated in.
In list context it evaluates to a list containing 3 values: 4 5 and 6.
In scalar context it evaluates to the value 6.
That is because the 'comma' operator
-In list context evaluates the expressions on his left hand - and right hand
side and returns a list containing of the results of these expressions.
-In scalar context evaluates the left hand side, discards it and returns the
result of the expression on its right hand side.
Christoph
--
perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"
------------------------------
Date: 26 Sep 2006 16:01:01 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: meaning of "child processes are reaped"
Message-Id: <4nt15tFc3c2pU1@news.dfncis.de>
bernd <bew_ba@gmx.net> wrote in comp.lang.perl.misc:
> Hello folks,
>
> not very experienced with interprocess communication and not a native
> English speaker I would like to know what the meaning of the expression
> "child processes are reaped" is. I encountered it in connection with
> Perl's waitpid-function.
>
> Could somebody explain this term?
Under Unix, when a process exits while its parent process is still
active, the process doesn't go away entirely. The entry in the process
table is kept around containing the exit status and CPU time consumed.
The parent process can access this information through the wait() and
waitpid() commands. Only then, or when the parent process exits itself,
is the process entry released entirely.
This procedure is likened to the mythical situation after a person's
death. The deceased's soul hangs around as a zombie until Death
(the Grim Reaper) comes and takes care of it. Thus the term "reaper"
for the procedure that calls waitpid() on the PIDs of finished child
processes.
Anno
------------------------------
Date: 26 Sep 2006 09:22:02 -0700
From: "bernd" <bew_ba@gmx.net>
Subject: Re: meaning of "child processes are reaped"
Message-Id: <1159287722.667024.60540@e3g2000cwe.googlegroups.com>
Hi Anno,
thank You for the detailed and plastically explanation. Brings me
further ;-)
Cheers
Bernd
anno4000@radom.zrz.tu-berlin.de wrote:
> bernd <bew_ba@gmx.net> wrote in comp.lang.perl.misc:
> > Hello folks,
> >
> > not very experienced with interprocess communication and not a native
> > English speaker I would like to know what the meaning of the expression
> > "child processes are reaped" is. I encountered it in connection with
> > Perl's waitpid-function.
> >
> > Could somebody explain this term?
>
> Under Unix, when a process exits while its parent process is still
> active, the process doesn't go away entirely. The entry in the process
> table is kept around containing the exit status and CPU time consumed.
> The parent process can access this information through the wait() and
> waitpid() commands. Only then, or when the parent process exits itself,
> is the process entry released entirely.
>
> This procedure is likened to the mythical situation after a person's
> death. The deceased's soul hangs around as a zombie until Death
> (the Grim Reaper) comes and takes care of it. Thus the term "reaper"
> for the procedure that calls waitpid() on the PIDs of finished child
> processes.
>
> Anno
------------------------------
Date: 26 Sep 2006 08:45:47 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: passing multiple values into an argument as an array ?
Message-Id: <1159285546.877357.145610@k70g2000cwa.googlegroups.com>
Dave Weaver wrote:
> On 22 Sep 2006 20:43:51 -0700, Jack <jack_posemsky@yahoo.com> wrote:
> > I am reading in arguments just fine using the code below, but I want to
> > be able to add a variable number of values into an argument into perl -
> >
> > I want to be able to say
> > perl -f value1 value2 ..valueN -v value value2 ..valueN
> >
> > and store the values of -f in a single array, and -v also (and the
> > number of passed values could vary !)
>
> I've just discovered the clever Getopt::Declare module, which can do
> just that:
>
> #/usr/bin/perl
> use strict;
> use warnings;
> use Getopt::Declare;
>
> my $args = Getopt::Declare->new(<<END);
> -f <value>... a list of values
> -v <value>... another list of values
> END
>
> my @f = @{ $args->{'-f'} };
> my @v = @{ $args->{'-v'} };
> print "f = @f, v = @v\n";
It's unfortunate that this topic was multiposted, because David Filmer
has already pointed out in perl.beginners that the newest version of
Getopt::Long (version 2.35) supports this functionality natively (ie:
without split()-ing) though the module's author lists this
functionality as 'experimental'.
-jp
------------------------------
Date: 26 Sep 2006 10:29:34 -0700
From: "Markus Dehmann" <markus.dehmann@gmail.com>
Subject: perl -pe for blocks of lines instead of single lines
Message-Id: <1159291774.849505.175540@m7g2000cwm.googlegroups.com>
I just found the answer to my own problem. I'm gonna share this so
people can find it via google:
I have a data file that contains blocks of data, separated by empty
lines:
line1
line2
line1
line2
Now I want to read it on the command line, one block at a time. But
perl -pe '...' reads only single lines.
The answer is: Use -00
So, this:
perl -00 -ne 'chomp; print "<BLOCK>$_</BLOCK>\n"' data.txt
Prints
<BLOCK>line 1
line2</BLOCK>
<BLOCK>line 1
line2</BLOCK>
Just wanted to share ...
Markus
------------------------------
Date: 26 Sep 2006 18:19:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Reading from standard input
Message-Id: <p6jih25fm2mkofhb9n4c48e7dsm9dde4aq@4ax.com>
On 26 Sep 2006 07:01:57 -0700, "Harpreet" <harpreet.saluja@gmail.com>
wrote:
>Subject: Reading from standard input
<STDIN>
>I am learning perl scripting and was reading an online tutorial where i
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
Ouch! I smell... well, something bad...
>encountered this code(at the end of message). The first part of the
>code (reading from file) has been pasted as-is and the second(reading
>from standard input stream) was written by me. When I execute the
>program, I get the correct result from the first one and then I type
>into the stream some data but I don't know how to end it. I used the
^D
>conventional unix "dot-enter" scheme but it didn't work. Neither did
What is it?!?
>Ctrl-D. I found some examples which read from <STDIN> and worked with a
>while loop. Can somebody explain me why reading from the standard input
Indeed that would be the "canonical" way to read line by line...
>#!usr/local/bin/perl
(please do a favour to yourself and have perl you give all the help it
can give to avoid common mistakes, so)
use strict;
use warnings;
>$file = '/etc/passwd'; # Name the file
my $file = '/etc/passwd';
# Do you really want to play with *that* file?
>open(INFO, $file); # Open the file
open my $info, '<', $file or die "Can't open `$file': $!\n";
>@lines = <INFO>; # Read it into an array
>close(INFO); # Close the file
>print @lines; # Print the array
As above, if there's no real need to slurp in all the file at once,
don't. Use a while loop instead:
print while <INFO>;
# or
print while <$info>;
>open(INFO, '-');
You don't need that. You already have STDIN.
>@lines2 = <INFO>; # Read it into an array
My first guess was that reading from STDIN in list context would
return the lines available at the moment of the call and that that
would explain your problem. But indeed I made an experiment and for me
it works as expected:
$ perl -MFatal=open -MData::Dumper -e 'open I,"-";
> chomp(@a=<I>); print Dumper \@a'
foor
baar
bazz
$VAR1 = [
'foor',
'baar',
'bazz'
];
I just pressed ^D here.
HTH,
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: 26 Sep 2006 08:14:59 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: regular expression pb. with tags
Message-Id: <1159283698.834087.62350@h48g2000cwc.googlegroups.com>
steeve_dun@SoftHome.net wrote:
> Hi,
> I want to make some pattern replacement. ie to delete every thing
> that's between 2 tags.
> For example for
>
> 1<tag> 2</tag>3
> x<tag> a<tag> b </tag> c</tag>z
>
> I want to get
>
> 1 3
> x z
>
> But I have a problem with embeded tags.
> I've tried :
> $text =~ s/\<tag\>(.*?)\<\/tag\>//sg;
> but it doens't work for embeded tags. It gives:
> 13
> x c</tag>z
>
> Is there a way to deal with this?
Since you are using Perl, and XML is quite well formated, you may try
something like:
my $ptn;
$ptn = qr(<tag>(?:(??{$ptn})|.)*?</tag>)s;
$line =~ s/$ptn//g;
I am not encouraging you using regexes at work. But in case of some
small programs, using regexes might be much faster/easier if you know
what you do.
Regards,
Xicheng
------------------------------
Date: Tue, 26 Sep 2006 14:00:49 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: sort with Perl ..
Message-Id: <g69u02u1p9q.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 25 Sep 2006, David.Squire@no.spam.from.here.au wrote:
> Many here think that when asking for help, you should show us the
> code for your attempt so far. People are happy to help you to get
> your code working. They are generally not happy to write code for
> people from scratch. Also, getting feedback on your code is likely
> to be a much more fruitful learning experience than simply getting a
> ready-made solution - particularly since some here take pleasure in
> producing clever and compact solutions, rather than ones easily
> understandable by novices :)
I understand the sentiment, but find it misplaced. In a classrooom
it's fine, but in an open forum I don't think it's reasonable to jump
on other people who help each other. Yes, it's free speech, but that
doesn't mean it's reasonable or welcome, especially if it intends to
represent the spirit of this newsgroup.
So what if the OP didn't learn to program Perl? Why does he have to,
in order to solve a specific problem? We all drive cars we didn't
design, eat foods we didn't grow, and so on... I think the way to
interest someone in Perl is with gentle help, not by asking them to do
a lot of work up front. It's just not as easy for everyone as it is
for experienced programmers to "show some work."
Ted
------------------------------
Date: Tue, 26 Sep 2006 18:07:40 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <mr-609628.18074026092006@individual.net>
In article <4nsqafFbtkmtU1@news.dfncis.de>,
anno4000@radom.zrz.tu-berlin.de wrote:
> > > I would use the substitution operator s/// to repeatedly suck off
> > > keyword and value segments and place them in a hash. The /e option to
> > > s/// allows you execute complicated expressions, and that's what I would
> > > use here.
> > >
> > > Try it yourself.
> >
> > Yeah, that's pretty much how I've been doing it. I just thought that
> > there were a more modular approach. I'll try some more. Thanks :)
>
> You've said that twice now. "Modular" means consisting of independent
> components. How does that apply here?
In programming, "modular" really hasn't got a strict definition. I
used it to mean that I could add and subtract dependencies in the
script at will, without having to change the code.
Plus, I'm from sweden.
--
Sandman[.net]
------------------------------
Date: Tue, 26 Sep 2006 18:09:12 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <mr-D8F71B.18091226092006@individual.net>
In article <1159280569.894960.270420@m73g2000cwd.googlegroups.com>,
"Paul Lalli" <mritty@gmail.com> wrote:
> > If you don't want to help, that's fine. No need to be aggressive.
>
> While I was not being agressive, I rather disagree that there was no
> need to be. For some reason, you seem completely unwilling to help
> anyone to help you without mulitple prodding.
Ok, then leave it at that. No problem for me. Thanks anyway.
--
Sandman[.net]
------------------------------
Date: 26 Sep 2006 16:26:12 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Splitting and keeping key/value
Message-Id: <4nt2l4Fc3du5U1@news.dfncis.de>
Sandman <mr@sandman.net> wrote in comp.lang.perl.misc:
> In article <4nsqafFbtkmtU1@news.dfncis.de>,
> anno4000@radom.zrz.tu-berlin.de wrote:
>
> > > > I would use the substitution operator s/// to repeatedly suck off
> > > > keyword and value segments and place them in a hash. The /e option to
> > > > s/// allows you execute complicated expressions, and that's what I would
> > > > use here.
> > > >
> > > > Try it yourself.
> > >
> > > Yeah, that's pretty much how I've been doing it. I just thought that
> > > there were a more modular approach. I'll try some more. Thanks :)
> >
> > You've said that twice now. "Modular" means consisting of independent
> > components. How does that apply here?
>
> In programming, "modular" really hasn't got a strict definition.
If that is what you think then don't use the term. It can only
add to the confusion.
> I
> used it to mean that I could add and subtract dependencies in the
> script at will, without having to change the code.
So you expect us to divine what meaning you have assigned to the
term for the moment? Great attempt at communication!
> Plus, I'm from sweden.
Then don't teach us about English. The term modular has a quite
well-defined meaning, especially in programming.
Anno
------------------------------
Date: Tue, 26 Sep 2006 17:59:51 +0200
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: WIn32API and keyboard
Message-Id: <45194e81$0$27383$ba4acef3@news.orange.fr>
"mw" <mbw@vp.pl> wrote in message news:efbam2$t17$1@news.onet.pl...
> Hi !
>
> I test GetAsyncKeyState function on my XP.
> Here is my code :
>
> use Win32::API;
>
> my $rsGetAsyncKeyState = new Win32::API("user32", "GetAsyncKeyState", "N",
> "I");
>
> sub GetAsyncKeyState {
> my ($keyCode) = @_;
> my $ret = $rsGetAsyncKeyState->Call($keyCode);
> print "ret = $ret\n";
> return( $ret & 1 );
> }
>
>
> while () {
> sleep 1 ;
> $keystate=GetAsyncKeyState(97) ;
> # 97 is "a" ascii code
> #print "a state=$keystate\n" ; ;
> }
>
>
> When I run this code and press "a" key I see only :
>
> .
> .
> ret = 0
> ret = 0
> ret = 0
> .
> .
> .
> It means that "a" key is not pressed.
> What's wrong ?
>
> Pls help
>
>
I would have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/getasynckeystate.asp
especially the note for NT/2000/XP.
Also, I'm not sure what your "N" and "I" represent.
------------------------------
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 9771
***************************************