Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl error

Status
Not open for further replies.

dirdmalah

Programmer
Jun 20, 2008
2
US
hello all

I execute this:

# perl -p -w -e 's/</book>(?:\n)<collection>(.*)</collectioninfo>//g' test1.txt

And get this:

Bareword found where operator expected at -e line 1, near "s/</book>(?:\n)<collection>(.*)</collectioninfo"
Unquoted string "collectioninfo" may clash with future reserved word at -e line 1.
syntax error at -e line 1, near "s/</book>(?:\n)<collection>(.*)</collectioninfo"
Execution of -e aborted due to compilation errors.


Any help ?

Thx !!
 
it's going to pick up all those /'s unless you escape them.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
so.. how can I run that

like this:

perl -p -w -e '/s</book>(?:\n)<collection>(.*)</collectioninfo>//g' test1.txt
 
use \/ on any /'s that are part of the s/// syntax
/s<\/book> etc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
or use a different delimiter for the regexp itself, one that is not part of the pattern:

Code:
perl -p -w -e 's#</book>(?:\n)<collection>(.*)</collectioninfo>##g' test1.txt

makes code more readable than using escapes, but either way will work.



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Should have said

use \/ on any /'s that are not part of the s/// syntax
/s<\/book> etc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top