mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-12 22:56:34 +00:00
fhem.pl: add Each userlevel function (Forum #40022)
git-svn-id: https://svn.fhem.de/fhem/trunk@9077 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
c066ead7c5
commit
ca5b53bddd
16
fhem/fhem.pl
16
fhem/fhem.pl
@ -54,6 +54,7 @@ sub DoSet(@);
|
||||
sub Dispatch($$$);
|
||||
sub DoTrigger($$@);
|
||||
sub EvalSpecials($%);
|
||||
sub Each($$;$);
|
||||
sub FileRead($);
|
||||
sub FileWrite($@);
|
||||
sub FmtDateTime($);
|
||||
@ -4330,4 +4331,19 @@ fhemFork()
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub
|
||||
Each($$;$) # can be used e.g. in at, Forum #40022
|
||||
{
|
||||
my ($dev, $string, $sep) = @_;
|
||||
return "" if(!$defs{$dev});
|
||||
my $idx = ($defs{$dev}{EACH_INDEX} ? $defs{$dev}{EACH_INDEX} : 0);
|
||||
$sep = "," if(!$sep);
|
||||
my @arr = split($sep, $string);
|
||||
|
||||
$idx = 0 if(@arr <= $idx);
|
||||
$defs{$dev}{EACH_INDEX} = $idx+1;
|
||||
|
||||
return $arr[$idx];
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user