perl

How can I tell cpan to change the target for the module installation?

Hello! When I installed perl from the source the first nice surprise was that without doing something all module installed from now on were available to the new perl. Since I didn't find one module on cpan that comes with my OS I have to use for some scripts the onboard-perl. For one of these scripts I would like to install Text::Format ...

How can I print text immediately without waiting for a newline in Perl?

I have a computationally expensive task in perl, and would like to inform the user that computation is ongoing by printing out a period after each portion of the computation is completed. Unfortunately, until I print a "\n", none of my periods are printed. How can I address this? ...

How do you replace a method of a Moose object at runtime?

Is it possible to replace a method of a Moose object at runtime ? By looking at the source code of Class::MOP::Method (which Moose::Meta::Method inherits from) I concluded that by doing $method->{body} = sub{ my stuff } I would be able to replace at runtime a method of an object. I can get the method using $object->meta->find_meth...

Best way to convert log files (*.txt) to web-friendly files (*.html, *.jsp, etc)?

I have a bunch of log files which are pure text. Here is an example of one... Overall Failures Log SW Failures - 03.09.2010 - /logs/swfailures.txt - 23 errors - 24 warnings HW Failures - 03.09.2010 - /logs/hwfailures.txt - 42 errors - 25 warnings SW Failures - 03.10.2010 - /logs/swfailures.txt - 32 errors - 27 warnings HW Failures - 03....

Getting the directory of an uploaded file with perl

Hello, I have a Perl script which will allow for a file to be uploaded to my server. I'm not completely done with it yet, but I would like to know, if there is any way for me to get the full path of a file i uploaded. Shouldn't this be possible by checking the PATH_INFO environment variable, but when i try to check the path info, nothing...

How can I match at the beginning of any line, including the first, with a Perl regex?

According the the Perl documentation on regexes: By default, the "^" character is guaranteed to match only the beginning of the string ... Embedded newlines will not be matched by "^" ... You may, however, wish to treat a string as a multi-line buffer, such that the "^" will match after any newline within the string ... you can do th...

Why does Perl complain "Use of implicit split to @_ is deprecated"?

This code triggers the complaint below: #!/usr/bin/perl use strict; use warnings; my $s = "aaa bbb"; my $num_of_item = split(/\s+/, $s) ; print $num_of_item; When I run the code, Perl complains that "Use of implicit split to @_ is deprecated" . I really have no "context" for the problem, so I expect you help to explain what's wrong...

How can I initialize a 2d array in Perl?

How do I initialize a 2d array in perl? I am trying the following code: 0 use strict; 10 my @frame_events = (((1) x 10), ((1) x 10)); 20 print "$frame_events[1][1]\n"; but it gives the following error: Can't use string ("1") as an ARRAY ref while "strict refs" in use at ./dyn_pf.pl line 20. This syntax only seems to initialize a ...

What do parentheses in a Perl regex do?

I have been trying several regular expressions in the substitution operator: $str =~ s/^0+(.)/$1/; converts 0000 to 0 and 0001 to 1 $str =~ s/^0+./$1/; converts 0000 to empty string, 000100 to 00, 0001100 to 100. what difference is the parentheses making? ...

How can I use Perl to concatenate array elements between two indexes?

I have an array of strings: @array I want to concatenate all strings beginning with array index $i to $j. How can I do this? ...

How can I properly use environment variables encoded as Windows-1251 in Perl?

I have an environment variable set in Windows as TEST=abc£ which uses Windows-1252 code page. Now, when I run a Perl program test.pl this environment value comes properly. When I call another Perl code - test2.pl from test1.pl either by system(..) or Win32::Process, the environment comes garbled. Can someone provide information why t...

Get Template::Plugin::Date to accept MySQL dates as well as datetimes

I'm using the date plugin for Template::Toolkit (Template::Plugin::Date), it works well with datetimes (yyyy-mm-dd hh:mm:ss) pulled straight out of MySQL, but it will not work with dates (yyyy-mm-dd). What's the simplest way to get date.format to accept dates (without modifying the sql query)? Thanks. ...

Do you use an exception class in your Perl programs? Why or why not?

I've got a bunch of questions about how people use exceptions in Perl. I've included some background notes on exceptions, skip this if you want, but please take a moment to read the questions and respond to them. Thanks. Background on Perl Exceptions Perl has a very basic built-in exception system that provides a spring-board for mor...

How to remove lowercase sentence fragments from text?

Hello: I'm tyring to remove lowercase sentence fragments from standard text files using regular expresions or a simple Perl oneliner. These are commonly referred to as speech or attribution tags, for example - he said, she said, etc. This example shows before and after using manual deletion: Original: "Ah, that's perfectly tr...

Can I pass a regex to isa() with Moose-based objects?

Can I use isa in Moose with a regex as a parameter ? If not possible can I achieve the same thing with someothing other than ->isa ? ok, having the following types Animal::Giraffe , Animal::Carnivore::Crocodile , I want to do ->isa(/^Animal::/), can I do that ? if I can't, what can I use to reach the desired effect ? ...

How do I make a shortcut for a Perl program under Windows using a DOS batch file?

I'm trying to "hide" some of my perl program from the end user to make things easier on them. I'm doing what I can to keep them out of the command prompt. The program itself has a GUI designed in Perl/Tk, so they don't have to worry about the command prompt. Could I write out a quick batch file that goes along the lines of: START perl ...

Why does my ActivePerl program on Windows stop accepting socket connections?

I'm using fork() on Perl on Windows (ActivePerl) for a basic socket server, but apparently there are problems (it won't accept connections after a few times), is there any workaround? Here is the portion of the relevant code: while($client = $bind->accept()) { $client->autoflush(); if(fork()){ $client->close(); } else { $bi...

What is the fastest way to pull a few element values out of XML files in Perl?

I have a bunch of XML files that are about 1-2 megabytes in size. Actually, more than a bunch, there are millions. They're all well-formed and many are even validated against their schema (confirmed with libxml2). All were created by the same app, so they're in a consistent format (though this could theoretically change in the future)....

How can I find out the original username a process was started with?

There is a perl script that needs to run as root but we must make sure the user who runs the script did not log-in originally as user 'foo' as it will be removed during the script. So how can I find out if the user, who might have su-ed several times since she logged in has not impersonated 'foo' at any time in that chain? I found an i...

Why does my ActivePerl program report 'Sorry. Ran out of threads'?

Tom Christiansen's example code (à la perlthrtut) is a recursive, threaded implementation of finding and printing all prime numbers between 3 and 1000. Below is a mildly adapted version of the script #!/usr/bin/perl # adapted from prime-pthread, courtesy of Tom Christiansen use strict; use warnings; use threads; use Thread::Queue; su...