Hi Jacinta and Hamish,<br><br>Thanks for pointing out to use the chomp function. That has done the trick. As I am fairly new to Perl, I could not for the life of me work this out.<br><br>Jacinta, thanks also for explaining other items related to the code. I have modified it accordingly.<br>
<br>Thanks for your assistance. <br><br><div class="gmail_quote">2009/3/27 Jacinta Richardson <span dir="ltr"><<a href="mailto:jarich@perltraining.com.au">jarich@perltraining.com.au</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Camillo Pereira wrote:<br>
<br>
> This is something that I had tried as well, however, the format of the<br>
> file ends up looking like the following:<br>
<br>
> <a href="http://cpploupoi09.my.domain.com.au" target="_blank">cpploupoi09.my.domain.com.au</a><br>
> <a href="http://1cabloupoi08.my.domain.com.au" target="_blank">1cabloupoi08.my.domain.com.au</a><br>
> <a href="http://1cacloupoi07.my.domain.com.au" target="_blank">1cacloupoi07.my.domain.com.au</a><br>
> <a href="http://1cadloupoi06.my.domain.com.au" target="_blank">1cadloupoi06.my.domain.com.au</a><br>
> <a href="http://1caeloupoi05.my.domain.com.au" target="_blank">1caeloupoi05.my.domain.com.au</a><br>
> <a href="http://1cafloupoi06.my.domain.com.au" target="_blank">1cafloupoi06.my.domain.com.au</a><br>
> 1<br>
<br>
</div>This suggests that the lines with your domain names on them have newlines still<br>
attached. You'll need to chomp these newlines off (perldoc -f chomp). For example:<br>
<br>
foreach (@DEVICE_LIST)<br>
{<br>
foreach my $t (@critical_device_def)<br>
<div class="im"> {<br>
my ($site, $device, $flag) = @$t;<br>
if ($_ =~ m/\G($device)/gc)<br>
{<br>
</div> chomp;<br>
print UPDATE "$_\t1\n" ;<br>
next;<br>
}<br>
}<br>
}<br>
<br>
I'm a bit worried about this line:<br>
<div class="im"><br>
if ($_ =~ m/\G($device)/gc)<br>
<br>
</div><div class="im">(which we'd normally write:<br>
<br>
if( m/\G$device/gc )<br>
<br>
</div>because you don't seem to be using $1 and matches work on $_ by default).<br>
<br>
It's very rare to need to use \G and /g, and I can't think of any way you'd need<br>
to be using it if you're going to call next; straight after a match. \G allows<br>
you to restart the regular expression from the end of the last successful match<br>
and try to match again from there. For example this code, with the repeating \G<br>
match line commented out:<br>
<br>
my $str = "catsatmat";<br>
<br>
foreach (1..3) {<br>
#if( $str =~ m{\G(\wat)}g ) {<br>
if( $str =~ m{(\wat)} ) {<br>
print "$1\n";<br>
}<br>
}<br>
<br>
gives us:<br>
<br>
cat<br>
cat<br>
cat<br>
<br>
If we swap the if statements, then we get:<br>
<br>
cat<br>
sat<br>
mat<br>
<br>
Since you're calling next after your successful match, I'd rewrite your inner<br>
loop to be:<br>
<br>
foreach my $t (@critical_device_def)<br>
<div class="im"> {<br>
my ($site, $device, $flag) = @$t;<br>
</div> if ($_ =~ m/$device/)<br>
{<br>
chomp;<br>
print UPDATE "$_\t1\n" ;<br>
}<br>
}<br>
<br>
I'm assuming that since you don't appear to know what $device matched you don't<br>
need to capture it. If you've simplified your code a lot, I might be wrong.<br>
I'm also assuming that you won't now need the next, but if you're doing extra<br>
stuff after the if() that you don't want to do on a match, you'll need to put it<br>
back in.<br>
<br>
Finally, you define a bunch of patters:<br>
<div class="im"><br>
my @critical_device_def = (<br>
[AAA => qr{...apb09} ],<br>
[BBB => qr{...avggd09} ],<br>
[CCC => qr{...uytwop09} ],<br>
</div> [DDD => qr{...loupoi09} ],<br>
);<br>
<br>
Using fat-comma here - while completely appropriate - may cause some people to<br>
misread this as a number of hash references. I just recommend to you that you<br>
keep that in mind.<br>
<br>
All the best,<br>
<br>
J<br>
<font color="#888888"><br>
--<br>
("`-''-/").___..--''"`-._ | Jacinta Richardson |<br>
`6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia |<br>
(_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 |<br>
_..`--'_..-_/ /--'_.' ,' | <a href="mailto:contact@perltraining.com.au">contact@perltraining.com.au</a> |<br>
(il),-'' (li),' ((!.-' | <a href="http://www.perltraining.com.au" target="_blank">www.perltraining.com.au</a> |</font></blockquote><div><br><br>===============================================================<br>
<br><br>---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Hamish Carpenter</b> <span dir="ltr"></span><br>Date: 2009/3/27<br>Subject: Re: [Melbourne-pm] Writing array data to file with appended information<br>
To: Camillo Pereira <br>Cc: <a href="mailto:melbourne-pm@pm.org">melbourne-pm@pm.org</a><br><br><br>Camillo,<br>
<br>
I believe the output you are getting has a newline at the end of each
domain. You will need to chomp() each line of output to remove the
newline and then manually append a new line.<div class="im"><br>
<br>
chomp;<br>
print UPDATE "$_\t1\n";<br>
<br></div>
See `perldoc -f chomp` for more info on chomp.<br>
<br>
Hamish <br></div></div><br>