Feed on
Posts
Comments

Fill up for $100+?
It’s been reported that certain Dodge dealerships are discounting their gas-guzzling Ram Pickups by a whopping $13,000! This kind of news makes me feel warm and fuzzy inside. Is it justice? Is it karma? I don’t know what to call it exactly, but it basically comes down to simple economics. Folks is poor! Gas is expensive! The rest will work itself out.

The other reason I love this news is that supports my idea for lowering gas prices. Forget those “hands across America” chain letter emails calling for a gas boycott on “Lameuary 51st”, they don’t work. They don’t work because people will continue to buy gas as long as their cars are powered by gas. Therefore, the only way things are going to change is if our cars are no longer powered by gasoline. Hmmm…now who has the power to do this? The car companies? Bingo! “But, MrToothDecay, how do we get the car companies to do this, I’m just one consumer?”, you might ask. Well, don’t fret, my lonelies, I have a great idea. Stop buying new cars! I’ll say it again…Stop buying new cars! It’s simple, really. Swallow your ego, save some cash, and help the environment by purchasing a pre-owned vehicle instead of a new one. Eventually car companies will get the message and change will occur.

Stop buying new cars! I can’t think of a simpler way to drive (ha ha pun) the point home to the car companies that we demand better. Stop buying new cars.

This is how to create a progress spinner in PERL. Concepts covered include: autoflush var, modulo operator, for loop, carriage return character.

 1: local $|=1;
 2: my @spinner = ('|', '/', '-', '\\');
 3: for(my $i=0; $i <= 32; $i++)
 4: {
 5:     print "Voila! ", $spinner[$i % 4];
 6:     print “\r”;
 7:     sleep 1;
 8: }
 9: print “\nDone!\n”;

Let’s look at the meaningful lines:

Line 1: local $| = 1;
This sets PERL’s print buffer to auto flush. This causes the print statements within the for-loop to be output to the screen as soon as they occur, instead of waiting for a newline. $| defaults to zero.

Line 2: my @spinner = (’|', ‘/’, ‘-’, ‘\\’);
A simple array to hold the crude, but sufficient, characters that will emulate a spinner.

Line 5: print “Voila! “, $spinner[$i % 4];
Since we have four pieces to our spinner, we’ll address each one in succession by using a modulo 4 calculation on the array index.

Line 6: print “\r”;
This prints a carriage return, which basically moves the cursor back to the beginning of the line. This causes each subsequent print to overwrite the previous one. In quick succession this creates the illusion we’re looking for.

Remember, there’s more than one way to do it!