[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Merging elements



Before reading on , please take note of 1 point -I didn't write it in a
more compact form as the poster probably hasn't been using Perl very long.
To put it quite bluntly Mr Kimball, you don't seem to  remember what it was
like to learn.

>> $in=~tr/ //s; #take out any unwanted extra spaces
>> @raw_data = split(/\s/,$in); #load the data into an array for manipulation

Ronald J Kimball wrote:
>What's wrong with split(' ', $in)??

using the data as it was given, a simple split won't work as there are
extra spaces in the data :-).  Secondly so the poster can see where the
data is going  I purposely don't use implicit $_ or @_ throughout the script


>Why are you going to all the trouble of creating a hash with the keys and
>values backwards, when you're going to end up reversing the hash anyway?
>
>Especially when you're basing your assumption that all the values are
>unique on a very small sample of input data.

from the small snippet of code, neither  you nor I know what the greater
picture is, based on what is under your nose however the PERL approach to
dealing with this situation - ie using a HASH to extract unique elements
from a list - is clear.

>I would not recommend using this approach to solve the problem.
just as I wouldn't recommend your approach to a newbie learning the trade
:-), but rather as an example of nicely turned code for those who
understand the it. <SMILE>It all depends on your motivations for posting,
doesn't it</SMILE>


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org