Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Is it evaluated in scalar or list context?

by 7stud (Deacon)
on Jan 19, 2013 at 19:53 UTC ( #1014231=note: print w/replies, xml ) Need Help??


in reply to Is it evaluated in scalar or list context?

$var1 = something1 ;

On the left of the assignment is a scalar variable. A scalar variable on the left of an assignment cries out, "Give me a scalar(single) value to store!" Similarly, an array variable on the left of an assignment:

@x = something;

...cries out, "Give me a list to store!"

Now look at this code:

use strict; use warnings; use 5.012; my @something = ('a', 'b', 'c'); my $x = @something; my($y) = @something; say $x; say $y; --output:-- 3 a

When $x cries out for a single value, the array provides its length. On the other hand, ($y) is a list, and it cries out for a list--so that list assignment can be performed:

my @something = ('a', 'b', 'c'); my $d; my $e; my $f; ($d, $e, $f) = @something; say $d; say $e; say $f; --output:-- a b c
($d, $e) = @something; say $d; say $e; --output:-- a b
($d) = @something; say $d; --output:-- a
$d = @something; say $d; --output:-- 3
my($s, $t, $u) = @something; say $s; say $t; say $u; --output:-- a b c

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014231]
help
Chatterbox?
[Lady_Aleena]: Has anyone here ever use pcregrep? I can't seem to get the --include regex right. --include=*.p[lm] works in grep but not pcregrep.
[erix]: to lift your spirits, here is some more happy Randy news...
[Lady_Aleena]: The reason I would like to use pcregrep is because it can do multiline searches supposedly.
[perldigious]: What are your criteria for looking Tanktalus? What things must a job have for you to consider it? And where are you in your career? Start, middle, or end?
[erix]: are there any regex-engines that do not do multiline?
[Lady_Aleena]: erix, grep doesn't.
[Lady_Aleena]: Linux grep that is...
[Lady_Aleena]: $ grep --include=*.p[lm] -Ern 'get_(array|hash| data)' does not do multiline search.
[Discipulus]: focus on Perl LA; you can already search multiline patterns
[erix]: grep is a program, not a regex-engine

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2017-05-23 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?