While populating an array, (data used later for comparison), I have noticed some entries contain characters that break a regexp, a plus sign "+" for example.
I am questioning the best way to escape these characters. It seems easiest to continue pushing everything "as-is" into the array and do the escaping as needed when parsing through, but I am not sure.
Now for the obligatory coding example...
#! /usr/bin/perl -w
use strict;
my @current = `rpm -qa`;
my @base = `cat /tmp/install.log`;
my $cur_cnt = @current;
my $base_cnt = @base;
$cur_cnt -= 1;
$base_cnt -= 1;
foreach (@current) {
# Reset to stay out of the negative when decrementing below.
$base_cnt = @base;
# Set these because the first iteration through the
# loop gripes about unitialized value.
$cur_cnt -= 1;
$base_cnt -= 1;
foreach (@base) {
if ($base[$base_cnt] =~ $current[$cur_cnt]) {
print "Unchanged: $base[$base_cnt]";
} else {
#Do Nothing
}
$base_cnt -= 1;
}
}
This iterates through (while begging for optimization) a listing of installed RPMs, and matches against a listing of RPMs installed at build time, Any deviation, either version update or new software package is printed to the screen.
The trouble arises when the loop hits a package name with special chars, for example: timidity++-2.11.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.