Jump to content

Need a perl study-buddy

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
17 replies to this topic

#1
pvpchina

pvpchina

    Newbie

  • Members
  • Pip
  • 9 posts
I got a test next week in perl :) If someone could help me with a few things later on id appreciate it..

my msn is : pvpchina@hotmail.com - maybe I can pay you something :) wont take more than 1 hour i promise! just need sum questions answered

#2
KevinADC

KevinADC

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
If you have questions you should just post them. If you are, on the other hand, trying to cheat on a test, forget it. As far as contacting you by email and providing personal service, I'll pass.

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I agree with KevinADC. We do not cheat for you at school. If you are required to learn Perl in school then you should actually learn it, it may help you in the future.

#4
pvpchina

pvpchina

    Newbie

  • Members
  • Pip
  • 9 posts
its not cheating.. just hm :) extra tutoring to get an in-depth knowledge..anyways ill ask for some specific help later =) at the moment trying to figure out what chop means mhhhhh

#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
The chop() function removes the last character of any string, regardless of what that character actually is. chop("jordan") would return cause the string to become "jorda" with a return value of "n".

Using the Perl chop() function

#6
KevinADC

KevinADC

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
look up perls builtin functions on the perldoc website, Perl version 5.10.0 documentation - perldoc.perl.org but as a personal observation, if you need assistance with chop() you're in for a long and hard journey in learning perl. Hopefully you were just joking.

#7
pvpchina

pvpchina

    Newbie

  • Members
  • Pip
  • 9 posts
cool thanks, got it. so chop is used to remove the last character, and if i have
a new line, it will remove the new line when i press enter.

now i need to know difference between

$a = <STDIN>;

my $a = <STDIN>;

=)) which one to use?

#8
pvpchina

pvpchina

    Newbie

  • Members
  • Pip
  • 9 posts
#!/usr/bin/perl -w
use strict;
sub funky();


funky();
print(funky()."\n");

my $random = <STDIN>;

print(funky().$random);


sub funky(){

my $var1 = $_[0] * 30;

return $var1;
}




also need help with this one.. duno why it doesnt work =(

#9
KevinADC

KevinADC

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
Stop doing this:

sub funky(){

do not put parenthesis after subroutine names, write it like this:

sub funky {

when you put parenthesis you are creating a prototype, there is no reason to do that and it will just complicate matters if you continue to do it.

Here it is rewritten simpler and passing $random into the function properly:

#!/usr/bin/perl
use warnings;
use strict;
my $random = 5;

print funky($random);

sub funky{
   my $var1 = $_[0] * 30;
   return $var1;
}


#10
pvpchina

pvpchina

    Newbie

  • Members
  • Pip
  • 9 posts
thanks, im totally pro at functions now! =) gimi a task involving sub routines and functions.. wanna see if im pro ^^


#!/usr/bin/perl -w
use warnings;
use strict;
sub one;
sub two;

print ("\nPlease Choose a converter \n \n celcius to farenheit (press 1) \n Farenheit to celcius (press 2) \n");
my $a = <STDIN>;
if ($a == 1) {
print ("You chose option 1. Enter your value below \n\n");
my $b = <STDIN>;
print one($b,32,1.8);
}
sub one {
	my $var1 = ($_[0] * $_[2]) +$_[1];
	return $var1;
	}
if ($a == 2) {
print ("You chose option 2. Enter your value below\n\n");
my $c = <STDIN>;
print two($c,32,(5/9));
}
sub two {
	my $var2 = ($_[0] - $_[1]) * $_[2];
	return $var2;
	}




maybe someone see any improvements here? =))))

#11
KevinADC

KevinADC

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
What happens if something besides 1 or 2 is entered as the option?

drop the -w switch from the shebang line. The warnings pragma is better:

use warnings;

Don't use parenthesis around print commands:

print ("You chose option 1. Enter your value below \n\n");

should be:

print "You chose option 1. Enter your value below \n\n";

print is not a function, using parenthesis can sometimes cause problems.

#12
KevinADC

KevinADC

    Programmer

  • Members
  • PipPipPipPip
  • 125 posts
declaring the subs at the beginning of the script is also unnecessary:

sub one;
sub two;

You can drop that now before it becomes a bad habit.