perl

how to grep perl Hash Keys in to an array?

Iam a perl newbie and need help in understanding the below piece of code. I have a perl Hash defined like this 1 my %myFavourite = ("Apple"=>"Apple"); 2 my @fruits = ("Apple", "Orange", "Grape"); 3 @myFavourite{@fruits}; # This returns Apple. But how? It would be great if perl gurus could explain what's going on in Line-3 of th...

Where do I install Perl modules that I wrote?

I wrote some modules, and trying to run them. How I tell where to take the module from? I am writing in Windows, and tried to put it in c:\perl\lib but it didn't help. Can I put it in the same directory, as the file that calls the module? ...

Adding LDAP OU using Net::LDAP

What is the correct syntax of adding an OU using Net::LDAP, I tried the following: #!/usr/bin/perl -w use 5.10.1; use strict; use Net::LDAP; use Data::Dumper; my $ldap = Net::LDAP->new("192.168.183.2") or die "$@"; my $mesg = $ldap->bind( "cn=admin,dc=lab,dc=net", password => 'xxx' ); $mesg = $ldap->add( "ou=Users,dc=lab,dc=net...

Why do my Perl module tests fail when I run them with Test::Harness::runtests?

I have a Test::More test script for a module we have made. When running the test script by itself, it works just as expected. Since there are several tests we need to run, I made a Test::Harness file that run all scripts. However, when executing from the Test::Harness runtests the script returns errors. During debugging I tried to run ...

Can I use rrdtool with Perl to make graphs from CSV files?

Below is the sample data format in my CSV file. date,<options> YYYY-MM-DD,<values> Every next morning this CSV file has been updated with next date values. Can I use rrdtool to create graphs, and if so how? ...

How do you generate website navigation?

I am interested in how other people handle website navigation. Not the styling or usability part, but the generation part. Most websites have some kind of “navigation tree” that is displayed in form of one or more menu levels – in what form do you save and process this tree? The simplest solution is a static menu template, something like...

Formal language expressiveness of Perl patterns

Classical regular expressions are equivalent to finite automata. Most current implementations of "regular expressions" are not strictly speaking regular expressions but are more powerful. Some people have started using the term "pattern" rather than "regular expression" to be more accurate. What is the formal language classification of...

Are there any problems handling a POST request as a GET request on the server

In an attempt to resolve the issue I posted in this question: Is it possible to send POST parameters to a CGI script using a system() call? So far the only successful resolution to the problem is to trick the environment to think the request was a GET. I do this by converting the POST parameters to a query string, saving that string i...

What are valid Perl module return values?

The common practice in Perl is of course to end modules with 1; so that a call to require can then be checked for success. Is there any reason that the return value couldn't be another true value? In my testing, it does not see to cause any problems, but I'd like to know if anyone has run across any issues (such as some other modules o...

How to implement sql LIKE qualifier with placeholdes for an array?

I am trying to implement sql LIKE qualifier with placeholders for a set of values. I know how to do it for one particular value as follows: use strict; use DBI; my $dbh = DBI->connect("dbi:Sybase:server=$Srv;database=$Db", "$user", "$passwd") or die "could not connect to database"; my $query = "Select key, first_name from names where la...

How can I capture and edit network packets on the fly with Perl?

Does someone know about a CPAN module on Win32 that captures network packets and edit them on the fly? As far as I know, the only Perl module on Win32 that deals with packets on the fly is Net::Pcap but it only support passive monitoring and not affet the TCP/IP stack. Is there a such module could someone provide example /reference /doc...

Moose ArrayRef attribute returned as an Array

I have a Moose class with an attribute that is an ArrayRef (read-only) and is manipulated internally by the object. But when someone calls the accessor method I want it to return an Array (or list) not a reference. Not only would this cut down on the amount of dereferencing that the user of the class has to do, but it will mean they can'...

Perl: Using DBI placeholders for ORDER BY clause

Can I use placeholders in a prepared statement for the order by clause of my query? I'm guessing not, as I tried it, and it didn't seem to work, but it didn't throw any errors either, which seemed strange. Is there a better way to do this, other than just generating an SQL string with the validated inputs? ...

What happens when you put an array on the right side of a => operator?

This might seem like a stupid question but it's been a long day. I'm an adapting some Perl code for another use and I ran across this syntax: my @request; #... fill the array with stuff... my $reply = $service->call('requestMessage' => @request, $header); That method call seems implausible, if => is just a special kind of comma and ...

How can I print list elements separated by line feeds in Perl?

What is the easiest way to print all a list's elements separated by line feeds in Perl? ...

How can I do 64-bit arithmetic in Perl?

I am a perl newbie, Can I simply use 64-bit arithmetic in Perl? For example $operand1 = 0xFFFFFFFFFFFF; // 48 bit value $operand2 = 0xFFFFFFFFFFFF; // 48 bit value $Result = $operand1 * $operand2; I am basically looking for a replacement for the int64_t in perl. Is there any way to mention, if the variable is signed or unsigne...

How can I sort a Perl list in an arbitrary order?

Hi Everyone, I have a list of strings whose values come from a fixed set. I need to sort this list in an arbitrary order. The order of the set is specified by another list of all possible strings, sorted in order in an array. Here is an example: my @all_possible_strings_in_order = ('name', 'street', 'city','state', 'postalcode'); ...

How do I extract words from a comma-delimited string in Perl?

Hi. I have a line: $myline = 'ca,cb,cc,cd,ce'; I need to match ca into $1, cb into $2, etc.. Unfortunately $myline =~ /(?:(\w+),?)+/; doesn't work. With pcretest it only matches 'ce' into $1. How to do it right? Do I need to put it into the while loop? Thanks! ...

How can I copy an entire directory in Perl?

I need to copy entire directory to some location. What is the best way to do so ? File::Copy copies only file by file as I saw it. By the way I work under Windows. Thanks for help. ...

How can I sum arrays element-wise in Perl?

Hi. I have two arrays: @arr1 = ( 1, 0, 0, 0, 1 ); @arr2 = ( 1, 1, 0, 1, 1 ); I want to sum items of both arrays to get new one like ( 2, 1, 0, 1, 2 ); Can I do it without looping through arrays? ...