Common file operations

  • Thread starter Shmuel (Seymour J.) Metz
  • Start date
U

Uri Guttman

SM> Typo. That should have been

SM> if (@dirs==0) {

if you get anything from this, it is to use strict so you don't get
spelling bugs like this.

uri
 
M

Michele Dondi

But would it be as clear?

IIRC the original code was

print '@ARGV=(',join(',',@ARGV),")\n";

so, even if readability/clarity is to a large extent a personal
matter, I would say: YES. However it is worth pointing out that indeed
the advantage for a single string is not so relevant, but since you
were printing many entries like that, you *may* have earned much by
wrapping the whole section in a block and locally setting the relevant
variables there:

{
local ($\, $,)=("\n", ',');
print "\@ARGV=(@ARGV)";
...
print "\@DIRS=(@DIRS)";
...
}

You're right; I need parentheses around the comparisons.

Another good reason for not retyping code, but to paste instead, as
people often suggest here.
Typo. I meant

elsif (@dirs>1) {
die "$dir matches multiple directory names:\n",
' ', join("\n ",@dirs),"\n";

Which indents for readability.

Personally I don't see any usefulness in that, but I'm not contending
your claim since I understand that it's something depending solely on
one's taste.
What is the reason for mixing styles here, as opposed to putting the
tests on the same ends?

No good reasons, I'm afraid. Again, a matter of personal tastes: I'm
not bothered by the mixing of styles and OTOH I like to use logical
operator's short circuiting but I like it better with some constructs
and I like it less with some others. All in all the example code
snippet quoted above 'sounds good' which is fine for me. If you prefer
to avoid any mix of styles and cosider that more elegant, of course
I'm not contending that in any way...

BTW: I'm not golfing, but I'm lazy and since

@dirs or die "`$dir' doesn't match any directory name\n";

and

die "`$dir' doesn't match any directory name\n" unless @dirs;

'sound just as good' but the latter costs a few more keystrokes, I've
probably instinctively chosen the former. Of course another
possibility (amongst the seemingly infinite ones) could have been "if
!@dirs", but hey, that would have costed me pressing the shift key!
Jokes apart, in these situations *generally* I prefer C<unless>. But
then this is yet another one of those matters of personal
preferences...
That's how I got the text I quoted, in

=head1 DESCRIPTION
=head2 Warning on \1 vs $1

It seemed more relevant than the text in

=head1 DESCRIPTION
=head2 Regular Expressions

since I wasn't using $&, $' or $`.

Well, whatever, 'WARNING' ne 'Warning'. It was relevant though in that
you were concerned in possible performance issues with "my solution"
as opposed to "your solution" and mine was not capturing while yours
was: in fact you weren't "using $&, $' or $`", but indeed you were
using $1. Also I wrote that you *may* have been interested; since you
were concerned about performance issues anyway.


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top