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

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.

Thread Tools Search this Thread
Old 11-07-2007, 11:57 PM   #11
Posts: n/a

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.
  Reply With Quote
Old 11-08-2007, 12:22 AM   #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 = <STDIN>;
	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

Related Topics
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 06:28 PM
java script off? Drifty Lounge 1 08-04-2007 03:59 AM
Can you figure this one out??? SSE14U24ME Lounge 7 04-18-2004 06:10 AM
I HOPE SOMEONE CAN FIGURE THIS OUT bonnie94ssei Everything Electrical & Electronic 9 02-20-2004 05:48 PM
uhhh can someone figure this out? FiReDeViL Lounge 9 08-24-2003 12:39 AM

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 Off
Pingbacks are Off
Refbacks are Off

All times are GMT -4. The time now is 04:45 PM.

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.