Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

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,739
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)

  • 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.

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

  • @PIKAMONjake Actually, I have a Windows computer, as well as two Macs and two Linux boxes. It might be some kind of addiction! ;)

Video Responses

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

All Comments (20)

Sign In or Sign Up now to post a comment!
  • Now I can hide dirty pictures from anyone on plain sight =)

  • @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).

  • If i'm using windows 7 and I wanted to execute this out of a command prompt directly from a .pl file, i assume this would not be the correct syntax. could you respond back what would be?

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