perl

How can I suppress \\ in my output from Perl's JSON module?

Following code always print paths with double slashes: use JSON; use File::Spec; my $installdir = $ENV{"ProgramFiles"}; my $xptrlc = File::Spec->catfile($installdir,"bin","sample"); my $jobhash; my $return_packet; $jobhash->{'PATH'} = $xptrlc; $return_packet->{'JOB'} = $jobhash; my $js = new JSON; my $str = $js->objToJson($return_p...

How can I iterate through nested arrays in Perl?

I have created an array as follows while (defined ($line = `<STDIN>`)) { chomp ($line); push @stack,($line); } each line has two numbers. 15 6 2 8 how do iterate over each item in each line? i.e. I want to print 15 6 2 8 I understand it's something like foreach (@{stack}) (@stack){ p...

How do I get perl-support.vim to recognize Perl files?

I installed perl-support.vim into ~/.vim (unzipped). When I create a new .pl file it shows me the default template, which means my installation is successful (I guess). I have already added filetype plugin on in ~/.vimrc & /etc/vimrc. How do I enter a perl-support command? The write up recommends typing \isu in normal mode for creating ...

How can I convert spaces to required tabs in Perl?

Hi this is the sample text file with values , i need to remove the spaces and add the tabs could any one guide me the process? Alpha : 12 13 14 15 Beta : 14 45 56 67 Gama : 89 98 00 00 Thanks in advance. ...

Why do Perl string operations on Unicode characters add garbage to the string?

A quick question for a change. Perl: $string =~ s/[áàâã]/a/gi; #This line always prepends an "a" $string =~ s/[éèêë]/e/gi; $string =~ s/[úùûü]/u/gi; This Regex should convert "été" into "ete". What it does instead is converting it to "aetae". In other words, it prepends an "a" to every matched element. Even "à" is converted to "aa". ...

The future of Perl? (Perl 6, Employability)

I've found a few related questions, like Python V Perl and Is Perl Worth it?, but I can't seem to find anything that directly addresses this question. Is there a legitimate future in Perl? I work in a Perl shop right now, and I came from PHP so I see some of the advantages of an arguably "lower" level language when doing things on the s...

Where does the Perl Package Manager get its 'areas' data from on Win32?

I guess I didn't upgrade the right way, but for a while I was running two versions of Perl concurrently. Now I just have one, but every time I start PPM it recreates the Perl folder of one of the old locations. I've set the active one to be the current Perl folder, but because the old one is still present on the list (displayed when I ...

Is this the way to go about building Perl subroutines?

So I've had a simple ucwords function for Perl which I've had a while, and wanted to expand it, this is what I've come up with, is this the way I should be building my functions to handle optional parameters? Original: sub ucwords{ $str = @_[0]; $str = lc($str); $str =~ s/\b(\w)/\u$1/g; return $str; } Extended: sub u...

What are your suggestions for an ideal Vim configuration for Perl development?

There are a lot of threads pertaining to how to configure Vim/GVim for Perl development on PerlMonks.org. My purpose in posting this question is to try to create, as much as possible, an ideal configuration for Perl development using Vim/GVim. Please post your suggestions for .vimrc settings as well as useful plugins. I will try to merg...

Why does my Apache2::Log output replace newlines with \n?

I've set up multiple vhosts under apache2 / mod_perl. I used the ErrorLog directive to get a separate error log for each vhost. This only worked as expected when I used Apache2::Log. 'warn' would only log to the regular error log. So that's all working. Finally. But there's one issue remaining: When I log via $r->log_error, I find that ...

How can I check that a column in a tab-delimited file has valid values?

I have a large file named CHECKME which is tab delimited. There are 8 columns in each row. Column 4 is integers. By using Perl or Python, is it possible to verify that each row in CHECKME has 8 columns and that column 4 is an integer? ...

Trying to run ftpsync.pl from post-commit hook

As the title says, I'm trying to ftpsync changed tree to our dev web server. On committing I get this error: post-commit hook failed (exit code 13) with output: Cannot create syncfile for time sync option at /data/ftpsync/ftpsync.pl line 484. I've tried looking at line 484 but Perl looks like a foreign language to me :) What...

Do I need to trap errors in my calls to Win32::OLE->LastError?

[EDIT] - with the benefit of hindsight, this question was misdirected. I have not deleted it because it is a good example of the incorrect use of eval and correct criticism by Perl::Critic. Perl Critic raises the following criticism for the code below: Return value of eval not tested. You can't depend upon the value of $@/$EVAL_ERR...

How can I access parameters passed in the URL when a form is POSTed to my script?

I've run into an issue with mod_rewrite when submitting forms to our site perl scripts. If someone does a GET request on a page with a url such as http://www.example.com/us/florida/page-title, I rewrite that using the following rewrite rule which works correctly: RewriteRule ^us/(.*)/(.*)$ /cgi-bin/script.pl?action=Display page in this...

What is the best way to validate XML against XML Schema, parsing it and storing data back to MySQL Database using Perl ?

Dear SO Readers, Currently I am working with XML and I want to know what would be best approach to validate XML against XML Schema, parse it and store it back to MySQL database using Perl ? I think of XML::Xerces for parsing purpose but not sure if it's the right approach. Note: I have very large XML file >1GB size. ...

perl hangs on exit (after closing a filehandle)

I've got a function that does (in short): my $file = IO::File->new("| some_command >> /dev/null 2>&1") or die "cannot open some_command for writing: $!\n"; ... undef $file; Right now I'm not even writing anything to $file. Currently there are no other operations on $file at all. When I run the program, it doesn't exit properly. I...

How can I mock %ENV in Perl tests?

I'm trying to retrofit some tests using Test::More to legacy code and I've bumped into a bit of a snag. I don't seem to be able to set %ENV in the test module. The called function definitely uses this variable so %ENV doesn't seem to be carried across to the test object. #!/usr/bin/perl use strict; use warnings; use Test::More qw(no_pl...

How do I move the instruction point in the Perl debugger?

I would like to be able to (reasonably) arbitrarily set my execution point in the Perl debugger. E.g., moving immediately prior to an if from the body of the if and setting a variable. Rummaging around the perldebug(and perldebguts and the perl debugger POD) page suggests that this kind of functionality is either not supported or not do...

How do I install XML::Xerces?

Please see Part 2 which list latest errors while installing module continued post. Normally when I try to install XML::Xerces CPAN module using standard cpan> install XML::Xercers than I get following error message after some processing: XML-Xerces-2.7.0-0/samples/SEnumVal.pl ... XML-Xerces-2.7.0-0/postSource.pl XML-Xerces-2.7.0-0/xerc...

How do I build a 2d matrix using STDIN in Perl?

How do I build a 2d matrix using STDIN? If I input a matrix like so: 1 2 3 4 5 6 7 5 6 7 8 9 4 5 6 3 3 3 how do I input this and create two matrices out of this? Here's my code so far while (defined ($a=<STDIN>)) { chomp ($a); push @a,($a); } This is just for the input. My understanding is I can just add each row...