who can help me figure out some PERL script?
#1
Guest
Posts: n/a
who can help me figure out some PERL script?
I have to run this code and print out the results for class but i can't figure out what the heck it does! when i run it i do'ntn know what to do with it to make it "show" anything. anyonne have any ideas?
#! /usr/bin/perl -w
$in = "";
print "Enter a key/value pair separated by a colon
(quit to finish)\t";
$in = <STDIN>;
chomp $in;
while($in ne "quit") {
($key, $val) = split(/:/, $in);
$myhash{$key} = $val;
print "Enter a key/value pair separated by a colon
(quit to finish)\t";
$in = <STDIN>;
chomp $in;
}
$cnt = 0;
foreach $temp (sort keys %myhash) {
$keyarray[$cnt] = $temp;
$valarray[$cnt++] = $myhash{$temp};
}
while($cnt > 0) {
$t = pop(@keyarray);
$tt = pop(@valarray);
print("Key: $t Value: $tt\n");
$cnt--;
}
exit(0);
$in = "";
print "Enter a key/value pair separated by a colon
(quit to finish)\t";
$in = <STDIN>;
chomp $in;
while($in ne "quit") {
($key, $val) = split(/:/, $in);
$myhash{$key} = $val;
print "Enter a key/value pair separated by a colon
(quit to finish)\t";
$in = <STDIN>;
chomp $in;
}
$cnt = 0;
foreach $temp (sort keys %myhash) {
$keyarray[$cnt] = $temp;
$valarray[$cnt++] = $myhash{$temp};
}
while($cnt > 0) {
$t = pop(@keyarray);
$tt = pop(@valarray);
print("Key: $t Value: $tt\n");
$cnt--;
}
exit(0);
#7
Guest
Posts: n/a
I was running it though notepad++ and when i would give the "quit" command so i could see my printout it would just close the screen.
i went into the cmd prompt and ran it that way and what do ya know... it does work.
I have a bit to learn here...
on another note, can you print what you see in the command prompt window? i'm just looking for the best way to turn in the printout of what the code displays. all i can think of is a good ole screen shot.
#10
Senior Member
Posts like a Camaro
Join Date: Nov 2002
Posts: 1,109
Likes: 0
Received 0 Likes
on
0 Posts
Originally Posted by Darrel
on another note, can you print what you see in the command prompt window? i'm just looking for the best way to turn in the printout of what the code displays. all i can think of is a good ole screen shot.
In any event, as far as printing out what you see in the command window, you can do an "edit, select all" by clicking on the top left corner icon. You can also highlight what you want with the mouse and press enter. After executing one of these actions, you can paste the results into an editor
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.