[32390] in Perl-Users-Digest
Perl-Users Digest, Issue: 3657 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 3 14:09:30 2012
Date: Tue, 3 Apr 2012 11:09: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, 3 Apr 2012 Volume: 11 Number: 3657
Today's topics:
Re: First Commercial Perl Program <jimsgibson@gmail.com>
Re: First Commercial Perl Program <justin.1203@purestblue.com>
Re: First Commercial Perl Program <rweikusat@mssgmbh.com>
Re: First Commercial Perl Program <rweikusat@mssgmbh.com>
Re: First Commercial Perl Program (Seymour J.)
Re: First Commercial Perl Program <justin.1203@purestblue.com>
Re: First Commercial Perl Program <rweikusat@mssgmbh.com>
Google Tech Talk: lisp at JPL <xahlee@gmail.com>
Re: Is Programing Art or Science? <jurgenex@hotmail.com>
Re: Is Programing Art or Science? <chiron613.no.spam.@no.spam.please.gmail.com>
Re: Is Programing Art or Science? <tfb@tfeb.org>
Re: Is Programing Art or Science? <dev-null@shared-files.de>
Re: Is Programing Art or Science? <acm@muc.de>
Re: Is Programing Art or Science? <Peter.Davis@mathworks.com>
Re: Is Programing Art or Science? <rweikusat@mssgmbh.com>
Re: Is Programing Art or Science? <cartercc@gmail.com>
Re: New module name (Eclipse::PHPMe) <oneingray@gmail.com>
splitting to a hashref <bytebrothers.uk@gmail.com>
Re: splitting to a hashref <rweikusat@mssgmbh.com>
Re: splitting to a hashref (Tim McDaniel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 02 Apr 2012 18:02:27 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: First Commercial Perl Program
Message-Id: <020420121802277694%jimsgibson@gmail.com>
In article
<f061a0f9-dd9a-4801-882d-310262e3a697@z3g2000pbn.googlegroups.com>,
tbb!/fbr! <ronaldljohnson@gmail.com> wrote:
> Okay, I think I have a very ugly piece of code below. Please keep in
> mind I'm a 'Learning Perl' to 'Intermediate Perl' programmer, and have
> much to learn. I am doing a crapload of manipulations below, but I'm
> sure it could all be done in a line or two, not the 6-8 lines I did it
> in. I understand the way I did it, but again, am looking for options
> on how someone more experienced would do it.
It helps to figure out your program if we know what you are trying to
do. In this case, it looks like you are trying to generate a string of
140 random characters.
>
> use List::Util qw(shuffle);
> my $str='1234567890!@#$
> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
> =[]\;\',./1234567890!@#$
> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
> =[]\;\',./';
Here is a way to build up your source string from pieces that are
easier to type and understand:
my $numbers = join('',(0..9));
my $letters = join('',('a'..'z'));
my $ucletters = uc $letters
my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
my $str = $numbers . $letters. $ucletters. $punct;
$str .= $str;
> my @bits=split(//,$str);
> my @rnd=shuffle(@bits);
> my $stringer="@rnd";
> $stringer=~s/\s//g;
> $stringer=substr($stringer,0,140);
What Rainer said. I would add that their aren't any whitespace
characters in your source, so their shouldn't be any in your output.
--
Jim Gibson
------------------------------
Date: Tue, 3 Apr 2012 10:56:44 +0100
From: Justin C <justin.1203@purestblue.com>
Subject: Re: First Commercial Perl Program
Message-Id: <s3uq49-ar9.ln1@zem.masonsmusic.co.uk>
On 2012-04-03, Jim Gibson <jimsgibson@gmail.com> wrote:
> In article
> <f061a0f9-dd9a-4801-882d-310262e3a697@z3g2000pbn.googlegroups.com>,
> tbb!/fbr! <ronaldljohnson@gmail.com> wrote:
>
>> Okay, I think I have a very ugly piece of code below. Please keep in
>> mind I'm a 'Learning Perl' to 'Intermediate Perl' programmer, and have
>> much to learn. I am doing a crapload of manipulations below, but I'm
>> sure it could all be done in a line or two, not the 6-8 lines I did it
>> in. I understand the way I did it, but again, am looking for options
>> on how someone more experienced would do it.
>
> It helps to figure out your program if we know what you are trying to
> do. In this case, it looks like you are trying to generate a string of
> 140 random characters.
>>
>> use List::Util qw(shuffle);
>> my $str='1234567890!@#$
>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
>> =[]\;\',./1234567890!@#$
>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
>> =[]\;\',./';
>
> Here is a way to build up your source string from pieces that are
> easier to type and understand:
>
> my $numbers = join('',(0..9));
> my $letters = join('',('a'..'z'));
> my $ucletters = uc $letters
> my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
> my $str = $numbers . $letters. $ucletters. $punct;
> $str .= $str;
Seeing as the OP, after constructing a string, then converts it into an
array, why not skip straight to the array... at least with the easy
bits:
my @bits = (0..9, "a".."z", "A".."Z");
my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
push @bits, $_ for (split(//, $punct));
>> my @bits=split(//,$str);
>> my @rnd=shuffle(@bits);
>> my $stringer="@rnd";
>> $stringer=~s/\s//g;
>> $stringer=substr($stringer,0,140);
>
> What Rainer said. I would add that their aren't any whitespace
> characters in your source, so their shouldn't be any in your output.
>
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 03 Apr 2012 12:17:09 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: First Commercial Perl Program
Message-Id: <87pqbpkqtm.fsf@sapphire.mobileactivedefense.com>
Jim Gibson <jimsgibson@gmail.com> writes:
[...]
>> my $str='1234567890!@#$
>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
>> =[]\;\',./1234567890!@#$
>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
>> =[]\;\',./';
[...]
> their aren't any whitespace characters in your source, so their
> shouldn't be any in your output.
There are: the newlines (\n).
------------------------------
Date: Tue, 03 Apr 2012 12:27:57 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: First Commercial Perl Program
Message-Id: <87limdkqbm.fsf@sapphire.mobileactivedefense.com>
Justin C <justin.1203@purestblue.com> writes:
> On 2012-04-03, Jim Gibson <jimsgibson@gmail.com> wrote:
[...]
>>> use List::Util qw(shuffle);
>>> my $str='1234567890!@#$
>>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
>>> =[]\;\',./1234567890!@#$
>>> %^&*()qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_+{}|:"<>?~`-
>>> =[]\;\',./';
>>
>> Here is a way to build up your source string from pieces that are
>> easier to type and understand:
>>
>> my $numbers = join('',(0..9));
>> my $letters = join('',('a'..'z'));
>> my $ucletters = uc $letters
>> my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
>> my $str = $numbers . $letters. $ucletters. $punct;
>> $str .= $str;
>
> Seeing as the OP, after constructing a string, then converts it into an
> array, why not skip straight to the array... at least with the easy
> bits:
>
> my @bits = (0..9, "a".."z", "A".."Z");
> my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
> push @bits, $_ for (split(//, $punct));
Including the result of this code as literal value in the source is a
better idea than regenerating it everytime the code runs. A way to do
this with an array (assumes ASCII and relies on ord('(') < ord(')')) would be:
----------
@chars = map { $c = chr($_); $c =~ /[[:graph:]]/ ? $c : (); } (0 .. 127);
print('my @chars = qw(', join(' ', @chars, @chars), ");\n");
----------
This will print Perl-code creating and initializing the array @chars
with a suitable set of values and this code can then be included
in the script. It is also a nice example of something useful which
can't be 'enhanced' by use warning; use strict :-).
------------------------------
Date: Tue, 03 Apr 2012 08:07:10 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: First Commercial Perl Program
Message-Id: <4f7ae7ee$7$fuzhry+tra$mr2ice@news.patriot.net>
In <s3uq49-ar9.ln1@zem.masonsmusic.co.uk>, on 04/03/2012
at 10:56 AM, Justin C <justin.1203@purestblue.com> said:
>my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
>push @bits, $_ for (split(//, $punct));
Why not push @bits, split(//, $punct);
or eliminate $punct and use
push @bits, split(//, q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()");
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Tue, 3 Apr 2012 14:42:33 +0100
From: Justin C <justin.1203@purestblue.com>
Subject: Re: First Commercial Perl Program
Message-Id: <9bbr49-7jd.ln1@zem.masonsmusic.co.uk>
On 2012-04-03, Shmuel Metz <spamtrap@library.lspace.org.invalid> wrote:
> In <s3uq49-ar9.ln1@zem.masonsmusic.co.uk>, on 04/03/2012
> at 10:56 AM, Justin C <justin.1203@purestblue.com> said:
>
>>my $punct = q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()";
>>push @bits, $_ for (split(//, $punct));
>
> Why not push @bits, split(//, $punct);
>
> or eliminate $punct and use
>
> push @bits, split(//, q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()");
'cos I'm not that smart, yet...
I'm working on it, though.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 03 Apr 2012 15:48:27 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: First Commercial Perl Program
Message-Id: <87obr8swg4.fsf@sapphire.mobileactivedefense.com>
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid> writes:
[...]
> or eliminate $punct and use
>
> push @bits, split(//, q(!@#$%^&*_+{}|:"<>?~`-=[];',./) . "()");
[rw@sapphire]~ $perl -e '$a = q(()); print $a, "\n";'
()
------------------------------
Date: Mon, 2 Apr 2012 22:53:11 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: Google Tech Talk: lisp at JPL
Message-Id: <cef54fe5-768d-47f8-8e8b-a69a91b7358f@9g2000pbn.googlegroups.com>
Dearly beloved lisperati,
I present you, Ron Garret (aka Erann Gat =E2=80=94 aka Naggum hater and ene=
my
of Kenny Tilton), at Google Tech Talk
=E3=80=88The Remote Agent Experiment: Debugging Code from 60 Million Miles
Away=E3=80=89
Google Tech Talk, (2012-02-14) Presented by Ron Garret. @
http://www.youtube.com/watch?v=3D_gZK0tW8EhQ
i just started watching, havn't done yet.
(thx jcs's blog for the news)
PS posted to python and perl forums too, because i think might be
interesting for lang aficionados . Reply to just your community
please.
Xah
------------------------------
Date: Mon, 02 Apr 2012 16:52:35 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <rpekn71hd2c0hjl1d43648i0bihnkri473@4ax.com>
"Pascal J. Bourguignon" <pjb@informatimago.com> wrote:
>ccc31807 <cartercc@gmail.com> writes:
>
>> Programming is neither an art nor a science, but a trade.
Oh, that's why it is tought in trade schools alongside butchery,
plumbing, masonry, and chimney sweeping and why you don't find any
programming classes at university.
jue
------------------------------
Date: Tue, 03 Apr 2012 04:26:58 GMT
From: Chiron <chiron613.no.spam.@no.spam.please.gmail.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <m_uer.48640$M%7.30157@newsfe10.iad>
On Fri, 30 Mar 2012 01:27:16 -0700, Xah Lee wrote:
> 〈Is Programing Art or Science〉
Why is this question important?
--
You are confused; but this is your normal state.
------------------------------
Date: Tue, 3 Apr 2012 10:42:34 +0100
From: Tim Bradshaw <tfb@tfeb.org>
Subject: Re: Is Programing Art or Science?
Message-Id: <jlegma$lhp$1@dont-email.me>
On 2012-04-03 00:52:35 +0100, Jürgen Exner said:
> Oh, that's why it is tought in trade schools alongside butchery,
> plumbing, masonry, and chimney sweeping and why you don't find any
> programming classes at university.
So, you know, no one would do law or medicine at a university. Oh, wait.
------------------------------
Date: Tue, 03 Apr 2012 12:17:03 +0200
From: Torsten Mueller <dev-null@shared-files.de>
Subject: Re: Is Programing Art or Science?
Message-Id: <3dlimdxgps.fsf@shared-files.de>
Xah Lee <xahlee@gmail.com> wrote:
> So, is programing a art or science? is it art or science? I really
> need to know.
Sience? Almost never.
It's handcraft.
Seldom, in very rare cases, it's true art for a very limited audience,
mostly it's routine, and in many cases it's also idiocy.
T.M.
------------------------------
Date: Tue, 3 Apr 2012 10:42:21 +0000 (UTC)
From: Alan Mackenzie <acm@muc.de>
Subject: Re: Is Programing Art or Science?
Message-Id: <jlek6d$1p6a$1@colin.muc.de>
Hi, Xah,
In comp.emacs Xah Lee <xahlee@gmail.com> wrote:
> For these computing jockeys, there remains the question of why Knuth
> named his books the ?Art? of Computer Programing, or why some
> computing luminaries litter the caution that programing is as much a
> art as science. What elite dimwits need to realize is that these
> authors are not defining or correcting, but breaking precepts among
> the automatons in programing industry.
He was using art in the sense of "the exercise of human skill (as
distinguished from nature)". That's the second definition in my
dictionary. When people talk about, for example, the art of painting
water colours, they mean the techniques of mixing paints, depicting
objects on paper, etc. They are not referring to the artistic value of
the painting painted.
> yours humbly,
>
> Xah
--
Alan Mackenzie (Nuremberg, Germany).
------------------------------
Date: Tue, 03 Apr 2012 09:20:45 -0400
From: Peter Davis <Peter.Davis@mathworks.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <jletfd$52u$1@newscl01ah.mathworks.com>
On 3/30/2012 4:27 AM, Xah Lee wrote:
> Is Programing Art or Science?
>
Programming itself is a bit like being a natural language translator for
an autistic person. You have to understand the "message" to be
communicated, and then interpret it *very* literally for the listener.
Note that programming is just one of a set of activities and skills that
are part of software engineering. Others include UI design (which
combines visual design, psychology, etc.), software architecture (which
is like ... well, architecture) and various other skills.
Collectively, "engineering" is the best catch-all description. Is
building a bridge art or science? A little of both, and some other
things as well.
-pd
------------------------------
Date: Tue, 03 Apr 2012 16:22:56 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <87hax0suun.fsf@sapphire.mobileactivedefense.com>
Xah Lee <xahlee@gmail.com> writes:
[...]
> For example, “Is mathematics science or art?â€, is the same type of
> question that has been broached by dabblers now and then.
http://en.wikipedia.org/wiki/Liberal_arts
HTH.
------------------------------
Date: Tue, 3 Apr 2012 10:00:17 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <72e8ce7a-0c00-4436-80cd-8f3d79cbcfa2@f37g2000yqc.googlegroups.com>
On Apr 2, 5:48=A0pm, "Pascal J. Bourguignon"
> This is a narrow-minded definition of programming.
Well, that's the point.
If we make a list and include things like:
computer science
software engineering
computer engineering
discrete math
logic
formal methods
web development
computer graphics
information technology
information management
data processing
database management
database administration
network administration
artificial intelligence
... and so on and so forth ...
Some of these involve real art. Some of these involve real science.
Even engineering can be considered as science, in a way, and perhaps
art in a way. All these include programming! HOWEVER, 'programming'
seen as 'talking to a computer' is neither an art nor a science, but
simply a learned skill, like plumbing or cabinet making, or even
medicine or law.
I was a lawyer for 14 years, so I know what I'm talking about: the
practice of law in the ordinary sense is simply that, the practice of
law, and as such it's not an art nor a science, but simply a trade,
albeit a highly skilled and abstract trade. And yes, lawyers can be
artists and scientists, but neither one of these is basic to the
practice of law.
I'm not saying that artists and scientists can't be programmers. Many
of them are. What I'm saying is that you can program a computer (i.e.,
practice programming) without being either an artist or a scientist.
CC.
------------------------------
Date: Tue, 03 Apr 2012 12:27:38 +0700
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: New module name (Eclipse::PHPMe)
Message-Id: <86r4w575bp.fsf@gray.siamics.net>
>>>>> kinow <brunodepaulak@yahoo.com.br> writes:
[Cross-posting to news:comp.lang.perl.misc, for
news:comp.lang.perl.modules has somewhat low activity these
days.]
> Hi all! I wrote a Perl utility to turn an ordinary directory into an
> Eclipse PHP project. I'm new to CPAN and Perl, so I have few
> questions:
> - Is CPAN the right place for it? It's only a script (referenced in
> EXE_FILES in Makefile.PL). I intend to use this script as I'm always
> importing different PHP projects in Eclipse and it can be handy
> - I've looked for the Eclipse namespace in CPAN, searching for
> Eclipse with the filter set to 'Module', and found nothing. Is
> Eclipse::PHPMe a good name?
There's the App:: namespace prefix for applications (and
scripts):
--cut: https://pause.perl.org/pause/query?ACTION=pause_namingmodules --
App
You can distribute applications as Perl distributions. Typically,
those sorts of distributions go under the App namespace, like
App::Ack, App::Cpan, and App::Prove. The namespace implies that its
a ready-to-use program rather than a module.
--cut: https://pause.perl.org/pause/query?ACTION=pause_namingmodules --
There seem to be a plenty of Perl applications distributed this
way. Consider, e. g.:
http://search.cpan.org/~petdance/ack-1.96/
http://search.cpan.org/~rjbs/App-Addex-0.023/
[...]
--
FSF associate member #7257
------------------------------
Date: Tue, 3 Apr 2012 08:42:03 -0700 (PDT)
From: Keith <bytebrothers.uk@gmail.com>
Subject: splitting to a hashref
Message-Id: <7ed9bf3e-b85c-4764-9d6c-6753d3fe61b2@h20g2000yqd.googlegroups.com>
I'm getting myself all confused - nothing new there.
I'm building a data structure something like this (greatly
simplified):
my %company;
.
.
$company{company_code} = {
classes => [ split ('/',
$record->{class_codes}) ]
}
The incoming data field 'class_codes' is structured like this:
"CLASS1/CLASS2/CLASS3/CLASS7/CLASS9"
This means my data structure ends up with an entry called 'classes'
which holds an array reference to a list of class codes. What I'd
really like is that entry to hold a hash reference where each key is a
class code, and the corresponding value is 'Y' (for example).
I did try changing that line to read:
classes => { split ('/',
$record->{class_codes}) => 'Y' }
But that gives me this:
$VAR1 = {
'classes' => {
'CLASS9' => 'Y',
'CLASS3' => 'CLASS7',
'CLASS1' => 'CLASS2'
}
};
I'm missing something fundamental about slices here, I guess. Please
help!
------------------------------
Date: Tue, 03 Apr 2012 17:00:36 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: splitting to a hashref
Message-Id: <87d37ost3v.fsf@sapphire.mobileactivedefense.com>
Keith <bytebrothers.uk@gmail.com> writes:
> I'm getting myself all confused - nothing new there.
>
> I'm building a data structure something like this (greatly
> simplified):
>
> my %company;
> .
> .
> $company{company_code} = {
> classes => [ split ('/',
> $record->{class_codes}) ]
> }
>
> The incoming data field 'class_codes' is structured like this:
>
> "CLASS1/CLASS2/CLASS3/CLASS7/CLASS9"
>
> This means my data structure ends up with an entry called 'classes'
> which holds an array reference to a list of class codes. What I'd
> really like is that entry to hold a hash reference where each key is a
> class code, and the corresponding value is 'Y' (for example).
{ map { $_, 'Y'; } split('/', $record->{class_codes}); }
>
> I did try changing that line to read:
> classes => { split ('/',
> $record->{class_codes}) => 'Y' }
This means you initialize the hashref with the list of 'classes', as
created by split, and a trailing 'Y' appended. Each adjacent pair of
members of this list will become a (key, value) pair of the hash (=>
is just a fancy way to write ,).
------------------------------
Date: Tue, 3 Apr 2012 16:03:47 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: splitting to a hashref
Message-Id: <jlf713$i06$1@reader1.panix.com>
In article
<7ed9bf3e-b85c-4764-9d6c-6753d3fe61b2@h20g2000yqd.googlegroups.com>,
Keith <bytebrothers.uk@gmail.com> wrote:
>I'm building a data structure something like this (greatly
>simplified):
>
>my %company;
>.
>.
>$company{company_code} = {
> classes => [ split ('/',$record->{class_codes}) ]
>}
(I removed massive whitespace)
>The incoming data field 'class_codes' is structured like this:
>
>"CLASS1/CLASS2/CLASS3/CLASS7/CLASS9"
>
>This means my data structure ends up with an entry called 'classes'
>which holds an array reference to a list of class codes. What I'd
>really like is that entry to hold a hash reference where each key is
> a class code, and the corresponding value is 'Y' (for example).
>
>I did try changing that line to read:
> classes => { split ('/', $record->{class_codes}) => 'Y' }
>
>But that gives me this:
>$VAR1 = {
> 'classes' => {
> 'CLASS9' => 'Y',
> 'CLASS3' => 'CLASS7',
> 'CLASS1' => 'CLASS2'
> }
> };
>
>I'm missing something fundamental about slices here, I guess. Please
>help!
Perl isn't quite as slicy as you'd like. Also, => is not a special
pairing operator; it's just a fancy-pants way of writing ",". So the
guts are equivalent to
{ split ('/', $record->{class_codes}), 'Y' }
which evaluates to a list of just the class codes, followed by one
"Y", so it's just
{ 'CLASS1', 'CLASS2', 'CLASS3', 'CLASS7', 'CLASS9', 'Y' }
{...}, or other uses of lists where it's expecting a hash, then does
the pairing, using alternating elements of the list as key and value
in that order. That produces your result (out of alphabetical order
because Perl hashes do that).
Perl doesn't provide the pairing you want, so you have to do it by
hand:
classes => { map { $_, 'Y' } split ('/', $record->{class_codes}) }
(Most people would actually write "$_ => 'Y'", but I want to emphasize
to you that => really IS a comma, and what's important is having
key followed by value.)
{} have two different meanings here. {} in map{} are code block
delimiters, like if{} or sub{}. It's the outer {...} that make an
anonymous hash ref.
Or you could assign to a temp array and do a foreach, or do something
involving
@classes{@classes_array} = ('Y') x scalar @classes_array;
but that map version is really simplest.
--
Tim McDaniel, tmcd@panix.com
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 3657
***************************************