in reply to Repeating the same command in different portions of input
What you want is a loop. Perl has several different kinds of loop - for, foreach, while, until, etc. They all boil down to the same thing, but depending on what you're doing, one type of loop might be more convenient than then other.
use v5.12; use strict; use warnings; # Obscure but easy way of reading a file into a string to match agains +t... $_ = do { local (@ARGV, $/) = 'loop.txt'; <> }; # Extract text we're interested in... my @matches = m{<a>(.+?)</a>}sg; # Loop through the matches... foreach my $match (@matches) { # This block gets executed for each match! say "GOT: $match"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Repeating the same command in different portions of input
by albascura (Novice) on Jan 15, 2013 at 10:47 UTC |