ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Thank you.It's working.
But, may I know where my code went wrong?
I used
Code:
$_=~s/[0-9]/[0-9]\n/;
$_ which you didn't used takes by default. So, I think there is no mistake here. =~,used to match and assign at the same time. s///,used for substitution.
1st [0-9]used to match the digit.
2nd [0-9]used to print a digit. I think the interpreter doesn't know which digit to choose. Is the code wrong went wrong here??
Even though I will not get the output as I were expected, this should print any digit between [0-9] instead of [0-9]. Why this is not happening? Could you please explain me???
Thank you.It's working.
But, may I know where my code went wrong?
I used
Code:
$_=~s/[0-9]/[0-9]\n/;
$_ which you didn't used takes by default. So, I think there is no mistake here. =~,used to match and assign at the same time. s///,used for substitution.
1st [0-9]used to match the digit.
2nd [0-9]used to print a digit. I think the interpreter doesn't know which digit to choose. Is the code wrong went wrong here??
Even though I will not get the output as I were expected, this should print any digit between [0-9] instead of [0-9]. Why this is not happening? Could you please explain me???
Regarding item in red - you wrongly understand how 's' operator works.
Read
perldoc perlop
- 's' operator is explained there pretty well.
Also, read
perldoc perlretut
perldoc perlre
- both these documents also have explanations on 's' operator.
2nd [0-9]used to print a digit. I think the interpreter doesn't know which digit to choose. Is the code wrong went wrong here??
Yes. Also, even if it would work, it would put the newline after the digit.
To use the s/// command to replace parts of the original text onto the output, put all the parts you want to retrieve in ()'s. Then use \1, \2 \3, etc. allt the way to \9 to refer to these parenthesized parts.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.