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

View Raw

More Information

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

#!/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;