Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Arrow Operator and questions related to Path::Class

by kennethk (Monsignor)
on Sep 11, 2012 at 15:22 UTC ( #993009=note: print w/ replies, xml ) Need Help??


in reply to Arrow Operator and questions related to Path::Class

Let's go line by through the code.

use Path::Class;

So, we'll use Path::Class. According to the linked docs, this use statement exports 2 functions: dir and file. So now we know anytime we see the function dir, we are invoking the one from Path::Class. From the docs:

dir

A synonym for Path::Class::Dir->new.

So the correct place to find docs on the object returned by dir is Path::Class::Dir. Let us continue:
# Iterate over the content of foo/bar while (my $file = $dir->next) {
Now we've invoked the method next via an arrow dereference, so we check the appropriate package for the object for the method documentation. If you didn't realize it what package it was, you can use ref to tell you via the debug statement print ref $dir;.
$dir_or_file = $dir->next()

A convenient way to iterate through directory contents. The first time next() is called, it will open() the directory and read the first item from it, returning the result as a Path::Class::Dir or Path::Class::File object (depending, of course, on its actual type). Each subsequent call to next() will simply iterate over the directory's contents, until there are no more items in the directory, and then the undefined value is returned....

So now we have either a Path::Class::Dir or a Path::Class::File, depending on what the iterator hit. In both cases, methods by the name of stringify and is_dir are available and documented in the appropriate docs. When you get to the line

next if $file->is_dir();

we see next is not associated with a object dereference, so unless Path::Class exports something by that name, it will be a Perl CORE function. So, if we check the docs, either via the web at next or on the command line via perldoc -f next, we see it's a language keyword for flow control.

This is all recoverable if you follow the logical flow of the program.


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


Comment on Re: Arrow Operator and questions related to Path::Class
Select or Download Code
Re^2: Arrow Operator and questions related to Path::Class
by nemesdani (Friar) on Sep 25, 2012 at 13:54 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-09-18 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls