RE: Regex search using scalar
The search patterns I am looking for are contained inside the list (each element of the list is going to be used to scan an entire log file). So if ( /match/ ) needs to reference each element of the FOREACH loop which I will have nested inside a while FILENAME loop. That's what's confusing me. -Original Message- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Tore Aursand Posted At: Wednesday, November 05, 2003 5:12 AM Posted To: Perl Conversation: Regex search using scalar Subject: Re: Regex search using scalar On Tue, 04 Nov 2003 20:41:17 -0800, Paul Harwood wrote: I would like to enumerate a list and search through each element like so: [...] Why do you want to enumerate the list? Do you _really_ need to know the index of the current element? If really so: my $i = 0; foreach ( @list ) { $i++; if ( /match/ ) { # ... } } If (/$logs[i]/) Please post _real_ Perl code. The code above has no meaning and won't even compile. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regex search using scalar
Paul Harwood wrote: The search patterns I am looking for are contained inside the list (each element of the list is going to be used to scan an entire log file). So if ( /match/ ) needs to reference each element of the FOREACH loop which I will have nested inside a while FILENAME loop. That's what's confusing me. This is a FAQ perldoc -q 'How do I efficiently match many regular expressions at once' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Regex search using scalar
I would like to enumerate a list and search through each element like so: If (/$logs[i]/) { # code} I know the syntax is wrong so I was hoping someone could explain how to do this. Thanks. --Paul
Re: Regex search using scalar
On Tue, 04 Nov 2003 20:41:17 -0800, Paul Harwood wrote: I would like to enumerate a list and search through each element like so: [...] Why do you want to enumerate the list? Do you _really_ need to know the index of the current element? If really so: my $i = 0; foreach ( @list ) { $i++; if ( /match/ ) { # ... } } If (/$logs[i]/) Please post _real_ Perl code. The code above has no meaning and won't even compile. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Regex search using scalar
Paul Harwood wrote: I would like to enumerate a list and search through each element like so: If (/$logs[i]/) { # code} I know the syntax is wrong so I was hoping someone could explain how to do this. If I understand correctly, you want to use grep(): for (grep /pattern/, @list) { ... do something with $_ ... } perldoc -f grep -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Regex search using scalar
Paul Harwood wrote: Thanks. Can I substitute /pattern/ with a scalar though? Yes. grep $_ eq 'string', @list -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 05, 2003 5:24 AM To: Paul Harwood; Beginner Perl Subject: RE: Regex search using scalar Paul Harwood wrote: I would like to enumerate a list and search through each element like so: If (/$logs[i]/) { # code} I know the syntax is wrong so I was hoping someone could explain how to do this. If I understand correctly, you want to use grep(): for (grep /pattern/, @list) { ... do something with $_ ... } perldoc -f grep -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]