<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Foreach weird bug in variable in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310945#M93227</link>
    <description>&lt;P&gt;Can you try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval matched=0 | foreach UF* [eval matched = if(like('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',valMask),matched+1,matched) ]| foreach UF* [eval Property=if(matched&amp;gt;=1,Property,null)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Jan 2018 15:09:52 GMT</pubDate>
    <dc:creator>mayurr98</dc:creator>
    <dc:date>2018-01-18T15:09:52Z</dc:date>
    <item>
      <title>Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310944#M93226</link>
      <description>&lt;P&gt;So I have this chunk of code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval matched=0 | foreach UF* [eval matched = if(like('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',valMask),matched+1,matched) | eval Property = if(matched&amp;gt;=1,Property,null)]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Amusingly if the &lt;CODE&gt;matched&lt;/CODE&gt; variable equals 1, the &lt;CODE&gt;Property&lt;/CODE&gt; will get null value, when I explicity say that if it is bigger or equal than 1, the Property should remain with her original value.&lt;/P&gt;

&lt;P&gt;Proof matched = 1 &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4162i0F4596A6F0B2C4A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thoughts on this ?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 14:46:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310944#M93226</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2018-01-18T14:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310945#M93227</link>
      <description>&lt;P&gt;Can you try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval matched=0 | foreach UF* [eval matched = if(like('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',valMask),matched+1,matched) ]| foreach UF* [eval Property=if(matched&amp;gt;=1,Property,null)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jan 2018 15:09:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310945#M93227</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-18T15:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310946#M93228</link>
      <description>&lt;P&gt;Same result.. What was your reasoning ?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 15:42:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310946#M93228</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2018-01-18T15:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310947#M93229</link>
      <description>&lt;P&gt;The structure generally looks ok, so I'm kind of reaching here. Any chance &lt;CODE&gt;Property&lt;/CODE&gt; was null before the second half of the &lt;CODE&gt;foreach&lt;/CODE&gt; ran? If you remove the second &lt;CODE&gt;eval&lt;/CODE&gt; clause, is &lt;CODE&gt;Property&lt;/CODE&gt; always populated?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 16:22:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310947#M93229</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-18T16:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310948#M93230</link>
      <description>&lt;P&gt;I removed the eval clause, and all the &lt;CODE&gt;Properties&lt;/CODE&gt; get populated.. &lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 16:28:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310948#M93230</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2018-01-18T16:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310949#M93231</link>
      <description>&lt;P&gt;The only possibility I'm seeing is that &lt;CODE&gt;matched&lt;/CODE&gt; is still 0 inside the &lt;CODE&gt;foreach&lt;/CODE&gt;. Like a lazy interation&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 16:32:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310949#M93231</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2018-01-18T16:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach weird bug in variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310950#M93232</link>
      <description>&lt;P&gt;So apparently, &lt;CODE&gt;matched&lt;/CODE&gt; inside the &lt;CODE&gt;foreach&lt;/CODE&gt; is still 0. Something like Lazy Evaluation, but I don't really know. Anyway.. this works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foreach UF* [eval matched = if(like('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;',valMask),matched+1,matched)] | eval Property =  if(matched&amp;gt;=1,Property,null) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Jan 2018 16:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-weird-bug-in-variable/m-p/310950#M93232</guid>
      <dc:creator>greggz</dc:creator>
      <dc:date>2018-01-18T16:35:54Z</dc:date>
    </item>
  </channel>
</rss>

