in reply to Re: Grave accent caveats
in thread Grave accent/Backtick/`` caveats

Thanks for checking!

I get:

98bed27374f41bdef95f4dbc6cb3ff3728721837 and
fb723667fcd81966afcd60ec6b9d6eab364e0a31

I am on Mac OS X with perl v5.8.8, now I am beginning to wonder if it is caused by the Mac environment. I just fired a test on a Linux VM, and I get identical results for $hash1 and $hash2 too! Any perl users on Mac here?

Replies are listed 'Best First'.
Re^3: Grave accent caveats
by derby (Abbot) on Jan 19, 2009 at 17:38 UTC

    Try bypassing the backtick operator and use IPC::Open2

    #!/usr/bin/perl use Digest::SHA1; use IPC::Open2; use strict; use warnings; my $text = "deepak.gulati"; my $hash1 = do_openssl( $text ); my $hash2 = Digest::SHA1::sha1_hex( $text ); print $hash1, "\n"; print $hash2, "\n"; sub do_openssl { my $text = shift; open2( my $rfh, my $wfh, 'openssl dgst -sha1' ) || die "cannot open: + $!\n"; print $wfh $text; close( $wfh ); my $value = <$rfh>; close( $rfh ); chomp( $value ); return $value; }

    -derby
      Thanks a ton! This gave identical result for $hash1 and $hash2. Any idea why backticks are problematic here?

        I'm guessing that the 'echo' command perl is picking up for use is not the same one you're using from the command line (which is probably not the standalone echo command but a shell builtin). You can play around by providing the full path to stand-alone echo (in both your perl script and on the command line) to see what happens.

        -derby