Questions tagged [perlop]

Perl operators and precedence

6 questions
6
votes
3 answers

Is there a name for the special variable %+?

I was wondering if there was an operator name for %+, so instead of code like: /(?\w+)/; ... my $whatever=$+{CaptureName}; I could use something more readable: use English; /(?\w+)/; ... my $whatever=$?????{CaptureName};
Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181
4
votes
1 answer

Why using utf8 patterns within perl substitute(s) and match(m) operators within one-liners does not work?

I found this issue when using Perl's one-liners for substituting some utf8 text in files. I am aware of hacks at How to handle utf8 on the command line (using Perl or Python)?. They don't work for this case. OS is linux, locate is set to utf8 # make…
okharch
  • 387
  • 2
  • 10
2
votes
2 answers

Why "?:" operator cannot return list?

Why ?: operator can not return list? my $hash = { ... ($row->active?checked=>1:()), }; The DOC say nothing about scalar or list context UPD Another example: @list = 2,3; # CORRECT @list = 1? 2,3 : (); # Syntax error Why first is…
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
1
vote
2 answers

What is precedence in this expression?

When I run this program: print(rand*100) I get values from [0,1) range. But for this: print(100*rand) I get values from [0,100) range. What is precedence here? and why first expression does not return values from [0,100) range?
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
1
vote
4 answers

How to check if a file name contains directory info?

I would like to check if a file name has any directory information within it, preferably without using a system dependent hack like index($file_name,'/')!=-1. I know of the File::Spec module, but can't seem to find a way to use that module to make…
Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181
-1
votes
4 answers

Perl dereferencing in non-strict mode

In Perl, if I have: no strict; @ARY = (58, 90); To operate on an element of the array, say it, the 2nd one, I would write (possibly as part of a larger expression): $ARY[1] # The most common way found in Perldoc's idioms. Though, for some reason…
g.cze
  • 38
  • 6