# Syntax Question

What is the meaning of the line below:

my \$hh=join('+',sort {\$a <=> \$b} @l) ; \$f[\$t]=\$hh ;

Also could you explain :

foreach my \$m (split(/\+/,\$f[\$t])) {
push @cl,\$mbd[\$m] ;
}
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
have you considered reading the documentation that comes with Perl?
0
Commented:
What algorithm was the file encrypted with?

0
Commented:
Argh, damn quickpost. :)

0
Commented:
This portion:

my \$hh=join('+',sort {\$a <=> \$b} @l) ;  \$f[\$t]=\$hh ;

Array @l contains elements that are sorted from lowest to highest value and joined with the '+' sign
The result is a scalar, assigned to variable \$hh, which is in turn assigned to the element \$t or the array @f;

For example,
let's say
@l = ('222','333','111');
After:
\$hh=join('+',sort {\$a <=> \$b} @l) ;

\$hh will be equal to  '1+2+3'
and if We have an array with elements
@f = ('first','second','third');
and \$t = 1, then after
\$f[\$t]=\$hh ;

\$f[\$t] will be '1+2+3';
And
@f will be equal to ('first','1+2+3','third');

##########################################################
The Next process takes the value
'1+2+3' and splits it in places where the character '+' is into elements.
It loops though the elements, assigning each current value to variable \$m

foreach my \$m (split(/\+/,\$f[\$t]))
{
push @cl,\$mbd[\$m] ;
}

For each iteration, variable \$m will take a value of  '1', then '2', then '3' because we split the Scalar into these elements.

There is an array @mbd with some elements in it;
If For Example
@mbd = ('First','Second','Third','Fourth');

Then element \$mbd[1] is "Second";
Element \$mbd[2] is "Thurd"; etc.

So when we loop though the splitted elements of the scalar variable \$f[\$t] (which is just one element of an array @f) we get
\$mbd[1] then \$mbd[2]  then \$mbd[3]  because \$m = 1, then \$m = 2, then \$m = 3
Command 'push'; pushes the values of the array \$mbd into a new array - @cl

After the loop finishes, @cl = ('Second','Third','Fourth');

###################################################################

There is nothing more to it.

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Change
#################
For example,
let's say
@l = ('222','333','111');
#################
To:
#################
For example,
let's say
@l = ('2','3','1');
#################
0
Commented:
a. as some has pointed, you're gonna have to buy a good Perl book (I recommend on "Learning Perl" if you're new to programming and or perl. Also, "Programming Perl". Both of them are 3rd edtioins from O'reilly.

b. Here is a sample code for your first question:
my @l = (4,2,8,4,10);
my \$hh=join('+',sort {\$a <=> \$b} @l) ;
print "\$hh\n";

sort {\$a <=> \$b} @l

sort function gets as parameters
a. sorting function (which defaults to asciibetically)
b. a list to sort
Here the sorting function is to sort numerically. This is the meaning of the "Spaceship" operator (<=>). \$a and \$b are special variables to sort, which tells it, in that case to sort in ascending order.

join gets as parameters
a. a joiner character
b. a list to join.
It returns as result the string.

Run this code to see what I mean.

\$f[\$t]=\$hh ;

This is a simple assignment of the result to the \$t element in @f array.

c.
foreach my \$m (split(/\+/,\$f[\$t])) {
push @cl,\$mbd[\$m] ;
}

split(/\+/,\$f[\$t])

split is the reverse of join.
It gets
a. the character to split according to
b. the string to split
It returns a list.

This loop iterates on each element of this list, (which seems like a list of array's indices) in each iteration pushing the result to @cl array.
0
Commented:
c. could also be
push @cl,@mbd[split(/\+/,\$f[\$t]];
or, combining the two:
push @cl,@mbd[sort {\$a <=> \$b} @l];

see
perldoc -f sort
perldoc -f join
perldoc -f split
perldoc -f push
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.