Hello, I am breaking my head, why this works:
if(@files && ! scalar keys %tree){$isChanged = 1;}
else{foreach my $file (@files){$isChanged = 1 && last if( grep { $
+files_cached{'stats'}{$file}{$_} != $params->{'files'}{'stats'}{$file
+}{$_} } ('mtime', 'ctime', 'size') );}}
, but this gives a syntax error:
(@files && ! scalar keys %tree)?
($isChanged = 1):
(foreach my $file (@files){$isChanged = 1 && last if( grep { $file
+s_cached{'stats'}{$file}{$_} != $params->{'files'}{'stats'}{$file}{$_
+} } ('mtime', 'ctime', 'size') )});
...?...
I checked and rechecked, but didn't find any paretacy or semicolon missing or extra.
Thanx in advance.
Here is an uncondenced version of the if code:
if(@files && ! scalar keys %tree){
$isChanged = 1;
}else{
foreach my $file (@files){
$isChanged = 1 && last if( grep { $files_cached{'stats'}{$file
+}{$_} != $params->{'files'}{'stats'}{$file}{$_} } ('mtime', 'ctime',
+'size') );
}
}
New question:
I tried to convert an expression to using map:
(@files && ! scalar keys %tree)?
($isChanged = 1):
(map { my $file = $_; if( grep { $files_cached{'stats'}{$file}{$_}
+ != $params->{'files'}{'stats'}{$file}{$_} } ('mtime', 'ctime', 'size
+') ){$isChanged = 1; last;} } @files);
Now I'm curious, I cannot break out of map execution in the middle, using last or some other means. It will process an entire list to the end? It appears that the last statement in the above code will break out of the loop, containing the map command, not from the map itself, so, I've had to remove last from the code above:
(@files && ! scalar keys %tree)?
($isChanged = 1):
(map { my $file = $_; $isChanged = 1 if( grep { $files_cached{'sta
+ts'}{$file}{$_} != $params->{'files'}{'stats'}{$file}{$_} } ('mtime',
+ 'ctime', 'size') ) } @files);
Am I correct, if so, is there actually a way to breakout of map?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.