Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I've created a program for my own purposes in three different languages, Perl, Python, and Ruby. Each program will be posted in with their own tag but I will add links to them through on each post. The program itself is very simple, all it does is ask the user about three different languages which are saved into an array, it then prompts the user to choose a language that runs through an if statement, and if the user chooses the language they're writing in it then takes a random language from the array and outputs it.

See also Python See also Python

See also Ruby See also Ruby

use strict;
use warnings;
sub welcome {
 my @choices = qw( Perl Python Ruby );
 my $lang = 3;
 print("Welcome, to the test script, this will test what language you would like to learn.. In order to find out these choices, write this same definition in all three different languages\n");
 print("There are $lang, languages to chose from please pick one:\n");
 print "@choices\n";
 my $choice = <STDIN>;
 chomp $choice;
 if ($choice eq "Ruby") {
 print("You have chosen Ruby!\n");
 } 
 elsif ($choice eq "Python") {
 print("You have chosen Python!\n");
 } 
 else {
 print("You're already writing in Perl!! Let me choose for you:\n");
 my $rand_elm = @choices[rand @choices];
 print "$rand_elm\n"
 }
}
welcome();

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function. All in all I think Perl is definitely a great language to learn.

I also have some questions about Perl:

  • Is there any better syntax that I should be using here in order to shorten the program?
  • Does Perl have an equivalent to Ruby's puts?
  • Why is it easier to use a sub instead of a function?

example:

 welcome(); 
 # instead of
 sub welcome();

I've created a program for my own purposes in three different languages, Perl, Python, and Ruby. Each program will be posted in with their own tag but I will add links to them through on each post. The program itself is very simple, all it does is ask the user about three different languages which are saved into an array, it then prompts the user to choose a language that runs through an if statement, and if the user chooses the language they're writing in it then takes a random language from the array and outputs it.

See also Python

See also Ruby

use strict;
use warnings;
sub welcome {
 my @choices = qw( Perl Python Ruby );
 my $lang = 3;
 print("Welcome, to the test script, this will test what language you would like to learn.. In order to find out these choices, write this same definition in all three different languages\n");
 print("There are $lang, languages to chose from please pick one:\n");
 print "@choices\n";
 my $choice = <STDIN>;
 chomp $choice;
 if ($choice eq "Ruby") {
 print("You have chosen Ruby!\n");
 } 
 elsif ($choice eq "Python") {
 print("You have chosen Python!\n");
 } 
 else {
 print("You're already writing in Perl!! Let me choose for you:\n");
 my $rand_elm = @choices[rand @choices];
 print "$rand_elm\n"
 }
}
welcome();

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function. All in all I think Perl is definitely a great language to learn.

I also have some questions about Perl:

  • Is there any better syntax that I should be using here in order to shorten the program?
  • Does Perl have an equivalent to Ruby's puts?
  • Why is it easier to use a sub instead of a function?

example:

 welcome(); 
 # instead of
 sub welcome();

I've created a program for my own purposes in three different languages, Perl, Python, and Ruby. Each program will be posted in with their own tag but I will add links to them through on each post. The program itself is very simple, all it does is ask the user about three different languages which are saved into an array, it then prompts the user to choose a language that runs through an if statement, and if the user chooses the language they're writing in it then takes a random language from the array and outputs it.

See also Python

See also Ruby

use strict;
use warnings;
sub welcome {
 my @choices = qw( Perl Python Ruby );
 my $lang = 3;
 print("Welcome, to the test script, this will test what language you would like to learn.. In order to find out these choices, write this same definition in all three different languages\n");
 print("There are $lang, languages to chose from please pick one:\n");
 print "@choices\n";
 my $choice = <STDIN>;
 chomp $choice;
 if ($choice eq "Ruby") {
 print("You have chosen Ruby!\n");
 } 
 elsif ($choice eq "Python") {
 print("You have chosen Python!\n");
 } 
 else {
 print("You're already writing in Perl!! Let me choose for you:\n");
 my $rand_elm = @choices[rand @choices];
 print "$rand_elm\n"
 }
}
welcome();

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function. All in all I think Perl is definitely a great language to learn.

I also have some questions about Perl:

  • Is there any better syntax that I should be using here in order to shorten the program?
  • Does Perl have an equivalent to Ruby's puts?
  • Why is it easier to use a sub instead of a function?

example:

 welcome(); 
 # instead of
 sub welcome();
edited tags
Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
removed irrelevant quote tag; fixed spelling error
Source Link
BCdotWEB
  • 11.4k
  • 2
  • 28
  • 45

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function, all in all I think Perl is defiantly a great language to learn

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function. All in all I think Perl is definitely a great language to learn.

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function, all in all I think Perl is defiantly a great language to learn

Perl took me the longest out of all the programs I wrote, this was my first ever Perl script. With all the ; and the random symbols I had to use to make variables and arrays, it was defiantly hard. However I really enjoyed writing this in Perl, it was something different. Perl maxed out as the longest program at a total of 30 lines. At one point I kept getting an NameError that was due to me missing a ; at the chomp function. All in all I think Perl is definitely a great language to learn.

added 68 characters in body
Source Link
13aal
  • 872
  • 1
  • 9
  • 30
Loading
added 125 characters in body
Source Link
13aal
  • 872
  • 1
  • 9
  • 30
Loading
Source Link
13aal
  • 872
  • 1
  • 9
  • 30
Loading
lang-perl

AltStyle によって変換されたページ (->オリジナル) /