one key hash
Bob Forgey
rforgey at grumpydogconsulting.com
Thu Feb 24 17:16:12 CST 2000
~sdpm~
Hi,
I think the hash is fine. You're putting together a set (of the
top-level directories), and then counting the number of elements. In
perl, a set is implemented as a hash in which you only care about the
keys. I would probably use
keys(%foo_h)[0]
instead of the `each %foo_h', just to be explicit. Also, I would
change the regexp
/([^\/]+)/
to
/^([^\/]+)/
so when I look at it, instead of wondering which string of non-/ it
matches, it's clear that the first one is what's wanted.
I presume you're using `tar tvf ...', which is the reason for the map
function, instead of a chomp?
Thanks
Bob
>>>>> "CA" == C Abney <cabney at cyberpass.net> writes:
CA> ~sdpm~
CA> I'm wondering if anyone can come up with a nicer way to get this key.
CA> Or even dump the hash altogether. I'm using:
CA> $top = each (%foo_h);
CA> By nicer I guess I mean more direct. I find this misleading.
CA> It's a part of the same script, in which I'm checking the manifest of
CA> a tarball for what are (to my mind) unexpected features. Obviously I'm
CA> automating an install (shhh!) of some software, and want to make sure
CA> nothing tooo out of the ordinary is happening while I'm not looking.
CA> It's a part of this code sequence:
CA> ...
CA> @flist = map +(split)[-1], @tarout;
CA> log_n_die ( "Unpack from rootdir, Huh?" ) if ( $flist[0] =~ /^\// );
CA> # this grabs the topmost directory/file name(s) from the tar manifest
CA> for (@flist) { $foo_h{$1}++ if /([^\/]+)/; };
CA> log_n_die ( "No top-level directory!!!" ) if ( keys (%foo_h) != 1);
CA> $top = each (%foo_h);
CA> ... # more checks, unpacking stuff
CA> log_n_die ( "Couldn't find PBS source dir, $top" ) unless ( -d $top );
CA> ... # and so on...
CA> I'd also appreciate a lecture on regular expressions...<g> One of the
CA> biggest gripes I hear about Perl is its obscure syntax and resulting
CA> poor maintainability. I KNOW that's wrong! I don't want to contribute
CA> to that perception and therefore welcome any hints (but I'm off topic
CA> now, and it's my own post, so... )
CA> Perhaps you've noticed this is very closely related to what I posted
CA> last time! I'm really not a slow coder, honest. Really. Weell, I have
CA> a lot of other things that get in the way. Or something. Oh, this is
CA> the next revision! Yeah, that's it.
CA> Anyway, anyone have a better way to do this?
CA> p.s. Sorry I missed the meeting. How'd it go?
CA> CA
CA> --
CA> Mighty Mouse is a cartoon. Superman is a real guy. No way a cartoon
CA> could beat up a real guy! -- Teddy C. Abney
CA> ~sdpm~
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list