Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

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



  • 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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found