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.
The problem with that regex is \s applies to tabs, newlines, and spaces - so this would match two spaces, or a tab followed by a space, or other undesirables. Also, I believe, perl regexes default to single line mode, so what you need is this:
$line =~ /^\n\n/m;
assuming $line contains your lines of text. The m on the end forces the regex into "multiline" mode.
Location: Location??? Where I am is top secret, if I tell you, I have to kill you.
Distribution: College, Slack
Posts: 24
Rep:
Ugh... I am not sure that the person above me's will work. Simply because your <STDIN> is asking from input from the user. I am don't think this guy is trying to get input from the keyboard. I thought it was from a file.
Whoever has the question, just post the name and the directory that the file is in, and I will write you a quick little script.
Ugh... what in thee hell is "if ( /^$/ ) {" suppose to do? If I am reading that correct, if $_ is holding nothing, then continue.
It's meant as an example, and assumes you pass the input through on STDIN - I don't know what his filename will be or how he reads it, but I've tested the script myself using a command like this:
cat file_with_blanks | /path/script.perl
In this case, the user would not be asked for input. Obviously, mosh could change it to use a different file handle, though I can't see why you'd want to write a generic script like this and then hardcode the filename. I'd think it more likely he'd want to use it on multiple files (either now or in the future). There is a semi-bug in that it will print the "double line" message twice for three blanks in a row, but it's easy to see how to get around that.
> Ugh... what in thee hell is "if ( /^$/ ) {" suppose to do? If I am reading that correct, if $_ is holding nothing, then continue.
Did you read the question? He's looking for empty lines. Geeze.
P.S: Sorry, the form ate my spaces - it does look quite ugly without some indenting.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.