Is there a one-liner to get the first element of a split?

You should have tried your hunch. That’s how to do it. my $first = (split /\./, “hello.world”)[0]; You could use a list-context assignment that grabs the first field only. my($first) = split /\./, “hello.world”; To print it, use print +(split /\./, “hello.world”)[0], “\n”; or print ((split(/\./, “hello.world”))[0], “\n”); The plus sign is there because of … Read more

Array initialization in Perl

If I understand you, perhaps you don’t need an array of zeroes; rather, you need a hash. The hash keys will be the values in the other array and the hash values will be the number of times the value exists in the other array: use strict; use warnings; my @other_array = (0,0,0,1,2,2,3,3,3,4); my %tallies; … Read more

How can I speed up my Perl program?

Please remember the rules of Optimization Club: The first rule of Optimization Club is, you do not Optimize. The second rule of Optimization Club is, you do not Optimize without measuring. If your app is running faster than the underlying transport protocol, the optimization is over. One factor at a time. No marketroids, no marketroid … Read more

STL map in Perl using SWIG

I put your C++ function into header file as an inline function for testing. I was then able to construct a SWIG interface that does what you are looking for. It has two key parts. Firstly I wrote a typemap that will allow either a std::map, or a perl hash to be given as input … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)