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
[...]
>> my ( $SrcDir, $TrgDir ) = @ARGV[ 1, 2 ];
>>
>> ## [HP I would have thought it would cause perl to still treat ARGV
>> as ## file names since its value is not zeroed out by the above ##
>> operations, but apparently that is not a problem
>> ## ]
>
> @ARGV is just an array, you can process its contents in whatever way
> you like. The contents are assumed to be file names when you use the
> special <> readline operator.
Good to know I guess I'm revealing how shell scripting led me here...
[...]
>
> It is used to limit the scope of the lexical variables, particulary the
> directory handle $dh which will be closed automatically when it goes
> out of scope.
[...]
OK, I'm starting to see how the idea of limiting scope is supposed to
work.
>> ## [ 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;'
But I'm still wondering why its necessary or a good idea to use the
size checking and raw. What would be the result if a file failed the
test or conversely if one got copied over that didn't satisfy such a
test?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/