PDA

View Full Version : whats this?


shuchi
02-05-03, 05:04
time for another doubt!

i was going thru someones perl code and needed to know what the following statements could be doing. thnx to anyone who could help..

1. my $variable=shift; # why assign "shift" to a variable?

2. $array[@array]=somevalue #what does this do and hos does this work?

3. $/="\f"; # this is some sort of "formfeed" matching- what is formfeed and whats cud be the purpose of doing ths?

4. can we use a variable without declaring it in perl if we dont use strict or warnings?

5. my $portfolio=$1 # is the variable = 1 or "$1"


hmmm these are the main doubts coz of which i cant really get the hang of the code...if neone can help please reply asap..aslo if u need any other info abt the code to help me pleez ask fr it..
thnxx in advance once again

-shuchi

Bernd Dulfer
02-06-03, 06:20
time for another doubt!

i was going thru someones perl code and needed to know what the following statements could be doing. thnx to anyone who could help..


You should grab a good book about Perl (Leraning Perl or Programming Perl) spend the weekend reading it and the following questions would have been answered.


1. my $variable=shift; # why assign "shift" to a variable?


shift without a parameter removes and returns the first element of the default array (@_) which contains parameters given to subroutines.
see: perldoc -f shift


2. $array[@array]=somevalue #what does this do and hos does this work?


@array in scalar context gives the number of elements in the array, which is also the next free index.
This just appends a value to the array.
see: perldoc perldata


3. $/="\f"; # this is some sort of "formfeed" matching- what is formfeed and whats cud be the purpose of doing ths?


$/ is the input record separator, assinging \f to it will split the next file on \f when reading it with <>.
see: perldoc perlvar


4. can we use a variable without declaring it in perl if we dont use strict or warnings?


Yes.


5. my $portfolio=$1 # is the variable = 1 or "$1"


$1 contains the value of the first parenthesized match in a regular expression.
see: perldoc perlre



Again: Get a good book and read it. You will solve your problems faster and easier.

Regards

Bernd

shuchi
02-06-03, 23:38
Thanx fr the great help.

I have got my hands on the book bt since im v new to it thot it wud be a faster method ths way as i have to muhc to do n v little time...

This doesnt happen to be my regular method of learning a language trust me!:)...
thnx again....

-shuchi