CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Can someone tell me what this syntax means?

 



homer_3
New User

Mar 1, 2014, 5:43 PM

Post #1 of 2 (1412 views)
Can someone tell me what this syntax means? Can't Post

I'm looking through some perl code and ran across some syntax I can't figure out. Can someone tell me what the below code means?


Quote
$self = shift;
$self->{'_invert'};



(This post was edited by homer_3 on Mar 1, 2014, 5:44 PM)


FishMonger
Veteran / Moderator

Mar 2, 2014, 8:16 AM

Post #2 of 2 (1397 views)
Re: [homer_3] Can someone tell me what this syntax means? [In reply to] Can't Post


Code
$self = shift;

That's a var assignment.

The shift function removes the first element of an array shortening the array by 1 element, presumably this line is in a subroutine so it would be acting on the @_ array. In this case the value shifted off of the array is being assigned to $self.

See: perldoc -f shift
http://perldoc.perl.org/functions/shift.html


Code
$self->{'_invert'};

Here, we see that $self is hash reference and one of its keys is '_invert'. Since it's being used in void context, my assumption is that the '_invert' key is being added to the hash and its value will default to undef.

If the '_invert' key was already in the hash, then that line would do nothing and would be pointless.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives