perl

Find method to store an IP in MySQL for better performance

Find method to store an IP in MySQL for better performance Question: We’ve got a healthy debate going on in the office this week. We’re creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 …

Total answers: 7

Is there a Perl equivalent to Python's `if __name__ == '__main__'`?

Is there a Perl equivalent to Python's `if __name__ == '__main__'`? Question: Is there a way to determine if the current file is the one being executed in Perl source? In Python we do this with the following construct: if __name__ == ‘__main__’: # This file is being executed. raise NotImplementedError I can hack something …

Total answers: 3

How can I remove text within parentheses with a regex?

How can I remove text within parentheses with a regex? Question: I’m trying to handle a bunch of files, and I need to alter then to remove extraneous information in the filenames; notably, I’m trying to remove text inside parentheses. For example: filename = “Example_file_(extra_descriptor).ext” and I want to regex a whole bunch of files …

Total answers: 9

Is there a need for a "use strict" Python compiler?

Is there a need for a "use strict" Python compiler? Question: There exist static analysis tools for Python, but compile time checks tend to be diametrically opposed to the run-time binding philosophy that Python embraces. It’s possible to wrap the standard Python interpreter with a static analysis tool to enforce some “use strict“-like constraints, but …

Total answers: 10

Character Translation using Python (like the tr command)

Character Translation using Python (like the tr command) Question: Is there a way to do character translation / transliteration (kind of like the tr command) using Python? Some examples in Perl would be: my $string = "some fields"; $string =~ tr/dies/eaid/; print $string; # domi failed $string = ‘the cat sat on the mat.’; $string …

Total answers: 6

Is there a Term::ANSIScreen equivalent for Python?

Is there a Term::ANSIScreen equivalent for Python? Question: Perl has the excellent module Term::ANSIScreen for doing all sorts of fancy cursor movement and terminal color control. I’d like to reimplement a program that’s currently in Perl in Python instead, but the terminal ANSI colors are key to its function. Is anyone aware of an equivalent? …

Total answers: 4

For Python programmers, is there anything equivalent to Perl's CPAN?

For Python programmers, is there anything equivalent to Perl's CPAN? Question: I’m learning Python now because of the Django framework. I have been a Perl programmer for a number of years and I’m so used to Perl’s tools. One of the things that I really miss is Perl’s CPAN and its tools. Is there anything …

Total answers: 3

What are the differences between Perl, Python, AWK and sed?

What are the differences between Perl, Python, AWK and sed? Question: What are the main differences among them? And in which typical scenarios is it better to use each language? Asked By: Khaled Al Hourani || Source Answers: I wouldn’t call sed a fully-fledged programming language, it is a stream editor with language constructs aimed …

Total answers: 5

Can I use named groups in a Perl regex to get the results in a hash?

Can I use named groups in a Perl regex to get the results in a hash? Question: Is it possible to perform a named-group match in Perl’s regex syntax as with Python’s? I always bind the $n values to proper names after matching, so I’d find it more convenient to do it in the regex …

Total answers: 5

How do you translate this regular-expression idiom from Perl into Python?

How do you translate this regular-expression idiom from Perl into Python? Question: I switched from Perl to Python about a year ago and haven’t looked back. There is only one idiom that I’ve ever found I can do more easily in Perl than in Python: if ($var =~ /foo(.+)/) { # do something with $1 …

Total answers: 15