in reply to Re^6: while(){}continue{}; Useful?
in thread while(){}continue{}; Useful?
#!/usr/bin/perl use strict; use warnings; my @lines = <DATA>; my ($error, $content); my %pragma_once; while (defined(local $_ = shift @lines)) { unless (/^#/) { $content .= $_; undef $_, next; } if (/^#include\s*/) { if (/<math/) { $content .= "import java.lang.Math;\n"; undef $_, next; } if( /"stdafx.h"/ ) { # Drop it undef $_, next; } if( m["(.+)"] ) { open my $inc_handle, '<', $1 or warn "$1: $^E\n" and next; my $include = do {local $/; <$inc_handle>;}; # slurp $include = "" if defined $pragma_once{$1}; $pragma_once{$1}++ if ($include =~ s/^#pragma once//m); unshift @lines, split /(?<=$\/)/, $include; undef $_, next; } warn "Unhandled include\n"; } if (/^#defined/) { #... } if (/^#ifdef/) { #... } if (/^#else/) { #... } if (/^#endif/) { #... } } continue { if (defined) { chomp; warn qq{Unhandled line "$_"\n}; $error++; } } print "\nContent:\n'$content'\n"; die "$error errors encountered\n" if $error; __DATA__ #include "stdafx.h" #include <math.h> #include <stdio.h> // A comment #include "AlyLee.h" #include "Common.h"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: while(){}continue{}; Useful?
by BrowserUk (Patriarch) on Apr 06, 2010 at 06:14 UTC | |
by kennethk (Abbot) on Apr 06, 2010 at 14:55 UTC |