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

Comment on

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

Either learn how to use the debugger or Data::Dumper. I've modified your code to dump some values. They are not quite what you expect!

#!/usr/bin/perl -w use Data::Dumper; use strict; my $dir = 'C:\Users\ZB\Desktop\Text Files'; $dir = 'c:'; opendir (DIR, $dir) or die "cannot opendir $dir"; foreach my $file (readdir(DIR)) { warn Data::Dumper->Dump([\$file],[qw(*file)]).' '; &process_file ($file); } sub process_file { warn Data::Dumper->Dump([\@_],[qw(*_)]).' '; my $line = @_; warn Data::Dumper->Dump([\$line],[qw(*line)]).' '; my @array = split(/ /, $line); print "$#array\n"; } closedir (DIR);

And this produces:

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:>perl $file = \'.'; # This is '.' at line 12. @_ = ( # Your sub get an array containing +'.' '.' ); at line 18. $line = \1; # but $line is 1 (the length of @_) + ... at line 20. # what you really wanted is my ($fi +lename) = @_; # This is the name of the file that needs to be opened/ +read/closed 0 $file = \'..'; at line 12. @_ = ( '..' ); at line 18. $line = \1; at line 20. 0 $file = \'MyOpen(0).pl'; at line 12. @_ = ( 'MyOpen(0).pl' ); at line 18. $line = \1; at line 20. 0 ...

In reply to Re: Open a directory and recursively process files by clueless newbie
in thread Reaped: Open a directory and recursively process files by NodeReaper

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the monks are chillaxin'...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (2)
    As of 2018-01-21 11:11 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (227 votes). Check out past polls.