Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3482136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:31:27+00:00 2026-05-18T10:31:27+00:00

I recently came across an interesting line of code that waits until a particular

  • 0

I recently came across an interesting line of code that waits until a particular file springs to life:

sleep 1 until -e $file;

While at face value the line does what one expects it to, I can’t but help feel that something is not right here; it just seems more natural to write the following:

while (1) {

    sleep 1;
    last if -e $file;
}

Are the file test operators intended for use only with if and unless? And are there any performance penalties in deploying such operators within while conditionals?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:31:28+00:00Added an answer on May 18, 2026 at 10:31 am

    There is no difference between using a file test operator in a while-true (while) vs a while-false (until) loop, or by separating out the test with an if/unless, nor is there a difference with anything else in Perl.

    The only magical case with the while loop is ... while <$handle>; or while (<$handle>) {...} which sets $_ to the next line while it is defined. And it doesn’t really make sense to use the while-false (until) loop with bare handles.

    The a until b construct is simply a while not b.

    To convert sleep 1 until -e $file; into a while loop, you would use the following:

    sleep 1 while not -e $file;
    

    This can then be expanded to the block form:

    while (not -e $file) {sleep 1}
    

    Or as an infinite while with internal escape:

    while (1) {
       last if -e $file;
       sleep 1;
    }
    

    And all of these forms are equivalent.

    Answering the rest of your question, most file systems should be fine with 1 second sleeps between checks, but you many way to pick a larger number if the process is not urgently waiting on the file. Also if you are on a device with a slow file system (stored in flash memory or via slow network) you might want to experiment with larger values as well.

    And as ysth nitpicks below, in general, statement forms return differently than block forms when they are the last element of a construct that returns: do {...}, sub {...}, do FILE, eval …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An interesting issue came up recently. We came across some code that is using
I recently came across some Java code that simply put some strings into a
I've recently came across a very interesting inconsistency while using libxml++ (a C++ wrapper
I recently came across a bit of not-well-tested legacy code for writing data that's
I recently came across some code that looks something like this: <head> <?php /*
I recently came across the following line of code: var type = (typeof x).toLowerCase();
I recently came across some code that looked like: if(sizeof(var,2) == 4) { ...
I recently came across this line in a code - fprintf(logfile, |-IP Version :
I recently came across a piece of code, that I thought was very funny.
I recently came across this line in a PHP script: $_REQUEST['start_date']=$date; Is it allowed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.