Over a million developers have joined DZone.

Tidy Up Copy'n'paste Code Snippets From DZone

·
// 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 = ) {
    $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});
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}