Re: RFC on first perl script

2003-11-07 Thread drowl

> <[EMAIL PROTECTED]> wrote:
>>
>>  well im trying at lerning this perl stuff.. reading from the
>> "learning
>> perl" oreilly book and a few other places,
>> but also using perl a long time before i should ie making the below
>> script, so that i dont get in to any very bad habbits at such an early
>> stage. could some one please have a look at the code below and give
>> comments, the code does do what i want it to ( well at leest from this
>> stage).
>
> [snip code]
>
> You seem to lack care. All lower-case and misspellings are likely
> to be reflected in your programming.
>

are yes sorry im dyslexic and lazzy, luckly when i spell a command wrong,
perl lets me know...
>> fnord
>> yes im a Concord Engineer, no it never flown!
>
> The aeroplane is spelled 'Concorde'. If you were truly on
> the engineering team for her then I have a million
> questions for you!
>
> Rob
>
>
yes i am not a 'Concorde' engineer im a Concord engineer
as you pointed out 'Concorde' is an aeroplane,
'Concord' is a network managment package ie http://www.concord.com

(i dont work for them i work for a companny the uses it, but my job title
is Concord engineer)

>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


-- 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RFC on first perl script

2003-11-07 Thread Rob Dixon
<[EMAIL PROTECTED]> wrote:
>
> well im trying at lerning this perl stuff.. reading from the "learning
> perl" oreilly book and a few other places,
> but also using perl a long time before i should ie making the below script,
> so that i dont get in to any very bad habbits at such an early stage.
> could some one please have a look at the code below and give comments, the
> code does do what i want it to ( well at leest from this stage).

[snip code]

Please post again, with the guidelines that others in this thread
have set.

If you can explain your problem properly then you have more
or less written your code.

<< The best software describes the data, just as the best
massage describes the person. >>

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RFC on first perl script

2003-11-07 Thread Rob Dixon
<[EMAIL PROTECTED]> wrote:
>
>  well im trying at lerning this perl stuff.. reading from the "learning
> perl" oreilly book and a few other places,
> but also using perl a long time before i should ie making the below script,
> so that i dont get in to any very bad habbits at such an early stage.
> could some one please have a look at the code below and give comments, the
> code does do what i want it to ( well at leest from this stage).

[snip code]

You seem to lack care. All lower-case and misspellings are likely
to be reflected in your programming.

> fnord
> yes im a Concord Engineer, no it never flown!

The aeroplane is spelled 'Concorde'. If you were truly on
the engineering team for her then I have a million
questions for you!

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RFC on first perl script

2003-11-06 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote:

> Hi all
>  well im trying at lerning this perl stuff.. reading from the "learning
> perl" oreilly book and a few other places,
> but also using perl a long time before i should ie making the below script,
> so that i dont get in to any very bad habbits at such an early stage.
> could some one please have a look at the code below and give comments, the
> code does do what i want it to ( well at leest from this stage).

I would comment on the process here.  I am sure that you know what you want, but do 
we?  Since you say
it does what you want, I assume it compiles.  While it may not be impossible to write 
good code by just
jumping into the coding, it is highly unlikely to happen.

> #!/usr/bin/perl -w
> 
> # this function creates a arf rule file from an input file
> # Version 0.1 6/11/03
> 

use strict;
use warnings;

> [snip]

Now recompile your code with those two lines at the top, and then repost, referably 
telling us, in
real-world terms, what problem you are trying to solve, or what task you are trying to 
accomplish, with
your program.  Defining your objective is the first step in solid programming.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: RFC on first perl script

2003-11-06 Thread Dan Muey
Howdy, 

Always use strict;
Then your variables won't get messy, see the perldoc strict for more details.

> foreach $site (@dataFile) {  # loop  for each line/site in dataFile
> chomp $site;

You might make your life easier to by not declaring a variable at all here:

for(@datafile) {
chomp;
...

Then you just use $_ where you would have used $site and you're all set. 
(Except with functions that are expecting $_ if nothing else is specified, 
like chomp for instance.)

But yes to declare a variable with use strcit you need to do my before and 
that will elt you use it within the block you declared it in.

HTH

DMuey

> 
> 
> ($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3); 
> #split up main / pvc info
> 
> ($siteIP,$siteString,$SiteName,$siteGroup,$siteCCTReff,$siteAC
> Rate)=split(/,/,$siteLink,6);
> #split up main info
> (@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);
> 
> my $siteARFfile = "$siteIP.arf";
> open(ARFfile, ">$siteARFfile") or die("can not open
> '$siteARFfile': $!");
> 
> print ARFfile 
> ("
> ##
> \n# \n# Discover Rule for:
> $siteIP \n# 
> \n
> ##
> \n\n"); # print header
> 
> print ARFfile ("@standardRules\n"); #print standard bits
> 
> print ARFfile ("name matches  \".*-Cpu-.*\": {\n \tsetName
> (\"$SiteName-RH-Cpu\") ;\n \tsetGroup (\"$siteGroup\")
> ;\n \tsetAlias (\"RH-Cpu\") ;\n} \n\n" ); # print -Cpu- rule
> 
> print ARFfile ("name matches  \".*-RH\": { \n \tsetName
> (\"$SiteName-RH\") ;\n \tsetGroup (\"$siteGroup\") ; \n \t 
> setAlias (\"RH\") ;\n} \n\n" ); # print -RH rule
> 
> print ARFfile ("name matches  \".*RH-Serial.*\": {\n \tsetName
> (\"$SiteName-RH-WAN\$2\") ;\n \tsetGroup (\"$siteGr
> oup\") ;\n \tsetAlias (\"$siteCCTReff\") ;\n \tsetSpeedIn
> (\"$siteACRate\") ;\n \tsetSpeedOut (\"$siteACRate\") ;\n 
> \tsetD eviceSpeedIn (\"$siteACRate\") ;\n \tsetDeviceSpeedOut 
> (\"$siteACRate\") ;\n} \n\n"); # print RH-Serial rule
> 
> 
> print ARFfile ("name matches  \".*-Serial.*\": {\n \tsetName
> (\"$SiteName-WAN\$2\") ;\n \tsetGroup (\"$siteGroup\"
> ) ;\n \tsetAlias (\"$siteCCTReff\") ;\n \tsetSpeedIn 
> (\"$siteACRate\") ;\n \tsetSpeedOut (\"$siteACRate\") ;\n 
> \tsetDevice SpeedIn (\"$siteACRate\") ;\n \tsetDeviceSpeedOut 
> (\"$siteACRate\") ;\n} \n\n"); # print -Serial rule
> 
> for ($i = 0; $i < $siteNoOfPVCs ; $i++ ) { # loop for each PVC
> 
> 
> ($PVCdlci,$PVCname,$PCVreff,$PVCcir)=split(/,/,"$sitePVCs[$i]",4);
> # split out pvc info
> 
> print ARFfile ("name matches  
> \".*-dlci-$PVCdlci\": {\n \tsetName (\"$SiteName-$PVCname\") 
> ;\n \tsetGroup
> (\"$siteGroup\") ;\n \tsetAlias (\"$PCVreff\") ;\n \tsetSpeedIn
> (\"$PVCcir\") ;\n \tsetSpeedOut (\"$PVCcir\") ;\n \tsetDev 
> iceSpeedIn (\"$PVCcir\") ;\n \tsetDeviceSpeedOut 
> (\"$PVCcir\") ;\n} \n\n"); # print PVC rules
> 
> 
> }
> 
> close(ARFfile) or die("can not close '$siteARFfile': $!"); }
> 
> 
> 
> ---
> fnord
> yes im a Concord Engineer, no it never flown!
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: RFC on first perl script

2003-11-06 Thread Dan Anderson
> Global symbol "$site" requires explicit package name at ./makeArf.pl line 17.

One of the things about strict is it makes you declare the scope of your
variables before using them.  So, for instance, while:

#! /usr/bin/perl
$foo = "foo\n";
print $foo;

Would run, the following wouldn't:

#! /usr/bin/perl
use warnings;  # yelp and whine if we screw up
use strict;# force us to not be sloppy.
$foo = "foo\n";
print $foo;

It would cause perl to say:
Global symbol "$foo" requires explicit package name at - line 4

We could fix that by changing like 4 to one of the following:
my $foo = "foo\n";   
our $foo = "foo\n";
local $foo = "foo\n";

>From Perldoc:

my EXPR
my TYPE EXPR
my EXPR : ATTRS
my TYPE EXPR : ATTRS

A "my" declares the listed variables to be local (lexically)
to the enclosing block, file, or "eval". If more than one value is
listed, the list must be placed in parentheses.  

The exact semantics and interface of TYPE and ATTRS are
still evolving. TYPE is currently bound to the use of "fields" pragma,
and attributes are handled using the "attributes" pragma, or starting
from Perl 5.8.0 also via the "Attribute::Handlers" module. See "Private
Variables via my()" in perlsub for details, and fields, attributes, and
Attribute::Handlers. 

local EXPR

You really probably want to be using "my" instead, because
"local" isn't what most people think of as "local". See
"Private Variables via my()" in perlsub for details.

A local modifies the listed variables to be local to the
enclosing block, file, or eval. If more than one value is
listed, the list must be placed in parentheses. See "Temporary   our
EXPR
our EXPR TYPE
our EXPR : ATTRS
our TYPE EXPR : ATTRS

An "our" declares the listed variables to be valid globals
within the enclosing block, file, or "eval". That is, it has the
same scoping rules as a "my" declaration, but does not create a
local variable. If more than one value is listed, the list must
be placed in parentheses. The "our" declaration has no semantic
effect unless "use strict vars" is in effect, in which case it
lets you use the declared global variable without qualifying it
with a package name. (But only within the lexical scope of the
"our" declaration. In this it differs from "use vars", which is
package scoped.)

An "our" declaration declares a global variable that will be
visible across its entire lexical scope, even across package
boundaries. The package in which the variable is entered is
determined at the point of the declaration, not at the point of
use. This means the following behavior holds:

package Foo;
our $bar;   # declares $Foo::bar for rest of lexical scope
$bar = 20;

package Bar;
print $bar; # prints 20

Multiple "our" declarations in the same lexical scope are
allowed if they are in different packages. If they happened to
be in the same package, Perl will emit warnings if you have
asked for them.

use warnings;
package Foo;
our $bar;   # declares $Foo::bar for rest of lexical scope
$bar = 20;

package Bar;
our $bar = 30;  # declares $Bar::bar for rest of lexical scope
print $bar; # prints 30

our $bar;   # emits warning

An "our" declaration may also have a list of attributes
associated with it.

The exact semantics and interface of TYPE and ATTRS are still
evolving. TYPE is currently bound to the use of "fields" pragma,
and attributes are handled using the "attributes" pragma, or
starting from Perl 5.8.0 also via the "Attribute::Handlers"
module. See "Private Variables via my()" in perlsub for details,
and fields, attributes, and Attribute::Handlers.

The only currently recognized "our()" attribute is "unique"
which indicates that a single copy of the global is to be used
by all interpreters should the program happen to be running in a
multi-interpreter environment. (The default behaviour would be
for each interpreter to have its own copy of the global.)
Examples:

our @EXPORT : unique = qw(foo);
our %EXPORT_TAGS : unique = (bar => [qw(aa bb cc)]);
our $VERSION : unique = "1.00";

Note that this attribute also has the effect of making the
global readonly when the first new interpreter is cloned (for
example, when the first new thread is created).

Multi-interpreter environments can come to being either through
the fork() emulation on Windows platforms, or by embedding perl
in a multi-threaded application. The "unique" attribute does
nothing in all other environments.

Values via local()" in perlsub for details, including issues
with tied arrays and hashes.

-Dan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RFC on first perl script

2003-11-06 Thread drowl
> On Thu, 06 Nov 2003 16:33:41 +, drowl wrote:
>> #!/usr/bin/perl -w
>
> No big deal, but - IMO - easier to read, and it adds strict;
>
>   #!/usr/bin/perl
>   #
>   use strict;
>   use warnings;
>
>> @dataFile=<>; # read in file from command line
>> @standardRules=`cat standard.for.arf.txt` ;
>
>   my @dataFile  = <>;
>   my @standardRules = `cat standard.for.arf.txt`;
>
> Also have in mind that this is platform dependent, as there is no 'cat'
> command in DOS/Windows (or on many other platforms, I would guess).
>
> Instead of doing the whole work with open, read and close all the time,
> you could do as me:  Write your own module which has a 'read_file'
> function;
>
>   sub read_file {
>   my $filename = shift || '';
>
>   my @lines = ();
>   if ( $filename && -e $filename ) {
>   if ( open(FILE, $filename) ) {
>   @lines = ;
>   close( FILE );
>   chomp( @lines );
>   }
>   }
>
>   return ( wantarray ) ? @lines : join("\n", @lines);
>   }
>
> This one is very simplified, but it gives you and idea.  Next time you
> need to read a (text) file:
>
>   my $text = read_file( 'text.txt' );
>

nice... how ever i hope to turn this into a sub with  $site as input
and $siteIP and $siteString as output + the arf file of course

but maybe i can use this in the main proggi..

>> #split up main / pvc info
>> ($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3);
>
> As long as we don't know what the contents of $site looks like, we can't
> comment on this.

$site would look like:
127.0.0.1,comunityString,sitename,group,e23,2:2:bsite,21,p235,32000;csite,22,p523,64000

>
>> for ($i = 0; $i < $siteNoOfPVCs ; $i++ ) { # loop for each PVC
>
> I guess this should do the trick:
>
>   foreach ( @sitePVCs ) {
>   # ...
>   }
>
>
humm then would i just use ...=split(/,/,$_,4);  ???


> --
> Tore Aursand <[EMAIL PROTECTED]>
>
>
>


Thanks
   Ritch
-- 
fnord
yes im a Concord Engineer, no it never flown!



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RFC on first perl script

2003-11-06 Thread drieux
On Thursday, Nov 6, 2003, at 09:56 US/Pacific, [EMAIL PROTECTED] wrote:

i now get the below warning along with many others...
how does one declair a varible then?
Global symbol "$site" requires explicit package name at ./makeArf.pl 
line 17.


I think your hit is at:

	foreach $site (@dataFile) {  # loop

and that should have been

	foreach my $site (@dataFile) {  # loop

this way '$site' is limited to the scope of the foreach loop.

ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: RFC on first perl script

2003-11-06 Thread drowl

 Good stuff all taken on board
  did take me a while to figger out that EOF had to be at the begging of
the line tho, but i got there in the end...

and a question about "use strict"

i now get the below warning along with many others...
how does one declair a varible then?

Global symbol "$site" requires explicit package name at ./makeArf.pl line 17.



 thank you
   Ritch

>> please have a look at the code below and give comments
>
> Here are some quick comments.
>
> #1. Always "use strict"
> #2. See #1.
>
> When you "use strict" it foeces you to do things the "right way" and
> will help catch errors because of the extra checks it makes.
>
> So something like this:
>> @dataFile=<>; # read in file from command line
>
> Needs to be changed to this by explicitly declaring that variable: my
> @dataFile=<>; # read in file from command line
>
>> @standardRules=`cat standard.for.arf.txt` ;
>
> This isn't portable (if you care for it to be), and does not check for
> errors.  This might be better:
>
> open IN, 'standard.for.arf.txt' or die $!;
> my @standardRules = ;
> close IN;
>
>> (@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);
>
> The "(" and ")" force list context.  The array @sitePVCs will already
> force list context without the parens.  This can be rewriten like this,
> which may or may not be more readable to you:
>
> my @sitePVCs = split(/;/,$siteAllPVCs,$siteNoOfPVCs);
>
>> open(ARFfile, ">$siteARFfile") or die("can not open
>
> Typically filehandles are in all caps.  They don't need to be, but it is
> the usual way of doing things because it makes them easier to spot
> (especially to people other than the author).  Also the parens are not
> needed because "or" has very low precedence.  I also tend to put my
> error condition on the next line, but that is just my preference.
>
> open ARFFILE, ">$siteARFfile"
>   or die "can not open '$siteARFfile': $!";
>
> Again, parens not needed here, but they don't hurt either:
>
>> print ARFfile ("@standardRules\n"); #print standard bits
> print ARFFILE "@standardRules\n"; #print standard bits
>
> This is pretty icky:
>>print ARFfile ("name matches  \".*RH-Serial.*\":
>> {\n \tsetName(\"$SiteName-RH-WAN\$2\") ;\n \tsetGroup
>> (\"$siteGroup\") "); # print RH-Serial rule
>
> Try a here-document instead:
>
> # print RH-Serial rule
> print ARFFILE < name matches  ".*RH-Serial.*": {
> setName("$SiteName-RH-WAN\$2");
> setGroup("$siteGroup");
> setAlias("$siteCCTReff");
> setSpeedIn("$siteACRate");
> setSpeedOut("$siteACRate");
> setDeviceSpeedIn("$siteACRate");
> setDeviceSpeedOut("$siteACRate");
> }
> EOF
>
> It makes it a lot easier to read, not to mention I could remove the \n
> and the \" escapes.  BTW - If you have quotes in your string you can do
> this qq[a "blah" b] instead of "a \"blah\" b".  The char following the
> "qq" can be any char, so you could use qq{}, qq||, qq**, etc.
>
> In general there isn't anything *wrong* with the script... but "use
> strict" is STRONGLY encouraged.  The rest are just suggestions for
> readability.
>
> Rob
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 06, 2003 11:34 AM
> To: [EMAIL PROTECTED]
> Subject: RFC on first perl script
>
>
>
>
> Hi all
>  well im trying at lerning this perl stuff.. reading from the "learning
> perl" oreilly book and a few other places,
> but also using perl a long time before i should ie making the below
> script, so that i dont get in to any very bad habbits at such an early
> stage. could some one please have a look at the code below and give
> comments, the code does do what i want it to ( well at leest from this
> stage).
>
>
> #!/usr/bin/perl -w
> 
> # this function creates a arf rule file from an input file
> # Version 0.1 6/11/03
> 
> @dataFile=<>; # read in file from command line
> @standardRules=`cat standard.for.arf.txt` ;
>
> foreach $site (@dataFile) {  # loop  for each line/site in dataFile
> chomp $site;
>
> ($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3);
> #split
> up main / pvc info
>
> ($siteIP,$

Re: RFC on first perl script

2003-11-06 Thread Tore Aursand
On Thu, 06 Nov 2003 16:33:41 +, drowl wrote:
> #!/usr/bin/perl -w

No big deal, but - IMO - easier to read, and it adds strict;

  #!/usr/bin/perl
  #
  use strict;
  use warnings;

> @dataFile=<>; # read in file from command line
> @standardRules=`cat standard.for.arf.txt` ;

  my @dataFile  = <>;
  my @standardRules = `cat standard.for.arf.txt`;

Also have in mind that this is platform dependent, as there is no 'cat'
command in DOS/Windows (or on many other platforms, I would guess).

Instead of doing the whole work with open, read and close all the time,
you could do as me:  Write your own module which has a 'read_file'
function;

  sub read_file {
  my $filename = shift || '';

  my @lines = ();
  if ( $filename && -e $filename ) {
  if ( open(FILE, $filename) ) {
  @lines = ;
  close( FILE );
  chomp( @lines );
  }
  }

  return ( wantarray ) ? @lines : join("\n", @lines);
  }

This one is very simplified, but it gives you and idea.  Next time you
need to read a (text) file:

  my $text = read_file( 'text.txt' );

> #split up main / pvc info
> ($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3);

As long as we don't know what the contents of $site looks like, we can't
comment on this.

> for ($i = 0; $i < $siteNoOfPVCs ; $i++ ) { # loop for each PVC

I guess this should do the trick:

  foreach ( @sitePVCs ) {
  # ...
  }


-- 
Tore Aursand <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: RFC on first perl script

2003-11-06 Thread Hanson, Rob
> please have a look at the code below and give comments

Here are some quick comments.

#1. Always "use strict"
#2. See #1.

When you "use strict" it foeces you to do things the "right way" and will
help catch errors because of the extra checks it makes.

So something like this:
> @dataFile=<>; # read in file from command line

Needs to be changed to this by explicitly declaring that variable:
my @dataFile=<>; # read in file from command line

> @standardRules=`cat standard.for.arf.txt` ;

This isn't portable (if you care for it to be), and does not check for
errors.  This might be better:

open IN, 'standard.for.arf.txt' or die $!;
my @standardRules = ;
close IN;

> (@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);

The "(" and ")" force list context.  The array @sitePVCs will already force
list context without the parens.  This can be rewriten like this, which may
or may not be more readable to you:

my @sitePVCs = split(/;/,$siteAllPVCs,$siteNoOfPVCs);

> open(ARFfile, ">$siteARFfile") or die("can not open

Typically filehandles are in all caps.  They don't need to be, but it is the
usual way of doing things because it makes them easier to spot (especially
to people other than the author).  Also the parens are not needed because
"or" has very low precedence.  I also tend to put my error condition on the
next line, but that is just my preference.

open ARFFILE, ">$siteARFfile"
  or die "can not open '$siteARFfile': $!";

Again, parens not needed here, but they don't hurt either:

> print ARFfile ("@standardRules\n"); #print standard bits
print ARFFILE "@standardRules\n"; #print standard bits

This is pretty icky:
>print ARFfile ("name matches  \".*RH-Serial.*\":
> {\n \tsetName(\"$SiteName-RH-WAN\$2\") ;\n \tsetGroup
> (\"$siteGroup\") "); # print RH-Serial rule

Try a here-document instead:

# print RH-Serial rule
print ARFFILE <mailto:[EMAIL PROTECTED]
Sent: Thursday, November 06, 2003 11:34 AM
To: [EMAIL PROTECTED]
Subject: RFC on first perl script




Hi all
 well im trying at lerning this perl stuff.. reading from the "learning
perl" oreilly book and a few other places,
but also using perl a long time before i should ie making the below script,
so that i dont get in to any very bad habbits at such an early stage.
could some one please have a look at the code below and give comments, the
code does do what i want it to ( well at leest from this stage).


#!/usr/bin/perl -w

# this function creates a arf rule file from an input file
# Version 0.1 6/11/03

@dataFile=<>; # read in file from command line
@standardRules=`cat standard.for.arf.txt` ;

foreach $site (@dataFile) {  # loop  for each line/site in dataFile
chomp $site;

($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3); #split
up main / pvc info
 
($siteIP,$siteString,$SiteName,$siteGroup,$siteCCTReff,$siteACRate)=split(/,
/,$siteLink,6);
#split up main info
(@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);

my $siteARFfile = "$siteIP.arf";
open(ARFfile, ">$siteARFfile") or die("can not open
'$siteARFfile': $!");

print ARFfile
("##
\n# \n# Discover Rule for:
$siteIP \n#
\n##
\n\n"); # print header

print ARFfile ("@standardRules\n"); #print standard bits

print ARFfile ("name matches  \".*-Cpu-.*\": {\n \tsetName
(\"$SiteName-RH-Cpu\") ;\n \tsetGroup (\"$siteGroup\")
;\n \tsetAlias (\"RH-Cpu\") ;\n} \n\n" ); # print -Cpu- rule

print ARFfile ("name matches  \".*-RH\": { \n \tsetName
(\"$SiteName-RH\") ;\n \tsetGroup (\"$siteGroup\") ; \n \t
setAlias (\"RH\") ;\n} \n\n" ); # print -RH rule

print ARFfile ("name matches  \".*RH-Serial.*\": {\n \tsetName
(\"$SiteName-RH-WAN\$2\") ;\n \tsetGroup (\"$siteGr
oup\") ;\n \tsetAlias (\"$siteCCTReff\") ;\n \tsetSpeedIn
(\"$siteACRate\") ;\n \tsetSpeedOut (\"$siteACRate\") ;\n \tsetD
eviceSpeedIn (\"$siteACRate\") ;\n \tsetDeviceSpeedOut (\"$siteACRate\")
;\n} \n\n"); # print RH-Serial rule


print ARFfile ("name matches  \".*-Serial.*\": {\n \tsetName
(\"$SiteName-WAN\$2\") ;\n \tsetGroup (\"$siteGroup\"
) ;\n \tsetAlias (\"$siteCCTReff\") ;\n \tsetSpeedIn (\"$siteACRate\") ;\n
\tsetSpeedOut (\&q

RFC on first perl script

2003-11-06 Thread drowl


Hi all
 well im trying at lerning this perl stuff.. reading from the "learning
perl" oreilly book and a few other places,
but also using perl a long time before i should ie making the below script,
so that i dont get in to any very bad habbits at such an early stage.
could some one please have a look at the code below and give comments, the
code does do what i want it to ( well at leest from this stage).


#!/usr/bin/perl -w

# this function creates a arf rule file from an input file
# Version 0.1 6/11/03

@dataFile=<>; # read in file from command line
@standardRules=`cat standard.for.arf.txt` ;

foreach $site (@dataFile) {  # loop  for each line/site in dataFile
chomp $site;

($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3); #split
up main / pvc info

($siteIP,$siteString,$SiteName,$siteGroup,$siteCCTReff,$siteACRate)=split(/,/,$siteLink,6);
#split up main info
(@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);

my $siteARFfile = "$siteIP.arf";
open(ARFfile, ">$siteARFfile") or die("can not open
'$siteARFfile': $!");

print ARFfile
("##
\n# \n# Discover Rule for:
$siteIP \n#
\n##
\n\n"); # print header

print ARFfile ("@standardRules\n"); #print standard bits

print ARFfile ("name matches  \".*-Cpu-.*\": {\n \tsetName
(\"$SiteName-RH-Cpu\") ;\n \tsetGroup (\"$siteGroup\")
;\n \tsetAlias (\"RH-Cpu\") ;\n} \n\n" ); # print -Cpu- rule

print ARFfile ("name matches  \".*-RH\": { \n \tsetName
(\"$SiteName-RH\") ;\n \tsetGroup (\"$siteGroup\") ; \n \t
setAlias (\"RH\") ;\n} \n\n" ); # print -RH rule

print ARFfile ("name matches  \".*RH-Serial.*\": {\n \tsetName
(\"$SiteName-RH-WAN\$2\") ;\n \tsetGroup (\"$siteGr
oup\") ;\n \tsetAlias (\"$siteCCTReff\") ;\n \tsetSpeedIn
(\"$siteACRate\") ;\n \tsetSpeedOut (\"$siteACRate\") ;\n \tsetD
eviceSpeedIn (\"$siteACRate\") ;\n \tsetDeviceSpeedOut (\"$siteACRate\")
;\n} \n\n"); # print RH-Serial rule


print ARFfile ("name matches  \".*-Serial.*\": {\n \tsetName
(\"$SiteName-WAN\$2\") ;\n \tsetGroup (\"$siteGroup\"
) ;\n \tsetAlias (\"$siteCCTReff\") ;\n \tsetSpeedIn (\"$siteACRate\") ;\n
\tsetSpeedOut (\"$siteACRate\") ;\n \tsetDevice
SpeedIn (\"$siteACRate\") ;\n \tsetDeviceSpeedOut (\"$siteACRate\") ;\n}
\n\n"); # print -Serial rule

for ($i = 0; $i < $siteNoOfPVCs ; $i++ ) { # loop for each PVC

($PVCdlci,$PVCname,$PCVreff,$PVCcir)=split(/,/,"$sitePVCs[$i]",4);
# split out pvc info

print ARFfile ("name matches  \".*-dlci-$PVCdlci\": {\n
\tsetName (\"$SiteName-$PVCname\") ;\n \tsetGroup
(\"$siteGroup\") ;\n \tsetAlias (\"$PCVreff\") ;\n \tsetSpeedIn
(\"$PVCcir\") ;\n \tsetSpeedOut (\"$PVCcir\") ;\n \tsetDev
iceSpeedIn (\"$PVCcir\") ;\n \tsetDeviceSpeedOut (\"$PVCcir\") ;\n}
\n\n"); # print PVC rules


}

close(ARFfile) or die("can not close '$siteARFfile': $!");
}



---
fnord
yes im a Concord Engineer, no it never flown!



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]