one key hash
C. Abney
cabney at cyberpass.net
Fri Feb 25 14:14:22 CST 2000
~sdpm~
On Thu, 24 Feb 2000, Bob Forgey wrote:
> ... I would probably use
> keys(%foo_h)[0]
> instead of the `each %foo_h', just to be explicit.
I tried that and couldn't get it to work. Made sense to me too, otherwise.
It's a bit wordier than mine, but tells you exactly what you want to do.
I even tried it with a symref... :(
> I presume you're using `tar tvf ...', which is the reason for the map
> function, instead of a chomp?
Yes, and that it'll also work with (for example) long file listings, or
ftp->ls(), or...
my root dir test was really messed up, though. Here's a mod on the
script (and in usable form!)
============================================================
#! /usr/bin/perl
# Takes output from a tarball manifest listing and checks that only one
# toplevel directory/file exists.
# just do a 'tar tvfz bar.tar.gz | onekeyhash.pl'
@flist = map +(split)[-1], <>;
# Danger: tar Pczf bar.tar.gz meme proxy /vmlinuz
# this grabs the topmost directory/file name(s) from the tar manifest
for (@flist) { $foo_h{$1}++ if m|([^/]+)|; $augh++ if m|^/|; };
die "someone's out to get you\n" if ( $augh );
die "more than one topmost directory or file\n" if ( keys (%foo_h) != 1 );
$top = each (%foo_h);
print "topmost directory: $top\n";
============================================================
Thanks for the tips...
CA
--
Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein. -- Larry Wall C. Abney
~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