Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

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

Am trying to read directory/subdirectories and for files from a path recursively. Once file found in any directory, reading file content(usually just 1 line in a file) and substituting space with comma from the line. then I need to pass the values to another sub functions.

Problem : 1. line number 35 doesn't seems to be working. when i try to print $line, it doesn't show anything/value. 2. Need to pass @columns/@filenames/@dir_names to the sub function(&write_output) called in line number 46.

Can someone tell me where am doing wrong and help me out

I need to know is there any tool/utlity for Windows XP where in which in can run the perl script line by line debugging mode so, that i can see what's happen to the variables during run time.

Many Thanks...
#! /usr/bin/perl use warnings; use strict; use File::Find; use File::Basename; my $base_dir = 'C:\Perl\TestData'; my (@columns,@dirs,@buf,@dir_names,@filenames); my ($dir,$file,$resultxmlfile,$line,$fh); $line=''; sub process_files { print "dive into: $_[0]\n"; opendir DIR, $_[0] or die "Could not open directory"; print $_[0]; print "\n"; @dirs = readdir DIR; closedir DIR; foreach $file (@dirs) { if ($file =~ /\.{1,2}/) {next } print "processing: $file\n"; if ( -d "$_[0]/$file" ) { process_files ("$_[0]/$file"); push(@dir_names, basename($file)); print @dir_names; print "\n"; foreach my $file (@dirs){ print $file; next if $file eq '.' or $file eq '..'; print "\n"; open (FILE, "<", $file) or die "Could not open file -- $_[0] +/$file"; @buf = <FILE>; foreach $line (@buf) { $line = <FILE>; # this line doesn't work. don't know w +hat's wrong here.. $line=~ s/ /,/g; print $line; push(@columns,$line); print @columns; print "\n"; $file =~ s/.*\///; $file =~ s/\.[^.]+$//; push(@filenames, $file); print @filenames; } &write_output; # need to pass @columns/@filenames/@dir +_names values to this function close FILE; } } } } process_files $base_dir;

In reply to process a file and reading a line and passing the values to another sub function by Vijay81

Title:
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!
  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (11)
    As of 2015-07-07 09:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (88 votes), past polls