Stupid Perl Trick

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
3,760
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 14, 2009

This is a stupid little Perl trick that corrupts a file by performing a pattern substitution throughout the file. The example file is an image file. The following can be entered at a command prompt to corrupt a file:

perl -pi -e 's/c/salami/g' file.jpg

This is a really simple little trick that anyone can try as long as they have Perl loaded on their computer. Perl comes standard with most flavors of Linux and with Mac OS X. While this trick as demonstrated in this video is kind of just a funny gimmick, command line substitution is a powerful tool, especially when combined with the use of regular expressions.

WARNING: Backup any images before experimenting with this trick. Some substitutions are potentially irreversible!!!

MORE INFO: http://www.blackturtle.us/SONGS/NEWPAGES/stupidperl.html

  • likes, 2 dislikes

Link to this comment:

Share to:

Uploader Comments (blackturtleshow)

  • Now I can hide dirty pictures from anyone on plain sight =)

  • @symptomxx There are many much more powerful forms of encryption and obfuscation available to take care of those nasty pics! This is just a fun little experiment! Thanks for watching and commenting!

  • Can't you just use perl -pie? Easier to remember and mmm... perl pie. Also, that's only reversible if the word starts with the letter being replaced. If you were to do /d/california/, then any original instances of california in the file (not likely in a JPEG) will be mangled when you do /california/d/.

  • @uzimonkey Thanks for watching! Using -pie won't work. (I double-checked just now.) Secondly, it doesn't matter what the word STARTS with. All that matters is that the new pattern that is created doesn't already exist in the target file. That's what I mean by one-to-one and many-to-one pattern substitutions. I didn't explain this fully or give examples since I wanted to keep the video short. Also I figured people who are interested would experiment around and figure it out that way.

  • @blackturtleshow Actually, it will work if california already exists in the file and you use c. If you do /c/california/ it would end up as califroniaalifornia, which will go back to california when you do /california/c/.

  • @uzimonkey True, but in that case you're modifying an existing pattern as opposed to replicating an existing pattern.

Video Responses

This video is a response to Cmd tricks that will blow your mind
see all

All Comments (21)

Sign In or Sign Up now to post a comment!
  • @PIKAMONjake Actually, I have a Windows computer, as well as two Macs and two Linux boxes. It might be some kind of addiction! ;)

  • machontosh huh, im a loyal windows user but mac is pretty popular these days

  • @wowonice1 Actually the demo program is really short, so here's the whole thing:

    #!/usr/bin/perl

    $str = "TTAAGGCCATGCGGATACACGATGAC";

    print "ORIGINAL: $str\n";

    $str =~ s/T/U/g;

    print "AFTER SUBSTITUTION: $str\n";

    FROM:

    blackturtle.us/BIOINFO/BIOPERL­2/bp2_02.html

  • @wowonice1

    $str =~ s/T/U/g;

    This line substitutes a U for all instances of T in the string $str (in this case a nucleotide sequence).

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more