perl

How do I properly format plain text data for a simple Perl dictionary app?

I have a very simple dictionary application that does search and display. It's built with the Win32::GUI module. I put all the plain text data needed for the dictionary under the __DATA__ section. The script itself is very small but with everything under the __DATA__ section, its size reaches 30 MB. In order to share the work with my fri...

Validate XML using LibXML

Hi All, Currently, I am using the XML::LibXML perl module to validate an XML file against a defined XML schema. At the moment, if my XML file fails to validate successfully against the defined XML Schema, I will get a list of errors informing me, for example that certain elements were not expected and then what was expected instead. In ...

Reading output from TCPFlow with Perl Script

I have been playing around with TCPFlow to look at telnet traffic. What I would like to do is have the output from TCPFlow redirected to a Perl Script that watches for the phrase "Password:" then prints out the following password to a terminal window or separate file. How do I redirect the output from TCPFlow to my Perl Script then cons...

How do I use $File::Find::prune?

I have a need to edit cue files in the first directory and not go recursively in the subdirectories. find(\&read_cue, $dir_source); sub read_cue { /\.cue$/ or return; my $fd = $File::Find::dir; my $fn = $File::Find::name; tie my @lines, 'Tie::File', $fn or die "could not tie file: $!"; foreach (@lines) { ...

How to get matching string by performing search on Lucene ?

I would like to know how can I get the matching string results by performing search on a Lucene index ? I have tried to install the Perl module Lucene::Search::Highlight and failed over and over again. Is there another I can get the relevant fragments of text that Lucene "thinks" they relevant for my search phrase? ...

How can I determine the number of vars defined in another regexp?

For example, /(\w+) (?:\+) (\w)/ that regexp must return 2. I must apologize for an incomplete question. Here's the problem: Input is XML-file (in fact it does not matter :), which sets rules for strings. At the moment it looks like this: <string svars="3">(?:total ?|)(\d{1,2}(?:[\.,]\d{1,2}|))\/(\d{1,2}(?:[\.,]\d{1,2}|))\/(\d{1,2}(?:...

Shorthand for referring to Perl/Moose package names?

In both Python and Java we have import to eliminate the repetition of fully-qualified package/module names throughout code. Is there any equivalent in Perl/Moose? I think it would really make Moose nicer to use if we didn't have to repeat MyApp::Model::Item. Instead, I'd like to [somehow declare] MyApp::Model::Item; and later on, simply ...

Import MooseX::Method::Signatures into caller's scope

I've made a "bundle" module which does a bunch of things: imports Moose, imports true, namespace::autoclean, makes the caller's class immutable (taken from MooseX::AutoImmute). The one thing I haven't been able to figure out is how to include MooseX::Method::Signatures. Here's what I've got so far: package My::OO; use Moose::Exporter;...

How to Debug Perl XS code on Windows

Can you describe the steps for debugging Perl XS dll on Windows. A UI debugger like Windbg is preferred. I want to be able to set breakpoint on the routines in the dll and examine stack etc. I have debug build of perl on my box. ...

Extract binary data from DB to file

How do I extract binary data from DB to file CREATE TABLE `mail_attachs` ( `attachid` int(15) NOT NULL auto_increment, `filecontent` longtext, PRIMARY KEY (`attachid`), ) ENGINE=MyISAM The binary data has been saved in the filecontent column. I want to extract the files and text saved in this column and save it to a file on th...

Why are the parentheses so important when assigning this regex match?

I have a piece of code: $s = "<sekar kapoor>"; ($name) = $s =~ /<([\S\s]*)>/; print "$name\n"; # Output is 'sekar kapoor' If the parentheses are removed in the second line of code like this, in the variable $name: $name = $s =~ /<([\S\s]*)>/; # $name is now '1' I don't understand why it behaves like this. Can anyone...

Can I change lines of code in a loaded module in Perl?

When I use the FLV::Info module to extract metadata from or merge multiple FLV files, I frequently receive a "Tag size is too small" error and then the module will just refuse to work. Someone issued a bug report here three years ago but there does not seem to be a fix. Well, recently I find if I simply comment out the following lines o...

How to get nested directories contents in Perl

Hello all, i'm trying to write a script which would process certain files. The data are organized like this: there is a folder (let's call it X) where my script will be placed. In this same folder there is a subfolder called 'data'. This contains several more subfolders with various names and each of these contains many files (no other ...

Quickly filter a perl hash of hashes

I have a perl hash of hashes like the following: $VAR1 = { 'ID_1' => { 'FILE_B' => '/path/to/file/file1', 'FILE_C' => '/path/to/file/file2', 'FILE_A' => '/path/to/file/file3' }, 'ID_2' => { ...

Redirecting from one CGI page to another

I am a nembie to CGI with Perl, please do help me out and please do correct me wherever I have committed a mistake. This is the code. The problem is that after the password is validated and found as correct, instead of redirecting to the next page it is giving this message: Status: 302 Found Location: http://localhost/cgi-bin/Main.cgi ...

What is the purpose of the parentheses in Perl's `foreach` statement?

I always wonder why I must write foreach my $x (@arr) instead of foreach my $x @arr What is the purpose of the parentheses here? ...

Parsing XML file in Perl - Retain sequence

The XML Structure is as below: <Entities> <Entity> <EntityName>.... </EntityName> <EntityType>.... </EntityType> <Tables> <DataTables> <DataTable>1</DataTable> <DataTable>2</DataTable> <DataTable>3</DataTable> <DataTable>4</DataTable>...

How can I redirect the client from one CGI page to another using Perl?

My problem is the following. After the password is recognized as valid I need to redirect to main.cgi but I am getting the message as: Status: 302 Found Location: http://localhost/cgi-bin/Main.cgi I know the reason for this is that I am writing this statement after Content-Type so it is taking this as HTML and printing it on screen. I...

Match regex and assign results in single line of code

Hi, I want to be able to do a regex match on a variable and assign the results to the variable itself. What is the best way to do it? I want to essentially combine lines 2 and 3 in a single line of code: $variable = "some string"; $variable =~ /(find something).*/; $variable = $1; Is there a shorter/simpler way to do this? Am I missi...

Perl Module to get all pages of a website?

Is there a module out there that can give me links to all the pages a website has?? Why I need it: I want to crawl some sites and search for tags in them, searching only on mainpage is not enough. Thanks, ...