perl

what is the difference between my and our in Perl?

I know what my is in Perl. It defines a variable that exists only in the scope of the block in which it is defined. What does our do? How does it differ from my? ...

How can I check if a binary dependency is available in Perl?

Having volunteered to maintain a stagnant CPAN package (GnuPG) I'd like improve the install files such that they exit gracefully if the gpg binary (which GnuPG is a wrapper for) cannot be found. After a bit of seeking inspiration from other packages, I've come up with adding this to Makefile.PL: my @paths = grep { -x "$_/gpg" } split /:...

How can I convert a log4j timestamp to milliseconds in Perl?

The log4j logs I have contain timestamps in the following format: 2009-05-10 00:48:41,905 I need to convert it in perl to millseconds since epoch, which in this case would be 124189673005, using the following gawk function. How do I do it in perl? I have little or no experience in perl, so appreciate if someone can post an entire sc...

How can I remove the last seven characters of a hash value in Perl?

I need to cut off the last seven characters of a string (a string that is stored in a hash). What is the easiest way to do that in perl? Many thanks in advance! ...

Python equivalent of perl's dbi/DBD::Proxy access? (Perl DBI/DBD::Proxy for Python)

I have a perl script that interfaces with an existing database (type of database is unknown) through the DBI module, that I would like to access in python 2.6 on winXP. The perl code is: use DBI; my $DSN = "DBI:Proxy:hostname=some.dot.com;port=12345;dsn=DBI:XXXX:ZZZZZ"; my $dbh = DBI->connect($DSN); Can this be translated into a pyth...

Stop Oracle from generating sqlnet.log file

I'm using DBD::Oracle in perl, and whenever a connection fails, the client generates a sqlnet.log file with error details. The thing is, I already have the error trapped by perl, and in my own log file. I really don't need this extra information. So, is there a flag or environment for stopping the creation of sqlnet.log? Thanks ...

sed optimization question (large file modification based on smaller dataset)

Hi all, I do have to deal with very large plain text files (over 10 gigabytes, yeah I know it depends what we should call large), with very long lines. My most recent task involves some line editing based on data from another file. The data file (which should be modified) contains 1500000 lines, each of them are e.g. 800 chars long. ...

Editing Photoshop PSD text layers programmatically

I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying to figure out a way I can, from a bash/perl/python/whatever-else program: load the PSD edit the text in said layer flatten all layers in the image save as a web-friendly format like PNG or JPG I immediately thought of ImageMagick, but I don't t...

[Perl]: Read directory and files, and regex

Hi all, from this string, (champs1 (champs6 donnee_o donnee_f) [(champs2 [] (champs3 _YOJNJeyyyyyyB (champs4 donnee_x)) (debut 144825 25345) (fin 244102 40647)), (champs2 [] (champs3 _FuGNJeyyyyyyB (champs4 donnee_z)) (debut 796443 190570) (fin 145247 42663))] [] [])., i would like to extract the first number after the word "debut", and...

How can I access an intranet web page from Perl?

I am writing a Perl script to access intranet page with authentication. Is there any Perl module to access intranet web page? ...

Converting grouped hex characters into a bitstring in Perl

I have some 256-character strings of hexadecimal characters which represent a sequence of bit flags, and I'm trying to convert them back into a bitstring so I can manipulate them with &, |, vec and the like. The hex strings are written in integer-wide big-endian groups, such that a group of 8 bytes like "76543210" should translate to th...

How can I get a row count in DBI without running two separate calls to process?

I'm running DBI in Perl and can't figure out how, when I run a prepared statement, I can figure out if the returned row count is 0. I realize I can set a counter inside my while loop where I fetch my rows, but I was hoping there was a less ugly way to do it. ...

Please introduce a multi-processing library in Perl or Ruby

In python we can use multiprocessing modules. If there is a similar library in Perl and Ruby, would you teach it? I would appreciate it if you can include a brief sample. ...

launch a process off a mysql row insert

I need to launch a server side process off a mysql row insert. I'd appreciate some feedback/suggestions. So far I can think of three options: 1st (least attractive): My preliminary understanding is that I can write a kind of "custom trigger" in C that could fire off a row insert. In addition to having to renew my C skills this would r...

How can I get exactly n random lines from a file with Perl?

Following up on this question, I need to get exactly n lines at random out of a file (or stdin). This would be similar to head or tail, except I want some from the middle. Now, other than looping over the file with the solutions to the linked question, what's the best way to get exactly n lines in one run? For reference, I tried this:...

How do I make multiple database queries more efficient in Perl?

Hi all, I have a queries that reside in multiple methods each (query) of which can contain multiple paramaters. I am trying to reduce file size and linecount to make it more maintainable. Below is such an occurence: $sql_update = qq { UPDATE database.table SET column = 'UPDATE!' WHERE id = ? ...

How do I replace part of string using regexp?

HI, I have a string that looks like /dir/dir1/filename.txt I want to replace the "filename.txt" with some other name leaving the "/dir/dir1" intact so after the replace the string would look like /dir/dir1/newfilename.txt how would I do that using RegExp in Perl considering that I don't know the value of "filename" Many Thanks...

How I can check for a valid date format in Perl?

Hi, I am getting a date field from the database in one of my variables, at the moment I am using the following code to check if the date is in "yyyy-mm-dd" format if ( $dat =~ /\d{3,}-\d\d-\d\d/ ) My question, is there a better way to accomplish this. Many Thanks ...

Need Help parsing stream data from php socket server with perl.

I'm working on a project for my company that uses a socket server (php) to gather data from a remote device. How can I make this perl program run directly on the stream instead of first having the server write to a tmp file then running this script on that file then writing out a csv file for insertion into a database? I thought about ...

Perl+Postgresql: a function does not return a value if RAISE NOTICE is present

Hi, I noticed that when I call a PL/PgSQL or PL/Perl function from a Perl script using DBI, it does not return a value if a RAISE NOTICE or elog(NOTICE) is used in the function. To illustrate: A simple table: CREATE TABLE "public"."table1" ( "fld" INTEGER ) WITHOUT OIDS; A simple function: CREATE OR REPLACE FUNCTION "public"."fun...