Learn Perl

 

Want to learn Perl? Good tutorials can be hard to find, and many of the top tutorials that Google directs people towards were written over 10 years ago and do not teach best practices. In fact, some of the practices that they encourage are downright bad practices. If you’re just starting out with Perl and you want to learn modern Perl programming techniques and practices start with a tutorial that was written recently using a modern version of Perl.

I recommend the following guides:

Once you’ve digested the basics, move on to these more advanced topics:

  • Perl for Facebook – Write a Perl program that works with Facebook data, pulling data from and updating information on Facebook.
  • Net::Twitter – You can also write Perl apps that work with Twitter using Twitter API calls in Perl.
  • Moose – Moose is a complete object system for Perl. You can create objects from scratch using Perl, or you can use any one of dozens of modules that create objects for you. Moose is an easy to use and comprehensive object system, well worth the time to learn.
  • DBIx::Class – Object-relational mapping simplified. Store your objects in a database.
  • Dancer – A micro web application framework for Perl. Fast, lightweight, and powerful.
  • Catalyst – Web framework for Perl similar to Ruby on Rails.
  • PSGI/Plack– From the website: “PSGI is an interface between Perl web applications and web servers, and Plack is a Perl module and toolkit that contains PSGI middleware, helpers and adapters to web servers.” If you’re writing large, scalable, service-oriented web applications in Perl, check out PSGI/Plack.

Work-around for a locked-up Gnome 3 screen saver in Ubuntu 11.10

Gnome 3 has a screen saver (or more accurately a screen blanker — there are no pretty pictures) which is turned on by default and which password-protects (locks) your desktop by default when it activates. Unfortunately it’s been known to be buggy since it was released as part of Gnome 2, often refusing to unlock your screen and forcing you to reboot your system.

Users of the Gnome 3 desktop shell are reporting that for some video card and monitor combinations the Gnome 3 screen saver, after getting a key press / mouse movement that should prompt you for your password to unlock the screen:

  • Won’t unlock the screen at all.
  • Will display a mouse pointer but no password prompt.
  • Will display your original screen and all open documents (without prompting for a password) but will not allow you to click on anything, basically appearing as a locked-up desktop.

My setup reliably produces situation #3.

To unlock a locked-up desktop:

  • Ctrl-Alt-F1 will give you a text-based terminal login.
  • Log in with your user name and password.
  • Type: “killall gnome-screensaver”
  • Ctrl-Alt-F7 to get back to the (now unlocked) Gnome 3 desktop.

To replace the Gnome 3 screen saver with something less buggy:

  • Activities > Applications > Other > Synaptic Package Manager
  • Quick filter: xscreensaver
  • Right click ‘xscreensaver’ and select ‘Mark for Installation’
  • Click ‘Apply’ to install
  • Activities > Applications > System Tools  > System Settings > Screen
  • Set “Turn off after” to ‘Never’ and “Lock” to ‘OFF’. This disables gnome-screensaver.
  • Activities > Applications > All > Screensaver
  • Follow the prompts to activate xscreensaver

If you try to uninstall gnome-screensaver Synaptic Package Manager will also want to uninstall gnome and gnome-core, which is a bad idea if you want to run Gnome. Gnome will always start gnome-screensaver even if you have it disabled, and xscreensaver won’t run if gnome-screensaver is running. So you basically need to kill gnome-screensaver after Gnome has started and then start xscreensaver. You can do this by adding a startup program:

  • Activities > Applications > Other > Startup Programs > Add
  • Name: “Screen Saver”
  • Command: “sleep 30; killall gnome-screensaver; sleep 5; xscreensaver”
  • Comment: “Kill gnome-screensaver, start xscreensaver”
  • Click “Add”

Hope you find this useful.

Adding a task bar to Gnome 3 on Ubuntu 11.10

To install Gnome 3 on Ubuntu 11.10 start up a terminal and type:

sudo apt-get install gnome-shell

To use Gnome 3 instead of Unity: when you log in, click the “gear” above your password. Select “Gnome”, log in.

After you get tired of “click Activities, find the window you want, click the window” every time you want to switch from one window to another, and you decide you really need a taskbar again to maintain your sanity, start up a terminal and type:

sudo apt-get install tint2
tint2 &

You now have a taskbar again. To get it to appear every time you start Gnome 3 go to Activities > Applications > Other > Startup Applications, then click “Add”, Name: “tint2 task bar”, Command: “tint2”, click “Save”.

Done.

Hope you find this useful.

How to turn off smart quotes in Libre Office Writer

To turn off smart quotes in Libre Office Writer, so that the double quote character is shown in the document as ” — exactly as you typed it — and doesn’t get converted into something curly:

  • Go to Tools > Autocorrect Options
  • Select the Localized Options tab
  • Click the button under Start Quote. If you’re using the Basic Latin character set, scroll all the way to the top of the character set display and click the ” box (third box from the top left row, next to the !). If you are using some other character set try searching near the top of the set for the ” character.
  • Click OK
  • Click the button under End Quote. Scroll all the way to the top of the character set display and click the ” box (third box from the top left row, next to the !)
  • Click OK
  • Click OK

Smart quotes are now off for the document that you’re working on. They will also be off for any new documents that you create, including spreadsheets and files created by other Libre Office applications.

To get rid of smart quotes already in a document:

  • Highlight any start smart quote and copy it (Ctrl-C or File > Copy)
  • Select Edit > Find & Replace
  • Paste the smart quote into the Search for box
  • Type ” in the Replace with box
  • Click the Replace All button
  • Click Close
  • Repeat these steps using a copy of the end smart quote

Recovering from a lost connection when upgrading Ubuntu via ssh

I wanted to upgrade my desktop machine at work to the latest version of Ubuntu, but since it takes several hours to upgrade an Ubuntu host, and I have work to do during the day, I figured I could log into my workstation from home in using ssh and start the upgrade remotely.

So I logged into my workstation from home and ran:

> sudo apt-get install update-manager-core
> sudo do-release-upgrade

The upgrade script warned me that I was using ssh and asked if I was sure I wanted to continue. I said “Y”, and a little while later the upgrade manager was busy downloading upgrade packages.

I planned to check it a couple of times that night, answer any package upgrade questions that popped up, and then in the morning when I got to work the upgrade would be complete.

Of course what actually happened was that I got side-tracked onto some other problem that night, forgot about the upgrade in progress, and when I got to work the next day my workstation was in a state of limbo, with the upgrade halfway complete, waiting for me to answer some question on the screen — at my house.

Luckily the Ubuntu developers who created the ssh upgrade process run that upgrade inside of a screen session. As the screen pages states, “Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).”

So at work all I had to do was get the list of current screen sessions:

> sudo screen -list
There are screens on:
        9129.ubuntu-release-upgrade-screen-window       (05/17/2011 08:50:08 PM)        (Attached)
2 Sockets in /var/run/screen/S-root.

Invoke screen using the “-d -r sessionowner/[pid.tty.host]” flags:

> sudo screen -d -r root/9129.ubuntu-release-upgrade-screen-window

… and I could pull up the screen at work that had been displaying at my home. Once I answered the remaining questions about whether to keep my custom configuration files or use the new, packaged configuration files my workstation rebooted and the latest version of Ubuntu booted right up.