Skip to content

Conversation

mauke
Copy link
Contributor

@mauke mauke commented Aug 22, 2025

Time::HiRes::sleep is supposed to be a drop-in replacement for CORE::sleep, but before this patch Time::HiRes::sleep had no prototype, leading to the following incompatibilities:

CORE::sleep(1, "foo", "bar");  # syntax error
Time::HiRes::sleep(1, "foo", "bar");  # OK, ignores all but 1st argument

my @t = 42;
CORE::sleep @t;  # sleeps for one second (number of elements in @t)
Time::HiRes::sleep @t;  # sleeps for 42 seconds (@t in list context)

CORE::sleep 1, next if $foo;
# if $foo, then sleep for one second and start next loop iteration

Time::HiRes::sleep 1, next if $foo;
# parses as: Time::HiRes::sleep(1, next) if $foo;
# if $foo, then start next loop iteration; no delay

Fixes #23628.


  • This set of changes requires a perldelta entry, and it is included.

mauke added 3 commits August 23, 2025 10:06
Time::HiRes::sleep is supposed to be a drop-in replacement for
CORE::sleep, but before this patch Time::HiRes::sleep had no prototype,
leading to the following incompatibilities:

    CORE::sleep(1, "foo", "bar");  # syntax error
    Time::HiRes::sleep(1, "foo", "bar");  # OK, ignores all but 1st argument

    my @t = 42;
    CORE::sleep @t;  # sleeps for one second (number of elements in @t)
    Time::HiRes::sleep @t;  # sleeps for 42 seconds (@t in list context)

    CORE::sleep 1, next if $foo;
    # if $foo, then sleep for one second and start next loop iteration

    Time::HiRes::sleep 1, next if $foo;
    # parses as: Time::HiRes::sleep(1, next) if $foo;
    # if $foo, then start next loop iteration; no delay

Fixes Perl#23628.
Bareword filehandles have been obsolete since 2000. There is no point in
adding '1;' to scripts; only modules have return values.
@mauke mauke force-pushed the fix-23628-time-hires-sleep-prototype branch from cece5bd to 01c4539 Compare August 23, 2025 08:15
@mauke mauke merged commit 079dff6 into Perl:blead Aug 24, 2025
33 checks passed
@mauke mauke deleted the fix-23628-time-hires-sleep-prototype branch August 24, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Time::HiRes::sleep takes multiple args, incompatible behavior with core sleep()

4 participants