Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports.
3
votes
1answer
19 views
Parsing psql output into multiple files
I wrote the following simple Perl script to read lines from stdin that are the output from a psql call that returns lines of the form key1 | key2 | long text field and create a separate output file ...
7
votes
0answers
25 views
Regular backup/snapshots
A (long) while ago I set up a file server in my basement running Linux. I am OCD when it comes to backups.
I set the server up with (remember, this was a while ago):
disk for OS
disk for 'valuable' ...
7
votes
3answers
150 views
Bowling calculator in Perl
A bowling score calculator is my go-to exercise for learning the basics of a language. I recently had to pick up Perl so I did this.
I'm concerned that I'm doing subroutines wrong. I had a hard time ...
13
votes
3answers
309 views
Rainfall Problem
About a year ago when I was applying to jobs for the first time, I had an interview at a company and they posed the following problem to me, which I preceded to bomb.
A year later I actually came up ...
3
votes
1answer
36 views
Data structure to RDF (Perl)
I believe any data structure can be converted to RDF, and I wrote the
subroutine below which sort of does this, at least for arbitrarily
complex hashes.
However, I'm unhappy with it because:
...
1
vote
1answer
52 views
TCPDUMP file (part of a real capture)
I have been working on this code for quite a while and just want to make sure it is up to good standards. I know many of you will have questions, so as they come up, I will edit my initial question to ...
4
votes
1answer
50 views
Find common preamble of a list of strings
Think of a set of text lines starting with a common string, e.g. indented code.
my $preamble = reduce {
my $len = min(length $a, length $b);
--$len while substr($a, 0, $len) ne substr($b, 0, ...
3
votes
2answers
95 views
Perl Code Improvements - reading CSV file
I am very new to Perl, but quite pleased with my short introduction to it!
So, scenario is I have a number of text files (they are reports from a financial system) stored in a directory. Each report ...
2
votes
1answer
85 views
Parsing text from reports
I want to parse some reports from multiple devices, reports looks like this:
VR Destination Mac Age Static VLAN VID Port
VR-Default 192.168.11.13 ...
7
votes
2answers
108 views
Is the following a good C program for launching an interpreted script?
I was just wondering if this is a good example, following good practices, of a C program for launching an interpreted script from a native binary executable. Here the interpreter is Perl and the ...
1
vote
2answers
97 views
How do you “sordid sort” alphanumeric strings?
The question is about sorting alphanumeric string in a "more natural" order. Source: Marc LeBrun's "Sordid Sort" Computist Quiz
Often a system string comparison sorts alphanumeric data ...
1
vote
1answer
243 views
More elegant way to get timestamp from day/hour? (Perl)
http://coolwx.com/buoydata/data/curr/all.html provides weather data
from ships (or maybe buoys) at sea, but the date is given as "25/18" (meaning the 18th
hour of the 25th day of the month, all ...
-1
votes
1answer
63 views
Extract SVG attribute properties [duplicate]
Can this code to parse the definitions of attributes of SVG elements be simplified within the constraints that this has to be a Perl/Windows/ActiveState solution?
...
0
votes
1answer
34 views
Perl Hash mapping SVG elements to their attributes [duplicate]
Is there a more reliable way of building a hash of the attributes associated with each SVG element?
#-----------------------------------------------------------------------
# Hash of SVG ...
0
votes
1answer
58 views
Perl hash mapping SVG elements to content elements
Is there a more reliable way of getting the content elements for each SVG element?
#-----------------------------------------------------------------------
# Get Element content from SVG ...
0
votes
1answer
48 views
Complex structure vs object
This is not, strictly speaking, code review, but I think my question can be asked here.
This is a request to find out what seems to be the cleanest. This project is a blog engine that uses the file ...
0
votes
1answer
24 views
Highlight a pattern found
I made a small web application with a search box. I wanted to highlight the words found in the search.
foreach my $article (@{$search_articles}) {
my @result;
foreach my $word (split(' ', ...
1
vote
2answers
97 views
Optimization of a while-loop searching for words in a dictionary
This is my first question here. I'm using an open source program called MElt which lemmatize (give the lemma example:giving-->give) of words. MElt works on Linux and its programmed in Perl and ...
1
vote
2answers
41 views
Review a filter by date method
Method that allows me to filter by date a data structure list of hash that contains articles. I would like to have your opinion on the code:
=method article_by_date
...
0
votes
0answers
56 views
Design object Perl
It is a small backend blog engine that uses the file system as a storage. But I have some ideas to improve things a bit, I'll add support for git and another thing. But I'd like to have an opinion in ...
3
votes
2answers
125 views
Perl script for generating iTunes xml Metadata for MP3 CDs/DVDs
Many years ago, I wrote a script in Perl that was meant to create a cached metadata of MP3 files (in Apple's plist/XML format) which iTunes uses when you insert a CD/DVD full of MP3 files (the same ...
7
votes
1answer
149 views
Review a Python module i18n
To start, I am a developer Perl and Python. I am passionate and I love to write code. I discovered this site through stackoverflow and I think it's great. I love the code review, peer programming, ...
2
votes
2answers
72 views
Advice on refactoring my Perl code
How should a refactor the script I’m writing?
The script currently loops through an output line by line picking out elements of interest and adds them to a hash data structure. If a key already ...
0
votes
3answers
59 views
Structured instructions for simple extraction script
I have a rather simple task in trying to extract keywords from input.dat which looks like:
func1
{
yes true;
keyword123 (1.1 0 -0.3);
gamma (0 1 0);
dir ...
1
vote
3answers
78 views
How to improve the computation speed of my shell script/program?
I have written a shell script to process my huge data files (each one having around 7,000,000 lines ~ a weeks data in a single file). Below is the sample of my data file (i.e., input file) structure:
...
2
votes
1answer
88 views
Perl script to rename multiple files with vi(m)
I'm new to Perl, learning on my own. I've wrote many scripts (utilities) for myself but never posted them online. I would really appreciate any feedback on this script before I post it on a forum.
...
0
votes
2answers
68 views
Method refactoring in perl
I'm getting data to fill out an e-mail template, and I'm wondering if this method is too long. How could I refactor it?
sub getEmailData
{
my $self = shift;
my $defs = ...
2
votes
2answers
99 views
Perl mutiple children creation
My program will fork, launching $n children. When a child finishes, the parent will launch a new one, if we have more to launch.
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
...
0
votes
1answer
97 views
Search and replace on command line [closed]
Is there a tighter (less characters) way to use perl on the command line to search and replace text from STDIN than I've got here? The code below works.
echo hi | perl -e '$a = <STDIN>; $a =~ ...
0
votes
2answers
94 views
Comparing two arrrays
I have two arrays:
first one is ip addresses from billing for blocking
second is ip addresses from firewall - already blocked
My task is, compare it, and if ip address new in billing list - block ...
1
vote
1answer
387 views
SpamAssassin spam analyzer script in PHP based on sa-learn command
I wrote a small script to analyse spam messages that are spam false negative; meaning that they are spam messages in nature but that happened to be in your INBOX folder because your spam filter failed ...
3
votes
1answer
50 views
What changes, if any, are required to make the following Perl eval bullet proof?
eval {
# here is put some code that may throw exception
1; # Why is the "1;" here ?
} or do {
my $error = $@;
# Handle error.
};
Does the following style protect against $@ not being ...
2
votes
2answers
67 views
Trying to improve a working regex
I am extracting data from a text file. Some of the lines from which I want to extract the data consist of a text description with single spaces, followed by a multiple-space gap preceding four fields ...
1
vote
1answer
76 views
clean way to make array a 2d array
Looking for a cleaner (possibly one liner) way to write the following
my $spec_2d = ( );
foreach ( @spec ) {
$spec_2d[$_][0] = $spec[$_];
}
@spec = @spec_2d;
Basically I'm making an array an ...
0
votes
2answers
80 views
Cleaner way to write the following
What would be the most efficient way to write the following code in Perl:
my $index = 0;
foreach ( @spec ) {
if ( $module =~ m/$_/ ) {
splice(@spec, $index, 0, ...
0
votes
2answers
636 views
Perl script to rename files in a directory tree (Beginner looking for code review)
I'm taking a scipting language course with no prior scipting language or linux experience, though I've taken classes in VB, Java, and C++. Our first assignment is to write a script that will traverse ...
8
votes
1answer
281 views
I think my company are using an Antipattern. Can you help me identify it please?
I work in a Perl development team with 30 of my peers split across 7 or 8 Agile development teams. We employ code reviews as so forth but recently a weird new design pattern I'm going to refer to as ...
5
votes
2answers
204 views
Guess my Number in Perl
I have recently just started learning Perl, so I decided to program the classic 'Guess my Number' game. I was wondering if anyone can spot any areas for improvement, as it's my first program, I expect ...
2
votes
1answer
85 views
Code style: passing a reference to subroutine
Is the subroutine test1 ugly?/uglier than the others?
#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.1;
use Data::Dumper;
my $ref = { one => 1, two => 2, three => 3 };
sub test1 {
...
2
votes
2answers
57 views
Reading fields idiomatically
This technique is more general than just for config files which is why I'm not using Config::Any in this example.
I have a config file with lines like this:
userid foo-admin # foo-comment
directory ...
1
vote
1answer
77 views
Perl project review - Word counter
I wrote this perl script that analizes a text and plot out a bar graph of the word occurrences during the text.
Since come mainly from Javascript and PHP, i would like to know how bad is this code ...
3
votes
1answer
87 views
Feedback on my Perl wrapper library (written using Moose) for a REST API
I wrote a wrapper library for a REST API (https://semantics3.com) in perl using the Moose library. I would like to gather some feedback on it (mainly on the oop part since I am new to moose), before ...
1
vote
1answer
159 views
Perl CGI script to respond to erroneous Base64 image requests
I often get lines like this in my Apache error log:
File does not exist: /path/to/www/data:image/gif;base64,R0lGODlhBgAGAIAOAP/yH5BAEACAEALAAAAAAGGAYAAAIJhB0Xi5vOoFwFADs=
Obviously, this is due to ...
2
votes
1answer
113 views
Ls improved, constructive criticism
I have written a script that improves the Linux terminal experience.
This script is introduced here: http://hermannn.com/programs/aa/.
It basically displays the content of the terminals current ...
1
vote
1answer
68 views
Markdown.pl extending
I'm not used with perl but had the need to add a couple of features, I wish I can adopt a more perl-ish coding.
Any help is welcome.
This is to add style classes to paragraphs if strarting with !, ...
-1
votes
1answer
681 views
CSV parsing in Perl
I am looking for a Perl (5.8.8) script for CSV parsing that would follow CVS standards.
(See Wikipedia or RFC-4180 for details)
Sure, code should be fast enough, but more important is that it should ...
3
votes
2answers
297 views
Improving python3 processing speed (against a reference perl script)
In order to create fast map/reduce processor for hadoop, I'm evaluating many languages. I'm learning python so I would like my python processor to go as fast as my perl processor.
So, for this ...
0
votes
1answer
94 views
Causes Puzzle Solution: Improvements needed
sub addMember {
my ( $self, $newMember ) = @_;
my $len = length($newMember->{'_data'});
my $newMemberIndex = push(@{$self->{'_MemberList'}}, $newMember) - 1;
...
3
votes
2answers
481 views
parsing a flat file and removing duplicates
Have some code that I wrote to parse a flat file of IP address and other junk unwanted information. Just wanting to see if there was any way to make shorter or better.
#!/usr/bin/perl
use strict;
...
0
votes
1answer
206 views
extract href from html
I am building a Perl module which I am attempting to use as few non-core dependencies as possible. Should my following code fail, I would add a dependency on HTML::LinkExtor and be done with it, but I ...