Questions tagged [special-variables]
25 questions
10
votes
2 answers
How to use $a and $b in Perl subroutine
I would like to use $a and $b variables in my anonimous binary functions like it is done in sort {$a <=> $b} (1, 2, 3) but I can not figure out why code like
#!/usr/bin/env perl
use strict;
use warnings;
Foo::Bar(sub { $a + $b });
package…

alexanderkuk
- 1,551
- 2
- 12
- 29
9
votes
3 answers
What does perl special variable $-[0] and $+[0] means
I want to know the meaning of perl special variables $-[0] and $+[0]
I have googled and found that $- represent number of lines left on the page and $+ represent the last bracket matched by the last search pattern.
But my question is what $-[0] and…

AnonGeek
- 7,408
- 11
- 39
- 55
8
votes
2 answers
What does __FILE__ == $PROGRAM_NAME mean in ruby?
I have stumbled across this sintax while reviewing a code in Ruby. The code is:
if __FILE__ == $PROGRAM_NAME
#some code...
end
I suppose __FILE__ is a variable that gets me the name of the file I am in?
But what does $PROGRAM_NAME simbolize then?…

Mc-Ac
- 161
- 1
- 8
7
votes
2 answers
Dynamic variables in perl
I am wondering about how I can do in Perl what I commonly do in lisp:
(defvar *verbose-level* 0)
(defun my-function (... &key ((:verbose-level *verbose-level*) *verbose-level*) ...) ...)
this means that my-function is run at the current level of…

sds
- 58,617
- 29
- 161
- 278
6
votes
2 answers
Where can I find information about Perl's special variables?
Perl has quite a few special variables such as @F, $!, %! ... etc. Where are all Perl's special variables documented?

Sinan Ünür
- 116,958
- 15
- 196
- 339
6
votes
1 answer
Perl implicit close resets the $. variable
The documentation for Perl's close states that $. isn't reset if you use the implicit close done by open. I was trying to see exactly what this meant, but couldn't get it to happen. Here's my script:
use strict;
use warnings;
use autodie;
my @files…

Nate Glenn
- 6,455
- 8
- 52
- 95
5
votes
2 answers
Are there any side-effects to using `arg` as an argument name in Lua?
I was using arg as an argument name for a function:
function foo(cmd, arg)
-- etc.
end
I just learned arg is a special, hidden variable that represents a table of arguments when using variable arguments:
function foo(bar, baz, ...)
--…

Andrew Cheong
- 29,362
- 15
- 90
- 145
3
votes
1 answer
Behaviour of special variables under macro expansion
FUZZ> (defvar *foo* nil)
*FOO*
FUZZ> (defmacro bar ()
(format t "foo: ~A" *foo*)
`(+ 1 1))
BAR
FUZZ> (defmacro bot ()
(let ((*foo* 17))
`(bar)))
BOT
FUZZ> (bot)
foo: NIL
My mental model (clearly wrong) of macro…

gtod
- 229
- 2
- 10
3
votes
1 answer
Any documentation for $^I in perl?
I have used $^I in a perl script to search and replace conditionally. I want to know whether $^I makes a copy of the file in the buffer and write backs entire buffer back to file after processing the buffer or it does in line editing.
The code is as…

user3140798
- 33
- 3
3
votes
1 answer
How are the "lexical and special variable" semantics implemented under the hood in general?
CLtL2 has clarified the distinction between scope and extent. My take on it, in relation to lexical and special variables, is that lexical variables are “lexically scoped with indefinite extent” while special variables are “indefinitely scoped with…

Wei Peng 彭巍
- 99
- 3
2
votes
4 answers
How to establish a variable binding that will be active during macroexpansion time?
Let's define a function, the body of which contains the macro, which will be expanded at some unspecified time and will use a global dynamic value of *test* during this process.
> (defvar *test* nil)
> (defmacro body ()
`(print ,*test*))
>…

Vsevolod Dyomkin
- 9,343
- 2
- 31
- 36
2
votes
2 answers
How do I set a response status code with caveman2?
I'm trying to create an endpoint that will send a status code using caveman2.
(defroute "/books/" ()
(render-json "Hello"))
I have found the function throw-code which enables me to send a status code, but it won't let me send a response body as…

zimio
- 107
- 9
2
votes
1 answer
What is the dollar caret zero variable ( $^0 ) in Perl?
I've found some Perl code that makes the following check:
if ($^O eq 'MSWin32')
What is the $^0 variable? It looks like it contains the architecture/OS of the machine it's running on, but I don't know if that's the result of assigning it elsewhere…

M_M
- 1,955
- 2
- 17
- 23
2
votes
1 answer
Why does adding a sleep to a bash script seem to break variable decrementing for certain named variables?
With the following bash script:
#!/bin/bash
let SECONDS=5
until [[ "$SECONDS" -le "1" ]]; do
echo SECONDS $SECONDS
(( SECONDS -= 1 ))
# sleep 1
done
I am seeing strange behavior. Namely, that if I uncomment the sleep 1 the loop…

enderland
- 13,825
- 17
- 98
- 152
2
votes
2 answers
Iterating over the values of $@
I would like to iterate over the arguments given to a bash script, for example:
./bash_script file1 file2 file3
$@ gives me all the files given to the script but how do I iterate over the files?
I would like to cat each file and remove the contents…

user3314672
- 87
- 4