binary sed replacement

bbe is a “sed for binary files”, and should work more efficiently for large binary files than hexdumping/reconstructing. An example of its use: $ bbe -e ‘s/original/replaced/’ infile > outfile Further information on the man page.

How to print variables in Perl

print “Number of lines: $nids\n”; print “Content: $ids\n”; How did Perl complain? print $ids should work, though you probably want a newline at the end, either explicitly with print as above or implicitly by using say or -l/$\. If you want to interpolate a variable in a string and have something immediately after it that … Read more

What is the difference between Perl’s ( or, and ) and ( ||, && ) short-circuit operators?

Due to the low precedence of the ‘or’ operator, or3 parses as follows: sub or3 { my ($a,$b) = @_; (return $a) or $b; } The usual advice is to only use the ‘or’ operator for control flow: @info = stat($file) or die; For more discussion, see the perl manual: http://perldoc.perl.org/perlop.html#Logical-or-and-Exclusive-Or

Is there an advantage to using Bash over Perl or Python? [closed]

Two advantages come to mind: Simplicity: direct access to all wonderful linux tools wc, ls, cat, grep, sed… etc. Why constantly use python’s subprocess module? I’m increasingly fond of using gnu parallel, with which you can execute your bash scripts in parallel. E.g. from the man page, batch create thumbs of all jpgs in directory … Read more

How can I assign two arrays to a hash in Perl?

You can do it in a single assignment: my %hash; @hash{@array1} = @array2; It’s a common idiom. From perldoc perldata on slices: If you’re confused about why you use an ‘@’ there on a hash slice instead of a ‘%’, think of it like this. The type of bracket (square or curly) governs whether it’s … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)