Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
BEFORE
AFTER(object (name1 val1 name2 val2))
My question is: Is there a way to do this without resorting to a secondary file? I have another script that will use this code recursively against a whole baseline of design files, and using temporary files may make it too slow.( object ( name1 val1 name2 val2 ) )
The Script:
Thanx, jojo$tempfile = "jojowashere.jbc"; if ($#ARGV < 0) { print "\nUSAGE: $0 filename.cat"; exit(0); } open (fp,$ARGV[0]) || die ("Can't open $ARGV[0]! Exiting."); open (tempfp,"> $tempfile") || die ("Can't create $tempfile! Exiting." +); while(<fp>) { if (m/(^.*)(".+")(.*)/) { $a = $1; $b = $2; $c = $3; $a =~ s/\(/\n\(\n/g; $a =~ s/\)/\n\)\n/g; $c =~ s/\(/\n\(\n/g; $c =~ s/\)/\n\)\n/g; $_ = $a . $b . $c; } else { s/\(/\n\(\n/g; s/\)/\n\)\n/g; } print tempfp "\n$_"; } close fp; close tempfp; $num_indents = 0; open (fp,$tempfile) || die ("Can't open $tempfile!"); while (<fp>) { s/^\s+//; s/\s+$//; chomp; if (length) { if (m/^\)$/) { --$num_indents; } $spacing = ""; for ($j=0;$j<$num_indents;$j++) { $spacing .= " " }; print "\n$spacing$_"; if (m/^\($/) { ++$num_indents; } } } close fp; unlink $tempfile;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing a file, splitting current line into multiple ones, to be parsed separately
by John M. Dlugosz (Monsignor) on Jun 14, 2001 at 02:54 UTC | |
by JojoLinkyBob (Scribe) on Jun 14, 2001 at 03:05 UTC | |
by davorg (Chancellor) on Jun 14, 2001 at 12:30 UTC | |
|
Re: Parsing a file, splitting current line into multiple ones, to be parsed separately
by JojoLinkyBob (Scribe) on Jun 14, 2001 at 02:37 UTC |