?
Solved

Use of ==> to establish value in a scalar

Posted on 2007-12-01
3
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
Wod earned 300 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

770 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