First of all, many thanks for your valuable input! I learn a lot from your comments :-)

I understood that my ($infile, $param) = @ARGV; is a smart way to read two input parameters from the command line. What happens if the second parameter is missing, i.e. perl entityPairs.pl input.xml? Will that mean that the condition in ternary operator expression evaluates to false and the values after ":" are taken?

I've got two issues:

FYI, the current version of the script:

#!/usr/bin/perl use warnings; use strict; use diagnostics; print "Find pair of entities without/with separating space\n"; # read input file and param ('mod' = for modified files) my ($infile, $param) = @ARGV; my @regexes = $param ? (qr/&ndash;&sect;/, qr/&ndash;&Uuml;/, qr/&szlig;&sect;/) : (qr/&[^;]+;\s&[^;]+;/); open my $in, '<', $infile or die "Cannot open $infile for reading: $!" +; #read input file in variable $xml my $xml; { local $/ = undef; $xml = <$in>; } #define output file open my $out, '>', 'pairs.txt' or die $!; #output statistics print {$out} "Find pair of entities without/with separating space\n\ni +nput file: "; print {$out} "$infile"; print {$out} "\n====================================================== +==================\n\n"; for my $i (0 .. $#regexes) { my $regex = $regexes[$i]; $regex =~ s/^\(\?\^://; $regex =~ s/\)$//; print {$out} "$regex: $1\n" while $xml =~ /$regex/g; } close $in; close $out;


In reply to Re^2: Output minimal occurrences of matching regex(es) by LexPl
in thread Output minimal occurrences of matching regex(es) by LexPl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.