perl

How do I find a link's content type in Perl?

Suppose you're given an URL, http://site.com . How do you find out what it's content type is without downloading it? Can Perl's WWW::Mechanize or LWP issue a HEAD request? ...

How can I call methods on a tied variable?

I've just started to learn about tie. I have a class named Link which I would like to do the following thing: if fetched, return the link's address if stored, store the new address be able to call methods on it So far, my code is : package Link; sub FETCH { my $this = shift; return $this->{"site"}; } sub STORE { my ($...

How do I daemonize an arbitrary script in unix?

I'd like a daemonizer that can turn an arbitrary, generic script or command into a daemon. There are two common cases I'd like to deal with: I have a script that should run forever. If it ever dies (or on reboot), restart it. Don't let there ever be two copies running at once (detect if a copy is already running and don't launch it ...

How can I import constants into multiple modules in Perl?

I'm writing an app in Perl with several modules. I want to write some global constants that will be visible from everywhere, like this: #Constants.pm $h0 = 0; $scale = 20; And then use them without qualifying with main:: or Constants:: in several modules. However, if I write use Constants; in more than one module, they only get import...

How can I rotate and compress Log4perl log files?

From what I can tell neither Log4Perl or any of its related modules in CPAN supports rotate & compression of log files. Rotation can be accomplished by using: Log::Log4perl::Appender::File Log::Dispatch::FileRotate. But neither modules supports rotation and compression. (Log::Dispatch::FileRotate has it in its todo list, but it's n...

Double interpolation of regular expressions in Perl

I have a Perl program that stores regular expressions in configuration files. They are in the form: regex = ^/d+$ Elsewhere, the regex gets parsed from the file and stored in a variable - $regex. I then use the variable when checking the regex, e.g. $lValid = ($valuetocheck =~ /$regex/); I want to be able to include perl variables...

How can I tell if STDIN is connected to a terminal in Perl?

How can I tell if STDIN is connected to a terminal in Perl? ...

How do I write a regex that performs multiple substitutions on each line, EXCEPT when the line starts with a certain string?

I'm trying to write a regular expression that surrounds "http" URLs with angle brackets, except for lines beginning with two slashes. The best I've come up with is: s#^(?!//)(.*?)(http://[^\s]+)#$1&lt;$2>#gm; This works great for these two: Input: http://a.com Output: <http://a.com> Input: //http://a.com Output: //http://a.com ...

Do Python regexes support something like Perl's \G?

I have a Perl regular expression (shown here, though understanding the whole thing isn't hopefully necessary to answering this question) that contains the \G metacharacter. I'd like to translate it into Python, but Python doesn't appear to support \G. What can I do? ...

Can Perl's Getopt::Long parse arguments I don't define ahead of time?

I know how to use Perl's Getopt::Long, but I'm not sure how I can configure it to accept any "--key=value" pair that hasn't been explicitly defined and stick it in a hash. In other words, I don't know ahead of time what options the user may want, so there's no way for me to define all of them, yet I want to be able to parse them all. Su...

How can I manipulate a Sybase datetime string in Perl?

Hey all I have a datetime field in a Sybase table, and need to use it in Perl for doing some calculations (differences to make sure I'm picking up the records that are at least 'n' mins apart). Now, if I simply do a select <datetime field>, Sybase returns a human readable field which is no use to me. I was looking at some way to convert...

How can I trim log files using Perl?

I have recently come up with a situation where I need to trim some rather large log files once they grow beyond a certain size. Everything but the last 1000 lines in each file is disposed of, the job is run every half hour by cron. My solution was to simply run through the list of files, check size and trim if necessary. for $file (@fil...

How can I force a Perl script to use ActiveState's wperl?

I have a Perl script that requires two command line arguments that takes a while to run. I am using ActiveState Perl to run it. I can call it with wperl script.pl arg1 arg2 from a command prompt and it runs in the background fine. If I change the .pl association from perl.exe to wperl.exe and call it with script.pl arg1 arg2 the argument...

Perl build, unit testing, code coverage: A complete working example

Most Stackoverflow answers that I have found in regards to the Perl build process and unit testing and code coverage simply point me to CPAN for the documentation there. There's absolutely nothing wrong with pointing to CPAN modules because that's where the full documentation is supposed to reside. I've had trouble finding complete wor...

How can I get forking pipes to work in Perl on Windows?

I'm trying to port a Perl script over from Unix to Windows but am having a near impossible time getting it to work due to the unsupported forking pipes in the open function. Here's the code: sub p4_get_file_content { my $filespec = shift; return 'Content placeholder!' if ($options{'dry-run'}); debug("p4_get_file_content: $f...

How can I find the free space available on mounted volumes using Perl?

I'm trying to untar a file. Before untarring I would like to know free space available on the mounted volume. The plan is if there is not enough space I will not untar it! So how can I find the free space available on a mounted volume using Perl? By the way, I'm using Perl for tar and untar. Everybody is saying about df and dh but these...

Is there a Perl plugin for IntelliJ?

What do people do when they want to write Perl in IntelliJ? I haven't seen any plugins that add language support. Does anyone have any experience writing language plugins for IntelliJ? Is it hard? Could I take an existing plugin and change it to make it support Perl? Any suggestions? ...

How do you debug a mod_perl2 module without restarting?

Environment: Apache/2.2.11 (Win32) mod_apreq2-20051231/2.6.2-dev mod_perl/2.0.4-dev Perl/v5.10.0 Situation very similar to what's described in this discussion list post, except for being on win32. I have this in httpd.conf: PerlModule Apache2::Reload PerlInitHandler Apache2::Reload PerlSetVar ReloadAll Off PerlSetVar ReloadModules "My...

How can I throttle a download in a Perl program?

Is there any Perl module available for download throttling? I would like to download a certain file but limit the download rate to a specific number of KB/sec . ...

How should I do integer division in Perl?

What is a good way to always do integer division in Perl? For example, I want: real / int = int int / real = int int / int = int ...