Re: Need help with a question.



In article <48666e7f$0$14348$e4fe514c@xxxxxxxxxxxxxx>, Erwin van Koppen
<invalid@xxxxxxxxxxxxxxx> wrote:

"Trev" wrote:

Thanks, I've made the changes and so far so good.

foreach $cpqlog (@cpqlog_data) {
{
chomp($cpqlog);

if ($cpqlog =~ /MAC/) {
$cpqlog =~ s/ <FIELD NAME="Subject" VALUE="//i;
$cpqlog =~ s/ <FIELD NAME="MAC" VALUE="//i;
$cpqlog =~ s/"\/>//i;
}
}
}

You do understand that the above code does not actually change anything in
the file, right? The substitutions in $cpqlog are just discarded at the end
of the loop.

Not quite. In Perl, the loop variable $cpqlog is an "alias" to the
array elements, so the changes to $cpqlog are applied to the members of
the array. Of course, whether or not the file is modified depends upon
what is done after the loop. (Just trying to clear up any
misunderstanding about what "discarded at the end of the loop" means.)

--
Jim Gibson
.



Relevant Pages

  • Re: Need help with a question.
    ... The substitutions in $cpqlog are just discarded at the end of the loop. ... You'd still have to write that array back to the file if that's the ... intent. ... foreach my $cpqlog ...
    (comp.lang.perl.misc)
  • Re: Need help with a question.
    ... foreach $cpqlog { ...     chomp; ... The substitutions in $cpqlog are just discarded at the end ...
    (comp.lang.perl.misc)
  • Re: Need help with a question.
    ... "Trev" wrote: ... foreach $cpqlog { ... The substitutions in $cpqlog are just discarded at the end ... and you might want to get rid of the superfluous 's... ...
    (comp.lang.perl.misc)