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

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

Replies are listed 'Best First'.
Re^4: Grave accent caveats
by deepakg (Novice) on Jan 19, 2009 at 17:45 UTC
    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
        You are right. I changed

        $hash1 = `echo -n $text|openssl dgst -sha1`;

        to

        $hash1 = `/bin/echo -n $text|openssl dgst -sha1`;

        and I now get the expected values. Thanks for your help!