in reply to I don't understand why I'm getting an "Use of uninitialized value" error
To answer your direct question, you backslash them. The string literal «"foo \\ bar"» produces the string «foo \ bar».
But that's the least of your problems, /.../ is the match operator, so it's Perl code. If you want to compile and run Perl code, you'd have to use eval EXPR.
But if @search contained regular expressions instead of Perl code, you could wouldn't need to go to such drastic measures.
my @patterns = ( "<ID>(.*?)</ID>", # ID "<TimeStamp>(.*?)</TimeStamp>", # Time Stamp "<IP_Address>(.*?)</IP_Address>", # IP Address "<Title>(.*?)</Title>", # Title "<Complainant><Entity>(.*?)</Entity>", # Reporting Entity "<Contact>(.*?)</Contact>", # Reporting Entity Contact "<Address>(.*?)</Address>", # Reporting Entity Address "</Phone><Email>(.*?)</Email>", # Reporting Entity Email ); my @xml_files = <*xml>; for my $file (@xml_files) { for my $pattern (@patterns) { ... if ($line =~ $pat) { ... } }
Furthermore, it would be beneficial to use qr//.
my @regexps = ( qr{<ID>(.*?)</ID>}, # ID qr{<TimeStamp>(.*?)</TimeStamp>}, # Time Stamp qr{<IP_Address>(.*?)</IP_Address>}, # IP Address qr{<Title>(.*?)</Title>}, # Title qr{<Complainant><Entity>(.*?)</Entity>}, # Reporting Entity qr{<Contact>(.*?)</Contact>}, # Reporting Entity Contact qr{<Address>(.*?)</Address>}, # Reporting Entity Address qr{</Phone><Email>(.*?)</Email>}, # Reporting Entity Email ); my @xml_files = <*xml>; for my $file (@xml_files) { for my $regexp (@regexps) { ... if ($line =~ $regexp) { ... } }
|
|---|