I have been struggling with a problem for about 2 weeks now. all I need to do is add a sed call to a perl script. I have tried several of the tricks listed on perl monks and finally have given into asking for help.
sed -e 's#[^0-9]*\([0-9]\{3\}\)[^0-9]*\([0-9]\{3\}\)[^0-9]*\([0-9]\{4\}\)#(\1) \2-\3#' $FILEall I need to do is add the above complex set to perl, when I attempt to run s2p I recieve a bunch of errors in the output code. As a perl novice I have little experience debugging something of this nature. I have attached the output. I would love it if someone could say BTW oneliner x will make this work, or here is how to set the system call. Thank you for any help Perl Novice.
s2p 's#[^0-9]*\([0-9]\{3\}\)[^0-9]*\([0-9]\{3\}\)[^0-9]*\([0-9]\{4\}\) +#(\1) \2-\3#' Having no space between pattern and following word is deprecated at (e +val 1) line 27. Bareword found where operator expected at (eval 1) line 27, near "s #\ +D*(\d{3})\D*(\d{3})\D*(\d{4})#(${1}) ${2}-${3}#s; $CondReg ||= $s; } EOS: if( $doPrint" (Might be a runaway multi-line $$ string starting on line 25) (Do you need to predeclare s?) Code: # prototypes sub openARGV(); sub getsARGV(;\$); sub eofARGV(); sub printQ(); # Run: the sed loop reading input and applying the script # sub Run(){ my( $h, $icnt, $s, $n ); # hack (not unbreakable :-/) to avoid // matching an empty string my $z = "\000"; $z =~ /$z/; # Initialize. openARGV(); $Hold = ''; $CondReg = 0; $doPrint = $doAutoPrint; CYCLE: while( getsARGV() ){ chomp(); $CondReg = 0; # cleared on t BOS:; # s#[^0-9]*\([0-9]\{3\}\)[^0-9]*\([0-9]\{3\}\)[^0-9]*\([0-9]\{4\}\)#(\ +1) \2-\3# { $s = s #\D*(\d{3})\D*(\d{3})\D*(\d{4})#(${1}) ${2}-${3}#s; $CondReg ||= $s; } EOS: if( $doPrint ){ print $_, "\n"; } else { $doPrint = $doAutoPrint; } printQ() if @Q; + } + + exit( 0 ); + { + + # openARGV: open 1st input file + # + sub openARGV(){ + unshift( @ARGV, '-' ) unless @ARGV; + my $file = shift( @ARGV ); + open( ARG, "<$file" ) + || die( "$0: can't open $file for reading ($!)\n" ); $isEOF = 0; } # getsARGV: Read another input line into argument (default: $_). # Move on to next input file, and reset EOF flag $isEOF. sub getsARGV(;\$){ my $argref = @_ ? shift() : \$_; while( $isEOF || ! defined( $$argref = <ARG> ) ){ close( ARG ); return 0 unless @ARGV; my $file = shift( @ARGV ); open( ARG, "<$file" ) || die( "$0: can't open $file for reading ($!)\n" ); $isEOF = 0; } 1; } # eofARGV: end-of-file test # sub eofARGV(){ return @ARGV == 0 && ( $isEOF = eof( ARG ) ); } # makeHandle: Generates another file handle for some file (given by it +s path) # to be written due to a w command or an s command's w fla +g. sub makeHandle($){ my( $path ) = @_; my $handle; if( ! exists( $wFiles{$path} ) || $wFiles{$path} eq '' ){ $handle = $wFiles{$path} = gensym(); if( $doOpenWrite ){ if( ! open( $handle, ">$path" ) ){ die( "$0: can't open $path for writing: ($!)\n" ); } } } else { $handle = $wFiles{$path}; } return $handle; } # printQ: Print queued output which is either a string or a reference # to a pathname. sub printQ(){ for my $q ( @Q ){ if( ref( $q ) ){ # flush open w files so that reading this file gets it all if( exists( $wFiles{$$q} ) && $wFiles{$$q} ne '' ){ open( $wFiles{$$q}, ">>$$q" ); } # copy file to stdout: slow, but safe if( open( RF, "<$$q" ) ){ while( defined( my $line = <RF> ) ){ print $line; } close( RF ); } } else { print $q; } } undef( @Q ); } s2p: internal error - generated incorrect Perl code: syntax error at ( +eval 1) line 27, near "s #\D*(\d{3})\D*(\d{3})\D*(\d{4})#(${1}) ${2}- +${3}#s; $CondReg ||= $s; } EOS: if( $doPrint " syntax error at (eval 1) line 29, near "} else" syntax error at (eval 1) line 36, near "; }" syntax error at (eval 1) line 46, near "; }" Can't use global @_ in "my" at (eval 1) line 51, near "= @_ " Global symbol "$argref" requires explicit package name at (eval 1) lin +e 52. syntax error at (eval 1) line 61, near "; }" Can't use global @_ in "my" at (eval 1) line 72, near "= @_" syntax error at (eval 1) line 85, near "; }" Missing right curly or square bracket at (eval 1) line 111, at end of +line (eval 1) has too many errors.
In reply to Running complex sed from perl by sunglant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |