data

How to populate sample data when a Play Framework application starts up

If you ever need an example of how to do something when a Play Framework application starts up, check out the Zentasks application in the Play distribution samples directory. You'll find the following code in the Global.scala file in the app subdirectory of the project. It shows how to use the onStart method of the Global object to populate some sample data when the Play Framework app starts up.

Here's the source code for that class:

Scala - calling foreach on a Seq to populate sample data

I just saw the following Scala source code in a Play Framework 2 sample application, and it struck me as a nice example of how to call the foreach method on a Seq to populate some sample data:

Handling spaces in Linux shell script input (and for loops)

Linux shell script FAQ: How can I deal with spaces (blank spaces) in my input data when I'm writing a shell script for loop or while loop?

I was just working on a Linux shell script, and ran into the ages-old problem of handling data that has spaces (space characters) in it. I run into this any time I try to read a data file with blank spaces in it, or when I run into files and directories with spaces in their names. Whenever I try to work this data like this in a shell script for loop, the spaces always ruin what I'm trying to accomplish.

JList "add data" - how to add/edit JList data

I don't need to do add data to the JList in my current Java/Swing application, but out of curiosity I did some research to see what you would have to do if you wanted to add data to a JList, and here are the results.

It turns out that if you need to add or edit JList data, you're probably better off creating your data as an instance of a DefaultListModel (as opposed to on object array or Vector).

Java URL and URLConnection example - how to read content from a URL

Question: Using Java, how can I open a URL from my program, and then read the content of that URL?

Perl pipe - Reading from a pipeline with Perl

Perl pipeline FAQ: How can I read output from a shell command pipeline (pipe) in a Perl script?

One of the great things about Perl is that it's very easy to run operating system commands, and read the output of those commands. Perl makes this process very easy and natural - it's just like reading data from a file. In this article we'll demonstrate the process of running external commands from within Perl, and then reading the output of those commands.

Perl files example - How to open and read data files with Perl

Perl files FAQ: How do I open and read files in Perl?

This article demonstrates how to open and read files in Perl. As you'll see, the creators of Perl thought this was a fundamental activity, and they've made it as easy as possible. (That's one of the things I really like about Perl - many of the routine, daily programming tasks have been made very easy with this language.) If you've used other "structured" languages, such as C or FORTRAN, you'll appreciate how easy it is to open a file and create a loop to read data from the file.

How to sort an array of Ruby objects by multiple class fields

In a previous tutorial I wrote about how to sort an array of Ruby objects by one field in the object. In today's tutorial I'd like to demonstrate how to sort an array of Ruby objects by multiple attributes (or fields) of the class contained by the array.

Ruby CSV - An example of how to split CSV row data into fields

Ruby CSV FAQ: Can you share some sample Ruby code to demonstrate how to read a CSV file in Ruby?

I just created a Ruby script that would open, read, and parse a simple CSV file. If you're interested in the full class definition, the full Ruby source code is available here.

But if you're just interested in seeing how to parse the records and fields of a CSV file, keep reading here.

How to embed data in your Perl program

Here's a sample Perl program that demonstrates how you can include (embed) data inside of your Perl program, right in there next to the source code.

This simple program takes the data after the special __END__ tag, and makes it available to your Perl source code.

#!/usr/bin/perl

while (<main::DATA>)
{
  print $_;
}

__END__
George Washington
Abraham Lincoln
John F. Kennedy

As you can see, you loop through the data with this line of code:

Syndicate content