Skip to main content
31 votes

Perl CGI script to serve a PDF file

I will go through your code line by line and give feedback. We will skip the general advice on don't use CGI as it's actually suited for what you are trying to do here. I wrote this answer in two ...
simbabque's user avatar
  • 1,033
11 votes

Perl CGI script to serve a PDF file

...
choroba's user avatar
  • 1,413
11 votes

Simple C transpiler

Making shebang line more portable Fixing the perl binary to /usr/bin/perl in the shebang will not work if you are using ...
Håkon Hægland's user avatar
10 votes
Accepted

Letter frequency analysis (Breaking Vigenere)

use File::Slurp; File::Slurp is considered broken by a lot of people. A good alternative is Path::Tiny. It's also good practice to import only what you need when ...
simbabque's user avatar
  • 1,033
9 votes
Accepted

Remove duplicate lines without sorting or removing empty lines

Why not just print if /^\s*$/ || ! $SEEN{$_}++ I don't see the point of nesting here. You want to print if the line is empty or if it has not been seen previously....
mdfst13's user avatar
  • 22.4k
8 votes
Accepted

Becoming a Perl bandit

This answer is going to talk about your style, and best practices. Some of it may be subjective. I'll go through the code line by line. use strict; use warnings; ...
simbabque's user avatar
  • 1,033
8 votes

Perl CGI script to serve a PDF file

Your param('f') is user-provided and may therefore open up security concerns. In particular, it may be used to navigate to ...
amon's user avatar
  • 12.7k
8 votes
Accepted

Parallel processing in different directories in Perl

I'll do a first pass where I point out syntax and Perl conventions, mostly line by line. I will then talk about alternative strategies to make it more efficient and maintainable. Syntax ...
simbabque's user avatar
  • 1,033
8 votes
Accepted

Count line of code for a JavaScript project

fileExt="*.js" allFiles=$(find ./ -name $fileExt) This is a bug. The wildcard in $fileExt will be expanded by the shell, and ...
Oh My Goodness's user avatar
8 votes
Accepted

Perl - Splitting a string

- Use the strict and warnings pragmas This helps catch many errors at an early stage. - Declare lexical variables with ...
Håkon Hægland's user avatar
7 votes
Accepted

Removing empty lines from a file

Don't indent the open line differently to the surrounding lines. Always check the result of open, or use autodie. Why do you ...
choroba's user avatar
  • 1,413
7 votes
Accepted

Perl script to set IP settings

There's no need to predeclare the subs (sub whatever;). There's no need to assign the initial values to %resulthash. ...
choroba's user avatar
  • 1,413
7 votes
Accepted

Highly nested bioinformatics processing

Non-code / very-high-level considerations. The first thing you can do to speed up the performance would be to get a better computer. My computer is several years old, but it runs the unmodified code ...
Peter Taylor's user avatar
  • 24.5k
7 votes
Accepted

Perl one-liner for parsing host names from ssh config file

I would use something like perl -lane '@h{@F[1..$#F]}=()if/^Host\b/;END{$,=" ";print keys %h}' -- file or ...
choroba's user avatar
  • 1,413
7 votes
Accepted

This perl script renames all files in a directory to have an equal amount of digits

As you suspect, this can be done in fewer lines, but it's not a one-liner. use strict; use warnings; use diagnostics; Always a good idea. Consider ...
Oh My Goodness's user avatar
7 votes

Simple C transpiler

Along with the excellent answer of Håkon Hægland, Use perl's quoted regexes to simplify your code and improve readability massively. ...
DeathIncarnate's user avatar
6 votes
Accepted

Convert British and Irish National Grid references to or from WGS84 geodetic coordinates

NB: This review assumes Perl5, specifically the Unicode features in 5.12 (released 2010) and later. 1. the parsing could be simpler and more featureful Much code is devoted to handling delimiters ...
Oh My Goodness's user avatar
6 votes

Count line of code for a JavaScript project

General Run shellcheck on this script - almost all variable expansions are unquoted, but need to be quoted. That will also highlight the non-portable ...
Toby Speight's user avatar
  • 88.4k
6 votes
Accepted

Parse data from Input file and print results

The code looks fine and it is working for the given input data. However, it can be difficult to assess which inputs will be regarded as valid, and how it will behave in case of unexpected input. One ...
Håkon Hægland's user avatar
6 votes
Accepted

Python Package Index recursive package dependency resolver

The layout of the code is very good, with nice use of vertical whitespace and consistent indentation. It also makes good use of comments. It is great that you used ...
toolic's user avatar
  • 15.9k
6 votes
Accepted

A file renamer in Perl that gets rid of spaces, commas, dots, and dashes

You have done an excellent job of using good coding style: good layout, good use of subroutines and good leveraging of other's code (modules). It is great that you used ...
toolic's user avatar
  • 15.9k
5 votes

Remotely collect server data using Net::OpenSSH

Looks good to me. Kudos for the "... or die" idiom. More informative output would be "unable to run df on $s" or "unable to run svmon on $s". You don't have to do ...
J_H's user avatar
  • 42.3k
5 votes

Find common preamble of a list of strings

For me, a better approach often means finding out if there's an existing module that does what I need so I don't have to reinvent the wheel. And, indeed, looking on CPAN, I found ...
Shawn's user avatar
  • 431
5 votes

Removing empty lines from a file

Your program is a decent attempt to remove empty lines, and for sure, it works, but, how could it be better? (The StackOverflow folk are right, a review could help). First up, the ...
rolfl's user avatar
  • 98.2k
5 votes

Executable wrapper around Perl script on Windows

Disclaimer It isn't clear to me what part you want reviews to focus on. I'm not a C++ on Windows person so I can't say much about that part of things. Your C++ is nicely formatted. The ...
chicks's user avatar
  • 2,889
5 votes
Accepted

Executable wrapper around Perl script on Windows

C++ Globally, your C++ seems good enough. In argvw_of_cmdline you don't have to wrap your second part in a else since you return ...
Calak's user avatar
  • 2,411
5 votes
Accepted

Extract strings from nested array in Perl

Your concept of "string" seems incomplete. I would look to firm up that definition and precisely match the need. Is "" a string? Do you want "valid identifiers" (...
Oh My Goodness's user avatar
5 votes

Get specific lines from a huge text file

I know this might be a one time task, however, if you want to create a reusable code, I would always put the line counting code in a "continue" block. It is more readable and safer for future ...
Ronen Moldovan's user avatar
5 votes

ds - directory switcher - a *nix command line utility for tagging the directories and switching between them via tags (Perl + bash)

This will focus on your Perl code. I agree with the Perl assessment in the answer posted previously. Very well done indeed. Command line I see that you created your own command line parser. You ...
toolic's user avatar
  • 15.9k
5 votes

Bash/perl function to search `lsblk` for drives whose partitions all match a filter

Given that the majority of this is Perl, it's probably worth using Perl as the main interpreter and using that to invoke lsblk directly. Alternatively, use shell ...
Toby Speight's user avatar
  • 88.4k

Only top scored, non community-wiki answers of a minimum length are eligible