http://www.perlmonks.org?node_id=1062758

guitarplayer68 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I’ve got a regex issue I am trying to figure out. The situation is I need to pull a file from several servers and return everything past a particular point in that file. The module selection is limited to what is available in a default install. The problem I am having is the regex works the first time. It only returns what I requested, but when it moves on to the next server, and every server thereafter, it returns the entire file. I’ve banged my head at this for the past day or so and just can’t seem to get anywhere. The code is below, generalized for this example.

#!/usr/bin/perl use strict; my $server; my $usrallow = "/etc/opt/quest/vas/users.allow"; my @ssh; my $line; foreach $server(@ARGV) { print "getting cgrpfile from $server\n"; @ssh = `ssh $server /bin/cat $usrallow `; foreach $line (@ssh) { if ($line =~ /line/../\\Z/) { print $line; } } }

The output is below, again somewhat generalized

getting cgrpfile from x.x.x.5 customizations must be after this line. customgrp1 customgrp2 customgrp3 getting cgrpfile from x.x.x.6 #START: Core Groups defaultgrp1 defaultgrp2 defaultgrp3 defaultgrp4 defaultgrp5 defaultgrp6 customizations must be after this line customgrp1 customgrp7 customgrp8 getting cgrpfile from x.x.x.7 #START: Core Groups defaultgrp1 defaultgrp2 defaultgrp3 defaultgrp4 defaultgrp5 defaultgrp6 customizations must be after this line customgrp5 customgrp12 customgrp10