Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

need more explanation on the second arguement in open

by greatshots (Pilgrim)
on Oct 20, 2006 at 02:24 UTC ( [id://579498]=perlquestion: print w/replies, xml ) Need Help??

greatshots has asked for the wisdom of the Perl Monks concerning the following question:

open(my $fh, "<:utf8", "foo.html") || die;
I have no Idea on the second arguement which is given in the open function. I read that line from HTML::Parser
what does that second argument do in open function?
what is the meaning of using ":utf8"?

Replies are listed 'Best First'.
Re: need more explanation on the second arguement in open
by imp (Priest) on Oct 20, 2006 at 02:28 UTC
    From open:
    You may use the three-argument form of open to specify IO "layers" (sometimes also referred to as "disciplines") to be applied to the handle that affect how the input and output are processed (see open and PerlIO for more details). For example

    open(FH, "<:utf8", "file")

    will open the UTF-8 encoded file containing Unicode characters, see perluniintro. Note that if layers are specified in the three-arg form then default layers stored in ${^OPEN} (see perlvar; usually set by the open pragma or the switch -CioD) are ignored.

Re: need more explanation on the second arguement in open
by grep (Monsignor) on Oct 20, 2006 at 02:35 UTC
    When confronted with a problem that involved the syntax of a commonly used function, I would recommend reading the docs.

    It explains:
    open(FH, "<:utf8", "file") will open the UTF-8 encoded file containing Unicode characters.

    If you've never dealt with Unicode before it says: see perluniintro



    grep
    One dead unjugged rabbit fish later
Re: need more explanation on the second arguement in open
by Hofmator (Curate) on Oct 20, 2006 at 08:51 UTC
    Also note that these IO layers are only available starting from perl 5.8

    -- Hofmator

    Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://579498]
Approved by planetscape
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: (5)
As of 2024-04-19 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found