perl

Why was this regex calling substcont an excessive number of times?

This is more out of curiosity than anything else, as I'm failing to find any useful info on Google about this function (CORE::substcont) In profiling and optimising some old, slow, XML parsing code I've found that the following regex is calling substcont 31 times for each time the line is executed, and taking a huge amount of time: ...

How can Perl's print add a newline by default?

In Perl most of my print statements take the form print "hello." . "\n"; Is there a nice way to avoid keeping all the pesky "\n"s lying around? I know I could make a new function such as myprint that automatically appends \n, but it would be nice if I could override the existing print. ...

How can I map UIDs to user names using Perl library functions?

I'm looking for a way of mapping a uid (unique number representing a system user) to a user name using Perl. Please don't suggest greping /etc/passwd :) Edit As a clarification, I wasn't looking for a solution that involved reading /etc/passwd explicitly. I realize that under the hood any solution would end up doing this, but I was se...

Safe non-tamperable URL component in Perl using symmetric encryption?

OK, I'm probably just having a bad Monday, but I have the following need and I'm seeing lots of partial solutions but I'm sure I'm not the first person to need this, so I'm wondering if I'm missing the obvious. $client has 50 to 500 bytes worth of binary data that must be inserted into the middle of a URL and roundtrip to their customer...

How do I get code coverage of Perl CGI script when executed by Selenium?

I'm using Eclipse EPIC IDE to write some Perl CGI scripts which call some Perl modules that I have also written. The EPIC IDE lets me configure a Perl CGI "run configuration" which runs my CGI script. And then I've got Selenium set up and one of my unit test files runs some Selenium commands to run my cgi script through its paces. But...

How do I edit an XML file with Perl?

I have a movie collection catalogue with local links to folders and files for an easy access. Recently I reorganaized my entire hard disk space and I need to update the links and I'm trying to do that automatically with Perl. I can export the data in a XML file and import it again. I can extract the new filepaths with the use of File::...

Extract Lines when Column K is empty with AWK/Perl

I have data that looks like this: foo 78 xxx bar yyy qux 99 zzz xuq xyz They are tab delimited. How can I extract lines where column 2 is empty, yielding bar yyy xuq xyz I tried this but doesn't seem to work: awk '$2==""' myfile.txt ...

How can I create a directory and fetch a file over FTP into that directory using Perl?

I have a file that looks like this: ftp://url1/files1.tar.gz dir1 ftp://url2/files2.txt dir2 .... many more... What I want to do are these steps: Create directory based on column 2 Unix 'cd' to that directory Download file with 'wget' based on column1 But how come this approach of mine doesn't work while(<>) { chomp; my ($url...

How do I pass disabled input elements from page 1 to page 2 in Catalyst?

How do I pass disabled input elements (TT) from page 1 to page 2 in Catalyst framework? I can do it with hidden input. Is there any other way to handle it? ...

How can I persist a large Perl object for re-use between runs?

I've got a large XML file, which takes over 40 seconds to parse with XML::Simple. I'd like to be able to cache the resulting parsed object so that on the next run I can just retrieve the parsed object and not reparse the whole file. I've looked at using Data::Dumper but the documentation is a bit lacking on how to store and retrieve it...

How do I get schemas from Perl's DBI?

I have using Perl DBI. In that $dbase->tables() will return all the tables in the corresponding database. Like this I want to know the schema's available in the database. Is there any function available for that? ...

How can I parse a string into a hash using keywords in Perl?

I have a string where different predefined keywords introduce different data. Is there a way to do that using clever use of regexp, or something? Here is an example: Keywords can be "first name: " and "last name: ". Now I want to parse: "character first name: Han last name: Solo" into { "first name: " => "Han ", "last name: " => "So...

Operating System Commands execution in Catalyst Controller?

How to use Operating System Commands in Catalyst Controller? For example. I want to use Perl system command in Controller .it’s not working .. Any idea? In Controller module my $cmd = "/temp/useradd.sh $username_st1 $_ $log_file &"; system ($cmd ); ...

How can I test whether a csv file is currently open and being written to - the file, not a file handle - with Perl?

I've seen a few questions/answers here that deal with this, but none really give me an answer/solution. I've got a Clipper system writing csv files to a Windows directory. I have a perl script running on a Linux server that is reading a mount of that Windows directory and importing the files to a database. Right now we're using flag f...

Perl, convert hash to array

If I have a hash in Perl that contains complete and sequential integer mappings (ie, all keys from from 0 to n are mapped to something, no keys outside of this), is there a means of converting this to an Array? I know I could iterate over the key/value pairs and place them into a new array, but something tells me there should be a built...

NCurses and Perl, any guides?

Hi! I need to use NCurses, with Perl. I found some very short bits of text about it but no example at all. Is there anyone aware of any existing guide online? Thanks! ...

Running a batch file from Perl (Activestate perl in Windows)

I have a Perl program which does something like below: #!perl use strict; use warnings; my $exe = "C:\\project\\set_env_and_run.bat"; my $arg1 = "\\\\Server\\share\\folder1"; my $arg2 = "D:\\output\\folder1"; my $cmd = "$exe \"$arg1\" \"$arg2\""; my $status = system("$cmd > c:\\tmp\\out.txt 2>&1"); print "$status\n"; I...

How can I redirect standard output to a file in Perl?

I'm looking for an example of redirecting stdout to a file using Perl. I'm doing a fairly straightforward fork/exec tool, and I want to redirect the child's output to a file instead of the parents stdout. Is there an equivilant of dup2() I should use? I can't seem to find it ...

Perl - Object value not saved

Trying to get the hang of using OOP in Perl. My problem is that I'm setting a variable in the class, but the value is lost when I try and retrieve it. I'm sure the issue is glaring, but I need some extra eyes. Constructor: sub new { my ($class, $name) = @_; my $self = { _name => $name, _times => [] }; bl...

How to run perl script with a few arguments from php

My html webpage calls a php script to upload files to the server from a local computer as follows. <form enctype="multipart/form-data" action="upload.php" method="POST"> <p><b><h3> <font color="#003366"> (1) Upload your reading text file. </font> </h3> </b> </p> <INPUT type="file" name="uploaded" size="50" > <br/> <input type="submi...