perl

Why does WWW::Mechanize and login-data break when I switch from a query string to a hash?

Hello! The following script works fine: #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use WWW::Mechanize; my $loginData = "userName=username&password=password&deeplinkForward=%2Fselfcare%2Frestricted%2FprepareCoCo.do&x=84&y=7"; my $loginUrl = "https://www.login.login/login.do"; my $mech = WWW::Mechanize->new( show_pro...

What regex can I use to match any valid IP-address represented in dot-decimal notation?

What regex can I use to match any valid IP-address represented in dot-decimal notation? ...

How can I list all CPAN modules depending on a given module?

How can I list all CPAN modules depending on a given module? For example, create a list of modules using Class::Workflow? ...

How can I set boilerplate information for the files generated by catalyst.pl?

When I use catalyst.pl to auto-generate my application, the AUTHOR section of the POD includes only my name like this. Kiffin Gish,,, What are the missing fields and how can I use them? Is it possible to use another boilerplate for the PODs? ...

Using Perl to select 1 from@db_link where db_link comes from each entries of a lookup table

I want to read a table in oracle which contains database links for checking availabilty of each database link and return only the bad results for each database link and error message. I want to fetch this lookup table into an array, and pass the entries of db_link to a select from dualQdb_link, test all the entries of lookup to test fo...

How do I replace any color that is not a specific color using PerlMagick?

After many hair-pulling frustrations I've finally got one version of the PerlMagick module working with my ActivePerl 5.10.0 build 1005. Now I'm playing with it to do some very basic color substitution. I already can substitute one color ,say, black, with another, say, blue, using the following code: #!perl use strict; use warnings; ...

Converting JSON to XML in Perl

Hi foks, my task is to convert JSON file into XML file in Perl. It is forbidden use automatic tools like XML2JSON, so I need to parse JSON in Perl variables and then, store it in XML file. Can you give me some examples how to use JSON:XS and XML:Simple to complete my task? Thanks a lot ...

Perl: How do I write to a directory besides bin?

I am trying to output a file in perl. I open the file and output like this.. open(my $out, ">", "output.html") or die "Can't open output.txt: $!"; print $out "something!"; Which works perfect. If I change it to this open(my $out, ">", "c:\somedirectory\output.html") or die "Can't open output.txt: $!"; print $out "something!"; It...

What does @_ -1 mean in Perl?

I'm trying to translate a Perl script to PHP and I'm having trouble with some Perl things. For instance, what does @_ -1 mean? And how do I write it in PHP? The whole function is as follows: sub variance { my $sum = sum_squares (@_); my $deg = @_ - 1; return $sum/$deg; } ...

Including perl cgi scripts in html

Hi, I want to write a header and footer perl scrip that will return the headers and footers of my individual webpages. I was assuming I would do some sort of include of that file in the part of the html file I want it to appear. Is that the way I should go about this, if so how do I do that? If anyone has any other suggestions for bet...

What does {$histogram{$value}++} mean in Perl?

The whole subroutine for the code in the title is: sub histogram { # Counts of elements in an array my %histogram = () ; foreach my $value (@_) {$histogram{$value}++} return (%histogram) ; } I'm trying to translate a Perl script to PHP and I'm having difficulties with it (I really don't know anything of Perl but I'm trying). So...

Perl and reading files with different encodings

I am using a perl script to read in a file, but I'm not sure what encoding the file is in. Basically, my file is a list of book titles, but each book has other info associated with it (author, publication date, etc). So each book title is within a discrete chunk of data for the book. So I iterate through the file line by line until I fin...

How to access data stored in Hash

I have this code: $coder = JSON::XS->new->utf8->pretty->allow_nonref; %perl = $coder->decode ($json); When I write print %perl variable it says HASH(0x9e04db0). How can I access data in this HASH? ...

How do I test for an exception type in perl?

How can I check what kind of exception caused the script or eval block to terminate? I need to know the type of error, and where the exception occurred. ...

regex to match postgresql bytea

In PostgreSQL, there is a BLOB datatype called bytea. It's just an array of bytes. bytea literals are output in the following way: '\\037\\213\\010\\010\\005`Us\\000\\0001.fp3\'\\223\\222%' See PostgreSQL docs for full definition of the format. I'm trying to construct a Perl regular expression which will match any such string. It sh...

How do I create a nested has_many or belongs_to relationship with DBIx::Class?

In my code I have three classes as follows: Forum, Forum::Thread and Forum::Post What I want to do is create a belongs_to-relationship from the Forum::Post class to the Forum class and vice versa with a has_many, preferably without creating a custom function for it. (This is admittedly more of an intellectual exercise than a technical l...

How to get all returned lines with each oracle errror message into one variable using perl

How do i get all of the lines of "$dblink is down" into one $l_msg string? Ideally I would like to get the error returned by oracle on failure and I cannot see a way to solve this. my $dblinks = $l_dbh->selectcol_arrayref("select dbname from db_link"); for my $dblink (@$dblinks) { my $l_results = eval { my ($l_erg) = $l_dbh->s...

In Perl, what is the sane way for converting a string into a list of its characters?

I have been wondering if there's a nicer, but concise way for splitting a string into its characters @characters = split //, $string is not that hard to read, but somehow the use of a regular expression looks like overkill to me. I have come up with this: @characters = map { substr $string, $_, 1 } 0 .. length($string) - 1 but I f...

How can I mock -f on an object in Perl?

I have a Perl object that has defined use overload '""' => \&name; and a name method. In my unit tests I have mocked this object, including the name method, but code like if (-d $object) still gives me Use of uninitialized value in -d .... The mocked method is not being executed. My mock code: my $CMmock = Test::MockObject::Extend...

Perl IO::Socket timing problem

I've bumped into a strange problem. I wrote a little daemon in Perl which binds a port on a server. On the same server there's a LAMP running and the client for my Perl daemon is a php file that opens a socket with the daemon, pushes some info and then closes the connection. In the Perl daemon I log each connection in a log file for lat...