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 ...
11
votes
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 ...
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 ...
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....
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;
...
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 ...
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
...
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 ...
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 ...
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 ...
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.
...
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 ...
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
...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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" (...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
perl × 228regex × 32
performance × 26
beginner × 21
parsing × 17
file-system × 16
bash × 10
csv × 10
algorithm × 9
linux × 9
file × 8
strings × 7
bioinformatics × 7
multithreading × 6
datetime × 6
security × 5
xml × 5
unix × 5
programming-challenge × 4
recursion × 4
networking × 4
email × 4
git × 4
status-monitoring × 4
python × 3