in reply to Need Some help with finding a word in a file
The special variables $1, $2, etc are set to the data inside of parens when you use parens to encapsulate part of your regex. So $1 matches the first (...), $2 the second, and so forth.#!/usr/bin/perl my $data_file = '/home/resources.xml'; my $data_out = '/home/out.log'; open DATA, "$data_file" or die "can't open $data_file $!"; open DATA_OUT, ">>$data_out"; my @array_of_data = <DATA>; my $match; foreach my $line (@array_of_data) { if ($line =~ m/authDataAlias=(.*-.*-.*_DM)/i) { $match = $1; print DATA_OUT "$line\n"; } } close (DATA); close (DATA_OUT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need Some help with finding a word in a file
by was6guy (Initiate) on Nov 29, 2007 at 14:42 UTC | |
by jrsimmon (Hermit) on Nov 29, 2007 at 15:42 UTC | |
by was6guy (Initiate) on Nov 29, 2007 at 19:27 UTC | |
by jrsimmon (Hermit) on Nov 29, 2007 at 20:43 UTC | |
by was6guy (Initiate) on Nov 29, 2007 at 21:27 UTC |