in reply to Re^6: Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
in thread Error in insertion of MULTIPLE FILENAMES & CONTENTS INTO DATABASE
foreach (@files) { open FILE, "$_" or die $!; print "$_", br() x3; $_ = map m{([^/]+)\.txt}, $_; #Strip out of the string the path + and extension leaving only the filename intact ... }
(Perverted enough to poke my eye with the Red Ryder BB gun.)
Why do you need to invoke map when m// would have been just fine? Instead of abusing $_ (and thus modifying @files), why not just assign the matched captured text to a normal variable?
As for getting 1s, from perldoc -f map ...
- map BLOCK LIST
- map EXPR,LIST
- Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value composed of the results of each such evaluation. In scalar context, returns the total number of elements so generated.
Added the next day ... Or, instead of "$_ = map ..., $_", try similar to one of these ...
( my $name ) = m{ ([^/]+) \.suffix }x; # or, my $name = ( m{ ([^/]+) \.suffix }x )[0]; # or, use File::Basename; my $name = fileparse( $_ , qr{ \.suffix }x );
|
|---|