Questions tagged [scalar-context]

10 questions
9
votes
6 answers

Is there such a thing as a list in scalar context?

my $mind = ( 'a', 'little', 'confused' ); And it's because perldoc perlfaq4 explains the line above as follows (emphasis added): Since you're assigning to a scalar, the righthand side is in scalar context. The comma operator (yes, it's an…
Zaid
  • 36,680
  • 16
  • 86
  • 155
5
votes
2 answers

Can the empty list be in scalar context?

There is a lie that a list in scalar context yields the last element of the list. This is a lie because (as the saying goes) you can't have a list in scalar context. What looks like a list in scalar context is really the comma operator in scalar…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
5
votes
2 answers

How to update navigation properties / related tables in EF?

I have an object Customer with a navigation property Days (days is a separate table which have - day_id, customer_id - FK). mycontext.Customers.ApplyCurrentValues(cust); mycontext.SaveChanges(); This only updated the scalar properties of Customer,…
4
votes
4 answers

Perl "reverse comma operator" (Example from the book Programming Perl, 4th Edition)

I'm reading "Programming Perl" and ran into a strange example that does not seem to make sense. The book describes how the comma operator in Perl will return only the last result when used in a scalar context. Example: # After this statement,…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
3
votes
2 answers

How does word counting by list assignment work in Perl?

I cannot exactly understand how the following snippet works: my $str = 'abc def ghi'; my $num = () = $str =~ /\w+/g; say $num; # prints the word count, 3 I know that $str =~ /\w+/g returns a list of the words which, apparently, is conveyed to the…
Tolga Kurt
  • 85
  • 1
  • 6
3
votes
5 answers

Two-dimensional array access in Perl

I have an array populated with cities. I want to pass the array by reference to a sub routine and print each city to output. However, I have the following problems: I can access each element before my while loop in the subroutine. But I cannot…
donsiuch
  • 343
  • 3
  • 8
  • 18
1
vote
1 answer

Concatenating strings from a multidimensional array overwrites the target string in Perl

I've built a two dimension array with string values. There are always 12 columns but the number of rows vary. Now I'd like to build a string of each row but when I run the following code: $outstring = ""; for ($i=0; $i < $ctrLASTROW + 1; $i++) { …
0
votes
1 answer

Perl ARGV value in scalar context

Given the following Perl script: # USAGE: ./flurp -x -vf file1 file2 file3 file4 # e. $a = shift; $b = shift; $c = shift; @d = <>; # ei. value of $b = -vf # eii. value of @d = content of file2, file3, file4 print "$b\n"; print "@d\n"; print…
Alan W
  • 291
  • 1
  • 5
  • 18
0
votes
1 answer

After successfully using grep on a variable it prints blank

I am opening a directory that has files that look like the following. Here is one file: >UVWXY ABCDEFGHIJKLMNOPQRSTUVWXYZ >STUVW ABCDEFGHIJKLMNOPQRSTUVWXYZ >QRSTU ABCDEFGHIJKLMNOPQRSTUVWXYZ Here is a second file: …
Rob
  • 175
  • 12
0
votes
2 answers

Need help getting perl array out of scalar context

I have a perl array I need to store in the following way: $self->{spec}->{allImages} = @allImages; Then I need to retrieve the contents later: print Dumper($self->{spec}->{allImages}); This yields: $VAR1 = 10; (the number of items in the…
iLikeDirt
  • 606
  • 5
  • 17