[23266] in Perl-Users-Digest
Perl-Users Digest, Issue: 5486 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 11 09:05:50 2003
Date: Thu, 11 Sep 2003 06:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 11 Sep 2003 Volume: 10 Number: 5486
Today's topics:
Re: calculation in string <tom@nosleep.net>
Re: Creating a DSN-less connection to a MySQL database <al@bat400.com>
Re: DBD::CSV questions and is there a DBD::XML? <andrew@NOSPAM_andicrook.demon.co.uk>
Re: Defeating OS buffering? nobull@mail.com
Re: Detecting duplicate keys in a hash I am "requiring" <tassilo.parseval@rwth-aachen.de>
Re: Detecting duplicate keys in a hash I am "requiring" (Anno Siegel)
Re: Detecting duplicate keys in a hash I am "requiring" <tassilo.parseval@rwth-aachen.de>
Re: Detecting duplicate keys in a hash I am "requiring" (Anno Siegel)
Re: Detecting duplicate keys in a hash I am "requiring" <tassilo.parseval@rwth-aachen.de>
Difference between two regular expressions <neil.shadrach@corryn.com>
Re: Difference between two regular expressions (Anno Siegel)
Re: Newsgroup post test... <NoSpamPlease@bellsouth.net>
Re: Newsgroup post test... (Anno Siegel)
Re: Number of elements in an array <tassilo.parseval@rwth-aachen.de>
Re: Number of elements in an array <abigail@abigail.nl>
Re: perl regex question <mpapec@yahoo.com>
Re: Posting with Net::NNTP <usenet@expires12.2003.tinita.de>
Re: Printing a hash of hashes using an array for the he (Anno Siegel)
Re: Speeding up LWP::Simple <abigail@abigail.nl>
Re: Splitting and keeping the delimiter <bigj@kamelfreund.de>
Re: Splitting and keeping the delimiter (Anno Siegel)
wxPerl <mpapec@yahoo.com>
Re: wxPerl (Helgi Briem)
Re: wxPerl <mpapec@yahoo.com>
Re: wxPerl (Helgi Briem)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 11 Sep 2003 00:46:18 -0700
From: "Tom" <tom@nosleep.net>
Subject: Re: calculation in string
Message-Id: <3f6027a7$1@nntp0.pdx.net>
lol, it even works in windows :)
Thanks,
Tom
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnbm071c.p2v.sholden@flexal.cs.usyd.edu.au...
> On Wed, 10 Sep 2003 22:46:54 -0700, Tom <tom@nosleep.net> wrote:
> > wtf is "perldoc -q usenet"?
>
> A reference to the FAQ that comes with perl.
>
> The FAQ you are supposed to check *before* posting.
>
> The FAQ that specifically answers your question.
>
> Run the command:
>
> perldoc -q usenet
>
> on one of the machines with perl on it (and set up to include the perl bin
> directory in your path) for the answer to your original question.
>
> >
> > "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> > news:GQH7b.18421$98.13891@nwrddc03.gnilink.net...
> >> Tom wrote:
> >> > and what would be the mainstream perl newsgroups?
> >>
> >> Please see "perldoc -q usenet".
> >> And don't top-post-full-quote!
> >>
> >> jue
> >>
> >>
>
> I see you ignored the second statement. Hope you don't have any
> perl quesions later, since I suspect a whole bunch of very knowledgable
> and helpful folk won't be reading your posts...
>
> --
> Sam Holden
>
------------------------------
Date: Thu, 11 Sep 2003 08:10:40 +0100
From: "Al Reynolds" <al@bat400.com>
Subject: Re: Creating a DSN-less connection to a MySQL database
Message-Id: <bjp7b6$fdld6$1@athena.ex.ac.uk>
"James Willmore" <jwillmore@cyberia.com> wrote in message
news:e0160815.0309101335.369977cb@posting.google.com...
> "Al Reynolds" <al@bat400.com> wrote in message
news:<bjn7n4$et28p$1@athena.ex.ac.uk>...
> > "James Willmore" <jwillmore@cyberia.com> wrote in message
> > news:20030909123830.2ce6ab2f.jwillmore@cyberia.com...
> > > On Tue, 9 Sep 2003 13:37:09 +0100
> > > "Al Reynolds" <al@bat400.com> wrote:
> > > > I hope someone will be able to help me with this.
> > > >
> > > > I am trying to set up a connection to my MySQL
> > > > database using perl. I already have the database
> > > > set up and have used it with PHP without any problems.
> > > >
> > > > When I try and execute the following code, I get an error:
> > > > (obviously I have substituted the names/passwords)
> > > >
> > > > #!/usr/bin/perl
> > > > use DBI;
> > > > my $dbh =
> > > > DBI->connect('DBI:mysql:databasename:localhost','username','passwor
> > > > d');$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
> > > > exit;
> > >
> > > Try to first, read the documentation for DBD::mysql and second, try to
> > > connect using ...
> > >
> > > DBI->connect('DBI:mysql:database=dbname;host=localhost',
> > > 'username',
> > > 'password')
> > > or die "Connection error: ".$DBI::errstr."\n";
> > >
> > > If you had read the documentation, you would have discovered that your
> > > connection statement is wrong.
> >
> > I read enough to decide that the using DBI would
> > generate a DSN connection*, which wasn't what I
> > wanted, which is why I gave up on the DBI route
> > to pursue the ADODB route. The code I used is
> > referred to in several perl-related resources and
> > tutorials on different web sites; I doubt that they
> > all made the same mistake. It isn't that uncommon
> > for a call to be possible in a variety of forms.
> >
> > Anyway, thank you for the code snippet. If I am
> > trying to make a DBI connection again I will use it.
> >
> > FWIW, I solved the problem using the older
> > mysql.pm module, which is less portable when
> > there is a possibility that the database type could
> > change later. It works fine just now though.
> >
> > Cheers,
> > Al
> >
> >
> > * This may be wrong of course - I am still not quite clear
> > on the matter. There is surprisingly little info online about
> > the difference between DSN and DSN-less database
> > connections and how to set them up using perl.
>
> I had to review the ADODB manual to find out what you meant by
> "DSN-less" database. In general, anything ADODB, DBI can do. There
> is the DBD::ODBC module that you can use to connect to data sources
> such as Access. You can also use DBD::Proxy to create a client/server
> type connection.
>
> Basically - this is a term that ADODB authors came up with. You still
> need to declare a data source using a "DSN-less" connection. So, the
> term is mis-leading.
>
> HTH
Cheers - it does.
Al
------------------------------
Date: Thu, 11 Sep 2003 12:17:25 +0100
From: "Andrew Crook" <andrew@NOSPAM_andicrook.demon.co.uk>
Subject: Re: DBD::CSV questions and is there a DBD::XML?
Message-Id: <bjplk0$pii$1$830fa78d@news.demon.co.uk>
> You might be able to retrieve XML via a SQL call and then use an XML
> parser on that data returned from your query. Many XML parsers exist
> for Perl.
No I don't want the results returned in xml I would like to query a xml file
as a database source using SQL!
did you mean there this a means to use SQL to query a xml source but the
result is in the form of xml, which I would then have to parse.
The actual result would be preferred as a standard record set, but the means
to do the latter would be better than nothing and may be useful in the
future.
Andi
"Scott Yanoff" <yanoff@STOP-SPAMMINGyahoo.com> wrote in message
news:3f576097$0$43851$39cecf19@news.twtelecom.net...
> Andrew Crook wrote:
> > Also does anyone know of a DBD::XML module?
>
> http://www.cpan.org did not show any hint of it.
>
> There was some discussion on this years ago in the DB mailing lists.
> http://www.geocrawler.com/archives/3/183/1998/10/100/1068137/
------------------------------
Date: 11 Sep 2003 04:26:54 -0700
From: nobull@mail.com
Subject: Re: Defeating OS buffering?
Message-Id: <4dafc536.0309110326.57f43b12@posting.google.com>
Eric Schwartz <emschwar@pobox.com> wrote in message news:<eto1xuoz66r.fsf@wormtongue.emschwar>...
> Vlad Tepes <minceme@start.no> writes:
>
> <snip>
>
> > The C-program:
> >
> > #include <stdio.h>
> > #include <unistd.h>
> >
> > int main ( void ) {
> > printf("Some text...");
> > fflush(NULL);
> ^^^^^^^^^^^^^
> <snip>
>
> That's the problem. Take that out, and it won't work. As I said, I
> don't have control over the C program, so I can't make it fflush.
It will probably fflush() implicitly on newline if it thinks it's
STDOUT is going to an interactive terminal.
I Expect (hint, hint) you could find something on CPAN that would
allow you to fool a subprocess into thinking it's connected to a
terminal.
------------------------------
Date: 11 Sep 2003 07:18:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Detecting duplicate keys in a hash I am "requiring"
Message-Id: <bjp7kb$agk$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Gupit <gupit@yahoo.com> wrote in comp.lang.perl.misc:
>> Unfortunately duplicate keys may have been specified in the lower
>> level hash structure as well. Replacing only the top level hash
>> structure wont help there.
>>
>> e.g. see key7 in the following example
>>
>> $hash = {
>> key1 => { key2 => val2,
>> key3 => val3,
>> },
>> key4 => [ vala,valb,],
>> key1 => {key5 => val5,
>> key6 => {
>> key7 => val7,
>> key8 => val8,
>> key7 => val9,
>> }
>> ),
>> };
>>
>> (I dont call this structure $hash in real life, I have simplified the
>> actual data structure here for ease of understanding and to retain the
>> focus of my question :))
>
> Well, if the problem re-appears at a lower level, re-apply the solution.
> In other words, re-design the data structure so that every hash that may
> have a key specified more than once is replaced with a list of pairs.
If we look at $hash->{key4}, regarding everything as a list likely has
its problems, too. The OP might be able to solve this with a
dispatch-table for particular entries. If he knows that there is always
a list associated with 'key4', then this is feasible. Here is a
spontaneous solution (might not be complete since it doesn't handle
structures within array-refs, only within hash-refs). And no, I do not
intend to win a beauty-award for it:
use Data::Dumper;
use strict;
use vars qw($list);
eval "require 'config_file'";
my %dispatch;
# these hash-keys all have another hash-ref as value
@dispatch{ qw/key1 key2 key3 key5 key6 key6/ } =
(sub {
my ($key, $val, $hash) = @_;
die "Duplicate key '$key'\n" if exists $hash->{ $key };
if (@$val > 1) {
for (my $i = 0; $i <= $#$val; $i += 2) {
die "Duplicate key '$val->[$i]'\n"
if exists $hash->{ $key }->{ $val->[$i] };
if (! ref $val->[$i+1]) {
$hash->{ $key }->{ $val->[$i] } = $val->[$i+1];
} else {
$dispatch{$val->[$i]}->($val->[$i], $val->[$i+1], $hash);
}
}
} else {
$hash->{ $key } = $val;
}
}) x 6;
# takes an array-ref as value
$dispatch{ key4 } =
sub {
my ($key, $val, $hash) = @_;
if (exists $hash->{ $key }) {
die "Duplicate key '$key'\n";
}
$hash->{ $key } = $val;
};
my %hash;
for (my $i = 0; $i <= $#$list; $i += 2) {
$dispatch{$list->[$i]}->($list->[$i], $list->[$i+1], \%hash);
}
print Dumper \%hash;
For a config-file without duplicate values like this:
$list = [
key1 => [ key2 => 'val2',
key3 => 'val3',
key4 => 'val1',
],
key4 => [ qw/vala valb/ ],
key5 => [ key5 => 'val5',
key6 => 'val6'
],
];
it will correctly produce:
$VAR1 = {
'key5' => {
'key5' => 'val5',
'key6' => 'val6'
},
'key4' => [
'vala',
'valb'
],
'key1' => {
'key2' => 'val2',
'key4' => 'val1',
'key3' => 'val3'
}
};
and die when duplicate keys within a sub-structure are detected.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 11 Sep 2003 08:37:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Detecting duplicate keys in a hash I am "requiring"
Message-Id: <bjpc7u$oga$1@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
>
> > Gupit <gupit@yahoo.com> wrote in comp.lang.perl.misc:
>
> >> Unfortunately duplicate keys may have been specified in the lower
> >> level hash structure as well. Replacing only the top level hash
> >> structure wont help there.
> >>
> >> e.g. see key7 in the following example
> >>
> >> $hash = {
> >> key1 => { key2 => val2,
> >> key3 => val3,
> >> },
> >> key4 => [ vala,valb,],
> >> key1 => {key5 => val5,
> >> key6 => {
> >> key7 => val7,
> >> key8 => val8,
> >> key7 => val9,
> >> }
> >> ),
> >> };
> >>
> >> (I dont call this structure $hash in real life, I have simplified the
> >> actual data structure here for ease of understanding and to retain the
> >> focus of my question :))
> >
> > Well, if the problem re-appears at a lower level, re-apply the solution.
> > In other words, re-design the data structure so that every hash that may
> > have a key specified more than once is replaced with a list of pairs.
>
> If we look at $hash->{key4}, regarding everything as a list likely has
> its problems, too.
Yes, the "real list" among the hashes had me worried to, but I
decided to gloss over it.
> The OP might be able to solve this with a
> dispatch-table for particular entries. If he knows that there is always
> a list associated with 'key4', then this is feasible.
We need a way to tell an ordinary list structure from one that is meant
to represent a hash with multiple keys. A dispatch table, like you
suggest, can do that. Another way would be to point to the "real"
listrefs though another reference. When traversing the structure,
whenever we meet a scalar ref, we know it contains a "real" listref.
A plain listref represents a multi-hash. (Or the other way around.)
Similarly, one could bless one kind of listrefs into a class to make
them distinguishable.
> Here is a
> spontaneous solution (might not be complete since it doesn't handle
> structures within array-refs, only within hash-refs). And no, I do not
> intend to win a beauty-award for it:
[code and results snipped]
> ...and die when duplicate keys within a sub-structure are detected.
I am beginning to have doubts about that. I get the impression the
OP *wants* the duplicate keys.
Anno
------------------------------
Date: 11 Sep 2003 09:12:53 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Detecting duplicate keys in a hash I am "requiring"
Message-Id: <bjpeal$hc1$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
>> Also sprach Anno Siegel:
>> > Well, if the problem re-appears at a lower level, re-apply the solution.
>> > In other words, re-design the data structure so that every hash that may
>> > have a key specified more than once is replaced with a list of pairs.
>>
>> If we look at $hash->{key4}, regarding everything as a list likely has
>> its problems, too.
>
> Yes, the "real list" among the hashes had me worried to, but I
> decided to gloss over it.
>
>> The OP might be able to solve this with a
>> dispatch-table for particular entries. If he knows that there is always
>> a list associated with 'key4', then this is feasible.
>
> We need a way to tell an ordinary list structure from one that is meant
> to represent a hash with multiple keys. A dispatch table, like you
> suggest, can do that. Another way would be to point to the "real"
> listrefs though another reference. When traversing the structure,
> whenever we meet a scalar ref, we know it contains a "real" listref.
> A plain listref represents a multi-hash. (Or the other way around.)
>
> Similarly, one could bless one kind of listrefs into a class to make
> them distinguishable.
Gee. We are beginning to make up our own little meta-language now. :-)
I think when things start to get that sophisticated, a complete new
approach is worth a look. Maybe the OP should use a real config-file
format. Either one already supported in the CPAN or his own one that is
easy to parse.
But still, the problem presented here again makes me want a tie_deeply()
mechanism for perl. There are situations (like this one), where tying
the nested structures is impossible because it happens too late.
>> ...and die when duplicate keys within a sub-structure are detected.
>
> I am beginning to have doubts about that. I get the impression the
> OP *wants* the duplicate keys.
Well, first step would be s/die/warn/g. :-) I'm too lazy now to modify
my routines accordingly, but it shouldn't be too hard to turn the value
of an already existing key/value pair into an array-ref and push the
second value onto it.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 11 Sep 2003 10:08:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Detecting duplicate keys in a hash I am "requiring"
Message-Id: <bjphjc$s70$1@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
>
> > Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in
> comp.lang.perl.misc:
> >> Also sprach Anno Siegel:
>
> >> > Well, if the problem re-appears at a lower level, re-apply the solution.
> >> > In other words, re-design the data structure so that every hash that may
> >> > have a key specified more than once is replaced with a list of pairs.
> >>
> >> If we look at $hash->{key4}, regarding everything as a list likely has
> >> its problems, too.
> >
> > Yes, the "real list" among the hashes had me worried to, but I
> > decided to gloss over it.
> >
> >> The OP might be able to solve this with a
> >> dispatch-table for particular entries. If he knows that there is always
> >> a list associated with 'key4', then this is feasible.
> >
> > We need a way to tell an ordinary list structure from one that is meant
> > to represent a hash with multiple keys. A dispatch table, like you
> > suggest, can do that. Another way would be to point to the "real"
> > listrefs though another reference. When traversing the structure,
> > whenever we meet a scalar ref, we know it contains a "real" listref.
> > A plain listref represents a multi-hash. (Or the other way around.)
> >
> > Similarly, one could bless one kind of listrefs into a class to make
> > them distinguishable.
>
> Gee. We are beginning to make up our own little meta-language now. :-)
> I think when things start to get that sophisticated, a complete new
> approach is worth a look. Maybe the OP should use a real config-file
> format. Either one already supported in the CPAN or his own one that is
> easy to parse.
Indeed. There are very useful config modules out there. However, I'm
afraid we lost the OP a few plies ago :)
> But still, the problem presented here again makes me want a tie_deeply()
> mechanism for perl. There are situations (like this one), where tying
> the nested structures is impossible because it happens too late.
I'm not sure what deep-tying would be (something like autovivification
to another tied object?).
> >> ...and die when duplicate keys within a sub-structure are detected.
> >
> > I am beginning to have doubts about that. I get the impression the
> > OP *wants* the duplicate keys.
>
> Well, first step would be s/die/warn/g. :-) I'm too lazy now to modify
> my routines accordingly, but it shouldn't be too hard to turn the value
> of an already existing key/value pair into an array-ref and push the
> second value onto it.
I wouldn't invest too much in it either, for the moment.
However, it occurred to me that this problem may have didactical uses
for the introduction of Perl objects:`
Use the problem to show that it's desirable to make similar references
distinguishable, and introduce bless/ref for the purpose.
Show a solution that uses bless() to mark those lists that represent
multi-key hashes, but doesn't use method calls yet. There'll be
a few "if ( ref( ...) eq '...' ) {" in the code.
Then introduce method calls and show how they simplify the solution.
End up with an implementation of a class "Multi_key_hash" that solves
the original problem.
That way, objects can be introduced with good motivation for every
step.
Anno
------------------------------
Date: 11 Sep 2003 11:17:52 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Detecting duplicate keys in a hash I am "requiring"
Message-Id: <bjpll0$o5u$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
>> Gee. We are beginning to make up our own little meta-language now. :-)
>> I think when things start to get that sophisticated, a complete new
>> approach is worth a look. Maybe the OP should use a real config-file
>> format. Either one already supported in the CPAN or his own one that is
>> easy to parse.
>
> Indeed. There are very useful config modules out there. However, I'm
> afraid we lost the OP a few plies ago :)
In my direct follow-up to him I warned him that a solution is
non-trivial. ;-)
>> But still, the problem presented here again makes me want a tie_deeply()
>> mechanism for perl. There are situations (like this one), where tying
>> the nested structures is impossible because it happens too late.
>
> I'm not sure what deep-tying would be (something like autovivification
> to another tied object?).
Yes, though I wouldn't call it autovivification. I didn't yet think how
the interface should look like, but this
%tied_hash = ( key1 => 'val1',
key2 => { subkey1 => 1,
subkey2 => 2 },
);
should not result in
(tied %tied_hash)->STORE('key1', 'val1');
STORE('key2', { subkey1 => 1, subkey2 => 2 });
but rather in
(tied %tied_hash)->STORE('key1', 'val1');
->STORE('key2', 'subkey1', 1);
->STORE('key2', 'subkey2', 2);
or so. And the above should happen recursively. It needs a proper
calling convention and all, then it would be very nice to have. It would
make a module such as MLDBM much more natural in use.
The idea however is not new. It's just tough finding volunteers to
implement it. ;-)
> I wouldn't invest too much in it either, for the moment.
>
> However, it occurred to me that this problem may have didactical uses
> for the introduction of Perl objects:`
>
> Use the problem to show that it's desirable to make similar references
> distinguishable, and introduce bless/ref for the purpose.
>
> Show a solution that uses bless() to mark those lists that represent
> multi-key hashes, but doesn't use method calls yet. There'll be
> a few "if ( ref( ...) eq '...' ) {" in the code.
>
> Then introduce method calls and show how they simplify the solution.
> End up with an implementation of a class "Multi_key_hash" that solves
> the original problem.
>
> That way, objects can be introduced with good motivation for every
> step.
Yes, it would be a more than welcome variation of the schemes that seem
to be preferred in those OO-tutorials, such as deriving pigs from
animals, letting them oink etc. ;-)
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 11 Sep 2003 09:54:50 +0000 (UTC)
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Difference between two regular expressions
Message-Id: <3F6045A3.7090200@corryn.com>
Why do the two 'print' lines behave differently in the following?
#!/usr/bin/perl -w
use strict;
use warnings;
$/.=$/;
while(<DATA>)
{
print "\nA:1[$1]\nA:2[$2]" if /bindings: (?:(.+ => .+)\n?\s*)(?:(.+ => .+\n?\s*))/;
print "\nB:1[$1]\nB:2[$2]" if /bindings: (?:(.+ => .+)\n?\s*){2}/;
}
__DATA__
community: public
enterprise: 9.9.9.9.9.9.999.9.9.9.9
agent addr: 999.99.99.999
agent name: ab.cd.ef.gh
generic ID: 9
specific ID: 999
uptime: 9:99:99
bindings: 9.9.9.9.9.9.9.9.9 => Warning: /local/file has reached maximum size
9.9.9.9.9.9.999.9.9.9.9.9 => local_storage
###
!/tmp/demo.pl
A:1[9.9.9.9.9.9.9.9.9 => Warning: /local/file has reached maximum size]
A:2[9.9.9.9.9.9.999.9.9.9.9.9 => local_storage
]Use of uninitialized value in concatenation (.) at /tmp/demo.pl line 11, <DATA> chunk 1.
B:1[9.9.9.9.9.9.999.9.9.9.9.9 => local_storage]
B:2[]
------------------------------
Date: 11 Sep 2003 10:41:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Difference between two regular expressions
Message-Id: <bjpjge$7o$1@mamenchi.zrz.TU-Berlin.DE>
Neil Shadrach <neil.shadrach@corryn.com> wrote in comp.lang.perl.misc:
>
> Why do the two 'print' lines behave differently in the following?
>
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> $/.=$/;
>
> while(<DATA>)
> {
> print "\nA:1[$1]\nA:2[$2]" if /bindings: (?:(.+ => .+)\n?\s*)(?:(.+
> => .+\n?\s*))/;
> print "\nB:1[$1]\nB:2[$2]" if /bindings: (?:(.+ => .+)\n?\s*){2}/;
> }
>
> __DATA__
> community: public
> enterprise: 9.9.9.9.9.9.999.9.9.9.9
> agent addr: 999.99.99.999
> agent name: ab.cd.ef.gh
> generic ID: 9
> specific ID: 999
> uptime: 9:99:99
> bindings: 9.9.9.9.9.9.9.9.9 => Warning: /local/file has reached
> maximum size
> 9.9.9.9.9.9.999.9.9.9.9.9 => local_storage
> ###
> !/tmp/demo.pl
>
> A:1[9.9.9.9.9.9.9.9.9 => Warning: /local/file has reached maximum size]
> A:2[9.9.9.9.9.9.999.9.9.9.9.9 => local_storage
>
> ]Use of uninitialized value in concatenation (.) at /tmp/demo.pl line
> 11, <DATA> chunk 1.
>
> B:1[9.9.9.9.9.9.999.9.9.9.9.9 => local_storage]
> B:2[]
The first patten contains two pairs of capturing parentheses, the second
contains only one. A regex sets only as many $<n> variables as it
captures.
Your problem is obfuscated by a lot of accidential circumstances,
like multiline matching with a non-standard $/, and more. Reduce
it to the simplest terms that still exhibit the problem:
$_ = 'tuttut';
print "$1, $2\n" if /(tut)(tut)/;
print "$1, $2\n" if /(tut){2}/;
Try this technique before posting -- you'll either solve your problem
yourself, or you'll be able to present a much more appealing question.
Anno
------------------------------
Date: Thu, 11 Sep 2003 06:44:49 -0400
From: "Rodney" <NoSpamPlease@bellsouth.net>
Subject: Re: Newsgroup post test...
Message-Id: <clY7b.5248$n82.3733@bignews3.bellsouth.net>
Well, at least my "test" has turned into a discussion.
So, in fact, it is no longer a test....
but instead, it a discussion about "test".
So now it should be a little more acceptable.
:)
--
...
`·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
------------------------------
Date: 11 Sep 2003 10:51:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newsgroup post test...
Message-Id: <bjpk3h$7o$2@mamenchi.zrz.TU-Berlin.DE>
Rodney <NoSpamPlease@bellsouth.net> wrote in comp.lang.perl.misc:
> Well, at least my "test" has turned into a discussion.
>
> So, in fact, it is no longer a test....
> but instead, it a discussion about "test".
A blatantly off-topic one that serves no other purpose than to teach
you some basic Usenet manners.
> So now it should be a little more acceptable.
No. Go away until you have a question or something to contribute.
Anno
------------------------------
Date: 11 Sep 2003 07:28:41 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Number of elements in an array
Message-Id: <bjp879$bc7$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Graham:
> Ron Reidy <r_reidy@comcast.net> wrote in message news:<3F5FAC79.9040301@comcast.net>...
>> Here is my output:
>>
>> DB<3> x @test
>> 0 HASH(0x8393598)
>> 'data' => ARRAY(0x83882f8)
>> 0 1
>> 1 2
>> 2 3
>> 'id' => 'aaa'
>> 'units' => 'kW/m2/st'
>> 1 HASH(0x824bef8)
>> 'data' => ARRAY(0x82a0a60)
>> 0 2
>> 1 4
>> 2 6
>> 'id' => 'bbb'
>> 'units' => 'rad'
>>
>> As you see, data is an array ref...so you should say 'print scalar
>> @{$test[0]{data}' and you will see what you are hoping to.
>
> Many thanks '@{$test[0]{data}}' is exactly what I needed. And people
> call perl a 'read-only' language ;)
No. This is very straight-forward actually, but you may be carried away
by all those parens a little. If you have an array-ref in $ary_ref you
do
@array = @{ $ary_ref };
to dereference it back into an array.
But you can replace $ary_ref with a much more complicated expression. In
your case, the array-ref was in $test[0]{data} (actually, in
$test[0]->{data}; but the arrow can be left out as a shortcut). So the
above becomes
@array = @{ $test[0]{data} };
It can get as fancy as you want, since what you put behind @{ } can be
arbitrarily complicated Perl-code (thousands of lines if you want)...in
the end this code just has to evaluate to an array reference. This means
the last statement in it has to be the reference. Think of it as a
'return' from a subroutine:
@array = @{ print "Hello, world\n";
$test[0]{data}; };
print "@array\n";
__END__
Hello, world
1 2 3
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 11 Sep 2003 09:33:44 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Number of elements in an array
Message-Id: <slrnbm0gbo.ldc.abigail@alexandra.abigail.nl>
Graham (GrahamWilsonCA@yahoo.ca) wrote on MMMDCLXIII September MCMXCIII
in <URL:news:eda30d78.0309102247.29b143c6@posting.google.com>:
`'
`' Thanks Chief, that is exactly what I needed. What a bizarre language.
Feel free to use a less bizarre language instead.
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Thu, 11 Sep 2003 09:04:31 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: perl regex question
Message-Id: <7b70mv477svbe9h7fmkbm3i69fudbm1egm@4ax.com>
On Wed, 10 Sep 2003 17:56:46 -0400, Jeff 'japhy' Pinyan
<pinyaj@rpi.edu> wrote:
>I wouldn't suggest the /(\d+)\D*$/ approach, because it requires you try
>to match at EACH chunk of digits. If there are many chunks of digits in
>your string, that'll be inefficient.
>
>I personally suggest reversing the string, matching the "first" set of
>digits, and then reversing that match.
>
> $last_num = reverse( (reverse($str) =~ /(\d+)/)[0] );
I guess index can be left out since list has only one value,
$last_num = reverse( reverse($procspeed) =~ /(\d+)/ );
------------------------------
Date: 11 Sep 2003 09:42:57 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: Posting with Net::NNTP
Message-Id: <bjpg31$m5nne$1@ID-24002.news.uni-berlin.de>
Mike wrote:
> I've been able to successfully view posts in specific newsgroups now,
> using a "public" news server. However, I'm trying to post, and
> although the program runs without errors, nothing's posting. Can
> someone glance this script over and let me know if it's the program or
> the server?
[...]
> my @message = (
> "Subject: This is a Test",
missing newline
> "From: Mike <csdude\@spampolice.com>",
again
> "Newsgroups: $group",
and again...
> "\nThis is an Net::NNTP test.\n"
> );
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -
------------------------------
Date: 11 Sep 2003 12:20:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Printing a hash of hashes using an array for the headings and getting the columns to line up
Message-Id: <bjpp9q$7o$4@mamenchi.zrz.TU-Berlin.DE>
Mothra <mothra@nowhereatall.com> wrote in comp.lang.perl.misc:
> Hi All,
>
> I am trying to print out a report using a Hash of Hashes and am having
> trouble
> getting the columns to print out correctly. I have an array that contains
> the column
> headings in the correct order but I am stuck as how to get the HoH to use
> this information. I have provided a test script as to what I have tried.
> How can I get the script to print the columns in the correct order.
>
> Thanks
>
> Mothra
>
>
>
> #!/app/perl5.8.0/bin/perl
> use strict;
> use warnings;
>
> my @family = qw(UNIGRAPHICS_NX UNIGRAPHICS SOLID_EDGE WEBTOOLS other);
>
> my %people = (
> 'wattsl' => {
> 'SOLID_EDGE' => 3,
> 'WEBTOOLS' => 10,
> 'UNIGRAPHICS' => 19,
> 'UNIGRAPHICS_NX' => 57
> },
> 'friasd' => {
> 'other' => 2,
> 'SOLID_EDGE' => 10,
> 'WEBTOOLS' => 25,
> 'UNIGRAPHICS' => 21,
> 'UNIGRAPHICS_NX' => 81
> },
> 'yamaguch' => {
> 'other' => 4,
> 'SOLID_EDGE' => 12,
> 'WEBTOOLS' => 11,
> 'UNIGRAPHICS' => 9,
> 'UNIGRAPHICS_NX' => 56
> },
> 'jung' => {
> 'other' => 2,
> 'SOLID_EDGE' => 5,
> 'WEBTOOLS' => 16,
> 'UNIGRAPHICS' => 13,
> 'UNIGRAPHICS_NX' => 39
> },
> 'riches' => {
> 'other' => 2,
> 'SOLID_EDGE' => 18,
> 'WEBTOOLS' => 24,
> 'UNIGRAPHICS' => 10,
> 'UNIGRAPHICS_NX' => 83
> },
>
> );
>
> printf "%24s %10s %10s %8s %5s \n", @family;
>
> foreach my $person( sort keys %people ) {
>
> printf "%9s %2d %2d %2d %2d %2d\n", $person,
> map { $people{$person}{$_} } sort keys %{ $people{$person} };
>
> }
I can't resist the temptation to plug my module Text::Table. Here
is how:
use Text::Table;
my $tb = Text::Table->new( 'name', @family);
$tb->add( $_, @{ $people{ $_}}{ @family}) for sort keys %people;
print $tb;
The advantage is that it figures out the alignment for you, that is,
you don't have to write and maintain the printf format.
Anno
------------------------------
Date: 11 Sep 2003 09:44:04 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Speeding up LWP::Simple
Message-Id: <slrnbm0gv4.ldc.abigail@alexandra.abigail.nl>
John Bokma (postmaster@castleamber.com) wrote on MMMDCLXIII September
MCMXCIII in <URL:news:1063246517.512524@halkan.kabelfoon.nl>:
==
== I live in the Netherlands and finally there will be soon a law that
== makes spamming harder. I don't have read all the details but opt-out is
== forbidden. Not sure if opt in without confirmation is ok, but it
== shouldn't. The only sound way is an opt in *with* confirmation.
Yeah, right. And that's going to help? Local law isn't going to solve
global issues. Unless you have an agreement and commitment amongst
many nations, then you might be able to solve the spam problem with
laws. But a law in a tiny country that makes "gedogen" (meaning that
law enforcement looks the other way) and "let's just ask them to come
with their own rules" standard policies isn't going to solve anything.
== I recently read a mail I wrote, complaining like mad about 5 or 6 spam
== mails a day... those where the days (1997). I receive now 200+ unwanted
== mails a day :-(. Yet I never going as far as changing my email address
== or munging the ones in the headers.
I get tons of unwanted email as well. But spam isn't the biggest
problem, spam filters work well. Bounces from faked email messages
send by virusses are. If you want to make laws, start with outlawing
Microsoft products.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: Thu, 11 Sep 2003 13:48:38 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Splitting and keeping the delimiter
Message-Id: <pan.2003.09.11.11.48.36.729807@kamelfreund.de>
Sandman wrote at Wed, 10 Sep 2003 22:29:57 +0200:
> Hello! I have a string like this:
>
> 12.00 Simpsons 12.30 Seinfeld 13.00 Movie: Dante's Peak
>
> And I want to split that in seperate "programs" that I'd like to deal with
> individually. So, I want this in an array like this:
>
> "12.00 Simpsons",
> "12.30 Seindfeld"
> "13.00 Movie: Dante's Peak"
I wouldn't split it, as it is easier IMHO to describe what you want
instead of what you won't:
my $progstr = "12.00 Simpsons 12.30 Seinfeld 13.00 Movie: Dante's Peak";
my @program = $progstr =~ /\d+\.\d+\s+.*?(?=\s+\d|$)/g;
print join "\n", @program;
Greetings,
Janek
------------------------------
Date: 11 Sep 2003 11:13:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Splitting and keeping the delimiter
Message-Id: <bjplcu$7o$3@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "DKW" == David K Wall <usenet@dwall.fastmail.fm> writes:
>
> DKW> You have workable solutions from several responses. Just one
> DKW> comment: use split() when you know what to throw away, a regex
> DKW> when you know what to keep. (I believe I'm quoting someone, but
> DKW> can't remember whom.)
>
> if he didn't say it first, he surely publicized the most, randal
> schwartz.
...so much so that the saying is sometimes called "Randal's Rule".
------------------------------
Date: Thu, 11 Sep 2003 09:14:20 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: wxPerl
Message-Id: <9m70mvgc4qp1aff3t2ifltevrva9d3nu34@4ax.com>
I would like to install wxPerl on win2k and wander if someone
successfully uses that combination. Step by step RTFMs are greatly
appreciated. :)
TIA
------------------------------
Date: Thu, 11 Sep 2003 10:00:16 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: wxPerl
Message-Id: <3f6043f1.496821521@News.CIS.DFN.DE>
On Thu, 11 Sep 2003 09:14:20 +0200, Matija Papec <mpapec@yahoo.com>
wrote:
>
>I would like to install wxPerl on win2k and wander if someone
>successfully uses that combination. Step by step RTFMs are greatly
>appreciated. :)
Get and install Perl for your Windows machine.
Activestate has a good distribution at (long URL may wrap):
http://activestate.com/Products/Download/Download.plex?id=ActivePerl
WxPerl is not available from Activestate yet, as is appropriate
for version 0.16, but can be downloaded from (long URL may wrap):
http://prdownloads.sourceforge.net/wxperl/Wx-0.16-wxmsw2.4.2-win32-5.8.0.zip
Unzip and install as explained in the README file, i.e.
C:\>ppm install Wx-0.16.ppd
I hope this helps.
------------------------------
Date: Thu, 11 Sep 2003 13:12:30 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: wxPerl
Message-Id: <1tl0mv481ufviu3f348m887dctjmdpmbdh@4ax.com>
On Thu, 11 Sep 2003 10:00:16 GMT, f_baggins80@hotmail.com (Helgi
Briem) wrote:
>>successfully uses that combination. Step by step RTFMs are greatly
>>appreciated. :)
>
>Get and install Perl for your Windows machine.
>Activestate has a good distribution at (long URL may wrap):
>
>http://activestate.com/Products/Download/Download.plex?id=ActivePerl
>
>WxPerl is not available from Activestate yet, as is appropriate
>for version 0.16, but can be downloaded from (long URL may wrap):
>
>http://prdownloads.sourceforge.net/wxperl/Wx-0.16-wxmsw2.4.2-win32-5.8.0.zip
>
>Unzip and install as explained in the README file, i.e.
>
>C:\>ppm install Wx-0.16.ppd
>
>I hope this helps.
Yes, great! Do you have any experience with cygwin? I think it's
easyer to work under it in case you need to compile some module.
------------------------------
Date: Thu, 11 Sep 2003 11:45:11 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: wxPerl
Message-Id: <3f605ff1.503988867@News.CIS.DFN.DE>
On Thu, 11 Sep 2003 13:12:30 +0200, Matija Papec <mpapec@yahoo.com>
wrote:
>Yes, great! Do you have any experience with cygwin?
Yes. I use it and like it.
> I think it's easyer to work under it in case you need to compile
> some module.
I don't use cygwin perl. I have had very good results
with Activestateperl and modules are *extremely*
easy to work with using PPM.
------------------------------
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 5486
***************************************