perl

How do I modify the destination MAC address in a packet?

I've a question related to a very basic thing in Perl, but I'm unable to find an efficient solution. Here's a bit of context first. I use Net::Pcap etc and when I'm in my function which processes packets (used by pcap_loop) I get a $packet scalar which contains my whole packet (ethernet header + ip header + tcp/udp header + payload). W...

How do I find if it is the last line while reading a file from within a loop in perl

I am working on a log parsing script using Perl. I am reading the log file as follows: open(LOGFILE, "$logFile") || die "Error opening log file $logFile\n"; while(<LOGFILE>) { #Processing statements goes here. } Now in processing statements I want to check if the file reading pointer is on the last line. if yes then wan...

How do I install Spreadsheet::WriteExcel on Windows with ActiveState Perl?

I have installed Perl version 5.6.1. But it doesn't support Date::Calc. So I installed 5.10.0. Now I am writing a program that writes data in Excel using Perl. For this, I have to use Spreadsheet::WriteExcel but Spreadsheet::WriteExcel was not installed when I installed ActiveState Perl. So now do I have to install another version of pe...

How can I customize tab completion in Perl's Term::Shell?

I am using Term::Shell package to implement a CLI tool. This package provides a API: comp_CMD. This function is invoked whenever the user presses the TAB. My requirement here is: shell> stackTAB over under `shell>stack overTAB flow sample junk But the default comp_CMD provides only one set of TAB options like shell> stack TAB ov...

How can I set the Cache-Control header for every response in Catalyst?

It seems that by default Catalyst does not output Cache-Control:, etc. headers. I know I can output them in a given controller method like this: $c->response->headers->last_modified(time); $c->response->headers->expires(time + $self->{cache_time}); $c->response->headers->header(cache_control => "public, max-age=$self->{cache_time}"); ...

How can I not send a cookie when I use the Cache-Control header in Catalyst?

I'm using sessions in my Catalyst app via Session, Session::Store::DBIC, and Session::State::Cookie. I have a few controllers and methods that send out data with a Cache-Control: public header, so its essential that the Set-Cookie: header not go out with those responses (otherwise, it'd be cached and sent to other clients, leading to p...

How do I check bug history on a module in the Perl core?

Quite recently, I asked a question about debugging a seg fault: What are some good methods or steps to debug a seg fault in Perl?. Somebody mentioned that Symbol had some deep XS magic in it. I'm wondering if I can find a bug history for a Perl core module. I tried looking on CPAN, but the change documentation is kept at the project le...

What is better in Perl: an array of hash references or list of "flat" hashes?

I cannot decide which approach is more (1) idiomatic Perl, (2) efficient, or (3) "clear". Let me explain by code. First, I can do sub something { ... $ref->{size} = 10; $ref->{name} = "Foo"; $ref->{volume} = 100; push (@references, $ref); ... return @references; } or, I can do sub something { ... push (@names, ...

How can I access the data in many large CSV files quickly from Perl?

I have a number of scripts that currently read in a lot of data from some .CSV files. For efficiency, I use the Text::CSV_XS module to read them in and then create a hash using one of the columns as an index. However, I have a lot of files and they are quite large. And each of the scripts needs to read in the data all over again. The q...

How can I serve unbuffered CGI content from Apache 2?

I would like to be able to allow a user to view the output of a long-running GCI script as it is generated rather than after the script is complete. However even when I explicitly flush STDOUT the server seems to wait for the script to complete before sending the response to the client. This is on a Linux server running Apache 2.2.9. ...

How can I integrate Moose into Komodo?

ActiveState's Komodo is my preferred Perl IDE on OS X and XP. Recently I've begun coding new projects using Moose. Has anyone found a way to teach Komodo how to "identify" Moose's Attribute and Method declarations? I would just love to see Moose-Support in the "Code Browser/Code Explorer" of Komodo. ...

How does Getopt::Std handle spaces in arguments on the command line?

Hi guys. I've been playing around with the Getopt::Std module and was wondering about arguments taking spaces. I have this code atm: getopts('dp:h', \%options); The problem is, that if the argument following the p flag contains a space, getopts stops processing the list right when it hits the space. Is there a way I can allow space...

Why doesn't my regular expression work with Perl's Switch module?

Hi, I wanted to use a switch statement. I ran into difficulties quickly. It looks like I was unlucky. I decided to use if else style instread of the switch. I wonder why this does not work. What about you? It looks like there is problem with /gc flags on the regular expression. use Switch; while ( pos($file) < length($file) ) { swit...

Perl: recomended method to plot(x,y) pixels to a monochrome bitmap

For a home project I need to plot (x,y) coordinates onto a 400x400 black and white-bitmap. What perl module would you recoment and what image format (GIF?, PNG? other?) would be easiest to handle on OS X, Windows, Linux? EDIT My solution, based on GD, as recomended by Brian Agnew use strict; use warnings; use GD; my $BitMap = GD:...

How do I get a list of all Unicode characters that have a given property?

Without looping over the entire range of Unicode characters, how can I get a list of characters that have a given property? In particular I want a list of all characters that are digits (i.e. those that match /\d/). I have looked at Unicode::UCD, and it is useful for determining the properties of a given character, but there doesn't se...

How to convert a Perl hash-of-hashes to a more flexible data structure?

In a quick-and-dirty Perl script, I have a data structure like this: $tax_revenue{YEAR}{STATE}{GOVLEV}{TAX} = integer The hash keys assume values like this: YEAR: 1900 .. 2000 STATE: AK, AL, ... WY GOVLEV: state, local TAX: type of tax (income, sales, etc.) In addition, the hash keys are unique. For example, no value for the TAX pa...

Why shouldn't I use shell tools in Perl code?

It is generally advised not to use additional linux tools in a Perl code; e.g if someone intends to print the last line of a text file he can: $last_line = `tail -1 $file` ; or otherwise, open the file and read it line by line open(INFO,$file); while(<INFO>) { $last_line = $_ if eof; } What are the pitfalls of using the pre...

Open source examples of well written SCM web interface in Perl

Can anyone point me to some good Open Source web interface for VCS (version control system) written in Perl? Something well written, so I can examine the code and steal the best parts (or organization) for gitweb. Preferably something without tons of external dependences not available in (extended) Perl core. ...

Filter C++ through a perl script?

I have a perl script I'd like to filter my cpp/h files through before gcc processes them normally -- basically as an extra preprocessing step. Is there an easy way to do this? I realize I can feed the cpp files to the script and have gcc read the output from stdin, but this doesn't help with the header files. ...

OpenOffice::OODoc stylize text within a paragraph

I have a simple task of adding a paragraph that has some formatted text within it. I cannot figure out how to stylize the text. Example output: John Smith 200 Main Street single my $doc = odfDocument(file=> 'outputfile.odt',create=> 'text'); $doc->appendParagraph(text => "John Smith 200 Main Street single", style => "optionalParag...