Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

question about star character in Perl

by dicty (Sexton)
on Jan 17, 2013 at 23:25 UTC ( [id://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!

Dicty

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 (Cardinal) 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.


    Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found