💾 Archived View for thrig.me › blog › 2024 › 04 › 17 › helloworld.pl captured on 2024-05-12 at 15:51:19.

View Raw

More Information

⬅️ Previous capture (2024-05-10)

-=-=-=-=-=-=-

#!/usr/bin/env perl
use 5.36.0;
use Test2::V0;

sub parse ($fh) {
    my ( $first, $second );

    my $amount = read $fh, $first, 5;
    die "read1 $!" unless defined $amount;
    die "len1 $amount" if $amount != 5;

    $amount = read $fh, $second, 5;
    die "read2 $!" unless defined $amount;
    die "len2 $amount" if $amount != 5;

    return $first, $second;
}

open my $fh, '<', \"helloworld" or die "open $!";
my ( $first, $second ) = parse($fh);
is $first,  'hello';
is $second, 'world';

done_testing;