perl

Executing zgrep recursively in Linux

This zgrep command is outputting a particular field of a line containing the word yellow when given a giant input log file for all 24 hours of 26th Feb 1989. zgrep 'yellow' /color_logs/1989/02/26/*/1989-02-26-00_* | cut -f3 -d'+' 1) I prefer using a perl script. Are there advantages of using a bash script? Also when writing this sc...

How can I mock Moose objects?

What strategies have Perl people used when mocking Moose objects that they will inject into other Moose objects as type-constrained attributes? Test::MockObject::Extends doesn't seem to play well with Moose. I need the object to blessed as a specific package though so a vanilla Test::MockObject won't work. I'm sure other folks have had ...

How do I change the record separator in a text file?

I'm trying to read in a file with names and addreses. It may look like this: John Doe 123 Main Street My Town, US 12345 Ralph Kramden c/o Joe 999 North Lane YourTown, US 22839 Where there is always a line between records. But I don't know how to tell Perl that the next X lines are all one record. (And X can vary). How can that be...

For a C++/Java Programmer, what scripting language should I learn first?

Background: Standard RIT computer engineering student. Took computer science courses (Java, then C++). I spend a lot of time on tech sites, so I constantly hear about scripting languages like Python, Perl, and Ruby. Besides them being scripting languages, I basically don't know anything else about them. I have a lot of experience in...

How do I find a date which is three days earlier than a given date in Perl?

How do I find a date which is 3 days earlier than a given date in Perl where the format is YYYY-MM-DD? ...

How do I use Perl modules from their distribution directory?

Assume I downloaded Date::Calc from http://guest.engelschall.com/~sb/download/. Now, I have a script, xxx.pl, which resides in the same directory as the untar-ed "thing" that I downloaded from the link above When untar-ed, it creates a "Date-Calc-5.6" folder with tons of stuff. How do I include Date::Calc in xxx.pl? (I keep getting "Ca...

Can someone suggest how this Perl script works?

I have to maintain the following Perl script: #!/usr/bin/perl -w die "Usage: $0 <file1> <file2>\n" unless scalar(@ARGV)>1; undef $/; my @f1 = split(/(?=(?:SERIAL NUMBER:\s+\d+))/, <>); my @f2 = split(/(?=(?:SERIAL NUMBER:\s+\d+))/, <>); die "Error: file1 has $#f1 serials, file2 has $#f2\n" if ($#f1 != $#f2); foreach my $g (0 .. $#f1...

How can I set options with variables in GD::Graph?

Hi, I am creating graphs using GD::Graph::lines. For option set, I have to write fixed values for options e.g. x_label => "label" as per below code: my $mygraph = GD::Graph::lines->new($x, $y); $mygraph->set( x_label => 'label1', y_label => 'label2', title => 'title', line_types => [1, 1, 1, 1], line...

I do replace literal \xNN with their character in Perl?

I have a Perl script that takes text values from a MySQL table and writes it to a text file. The problem is, when I open the text file for viewing I am getting a lot of hex characters like \x92 and \x93 which stands for single and double quotes, I guess. I am using DBI->quote function to escape the special chars before writing the value...

How can I use Expect to enter a password for a Perl script?

I wish to automatically enter a password while running an install script. I have invoked the install script using the backticks in Perl. Now my issue is how do I enter that password using expect or something else? my $op = `install.sh -f my_conf -p my_ip -s my_server`; When the above is executed, a password line is printed: Enter pas...

Why does installing certain CPAN modules require root privilege?

I need to install some CPAN modules in a linux box which I do not have the root privilege. The installation of Spreadsheet::WriteExcel goes quite smoothly. But the try to install File::Find::Rule failed with warning "you do not have permissions to install into ....." and hint "you may have to su to root to install the package" I'm pu...

Is there an OO Perl equivalent to an interface?

I know with OO Perl I can have objects and inheritance, but are interfaces implemented? If so, how are they enforced? ...

how to perform mathematical operations on Array of Arrays?

I have an array of array like below with all numeric values. I want to perform some mathematical operations with these values. 1) Add and print the values of each array elements. e.g. sum $VAR1 = sum1 sum $VAR2 = sum2 2) Add all the values from each variables. e.g. sum $VAR1 + $VAR2 +...+ $VARn = totalsum 3) Finding percentage of ...

What does colon mean in Perl?

What does the colon mean in the following Perl program? MAIN: { print "Hello\n"; } ...

How can I generate a set of ranges from the first letters of a list of words in Perl?

I'm not sure exactly how to explain this, so I'll just start with an example. Given the following data: Apple Apricot Blackberry Blueberry Cherry Crabapple Cranberry Elderberry Grapefruit Grapes Kiwi Mulberry Nectarine Pawpaw Peach Pear Plum Raspberry Rhubarb Strawberry I want to generate an index based on the first letter of my data...

How can I modify an existing Excel workbook with Perl?

With Spreadsheet::WriteExcel, I can create a new workbook, but what if I want to open an existing book and modify certain columns? How would I accomplish that? I could parse all of the data out of the sheet using Spreadsheet::ParseExcel then write it back with new values in certain rows/columns using Spreadsheet::WriteExcel, however. Is...

Is there a jUnit for Perl?

I've created some business classes using OO Perl and I want to make sure I don't break them when I change the code. Sounds like unit testing is the way to go. Is there anything like jUnit for Perl? Feel free to elaborate on how you've implemented unit testing in Perl projects. ...

How do I extract a date range from a csv using perl/php/grep/etc?

Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? date,test,time,avail 2009-09-01,JS,0.119,99....

How do I include one AGI file in another AGI file?

Hello, Is it possible to include an AGI file in another one and call functions from it which execute as part of the AGI file it is being called from? If yes, how to include one AGI in another? Thank You. ...

How can I read an unsigned int from a binary file in Perl?

Lets say I have a binary file that is formatted like [unsigned int(length of text)][text][unsigned int(length of text)][text][unsigned int(length of text)][text] and that pattern for the file just keeps repeating. How in Perl do I read the unsigned int and print it out followed by the text block? Again, this is a binary file and not ...