Results 1 to 3 of 3

Thread: whats this?

  1. #1
    Join Date
    Jan 2003
    Posts
    55

    Unanswered: whats this?

    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
    You try and try again..but then give up, there's no sense in being a complete fool about it!!!

  2. #2
    Join Date
    Sep 2002
    Location
    Germany, near Aachen
    Posts
    120

    Re: whats this?

    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
    Last edited by Bernd Dulfer; 02-06-03 at 06:24.

  3. #3
    Join Date
    Jan 2003
    Posts
    55
    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
    You try and try again..but then give up, there's no sense in being a complete fool about it!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •