# Special case blank identifier \_ in Zeek scripts

**URL:** <https://community.zeek.org/t/special-case-blank-identifier-in-zeek-scripts/6758>\
**Category:** Development\
**Created:** [October 18, 2022, 1:26pm UTC](https://community.zeek.org/t/special-case-blank-identifier-in-zeek-scripts/6758 "2022-10-18T13:26:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![awelzel](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/awelzel/32/609_2.png) [@awelzel](https://community.zeek.org/u/awelzel)\
**Post date:** [October 18, 2022, 1:26pm UTC](https://community.zeek.org/t/special-case-blank-identifier-in-zeek-scripts/6758/1 "2022-10-18T13:26:19Z")

</div>

Hello,

we’ve been toying with the idea of reserving the blank identifier `_` in Zeek scripts such that it can not be referenced anymore and therefore not used as a local identifier.

This would, besides other future use-cases, allow to support using `_` _and_ re-using it within the same scope to explicitly ignore loop variables similar to what may be known from Go or what is done conventionally in Python.

```auto
# Index, value vector iteration (coming with Zeek 5.1) ignoring the index
local vec = vector("a", "b", "c");
for ( _, v in vec )
    print v;

# Key, value iteration ignoring a subset of the key/index
local tab = table(["a",1,T] = "a1a", ["b",2,F] = "b2b", ["c",3,T] = "c3c");
for ( [_,c,_], v in tab )
    print c, v;

# Ignore all keys at once, only iterate over the values
for ( _, v in tab )
    print v;

# Poor man's strlen()
local str = "a string";
local len = 0;
for ( _ in str )
    ++len;

```

Above script would currently fail due to `_` being typed according to its first occurrence and clashing with later usages.

On the flip side, `_` will not be usable as a local identifier anymore. Outside of obfuscation exercises, this seems to take little away and we’re considering introducing this change without a deprecation/warning.

The following draft PR contains an initial set of changes - if you have thoughts/comments around this or had situations where ignoring loop vars would’ve been nice, happy to hear about it here, on Github or Slack.

> <https://github.com/zeek/zeek/pull/2449>
>
> Mostly: Do not instantiate variables within for loops and allow reusing differen…tly typed blanks which previously wasn't possible.
> 
> This may be missing some corner-cases, but the added tests seem to work as expected and nothing else fell apart it seems.

Thanks,  
Arne
