perl

How can I get the syntax tree from a coderef in Perl?

I'd like to inspect and manipulate code of arbitrary Perl procedures (got by coderefs) in Perl. Is there a tool/module/library for that? Something similar to B::Concise, except that B::Concise prints the code on output, but I'd like to inspect it programmatically. I'd like to use it like this. Given a coderef F, which is called eg. with...

Why do I use up so much memory when I read a file into memory in Perl?

I have a text file that is 310MB in size (uncompressed). When using PerlIO::gzip to open the file and uncompress it into memory, this file easily fills 2GB of RAM before perl runs out of memory. The file is opened as below: open FOO, "<:gzip", "file.gz" or die $!; my @lines = <FOO>; Obviously, this is a super convenient way to open g...

How do I URI escape Japanese characters in Perl?

How do I URI escape Japanese characters in Perl? ...

How can I build a Perl hash in C code?

I wish to embed a C code in Perl. In this C code I want to read a huge file into memory, make some changes and build a hash (a custom one). I wish to make this hash accessible from my Perl code. Is it possible? How can I reach the goal? ...

Create a hierarchy file using perl

My task is to create a parent-child hierarchy file using perl. Sample Input file (tab delimited). The records would be arranged in the file in random order and the "parent" may appear after the "child". S5 S3 S5 S8 ROOT S1 S1 S7 S2 S5 S3 S4 S1 S2 S4 77 S2 S9 S3 88 Sample Output File (tab delimited) ROOT S1 S2 S5 S3...

Perl -- DBI selectall_arrayref when querying getting Not Hash Reference

Hi I am very new to perl (but from a c# background) and I am trying to move some scripts to a windows box. Due to some modules not working easily with windows I have changed the way it connects to the DB. I have an sqlserver DB and I had a loop reading each row in a table, and then within this loop another query was sent to select diff...

perl win32::gui remove elements

I have a dialogbox, to which i populate elements(labels) on activate event. I want to remove these elements(labels) when the window is being deactivated. something like:[its erroneous fragment of main code but explanatory] my $wchRW = Win32::GUI::DialogBox->new( -name => "wchR", -title => "whed", -left => CW_USEDEFAULT, -size ...

How can I add repeated values to an array in Perl?

I have an array @genotypes = "TT AG TT AG...." and want to add a spike to it (e.g. 20 x TT) to make a new array. I can obviously push "TT" into the array 20 times - but is there a simpler way of doing this? (ie. not @newarray = push @genotypes ("TT", "TT", "TT",......20 times!); ...

How can I reliably parse a QuakeLive player profile using Perl?

I'm currently working on a Perl script to gather data from the QuakeLive website. Everything was going fine until I couldn't get a set of data. I was using regexes for that and they work for everything apart from the favourite arena, weapon and game type. I just need to get the names of those three elements in a $1 for further processi...

How can I set environment variables in my Linux service for Asterisk even though it doesn't have a real user?

I have created a linux service that runs as a deamon (and gets started from /etc/init.d/X). I need to set some environment variables that can be accessed by the application. Here's the scenario. The application is a bunch of Perl AGI scripts that depend on (and therefore need to run as) asterisk user but asterisk doesn't have a shell. I...

Getting data from a variable number of columns in Excel using Perl with OLE

I am using OLE with Perl to build a few charts in Excel. The data is in four different worksheets depending on which of the four tests it is for. The problem is that I don't know how to set the chart to look at all of the data when I don't know how long it will be. I know to use; $last_col = $sheet -> UsedRange -> Find({What => "*", Se...

Is there a DotNetOpenAuth equivalent that runs on a LAMP stack?

I really love the way the StackExchange family of sites allow someone to log in using their OpenID or OAuth provider, which has been open-sourced as DotNetOpenAuth. This is absolutely wonderful, but I am unable to use it on a *AMP stack. Is there anything analogous that runs in PHP, Perl, Python or Ruby? ...

How can I create arrays and hashes in Perl?

This is not generic question. I have asked this question because I'm confused with creating Perl arrays. How do I create or define the Array or hash? What are other ways to do that? How do I clear a array or hash? What are other ways to do that? How do I create a array or hash with empty element? What are the ways to create hash with...

Berkeley DB with Perl API, can't open existing database

This is very perplexing, but I'm having this weird error. Here's the code I have: my $env = new BerkeleyDB::Env ( -Home => "$dbFolder", -Flags => DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL | DB_CDB_ALLDB ) or die "cannot open environment: $BerkeleyDB::Error\n"; my $unsortedHash = BerkeleyDB::Hash->new ( -Filename => "Uns...

Why do I get many Moose warnings when I start Catalyst?

Hi everyone, I am having an issue (Catalyst related) apparently with Moose/Class::MOP. Starting my server I get the following output... (shown below in all its glory) The alias and excludes options for role application have been renamed -alias and -excludes at /usr/local/lib/perl/5.10.1/Moose/Meta/Role/Application.pm line 26 Moose:...

How can I delete a line in file if the line matched the required PATH, in Perl?

My target is to delete line in file only if PATH match the PATH in the file For example, I need to delete all lines that have /etc/sysconfig PATH from /tmp/file file more /tmp/file /etc/sysconfig/network-scripts/ifcfg-lo file1 /etc/sysconfig/network-scripts/ifcfg-lo file2 /etc/sysconfig/network-scripts/ifcfg-lo file3 I wri...

Comparing filehandle with glob returned by IO::Select::can_read()

Hello, I am trying to manage three filehandles via IO::Select in perl. I have 1 input handle, 1 input/output handle, and 1 output handle. Im having a little trouble determining which filehandle is which when processing Select's return arrays of can_read() and can_write(); Example below Any advice on how to actually compare these two f...

How can I use PDL rcols in a subroutine with pass-by-reference?

Specifically, I want to use rcols with the PERLCOLS option. Here's what I want to do: my @array; getColumn(\@array, $file, 4); # get the fourth column from file I can do it if I use \@array, but for backward compatibility I'd prefer not to do this. Here's how I'd do it using an array-ref-ref: sub getColumn { my ($arefref, $f...

Feedback, question about my module and if i should change anything ?

package My::Module; # $Id$ use strict; use Carp; use Data::Dumper; use DBI; $My::Module::VERSION = '0.1'; sub new { my ($class, %opt) = @_; my $opt_count = keys %opt; $class->set_error(''); #return $class->set_error("Too many arguments to initialize.") if ($opt_count > 5); #return $class->set_error("Missing argu...

How can I handle web sessions with CGI::Session in Perl?

Im creating a web application in Perl using CGI. This application implements the Model View Controller architecture and the system has the following structure in the root directory: -models -views -controllers -index.pl The file index.pl only includes the respective views according to certain parameters that are sent to it (using funct...