Click here to get back home

Merging/Joining AoA

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Merging/Joining AoA Vishal G 04-22-2008
Posted by nolo contendere on April 23, 2008, 10:46 am
Please log in for more thread options
On Apr 22, 11:49=A0pm, benkasminbull...@gmail.com wrote:
> > I'm not sure how much control you have over the structure of the data,
> > but it seems to me that you would be better served if the data were
> > stored in hashes to begin with:
>
> If the person needs to know how to put in a screw, why tell him he
> would be better served by using nails and a hammer?


huh? i began my suggestion with the caveat that this would be relevant
if the OP had the control to choose the data structures in which he
housed his data. to follow up on your analogy, if the person needs to
know how to build a house, and is scratching his head wondering how to
do it with only screws and a screwdriver, yes, i could help him by
telling him how to go about it.

or, i can point out that there is a tool shed around the corner of
which he is unaware, and then proceed to pick out more appropriate
tools that he can use to better build his house.

here's another analogy. if he asked, how do i add the following?
<<END_WORD_PROBLEM;

i want to add three 6's and six 4's using addition. sure, you could
say: well, first compute the sum of the three 6's, like so--
6 + 6 + 6 =3D 18.
then, compute the sum of six 4's, like so--
4 + 4 + 4 + 4 + 4 + 4 =3D 24.
finally, add the two sums together.
18 + 24 =3D 42.
END_WORD_PROBLEM

Or, I could make life a whole lot easier by suggesting:
just do: (3 x 6) + (6 x 4) =3D 42.

what's wrong with that? at the very worst, if there are restrictions
in place that prohibit him from using multiplication for this
particular problem, he is at least aware that there is a better
solution for similar problems in the future, when such restrictions
may may be lifted, or not even exist at all.

=2E..or did you just want an excuse to post that quote by Steven
King? ;-).


Posted by Ben Bullock on April 23, 2008, 6:47 pm
Please log in for more thread options
On Wed, 23 Apr 2008 07:46:35 -0700, nolo contendere wrote:

> On Apr 22, 11:49 pm, benkasminbull...@gmail.com wrote:

>> If the person needs to know how to put in a screw, why tell him he
>> would be better served by using nails and a hammer?
>
>
> huh? i began my suggestion with the caveat that this would be relevant
> if the OP had the control to choose the data structures in which he
> housed his data. to follow up on your analogy, if the person needs to
> know how to build a house, and is scratching his head wondering how to
> do it with only screws and a screwdriver, yes, i could help him by
> telling him how to go about it.

Well, I'm sorry to offend you.

> ...or did you just want an excuse to post that quote by Steven King?
> ;-).

No, I think it was the correct time to post that quote. Or maybe a more
relevant quote would be something about how if you endlessly try to
finesse things, you'll never actually get the job done. Perl programmers
should know how to deal with awkward data formats like the original
poster's, because these do occur in practice, and they may be unavoidable
for one reason or another.



Posted by Tad J McClellan on April 23, 2008, 11:02 pm
Please log in for more thread options
>
>> I'm not sure how much control you have over the structure of the data,
>> but it seems to me that you would be better served if the data were
>> stored in hashes to begin with:
>
> If the person needs to know how to put in a screw, why tell him he
> would be better served by using nails and a hammer?


Errr, because he would be better served, of course.


Q: I need to put a lot of screws in to hold the shingles on the roof.
Can anyone suggest a good power screwdriver?

A: You would be better served by using nails and a nail gun.


If you use screws it will take you 2 days to finish instead of 1 day.

Even worse, when you need to maintain your roof, it will take you
4 days to remove the old one instead of 1 day if you had used nails.



Choice of an approriate data structure is very important in designing
a software solution. (It made this task into a one-liner.)

If you don't have a choice of data structure, then you must
bite the bullet and write 10 or 20 lines of code.

nolo gave an appropriate predicate to his advice.

Seems clear enough that the advice should be skipped if the predicate
is not true...


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Posted by Ben Bullock on April 23, 2008, 11:16 pm
Please log in for more thread options

>> If the person needs to know how to put in a screw, why tell him he
>> would be better served by using nails and a hammer?
>
>
> Errr, because he would be better served, of course.
>
>
> Q: I need to put a lot of screws in to hold the shingles on the roof.
> Can anyone suggest a good power screwdriver?
>
> A: You would be better served by using nails and a nail gun.

Since I have no idea what the original poster's task was, why
speculate about it?

> Choice of an approriate data structure is very important in designing
> a software solution. (It made this task into a one-liner.)
>
> If you don't have a choice of data structure, then you must
> bite the bullet and write 10 or 20 lines of code.

My original solution had ten lines of code, it's true. But if you want
to reduce the lines of code, it's perfectly possible:

my %ak = (map @a);
my %bk = (map @b);
for (sort keys %ak) {my $v=$bk; push @c, [@}, @$v[1..$#$v]] if $v}
unshift @c, pop @c; # Just for Harmut Camphausen

That has the disadvantage of being less clear to read but it does
exactly the same thing.

If I was doing this for real I'd be much more worried about
problems such as empty values in the first column of the array, or
duplicate IDs in @a, or what to do with values which are in @a but not
in @b or vice-versa, than I would be about turning the whole thing into
a hash keyed by the values on the first line. That could just as
easily make other parts of the program more complicated, and it seems
to me that Perl programmers should be able to write code to deal with
arrays of arrays without getting confused, or write a regular
expression to match single quoted strings.

So I'm not sure what the point of the original advice was. To me it's
just confusing the issue.


Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap