value

Scala - Using tuples in an anonymous function

I just ran across this post about using tuples in an anonymous function, and thought it was good enough to reproduce here, with only the solution part.

In essence, the question is, if I have a Map like this, which is actually composed of tuples:

scala> val x = Map(1 -> "foo", 2 -> "bar")
x: scala.collection.immutable.Map[Int,String] = Map(1 -> foo, 2 -> bar)

how do I use each value in the tuples in an anonymous function?

Initialize Scala variables with Option, None, and Some (not null)

Summary: How to properly use the Scala Option/Some/None idiom to initialize empty var fields -- and specifically how not to use null values for the same purpose.

When you get started in the Scala world, you quickly learn that null values are a bad thing. Scala makes it easy to replace null values with something better, and that something better is what I call the Option/Some/None pattern (or idiom).

PHP array - How to loop through a PHP array

PHP array FAQ: How do I iterate (loop) through a PHP array?

Answer: The easiest way to loop through a PHP array is to use the PHP foreach operator. If you have a simple one-dimensional array, like the $argv array which lets you access command line arguments, you can loop through it like this:

My Perl hash tutorials

Perl hash tutorials FAQ: Can you share some Perl hash tutorials, or Perl hash examples?

I've recently written a number of articles about the Perl hash construct (or "Perl array hash"). In an effort to try to organize the Perl hash tutorials I've written, I've created this article to help link them all together.

Perl hash add element - How to add an element to a Perl hash

Perl hash "add" FAQ: How do I add a new element to a Perl hash? (Or, How do I push a new element onto a Perl hash?)

The Perl hash is a cool programming construct, and was very unique when I was learning programming languages in the late 1980s. A Perl hash is basically an array, but the keys of the array are strings instead of numbers.

Basic Perl hash "add element" syntax

To add a new element to a Perl hash, you use the following general syntax:

Perl hash introduction tutorial

Perl hash FAQ: Can you share some simple Perl hash examples?

Sure. If you're not familiar with them, a Perl hash is simply a Perl array that is indexed by a string instead of a number. A Perl hash is like a Map in the Java programming language, or an array in PHP.

Perl hash - Background information

To get started looking at a hash in Perl, let's look at a simple example. First, let's assume that Perl hashes don't exist. Next, lets assume that we need to store the prices of various food items you'll find in a restaurant.

Perl hash sort - How to sort a Perl hash by the hash value

Perl hash sorting FAQ: How do I sort a Perl hash by the hash value?

Before getting into this article, you if just need to sort a Perl hash by the hash key, this is a pretty well-known recipe. It's covered in another Q&A article titled "How to sort a hash by the hash key".

Perl environment variables - How to access Perl environment variables

Here's a quick example program that demonstrates how to access environment variables from within your Perl programs:

# environment variables are held in the %ENV hash
foreach $key (sort keys %ENV)
{
  print "$key is $ENV{$key}\n";
}

Using this simple Perl foreach loop, here's a subset of the output this script prints on my MacBook Pro:

An apology, and a good laugh

I just wanted to offer a quick apology to everyone that has sent me emails lately. Yes, I have received your messages, and I will get to them as soon as possible. I'm just a bit swamped right now, so please bear with me, and I'll get to them all as soon as possible.

In the meantime here's a fun exchange from the MySQL support pages:

1) From Person A: It's a bug that I can't write sql/ddl like this:

start_date date not null default now(),

2) Reply from a support person:

Perl true and false - What is true and false in Perl?

Perl true - false FAQ: What is true in Perl? What is false in Perl?

The Perl programming language is a little unusual in not having true and false boolean operators. Because of this -- and my advancing age -- I can never seem to remember what equates to true and false in Perl, so I decided to create this page.

Perl true false summary

In short, the following elements evalue to false in Perl:

Syndicate content