Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Thank you Loops and boftx!

Using the constructor for empty array as Loops showed, the script indeed ran without spewing errors.

I have looked a bit into the long script boftx pointed me at. It really remembers me of a game I liked much on old Apple II :) Many interesting Perl details, in a well-readable script. Not one of these cryptic examples in the docs... But I'll look at it tomorrow when I am not tired as now.

However, when trying to output the contents of the collected directory tree structures, I ran into another problem after adding a sub for this. I get an error "Global symbol "$mydir" requires explicit package name..." which I do not yet understand, as this is a my variable of a subroutine... Please excuse if I made an obvious blatant mistake :(

use strict; use warnings; use diagnostics; use 5.014; # so push/pop/etc work on scalars (experimental) use MooX::Struct -rw, Dirnode => [ qw( $dirname @subdlist ) ]; my $dirroot = crawldir( "."); printdirs ($dirroot); sub printdirs { my $mydir = $_; # if subdirectories exist, walk them first ### vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv PROBLEM if (@($mydir->subdlist)) { # if ($mydir->subdlist) { ### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PROBLEM foreach ($mydir->subdlist) { printdirs( $_); } } print "Dir: ", $mydir->dirname, "\n"; } sub crawldir { my $curpath = shift; my $dno = Dirnode["", []]; # my $dno = Dirnode->new(); $dno->dirname( $curpath ); opendir(DIR, $curpath); my @files = readdir(DIR); closedir(DIR); print "crawldir in directory ", $dno->dirname, "\n"; foreach (@files) { next if $_ eq '.' or $_ eq '..'; my $file_path = "$curpath/$_"; $file_path =~ s|/+|/|g; if (-d $file_path) { print "crawldir in directory ", $dno->dirname, ": calling c +rawldir( $curpath\/$_)\n"; push @{$dno->subdlist}, crawldir( "$curpath\/$_" ); } } return $dno; }

In reply to Re^4: Novice problem: How to push a MooX Struct into a list? by dissident
in thread Novice problem: How to push a MooX Struct into a list? by dissident

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-08-15 18:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found