Perl cross regex with newlines

I am new to Perl and working on a project for school and stuck.

Input: the specified text file containing email addresses, separated by a space, the tab ",", ";" or ":" [may be on separate lines].

I am trying to read email addresses and put them in an array. I can parse the data on one line, however, if there are line breaks or returns, I get only the last element.

Can someone help me figure out how to take a list with each address on a separate line and analyze them? I read a little about regex, but I need a lot more practice. Thanks.

open(EmailAddresses, "EmailAdressesCommaList.txt") || die "Can not open file $!";

# 
while (<EmailAddresses>)
{
    chomp;
    # Split the line into words
    @lines = split /[ ,;:\t\r\n(\t\r\n\s)+?]/;
}

foreach $value (@lines)
{
    print $value . "\n";
}
+3
source share
3
open(EmailAddresses, "EmailAdressesCommaList.txt") || die "Can not open file $!";
while(<EmailAddresses>) {
    chomp;
    push @lines, split /[ ,;:\t\r\n(\t\r\n\s)+?]/;
}
foreach $value (@lines) {
    print $value . "\n";
}

. , , @lines .

+7

, , , . , :

/[ ,;:\t\r\n][\t\r\n\s]+/

, :

/[,;:\s]+/
+1

The chaos is right. If you are going to open a text file and process it again in the same program, do not forget to clear the array.

@lines = ();
+1
source

Source: https://habr.com/ru/post/1705200/


All Articles