Questions tagged [perlsyn]

For questions about Perl core syntax

6 questions
10
votes
6 answers

foreach my $var (@list) -- $var is a reference?

So, I never knew this and I want to get some clarifcation on it. I know if you do foreach (@list){ if you change $_ in that loop it will affect the actual data. But, I did not know that if you did foreach my $var1 (@list){ If you changed $var1 in…
Ryan Detzel
  • 5,519
  • 9
  • 37
  • 49
8
votes
3 answers

Why does Perl warn about "useless constant 1" when using bigint?

I was writing a module as part of my application when I noticed syntax check results in warning about useless use of a constant (1). Why is that? The constant is the obligatory 1 at the end of the module which is normally ignored by warnings as…
Daniel Böhmer
  • 14,463
  • 5
  • 36
  • 46
4
votes
3 answers

Perl - pass code block as parameter inside parentheses

Is it possible to pass a block of code to a sub using "parentheses" syntax? I.e. when i write List::MoreUtils::any { defined ($_) } (undef, undef, 1); it works. But when i try to add parentheses List::MoreUtils::any ( { defined ($_) } , (undef,…
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
2
votes
3 answers

Scope of the default variable $_ in Perl

I have the following method which accepts a variable and then displays info from a database: sub showResult { if (@_ == 2) { my @results = dbGetResults($_[0]); if (@results) { foreach (@results) { …
skeniver
  • 2,647
  • 6
  • 28
  • 34
1
vote
3 answers

Meaning of the perl syntax construction involving a comma

I've encountered a piece of code in a book that looks like this: #for (some_condition) { #do something not particularly related to the question $var = $anotherVar+1, next if #some other condition with $var #} I've got no clue what does the comma…
Ivan
  • 163
  • 1
  • 12
1
vote
7 answers

Perl for loop explanation

I'm looking through perl code and I see this: sub html_filter { my $text = shift; for ($text) { s/&/&/g; s//>/g; s/"/"/g; } return $text; } what does the for loop do in this…
Timmy
  • 12,468
  • 20
  • 77
  • 107