perl

Should one minify server code when it's in production?

Should one minify server code when it's in production? Question: When it comes to the frontend code you always minify it (remove white spaces, comments etc) in production. Should one do the same with server code? I usually have a lot of comments in my server files. But I have never heard about people doing …

Total answers: 4

How to match a substring in a string, ignoring case

How to match a substring in a string, ignoring case Question: I’m looking for ignore case string comparison in Python. I tried with: if line.find(‘mandy’) >= 0: but no success for ignore case. I need to find a set of words in a given text file. I am reading the file line by line. The …

Total answers: 10

How to reliably guess the encoding between MacRoman, CP1252, Latin1, UTF-8, and ASCII

How to reliably guess the encoding between MacRoman, CP1252, Latin1, UTF-8, and ASCII Question: At work it seems like no week ever passes without some encoding-related conniption, calamity, or catastrophe. The problem usually derives from programmers who think they can reliably process a “text” file without specifying the encoding. But you can’t. So it’s been …

Total answers: 8

What is the Perl version of a Python iterator?

What is the Perl version of a Python iterator? Question: I am learning Perl at my work and enjoying it. I usually do my work in Python but boss wants Perl. Most of the concepts in Python and Perl match nicely: Python dictionary=Perl hash; Python tuple=Perl list; Python list=Perl array; etc. Question: Is there a …

Total answers: 8

python equivalent to perl's qw()

python equivalent to perl's qw() Question: I do this a lot in Perl: printf “%8s %8s %8sn”, qw(date price ret); However, the best I can come up with in Python is print ‘%8s %8s %8s’ % (tuple(“date price ret”.split())) I’m just wondering if there is a more elegant way of doing it? I’m fine if …

Total answers: 3

How can I make Perl and Python print each line of the program being executed?

How can I make Perl and Python print each line of the program being executed? Question: I know that bash -x script.sh will execute script printing each line before actual execution. How to make Perl and Python interpreters do the same? Asked By: Vi. || Source Answers: Devel::Trace is the Perl analogue, the trace module …

Total answers: 3

Is there any use for Bash scripting anymore?

Is there any use for Bash scripting anymore? Question: I just finished my second year as a university CS student, so my “real-world” knowledge is lacking. I learned Java my first year, continued with Java and picked up C and simple Bash scripting my second. This summer I’m trying to learn Perl (God help me). …

Total answers: 18

In Python what's the best way to emulate Perl's __END__?

In Python what's the best way to emulate Perl's __END__? Question: Am I correct in thinking that that Python doesn’t have a direct equivalent for Perl’s __END__? print “Perl…n”; __END__ End of code. I can put anything I want here. One thought that occurred to me was to use a triple-quoted string. Is there a …

Total answers: 6

Python for a Perl programmer

Python for a Perl programmer Question: I am an experienced Perl developer with some degree of experience and/or familiarity with other languages (working experience with C/C++, school experience with Java and Scheme, and passing familiarity with many others). I might need to get some web work done in Python (most immediately, related to Google App …

Total answers: 7

How to efficiently calculate a running standard deviation

How to efficiently calculate a running standard deviation Question: I have an array of lists of numbers, e.g.: [0] (0.01, 0.01, 0.02, 0.04, 0.03) [1] (0.00, 0.02, 0.02, 0.03, 0.02) [2] (0.01, 0.02, 0.02, 0.03, 0.02) … [n] (0.01, 0.00, 0.01, 0.05, 0.03) I would like to efficiently calculate the mean and standard deviation at …

Total answers: 17