perl

How do I efficiently parse a CSV file in Perl?

I'm working on a project that involves parsing a large csv formatted file in Perl and am looking to make things more efficient. My approach has been to split() the file by lines first, and then split() each line again by commas to get the fields. But this suboptimal since at least two passes on the data are required. (once to split by l...

configuring local W3C validator on xampp - windows xp sp3

Hi I have no experience on perl. I am trying to configure the W3C validator on my localhost (win32). I have already followed all the instructions given by W3C @http://validator.w3.org/docs/install_win.html, but I am getting the following error: Can't locate loadable object for module Encode::HanExtra in @INC (@INC contains: C:/xampp/...

Perl, treat string as binary byte array

In Perl, is it appropriate to use a string as a byte array containing 8-bit data? All the documentation I can find on this subject focuses on 7-bit strings. For instance, if I read some data from a binary file into $data my $data; open FILE, "<", $filepath; binmode FILE; read FILE $data 1024; and I want to get the first byte out, is...

What is the best GUI for Perl on Windows including a good GUI builder?

I want to build perl apps with a gui that: A: are windows compatible (no cygwin or the like) B: utilize a nice GUI builder C: is easily distributed (minimizing additional components that must be installed) D: has good documentation and tutorials for building and using the GUI E: is still be developed (has a future) and appears to be the...

Matching n parentheses in perl regex

Hi, I've got some data that I'm parsing in Perl, and will be adding more and more differently formatted data in the near future. What I would like to do is write an easy-to-use function, that I could pass a string and a regex to, and it would return anything in parentheses. It would work something like this (pseudocode): sub parse { ...

Why are references compacted inside Perl lists?

Putting a precompiled regex inside two different hashes referenced in a list: my @list = (); my $regex = qr/ABC/; push @list, { 'one' => $regex }; push @list, { 'two' => $regex }; use Data::Dumper; print Dumper(\@list); I'd expect: $VAR1 = [ { 'one' => qr/(?-xism:ABC)/ }, { 'two' => qr/(?-xism:ABC...

perl multiple tasks problem

I have finished my earlier multithreaded program that uses perl threads and it works on my system. The problem is that on some systems that it needs to run on, thread support is not compiled into perl and I cannot install additional packages. I therefore need to use something other than threads, and I am moving my code to using fork(). T...

how to make a non-blockin recv from perl socket

I make a recv call on a TCP socket and it tured out to be that the recv call is a blocking one even though the socket itself has set to be in non-blocking mode. So my question is just as simple as: how to implement a non-blocking recv on a perl socket? thanks in advance. ...

How do I use a dependency on a Perl module installed in a non-standard location?

I need to install two Perl modules on a web host. Let's call them A::B and X::Y. X::Y depends on A::B (needs A::B to run). Both of them use Module::Install. I have successfully installed A::B into a non-system location using perl Makefile.PL PREFIX=/non/system/location make; make test; make install Now I want to install X::Y, so I try...

Is there a way to avoid putting the Perl version number into the "use lib" line for Perl modules in non-standard locations?

I am trying to install some Perl modules into a non-standard location, let's call it /non/standard/location. I used perl Makefile.PL PREFIX=/non/standard/location make;make install to install them. In the script which uses the module, it seems to be necessary to specify a long directory path including the version of Perl, like so: ...

How to rewrite this eval block

Hi, This code smells... how do I rewrite it better? my $record; eval { while ( # undef $record here, so if getRecord() failed, nothing will be written # in the reject file do { undef $record; defined( $record = $dataFile->getRecord ) } ) { $LT_DataFile->encode($record); } 1; }; if ( my...

Using perl to split a line that may contain whitespace

Okay, so I'm using perl to read in a file that contains some general configuration data. This data is organized into headers based on what they mean. An example follows: [vars] # This is how we define a variable! $var = 10; $str = "Hello thar!"; # This section contains flags which can be used to modify module behavior # All modules r...

What is the difference between using $1 vs \1 in Perl regex substitutions?

I'm debugging some code and wondered if there is any practical difference between $1 and \1 in Perl regex substitutions For example: my $package_name = "Some::Package::ButNotThis"; $package_name =~ s{^(\w+::\w+)}{$1}; print $package_name; # Some::Package This following line seems functionally equivalent: $package_name =~ s{^(\w...

Why does Perl allow mutual "use" relationships between modules?

Let's say there are two modules that mutually use each other: package a; use b; sub p {} 1; package b; use a; 1; I think that it is systematically wrong to write code like the above, because the two modules will endlessly copy each other's code to themselves, but I can successfully run the following code, which makes me very surpris...

Why are values being truncated while reading an Excel 2007 (.xlsx) file in Perl?

I am reading an .xls file using Spreadsheet::ParseExcel and was able to get data as is. But,when reading an .xlsx file using Spreadsheet::XLSX, the read values are truncated. E.g., 2.4578 in .xls and .xlsx file is read as 2.4578 and 2.45, respectively. Please suggest why .xlsx file data is corrupted. ...

Parse and display MIME multipart email on website

I have a raw email, (MIME multipart), and I want to display this on a website (e.g. in an iframe, with tabs for the HTML part and the plain text part, etc.). Are there any CPAN modules or Template::Toolkit plugins that I can use to help me achieve this? At the moment, it's looking like I'll have to parse the message with Email::MIME, th...

How to "serialize" and "deserialize" command line arguments to/from string?

I call my script: $ ./script 'a!#*`*& ^$' "sdf sdf\"qw sdsdf" 1 -- 2 3 It gets arguments: 1: a!#*`*& ^$ 2: sdf sdf"qw sdsdf 3: 1 4: -- 5: 2 6: 3 If I need to call something with the same arguments locally, I do this: someprogram "$@" But how can I put all that array to a string (to store in file or in environment variable or pas...

Alternatives to storing Moose object using Apache::Session with CODE references

I have a Moose class that i would like to store using Apache::Session::File. However, Apache::Session::File by default will not store it and instead i get the error message: (in cleanup) Can't store CODE items at blib\lib\Storable.pm (autosplit into blib\lib\auto\Storable\_freeze.al)... This problem can be circumvented by setting $...

How can I optimize Perl code that checks for directory existence?

sub DirectoryExists { my $param = shift; # Remove first element of the array shift @{$param}; # Loop through each directory to see if it exists foreach my $directory (@{$param}) { unless (-e $directory && -d $directory) { return 0; } } # True return 1; } Is there any...

Perl - Unicode::String sub need to add/convert for Latin-9 support

Part 3 (Part 2 is here) (Part 1 is here) Here is the perl Mod I'm using: Unicode::String How I'm calling it: print "Euro: "; print unicode_encode("€")."\n"; print "Pound: "; print unicode_encode("£")."\n"; would like it to return this format: &#x20AC; # Euro &#x00A3; # Pound The function is below: sub unicode_encode { shift...