Perl is one of the things I never quite had the justification to get into. Unfortunately, I've got a very specific (looks like a bug to me) bit of Perl code, and I need to define it's operation provably.
This code is written and in production already, I wish to have it removed.
I believe it's impossible to successfully match, but it'...
In Perl, the array index -1 means the last element:
@F=(1,2,3);
print $F[-1]; # result: 3
You can also use the $# notation instead, here $#F:
@F=(1,2,3);
print $F[$#F]; # result: 3
So why don't -1 and $#F give the same result when I want to specify the last element in a range:
print @F[1..$#F]; # 23
print @F[1..-1]; # <empty>
T...
Given that the roles Fooable and Barable have both been defined, how do I say that class FooBar does Fooable and Barable? I have no problem saying
#!/usr/bin/perl
use MooseX::Declare;
role Fooable {
method foo { print "foo\n" }
}
role Barable {
method bar { print "bar\n" }
}
class Foo with Fooable {}
class Bar with Barable ...
I have a shell script, pretty big one. Now my boss says I must rewrite it in Perl.
Is there any way to write a Perl script and use the existing shell code as is in my Perl script. Something similar to Inline::C.
Is there something like Inline::Shell? I had a look at inline module, but it supports only languages.
...
The content of condition.conf:
condition1=$a>$b
Example Perl code:
$cnd_ConfFile = $ARGV[0];
open(CONDITIONS, '<', $cndConfFile);
$cndCount=0;
while ( <CONDITIONS> ) {
chomp; # no newline
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length;
...
I'm seeing some occasional (one time in five), momentary (5-10 seconds) "freezing" when it dragspossibly as part of the -startcommand callback. It never happens on the first drag.
The callback is simple enough; it just sets the text of the dragging cursor to the value that is being dragged:
sub DragStart {
my( $token ) = @_;
my $w...
I posted "How to undersand the POE-Tk use of destroy?" in an attempt to reduce the bug in my production code to a test case. But it seems that the solution to the test case is not working in the full program.
The program is 800+ lines long so I am hesitant to post it in full. I realize that the snippets I provide here may be too shor...
What is the best way to log an error when testing in Perl? I prefer a one-liner solution such as
return 0 if $var!=3 and $logger->error("Var is not 3"))
Can something like the example shown be implemented?
...
Is there an OS-agnostic Perl module that puts a hard limit on the amount of virtual memory a process can use; e.g. so that the process will be killed if it starts eating up too much memory?
I see Apache::SizeLimit, which is obviously Apache specific; and Process::MaxSize, which requires you to call a check function (and also has a hacky...
I am having difficulty with the BUILD method in MooseX::Declare. If I say:
#!/usr/bin/perl
use MooseX::Declare;
class Foo {
has foo => (is => "rw", isa => "Str", default => "foo");
method BUILD {
print "I was called\n";
}
}
Foo->new;
I get the following less than helpful error message:
Reference found where even...
Input:
F1 F2 F3 F4 F5 F6
4 ABCDEF1234 1111111111 20090101 00:00:00 XYZ 123
Output:
4 ABCDEF1234 1111111111 20090101-00:00:00 XYZ 123
F represents fields. F4 and F5 are date fields which needs to be concatenated with a hyphen. Is there a quick Perl script that does this?
...
Hello friends,
I have encountered a difficulty in understanding the subroutine syntax.
using the following code:
sub build_dyne_file{
open(DYNAP, "+>$veri_dir/$dyna_para") or die $!;
for (keys %hash){
print DYNAP "#define ",$_," ",$hash{$_}->[$i],"\n";
}
close(DYNAP);
}
for (my $i = 0 ; $i <$TEST_QUOTA ; $i++){
b...
I have a problem in Perl I don't understand. I stripped it down to this very short code.
Why does Perl's map function return an empty array? Shouldn't it return an array with 9 undefs?
sub mySub{
return;
}
my @arr = (1 .. 9);
my @arr2 = map( mySub($_), @arr );
print @arr . ' ' . @arr2, "\n";
It prints "9 0".
It is probably som...
I was asked to modify some existing code to add some additional functionality. I have searched on Google and cannot seem to find the answer. I have something to this effect...
%first_hash = gen_first_hash();
%second_hash = gen_second_hash();
do_stuff_with_hashes(%first_hash, %second_hash);
sub do_stuff_with_hashes
{
my %first_hash ...
What is the difference between doing use My::Module and require My::Module?
...
I have some simple Perl code:
#!/usr/bin/perl
use strict; # not in the OP, recommended
use warnings; # not in the OP, recommended
my $val = 1;
for ( 1 .. 100 ) {
$val = ($val * $val + 1) % 8051;
print ($val / 8050) . " \n";
}
But when I run it, the output is:
bash-3.2$ perl ./rand.pl
0.0002484472049689440.0006211180124223...
I keep printing my hash as # of buckets / # allocated.
How do I print the contents of my hash? Without using a while loop would be most preferable (ex: a one-line would be best)
...
Seeing some strange behavior, whereby connecting to Oracle database, and then calling external function, the value of $? is always -1.
Problem machine is running standard AIX5.3, with DBD::Oracle 1.20 and DBI 1.602.
#!/usr/bin/perl -w
use DBI;
CORE::system "pwd";
print "Before connect: $?\n";
DBI->connect('dbi:Oracle:', 'pwd', 'pwd');
...
Are there any examples I can look at that use HTML::FormFu with AJAX form validation and submission? I would really not like to write my validation routines three times (once in JS, once in FormFu constraints, and once in DBIC models), so I'd really like a way that's integrated with HTML::FormFu::Model::DBIC if possible.
...
How would I start a long-running job from within a Catalyst app? I want a page from which the user can upload a list of URLs, and the application would then go and download these URLs. I need to implement an AJAX progress indicator that would then show the status of this job.
...