perl

How can I convert an XML processing instruction to a tag using Perl?

How do I convert the processing instruction elements into normal XML element using Perl? for example: <?legalnoticestart?> <?sourcenotestart?> <para>Content para</para> <?sourcenoteend?> <?literallayoutstart?> <?literallayoutend?> <?literallayoutend?> <?legalnoticeend?> Required format: <legalnotice> <sourcenote> <p>Content para</p>...

How do I search for .exe files with a Perl program?

Do you guys have an idea on how to search or list down .exe files on the server I am currently using. (or maybe place it in an array)? I will use this command in my Perl program. Assuming that my program is also located on the said server. My OS is Linux - Ubuntu if that even matters, just in case. working in CLI here. =) ...

How do I check for numeric overflow and underflow conditions in Perl?

Hi All, I am doing one multiplication operation between two float variables. After that i need to check for numeric overflow, underflow and divide by zero errors if any. How I can do this? ...

Is 999...9 a real number in Perl?

sub is_integer { defined $_[0] && $_[0] =~ /^[+-]?\d+$/; } sub is_float { defined $_[0] && $_[0] =~ /^[+-]?\d+(\.\d+)?$/; } For the code mentioned above, if we give input as 999999999999999999999999999999999999999999, it is giving output as not real number. Can anyone help me in this regard why it is behaving like that? I forg...

How do I set up the data structure to make pie charts in GD::Graph?

I am writting a Perl script to create pie graph using GD::Graph::pie with these arrays: @Array1 = ("A", "B", "C", "D"); $array2 = [ ['upto 100 values'], ['upto 100 values'], ['upto 100 values'], ['upto 100 values'] ]; As per my understanding to get this done, I have to create an array with the references o...

How can I match a word that isn't certain words?

Using a Perl or unix regex, how would I capture a word that is not a range of values. Here is what I am trying to achieve. (\w:not('int','long')) ...

Why do I get an error when I try to use the reptition assignment operator with an array?

#!/usr/bin/perl use strict; use warnings; my @a = qw/a b c/; (@a) x= 3; print join(", ", @a), "\n"; I would expect the code above to print "a, b, c, a, b, c, a, b, c\n", but instead it dies with the message: Can't modify private array in repeat (x) at z.pl line 7, near "3;" This seems odd because the X <op>= Y are documented as be...

What is the Perl equivalent to bash's "$@"?

I'm working on a Perl script that I was hoping to capture a string entered on the command line without having to enter the quotes (similiar to bash's "$@" ability). I'll be using this command quite a bit so I was hoping that this is possible. If I have: if ($ARGV) { I have to put the command line string in quotes. I'd rather do the...

What's a good strategy to restart downed FastCGI processes automatically?

I've got a Perl based FastCGI app that rarely goes down. However, when it does go down, the restart is not automatic. Restarting Apache manually always does the trick but that does address improving the uptime of the app. I'm thinking of using a cron job in conjunction with a script that uses WWW::Mechanize to periodically check on the ...

How can I detect Russian spam posts with Perl?

I have an English language forum site written in perl that is continually bombarded with spam in Russian. Is there a way using Perl and regex to detect Russian text so I can block it? ...

How can I remove all non-word characters except the newline?

I have a file like this: my line - some words & text oh lóok i've got some characters I want to 'normalize' it and remove all the non-word characters. I want to end up with something like this: mylinesomewordstext ohlóokivegotsomecharacters I'm using Linux on the command line at the moment, and I'm hoping there's some one-liner I c...

In Perl: How to check for a pattern saved in $var for presence at the end of $str ? Both variables have special characters.

In perl, if I have a string $str and a pattern saved in $pat and I want to replace what is saved in $pat with 'nothing' only if $pat appears at the end of $str, how would the regular expression look like? I tried different versions of this - s/\$pat$// That, and all variations( s/$pat$//, s/\${pat}$//, s/${pat}$//) are not working :| ...

How do I call a Win32 DLL void** parameter using Win32::API?

I have a Windows DLL that I want to call from Perl. The prototype for the exported function is: int __stdcall func(const char*, int, int, int, double, double, void**); The last parameter returns a pointer to an object that is allocated in the function. The perl code – my $dll_path = "../stage/test_dll.dll"; my $dll_func = new Win32...

How can I get Perl's ref() function to return REF, IO, and LVALUE?

The documentation for ref() mentions several possible return values. I understand most of them, but not REF, IO, and LVALUE. How would I write Perl code to cause ref to return those values? After reading the documentation on typeglobs and file handles, I came close for IO with this code: open(INPUT, '<', 'foo.pl'); print ref(*INPUT{IO}...

How can I integrate parts of Catalyst into a legacy webapp?

I'm struggling with a classic legacy project: manual URL parsing and composition, manual routing etc. Knowing a bit of Catalyst I long for at least some of the concepts, for example proper (a.k.a. transparent) URL routing and parameter parsing for example. Ideally, I'd just use Catalyst and be done with it, but given it's a legacy projec...

How do I use a variable for the name of a table in a DBI query?

How do I using a variable for the name of a table in a DBI query? I know how to use placeholders as part of the where clause, but how do I do this for the table name? I would like to do something like this: my $table_name='table1'; my $query = $dbh_cgi->prepare("select * from ?"); $query->execute($table_name); So far, I end up get...

How can I order tags in XML::Simple's output?

Here's my scenario: I need to generate XML via Perl in which the schema is full of <xs:sequence> tags (i.e. the tags MUST appear in order). I don't have control over the schema (third party) and there have been so many problems whenever we add new CPAN modules (don't have a good way to propagate them to customers, etc) that we've basic...

Perl regular expression problem

I have this conditional in a perl script: if ($lnFea =~ m/^(\d+) qid\:([^\s]+).*?\#docid = ([^\s]+) inc = ([^\s]+) prob = ([^\s]+)$/) and the $lnFea represents this kind of line: 0 qid:7968 1:0.000000 2:0.000000 3:0.000000 4:0.000000 5:0.000000 6:0.000000 7:0.000000 8:0.000000 9:0.000000 10:0.000000 11:0.000000 12:0.000000 13:0.00000...

Why can't Cygwin CVS read the CVS password file in a Ruby/Perl script?

On the Windows command line and cygwin bash I can execute the following without problems: cvs login cvs -Q log -N -rVersion_01_00 A ruby script in the same directory contains the following: `cvs login`; `cvs -Q log -N -rVersion_01_00`; When I execute the ruby script on the Windows command line I get the following error: cvs log: w...

How can I return a list of hashrefs from a map in Perl?

I have the following mostly ok code: my $results = { data => [ map { my $f = $_->TO_JSON; $f->{display_field} = $_->display_field($q); $f; } $rs->all ]}; Only I'd rather it were more like the following: my $results = { data => [ map { %{$_->TO_JSON}, display_field => $_->display_field($q), },...