Solved

REGEX question

Posted on 2004-08-11
2
250 Views
Last Modified: 2010-03-05
What does this regex do.

/\S/ && !/\S/

Someone gave me the answer to help my script (And it did), I would just like to know what it is doing.

foreach (@textData) {
        $_ .= "\n" if $prev=~/\S/ && !/\S/;
        $prev = '';
        $prev = chomp if /\S/;
       
        print CONFIG $prev = $_
          unless (/-------/);
         
}
0
Comment
Question by:biggin777
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 11775021
If $prev contains a non-whitespace character, and $_ does not contain a non-whitespace character.
0
 
LVL 6

Expert Comment

by:Talmash
ID: 11775439

foreach (@textData) { # loading all lines line after line , line=$_
        $_ .= "\n" if $prev=~/\S/ && !/\S/; # NEVER adding \n (EOL)
        $prev = '';
        $prev = chomp if /\S/;
       
        print CONFIG $prev = $_
          unless (/-------/);
         
}

regular lines are concatenate to each other ,
empty line provide new line

tal
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json encode mysql results 4 182
Input from stdin for perl 6 108
cpan issue 1 55
Perl tar error 8 32
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now