(07-08-2015 06:50 PM)Paul Berger (Canada) Wrote: [ -> ]Part of my job involves extracting information from massive log files, and I can't think of anything better than PERL for a job like that
This can be done very elegantly with Python using generators as a pipeline:
Generator Tricks for Systems Programmers
Presentation Slides (PDF)
Cheers
Thomas
(07-08-2015 06:50 PM)Paul Berger (Canada) Wrote: [ -> ]Part of my job involves extracting information from massive log files, and I can't think of anything better than PERL for a job like that, and because it is interpreted, you can get instant feedback to see if your script works or not, without having to go though a compile and link cycle.
It sounds like Forth; but Forth is compiled and still you can add as little as a single line (or a portion of a line) to the already compiled portion and watch it work immediately, without having to re-compile and link the rest.
(07-08-2015 05:19 PM)Thomas Klemm Wrote: [ -> ] (07-08-2015 04:11 PM)emece67 Wrote: [ -> ](& I hate Perl)
Two books I can recommend:
Modern Perl
Higher-Order Perl
Kind regards
Thomas
Thanks Thomas. In fact I decided to learn Perl prior to Python, but after a few weeks tinkering with the Llama/Camel O'Reilly books I switched to Python and I guess it will be difficult for me to switch back, but I'll keep your advise at hand.
I feel really comfortable with Python, a feeling I never reached with Perl. And I cannot think of a problem where Perl may be notoriously preferable over Python.
(07-08-2015 04:11 PM)emece67 Wrote: [ -> ](& I hate Perl)
Personally, I hate Pascal. I implemented a market research survey cross-tabulation program in it, back in 1982, and it nearly drove me insane, so damned awkward was it for handling sane input processing and validation. I subsequently had people point out extensions that made this easier in Turbo Pascal - but that implementation had so many extensions, most of them contrary to the original strict and minimalist spirit of the language, that it really shouldn't have been called Pascal at all..
Perl is at the opposite extreme. I built a retail POS and perpetual inventory system in Perl, with MySQL as the database, and it went together really smoothly. The client loves it and is still using it, with no modifications, 15 years on. Which is just as well, because when I look at the code - especially the regexes - I wonder what on earth it does.
These days, Python has pretty much supplanted Perl, at least in my own work. It's the language of choice in the machine learning world, and the addition of Numpy and Scipy make it a strong contender for a lot of scientific/engineering work these days. When my calculators run out of steam, it's Python that I turn to, these days.
(07-08-2015 09:36 PM)emece67 Wrote: [ -> ]In fact I decided to learn Perl prior to Python
These are Python tutorials I can recommend:
Google's Python Class
Learn Python The Hard Way
The 1st has exercises written as test-cases and the 2nd has a radical concept: Do Not Copy-Paste.
Though I like Perl I'd advice to learn Python if you have a choice. No wonder you feel comfortable with it.
Keep having fun!
Thomas
(07-08-2015 07:27 PM)Thomas Klemm Wrote: [ -> ] (07-08-2015 06:50 PM)Paul Berger (Canada) Wrote: [ -> ]Part of my job involves extracting information from massive log files, and I can't think of anything better than PERL for a job like that
This can be done very elegantly with Python using generators as a pipeline:
Generator Tricks for Systems Programmers
Presentation Slides (PDF)
Cheers
Thomas
Yeah probably but I have a working knowledge of PERL and it does the job.
(07-08-2015 11:44 PM)Paul Berger (Canada) Wrote: [ -> ]Yeah probably but I have a working knowledge of PERL and it does the job.
That's the job Larry Wall originally designed Perl to do, and it really excels at it. O'Reilly has a book on using Perl for systems administration, and if I recall correctly, the downloadable free sample chapter on their site is about exactly this - using Perl to parse log files.
And because I would rather do this than start real work for the day, here's the guessing game again, this time in Perl:
Code:
#!/usr/bin/perl
# Guessing game, writtn in Perl
print "Hi there, what's your name? ";
$name = <STDIN>;
chomp($name);
print "OK, $name, do you want to play a guessing game? ";
$play = <STDIN>;
chomp($play);
while ($play =~ /^y/i) {
$number = int(rand(100))+1;
print "I'm thinking of a number between 1 and 100.\n";
print "You've got to try to guess it.\n";
print "What's your guess? ";
$guess = <STDIN>;
while ($guess != $number) {
if ($guess > $number) {print "Too high!";}
if ($guess < $number) {print "Too low!";}
print " What's your next guess? ";
$guess = <STDIN>;
}
print "You've got it, $name!!!\n";
print "Play again? ";
$play = <STDIN>;
chomp($play);
}
Very nice!
An alternative version of the following lines
Code:
if ($guess > $number) {print "Too high!";}
if ($guess < $number) {print "Too low!";}
Code:
print "Too high!" if ($guess > $number);
print "Too low!" if ($guess < $number);
Sylvain
(07-09-2015 01:55 AM)Sylvain Cote Wrote: [ -> ]
Code:
print "Too high!" if ($guess > $number);
print "Too low!" if ($guess < $number);
Hey, cool, Sylvain - thanks!! I'd forgotten that particular Perl paradigm - I've been away from it for too long, I guess. I'll change my version here, because that neatly demonstrates the Perl mantra: TMTOWTDI (There's More Than One Way To Do It)!
And because I'm in the mood, here's a version for Python 3.x, written in a very plain-vanilla style:
Code:
# guess.py (for Python 3)
import random
name = input("Hi there, what's your name? ")
play = input("OK, " + name + ", would you like to play a game? ")
while play.upper() == 'Y' :
number = int(random.random() * 100) + 1
print("I'm thinking of a number between 1 and 100.")
print("You've got to try to guess it.")
guess = int(input("What's your guess? "))
while guess != number :
if guess > number :
print("Too high! ")
if guess < number :
print("Too low! ")
guess = int(input("What's your next guess? "))
print("You got it, " + name + "!!!\n")
play = input("Play again? ")
This is for Don Shepherd:
Don,
We have all these "Guess the Number" program listings.
How about posting your basic code for the Android Nexus 7 with voice?
Thanks,
Bill
Smithville, NJ
I'm not sure these are considered languages or operating systems.
Back in the 70's at Indiana University, I was exposed to CDC Plato education system. Then in the 80's my girlfriend worked for a couple of interesting companies.
First was CDC in the Plato group. She would let me go in after hours and on weekends and play with the Plato system Of course most of my time was spent playing a multiuser version of a real-time version of star wars. It was a lot of fun.
A few years later, she went to work at Metaphor Computer Systems. This company was started by David Liddle, one of the Xerox PARC people. Again, after hours, I was allowed to play around with the system The workstations all had wireless mice and keyboards, and the GUI was a lot like the Xerox Star system. The company provided database services for the average executive. You could drag and drop pieces of a database into a tree like structure and the system would create the SQL inquiry to generate a beautiful report from the database. It was really easy to do. Beautiful system, but a little slow. Would be interesting to see how it would perform on todays hardware. Since they were competing with IBM's database software, IBM bought the company only for the database stuff, and then closed down the hardware piece.
Bill
Smithville, NJ
(07-09-2015 01:55 AM)Sylvain Cote Wrote: [ -> ]
Code:
print "Too high!" if ($guess > $number);
print "Too low!" if ($guess < $number);
Or then using the
ternary operator ?:
Code:
print $guess > $number ? "Too high!" : "Too low!";
(07-09-2015 02:00 AM)Les Bell Wrote: [ -> ]
Code:
if guess > number :
print("Too high! ");
if guess < number :
print("Too low! ");
Or then:
Code:
print("Too high! " if guess > number else "Too low! ")
Cheers
Thomas
PS: In Python there's no need to put a semicolon at the end of each line.
(07-08-2015 09:59 PM)Les Bell Wrote: [ -> ]Personally, I hate Pascal. I implemented a market research survey cross-tabulation program in it, back in 1982, and it nearly drove me insane, so damned awkward was it for handling sane input processing and validation. I subsequently had people point out extensions that made this easier in Turbo Pascal - but that implementation had so many extensions, most of them contrary to the original strict and minimalist spirit of the language, that it really shouldn't have been called Pascal at all.
So, a language should not be extended? It should be left as invented in 1970. or something and if new functionality is needed - new languages with new names should be "invented" instead?
Personally, I hate most of those scripting languages ...
(07-09-2015 06:42 AM)Thomas Klemm Wrote: [ -> ]PS: In Python there's no need to put a semicolon at the end of each line.
Good points, thanks, Thomas! As you point out, there's no need to test for both > and < in the central loop; if the code gets there, the guess can't equal the number, so if it's not greater it must be less. As to the semicolons: Damn! Old habits die hard. I'll go back and fix that.
(07-09-2015 06:53 AM)HrastProgrammer Wrote: [ -> ]So, a language should not be extended? It should be left as invented in 1970. or something and if new functionality is needed - new languages with new names should be "invented" instead?
Well, in the case of Pascal - yes. Niklaus Wirth was adamant that he wanted a small and efficient language for teaching purposes, and so it lacked a number of important features for commercial development. Brian Kernighan agreed - see his famous paper,
Why Pascal Is Not My Favorite Programming Language, for a full analysis. I was working with Pascal/M, which was a fairly pure implementation of the language as documented by Wirth, and I found it quite painful.
Turbo Pascal subsequently introduced a number of extensions that solved some of the problems, but were contrary to the spirit of the language. For example, I remember reading some Turbo Pascal code and suddenly finding a variable called "buflen" but which I couldn't find declared anywhere - what is this thing, and where did it come from? It turns out it was a pseudo-variable that was unique to the Turbo implementation.
It was these kinds of problems that led me to PL/I Subset G, which I always thought of as a "Pascal that's not afraid to get its hands dirty".
Turbo Pascal was an incredible product and hugely influential in its time - a lot of popular applications were written in it, and still are, using derivatives like Delphi - but I've always been of the opinion that it shouldn't have been called "Pascal". Wirth himself moved on to Modula and especially Modula-2, which solved the problems with Pascal.
(07-09-2015 07:36 AM)Les Bell Wrote: [ -> ] (07-09-2015 06:53 AM)HrastProgrammer Wrote: [ -> ]So, a language should not be extended? It should be left as invented in 1970. or something and if new functionality is needed - new languages with new names should be "invented" instead?
Well, in the case of Pascal - yes.
OK, if you say so.
Quote:Brian Kernighan agreed - see his famous paper, Why Pascal Is Not My Favorite Programming Language, for a full analysis.
I can as well write a paper "Why is Pascal my favorite programming language" or "Why I am using Pascal for professional development during the last 25 years" etc.
I must admit that I don't care much about "why someone doesn't like something", and especially in 2015. I couldn't care less about what has been written in 1981., even if it has been written by Brian Kernighan, with all the respect. There are tons of things I don't like in C (or C++) as well, and would take Pascal (I am talking about today's Pascals like Delphi and Free Pascal) over C/C++ almost anytime, not to speak about various scripting languages with totally awkward syntax.
But I can agree with you to some extent - with RAD tools like Delphi the original Pascal language is just a small part of the whole development environment ...
(07-09-2015 08:23 AM)HrastProgrammer Wrote: [ -> ]But I can agree with you to some extent - with RAD tools like Delphi the original Pascal language is just a small part of the whole development environment ...
Hey, whatever gets the job done and if Pascal floats your boat, great! It didn't, for me, but my one-man campaign to rid the world of the evil Pascal doesn't seem to have got very far. And the PL/I that I jumped ship to didn't exactly set the world on fire, either - which is why I wound up writing a lot of C, and later, Java code.
Sigh. Another day, another language, it sometimes feels like, as the market evolves. These days it looks like all the cool kids are using JavaScript.
(07-09-2015 08:38 AM)Les Bell Wrote: [ -> ]Sigh. Another day, another language, it sometimes feels like, as the market evolves. These days it looks like all the cool kids are using JavaScript.
Yeah, most likely ... All those libraries (
https://en.wikipedia.org/wiki/List_of_Ja..._libraries) etc., I stopped to count them quite some time ago. But, as you said - whatever gets the job done ...
(07-09-2015 06:42 AM)Thomas Klemm Wrote: [ -> ] (07-09-2015 01:55 AM)Sylvain Cote Wrote: [ -> ]
Code:
print "Too high!" if ($guess > $number);
print "Too low!" if ($guess < $number);
Or then using the ternary operator ?:
Code:
print $guess > $number ? "Too high!" : "Too low!";
Right, but to respect the same logic your line will have to modified like this
Code:
print $guess > $number ? "Too high!" : $guess < $number ? "Too low!" : "";