Skip to main content
added 24 characters in body
Source Link
g4v3
  • 241
  • 1
  • 4

Perl 5, 27 32 22 bytes

{{open my$h,'>o'}redo}

If simply changing the modification timestamp of a file suffices...

Quick explanation:

{ # Braces implicitly create/mark a loop.
    { # New,They morealso localizedcreate scopeclosures, for `my` variablevariables.
        open my $filehandle, '>', 'o';    # Writing to file "o".
        # close $filehandle;   # Called implicitly when
                               # variable gets destroyed.
    } # Scope$filehandle gets destroyed;destroyed sobecause doesthere $filehandleare no references to it.
    redo; # ...the loop.
}

Previous solution (32 bytes): {{open my$h,'>o';print$h 1}redo}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Perl 5, 27 32 22 bytes

{{open my$h,'>o'}redo}

If simply changing the modification timestamp of a file suffices...

Quick explanation:

{ # Braces implicitly create/mark a loop.
    { # New, more localized scope, for `my` variable.
        open my $filehandle, '>', 'o';    # Writing to file "o".
        # close $filehandle;   # Called implicitly when
                               # variable gets destroyed.
    } # Scope gets destroyed; so does $filehandle.
    redo; # ...the loop.
}

Previous solution (32 bytes): {{open my$h,'>o';print$h 1}redo}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Perl 5, 27 32 22 bytes

{{open my$h,'>o'}redo}

If simply changing the modification timestamp of a file suffices...

Quick explanation:

{ # Braces implicitly create/mark a loop.
    { # They also create closures, for `my` variables.
        open my $filehandle, '>', 'o';    # Writing to file "o".
        # close $filehandle;   # Called implicitly when
                               # variable gets destroyed.
    } # $filehandle gets destroyed because there are no references to it.
    redo; # ...the loop.
}

Previous solution (32 bytes): {{open my$h,'>o';print$h 1}redo}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

It seems changing file metadata is considered enough for solving the problem, so...
Source Link
g4v3
  • 241
  • 1
  • 4

Perl 5, 27 3232 22 bytes

{{open my$h,'>o';print$h 1'>o'}redo}

If simply changing the modification timestamp of a file suffices...

Quick explanation:

{    # <-- Braces implicitly create/mark a loop.
    {    # <-- New, more localized scope, for `my` variable.
        open my $filehandle, '>', 'o';      # Writing to file "o".
        print $filehandle 1;    # Yes, no comma there!
                                # Search "Indirect Object Notation".
        close $filehandle;    # Called automaticallyimplicitly when the
                               # variable gets deleteddestroyed.
    }    # <-- Scope gets destroyeddestroyed; so does $filehandle.
    redo;  # ...the loop!.
}

Previous solution (32 bytes): {{open my$h,'>o';print$h 1}redo}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Perl 5, 27 32 bytes

{{open my$h,'>o';print$h 1}redo}

Quick explanation:

{    # <-- Braces implicitly create/mark a loop.
    {    # <-- New, more localized scope, for `my` variable.
        open my $filehandle, '>', 'o';      # Writing to file "o".
        print $filehandle 1;    # Yes, no comma there!
                                # Search "Indirect Object Notation".
        close $filehandle;    # Called automatically when the
                              # variable gets deleted.
    }    # <-- Scope gets destroyed.
    redo;  #...the loop!
}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Perl 5, 27 32 22 bytes

{{open my$h,'>o'}redo}

If simply changing the modification timestamp of a file suffices...

Quick explanation:

{ # Braces implicitly create/mark a loop.
    { # New, more localized scope, for `my` variable.
        open my $filehandle, '>', 'o';    # Writing to file "o".
        # close $filehandle;   # Called implicitly when
                               # variable gets destroyed.
    } # Scope gets destroyed; so does $filehandle.
    redo; # ...the loop.
}

Previous solution (32 bytes): {{open my$h,'>o';print$h 1}redo}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Corrected the code so that it actually works
Source Link
g4v3
  • 241
  • 1
  • 4

Perl 5, 2727 32 bytes

{{open Fmy$h,'O';print F'>o';print$h 1;redo1}redo}

Expanded versionQuick explanation:

{    # <-- Braces implicitly create/mark a loop.
    {    # <-- New, more localized scope, for `my` variable.
        open FILEHANDLEmy $filehandle, 'O';'>', 'o';      # Writing to file "o".
        print FILEHANDLE$filehandle 1;    # Yes, no comma there!
    redo;                            # RedoSearch "Indirect Object Notation".
        close $filehandle;    # Called automatically when the 
 loop code                            # variable gets deleted.
    }    # <-- Scope gets destroyed.
    redo;  #...the loop!
}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Perl, 27 bytes

{open F,'O';print F 1;redo}

Expanded version:

{    # <-- Braces implicitly create a loop.
    open FILEHANDLE, 'O';
    print FILEHANDLE 1;
    redo;  # Redo the loop code.
}

Perl 5, 27 32 bytes

{{open my$h,'>o';print$h 1}redo}

Quick explanation:

{    # <-- Braces implicitly create/mark a loop.
    {    # <-- New, more localized scope, for `my` variable.
        open my $filehandle, '>', 'o';      # Writing to file "o".
        print $filehandle 1;    # Yes, no comma there!
                                # Search "Indirect Object Notation".
        close $filehandle;    # Called automatically when the 
                              # variable gets deleted.
    }    # <-- Scope gets destroyed.
    redo;  #...the loop!
}

Edit: {open F,'O';print F 1;redo} ← Didn't test the code before posting; now I had to correct it.

Added details
Source Link
g4v3
  • 241
  • 1
  • 4
Loading
Source Link
g4v3
  • 241
  • 1
  • 4
Loading