Hello,
To do an insert with Class::DBI, you can simply do:
my $object = Object::DB->insert({ a => 1, b => 2, c => 3, ...});
But there is no such thing for update. The best I could come up with is selecting the record first then updating it:
my $object = Object::DB->retrieve($id);
my $object->set( a => 1, b => 2, c => 3, ...};
$objec...
I've been looking at the options for getting our database schemas under version control. It seems that Ruby folks have got Rails Migrations, and .NET folks have got a few options (for instance this, this, and this). What about Perl?
I've seen this thread on PerlMonks which doesn't have much, although it mentions DBIX::Migration::Direc...
I want to get the size of a file on disk in megabytes. Using the -s operator gives me the size in bytes, but I'm going to assume that then diving this by a magic number is a bad idea:
my $size_in_mb = (-s $fh) / (1024 * 1024);
Should I just use a read-only variable to define 1024 or is there a programmatic way to obtain the size of a...
I need to set the an environment variable from within Perl. Ideally, I need to query a variable and then change it if it is not what is required. Specifically it is the PATH variable I want to change.
Can someone tell me how to get and set these variables?
...
What is the Perl equivalent of PHP's $_FILES? I've got some software that sends log files to a web server and I need to retrieve them using Perl instead of PHP. I'm using CGI.pm.
Here's the code in PHP:
<?
foreach ($_FILES as $key=>$value)
{
$uploaded_file = $_FILES[$key]['tmp_name'];
}
?>
...
I have this running:
if (open(PS_ELF, "/bin/ps -eLf|")) {
while (<PS_ELF>) {
if ($_ =~ m/some regex/) {
# do some stuff
}
}
}
If called locally, the loop runs just fine, once for every output line of ps -eLf
Now if the same script is called from Nagios via NRPE, PS_ELF does only contain one line (the first line outp...
In ActivePerl on Windows, how do I open a browser to some URL?
In Python, there is webbrowser.open(url), but I can't seem to find the Perl equivalent.
...
Is there a standard way to bind arrays (of scalars) in a SQL query? I want to bind into an IN clause, like so:
SELECT * FROM junk WHERE junk.id IN (?);
I happen to be using Perl::DBI which coerces parameters to scalars, so I end up with useless queries like:
SELECT * FROM junk WHERE junk.id IN ('ARRAY(0xdeadbeef)');
Clarification: ...
When using gtar to add extra files to an existing archive, the loop terminates prematurely or hangs. It also terminates after creating the initial tar.gz file.
However, if I remove the gtar calls from the loop and put print statements in their place instead, the loop executes as expected. Does anyone know why this is?
Below is the code ...
I want to archive a directory (I don't know whether I can call "I want to tar a directory"). I want to preserve the access permissions at the other end when I un-tar it. I should I tackle this problem in perl.
Thanks for the response but why I'm asking for doing it Perl is I want it independent of the platforms. I want to transfer one ...
Hello,
I've moved a WebBBS board from one server to another. Ever since the board doesn't work.
I'm getting an Apache error whenever I try to access the board. Don't even know where to start the debugging, I'm not a Perl person. The file paths remained the same and there isn't any DB involved.
http://gammonline.com/members/board/
Any ...
In Perl, I need to read the environment of other processes.
The script is running with root
privileges.
The script will be
running in both Linux and Solaris.
I would like a solution that's mostly platform agnostic, at least between Linux and Solaris. In Linux, examining the /env/<proc_id>/environ can get me the answer.
I would like ...
Hi,
I'm trying to handle the possibility that that no arguments and no piped data is passed to a Perl script. I'm assuming that if there are no arguments then input is being piped via STDIN. However if the user provides no arguments and does not pipe anything to the script, it will try to get keyboard input. My objective is to provide a...
I want to read UTF-8 input in Perl, no matter if it comes from the standard input or from a file, using the diamond operator: while(<>){...}.
So my script should be callable in these two ways, as usual, giving the same output:
./script.pl utf8.txt
cat utf8.txt | ./script.pl
But the outputs differ! Only the second call (using cat) see...
Is there a way to check if a file is already open in Perl?
I want to have a read file access, so don't require flock.
open(FH, "<$fileName") or die "$!\n" if (<FILE_IS_NOT_ALREADY_OPEN>);
# or something like
close(FH) if (<FILE_IS_OPEN>);
...
Anyone know if R has quote-like operators like Perl's qw() for generating character vectors?
...
I have an existing Perl script that uses the FTP object to send a couple of files to an AIX box. I just discovered that our Linux box does not support FTP. It does support SFTP. What steps should I go through to convert my script to use SFTP?
...
Can anybody tell me how to identify the middle part interestedInThis and backreference the prefix: fontsize=12 and postfix: fontstyle=bold as ${1} and ${2}?
I'm dealing with this string:
<fontsize=12 interestedInThis fontstyle=bold>
Addendum: Sorry, I was not precise enough, here are the specifics:
prefix and postfix could be abs...
How is the following code implemented in Perl?
sub add_item : Local {
my ( $self, $c ) = @_;
my $item_id = $c->req->param("item");
push @{ $c->session->{items} }, $item_id;
}
I am interested in the add_item : Local part, cause I don't think those are Perl keywords.
...
I really like being able to use =~ and !~ in Perl to evaluate a string against a regular expression. I'd like to port this functionality over to C#, but it appears that, while you can overload operators, you can't create new ones.
I'm considering extending the string type to provide a Match() method that will allow me to pass a regular ...