[26407] in Perl-Users-Digest
Perl-Users Digest, Issue: 8578 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 27 14:05:43 2005
Date: Thu, 27 Oct 2005 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 Thu, 27 Oct 2005 Volume: 10 Number: 8578
Today's topics:
FAQ 1.10 Can I do [task] in Perl? <comdog@pair.com>
Hash of hashes, of hashes, of arrays of hashes <timodonovan@noreply.com>
Re: Hash of hashes, of hashes, of arrays of hashes (Anno Siegel)
Re: Hash of hashes, of hashes, of arrays of hashes xhoster@gmail.com
Re: Microsoft Hatred FAQ <davids@webmaster.com>
Re: Microsoft Hatred FAQ <lasse@vkarlsen.no>
Re: printf and variable length? <sashimi123@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 Oct 2005 16:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 1.10 Can I do [task] in Perl?
Message-Id: <djqtnl$a7e$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
1.10: Can I do [task] in Perl?
Perl is flexible and extensible enough for you to use on virtually any
task, from one-line file-processing tasks to large, elaborate systems.
For many people, Perl serves as a great replacement for shell scripting.
For others, it serves as a convenient, high-level replacement for most
of what they'd program in low-level languages like C or C++. It's
ultimately up to you (and possibly your management) which tasks you'll
use Perl for and which you won't.
If you have a library that provides an API, you can make any component
of it available as just another Perl function or variable using a Perl
extension written in C or C++ and dynamically linked into your main perl
interpreter. You can also go the other direction, and write your main
program in C or C++, and then link in some Perl code on the fly, to
create a powerful application. See perlembed.
That said, there will always be small, focused, special-purpose
languages dedicated to a specific problem domain that are simply more
convenient for certain kinds of problems. Perl tries to be all things to
all people, but nothing special to anyone. Examples of specialized
languages that come to mind include prolog and matlab.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Thu, 27 Oct 2005 18:05:33 +0100
From: Tim O'Donovan <timodonovan@noreply.com>
Subject: Hash of hashes, of hashes, of arrays of hashes
Message-Id: <436108dd$1_1@mk-nntp-2.news.uk.tiscali.com>
Hi,
I'm trying to create a data structure that will (eventually) make it
easier to create a series of slightly different XML documents. The
structure will effectively hold a template.
Here's a section of code I am stuck on:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my %xmldoc = (
doc1 => {
customer => [{name => 'count', format => 'int'},
{name => 'unit', format => 'text'},
],
order => [{name => 'expected', format => 'date'},
],
},
#etc
);
The problem I am having is determining how many keys are present in:
$xmldoc{doc1}
and how many elements are present in:
$xmldoc{doc1}{customer}
and so on.
I was then planning on looping through each section and using the data
to contruct the XML.
For reference, here is the dumped output of %xmldoc:
$VAR1 = 'doc1';
$VAR2 = {
'customer' => [
{
'format' => 'int',
'name' => 'count'
},
{
'format' => 'text',
'name' => 'unit'
}
],
'order' => [
{
'format' => 'date',
'name' => 'expected'
}
]
};
Any advice would be greatly appreciated.
Thanks.
Kind regards,
Tim O'Donovan
------------------------------
Date: 27 Oct 2005 17:17:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Hash of hashes, of hashes, of arrays of hashes
Message-Id: <djr23p$bud$2@mamenchi.zrz.TU-Berlin.DE>
Tim O'Donovan <timodonovan@noreply.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I'm trying to create a data structure that will (eventually) make it
> easier to create a series of slightly different XML documents. The
> structure will effectively hold a template.
>
> Here's a section of code I am stuck on:
>
>
> #!/usr/bin/perl -w
>
> use strict;
> use Data::Dumper;
>
> my %xmldoc = (
> doc1 => {
> customer => [{name => 'count', format => 'int'},
> {name => 'unit', format => 'text'},
> ],
> order => [{name => 'expected', format => 'date'},
> ],
> },
> #etc
> );
>
>
> The problem I am having is determining how many keys are present in:
>
> $xmldoc{doc1}
>
> and how many elements are present in:
>
> $xmldoc{doc1}{customer}
>
> and so on.
>
> I was then planning on looping through each section and using the data
> to contruct the XML.
Look up "perldoc -f keys". In scalar context it gives you the number
of keys in a hash, in list context it returns a list of all keys to
loop over.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 27 Oct 2005 17:41:24 GMT
From: xhoster@gmail.com
Subject: Re: Hash of hashes, of hashes, of arrays of hashes
Message-Id: <20051027134124.757$aU@newsreader.com>
Tim O'Donovan <timodonovan@noreply.com> wrote:
> Hi,
>
> I'm trying to create a data structure that will (eventually) make it
> easier to create a series of slightly different XML documents. The
> structure will effectively hold a template.
>
> Here's a section of code I am stuck on:
>
> #!/usr/bin/perl -w
>
> use strict;
> use Data::Dumper;
>
> my %xmldoc = (
> doc1 => {
> customer => [{name => 'count', format => 'int'},
> {name => 'unit', format => 'text'},
> ],
> order => [{name => 'expected', format => 'date'},
> ],
> },
> #etc
> );
>
> The problem I am having is determining how many keys are present in:
>
> $xmldoc{doc1}
$xmldoc{doc1} is a hashref. hashref's don't have keys, so you need to
dereference it, using %{}. Then you need to ask how many keys are in it by
using "keys" in a scalar context.
my $size=keys %{$xmldoc{doc1}};
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 27 Oct 2005 06:08:22 -0700
From: "David Schwartz" <davids@webmaster.com>
Subject: Re: Microsoft Hatred FAQ
Message-Id: <djqjg7$6db$1@nntp.webmaster.com>
Roedy Green wrote:
> 1. it was a threat to destroy a business -- e.g vandalise tens of
> thousands of dollars of property. For all practical purpose they
> threatened to steal my business. It would be roughly the same dollar
> value as threatening to burn down a large house.
No, it was a threat to stop providing you with a business by allowing
you to resell their products.
> 2. it was a threat to force me to commit a criminal act -- namely
> extract money from people and hand it to Microsoft and give those
> people nothing of value in return. That in principle is no different
> from demanding I go out an night and rob people and give MS the
> proceeds. The selected victims were those who expressed a contempt
> for MS products by refusing to buy or even have any need for them.
If you didn't think Windows was worth paying for, don't sell it. An
wholesale agreement that prohibits you from selling competing products is
not at all unusual.
> 3. What MS did was theft, namely taking money from people and giving
> them nothing of value in return against their will.
Then don't agree to it. All you had to do was say no. All you would have
lost was the ability to do business *with* *Microsoft*.
> What if MS had simply made the threat without being specific about how
> they were going to carry it off? Would you consider MS so innocent
> then?
If it could have been in any way taken as a threat to use force, lie to
others about your company, file a lawsuit knowing it had no merit, or
anything of the like, then I would not consider MS innocent at all. To my
mind, that is where the line is drawn.
But in this case, all it seems that Microsoft threatened to do was to
prohibit you from doing business with them. And all they wanted in exchange
was more of what being able to sell their products was actually worth to
you.
The point here is that Microsoft was offering you something of
tremendous value to you. And they, in return, asked for a lot of money from
you. It's really this simple -- is the money they want from you more or less
than the value? If yes, you have no right to complain. If no, why ever did
you agree?
DS
------------------------------
Date: Thu, 27 Oct 2005 15:12:47 +0200
From: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= <lasse@vkarlsen.no>
Subject: Re: Microsoft Hatred FAQ
Message-Id: <djqjoe$qb7$2@sadr.dfn.de>
Roedy Green wrote:
> On Thu, 27 Oct 2005 04:06:16 -0700, "David Schwartz"
> <davids@webmaster.com> wrote, quoted or indirectly quoted someone who
> said :
>
>
>> Right I understand that. You could have complied simply by only selling
>>computers with Windows preinstalled. In other words, you could have treated
>>this the same as a demand for franchise or exclusivity if you had wanted to.
>
>
> It is obvious to everyone WHY MS did this, to maintain monopoly. But
> ignore motive for a while and see what they actually did and exactly
> how they intended to carry out he threat of destroying my business.
> What they did is clearly criminal. The hard part is proving it. Like
> any smart criminal who makes a threat, MS left no paper trail..
<snip>
> 2. it was a threat to force me to commit a criminal act -- namely
> extract money from people and hand it to Microsoft and give those
What, specifically, is the criminal act of which you speak?
--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:lasse@vkarlsen.no
PGP KeyID: 0x2A42A1C2
------------------------------
Date: Thu, 27 Oct 2005 17:17:18 +0200
From: Daemonice <sashimi123@gmail.com>
Subject: Re: printf and variable length?
Message-Id: <0rr1m1lvfim2p27sbf5heljqha9qdruuoe@4ax.com>
Thanks to everybody who answered, it was very useful for me!
------------------------------
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 8578
***************************************