473,378 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

problem with control structures ( if and next)


hello friends,

iam completely new bie iam tracing one

perl program .

this part of the code

</code>
sub parseRadAcct {

my ($refHashParam) = @_;
my $fname = $refHashParam->{'opt'}->{'radacct'};
open(RADACCT, "<$RADDIR/$fname")
my $l = "";
my $nr = 0;
my $ln = 0;
my %hashRec = ();
my $i = 0;
my $err = 0;
my $recLine = 0;
while($l = <RADACCT> ) {
$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");

};
</code>

my doubts are its not printing hello why?
and
what am i checking with if condition?

and what is storing in %hashRec
kindly help me

with regards
rama kanth

--
varala_kanth
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jul 19 '05 #1
3 3050
varala_kanth wrote:
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.
while($l = <RADACCT> ) {
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
Jul 19 '05 #2

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 wrote:
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.
while($l = <RADACCT> ) {
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/attachme...?postid=708305 |
+----------------------------------------------------------------+
--
varala_kanth
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Jul 19 '05 #3
varala_kanth wrote:
i try to learn in this way
That is a bad idea. You should learn Perl properly.
Try http://learn.perl.org for information.
yes open is succeded
Are you sure about that? You should *always* test the value
returned by open() to make sure it actually did succeed.
i actually have the semicolon
in my program while copieng it may have gone.
That is why you should copy-and-paste, not re-type the code.
i kept printf for my understandig purpose
You should use print() instead of printf() for that.
so please guide me


The code you posted could not possibly work.
It looks like you left something out.
It may help if you posted the actual code.
-Joe

P.S. Post to comp.lang.perl.misc next time; comp.lang.perl is defunct.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PHil Coveney | last post by:
Hello, I am having difficulty marshalling structures when calling DeviceIoControl. I am importing this Win32 function as static extern int DeviceIoControl (int hDevice, int...
2
by: Quantum | last post by:
I have the following Code I have a problem with. DataValues and RegNbr etc ... Never get written to. There's a problem about accessing the data structure member sdata. Can Any body Help ... ...
2
by: David Kao | last post by:
HI All: I am currently implementing a TextBox to allow user to type the things the user wants to search. The actual search routine is happening on Textbox Validated event. My user wants me trap...
3
by: Simang | last post by:
Hi everyone, I have a structure with this format: Public Structure Forms Public _01234 as string Public _04321 as string Public _03456 as integer End Structure As you can see, the variable...
8
by: ashu | last post by:
lets take a look at the following code:- #include<stdio.h> #include<conio.h> struct tag{ int age; char *name; }a;
4
by: Danny Mavromatis | last post by:
I'm trying to set up a structure using unions (fieldoffset) and I'm running into a problem. When I try to setup a union of data array or message type, I get the following error: ...
2
by: pgt | last post by:
I need to cease the execution of some code if a couple of conditions are not met. exit; destroys the rest of my page of course, so I *think* I need some sort of "wrapper", perhaps in a control...
3
by: shapper | last post by:
Hello, I had a class library which was working in Visual Studio 2008 Beta 2. Now that I installed the final version of VS2008 I get a error in my code: Dim footer As New...
9
MindBender77
by: MindBender77 | last post by:
Hello All, I believe I have a simple problem but, can't seem to find a easy solution. First, I developed a form (popup) with 2 combo boxes and a submit button. When I make a choice from both cbo...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.