Suchergebnisse mit Tag „perl“

TOP

Hash to string race

How to convert a hash to a string? Perl is TIMTOWTDY but which way is the fastest? I need a checksum (hash, digest) for the hash, so the string must be the same for the same hash every time. Hash keys are not sorted, even a simple join('', keys(%hash)) may be different for each call (if the hash has at least two keys).
Weiterlesen
TOP

Perl bits: Passing @_ to a subroutine

Perl subroutines may be called with or without leading & and with or without () at the end. Either one is strongly recommended - the command might end up as something else than a function call if both are missing.
Weiterlesen
TOP

DESTROY or __DIE__ - choose one

Some people always complain, even about the language they've been working with for years while they has other options. One of them recently complained that Perl cleans up objects in unpredictable order during global destruction (after exit; and all END blocks). Here is what happend, how we tracked it down and solved it.
Weiterlesen
TOP

Compressing test for short strings

Data is getting bigger and bigger as technology advances. We didn't even think about using something inefficent like XML when I started writing sourcecode on a Datapoint 6600 or even in MS-DOS world, but today? A meg more or less doesn't matter today. But sometimes space is still premium and so it is for my current project. I'm working with short strings (text plus some extra chars, about 6 bit  per char) and they should be compressed.
Weiterlesen
TOP

Using Memcache as database locking helper

Race conditions are nice: Two (or more) tasks are fighting for the same thing at the same time. Row locking on the database may help to avoid such races but only if the database supports them.
Weiterlesen
TOP

Parse both GET and POST data in the same request using CGI::Simple

The Perl CGI module is commonly used, but it's heavy. CGI::Simple is more lightweight but lacks some features. Here is a feature not supported by CGI but by CGI::Simple.
Weiterlesen
TOP

Web-Multitasking: Whos gonna work for the working man?

Web scripts usually do one thing at a time which is quite good as long as there is not too much to do. But serving thousands of request per minute with thousands of source code lines per request starts getting challenging. Bon Jovi asked for help for web scripts some time ago by writing his song "(Whos gonna) work for the working man". Well, there are little chances that he had something else in mind, but who cares.
Weiterlesen
TOP

Don't use exec and database connections

Typical Perl scripts (and others running as CGI-scripts) run and exit once they're done, but this isn't very efficient with medium or high request counts. Persistent solutions like FCGI and ModPerl avoid the additional interpreter loading and compiling phases, but start being challenging if any source file is changed.
Weiterlesen
TOP

Creating a crossword puzzle

Actually not a 100% real one, but something near by, like this one (near the end of the text).

Crossword puzzle creators must know and remember many words, but everybody could create one with a little help by a computer.

Weiterlesen
TOP

Undicht, Shopping und Fehler

Zoe ist seit einiger Zeit trocken und lange Zeit auch Nachts (mit seltenen Unfällen). Wenn sie Nachts mal muss, geht sie aufs Töpfchen und ruft so lange nach Mama bis wir wach sind. Seit einigen Tagen klappt das leider nicht mehr.
Weiterlesen
TOP

SQL injection 2.0: Regular Expression injection

SQL injections are well-known and could easily be used against against most PHP scripts, but there is a much easier injection leak in many Perl scripts: Regular Expression injection.
Weiterlesen
TOP

Counting letters in Perl

A blog comment resulting in a new post? Yes, a guy from southern Germany made me do this by trying to use the whole alphabet in his comment.
Weiterlesen
TOP

Perl style and C style

Perl is TIMTOWTDI but not every style is good style. It allows you to write down source which isn't executed the way you think.
Weiterlesen
TOP

Capture STDOUT and STDERR of external command

IO::CaptureOutput is a great module but provides limited control. Here is a quick hack to replace the capture_exec function while getting more control about what is being done.
Weiterlesen
TOP

SQL-Problem: SELECT id; if ($id) { UPDATE } else { INSERT }

SQL hat viele Nachteile, aber einer der größten ist die Unsinnige Aufteilung zwischen der Erstellung und Veränderung eines Datensatzes. mySQL macht es dem genervten Programmiere mit MyISAM auch nicht leichter, denn Row-Locks oder Transaktionen werden nicht unterstützt. Aber ich schweife ab...
Weiterlesen
TOP

Using a mySQL Temporary Table

Huston, we have a problem. Our company's headquarter isn't in Huston, but anyway... we got inconsistent data between some mySQL tables. There is a cron job fixing such problems but usually only very few records need assistance, much less than 10 a week. Updating the script to find the newly discovery differences was less than a hour, but running it turned out impossible.
Weiterlesen
TOP

Think looping

Software Developers need to think straight forward: Line 2 is executed after line 1, never before. But straight forward code isn't always good.
Weiterlesen
TOP

Perl-Jobs für Perl-Entwickler

Als Perl-Entwickler gehört man einer Minderheit an: Die Uni's lehren mehr oder weniger gut Java und die Kids steigen mit PHP ein. Es gibt sie, die Perl Jobs, aber sie sind gut versteckt - genauso wie die Entwickler, die sie suchen.
Weiterlesen
TOP

Can't call method on unblessed reference - but why?

OOP in Perl is pretty simple: Every reference may become an object. But trying to use a reference instead of an object for an OOP call results in Can't call method on unblessed reference.

Weiterlesen
TOP

Speed up your script using profiling

What is profiling?

Each script should care of resources (time, memory or CPU time) being used, but some don't. Profiling is a detailed analysis of your script's behavior while it's running.

A profiler notices every processed line, it's callers and called functions and time required to process it.

Weiterlesen