Using split and pattern matching : split « Regular Expression « Perl






Using split and pattern matching

    


while(<DATA>){
    @line = split(":", $_);
     print $line[0],"\n" if $line[1] =~ /408-/    # Using the pattern matching operator
}
__DATA__
    A:111-444-6677:12 Main St.
    B:222-222-1234:234 main Ln.
    C:408-567-4444:3456 Mary Way
    D:555-234-5678:8880 Main St.
    E:333-444-6556:54 Main Ln.
    F:444-333-7654:123 4th Ave.

   
    
    
    
  








Related examples in the same category

1.@a = split (//, $s);
2.To get at each field, we can split when we see a colon:
3.The split function splits up a string EXPR by some delimiter (whitespace by default) and returns an array.
4.Using split, an anonymous list, and pattern matching
5.Defaults to split(' ', $_).
6.Divide according to multiple separators.
7.Divide it into a specific number of fields.
8.Split a string by using the regular expression