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
Need a perl study-buddy
Started by pvpchina, Mar 11 2008 05:09 AM
17 replies to this topic
#1
Posted 11 March 2008 - 05:09 AM
|
|
|
#2
Posted 11 March 2008 - 11:14 AM
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_*
Posted 11 March 2008 - 01:50 PM
Guest_Jordan_*
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
Posted 11 March 2008 - 02:21 PM
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_*
Posted 11 March 2008 - 02:32 PM
Guest_Jordan_*
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
Using the Perl chop() function
#6
Posted 11 March 2008 - 11:32 PM
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
Posted 12 March 2008 - 10:45 AM
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?
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
Posted 12 March 2008 - 11:19 AM
#!/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 =(
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
Posted 13 March 2008 - 12:20 AM
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:
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
Posted 13 March 2008 - 09:01 AM
thanks, im totally pro at functions now! =) gimi a task involving sub routines and functions.. wanna see if im pro ^^
maybe someone see any improvements here? =))))
#!/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
Posted 13 March 2008 - 09:46 PM
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.
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
Posted 13 March 2008 - 09:52 PM
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.
sub one;
sub two;
You can drop that now before it becomes a bad habit.


Sign In
Create Account

Back to top









