Thread Perlverhalten bei undef im Schleifenkopf 5.18 und 5.20 (13 answers)
Opened by bianca at 2016-10-23 07:14

bianca
 2016-10-25 10:49
#185540 #185540
User since
2009-09-13
7016 Artikel
BenutzerIn

user image
Danke allen bisherigen Antworter(-inne)n!

Ist denn nun das readline() oder das scalar() Schuld?
Ich kann mit diesem Script die darunter folgenden Ergebnisse reproduzieren:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
local $Data::Dumper::Purity;
$Data::Dumper::Purity = 1;
local $Data::Dumper::Useqq;
$Data::Dumper::Useqq = 1;
local $Data::Dumper::Sortkeys;
$Data::Dumper::Sortkeys = sub {
    my ($hash) = @_;
    return [(sort {lc $a cmp lc $b} keys %$hash)];
};
use 5.010;
use Fcntl;


sysopen(my $fh,'test.txt',O_RDWR|O_CREAT) or die $!;
say "scalar:   ".scalar($fh);
say "readline: ".readline(0);
foreach my $in (split(/,/,readline(scalar($fh)))) {
    say "lesen";
}


perl 5, version 18, subversion 4 (v5.18.4) built for MSWin32-x64-multi-thread:
Quote
scalar: GLOB(0x55c200)
readline() on unopened filehandle 0 at test.pl line 20.
readline:


perl 5, version 20, subversion 2 (v5.20.2) built for x86_64-linux-gnu-thread-multi:
Quote
readline() on unopened filehandle 0 at test.pl line 20.
Use of uninitialized value in concatenation (.) or string at test.pl line 20.
Use of uninitialized value in split at test.pl line 21.
10 print "Hallo"
20 goto 10

View full thread Perlverhalten bei undef im Schleifenkopf 5.18 und 5.20