perl

How can I test that a Perl program compiles from my test suite?

I'm building a regression system (not unit testing) for some Perl scripts. A core component of the system is `perl script.pl @params 1>stdoutfile 2>stderrfile`; However, in the course of actually working on the scripts, they sometimes don't compile(Shock!). But perl itself will execute correctly. However, I don't know how to detect...

How do I access captured substrings after a successful regex match in Perl?

I am searching for a string in Perl and storing it in another scalar variable. I want to print this scalar variable. The code below doesn't seem to work. I am not sure what is going wrong and what is the right way to go about it. Why is it printing '1' when it doesn't exist in the program? Data it is running on DATA 13 E 0.496 ...

How can I randomly sample the contents of a file?

I have a file with contents abc def high lmn ... ... There are more than 2 million lines in the files. I want to randomly sample lines from the files and output 50K lines. Any thoughts on how to approach this problem? I was thinking along the lines of Perl and its rand function (Or a handy shell command would be neat). Related (Poss...

Is my use of XMLin killing my remote Asterisk AGI script?

Hi, I'm facing a strange problem while using XML::Simple module of Perl. I am writing an Asterisk AGI script in Perl where I am calling a function someSub() which uses curl to fetch XML from a CGI page into a variable $xmlstream. I then use XMLin on $xmlstream. The code is something as shown below: $xmlstream = someSub() ; #uses curl...

How do I handle embedded newlines in CSV files in Perl?

I'm reading a .csv file that was created in Excel with the first line being column headings. One column heading contains an embedded newline. I want to ignore that newline but reading it line-by-line like: while ( <IN> ) { ... } will treat it as a new line which will break my code (which I haven't written yet). My approach wa...

What does $1 mean in Perl?

What does $1 mean in Perl? Further, what does $2 mean? How many $number variables are there? ...

How do I use boolean variables in Perl?

I have tried: $var = false; $var = FALSE; $var = False; None of these work. I get the error message Bareword "false" not allowed while "strict subs" is in use. ...

Is there is a way to change a Windows folder icon using a Perl script?

Is there is a way to change a Windows folder icon using a Perl script? My intention is to change the ordinary icon of the "xxx_documents" folder to some other icon. I have to run the script in such a way that it takes care for the whole drive. The drive contains many folders. I have to search for each folder named "documents" (e.g. "xx...

What common programming mistakes should Perl developers avoid?

What are some common mistakes made by Perl developers, and how can we avoid them? Please look in to the list before posting a new answer. Please justify your answer as well, if applicable, and give examples. ...

How do I create a Perl class?

I am writing Perl classes to remove redundancies from scripts and since Perl has a lot of ways to make classes I keep having trouble making the classes properly. So does anyone have a best practice example of a class? The biggest question I have is if there should be no global variables in a module how do you use variables across sub() ...

Why doesn't my string equality test for a single character work?

How does one compare single character strings in Perl? Right now, I'm tryin to use "eq": print "Word: " . $_[0] . "\n"; print "N for noun, V for verb, and any other key if the word falls into neither category.\n"; $category = <STDIN>; print "category is...." . $category . "\n"; if ($category eq "N") { print "N\n"; push (@nouns...

How to open multiple folders and compare the files in Perl?

I have a parent_folder_1 and many sub folders inside that. I also have parent_folder_2 and many sub folders inside that. Sub folders contains .d files. I have to get the number of parent_folders that the user wants to compare. For example: "How many parent_folders do you want to compare?" If the user inputs 4, then the script s...

Is multiple inheritance in Perl and Java the same?

Is the multiple inheritance in Java and Perl the same? ...

What are some good Perl debugging methods?

Are there any other ways for debugging Perl apart from Data::Dumper and perl -d? ...

Does DDD support Perl?

Can DDD (Data Display Debugger) be used for Perl data structures? ...

How can I calculate the MD5 hash of a wav file in Perl?

I have a wav file and I need to calculate the MD5 hash of its contents. How can i do that using Perl? ...

How can I programmatically open and save a PowerPoint presentation as HTML/JPEG in C# or Perl?

I am looking for a code snippet that does just this, preferably in C# or even Perl. I hope this not a big task ;) ...

Recursively printing data structures in Perl

I am currently learning Perl. I have Perl hash that contains references to hashes and arrays. The hashes and arrays may in turn contain references to other hashes/arrays. I wrote a subroutine to parse the hash recursively and print them with proper indentation. Though the routine works as expected, my instructor was not convinced about...

What's the fastest way to check if a web site is up in Perl or C?

Hello all, I'm trying to check if a web site is up and running. I'm currently doing this with UserAgent library in Perl with timeout 1. However, it is still too slow for me. I call the script every five minutes from cron. There are lots of links to check and the script takes more than five minutes to complete execution. So, I need a mo...

How can I write a Perl subroutine that works both as a normal subroutine or a class method?

I'm writing a function that is mostly static in nature. I want to plug it into Template Toolkit, which passes along the class name. In essential, it is doing ClassName->function( $args.. ) but I want it to do something like ClassName::function( $args.. ) inside sub function { } what is the proper way to handle both cases? ...