Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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!


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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2017-10-20 18:17 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (266 votes). Check out past polls.