Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

question about star character in Perl

by dicty (Sexton)
on Jan 17, 2013 at 23:25 UTC ( #1013913=perlquestion: print w/ replies, xml ) Need Help??
dicty has asked for the wisdom of the Perl Monks concerning the following question:

I have a question about "*" character in Perl. In the code below, what does "*" or "*XML" mean?

open (XML, "<$xml_file");

get_data(*XML, \%hash);

Thanks a lot!


Comment on question about star character in Perl
Replies are listed 'Best First'.
Re: question about star character in Perl
by kennethk (Abbot) on Jan 17, 2013 at 23:41 UTC
    The * sigil refers to Typeglobs and Filehandles. In this case, the author wanted to pass the newly-opened XML filehandle into a subroutine, and old fashioned Perl didn't have a particularly clean way to pass one. Nowadays, you'd probably write that as:
    open (my $XML, "<", $xml_file) or die "File open failed ($xml_file): +$!; get_data($XML, \%hash);

    The indirect filehandle makes passing and stashing much cleaner (IMHO). See also open and Indirect Filehandles in perlopentut.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Got it. Thanks a lot!
Re: question about star character in Perl
by davido (Archbishop) on Jan 17, 2013 at 23:38 UTC

    The '*' character in this context is a sigil for typeglobs. It is to typeglobs approximately as '$' is to scalars, '%' is to hashes, '@' is to arrays, and '&' is to subroutines.

    See perldoc perldata | Typeglobs and Filehandles.

    In this case 'XML' is a bareword filehandle. It is being passed as a typeglob to the get_data() function, which presumably is populating %hash with a dump of the XML file.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1013913]
Approved by Old_Gray_Bear
Front-paged by Lotus1
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2015-11-28 12:46 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls