Solved

Use of ==> to establish value in a scalar

Posted on 2007-12-01
3
178 Views
Last Modified: 2010-04-21
A book example has the line:

Readonly my $ACTIVE_LOG => '>temp.log<';

I thought => was used for hash list? Why was the => used instead of =  ?
0
Comment
Question by:lqwest
3 Comments
 
LVL 7

Accepted Solution

by:
Wod earned 75 total points
ID: 20389518
The => digraph is mostly just a synonym for the comma operator:

Comma Operator

Binary ``,'' is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C's comma operator.

In list context, it's just the list argument separator, and inserts both its arguments into the list.

The => digraph is mostly just a synonym for the comma operator. It's useful for documenting arguments that come in pairs. As of release 5.001, it also forces any word to the left of it to be interpreted as a string.
0
 
LVL 17

Assisted Solution

by:mjcoyne
mjcoyne earned 50 total points
ID: 20389573
Likewise, a hash can be contructed from a comma-separated list:

#!/usr/bin/perl -w
use strict;

my %hash = ('apples', 'red', 'bananna', 'yellow');

foreach my $fruits (sort keys %hash) {
    print "$fruits are $hash{$fruits}\n"
}

0
 

Author Closing Comment

by:lqwest
ID: 31412145
I found some help also in the Perl's Best Practices book - basically has guideline that can be used when trying to decide if a => (aka fat comma) should be use: use it when you can say the symbol becomes blah-blah. Or as in my example ACTIVE_LOG becomes temp.log.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question