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 can I round a decimal number (floating point) to the nearest integer?
e.g.
1.2 = 1
1.7 = 2
...
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.
...
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...
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...
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...
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!
...
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...
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 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.
...
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...
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...
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?
...
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...
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(...
People keep giving me examples with carp instead of warn. Why? What makes carp better than warn?
...
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 ...
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...
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.
...
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...