perl

How do I get user and group information in Perl on Windows?

Perl has several built-in functions for accessing /etc/passwd on Unix systems (and elsewhere when supported) for user and group information. For instance, my $name = getpwuid($uid); will return the user name given the user ID, or undef if there is no such user. If a Perl script needs to be portable and run on Unices and Windows, how ...

How do you round a floating point number in Perl?

How can I round a decimal number (floating point) to the nearest integer? e.g. 1.2 = 1 1.7 = 2 ...

How can I find repeated letters with a Perl regex?

I am looking for a regex that will find repeating letters. So any letter twice or more, for example: booooooot or abbott I won't know the letter I am looking for ahead of time. This is a question I was asked in interviews and then asked in interviews. Not so many people get it correct. ...

What content encoding does a Perl CGI script use by default?

Hi there, I'm modifying a mature CGI application written in Perl and the question of content encoding has come up. The browser reports that the content is iso-8859-1 encoded and the application is declaring iso-8859-1 as the charset in the HTTP headers but doesn't ever seem to actually do the encoding. None of the various encoding tec...

How can I replicate Perl's unpack functionality in C#?

Hi, I am trying to recreate a Perl script in C# but have a problem creating a checksum value that a target system needs. In Perl this checksum is calculated using the unpack function: while (<PACKAGE>) { $checksum += unpack("%32C*", $_); } $checksum %= 32767; close(PACKAGE); where PACKAGE is the .tar file input stream I need to...

MySQL driver segfaulting under mod_perl - where to look for issue

I have a webapp that segfaults when the database in restarted and it tries to use the old connections. Running it under gdb --args apache -X leads to the following output: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1212868928 (LWP 16098)] 0xb7471c20 in mysql_send_query () from /usr/lib/libmysqlclient.so.1...

How can I match a pipe character followed by whitespace and another pipe?

Hello. I don't usually post to forums, but I am somewhat stuck. I am trying to find all matches in a string that begins with "| |" (quotations not included). I have tried doing: if ($line =~ m/^\\\|\s\\\|/) and that didn't work. I'm not sure if anyone has any tips or pointers, but any help would be appreciated. Thanks! ...

Monitoring Windows directory size

I'm looking for something that will monitor Windows directories for size and file count over time. I'm talking about a handful of servers and a few thousand folders (millions of files). Requirements: Notification on X increase in size over Y time Notification on X increase in file count over Y time Historical graphing (or at least sav...

Forking subprocesses in Perl unit tests stops prove; Test::Harness exiting

Hi, I have been trying to use the Perl utility/module "prove" as a test harness for some unit tests. The unit tests are a little more "system" than "unit" as I need to fork off some background processes as part of the test, Using the following... sub SpinupMonitor{ my $base_dir = shift; my $config = shift; my $pid = fork(); ...

Is there a Perl-compatible regular expression to trim whitespace from both sides of a string?

Is there a way to do this in one line? $x =~ s/^\s+//; $x =~ s/\s+$//; In other words, remove all leading and trailing whitespace from a string. ...

Should I change my utilities.pl to a utilities.pm module?

In our product we have a big utilities file that we require (with do) at the beginning of a lot of our files. Is there a reason not to turn this into a module? For example, instead of doing this: do '../dbi_utilities.pl'; our ($db,$user,$pw,$attr); my $Data = DBI->connect($db,$user,$pw,$attr) or die "Could not connect to database: $DB...

Crash when calling into C++ library from Perl using SWIG (AIX 5.1)

I'm trying to call into a C++ library from Perl on an AIX 5.1 machine. I've created a very simple test project to try to exercise this. My C++ shared library (test.cpp): #include <stdio.h> #include <iostream> void myfunc() { printf("in myfunc()\n"); std::cout << "in myfunc() also" << std::endl; } My SWIG interface file (tes...

How do I 'use' a Perl module in a directory not in @INC?

I have a module in the parent directory of my script and I would like to 'use' it. If I do use '../Foo.pm'; I get syntax errors. I tried to do: push @INC, '..'; use EPMS; and .. apparently doesn't show up in @INC I'm going crazy! What's wrong here? ...

New project: I am having troubles picking a language to use.

I am starting my first independent for profit venture. I am having a hard time deciding what language to use. I want to write my app in Perl, but I don't think it will be simple enough to compile. If I don't write it in Perl I will write it in C++. The application will have many features, including wxwidgets interface, Deal with SDL, ti...

How can I get Perl to give a warning message when a certain package/tag is imported?

I have a package that I just made and I have an "old-mode" that basically makes it work like it worked before: importing everything into the current namespace. One of the nice things about having this as a package is that we no longer have to do that. Anyway, what I would like to do is have it so that whenever anyone does: use Foo qw(...

Why should I use Carp instead of warn in Perl?

People keep giving me examples with carp instead of warn. Why? What makes carp better than warn? ...

Why does IIS crash when I print to stderr in Perl?

This has been driving me crazy. We have IIS (6) and windows 2008 and ActiveState Perl 5.10. For some reason whenever we do a warn or a carp it eventually corrupts the app pool. Of course, that's a pretty big deal since it means that our errors actually cause problems. This happened with the previous version of Perl (5.8) and Windows ...

How do I get a filehandle from the command line?

I have a subroutine that takes a filehandle as an argument. How do I make a filehandle from a file path specified on the command line? I don't want to do any processing of this file myself, I just want to pass it off to this other subroutine, which returns an array of hashes with all the parsed data from the file. Here's what the comm...

How do I replace an asterisk ('*') using a Perl regular expression?

I have the following string: $_='364*84252'; The question is: how to replace * in the string with something else? I've tried s/\*/$i/, but there is an error: Quantifier follows nothing in regex. On the other hand s/'*'/$i/ doesn't cause any errors, but it also doesn't seem to have any effect at all. ...

How can I store multiple values in a Perl hash table?

Up until recently, I've been storing multiple values into different hashes with the same keys as follows: %boss = ( "Allan" => "George", "Bob" => "George", "George" => "lisa" ); %status = ( "Allan" => "Contractor", "Bob" => "Part-time", "George" => "Full-time" ); and then I can reference $boss("Bob") a...