Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?

In reply to conditional statement works one way, but not the other (Updated) by igoryonya

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    Domain Nodelet?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2024-07-14 23:00 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.