To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
#!/usr/bin/env perl
use strict;
use warnings;
my $fil = './abc.log';
my $line;
my @VS;
open FPDATA, $fil or die "Can't open $fil";
while ($line = <FPDATA>) {
chomp ( $line );
if ( $line =~ "id=\"([[:alnum:]]*).*/" )
{
push(@VS, $1);
}
elsif ( $line =~ "socket-([[:alnum:]]*).*\]" && $line !~ "wup")
{
push(@VS, $1);
}
}
close (FPDATA);
foreach my $id (@VS)
{
print ("Login successful for ID $id\n");
}
# eof #
# output
# ------
# Login successful for ID PH12MC
# Login successful for ID PH11MC
# Login successful for ID PH11MD
# Login successful for ID PH11PP
# Login successful for ID PH11PK
# Login successful for ID ABC123
Hmmm.. Does it make any difference if you change the quotes to slashes?
Maybe I should have kept quiet, because I don't know the differences between MS perl and linux perl?( if there are any ). One would think the code would be portable ( except for line endings ).
@karan8810: Not sure if you understood what push(@VS, $1) does.
In the first if-block, you're using push, where as in the second if-block you're printing $1 directly. And you're not printing the values populated in @VS in the first if-block. So that's why you're not getting the output as expected.
You could do something like this:
while ( $line= <FILE>) {
chomp ($line);
if ($line =~ /virtualServer id=\"(.*?)\"/) {
push (@VS ,$1);
}
if ( $line =~ "socket-([[:alnum:]]*).*\]" && $line !~ "wup"){
push (@VS, $1);
}
}
close FILE;
print "@VS";
Also, did you try adapting ongoto's solution in post #14 ?