Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Chapter 8 of intermediate perl

by actualize (Monk)
on Jun 26, 2008 at 03:23 UTC ( #694099=note: print w/replies, xml ) Need Help??

in reply to Re: Chapter 8 of intermediate perl
in thread Chapter 8 of intermediate perl

I guess the only reason is because the book may be a bit out of date. This book really focuses on how to use references. They probably created this case to serve as an example. In this chapter it is about using references with File Handles. I think that they were using this case as an example of how to create file handles on the fly with references.

I am not sure why this IO::File is used in this case. They introduce it only as a subclass of IO::Handle and give some examples on how to use it.

Thanks for the help guys,


Replies are listed 'Best First'.
Re^3: Chapter 8 of intermediate perl
by brian_d_foy (Abbot) on Jun 26, 2008 at 05:43 UTC

    Chapter 8 in Intermediate Perl is about "Filehandle References", and it's current up to 5.8. We cover lexical filehandles and the three argument open, but we also cover the IO::Handle modules too. We have three exercises for that chapter, so we use a different technique for each answer.

    As with all of our answers, it's only one way to do it. And, as with any teaching environment, you don't necessarily do things as you would in real life. Once you know the technique, you can forget it and use the one you like best. In this case, it would be the three-argument open in the section "An Even Better Way" :)

    brian d foy <>
    Subscribe to The Perl Review

      Wow, I never thought I would get a response from one of the authors. Thanks. Anyway, I was hoping to get more visibility into this specific technique.

      I like how file handles are created on the fly in this code. I was thinking that all the filehandles are created through autovivification and that a new update of that specific module closed some security holes by forcing stricter programming practices

      I am thinking the next step is to explicitly create the object with "new" if the islander hash key isn't present yet. Is there anything I can do to get the current code to run? Can I only do it by modifying the module itself?

Re^3: Chapter 8 of intermediate perl
by ikegami (Pope) on Jun 26, 2008 at 04:43 UTC

    Handles created by open are also IO::Handle objects. All IO handles are, actually. You just need to load IO::Handle (use IO::Handle;) to use the methods.

    use IO::Handle; open(my $fh, '>', $fn) or die; print $fh 'foo!'; $fh->flush(); # From IO::Handle

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://694099]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-06-24 02:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.