perl

How should I store values in a multi-level Perl hash?

I am looking to do something like this. I remember I had some issues with values disappearing when programming like this. Is this type of structure "correct/valid" for a hash? my %VAR; $VAR{SCALAR} = "test scalar"; $VAR{ARRAY}[0] = "test array"; $VAR{HASH}{NAME}[0] = "test hash array 1"; $VAR{HASH}{NAME}[1] = "test hash array 2"; $VAR{H...

How can I connect to a Lotus Notes database (*.nsf) with Perl and DBI?

I've got a Perl/DBI program that needs to connect to a Lotus Notes database. With NotesSQL installed, the program works, but keeps prompting me for a Notes password. Is there any way to pass the Notes ID and password programmatically? I'm using ActiveState Perl 5.8.8, Notes 8.5, and NotesSQL 8.0. ...

Why does STDIN cause my Perl program to freeze?

I am learning Perl and wrote this script to practice using STDIN. When I run the script, it only shows the first print statement on the console. No matter what I type in, including new lines, the console doesn't show the next print statement. (I'm using ActivePerl on a Windows machine.) It looks like this: $perl script.pl What is the ex...

How can I revert to the previous Perl setup after installing Bundle::CPAN?

After installation of latest Bundle::CPAN, I realized that certain legacy code will not run in this latest version. I wish to remove (and not just unlink) this latest version and revert back to using the old version. How can I do that? ...

How can I exclude the part of the string that matches a Perl regular expression?

I have to file that has different types of lines. I want to select only those lines that have an user-agent. I know that the line that has this is something like this. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16 So, I want to identify the line that starts with the string "Us...

Is there a way to create XML dat according to an XSD in Perl?

I have a CSV file, and a XSD from which I need to create an XML file which conforms to the XSD Schema. Is there a way to create an XML according to an XSD? Doing it manually seems unreasonable. ...

Why does my Perl one-liner report "Bareword found where operator expected"?

I want to convert block size into MB. I am using the /e option in my substitution. When I add starting MB in substitution part it giving me the error. e.g: This works. echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2)#e; print' 8 This giving me the error. echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)...

How can I track users and other web stats in a Perl CGI program?

I have this internal website within a company and it's Perl CGI based. I would like to install some kind of system to track users and other web statistics. Any recommendations on how to do this? I would like to have full control and allow easy to install. ...

How can I dereference an array of arrays in Perl?

Can anyone please tell me how to dereference an array of arrays when passed to a function. I am doing like this: my @a={\@array1, \@array2, \@array3}; func(\@a); func{ @b=@_; @c=@{@b}; } Actually I want the array @c should contain the addresses of @array1, @array2, and @array3. ...

Using Actinic V8 and having a problem with Path to Perl and Perl Script Extension. Any help would be great.

Hi there, I am using Actinic v8 and having a problem locating the path to Perl. I am getting this message popping up and I just don't know what to do to solve it. The wizard needs to know where Perl is installed on the web server and what extension Perl scripts must have in order to execute on the remote server. You may need to cont...

Is there a compact Perl operation to slice alternate elements from an array?

If I have an array myarray in Python, I can use the slice notation myarray[0::2] to select only the even-indexed elements. For example: >>> ar = [ "zero", "one", "two", "three", "four", "five", "six" ] >>> ar [ 0 : : 2 ] ['zero', 'two', 'four', 'six'] Is there a similar facility in Perl? Thanks. ...

How can I check that two relational databases are identical regardless of primary keys?

I have a relational database with about 100 tables. Each table has unique, numerical, primary key with synthetic values and there are many foreign keys which link the tables. The tables are not big (tens or hundreds or records). This is a SQLite database. I need, for testing purposes, to compare two copies of the database by a linux scr...

How can I extract times of different formats from Perl strings?

I receive e-mails at least once a day with price changes. I am attempting to automate the recording of the data. I am fairly new to regex and now more confused than I was 5 hours ago. Here are some sample lines to parse. Note that the time format is not always the same: Effective 00:01AM, 10/13/10, PRICES WILL BE AS FOLLOWS UNLESS OT...

perl Moose accessor madness - can't define only a reader or writer accessor!

So I'm just trying to do a very simple thing: define a custom reader accessor for a moose attribute. So I try this: has 'compiled_regex' => ( isa => 'RegexpRef', is => 'rw', reader => 'get_compiled', ); but get_compiled never gets called, presumably because compiled_regex is read/write. Ok, no problem. I next try th...

How can I replace only complete IP addresses in a file using Perl?

I used the following Perl syntax in order to replace strings or IP address in a file: OLD=aaa.bbb.ccc.ddd (old IP address) NEW=yyy.zzz.www.qqq (new IP address) export OLD export NEW perl -pe 'next if /^ *#/; s/\Q$ENV{OLD }\E/$1$ENV{NEW }$2/' file example of problem: I want to change the IP address in file from 1.1.1.1 to ...

How can I execute an external Windows command and instantly return in Perl?

I've tried using system() with fork(), tried exec(), and still not getting what I need. I want to write a Perl script which executes, let's say, a different Perl script 5 times in a row (sending it different parameter values), but have it run concurrently. I realize I could turn my script into a .pm file and reference it but I'd prefer ...

What is a good way to deploy a Perl application?

I posted this question looking for something similar to Buildout for Perl. I think Shipwright is what I'm looking for but I'm not really sure. I've played around with it and I created a project, imported all of my source and dependencies and I've exported everything to a vessel then the documentation sort of just stopped. What do I do w...

How can I extract/parse tabular data from a text file in Perl?

I am looking for something like HTML::TableExtract, just not for HTML input, but for plain text input that contains "tables" formatted with indentation and spacing. Data could look like this: Here is some header text. Column One Column Two Column Three a b a b ...

How can I extract an array from a two-dimensional array in Perl?

I have once again forgotten how to get $_ to represent an array when it is in a loop of a two dimensional array. foreach(@TWO_DIM_ARRAY){ my @ARRAY = $_; } That's the intention, but that doesn't work. What's the correct way to do this? ...

How can I run multiple Perl scripts on Windows without opening separate command windows?

I have as many as ten Perl scripts to run on a Windows server. Is there something better than opening a new prompt for each script and having ten windows open on your server? ...