On Thu, 2018-05-17 at 15:22 +0100, Daniel P. Berrangé wrote:
> On Thu, May 17, 2018 at 04:10:37PM +0200, Andrea Bolognani wrote:
> > A friend suggested
> > 
> > diff --git a/guests/lcitool b/guests/lcitool
> > index 568e52c..5855368 100755
> > --- a/guests/lcitool
> > +++ b/guests/lcitool
> > @@ -21,7 +21,7 @@ hash_file() {
> >      perl -le '
> >          my @chars = ("A".."Z", "a".."z", "0".."9");
> >          my $salt; $salt .= $chars[rand @chars] for 1..16;
> > -        open(my $handle, "'"$PASS_FILE"'"); my $pass = <$handle>; chomp 
> > $pass;
> > +        open(my $handle, "'"$PASS_FILE"'"); chomp(my $pass = <$handle>);
> >          print crypt("$pass", "\$6\$$salt\$");'
> >  }
> > 
> > would be more idiomatic: mind if I squash that in before pushing?
> 
> Not sure I'd really agree - in fact at first glance I didn't expect this
> to even work, because its declaring a variable inside a functin parameter.
> I tested and it does work, but I find your original clearer.

I was surprised as well, but then I noticed we're doing the same
thing with open() too :)

Can't say I disagree with you, though. We could actually go a bit
further and apply

diff --git a/guests/lcitool b/guests/lcitool
index 568e52c..0c1520e 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -21,7 +21,8 @@ hash_file() {
     perl -le '
         my @chars = ("A".."Z", "a".."z", "0".."9");
         my $salt; $salt .= $chars[rand @chars] for 1..16;
-        open(my $handle, "'"$PASS_FILE"'"); my $pass = <$handle>; chomp $pass;
+        my $handle; open($handle, "'"$PASS_FILE"'");
+        my $pass = <$handle>; chomp($pass);
         print crypt("$pass", "\$6\$$salt\$");'
 }

instead. I don't particularly care either way, but being consistent
seems preferable than using both approaches in the same line.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to