335 users online (0 members and 335 guests)  


  Results 1 to 2 of 2

Related

  1. Problem viewing shift reports    Forum: PHP Forum
    Replies: 0
  2. explain    Forum: CGI Perl Forum
    Replies: 1
  3. Can someone please explain how to add this.    Forum: CGI Perl Forum
    Replies: 3
  1. #1
    nechowdary's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    3

    HI explain me about shift @_

    hi all,
    plz explain me , i am new to this..& perl.
    plz tell me about the bellow syntax & in this shift @_
    what rpresent and from where it will get his array values..
    my $self = shift @_;
    my $projdir = shift @_;

    thanks&regards
    chowdary.

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: HI explain me about shift @_

    the @_ is a special variable that is an array of all variables passed to the function/sub...

    and shift simply shaves the first element off the array and returns it at the same time...

    in other words if i had:

    Code:
    dosomething('foo', 'bar');
    sub dosomething(){
    #@_ = array('foo', 'bar')
    my $firstarrayelement = shift @_;
    #now $firstelement = 'foo'
    #now @_ = array('bar')
    my $secondarrayelement = shift @_;
    #now $secondarrayelement = 'bar'
    #now @_ = array(); <-- empty array
    }
    and of corse 'my' is just a way of declaring a variable
    Last edited by ALL; 10-21-2006 at 10:08 PM.



Tags for this Thread