Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
[root@server perl.pl]# perl perl16.pl
Backslash found where operator expected at perl16.pl line 6, near "_\"
syntax error at perl16.pl line 6, near "_\"
Execution of perl16.pl aborted due to compilation errors.
[root@server perl.pl]# vi perl16.pl
print "/$patter is an email id .\n";
print "/$patter is not a email id .\n"
let me know why this script is failing
Leading slash in front of $pattern (definite syntax error), backslash in front of pipe char (this won't cause a syntax error, but probably won't work the way you expect), underscores rather than dashes in alpha range at the end (again, not a syntax error, but probably won't work as you intend).
No doubt you mean $pattern, not $patter. However, this error should be picked up at runtime by you including "use strict". I don't know why you want that slash in front of what you're printing, but that's not an error.
Not wanting to burst your bubble, but things are simpler than you are making them. Check out:
Because . (dot) means "match any character". You don't want that in your example here. You want dot to match a dot and only a dot. So you have the backslash it, to escape its normal meaning of "match any character".
Without that backslash, the expression (\w|-|.) would mean "match a word character, or match a dash, or match any character" That final "or match any character" would make the first two specifications, \w and -, useless and redundant. Plus, it wouldn't do what you want, which in this case is "match a dot and only a dot".
You might want to say, "but what about a - (dash), doesn't that have special meaning too, so why doesn't it have to be escaped?"
The reason is, a dash only has special meaning in one context, inside a range, as in "[a-z]" or "[0-9]". If it is not in this context, it has no special meaning, therefore it doesn't need to be escaped. But you could escape it if you wanted. That wouldn't hurt anything. You see that fairly commonly. What it means is that the author did not know if the dash needed to be escaped or not, so they escaped it just to be sure.
[a-z] would match "any lowercase letter". [a\-z] would match "the letter a, or the letter z, or a dash"
To make things even more confusing, a backslash can do different things ... it can either remove special meaning as in "\.", or it can ADD special meaning as in "\w". In this second case, without the backslash, "w" means (obviously) the letter w. But putting a backslash in front of it ADDS special meaning, thus "\w" means "any word character".