Carl Inglis <carl.ing...@gmail.com> writes:

> Interesting - in perl 5.10.1 on my system it works as expected.
>
> One point to note, your "$myscript" in your usage should be escaped
> otherwise you get an error.

No.  That changed in some previous version a while ago I
believe... any way I haven't needed quoting in that usage for several
version upgrades... maybe a year or longer.

> You might want to:


> use Data::Dumper;
> print Dumper(@ARGV);

I'll try try that next time... thanks.

Mystery solved by Rob D... I was looking at one script and running a
different one.

[...]

Kent Fredric <kentfred...@gmail.com> writes:

> On 19 November 2014 11:46, Harry Putnam <rea...@newsguy.com> wrote:
>
>> Only thing I did to debug was to make sure `use File::Find; comes
>> after if (!@ARGV), but that seems not to matter.
>>
>
> That will be because 'use' is processed during BEGIN { }, while your
> condition is during the main execution phase.

I thought it might be something like that.... thanks.


Rob Dixon <rob.di...@gmx.com> writes:

[...]

> There are a few issues with your code, but nothing that would cause the
> symptoms you describe. Are you sure you're running the code you think
> you are?

Dead on; What a dope, my only lame excuse is that I have that script in
a mirrored dir too, and was running the mirror and editing the
source.... egad..

> Rather than
>
>     if (!@ARGV) { ... }
>
> I would prefer to see
>
>     if ( @ARGV == 0 ) { ... }
>
> which makes the intention much clearer.

With your massive experience, I'm pretty sure what you say there is
right... but just not seeing how !@ARGV is less clear than  @ARGV == 0.

Or is a matter of poor coding ... ?


> You also need to define `$myscript` *before* that `if` statement, as
> otherwise there is nothing for `usage` to use. It would be best written as
>
>     my ($myscript) = $0 =~ m{([^/]+)$};

Ah thanks for the formulation... Nice and clear.  

So far as placement; Egad that is a blunder I've made a number of
times... which I eventually catch when I notice that the usage() print
out lacks the script name...

> Finally, you need to ensure that `@trgs` isn't empty after removing any
> non-existent directories. I would write it like so
>
>     my @trgs;
>
>     for (@ARGV) {
>       if (-d) {
>         push @trgs, $_;
>       }
>       else {
>         print "Whoops, no directory <$_> found on system .. skipping\n";
>       }
>     }
>

>     die "No valid directories found" unless @trgs;

That looks like the cure for a nasty little blunder that might have lead
to lots of head scratching on my part ... in case all dir were
ditched.

Thanks a lot for all help.  Very useful.

Oh and, since I've already exposed the true depth of my ignorance, and
if you have time, please, feel free to point out other problems you
noticed in the code.

I code only sporadically and in a vacuum... home user, little or no
interaction with other perl folks... other than here on this list.  I
rarely see how other people do things, unless I specifically google up
some examples of something. So, I probably suffer from many really
poor habits and ways of doing things that are pretty sorry.

Any comments would be quite useful.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to