When deconstructing a perl-based one-liner, the error "Can not modify single ref builder in scalar assignment"

2
export dev2='/dev/sdb';
perl -'MDigest::MD5 md5' -ne 'BEGIN{\$/=24};print md5(\$_)' $dev2

Returns the following error:

  

Can not modify single ref builder in scalar assignment at -e line 1, near "1024}"
  BEGIN not safe after errors - compilation aborted at -e line 1.

Any suggestions of what I'm doing wrong? I'm relying on link

Thank you.

    
asked by anonymous 30.05.2015 / 19:33

2 answers

0

It is not very clear what you are about to do, but try something like:

perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=24};print md5($_)'

or to become more legible:

perl -'MDigest::MD5 md5_hex' -ne 'BEGIN{$/=24};print "\n$.:, md5_hex($_),"\n"'
    
16.01.2017 / 20:15
0

I may be wrong, but the bar in front of 1024 is to escape the argument passed to /root/.ssh/rsync_rsa (as per response in SeverFault ):

ssh -i /root/.ssh/rsync_rsa $remote "
  perl -'MDigest::MD5 md5' -ne 'BEGIN{\$/=24};print md5(\$_)' $dev2 | lzop -c" |
  lzop -dc | perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=24};$b=md5($_);
    read STDIN,$a,16;if ($a eq $b) {print "s"} else {print "c" . $_}' $dev1 | lzop -c |
ssh -i /root/.ssh/rsync_rsa $remote "lzop -dc |
  perl -ne 'BEGIN{\$/=} if (\$_ eq\"s\") {\$s++} else {if (\$s) {
    seek STDOUT,\$s*1024,1; \$s=0}; read ARGV,\$buf,1024; print \$buf}' 1<> $dev2"

Then in your case as you are not rsync_rsa and instead typing direct, you do not need to "escape" the number, just do this:

export dev2='/dev/sdb';
perl -'MDigest::MD5 md5' -ne 'BEGIN{\$/=1024};print md5(\$_)' $dev2

I have no terminal emulator, but if it still fails it is because I do not need to escape the $ within '...' (I can not say, I have not used Linux / Unix for a while):

export dev2='/dev/sdb';
perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=1024};print md5($_)' $dev2
    
16.01.2017 / 20:35