Hello jue,
thanks first for seeing the code
as i told you iam traceing the code
which was written by others
as i donot have much depth with perl
i try to learn in this way
soory for indentation i will keep it to
the standards next time onwards.
yes open is succeded
and also it has the data in that file
i actually have the semicolon
in my program while copieng it may have
gone.
i have the doubts in the statement like
these
if ($l =~ /^\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+$/m)
and after this if condtion it has to
goto(then only that code works properly)
next if i.e ( last record comment code)
iam attaching the program with this
i kept printf for my understandig
purpose
so please guide me
with regards,
rama kanth
OTE]-Originally posted by Jürgen Exner -
*varala_kanth said:
iam completely new bie iam tracing one
perl program .
[Your indention style is horrible; I strongly suggest you improve that,
it
would make your code much more readable]
sub parseRadAcct {
my ($refHashParam) = @_;
my $fname = $refHashParam->{'opt'}->{'radacct'};
open(RADACCT, "<$RADDIR/$fname")
This doesn't even compile! You are missing a semicolon.
Plus a test if the open succeded.
my $l = "";
my $nr = 0;
my $ln = 0;
my %hashRec = ();
my $i = 0;
my $err = 0;
my $recLine = 0;
No need for any of those initializations. Those are all the default
values
anyway.
Is this a $1 (one) or a $l (lima)?
I suggest you don't use characters that can easily be confused as
variable
names. l (lima) is one of them, the other hot candidate is o (oscar).
And why using an explicit name anyway? The default $_ ought to work
just as
well and wouldn't cause a lot of head scratching as to why the
programmer
decided to introduce an additional variable.
$ln++;
chomp $l;
# look for start of record
if ($l =~ /^\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+$/m) {
$nr = 1;
%hashRec = ();
$recLine = $ln;
next;
};
printf ("hello");
Don't use a printf() when a plain print() will do. See The Fine Manual
for
details.
};
</code>
my doubts are its not printing hello why?
Some possible reasons:
- You don't call the sub at all
- How do you know that the open() succeeded? You don't check the
return
value.
- Your file doesn't contain any data, therefore the while() fails
right
away.
and
what am i checking with if condition?
You wrote the code, don't you know? Tell us what _you_ had in mind when
you
wrote this RE, then we can check if it does what you think it should
do.
Reverse engineering REs without any hint to their intended use is a
rather
difficult job.
and what is storing in %hashRec
The hash is repeatedly set to the empty hash, nothing else.
jue *
+----------------------------------------------------------------+
| Attachment filename: rad2db.txt |
|Download attachment:
http://www.codecomments.com/attachment.php?postid=708305 |
+----------------------------------------------------------------+