perl

Why is $auth->loggedIn never true in my use of CGI::Session::Auth::DBI?

Using the examples from the CGI::Session::Auth::DBI and CGI::Session::Auth pages, I have attempted to implement the _login function with no success. I'm using Windows 7 and Apache 2. #!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use CGI; use CGI::Session; use CGI::Session::Auth::DBI; my $cgi = new CGI; # using '....

How do I write a Perl Script to read a CSV file first column and Update Oracle table?

How do I write a Perl Script to read a CSV file first column and Update Oracle table? cheers ...

How can I assign many Moose attributes at the same time?

I'm gradually Moose-ifying some code that reads lines from a pipe delimited, splits each and assigns adds them to a hash using a hash slice. I've turned the hash into a Moose class but now I have no idea how to quickly assign the fields from the file to the attributes of the class (if at all). I know I can quite easily just do: my $li...

How can I detect if there is ( = ) sign in current line in Perl?

Hi, How to detect if there is ( = ) sign in current line? thank you. $_ = $currentLine; if (Include =) { # do some thing } else { # do another thing } ...

split function extension

Hi, I am learning the sample code from split function. Sample code. #!C:\Perl\bin\perl.exe use strict; use warnings; my $info = "Caine:Michael:Actor:14, Leafy Drive"; my @personal = split(/:/, $info); # @personal = ("Caine", "Michael", "Actor", "14, Leafy Drive"); If change the $info = "Caine Michael Actor /* info data */"; How to...

Scripting HTTP more effeciently

Often times I want to automate http queries. I currently use Java(and commons http client), but would probably prefer a scripting based approach. Something really quick and simple. Where I can set a header, go to a page and not worry about setting up the entire OO lifecycle, setting each header, calling up an html parser... I am looking ...

Authentication Module Issues with Apache 2 and Perl

I am SharePoint Developer trying to get a Perl module to work with Subversion, but I think something is wrong with my syntax. I just need to get the username and password, pass it into the webservice, get a true/false and authenticate based on that information. Here is the code to the module in Perl: package Apache2::AuthGetUser; #aut...

find extra, missing, invalid strings when comparing two lists in perl

List-1 List-2 one one two three three three four four five six six seven eight eighttt nine nine Looking to output one | one PASS two | * FAIL MISSING three | three PASS * | three FAIL EXTRA four | four PASS five |...

What is the proper way to check if a string is empty in Perl?

I've just been using this code to check if a string is empty: if ($str == "") { // ... } And also the same with the not equals operator... if ($str != "") { // ... } This seems to work (I think), but I'm not sure it's the correct way, or if there are any unforeseen drawbacks. Something just doesn't feel right about it. ...

How to extend a binary search iterator to consume multiple targets

I have a function, binary_range_search, that is called like so: my $brs_iterator = binary_range_search( target => $range, # eg. [1, 200] search => $ranges # eg. [ {start => 1, end => 1000}, ); # {start => 500, end => 1500} ] brs_iterator->() will ...

What's wrong with this eval statement in Perl?

What's wrong with this eval statement in Perl? I'm trying to check that the XML is valid by catching any exceptions thrown from the parsing of the file with XML::LibXML: use XML::LibXML; my $parser = XML::LibXML->new(); #creates a new libXML object. eval { my $tree = $parser->parse_file($file) # parses the file contents i...

Regular expression (/<(\w+)\s+(.*?)>/) need improvement

Hi, There is a sub to handle the Type and Value. sub parse_type_value_specifier { my $tvs = shift; my ($type, $value) = $tvs =~ /<(\w+)\s+(.*?)>/; return $type, $value; } It should suit for three formats below. <B 0> - works, return $type = (B) and $value = (0) <A[1..80] ""> - doesn't work, need return $type = A[1..80]...

How can I guess if a string has text or binary data in Perl?

What is the best way to find out if the scalar value is ASCII/UTF8 (text) or a binary data in Perl? Is this code right?: if (is_utf8($scalar, 1) or ($scalar =~ m/\A [[:ascii:]]* \Z/xms)) { # $scalar is a text } else { # $scalar is a binary } Is there a better way? ...

Why doesn't Perl's eval catch problems from Test::Cmd::Common->unlink?

Hi, I have the following perl code : use strict; use warnings; use Test::Cmd::Common; my $path = "/something/not/available"; my $test = Test::Cmd::Common->new(string => 'File system operations'); eval{ $test->unlink("$path"); }; ok(!$@, "file unlike"); print "done.\n"; The $test->unlink() line will fail and throw exception....

How do I exit the command shell after it invokes a Perl script?

If I run a Perl script from a command prompt (c:\windows\system32\cmd.exe), how can I exit the command prompt after the script finishes executing. I tried system("exit 0") inside the Perl script but that doesn't exit the cmd prompt shell from where the Perl script is running. I also tried exit; command in the Perl script, but that does...

How can I tell if a Perl module is core or part of the standard install?

How can I check if a Perl module is part of the core - i.e. it is part of the standard installation? I'm looking for: a command-line command: a Perl subroutine/function to check within code Thanks in advance. Update Perhaps I should re-write the question to be: "How can I tell what modules were originally provided with the specifi...

How do I export this Unicode table as CSV in Perl 5?

I have a table that has some Unicode in it. I know that the Unicode data is fine as it comes out as JSON on our webserver just fine. But for some reason the CSV that I'm generating is ending up mangled. Here's our current code: my $csv = Text::CSV->new ({ eol => "\015\012" }); open my $fh, '>:encoding(utf8)', 'Foo.csv'; my $sth...

How can I find and replace text in XML using Perl?

My XML file looks something like this: <doc> <RU1> <conf> <prop name="a" val="http://a.org/a.html&gt; </conf> </RU1> <RAU1> <conf> <prop name="a" val="http://a.org/a.html&gt; </conf> </RAU1> <RU2> <conf> <prop name="a" val="http://a.org...

How can I kill a program that might not exist from Perl on Win32?

I'm looking for a way to make Perl kill all firefox.exe processes on Win32, and not give an error if no process exists. I'm currently using: system('taskkill /F /IM firefox.exe'); which throws up a big "ERROR: No such process found", when firefox wasn't present. ...

Perl Client to Java Server

I'm trying to write a perl client program to connect to a Java server application (JDuplicate). I see that the java server uses The DataInput.readUTF and DataInput.writeUTF methods, which the JDuplicate website lists as "Java's modified UTF-8 protocol". My test program is pretty simple, i'm trying to send client type data, which should...