[Israel.pm] typeglobs

Tal Kelrich tal at musicgenome.com
Wed Jun 27 07:23:29 PDT 2007

On Wed, 27 Jun 2007 11:56:51 +0300
"Levenglick Dov-RM07994" <dovl at freescale.com> wrote:

> Can someone please explain why call_bad doesn't print the file? What
> is the difference between it and call_good?

Try this, then read the docs referenced in comments.
here's a snippet of same:

"If what's within the angle brackets is neither a filehandle nor a
simple scalar variable containing a filehandle name, typeglob, or
typeglob reference, it is interpreted as a file- name pattern to be
globbed, and either a list of filenames or the next filename in the
list is returned, depending on context.  This distinction is determined
on syntactic grounds alone.  That means "<$x>" is always a readline()
from an indirect handle, but "<$hash{key}>" is always a glob().  That's
because $x is a simple scalar variable, but "$hash{key}" is not--it's a
hash element."

use strict;
use warnings;
use diagnostics;
use Fcntl qw(:seek);

open (IN, "$0") or die "$!\n";
seek(IN,0,SEEK_SET); #rewind the file

sub call_bad 
        my $moof;
        print "also works!\n";
        print while <$moof>;
        #for why, see perlop, grep angle brackets is neither a
sub call_good 
        print "Works\n";
        *A = $_[0];
        print while <A>;

Tal Kelrich
PGP fingerprint: 3EDF FCC5 60BB 4729 AB2F  CAE6 FEC1 9AAC 12B9 AA69
Key Available at: http://www.hasturkun.com/pub.txt
Art is a lie which makes us realize the truth.
		-- Picasso
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://perl.org.il/pipermail/perl/attachments/20070627/b3efc90e/attachment.pgp 

More information about the Perl mailing list