develooper Front page | perl.perl5.porters | Postings from July 2013

package-parsing bug in warn/die filehandle reporting

Thread Next
From:
Tom Christiansen
Date:
July 3, 2013 01:07
Subject:
package-parsing bug in warn/die filehandle reporting
Message ID:
613.1372813614@chthon
This shows a curious thing:

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use Symbol qw(qualify_to_ref);

    my @files = ( "/etc/motd" );
    push @files, qq(cat -n $files[0] |);
    push @files, qq(cat -n '$files[0]' |);

    for my $file (@files) {
	my $fh = qualify_to_ref($file);
	open($fh, $file) || die "Can't open $fh: $!";
	while (<$fh>) {
	    print;
	} 
	warn "all done with file";
	close $fh;
    } 

The last one is misinterpreting the single quote as a package separator:

    OpenBSD 4.4 (GENERIC) #0: Tue Oct 21 10:02:18 MDT 2008

    all done with file at bugtest line 17, </etc/motd> line 2.
	 1  OpenBSD 4.4 (GENERIC) #0: Tue Oct 21 10:02:18 MDT 2008
	 2  
    all done with file at bugtest line 17, <cat -n /etc/motd |> line 2.
	 1  OpenBSD 4.4 (GENERIC) #0: Tue Oct 21 10:02:18 MDT 2008
	 2  
    all done with file at bugtest line 17, < |> line 2.

That seems unfortunate.

--tom

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About