Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: How to open files found via File::Find

by gam3 (Curate)
on Jan 08, 2010 at 00:33 UTC ( #816195=note: print w/replies, xml ) Need Help??

in reply to How to open files found via File::Find

You are using single quotes in you open statements. try
open INFILE2,'<', $localfile ...
and you should have better luck. You also need 2 backslashes in a double quoted string. Or use $directory . '\' . $name.
use strict; use warnings; use Cwd; my $startdirectory = cwd; print "Starting directory: $startdirectory\n"; use File::Find; find ( \&inFiles, ('.') ); exit; sub inFiles { chomp; my $name = $_; my $directory = cwd; if ( $name =~ /.dat/) { print "dir = $directory\tname = $name\n"; open INFILE,'<', "$directory/$name" || warn ("Cannot open input fil +e $name\n"); my @infilecontent = <INFILE>; print length @infilecontent; my $localfile = "$directory\\$name"; #win32 open INFILE2,'<', $localfile || warn ("Cannot open input file $loca +lfile\n"); @infilecontent = <INFILE2>; print @infilecontent; } } #inFiles
-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^2: How to open files found via File::Find
by roboticus (Chancellor) on Jan 08, 2010 at 14:07 UTC

    For better portability, I'd suggest using "/" rather than "\\" as a directory separator.


      Or even better use File::Spec->catfile.
      -- gam3
      A picture is worth a thousand words, but takes 200K.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://816195]
[MidLifeXis]: hahaha: Just received a buzz-word-bingo- compliant email (internal) that starts with "%Firstname% %Lastname%...". It only gets better from there.
choroba finds working in a small company boring comparing to a large corporation
[MidLifeXis]: At least test before mass distribution.
[MidLifeXis]: More opportunities for anonymous snafus :-)
[MidLifeXis]: In a small group / company, at least you know who needs to buy the next round of beer for their mess-up.
[MidLifeXis]: :-)
[Discipulus]: are sure you are not really named "%Firstname% %Lastname%..." ? have you check your identity card?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-01-19 12:14 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (170 votes). Check out past polls.