Hi Vijay8l,
Am trying to read directory/subdirectories and for files from a path recursively
Why not use File::Find instead of doing all the jobs yourself.
..reading file content(usually just 1 line in a file) and substituting space with comma from the line.
Are you trying to create a Comma-separated values files? If yes then see Text::CSV.
Just to give a head up, using File::Find and substitution function, I did something very close to what you wanted.
Update:#!/usr/bin/perl use warnings; use strict; use File::Find; my $base_dir = '...'; # put in your base directory find( \&wanted, $base_dir ); sub wanted { return if $_ eq '.' or $_ eq '..'; if (-d) { print " >>> dive into: $_\n" if -d; } else { readout_file($_); ## call subroutine readout_file } } sub readout_file { my ($filename) = @_; open my $fh, '<', $filename or die "can't open file:$!"; while (<$fh>) { chomp; s/ /,/; ## OR s/ /,/g; if you want print $_, $/; ## OR any other subroutine you want } }
In reply to Re: process a file and reading a line and passing the values to another sub function
by 2teez
in thread process a file and reading a line and passing the values to another sub function
by Vijay81
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |