who can help me figure out some PERL script? - Page 2 - GM Forum - Buick, Cadillac, Chev, Olds, GMC & Pontiac chat
GM Forum - Buick, Cadillac, Chev, Olds, GMC & Pontiac chat

Go Back   GM Forum - Buick, Cadillac, Chev, Olds, GMC & Pontiac chat > General Offtopic Chat > Lounge

Lounge For casual talk about things unrelated to General Motors. In other words, off-topic stuff. And anything else that does not fit Section Description.

LinkBack Thread Tools Search this Thread
Old 11-07-2007, 10:57 PM   #11
True Car Nut
Join Date: Oct 2005
Posts: 2,515
Thanks: 0
Thanked 0 Times in 0 Posts
Darrel is on a distinguished road

Originally Posted by 1995BvSSE
You can also redirect output from pretty much any program by using the ">" character, and then print the file. For example:

perl myscript.pl >output.txt

Hope that helps.
Now thats cool. i'll have to try that next time. i just croped screenshots for now though. Cool. I"m sure i'll bring this thread back to life sometime in the next week if i get stuck on my next assignment again.
Darrel is offline   Reply With Quote
Old 11-07-2007, 11:22 PM   #12
Senior Member
Posts like a Camaro
Join Date: Nov 2002
Posts: 1,109
Thanks: 0
Thanked 0 Times in 0 Posts
1995BvSSE is on a distinguished road

By the way, if it were me, I'd write the script "more like this"

But the beauty of Perl is that it is quite flexible. Ask 5 Perl programmers to write something, you'll get 5 totally different scripts.

use strict;
use warnings;

#always declare variables, required with use strict
my $in;
my %myhash;
my @keyarray;
my @valarray;

#Take input from the user, tokenize the input and store it into a hash
#We make the loop "infinite" until the "last" condition is met below
while(true) {
	print "Enter a key/value pair separated by a colon\n(quit to finish)\t";
	$in = ;
	chomp $in;
	#using a "last" statement here precludes the need to have the "initial" set of
	#duplicate logic in the beginning of the script. i.e., we'll leave the loop
	#once our exit criteria is met
	last if $in eq "quit";
	(my @result) = split(/:/, $in);

	#Always verify your input!
	#Note that in Perl, treating an array as a scalar will give you the size.
	if (@result != 2)
		print "ERROR: input not understood\n"; 
		$myhash{$result[0]} = $result[1];

#iterate through each element in the hash in sorted fashion
foreach my $temp (sort keys %myhash) {
	#store the hash keys in keyarray
	#store the hash values in valarray

#Take elements off the end of the array, one at a time, thus reversed sorted order
while(@keyarray > 0) {
	print("Key: ".pop(@keyarray)." Value: ".pop(@valarray)."\n");

1995BvSSE is offline   Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me figure out where to hook up line out converter.... DADillac Audio (and aftermarket electronics) 8 09-25-2008 05:28 PM
java script off? Drifty Lounge 1 08-04-2007 02:59 AM
Can you figure this one out??? SSE14U24ME Lounge 7 04-18-2004 05:10 AM
I HOPE SOMEONE CAN FIGURE THIS OUT bonnie94ssei Everything Electrical & Electronic 9 02-20-2004 04:48 PM
uhhh can someone figure this out? FiReDeViL Lounge 9 08-23-2003 11:39 PM

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -4. The time now is 07:21 PM.