Java CSV to Array and Array to CSV

This is a little example in Java to convert a CSV String into an Multidimensional Array, after that i convert the Array back into a CSV String, you could choose the delimiter by yourself. In this case i take the “-” to see the different:

This is the Output, fist block separated with the “;” is the input and with “-” is the output:

perl shuffle String and Array

I wrote a little script in Perl to shuffle Arrays or strings:

This are my examples:

and we got his as result:

Perl reference vs. handing over Benchmark

I want to know if there is a different between a shift and normal handing over to a sub in Perl.This is only for scalar, for big data(array,hash) there is of course a different.

Our result:

If its not necessary we should avoid references for scalar types, and try to iterate and not shift: Perl shift iterate Benchmark.But for Skalar values it is the fastest way to use prototypes.

Perl array vs. hash handing over Benchmark

I want to compare the hash and array in Perl and both of them with a reference and a normal handing over.That is the code, I tried to hold it as simple and fast as possible:

Our result :

Looks good, the keys from the hashes are not sorted but I don’t want to waste performance with a sort.

 

Now this is the Benchmark result from 1..4 :

We could see the normal array is faster than the shift and prototype so for small data a reference is not faster than a normal use, but by the hash it is much faster than a normal handing over.and we could see array is faster than a hash, but the hash takes more information (key and values).

 

And this is the Benchmark result from 1..1000 :

Now the reference from the array and hash are both fastest, the hash is always slower than the array.Just take a look at scalars.

Perl remove double entries in array Benchmark

Today I Benchmark two solution to remove all double entries from an array in Perl:

We see the second function is 18% faster than the other one:

 

Now we have a good fast solution to remove the double entries from our array:

Our result:

Perl shift iterate Benchmark

This little Perl Benchmark shows that its better to iterate through an array as to manipulate via shift.For more about shift look at Perl array pop, push, shift, unshift.

We see its better to iterate as to shift from an array:

Perl array order to highest numbers

This example Perl-Script find the highest number in the array with the highest number and set it to 1 and then count up to the lowest.

Result looks like this:

Perl search in array

This Perl example is a function where I search for an element in an array, it returns the position or -1 if nothing matches.

As result we get for 9 -> 3 and for 4 -> -1 seems good.

Perl finding all number bigger than 10

In this example we want to filter all elements bigger than 10, for that we use grep like in this function:

We got this as result:

Perl graph

This Perl example function shows how to generate a graph from a array.

The sub returns this result: