On Monday 03 December 2007 15:19, [EMAIL PROTECTED] wrote:
> John W.Krahn <[EMAIL PROTECTED]> writes:
> > On Monday 03 December 2007 10:34, [EMAIL PROTECTED] wrote:
> >> John W.Krahn <[EMAIL PROTECTED]> writes:
> >> > If you want to incorporate the grep into the perl program then
> >> > this may work (UNTESTED):
> >>
> >> It works with 1 change and one caveat, The cavaet is that the
> >> file names in $ARGV must be absolute format or the program fails.
> >
> > The following program does not use the $ARGV variable, nor does
> > Perl use it.
>
> Make that @ARGV.
>
> >> That
> >> has something to do with File::Finds builtin of cd ing to the
> >> source directory I think.
> >
> > ???
>
> Try this test:
> ls src
> 1 100 102 104 106 108 11 111 113 115
> 10 101 103 105 107 109 110 112 114 116
>
> ls dest
> (nothing in it yet)
>
> ./Krahn1.pl 'Subject:' src dest
> Cannot open 'dest/1' No such file or directory at ./Krahn1.pl line
> 38.
>
> Now with absolute names in @ARGV.
>
> ./Krahn1.pl 'Subject:' `pwd`/src `pwd`/dest
> <20> files copied from:
> /home/reader/projects/perl/work/src
> to
> /home/reader/projects/perl/work/dest
> <20> files now in: /home/reader/projects/perl/work/dest
>
> I thought it might be because File::Find cds to the target dir then
> names like src dir or ./src ./dir fail. Just guessing
OK, that's my mistake, as I said I didn't test it ... oops. :-)
You can either use File::Find's no_chdir option:
find { no_chdir => 1, wanted => sub {
# same code here
} }, $SrcDir;
Or you can prepend the cwd to the $TrgDir variable:
use Cwd;
$TrgDir = getcwd() . "/$TrgDir" unless $TrgDir =~ /\A\//;
> >> ## [ I don't really understand why some of the processing is done.
> >> I ## hadn't seen `:raw' used before but apparently the :raw part
> >> is ## there to handle the possiblitiy of different line endings in
> >> the ## files. Then size is checked; apparently to ensure the size
> >> reported ## in -s is the same when `read'
> >
> > Correct.
> >
> >> ## And then the data is `printed' to its new home instead of just
> >> ## being copied there.... why is that being done?
> >
> > It is being copied, since all the data from the old file is in the
> > $data variable it is copied to the new file.
>
> I guess I can see why you might want to use that printing technique
> so as not to have to bring in `use File::Copy;'
If you used File::Copy then it would have to open the file and read and
write the contents again, but since you already have the contents of
the file in $data in order to match it you can just print $data to the
new file.
> But I'm still wondering why its necessary or a good idea to use the
> size checking and raw.
perldoc -f binmode
> What would be the result if a file failed the test
It would mean that read() did not read the entire file contents.
> or conversely if one got copied over that didn't satisfy such a
> test?
It would mean that there is a possibility that not all of the data was
copied correctly.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/