DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Frank has posted 1 posts at DZone. You can read more from them at their website. View Full User Profile

Tidy Up Copy'n'paste Code Snippets From DZone

09.24.2008
| 4010 views |
  • submit to reddit
        // remove the line numbers from DZone's copy'n'paste code snippets
#!/usr/bin/perl
#
#  usage :  dzone.pl copy_and_paste_file
#           copy_and_paste_file - file which contain the code snippet from DZone website

sub dzone_tidy {
  my ($infile) = @_;
  open(FILE, "< $infile") || die "ERROR: failed to open file: '$infile'";
  while (my $line = <FILE>) {
    $line =~ s/^[ ]*[0-9]*  //;
    print "$line";
  }
  close(FILE);
}

if ( $#ARGV ne 0 )
{
  print "ERROR: wrong number of parameters\n\n";
  exit(1);
}

my $infile = $ARGV[0];
dzone_tidy(${infile});
    

Comments

Brian Tully replied on Tue, 2008/12/09 - 3:42pm

it's a real shame one has to run an external script to remove the line numbers. Why can't DZone add a simple function that allows us to download code snippet or hide line numbers?