perl

How can I ignore a bad xmlns namespace with Perl's LibXML?

I have an XML document that references a namespace that is no available: <microplateDoc xmlns="http://moleculardevices.com/microplateML"&gt; ...my data is here... </microplateDoc> I have a script that reads it fine, but only when I delete the two above tags, otherwise it reads it all screwed up. Is it ok just to ignore it? I'm thin...

How can I create and maintain sessions in series of Perl CGI scripts?

Hi All, I am new to CGI-Perl and sessions. I have a problem running the following code. I have four files 1. Session.html or Session.pm 2. name.pl 3. hobbies.pl 4. job.pl The Session.pm is place in /var/www/html folder and the rest of the files are placed in /var/www/cgi-bin/session folder. I have a basic html file(Session.html) whic...

How can I extract attributes from repeated tags in XML using Perl?

I am trying to parse a set of XML files. The XML file may have single flag tag or multiple flag tags: <job> <flag exit="0">aaa</flag> </job> OR <job> <flag exit="0">aaa</flag> <flag exit="1">bbb</flag> <flag exit="2">ccc</flag> </job> But determining this "flag" count has to be determined on the fly. What's the best way to ...

How can I extract a CDATA value from the structure created by XML::Simple?

I use a Perl script with the module XML:Simple to parse an XML feed: my $xml=XMLin($resp->content); my $xml2 = $xml->{params}{param}{value}{array}{data}{value}{struct}{member}; print $xml2->{prod_id}{value}{int}; #works fine print $xml2->{product_text}{value}{string}; #returns a hash reference (hash(0x...) What have I to modify to ...

How can I translate my XML file to a CSV file, even if it has repeated tags?

I have this XML file: <cjl> <job> <plan on="1">aa</plan> <exec>d.java</exec> </job> </cjl> The job tag may be repeating and also the plan tag also may be repeating. <cjl> <job> <plan on="2">aa</plan> <exec>e.java</exec> </job> <job> <exec>f.java</exec> <plan on="1">bb</plan> ...

How can I answer the prompts from an external program with Perl?

I have a .exe file. When I run it it asks for the path of a CSV and a .C file. My problem is that I need to execute that .exe through Perl and provide the path of the .C file as well as CSV file path automatically. How can I do that? it is a gui .exe through open command i can browse and give the path of the c file and CSV.I hope it it ...

How can I match text and replace it with a computed value based on the match in Perl?

I have a function, call it f, that takes a string and returns a string. I have a file with lines that look like this: stuff:morestuff:stuff*:otherstuff:otherstuff*\n Colons only appear as delimiters and * only appears at the end of each word. I want to loop over the file and replace all instances of stuff* with f(stuff). The previou...

How can I escape meta-characters when I interpolate a variable in Perl's match operator?

Suppose I have a file containing lines I'm trying to match against: foo quux bar In my code, I have another array: foo baz quux Let's say we iterate through the file, calling each element $word, and the internal list we are checking against, @arr. if( grep {$_ =~ m/^$word$/i} @arr) This works correctly, but in the somewhat possi...

Why does WebService::Mappoint complain about "Not a HASH reference" when I call new()?

I've inherited some Perl code that makes a web service call to Microsoft's Mappoint wbeservice, but after a recent upgrade, it's started failing with the ever cryptic: Not a HASH reference at /usr/lib/perl5/site_perl/5.8.0/WebService/Mappoint.pm line 35. Without posting the full code of the module (after all, WebService::Mappoint i...

Why does my system call to another CGI script work on the command line but not when run as a CGI program?

I have a scriptA.cgi which calls scriptB.cgi. scriptB.cgi requires a param. I have tried both inside scriptA.cgi I have tried: `perl -l scriptB.cgi foo="toast is good" `; as well as @args = ("perl", "-l", "scriptB.cgi", "foo=\"toast is good\""); system(@args); When I call scriptA.cgi from the command line it works as expected. ...

How can I remove a Windows directory without following junction points?

I have a Perl script that needs to delete a directory with all its contents. Sometimes this directory contains a junction point into another directory. If I rmtree() naively, the rmtree() call will also delete all the files inside the target folder of the junction. I'm looking for a way to not do that, and instead just remove the junctio...

How can I escape single and double quotes in SQL prepared statement?

I have a SQL statement similar to the one shown below in Perl: my $sql="abc..TableName '$a','$b' "; The $a is free text which can contain anything including single quotes, double quotes, back- and front-slash characters, etc. How can these characters be escaped to make the SQL statement work? Thanks. ...

How can I run a shell script from inside a Perl script run by cron?

Is it possible to run Perl script (vas.pl) with shell sript inside (date.sh & backlog.sh) in cron or vice versa? Thanks. 0 19 * * * /opt/perl/bin/perl /reports/daily/scripts/vas_rpt/vasCIO.pl 2> /reports/daily/scripts/vas_rpt/vasCIO.err Error encountered: date.sh: not found backlog.sh: not found Perl script: #!/opt/perl/bin/per...

Why does Perl's Text::Capitalize turn "Juvénal" into "JuvéNal"?

I'm using Text::Capitalize to try and title case some UTF-8 encoded names from a web page (downloaded using WWW::Mechanize, but I'm not getting the results I'm expecting. For example, the name on web page is "KAJELIJELI, Juvénal" but capitalize_title returns "Kajelijeli, JuvéNal" (notice the uppercase N). I've tried use utf8; and chang...

How can I create a new CGI script programmatically and run it immediately?

I have written a Perl script to read the configuration file and create CGI scripts. This works fine and I get the output of CGI script on terminal and I can execute that CGI scripts on web pages. Below is my sample script. #!/usr/bin/perl -w use strict; use Text::Template; my $conf = "test.cfg"; open CFG, $conf or die "Could not open...

Why does the browser hang when I register a cleanup handler in mod_perl?

I'm using $r->pool->cleanup_register(\&cleanup); to run a subroutine after a page has been processed and printed to the client. My hope was that the client would see the complete page, and Apache could continue doing some processing in the background that takes a few seconds. But the client browser hangs until cleanup sub has returned. ...

How do I replace "\" with "//" in Perl?

I want to substitute, the "\" that appears in the Windows directory link to a "/". I tried using s//\////g, but it doesn't seem to do the trick. ...

Why do I get "Syntax error near '$rocks['" in this Perl code?

When I run this program on ActivePerl 5.8 on Windows XP, I get a syntax error: #!C:\Perl\bin\perl.exe use strict; # enabled use warnings; (my $rocks[0], my $rocks[1]) = qw/Hello World/; # Syntax error near '$rocks[' my $rocks[2] = 'Tom'; # Syntax error near '$rocks[' my $rocks[3] = 'Cat'; # Syntax error near '$rocks[' print $rocks[...

How can I reverse an array reference and store that in another array reference in Perl?

I have this example: my $numbers = [ 1, 2, 3, 4, 5, 6 ]; my $newarray = [ reverse @$numbers ]; This example contains some synthetic code to make the $numbers arrayref appropriate for the reverse function. I would like to remove that code and do something more like this: my $newarray = reverse $numbers; I know this doesn't work, it ...

Why would I return a hash or a hash reference Perl?

Hi I was wondering what the most effective way of accomplishing the below would be. ( i know they accomplish the same thing but was wondering how most people would do this between the three, and WHY ) a.pl my %hash = build_hash(); # do stuff with hash using $hash{$key} sub build_hash { # build some hash my %hash = (); my @...