Variable inside regular expression
- From: mattwoolnough@xxxxxxxxx
- Date: 29 Jun 2006 23:11:46 -0700
Hi there,
Im trying to get specific groups out of the unix group file. The list
of group names is contained in Group_list.txt, when I try and run this
code, I get no output. Is it possible to use variables inside regex?
----------------------------
#!/usr/bin/perl -w
use Slurp;
$datafile="/home/mw/Group_list.txt";
$groupfile="/etc/group";
my @array = Slurp::to_array($datafile);
foreach $entry(@array) {
open(FH, "<$groupfile");
while (<FH>)
{
chomp $_ ;
if ($_ =~ /^$entry/){print $_ . "\n" ;}
}
close (FH);
}
----------------------------
Thanks in advance,
matt
.
- Follow-Ups:
- Re: Variable inside regular expression
- From: Paul Lalli
- Re: Variable inside regular expression
- From: davidfilmer
- Re: Variable inside regular expression
- Prev by Date: Re: Detecting line terminators in a CSV file
- Next by Date: Re: Variable inside regular expression
- Previous by thread: Detecting line terminators in a CSV file
- Next by thread: Re: Variable inside regular expression
- Index(es):