[32391] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3658 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 4 16:09:53 2012

Date: Wed, 4 Apr 2012 13: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           Wed, 4 Apr 2012     Volume: 11 Number: 3658

Today's topics:
        Ajax Based Services Status in Unix <sssdevelop@gmail.com>
    Re: Google Tech Talk: lisp at JPL <cartercc@gmail.com>
    Re: Is Programing Art or Science? <pjb@informatimago.com>
    Re: Is Programing Art or Science? <cartercc@gmail.com>
    Re: Is Programing Art or Science? <xahlee@gmail.com>
    Re: Is Programing Art or Science? (Seymour J.)
    Re: Is Programing Art or Science? <chiron613.no.spam.@no.spam.please.gmail.com>
        pairs to tree <nospam.gravitalsun@hotmail.com.nospam>
    Re: pairs to tree (Tim McDaniel)
    Re: pairs to tree <nospam.gravitalsun.antispam@hotmail.com.nospam>
    Re: reason for local($_) ? jaialai.technology@gmail.com
    Re: reason for local($_) ? (Tim McDaniel)
    Re: reason for local($_) ? <tzz@lifelogs.com>
    Re: reason for local($_) ? <rweikusat@mssgmbh.com>
    Re: reason for local($_) ? (Tim McDaniel)
    Re: splitting to a hashref <cartercc@gmail.com>
    Re: splitting to a hashref <willem@toad.stack.nl>
    Re: splitting to a hashref <nospam.gravitalsun@hotmail.com.nospam>
    Re: splitting to a hashref <nospam.gravitalsun@hotmail.com.nospam>
    Re: splitting to a hashref (Tim McDaniel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 4 Apr 2012 04:07:01 -0700 (PDT)
From: SSS Develop <sssdevelop@gmail.com>
Subject: Ajax Based Services Status in Unix
Message-Id: <5c71bfc5-ab10-4656-ae3a-b0d68a119556@r9g2000yqd.googlegroups.com>

Hello,

Looking for web application, written in Perl - which help me manage
services/applications in Linux Server.

How difficult is  develop such application  Perl which has buttons
"Start" (if service is off), "Stop"(if service is on), "Restart" (if
service is on) services. The status etc should be fetched using Ajax
calls.


Any help in this regard will be of great help.

thank you,

sss


------------------------------

Date: Wed, 4 Apr 2012 08:47:35 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Google Tech Talk: lisp at JPL
Message-Id: <6a4a234d-db48-4659-8714-098d79fb94be@l30g2000yqb.googlegroups.com>

On Apr 3, 1:53=C2=A0am, Xah Lee <xah...@gmail.com> wrote:
> =E3=80=88The Remote Agent Experiment: Debugging Code from 60 Million Mile=
s
> Away=E3=80=89
> Google Tech Talk, (2012-02-14) Presented by Ron Garret. @http://www.youtu=
be.com/watch?v=3D_gZK0tW8EhQ

RG mentions giving a more technical version to a Lisp User Group. Any
chance that this talk is publicly available?

My reaction to this talk, particularly the part near the end, is that
NASA isn't alone. RG uses terms like 'rudderless institutions',
'outreach', 'mission', and others, which would be appropriate when
talking about religious institutions, i.e., churches. I'm not sure
that his prescriptions are addressed to the underlying causes, but
they certainly deal with the symptoms.

As to the question about Python vs. Lisp, I though RG's reaction
(wanting to shed a tear or two) was telling. Languages are tools that
users use to accomplish tasks. Apparently, Python has the appearance
of being a 'better' tool to accomplish programming tasks (at Google,
since that's the context) than Lisp.

My take FWIW is to learn many languages and use them appropriately. In
connection with my job, I recently did a comparison of several
different tasks in C++, ColdFusion, Perl, and Lisp. I use Perl
(mostly) and the tasks were those for which Perl is suited. The
functions are now written in ColdFusion (they are part of a web app.)
I use Lisp in order to highlight the verbosity and ease of different
languages, and even though using Lisp is totally impossible (speaking
to my employer's environment) I can tell you that the Lisp part of the
comparison received the most comment, and the most interesting
comments.

Thanks for the talk, Ron, I really enjoyed it, and wish you (and NASA)
all the best.

CC.


------------------------------

Date: Tue, 03 Apr 2012 20:27:11 +0200
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <871uo4n01s.fsf@kuiper.lan.informatimago.com>

ccc31807 <cartercc@gmail.com> writes:

> On Apr 2, 5:48 pm, "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.


Well, of course.  Those words designate different categories that are
not exclusive.  So it's meaningless to say that programming is or is not
art or science.

Art is something that comes from a quality of the would-be artist.

Science is something that comes from a methodology applied by the
would-be scientist.

Program is something that comes from the work applied by the would-be
programmer.

You can be both a programmer and artist and produce a program
arstistically (like a torero), or an artistic program (like a painter).

You can be both a programmer and scientist, and produce a program
scientifically (like a mathematician), or a science program (like a
physicist). 

You can be both a scientist and artist and produce science artistically,
or art scientifically.

You can be the three, producing programs artistically and
scientifically, or producing artisctic programs scientifically, or
producing scientific programs artistically, etc.

When you produce programs scientifically and artistically you're a 
hacker.

It could be nice to produce scientific programs scientifically, and even
better if your scientific programs are also artistic (so that you can
show the science in an interesting way to the public).
http://www.ted.com/talks/joann_kuchera_morin_tours_the_allosphere.html

You can also produce art programmatically.  For that you need to be both
an artist or a programmer. http://animusic.com/ Or you may try to split
the qualities among a team like at Pixar producing artistic movies
programmatically and scientifically like
http://www.pixar.com/featurefilms/index.html
http://graphics.pixar.com/library/UntanglingCloth/paper.pdf


And the best is to produce scientific programs that are artistic,
scientifically and artistically.  
Then you're an scientifico-artistico-hacker.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


------------------------------

Date: Tue, 3 Apr 2012 12:39:20 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <d9c2ac7b-2c78-4150-b0f1-d67af6c839a5@u5g2000yqu.googlegroups.com>

=93Beauty is more important in computing than anywhere else in
technology because software is so complicated. Beauty is the ultimate
defence against complexity.=94 --David Gelernter


------------------------------

Date: Tue, 3 Apr 2012 14:39:02 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <616c011e-c66e-4d57-9af8-8970327cbdf6@px4g2000pbc.googlegroups.com>

On Apr 3, 8:22=A0am, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
> Xah Lee <xah...@gmail.com> writes:
>
> [...]
>
> > For example, =93Is mathematics science or art?=94, is the same type of
> > question that has been broached by dabblers now and then.
>

 http://en.wikipedia.org/wiki/Liberal_arts

this is the best reply in this thread!

 Xah


------------------------------

Date: Wed, 04 Apr 2012 03:33:24 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: Is Programing Art or Science?
Message-Id: <4f7bf944$9$fuzhry+tra$mr2ice@news.patriot.net>

In <87hax0suun.fsf@sapphire.mobileactivedefense.com>, on 04/03/2012
   at 04:22 PM, Rainer Weikusat <rweikusat@mssgmbh.com> said:

>http://en.wikipedia.org/wiki/Liberal_arts

Do you need the Quadrivium or is the Trivium enough for programming
<g, d & r>?

If the term "art" is good enough for Knuth it's good enough for me.

-- 
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: Wed, 04 Apr 2012 17:52:19 GMT
From: Chiron <chiron613.no.spam.@no.spam.please.gmail.com>
Subject: Re: Is Programing Art or Science?
Message-Id: <nT%er.18676$cP4.7372@newsfe01.iad>

On Wed, 04 Apr 2012 03:33:24 -0400, Shmuel (Seymour J.) Metz wrote:

> If the term "art" is good enough for Knuth it's good enough for me.

I think that may be the most intelligent comment so far...


-- 
Some rise by sin and some by virtue fall.


------------------------------

Date: Wed, 4 Apr 2012 18:06:30 +0300
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: pairs to tree
Message-Id: <jlho10$49i$1@news.ntua.gr>

I am re-thinking an old graph problem . Any idea of how to build e.g. the 
tree

a
 b
  e
  f
 c
 d
  t
t
 a
f
 a

from the pairs ?

f,a
t,a
d,t
b,e
b,f
a,c
a,d
a,b




------------------------------

Date: Wed, 4 Apr 2012 16:03:08 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: pairs to tree
Message-Id: <jlhrbs$p5o$2@reader1.panix.com>

In article <jlho10$49i$1@news.ntua.gr>,
George Mpouras <nospam.gravitalsun@hotmail.com.nospam> wrote:
>I am re-thinking an old graph problem . Any idea of how to build
>e.g. the tree
>
>a
> b
>  e
>  f
> c
> d
>  t
>t
> a
>f
> a
>
>from the pairs ?
>
>f,a
>t,a
>d,t
>b,e
>b,f
>a,c
>a,d
>a,b

I'm curious: for what class is this a homework problem?

Also, I don't see the specification.  The pairs are
    parent,child
and it even appears to be bottom-up.

But sometimes it's shown as transitive, like how
    b,e
    a,b
resulted in
a
 b
  e

But
    t,a
    d,t
does not result in
 d
  t
   a
but instead
t
 a
is itself a side tree.

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Wed, 4 Apr 2012 22:25:33 +0300
From: "George Mpouras" <nospam.gravitalsun.antispam@hotmail.com.nospam>
Subject: Re: pairs to tree
Message-Id: <jli77e$299a$1@news.ntua.gr>

order is not important. pairs are unique. it is about building topology maps.


------------------------------

Date: Tue, 03 Apr 2012 16:47:29 -0400
From: jaialai.technology@gmail.com
Subject: Re: reason for local($_) ?
Message-Id: <adc97$4f7b61e1$813f0835$1757@news.eurofeeds.com>

On 3/29/12 4:08 PM, Peter J. Holzer wrote:
> On 2012-03-29 16:02, Randal L. Schwartz<merlyn@stonehenge.com>  wrote:
>>>>>>> "Ben" == Ben Morrow<ben@morrow.me.uk>  writes:
>> Ben>  That seems bizarre, to me. To *my* mind, $_ belongs to some very small
>> Ben>  block: a for or while (<>) loop a few lines long, or a map or grep
>> Ben>  expression or block. These blocks might occur all over the place, but
>> Ben>  they all set up their own (localised) values for $_, so they don't
>> Ben>  affect each other.
>>
>> The while *doesn't*.  Maybe that's what bit you one day, so that you now
>> practice this "shake a voodoo stick" thing at it.
>
> Uhm. I don't think jaialai was talking about Ben's code.

That is correct. I can affirm that I have never worked with Ben. :)
This was a very enlightening thread an I thank everyone that responded.
At the end of the day Randal is correct, I believe. The author of the
code in question was just blindly adding that line for more or less
uninformed and superstitious reasons.



------------------------------

Date: Tue, 3 Apr 2012 21:41:44 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: reason for local($_) ?
Message-Id: <jlfqqo$f5q$1@reader1.panix.com>

This thread was about a project where every sub was started with
    local($_);

In article <adc97$4f7b61e1$813f0835$1757@news.eurofeeds.com>,
 <jaialai.technology@gmail.com> wrote:
>At the end of the day Randal is correct, I believe. The author of the
>code in question was just blindly adding that line for more or less
>uninformed and superstitious reasons.

I'll disagree, because what's also consistent with the evidence is
"better safe than sorry, prevent an accidental while(<$sth>) or other
place here stomping $_".

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Wed, 04 Apr 2012 09:28:39 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: reason for local($_) ?
Message-Id: <87wr5vd3so.fsf@lifelogs.com>

On Tue, 3 Apr 2012 21:41:44 +0000 (UTC) tmcd@panix.com (Tim McDaniel) wrote: 

TM> This thread was about a project where every sub was started with
TM>     local($_);

TM> In article <adc97$4f7b61e1$813f0835$1757@news.eurofeeds.com>,
TM>  <jaialai.technology@gmail.com> wrote:
>> At the end of the day Randal is correct, I believe. The author of the
>> code in question was just blindly adding that line for more or less
>> uninformed and superstitious reasons.

TM> I'll disagree, because what's also consistent with the evidence is
TM> "better safe than sorry, prevent an accidental while(<$sth>) or other
TM> place here stomping $_".

My personal approach to $_ is very simple.  It follows from two of the
fundamental laws of programming: Know What The Hell Is Going On; and
Life's Too Short To Chase Bugs You Could Have Avoided.

If I know where $_ came from and can *see* the lines of code that
generated $_, I use $_.  So a tight loop or a small block is OK.  Never,
ever would I use $_ inside a function, hoping it's OK.  Regardless of
the optimization, it's just begging a bug report later.

If I don't know if it may have changed, I switch to using a variable.
It's very important not to be lazy about this switch.  Usually for me it
happens when the loop or code block exceeds 3 lines or calls a function.

I thus never have to use "local $_" because I KWTHISGO (hopefully, I say).

And I choose to avoid relying on $_ because LTSTCBYCHA.

Hope that helps...
Ted


------------------------------

Date: Wed, 04 Apr 2012 15:30:37 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: reason for local($_) ?
Message-Id: <8762dfmuwi.fsf@sapphire.mobileactivedefense.com>

tmcd@panix.com (Tim McDaniel) writes:
> In article <adc97$4f7b61e1$813f0835$1757@news.eurofeeds.com>,
>  <jaialai.technology@gmail.com> wrote:
>>At the end of the day Randal is correct, I believe. The author of the
>>code in question was just blindly adding that line for more or less
>>uninformed and superstitious reasons.
>
> I'll disagree, because what's also consistent with the evidence is
> "better safe than sorry, prevent an accidental while(<$sth>) or other
> place here stomping $_".

If you don't know what the code at deeper levels in the call tree is
going to do, how can you be sure that it won't intentionally try to
change 'the global $_'? It is already a bad idea to add code to work
around real bugs in other code and fixing these is always
preferrable (the long-term cost of 'a fucking mess' is usually severly
underestimated when being compared it with the short term cost of
'adding another quick & dirty hack, no time to solve the actual
problem now' ...). It is a really bad idea to add technically useless
code to work around hypothetical errors in other code.



------------------------------

Date: Wed, 4 Apr 2012 15:57:33 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: reason for local($_) ?
Message-Id: <jlhr1d$p5o$1@reader1.panix.com>

In article <8762dfmuwi.fsf@sapphire.mobileactivedefense.com>,
Rainer Weikusat  <rweikusat@mssgmbh.com> wrote:
>tmcd@panix.com (Tim McDaniel) writes:
>> In article <adc97$4f7b61e1$813f0835$1757@news.eurofeeds.com>,
>>  <jaialai.technology@gmail.com> wrote:
>>>At the end of the day Randal is correct, I believe. The author of the
>>>code in question was just blindly adding that line for more or less
>>>uninformed and superstitious reasons.
>>
>> I'll disagree, because what's also consistent with the evidence is
>> "better safe than sorry, prevent an accidental while(<$sth>) or other
>> place here stomping $_".
>
>If you don't know what the code at deeper levels in the call tree is
>going to do, how can you be sure that it won't intentionally try to
>change 'the global $_'?

Indeed it could, and thank you for pointing it out.  If it is possible
for a callee to change a value in a caller, one of the two should save
values and restore them at the end.  For example, in the IBM
System/370 architecture, a subroutine caller must set four registers,
but the callee is responsible for saving and restoring all other
registers.

It's a lot more practical for a callee to protect $_, because it
happens once at the top of the sub instead of every caller potentially
having to protect $_ on every call it makes in a $_-using scope.
I've been assuming that subs preserve $_.  Then again, my orkplace
uses the convention that sub names that start with an underscore are
supposed to be private and not called outside the source file, but
I've seen it happen nonetheless.

I'm thinking that lexical $_ is looking better and better, even with
the problem with map {} and grep {}.

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Tue, 3 Apr 2012 13:59:32 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: splitting to a hashref
Message-Id: <acd7456b-8e52-43c8-a108-a4105a9c8e95@s7g2000yqm.googlegroups.com>

On Apr 3, 11:42=A0am, Keith <bytebrothers...@gmail.com> wrote:
> I'm getting myself all confused - nothing new there.

Do it in small, simple steps, like this. Test each function separately
to see that it does what you expect. There are more sophisticated ways
to do this (e.g., Data::Dumper, Text::ParseWords, etc.) but this will
do what you want.

#! perl
use strict;
use warnings;
my (%in_data, %out_data);
open_file_and_build_in_data();
munge_in_data_to_out_data();
test_hashes();
write_out_data();
exit(0);

open_file_and_build_in_data
{
  open IN, '<', 'in_data.dat' or die "$!";
  while (<IN>)
  {
    chomp;
    my ($val1, $val2, $val3 ...) =3D split(/\/\, $));
    my $in_data{$val1} =3D {
      val2 =3D> $val2,
      val3 =3D> $val3,
      ... };
  }
  close IN;
}
munge_in_data_to_out_data
{
  foreach my $key (keys %in_data)
  {
    #iterate through the keys building your out data
  }
}
test_hashes
{
  #just for sanity's sake
  foreach my $key1 (keys %in_data)
  {
    print "$key1 =3D>\n";
    foreach my $key2 (keys %{$in_data{$key1}})
    {
      print "  $key2 =3D> $in_data{$key1}{$key2}\n";
    }
  }
  foreach my $key1 (keys %out_data)
  {
    print "$key1 =3D>\n";
    foreach my $key2 (keys %{$out_data{$key1}})
    {
      print "  $key2 =3D> $out_data{$key1}{$key2}\n";
    }
  }
}
}
write_out_data
{
  open OUT, '>', 'out_data.dat' or die "$!":
  foreach my $key1 (keys %out_data)
  {
    foreach my $key2 (keys %{$out_data{$key1}})
    {
      print OUT qq($key1,$out_data{$key1}{$key2} ... \n);
    }
    close OUT;
  }
}


------------------------------

Date: Wed, 4 Apr 2012 10:09:51 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: splitting to a hashref
Message-Id: <slrnjno7ff.osg.willem@toad.stack.nl>

Keith wrote:
) 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!

I have no idea what this has to do with slices, but if you want to
transform an array into a hash, you need to use 'map':

 classes => { map { $_ => 'Y' } split '/', ... }

Which will do what you wanted.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Wed, 4 Apr 2012 17:57:33 +0300
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: splitting to a hashref
Message-Id: <jlhng6$1uj$1@news.ntua.gr>

# I want to answer this !

my %company;
my $record = {};

$record->{class_codes} =  "CLASS1/CLASS2/CLASS3/CLASS7/CLASS9";
$company{company_code} = { classes => Doit($record->{class_codes}) };

use Data::Dumper; print Dumper(\%company);

sub Doit {
local $_=[[split/\//,$_[0]],{}];
for (my($i,$j)=(0,1);$i<=$#{$_->[0]};$i+=2,$j+=$i) {
exists $_->[0][$j] ? ($_->[1]{$_->[0][$i]}=$_->[0][$j] ):( 
$_->[1]{$_->[0][$i]} = 'Y' ) }
$_->[1]
} 




------------------------------

Date: Wed, 4 Apr 2012 18:14:34 +0300
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: splitting to a hashref
Message-Id: <jlhog4$6ig$1@news.ntua.gr>

# Sorry , you need this one

my %company;
my $record = {};

$record->{class_codes} =  "CLASS1/CLASS2/CLASS3/CLASS7/CLASS9";
$company{company_code} = { classes => eval{my$H; $H->{$_}='Y' foreach 
split/\//,$record->{class_codes};$H} };

use Data::Dumper; print Dumper(\%company);






------------------------------

Date: Wed, 4 Apr 2012 16:43:19 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: splitting to a hashref
Message-Id: <jlhtn7$qu4$1@reader1.panix.com>

In article <jlhog4$6ig$1@news.ntua.gr>,
George Mpouras <nospam.gravitalsun@hotmail.com.nospam> wrote:
># Sorry , you need this one
>
>my %company;
>my $record = {};
>
>$record->{class_codes} =  "CLASS1/CLASS2/CLASS3/CLASS7/CLASS9";
>$company{company_code} = { classes => eval{my$H; $H->{$_}='Y' foreach 
>split/\//,$record->{class_codes};$H} };
>
>use Data::Dumper; print Dumper(\%company);

If I may comment:

Use of whitespace and indentation can REALLY help readability.  I'm
sorry, but I think the above is a good entry in the Obfuscated Perl
Contest.

$record->{class_codes} =  "CLASS1/CLASS2/CLASS3/CLASS7/CLASS9";
$company{company_code} = {
    classes => eval {
        my $H;
        $H->{$_}='Y' foreach split /\//, $record->{class_codes};
        $H
    }
};
use Data::Dumper; print Dumper(\%company);

We had a discussion in the past few weeks about how to put code blocks
inside expressions.  One major opinion is "don't".  But if you're
going to do it, I think "do { ... }" is better than "eval { ... }",
because if anything dies inside, "eval" will swallow the error unless
you code to expose it (and you need to be more careful about that
depending on the version of Perl).

Looking at that, I still prefer

$company{company_code} = {
    classes => { map { $_, 'Y' } split /\//, $record->{class_codes} }
};

And
    @{$company{company_code}{classes}}[split /\//, $record->{class_codes}] =
        ('Y') x length $record->{class_codes};
is too silly and too obscure.

-- 
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 3658
***************************************


home help back first fref pref prev next nref lref last post