$tz is a reference variable that refers to the object obtained by blessing some package. site is a sub-routine (object method) in that package to which you're sending two arguments (as a list) viz. ['http','https'] and $site.
The single arrow (->) operator is called the dereference operator. In actual sense, a single arrow is used to refer to a value in a data structure (could be a scalar variable, list, hash, object). Observe the below example:
This will output 3, the 3rd number in the anonymous array whose reference is held in $anonyArrRef variable.
In your example, $tz is a reference variable that points to some object. And that object contains a sub-routine (object method) that is accessed by the thin arrow operator (->) -- $tz->site()A big arrow operator (=>) is just a notation used to represent key-value pairs while defining a hashmap.
In your example, you're sending one key-value pair to sub-routine site, where the key is an anonymous array ['http','https'] and value is a scalar variable $site. Actually, the key would be a reference to this anonymous array.
Hope this helps.
Last edited by balajesuri; 05-18-2013 at 01:17 AM..
This User Gave Thanks to balajesuri For This Post:
Technically, the -> is a binary infix dereference operator. In your case, since the right side of the operator is neither an array/hash subscript nor a subroutine argument list, it implies a method call with site being the method name and $tz could be an object reference or a class/package name.
The => operator is just a fancy comma. You can use it almost anywhere a , is used. Since this fat-arrow operator has the feature of autoquoting any Perl identifier to its immediate left (and also since it is eye-friendly), it is the preferred way to separate keys and values in a hash.
Last edited by elixir_sinari; 05-18-2013 at 04:32 AM..
This User Gave Thanks to elixir_sinari For This Post:
First, I know almost no perl, but that never stops me!
-> is stolen from C, says point to a child member of, in this case a member function or method of a class/object/struct type.
=> is somewhat synonymous with a comma, and has functions by context as a list separator or left operand discard, like in c you can say "x = ( y == 3 ? printf("Equal\n"), 1 : 0 );", which is assign to x the result of test y equal 3 if true printf and then discard the printf return and supply a 1 else supply a 0, which is an ugly way to say if y is three than printf and set x to 1 else set x to 0. The comma discards the return of the printf, and connects two commands that run together like a {}, especially handyin contexts where {} are not legal. However, the comma has special meanings by context, like separating key from value in a hash table. (A hash table is a lookup by some integer derived (hashed) from the key, to pick one of N buckets where there may be multiple but few key value pairs that have to be searched linearly. However, the hash and bucket select can be far faster than traversing a tree, and buckets are cheap, so you can have many, and so few buckets with many pairs. A good hash helps a lot, too.
$tz is a reference variable that refers to the object obtained by blessing some package. site is a sub-routine (object method) in that package to which you're sending two arguments (as a list) viz. ['http','https'] and $site.
The single arrow (->) operator is called the dereference operator. In actual sense, a single arrow is used to refer to a value in a data structure (could be a scalar variable, list, hash, object). Observe the below example:
This will output 3, the 3rd number in the anonymous array whose reference is held in $anonyArrRef variable.
In your example, $tz is a reference variable that points to some object. And that object contains a sub-routine (object method) that is accessed by the thin arrow operator (->) -- $tz->site()A big arrow operator (=>) is just a notation used to represent key-value pairs while defining a hashmap.
In your example, you're sending one key-value pair to sub-routine site, where the key is an anonymous array ['http','https'] and value is a scalar variable $site. Actually, the key would be a reference to this anonymous array.
Greetings!
Here's what I believe is a "simple one" for the community tonight ;)
What I'm trying to do is assign a "true/false" value to a variable depending upon whether a named process (some-process) exists; and then test for this value in the succeeding logic. I banged my head against the... (2 Replies)
Query with perl syntax
Aim: is to change a perl script to use a new file
I was required to replace
- entries \"$entries\"
with
-lib <full_path_to_filename>
So in the code detector.pm
sub rundetector
{
my $class = shift;
mkdir($resultDirectory);
my... (3 Replies)
Hallo everybody,
I have a following problem - I'm doing a map funciont to fill in a HTML table and I want to use some radiobutton groups. Unfortunatelly, they are grouped by names, so I have to add some "counter" that will divide one row from another, and I'm using CGI.pm for generating the... (3 Replies)
Hi,
i am running this code but i am getting syntax error
#!/usr/bin/perl
use warnings;
use strict;
use XML::LibXML;
use XML::LibXML::Reader;
use Data::Dumper;
my $file;
open( $file, 'DTC_Specification_transformed.xml');
my $reader = XML::LibXML::Reader->new( IO => $file ) or die... (1 Reply)
I'm just trying to confirm that I understand someone's code correctly.
If someone has code that says:
$foo ||= mysub();
I'm assuming that it means if $foo is nothing or undef, then assign it some value via mysub(). If I'm wrong on this, please let me know.
Also, what's the difference... (4 Replies)
Hi,
I am a newbie to PERL and working on a script. When running it I get a lot of compilation errors.
The actual command in the program (which is within a case structure) is given below
# This gives the actual count of inquires from a log file (It works fine when I type this on the... (2 Replies)
Im new at scripting and im trying to write a script using perl that will make sure there are 2 command line integer arguments and then check if the 2nd argument is greater than the first. i believe im close but still receive my error message even when i have 2 arguments and the second part gives me... (6 Replies)
All,
Does it matter what perl verios your running when you get syntax errors?
on version 5.6.1 the code works fine, but on 5.8.0 the code gets errors?
#!/usr/bin/perl
#use strict;
#use warnings;
my $mess = 'messages';
my $mess1 = 'messages.1';
my $mess2 = 'messages.2';
my... (13 Replies)
hi all
i was going through some perl code i came across this line and i am not getting what is exactly going on ..
$$this{localtion} = GetName->GetVarName("EXE_DIR") ;
what is the red part doing in above code (2 Replies)