Questions tagged [perl]

Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports.

Filter by
Sorted by
Tagged with
6
votes
2answers
110 views

Foreach-loop for and print commands

How can I make the following code shorter or efficient (maybe with other loops or other nice ideas), and keep the current functionality? ...
6
votes
1answer
883 views

Convert a mediawiki to dokuwiki script

I have quickly wrote a Perl script to convert a mediawiki to a dokuwiki. I know there's an existing script to make that, but I would have a simpler usage code and some use of the API from mediawiki. ...
3
votes
1answer
87 views

Reading a config file

I am relatively new to Perl and would like to check that the code I am writing docent have any major flaws in it or any bad practices. This is a fairly simple sub but one that gets used often. Seems ...
3
votes
1answer
98 views

Performance optimization in function for datastructure mapping

I want to optimize a Perl function which is frequently used in my application. The function creates a special datastructure from the results of ...
3
votes
1answer
153 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 ...
21
votes
1answer
620 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' ...
10
votes
3answers
389 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 ...
38
votes
4answers
6k views

Rainfall challenge

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 ...
4
votes
1answer
72 views

Data structure to RDF

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
356 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
490 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. ...
5
votes
2answers
763 views

Reading CSV files pertaining to financial recorts

I have a number of text files (they are reports from a financial system) stored in a directory. Each report has a particular piece of text to search for (eg Report Total) and then a range of ...
3
votes
1answer
191 views

Parsing text from reports

I want to parse some reports from multiple devices, reports looks like this: ...
15
votes
3answers
296 views

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 ...
2
votes
3answers
781 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 “unnaturally”...
1
vote
1answer
982 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 ...
0
votes
1answer
176 views

Perl Hash mapping SVG elements to their attributes

Is there a more reliable way of building a hash of the attributes associated with each SVG element? ...
0
votes
1answer
151 views

Perl hash mapping SVG elements to content elements

Is there a more reliable way of getting the content elements for each SVG element? ...
0
votes
1answer
70 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 ...
1
vote
1answer
32 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. ...
1
vote
2answers
133 views

Searching for words in a dictionary

I'm using an open source program called MElt which lemmatize (give the lemma example:giving-->give) of words. MElt works on Linux and it's programmed in Perl and Python. So far it's working good but ...
2
votes
2answers
77 views

Filter by date method

This method 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: ...
3
votes
2answers
296 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
718 views

Simple text localization system

My first question relates to the first Python module that I published on Python. This is a very small and simple module, the package contains only one class. This is a port of a Perl module Locale::...
2
votes
2answers
130 views

Adding elements to a hash from an output

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 exists (in this case the interface name), it ...
0
votes
2answers
81 views

Structured instructions for simple extraction script

I have a rather simple task in trying to extract keywords from input.dat which looks like: ...
3
votes
1answer
241 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
87 views

Preparing search criteria and results to be e-mailed

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? ...
2
votes
2answers
591 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. ...
3
votes
1answer
5k 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. ...
0
votes
2answers
138 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 it ...
1
vote
1answer
1k 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 ...
4
votes
1answer
235 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 ...
2
votes
2answers
81 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
108 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; ...
2
votes
2answers
138 views

Adding an entry for a matched $module

What would be the most efficient way to write the following code in Perl: ...
1
vote
3answers
5k views

Perl script to rename files in a directory tree

I'm taking a scripting language course with no prior scripting language or Linux experience, though I've taken classes in VB, Java, and C++. Our first assignment is to write a script that will ...
5
votes
2answers
3k views

“Guess my Number” game

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 ...
2
votes
1answer
225 views

Code style: passing a reference to subroutine

Is the subroutine test1 ugly?/uglier than the others? ...
3
votes
2answers
70 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: ...
2
votes
1answer
117 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
231 views

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
360 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 ...
4
votes
1answer
184 views

Improved remake of the Linux 'ls' command

I have written a script, introduced here, that improves the Linux terminal experience. It basically displays the content of the terminals current folder in a nicer way than the 'ls' command does. I ...
2
votes
1answer
83 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 <...
-2
votes
1answer
2k 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
668 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 ...
1
vote
1answer
125 views

“Causes” Puzzle solution (network of words with Levenshtein distance 1)

The "Causes" puzzle is to recursively find, starting with the word "causes", the number of words that can be formed by substituting one letter. ...
3
votes
2answers
1k 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. ...
1
vote
1answer
675 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 ...