Thanks. It worked but now I need to change teh regex to search for <endnote id= in the input.txt file. I changed the IF statement to reflect the change but now I am getting the Use of uninitialized... error again.</P.
input.txt
<endnote id=(1)>Text...</endnote>
<endnote id=(2)>Text...</endnote>
if ( $tag =~ m/<endnote id=/ ) {
$tags{sprintf("%04d%6s",$1 || 999,$2)} = $tag;
}
else {
warn "Failed to match: $tag"
}
| [reply] [Watch: Dir/Any] [d/l] |
The parentheses in regular expressions define so called "capture groups". Originally, you had two capture groups:
m/<tagid=(\d*)([[:alpha:]]*)>/
<~~~><~~~~~~~~~~~~>
#1 #2
The variables $1 and $2 contain the parts matched by the respective capture groups. \d* means "zero or more digits", [[:alpha:]]* means "zero or more characters". In your new regex, you don't have any parentheses:
m/<endnote id=/
So $1 and $2 aren't populated.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [Watch: Dir/Any] [d/l] [select] |
ok - now I understand. I'm thinking this is going to get a little complicated with the possible differences in the @ID values. It may or may not have parenthesis. Could have only closing parenthesis, so it has to be able to match all different occurrences.
I tried adding in opening/closing parenthesis and it still won't match. I'm not a REGEX expert.
if ( $tag =~ m/<endnote id=((\d*)([[:alpha:]]*))>/ ) {
Input could be:
<endnote id=(1)>Text...</endnote>
<endnote id=(2)>Text...</endnote>
<endnote id=1)>Text...</endnote>
<endnote id=2)>Text...</endnote>
<endnote id=1.>Text...</endnote>
<endnote id=2.>Text...</endnote>
<endnote id=1a>Text...</endnote>
<endnote id=2cb>Text...</endnote>
<endnote id=a.1>Text...</endnote>
<endnote id=a.2>Text...</endnote>
etc...
| [reply] [Watch: Dir/Any] [d/l] |