RE: Is CYGWIN a unix like environment to run PERL modules?

2005-01-18 Thread arjun.mallik

Hi
CYGWIN installation is in two parts , I am not sure whether u have
followed that ?
And CYGWIN is like X-windows to work on UNIX session from Windows
machines... Other s/w like this are Exceed [ licensed..].
If u want I can give u the full CYGWIN s/w I have.

cheers
Arjun

Deserve before you desire







-Original Message-
From: Zapa Perl [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 18, 2005 1:11 PM
To: beginners@perl.org
Subject: Is CYGWIN a unix like environment to run PERL modules?


Hello,

I installed CYGWIN on Win-2000 hoping to have a Linux like environment
and run PERL. I was expecting to click on the CYGWIN desktop icon and
get a prompt window and move on. but that is not what I got. when I
double click on CYGWIN desktop icon something flashes and disappears
quickly and no chance of doing anything. how do I get to CYGWIN prompt
window?
or how do I get to Linux like environment to run my PERL modules? thank
you in advance. Zapa.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com



Confidentiality Notice

The information contained in this electronic message and any attachments to 
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or 
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

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




Dynamic pattern matching?

2005-01-18 Thread Dan Fish

I've got a data file that for the most part, the entries look like:  (The
last 3 columns are data points...)

LKG_535   P10X0.6 -2.00E-09   0.00E+00  amps -3.800E-13
-3.920E-12   -7.800E-13 
VT_GM L0.8H40 -1.15E+00  -7.50E-01  volts-1.104E+00
-1.111E+00   -1.110E+00  
IDSAT_5   Y0.8N20 -5.80E-03  -3.00E-03  amps -5.036E-06
-5.001E-06   -4.853E-06   
VT_GP P0.8X.6 -1.15E+00  -7.50E-01  volts-1.018E+00
-9.966E-01   -1.012E+00 
LOGU_II2.00.6  6.00E-03   1.00E-02  amps  8.992E-03
8.939E-038.903E-03 

which I match with the following:

# RE for a valid floating point number
$fp = qr/[+-]?\ *(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?/;

# Case for 3 data points
if $line =~
/(.{9})\s+(.{10})\s+.{4}\s+($fp)\s+($fp)\s+(.{8})\s+($fp)\s+($fp)\s+($fp)\s+
$/o) 
{
  $datapts = 3
  #Insert matched vars into Class::Struct array...
  ...
}

But optionally, and once in a while there might be a line that looks like:
(this case shows 3 extra columns [data points], but in reality there could
be 1,3 or 5 more columns)

HGYPG5M1_LG   OT   0.00E+00   2.00E-08  amps  1.000E-06
4.000E-112.000E-116.000E-114.000E-118.000E-11 

I know I can write an if() clause to match every possible case, but I'm
wondering if there is a more general approach that would allow me to
dynamically match a varying number of extra columns within a single
expression.

Thanks,
-Dan   

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


RE: Dynamic pattern matching?

2005-01-18 Thread Moon, John
I've got a data file that for the most part, the entries look like:  (The
last 3 columns are data points...)

LKG_535   P10X0.6 -2.00E-09   0.00E+00  amps -3.800E-13
-3.920E-12   -7.800E-13 
VT_GM L0.8H40 -1.15E+00  -7.50E-01  volts-1.104E+00
-1.111E+00   -1.110E+00  
IDSAT_5   Y0.8N20 -5.80E-03  -3.00E-03  amps -5.036E-06
-5.001E-06   -4.853E-06   
VT_GP P0.8X.6 -1.15E+00  -7.50E-01  volts-1.018E+00
-9.966E-01   -1.012E+00 
LOGU_II2.00.6  6.00E-03   1.00E-02  amps  8.992E-03
8.939E-038.903E-03 

which I match with the following:

# RE for a valid floating point number
$fp = qr/[+-]?\ *(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?/;

# Case for 3 data points
if $line =~
/(.{9})\s+(.{10})\s+.{4}\s+($fp)\s+($fp)\s+(.{8})\s+($fp)\s+($fp)\s+($fp)\s+
$/o) 
{
  $datapts = 3
  #Insert matched vars into Class::Struct array...
  ...
}

But optionally, and once in a while there might be a line that looks like:
(this case shows 3 extra columns [data points], but in reality there could
be 1,3 or 5 more columns)

HGYPG5M1_LG   OT   0.00E+00   2.00E-08  amps  1.000E-06
4.000E-112.000E-116.000E-114.000E-118.000E-11 

I know I can write an if() clause to match every possible case, but I'm
wondering if there is a more general approach that would allow me to
dynamically match a varying number of extra columns within a single
expression.

Thanks,
-Dan   

Here a suggestion

#! /usr/local/bin/perl
open PNTS,"points.dat" or die "Open failed";
@jumps=(\&p8,\&p9,\&p10,\&p11,\&p12);
while () {
@points = split /\s+/;
print "entries =<", scalar(@points) - 8, ">\n";
&{$jumps[scalar(@points) - 8]}
if scalar(@points) > 7 && scalar(@points) < 13;
}
sub p8{print "8 values\n";}
sub p9{print "9 values\n";}
sub p10{print "10 values\n";}
sub p11{print "11 values\n";}
sub p12{print "12 values\n";}

I hope this gives you some ideas ...

jwm

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




regex needed

2005-01-18 Thread Chris Knipe
Lo everyone,

Can someone please give me a regex to parse the following... 



Flags: X - disabled, I - invalid, D - dynamic, J - rejected,
C - connect, S - static, r - rip, o - ospf, b - bgp
 #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
[EMAIL PROTECTED] >


I want the regex to return the rule number for all route entries that is static 
(S Flag) on Interface "National Gateway".  For added security, I'd like it if 
the regex will also only return true if the gateway address is part of 
165.165.0.0/8 or 165.146.0.0/8

Basically, I need to use the rule number in another command to delete the route 
entry... So I presume I'll need to extract it via the regex

Hope someone can help me here..

--
Chris.



Re: losing a value after chomp()

2005-01-18 Thread RichT
Hi again,
  ok i made the changes sugested, but something is still wrong.
the output im getting is 
--
"interface is "ATM0
"interface is "ATM0.38
--

ie the " is at the start of the line???

i think this is some thing to do with the way Cisco::Reconfig is
returning the values, becouse this happens every time i chomp a value
i get from it.
 any one why this might be happening?

yours most confused, Ritchie

new 
code---
#!/usr/local/bin/perl
use strict;
use Cisco::Reconfig;
use warnings;


# Scan PE routers configs from the rcl box
# Parameters :
#   router name of site to be found
#   $router.cfg file : this is the data file
# Returns :
#   outputs a csv with port info from config

my($routerName)=$ARGV[0] || die  "you must supply a router name on the
command line";
my($findVars)="discription, ip address, cctReff, siteName, vpnName";
my($findInterfaces)="Serial,POS,ATM";

if ( ! -r "currIPS/$routerName.cfg") {die "could not read
currIPS/$routerName.cfg : $!";}

my $config = readconfig("currIPS/$routerName.cfg");

for my $interfaceTypes (split/\,/,$findInterfaces) { #loop throught
interface types
  
  for my $found ($config->get('interface')->all($interfaceTypes)) { #
loop through found interfaces

my $interface=getPortFromFullInterface($found);

print "\$interface is \"$interface\"\n";
  }
} #end for

sub getPortFromFullInterface {
  my $part=shift;
  chomp($part);
  $part =~ s/^interface //g;
  $part =~ s/ point-to-point//g;
  $part =~ s/ multipoint//g;
  return($part);
};
--


On Mon, 17 Jan 2005 19:46:36 +0100, Tor Hildrum <[EMAIL PROTECTED]> wrote:
> On Mon, 17 Jan 2005 17:57:28 +, RichT <[EMAIL PROTECTED]> wrote:
> >   Hi All,
> >
> >time for me to ask dumb questions again...
> >
> > I have a script, what i want it to do is scan through a Cisco
> > router Config file (nicely saved in a text file already so no need for
> > and SNMP), then output it to a .csv file.
> > I an using the  Cisco::Reconfig; module to help me out.
> >
> >   My problem is when i try to remove a charidge return from a
> > variable, the value ends up blank, you will see from below i have
> > tryed a few different ways to make this work, but i am lost (i suspect
> > some basic Perl knowledge is missing).
> >   any help would be most appreciated thank you .
> 
> chomp($var); is perfectly valid.
> 
> Try this code:
> 
> > sub getPortFromFullInterface {
> >   my $part = shift;
> 
>  print "I'm inside getPortFromFullInterface(), \$part is: $part\n";
> 
> >   $part =~ s/^interface //g;
> >   $part =~ s/ point-to-point//g;
> >   $part =~ s/ multipoint//g;
>  chomp($part);
> 
> >   return($part);
> > };
> 
> Tor
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 


-- 
--
Fnord...
<-- http://23.me.uk --> <-- http://info-x.co.uk  --> <--
http://seti23.org --> <-- Get FireFox Now -->

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




Re: Is CYGWIN a unix like environment to run PERL modules?

2005-01-18 Thread Alfred Vahau
Hi,
Bring up command prompt and run cygwin.bat in it.
The contents of cygwin.bat should be [for my setup]
@echo off
C:
chdir C:\cygwin\bin
bash --login -i
If you want the Linux GUI feel, then you need to load X-Windows.
The cygwin URL is:
http://www.cygwin.com/
alfred,

Zapa Perl wrote:
Hello,
I installed CYGWIN on Win-2000 hoping to have a Linux like environment and run PERL.
I was expecting to click on the CYGWIN desktop icon and get a prompt window and move on.
but that is not what I got. when I double click on CYGWIN desktop icon something flashes
and disappears quickly and no chance of doing anything.
how do I get to CYGWIN prompt window? 
or how do I get to Linux like environment to run my PERL modules?
thank you in advance.
Zapa.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
 

--
Perl is my reason for following the Sun;

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



Re: regex needed

2005-01-18 Thread Randy W. Sims
Chris Knipe wrote:
Lo everyone,
Can someone please give me a regex to parse the following... 


Flags: X - disabled, I - invalid, D - dynamic, J - rejected,
C - connect, S - static, r - rip, o - ospf, b - bgp
 #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
[EMAIL PROTECTED] >
I want the regex to return the rule number for all route entries that is static (S 
Flag) on Interface "National Gateway".  For added security, I'd like it if the 
regex will also only return true if the gateway address is part of 165.165.0.0/8 or 
165.146.0.0/8
Basically, I need to use the rule number in another command to delete the route entry... So I presume I'll need to extract it via the regex
If it's a fixed width data format, its better (easier for you, faster 
for perl) to break up the string with C:

#!/usr/bin/perl
use strict;
use warnings;
while (defined( my $line =  )) {
chomp( $line );
my %data;
$data{rule}  = substr( $line,  0,  2 );
$data{flags} = substr( $line,  3,  2 );
$data{dest_ip}   = substr( $line,  6, 18 );
$data{g} = substr( $line, 25,  1 );
$data{gateway}   = substr( $line, 27, 16 );
$data{distance}  = substr( $line, 43,  8 );
$data{interface} = substr( $line, 52 );
# cleanup, stripping spaces
$data{$_} =~ s/^\s+|\s+$//g
for keys %data;
# reformat or reinterpret data
$data{flags} = [ split( //, $data{flags} ) ];
use Data::Dumper;
print Dumper( \%data );
}

__END__
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: regex needed

2005-01-18 Thread Chris Knipe
Hi Randy,
Ok thank you very much.  This works :)  The problem now, is that I have 
never before in my life worked with hashes...

I have now looped the route list, and it is saved in the hash.  Do I loop 
the hash again now (dumping all data) and then put in comparisions?  I'm not 
100% on how to work with this further now to check which route is on the 
interface that I actually want to delete...

I want to achieve something like
if (($data{interface} eq "National Gateway") && ($data{gateway} =~ 
m/165\.(165|146)\.0\.[0-8]/)) {
 #work with $data{rule};
}

--
Chris.



- Original Message - 
From: "Randy W. Sims" <[EMAIL PROTECTED]>
To: "Chris Knipe" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, January 18, 2005 4:04 PM
Subject: Re: regex needed


Chris Knipe wrote:
Lo everyone,
Can someone please give me a regex to parse the following... Flags: X - 
disabled, I - invalid, D - dynamic, J - rejected,
C - connect, S - static, r - rip, o - ospf, b - bgp
 #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
[EMAIL PROTECTED] >

I want the regex to return the rule number for all route entries that is 
static (S Flag) on Interface "National Gateway".  For added security, I'd 
like it if the regex will also only return true if the gateway address is 
part of 165.165.0.0/8 or 165.146.0.0/8

Basically, I need to use the rule number in another command to delete the 
route entry... So I presume I'll need to extract it via the regex
If it's a fixed width data format, its better (easier for you, faster for 
perl) to break up the string with C:

#!/usr/bin/perl
use strict;
use warnings;
while (defined( my $line =  )) {
chomp( $line );
my %data;
$data{rule}  = substr( $line,  0,  2 );
$data{flags} = substr( $line,  3,  2 );
$data{dest_ip}   = substr( $line,  6, 18 );
$data{g} = substr( $line, 25,  1 );
$data{gateway}   = substr( $line, 27, 16 );
$data{distance}  = substr( $line, 43,  8 );
$data{interface} = substr( $line, 52 );
# cleanup, stripping spaces
$data{$_} =~ s/^\s+|\s+$//g
for keys %data;
# reformat or reinterpret data
$data{flags} = [ split( //, $data{flags} ) ];
use Data::Dumper;
print Dumper( \%data );
}

__END__
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway


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



Re: losing a value after chomp()

2005-01-18 Thread Tor Hildrum
On Tue, 18 Jan 2005 13:22:14 +, RichT <[EMAIL PROTECTED]> wrote:
> Hi again,
>   ok i made the changes sugested, but something is still wrong.
> the output im getting is
> --
> "interface is "ATM0
> "interface is "ATM0.38
> --
> 
> ie the " is at the start of the line???

> print "\$interface is \"$interface\"\n";

Uhm? I can't see anything wrong here. Might be a linefeed at the end
of $interface though.

Try this code:
$interface =~ s/\r//g;
print "\$interface is \"$interface\"\n";

Tor

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




linked list again.

2005-01-18 Thread Christian Stalp
Hello again,
I still have some questions concerning the linked list.
The problem now is, that I try to access the head-pointer of the list after I 
left the loop in which the list were made. 

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

use constant NEXT => 0;
use constant VAL  => 1;


our $kopf = undef;
my $zeiger = \$kopf;
my $zahl = 5;

foreach ( 1..$zahl )
{
 my $node = [ undef, $_ * $_ ];

 if ( ! $kopf )
 {
  $zeiger = \$node;
  $kopf = \$node;
 }

 else
 {
  $$zeiger -> [ NEXT ] = \$node;
  $zeiger = $node -> [ NEXT ];
 }

 #print $node -> [ VAL ], "\n";
}

print Dumper ( $kopf );
print $$kopf -> [ VAL ], "\n";
$zeiger = $kopf;

while ( ref $zeiger  )
{
 print $$zeiger -> [ VAL ], "\n";
 $zeiger = $$zeiger -> [ NEXT ];
}

But the output shows me just the first two nodes: 1 and 4.
And if I create the nodes inside the loop as global ( our ) then it puts me 
only the last node out.
What did I wrong?

Gruss Christian


-- 
Christian Stalp

Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
Obere Zahlbacher Straße 69
55131 Mainz
Tel.: 06131/ 17-6852

E-Mail: [EMAIL PROTECTED]
Internet: www.imbei.de

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




Re: Dynamic pattern matching?

2005-01-18 Thread Dave Gray
> I know I can write an if() clause to match every possible case, but I'm
> wondering if there is a more general approach that would allow me to
> dynamically match a varying number of extra columns within a single
> expression.

You could shove all the data points into one parenthetical group in
the first regex and then process them inside the if statement.
Something like:

my $line = 'HGYPG5M1_LG   OT   0.00E+00   2.00E-08  amps  1.000E-06
4.000E-112.000E-116.000E-114.000E-118.000E-11';
$line =~ s/[\r\n]/ /g; #line wrap

# ... is everything else that i'm too lazy to type ;)
if ($line =~ /^...(?:amps|volts)((?\s+[.0-9eE+-]+)+)$/) {
  # last backref contains all data points
  my (..., $datapoints) = (..., $6);
  my @datapoints = split //, $datapoints;
  # process based on (scalar @datapoints)
}

HTH,
Dave

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




Re: Forcing script to run as root?

2005-01-18 Thread Randal L. Schwartz
> "Brian" == Brian Barto <[EMAIL PROTECTED]> writes:

Brian> Hi all. How can I check, within a script, to see if it is being
Brian> run as root or not? I would like it to exit with an error
Brian> message if it is not running as root.

die "we need more power!" if $>;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: losing a value after chomp()

2005-01-18 Thread RichT
On Tue, 18 Jan 2005 15:30:42 +0100, Tor Hildrum <[EMAIL PROTECTED]> wrote:
> On Tue, 18 Jan 2005 13:22:14 +, RichT <[EMAIL PROTECTED] > wrote:
> > Hi again,
> >   ok i made the changes sugested, but something is still wrong.
> > the output im getting is
> > --
> > "interface is "ATM0
> > "interface is "ATM0.38
> > --
> >
> > ie the " is at the start of the line???
> 
> > print "\$interface is \"$interface\"\n";
> 
> Uhm? I can't see anything wrong here. Might be a linefeed at the end
> of $interface though.
> 
> Try this code:
> $interface =~ s/\r//g;
> print "\$interface is \"$interface\"\n";

Grate that worked, the varible must of have a \r and a \n at the end.
thank you very much...

how would i find our what escape chars are in a varible?
or is there a way to print out a string with out perl translating the
escape chars?

 Thank you again, Ritchie

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


-- 
--
Fnord...
<-- http://23.me.uk --> <-- http://info-x.co.uk  --> <--
http://seti23.org --> <-- Get FireFox Now -->

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




dynamically calling a subroutine

2005-01-18 Thread Absolut Newbie
I have a program that generates a random number between 1 and 6. based on
the outcome I want to run a subroutine that corresponds to the result.
i.e if the result is 1 then the program should run sub F1. my question is
how can I dynamically call the subroutine.

i tried this but obviously it didn't work

$var1 = int(rand(6)) + 1 ; # i didn't want zero as an answer
$var1 ='F'.$var1; # sub names can't start w/ numbers

$var1(); # this is where it crashes

#assuming $var1 = F1 then it would run this
sub F1 {
print  "foo\n";
}

#assuming $var1 = F2 then it would run this.
sub F2 {
print  "bar\n";
}


Thanx !!



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




Re: dynamically calling a subroutine

2005-01-18 Thread Stone
On Tue, 18 Jan 2005 20:05:01 +0200, Absolut Newbie
<[EMAIL PROTECTED]> wrote:

> $var1(); # this is where it crashes

You're looking for the eval command, which will read a string and
evaluate the code it contains.  ie:

eval ( "$var1()" );

On on the other hand, you could do this with if statements.

if ($var1 == 1) {
   ...do something...
} elsif ($var1 == 2) {
   ...do something else...
} ...

HTH

-- 
http://xstonedogx.heroesmarket.net

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




RE: dynamically calling a subroutine

2005-01-18 Thread Moon, John
I have a program that generates a random number between 1 and 6. based on
the outcome I want to run a subroutine that corresponds to the result.
i.e if the result is 1 then the program should run sub F1. my question is
how can I dynamically call the subroutine.

i tried this but obviously it didn't work

$var1 = int(rand(6)) + 1 ; # i didn't want zero as an answer
$var1 ='F'.$var1; # sub names can't start w/ numbers

$var1(); # this is where it crashes

#assuming $var1 = F1 then it would run this
sub F1 {
print  "foo\n";
}

#assuming $var1 = F2 then it would run this.
sub F2 {
print  "bar\n";
}



Here's one way ...

%jumps = (F1=>\&F1, ... Fn=>\&Fn);
...
&{$jumps{$varl}} if exists $jumps{$varl};
...

Hope this gives you some idea's ...

jwm


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




Re: regex needed

2005-01-18 Thread John W. Krahn
Chris Knipe wrote:
Lo everyone,
Hello,
Can someone please give me a regex to parse the following... 

Flags: X - disabled, I - invalid, D - dynamic, J - rejected,
C - connect, S - static, r - rip, o - ospf, b - bgp
 #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
 0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
 1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
 2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
 3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
 4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
 5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
 6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
[EMAIL PROTECTED] >
I want the regex to return the rule number for all route entries that
is static (S Flag) on Interface "National Gateway".  For added security,
I'd like it if the regex will also only return true if the gateway
address is part of 165.165.0.0/8 or 165.146.0.0/8
Basically, I need to use the rule number in another command to delete
the route entry... So I presume I'll need to extract it via the regex
I take it that the first column is the rule number?
#   UNTESTED
my ( $rule_number ) =
m{^
   \s*   # start with optional whitespace
  (\d+)  # capture the first column
   \s+
   S # second col. must be 'S'
   \s+
   \S+
   \s+
   \S+
   \s+
   165\.(?: 146 | 165 )  # fifth col. must be correct IP range
(?: \.
(?: [1-9]?\d | 1\d\d | 2[0-4]\d | 25[0-5] )
){2}
   \s+
   \d+
   \s+
   National[ ]Gateway# last (seventh) column
 $}x;
#   UNTESTED

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: dynamically calling a subroutine

2005-01-18 Thread Bob Showalter
Absolut Newbie wrote:
> I have a program that generates a random number between 1 and 6.
> based on the outcome I want to run a subroutine that corresponds to
> the result. i.e if the result is 1 then the program should run sub
> F1. my question is how can I dynamically call the subroutine.
> 
> i tried this but obviously it didn't work
> 
> $var1 = int(rand(6)) + 1 ; # i didn't want zero as an answer
> $var1 ='F'.$var1; # sub names can't start w/ numbers
> 
> $var1(); # this is where it crashes

You need &$var1();

But 'use strict' doesn't like that, because $var1 is a so-called "soft"
reference, so you can enclose it in a block like this:

   { no strict 'refs'; &$var1(); }

This is generally frowned upon, but for what you're doing it's fine.

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




Re: dynamically calling a subroutine

2005-01-18 Thread Ron Wingfield

  - Original Message - 
  From: Stone 
  To: beginners@perl.org 
  Sent: Tuesday, January 18, 2005 12:20 PM
  Subject: Re: dynamically calling a subroutine


  On Tue, 18 Jan 2005 20:05:01 +0200, Absolut Newbie
  <[EMAIL PROTECTED]> wrote:

  > $var1(); # this is where it crashes

  You're looking for the eval command, which will read a string and
  evaluate the code it contains.  ie:

  eval ( "$var1()" );

  On on the other hand, you could do this with if statements.

  if ($var1 == 1) {
 ...do something...
  } elsif ($var1 == 2) {
 ...do something else...
  } ...

  HTH

--

  I just proved this example, too, (as coded, sub F2 executes):

#! /usr/bin/perl -w

my $var = 2;
eval("F$var()");

sub F1 {
print "Got to F1\n";
}

sub F2 {
print "Got to F2\n";
}
ALSO, I've been experimenting with a SWITCH scenario, . . .just this morning, 
and works as follows:# 
-
# Perl does not have a true case/switch operation; however, 
# this Perl "switch" construct emulates the scenario by using
# the pattern matching operator, //, the binding operator, =~,
# and the "short circuit" operator, &&, to "switch" through
# the conditions.  Note that there is nothing special or 
# reserved regarding the spelling of the word, "SWITCH",
# . . .it can be anything.  Also, the example is constructed
# within and returns from a subroutine.
# -

sub action_ex {
SWITCH: {
$action =~ /Inquire/ && do{
db_Inquire();
last SWITCH;
};
$action =~ /Update/  && do{
db_Update();
last SWITCH;
};
$action =~ /Insert/  && do{
db_Insert();
last SWITCH;
};
$action =~ /Delete/  && do{
db_Delete();
last SWITCH;
};
DEFAULT: return 0; # No match
} # end-switch
return 1;
} # end-sub

--


  -- 
  http://xstonedogx.heroesmarket.net

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




Re: dynamically calling a subroutine

2005-01-18 Thread John W. Krahn
Absolut Newbie wrote:
I have a program that generates a random number between 1 and 6. based on
the outcome I want to run a subroutine that corresponds to the result.
i.e if the result is 1 then the program should run sub F1. my question is
how can I dynamically call the subroutine.
i tried this but obviously it didn't work
$var1 = int(rand(6)) + 1 ; # i didn't want zero as an answer
$var1 ='F'.$var1; # sub names can't start w/ numbers
$var1(); # this is where it crashes
#assuming $var1 = F1 then it would run this
sub F1 {
print  "foo\n";
}
#assuming $var1 = F2 then it would run this.
sub F2 {
print  "bar\n";
}
Store references to the subroutines in an array something like this:
my @subs = ( \&F1, \&F2, \&F3, \&F4, \&F5, \&F6 );
And then call the one you want like this:
$subs[ rand @subs ]();

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: losing a value after chomp()

2005-01-18 Thread Tor Hildrum
On Tue, 18 Jan 2005 15:15:00 +, RichT <[EMAIL PROTECTED]> wrote:

> Grate that worked, the varible must of have a \r and a \n at the end.
> thank you very much...
> 
> how would i find our what escape chars are in a varible?
> or is there a way to print out a string with out perl translating the
> escape chars?
> 
>  Thank you again, Ritchie

I believe Windows use \r\n, while most(?) *nix' use \n. 
What happened is probably that when your script runs:

 for my $found ($config->get('interface')->all($interfaceTypes)) 

$config-get.. just returns the whole line(or the last part of the line) 
from a file that has windows line-ending(\r\n).

Tor

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




Re: dynamically calling a subroutine

2005-01-18 Thread JupiterHost.Net

Absolut Newbie wrote:
I have a program that generates a random number between 1 and 6. based on
the outcome I want to run a subroutine that corresponds to the result.
i.e if the result is 1 then the program should run sub F1. my question is
how can I dynamically call the subroutine.
i tried this but obviously it didn't work
use strict;
use warnings;
# always do those :)
$var1 = int(rand(6)) + 1 ; # i didn't want zero as an answer
my $var1 = ...
$var1 ='F'.$var1; # sub names can't start w/ numbers

Why not
my $var1 = 'F' . int(rand(6)) + 1;
??
$var1(); # this is where it crashes
see `perldoc perlref` for reference info
This is a soft ref and you're not doing it right
try
 $var1->();
or
 {$var1}->();
Or better yet, do it with hard references:
#!/usr/bin/perl
use strict;
use warnings;
my %funcs = (
  1 => \&foo,
  2 => \&bar,
  3 => \&baz,
  4 => \&bot,
  5 => \&wam,
  6 => \&pow
);
$funcs{ int(rand(6)) + 1 }->();
sub foo { print "Foo\n"; }
sub bar { print "Bar\n"; }
sub baz { print "Baz\n"; }
sub bot { print "Bot\n"; }
sub wam { print "Wam\n"; }
sub pow { print "Pow\n"; }
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: how to

2005-01-18 Thread Scott R. Godin
Juan Gomez wrote:
 
Good day 

 I am new to perl but I need a jump start to CGI so I have active perl 5.8.1
install in my pc 
Now a friend gave me a script that has a form and sends an email with the
data 
Now in his pc its working fine but when I try it in my pc did not work 


Is there some documentation about how to make it work from my computer???
Thanks
Hopefully this script is not one from Matt's Script Archive, but is in 
fact a drop-in replacement for those (which would be more secure and not 
prone to the bugs and hacking that matt's scripts are.)

see http://nms-cgi.sourceforge.net/
if you're simply sending e-mails from a form's submitted data, I'd use 
one of the scripts from the above source.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: beginners Digest 18 Jan 2005 12:52:35 -0000 Issue 2433

2005-01-18 Thread B McKee
Apologies for the layout and busted thread - I'm on digest mode
From: "JupiterHost.Net" <[EMAIL PROTECTED]>
I believe this will do what you want:
  next if grep { $rawreport_item =~ /$_/ } @possibleMatches;
Just make sure the regexes in @possibleMatches are not user supplied 
or they may try sneaky bad things :)
yep - strictly hardcoded for this useage.
perl -mstrict -we 'my @m = (q(^\d+$), q(^\w+$)); for my $item (qw(123 
abc 1-2we)){ next if grep { $item =~ /$_/ } @m; print "$item\n"; }'
HTH :)
Lee.M - JupiterHost.Net
Thanks Lee - that does look like what I was thinking of.
I'm now using
while () {
my @linesToDiscard = ( q(\f), q(^DATE : ), q(^\s{15,}PART ), 
q(^COUNTER QTY), q(^\s+$) ) ;
my $lineItem = $_ ;
next if grep { $lineItem =~ /$_/ } @linesToDiscard ;
  etc.

From: "John W. Krahn" <[EMAIL PROTECTED]>
What you probably want is:
while (  ) {
next if /\f|^DATE : |^\s{15,}PART |^COUNTER QTY|^\s+$/  ;
print ; # debugging purposes - other stuff here
}
Although you should read this first:
perldoc -q "How do I efficiently match many regular expressions at 
once"
John
Hi John -	I did think of using the | in the regex, but didn't that 
wasn't what I was after.
Long term I _may_ use this for different reports, or the report _may_ 
change, and I wanted
and easy spot to make changes.
I read that FAQ, and I don't understand it...:-) yet.  Thanks, 
I see how it applies,
but I think I'll skip using it until I get how that suggestion works.  
I've made a note
to revisit later.

So, now I'm off to figure out this scoping problem I have
But I'm learning !
Brian
--
"I don't understand," said the scientist, "why you lemmings all rush 
down
to the sea and drown yourselves."
"How curious," said the lemming. "The one thing I don't understand is 
why
you human beings don't."
-- James Thurber

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



Neat Trick

2005-01-18 Thread Graeme St. Clair
Or I thought so anyway.  Gurus are at liberty to think otherwise ;-)
 
I just had to make a single  with 4 submit buttons (each with the same
'value' legend) out of 4 's each with its own 'hidden' field.  I used
the following to distinguish between them:-
 
my $request = defined $formData->param(q{Submit1}) ? q{serial} :
  defined $formData->param(q{Submit2}) ? q{order} :
  defined $formData->param(q{Submit3}) ? q{sql} :
  defined $formData->param(q{Submit4}) ? q{user} :
 q{Unknown};

Probably it could be still more obfuscated...
 
HTH somebody, rgds, GStC.
 


Dblib.so can't load shared object

2005-01-18 Thread Laxminarayana, Jayanth N
I am getting the following error when I try to run a perl script

Can't load
'/opt/perllib-5.8.2/sybperl/2.16-1251.EBF12107/auto/Sybase/DBlib/DBlib.so'
for module Sybase::DBlib:
/opt/perllib-5.8.2/sybperl/2.16-1251.EBF12107/auto/Sybase/DBlib/DBlib.so:
cannot open shared object file: No such file or directory at
/usr/lib64/perl5/5.8.0/x86_64-linux-thread-multi/DynaLoader.pm line 229.
 at /home/riskqa/lib/MRT/Core/Database.pm line 22
Compilation failed in require at /home/riskqa/lib/MRT/Core/Database.pm line
22.
BEGIN failed--compilation aborted at /home/riskqa/lib/MRT/Core/Database.pm
line 22.
Compilation failed in require at /home/riskqa/lib/MRT/Core/DBConnPool.pm
line 18.
BEGIN failed--compilation aborted at /home/riskqa/lib/MRT/Core/DBConnPool.pm
line 18.
Compilation failed in require at /home/riskqa/bin/getbdate line 53.
BEGIN failed--compilation aborted at /home/riskqa/bin/getbdate line 53.

I am not able to find the reason as to why this is happening.
The file in question exists 

ls -l
/opt/perllib-5.8.2/sybperl/2.16-1251.EBF12107/auto/Sybase/DBlib/DBlib.so
-r-xr-xr-x1 root root   237446 Dec 23 17:46
/opt/perllib-5.8.2/sybperl/2.16-1251.EBF12107/auto/Sybase/DBlib/DBlib.so

Thanks,
Jayanth


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




Re: beginners Digest 18 Jan 2005 12:52:35 -0000 Issue 2433

2005-01-18 Thread JupiterHost.Net
From: "JupiterHost.Net" <[EMAIL PROTECTED]>
I believe this will do what you want:
  next if grep { $rawreport_item =~ /$_/ } @possibleMatches;
Just make sure the regexes in @possibleMatches are not user supplied 
or they may try sneaky bad things :)

yep - strictly hardcoded for this useage.
perl -mstrict -we 'my @m = (q(^\d+$), q(^\w+$)); for my $item (qw(123 
abc 1-2we)){ next if grep { $item =~ /$_/ } @m; print "$item\n"; }'
HTH :)
Lee.M - JupiterHost.Net

Thanks Lee - that does look like what I was thinking of.
great ;p
I'm now using
while () {
my @linesToDiscard = ( q(\f), q(^DATE : ), q(^\s{15,}PART ), 
q(^COUNTER QTY), q(^\s+$) ) ;
Why redefine @linesToDiscard which each $_ ?
my @linesToDiscard = ('\f','^DATE : ','^\s{15,}PART ','^COUNTER 
QTY','^\s+$');
while() {
 ...

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



Perl print command from browser

2005-01-18 Thread Grant
On Gentoo Linux

I have a printer that doesn't have a Linux driver, but I know how it
can be printed to within a perl environment.  The labels to be printed
are images viewed within a web browser (firefox), and firefox lets you
specify the exact command that prints.  I'm not too familiar with
perl.  Would it be possible to put the entire 5-or-so line script in
firefox's menu?  If not, would it work to put the script in a file and
change firefox's print command to execute the script?

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




Retrieving data from telephone system.

2005-01-18 Thread Jason Balicki
I'm looking for some help with a little project
that I've got going and I'm not a programmer.
I can muddle my way through some things, but
I've never started anything from scratch.

The overview is that I am trying to get some
accounting information from a phone system,
and this phone system has a simple, defined
protocol for retrieving data.

I have a little documentation for this, included
below.

So, would anyone be willing to give me a hand
with this?  I can't offer anything except
gratitude, sorry.

I feel certain that what I need is very, very
simple (connect to a port, squirt a "helo" type
message, and start logging responses.)  I've
been trying to do something with perl, but
I don't know anything about perl. :/  I've
done everything I've ever needed in some
sort of unix shell but I think I've hit the
limitations of that.

Below is what little documentation I've got
available from the system vendor.  They
offer their own application, but it's prohibitively
expensive.  If I can just get this data out and
put in a database I can manipulate it to my
hearts content.

I appreciate any help I can get at all here.  I
feel pretty confident that if I can just get
over the hump of getting started, just the
basic connect and retrieve, I can probably
take it from there and learn a lot in the
process.  I just don't know where to begin.

>From the docs, it seems like I could:

connect to pcx:2533, send 00H 11H 53H (I'm
assuming these are hex values)
Wait for the status message and proceed
accordingly ("server not available, etc")

If it's available, send the
init request

check for the response

check every line for test messages, send a
response to the test.

Log every other response from the phone system
to a file (for now) as it's probably call accounting
data.

Again, it appears to be simple, but, um,
how?  It's just a matter of syntax, but
I've been overloaded with information, I
think, and I need someone to kickstart me.

Documentation:

Dialog: principle
The PCX is considered to be a server and the external application to be a
client. The external machine initiates the connection. The PCX initiates
transmission of available tickets.

Note: If the external application is not available, tickets are stored
(buffer memory for 2500 tickets).

Connection with the application
Before dialog can be launched, the external application must connect to the
PCX. It must open a connection with port 2533 of the active CPU (Netaccess
server).

Once connected, dialog can be initiated.

initialization dialog
Identifying CPU role:

The external machine sends the message: 00H 11H 53H ("S" message used to
select the SvTSE application).

The PCX responds:

00H 11H 4FH if the CPU is active ("P" message),

00H 11H 53H if the CPU is in backup mode ("S" message),

00H 11H 55H if the CPU has undefined status, i.e. loading is in progress
("U" message).

If the CPU is not active, the connection must be closed and a new connection
made to the active CPU.

Server initialization:

The external machine sends the message "INIT_REQ": 00H 02H 00H 00H 

The PCX responds with the message "INIT_RSP": 00H 03H 01H 00H 01H 

Maintain connection dialog
To check that the remote machine is present, the PCX sends test frames every
30 seconds. 

The PCX sends the message "TEST_REQ": 00H 08H "TEST_REQ"

The external machine must repond with the message "TEST_RSP" : 00H 08H
"TEST_RSP"

If two "TEST_REQ" messages remain unanswered, the PCX considers that the
external machine can no longer be reached. It closes the connection and
releases associated resources.

Accounting (charging) ticket
When a ticket is available, the PCX sends the following message:

Accounting (charging) ticket
___
||||  |
| 01 | 02 | LG |   Ticket |
| H  | H  ||  |
---

LG is ticket length.

TICKET : is the accounting ticket. Ticket format depends on PCX release
(version).

No acknowledgement is expected.

Ticket format
Charging ticket format depends on PCX release (version). 


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




Re: Perl print command from browser

2005-01-18 Thread Daniel Kasak
Grant wrote:
On Gentoo Linux
I have a printer that doesn't have a Linux driver, but I know how it
can be printed to within a perl environment.  The labels to be printed
are images viewed within a web browser (firefox), and firefox lets you
specify the exact command that prints.  I'm not too familiar with
perl.  Would it be possible to put the entire 5-or-so line script in
firefox's menu?  If not, would it work to put the script in a file and
change firefox's print command to execute the script?
 

This last option sound like the way to go.
Just out of interest ... what sort of printer is it?
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: Perl print command from browser

2005-01-18 Thread Grant
> >On Gentoo Linux
> >
> >I have a printer that doesn't have a Linux driver, but I know how it
> >can be printed to within a perl environment.  The labels to be printed
> >are images viewed within a web browser (firefox), and firefox lets you
> >specify the exact command that prints.  I'm not too familiar with
> >perl.  Would it be possible to put the entire 5-or-so line script in
> >firefox's menu?  If not, would it work to put the script in a file and
> >change firefox's print command to execute the script?
> >
> >
> This last option sound like the way to go.

Ok, thanks a lot.  If that sounds like it should work then I'll set that up.

> Just out of interest ... what sort of printer is it?

It's a Zebra LP 2844 thermal label printer.

- Grant

> Daniel Kasak

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




Re: Neat Trick

2005-01-18 Thread Jenda Krynicky
From: "Graeme St. Clair" <[EMAIL PROTECTED]>
> Or I thought so anyway.  Gurus are at liberty to think otherwise ;-)
> 
> I just had to make a single  with 4 submit buttons (each with
> the same 'value' legend) out of 4 's each with its own 'hidden'
> field.  I used the following to distinguish between them:-
> 
> my $request = defined $formData->param(q{Submit1}) ? q{serial} :
>   defined $formData->param(q{Submit2}) ? q{order} :
>   defined $formData->param(q{Submit3}) ? q{sql} :
>   defined $formData->param(q{Submit4}) ? q{user} :
>q{Unknown};
> 
> Probably it could be still more obfuscated...

How about:

my %action = (
Submit1 => 'serial',
Submit2 => 'order',
Submit3 => 'sql',
Submit4 => 'user',
);
...

my ($request) = grep {defined $formData->param($_) and $action{$_}} 
keys %action;
$request ||= 'Unknown';


or 

my ($request) = map $action{$_}, (grep (defined($formData-
>param($_)), keys %action;
$request ||= 'Unknown';


I also think that your code would be more readable if you used '' 
instead of q{}.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




RE: Neat Trick

2005-01-18 Thread Graeme St. Clair
Wow!  I might just try these two for kicks, tho as nobody likely to inherit
this from me is likely to be a Perl hand, I think I'll probably KISS for
now.

I don't necessarily disagree about '' vs qq{}.  It's just that the rest of
the code is styled with qq{}, and I thought it better to keep that going.

Tx & rgds, GStC.


-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 18, 2005 7:26 PM
To: beginners@perl.org
Subject: Re: Neat Trick



How about:

my %action = (
Submit1 => 'serial',
Submit2 => 'order',
Submit3 => 'sql',
Submit4 => 'user',
);
...

my ($request) = grep {defined $formData->param($_) and $action{$_}} keys
%action; $request ||= 'Unknown';

or 

my ($request) = map $action{$_}, (grep (defined($formData-
>param($_)), keys %action;
$request ||= 'Unknown';

I also think that your code would be more readable if you used '' 
instead of q{}.

Jenda

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




more format stuff

2005-01-18 Thread Hawkes, Mick I
Hi all,

Before Christmas  I had a thread going where I was trying to get "pretty" or 
neat formats in an email

In the end someone kindly provided me with the following solution ( I can't 
find the post)

formline 'FORM', $name, $age, $ID;
NAME |AGE | ID NUMBER 
--++---
@<<< | @| | @ 
$name, $age,$ID,
===
COMMENTS  
---
FORM
formline 'FORM', $comments;
^<<< ~~
FORM

My $string = $^A

This is good, it allows me to use $string in my email code.

My question is how do I now modify the code to allow for a list of say 10 names 
from an array?

TIA


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




RE: regex needed

2005-01-18 Thread Manav Mathur

Chris , cant get to you.

1) Use $RouteArray[2] instead of $RouteArray['2']
2) POst me the 11th route entry

|-Original Message-
|From: Chris Knipe [mailto:[EMAIL PROTECTED]
|Sent: Tuesday, January 18, 2005 7:55 PM
|To: beginners@perl.org
|Subject: Re: regex needed
|
|
|Hi Randy,
|
|Ok thank you very much.  This works :)  The problem now, is that I have
|never before in my life worked with hashes...
|
|I have now looped the route list, and it is saved in the hash.  Do I loop
|the hash again now (dumping all data) and then put in
|comparisions?  I'm not
|100% on how to work with this further now to check which route is on the
|interface that I actually want to delete...
|
|I want to achieve something like
|
|if (($data{interface} eq "National Gateway") && ($data{gateway} =~
|m/165\.(165|146)\.0\.[0-8]/)) {
|  #work with $data{rule};
|}
|
|--
|Chris.
|
|
|
|
|
|
|
|- Original Message -
|From: "Randy W. Sims" <[EMAIL PROTECTED]>
|To: "Chris Knipe" <[EMAIL PROTECTED]>
|Cc: 
|Sent: Tuesday, January 18, 2005 4:04 PM
|Subject: Re: regex needed
|
|
|> Chris Knipe wrote:
|>> Lo everyone,
|>>
|>> Can someone please give me a regex to parse the following... Flags: X -
|>> disabled, I - invalid, D - dynamic, J - rejected,
|>> C - connect, S - static, r - rip, o - ospf, b - bgp
|>>  #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
|>>  0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
|>>  1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
|>>  2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
|>>  3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
|>>  4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
|>>  5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
|>>  6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
|>> [EMAIL PROTECTED] >
|>>
|>>
|>> I want the regex to return the rule number for all route
|entries that is
|>> static (S Flag) on Interface "National Gateway".  For added
|security, I'd
|>> like it if the regex will also only return true if the gateway
|address is
|>> part of 165.165.0.0/8 or 165.146.0.0/8
|>>
|>> Basically, I need to use the rule number in another command to
|delete the
|>> route entry... So I presume I'll need to extract it via the regex
|>
|> If it's a fixed width data format, its better (easier for you,
|faster for
|> perl) to break up the string with C:
|>
|> #!/usr/bin/perl
|>
|> use strict;
|> use warnings;
|>
|>
|> while (defined( my $line =  )) {
|> chomp( $line );
|>
|> my %data;
|> $data{rule}  = substr( $line,  0,  2 );
|> $data{flags} = substr( $line,  3,  2 );
|> $data{dest_ip}   = substr( $line,  6, 18 );
|> $data{g} = substr( $line, 25,  1 );
|> $data{gateway}   = substr( $line, 27, 16 );
|> $data{distance}  = substr( $line, 43,  8 );
|> $data{interface} = substr( $line, 52 );
|>
|> # cleanup, stripping spaces
|> $data{$_} =~ s/^\s+|\s+$//g
|> for keys %data;
|>
|> # reformat or reinterpret data
|> $data{flags} = [ split( //, $data{flags} ) ];
|>
|> use Data::Dumper;
|> print Dumper( \%data );
|> }
|>
|>
|>
|> __END__
|>  0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
|>  1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
|>  2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
|>  3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
|>  4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
|>  5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
|>  6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
|>
|>
|
|
|--
|To unsubscribe, e-mail: [EMAIL PROTECTED]
|For additional commands, e-mail: [EMAIL PROTECTED]
| 
|
|


*
Disclaimer:  

This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

*
Visit us at http://www.mahindrabt.com


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




RE: regex needed

2005-01-18 Thread Manav Mathur

Ok Chris. I think I know why thats happening. Its because in some of your
route entries, there's a space at the beginning whereas for some there aint
such thing.

try the following

#!/usr/bin/perl
my @RouteList = $Terminal->cmd("ip route print");
foreach (@RouteList) {
s/^\s*// ;
chomp ;
my @RouteArray = split(/ +/,$_,8);
if (($RouteArray[2] =~ /^\s*S$/) and ($RouteArray[5] =~
m/^165\.(165|146)/) and ($RouteArray[7] =~ m/National\s*Gateway/i)) {
  $Terminal->cmd("ip route remove " . $RouteArray[1]);
   }
  }



|-Original Message-
|From: Manav Mathur [mailto:[EMAIL PROTECTED]
|Sent: Wednesday, January 19, 2005 12:58 PM
|To: Chris Knipe; beginners@perl.org
|Subject: RE: regex needed
|
|
|
|Chris , cant get to you.
|
|1) Use $RouteArray[2] instead of $RouteArray['2']
|2) POst me the 11th route entry
|
||-Original Message-
||From: Chris Knipe [mailto:[EMAIL PROTECTED]
||Sent: Tuesday, January 18, 2005 7:55 PM
||To: beginners@perl.org
||Subject: Re: regex needed
||
||
||Hi Randy,
||
||Ok thank you very much.  This works :)  The problem now, is that I have
||never before in my life worked with hashes...
||
||I have now looped the route list, and it is saved in the hash.  Do I loop
||the hash again now (dumping all data) and then put in
||comparisions?  I'm not
||100% on how to work with this further now to check which route is on the
||interface that I actually want to delete...
||
||I want to achieve something like
||
||if (($data{interface} eq "National Gateway") && ($data{gateway} =~
||m/165\.(165|146)\.0\.[0-8]/)) {
||  #work with $data{rule};
||}
||
||--
||Chris.
||
||
||
||
||
||
||
||- Original Message -
||From: "Randy W. Sims" <[EMAIL PROTECTED]>
||To: "Chris Knipe" <[EMAIL PROTECTED]>
||Cc: 
||Sent: Tuesday, January 18, 2005 4:04 PM
||Subject: Re: regex needed
||
||
||> Chris Knipe wrote:
||>> Lo everyone,
||>>
||>> Can someone please give me a regex to parse the following... Flags: X -
||>> disabled, I - invalid, D - dynamic, J - rejected,
||>> C - connect, S - static, r - rip, o - ospf, b - bgp
||>>  #DST-ADDRESSG GATEWAY DISTANCE INTERFACE
||>>  0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
||>>  1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
||>>  2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
||>>  3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
||>>  4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
||>>  5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
||>>  6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
||>> [EMAIL PROTECTED] >
||>>
||>>
||>> I want the regex to return the rule number for all route
||entries that is
||>> static (S Flag) on Interface "National Gateway".  For added
||security, I'd
||>> like it if the regex will also only return true if the gateway
||address is
||>> part of 165.165.0.0/8 or 165.146.0.0/8
||>>
||>> Basically, I need to use the rule number in another command to
||delete the
||>> route entry... So I presume I'll need to extract it via the regex
||>
||> If it's a fixed width data format, its better (easier for you,
||faster for
||> perl) to break up the string with C:
||>
||> #!/usr/bin/perl
||>
||> use strict;
||> use warnings;
||>
||>
||> while (defined( my $line =  )) {
||> chomp( $line );
||>
||> my %data;
||> $data{rule}  = substr( $line,  0,  2 );
||> $data{flags} = substr( $line,  3,  2 );
||> $data{dest_ip}   = substr( $line,  6, 18 );
||> $data{g} = substr( $line, 25,  1 );
||> $data{gateway}   = substr( $line, 27, 16 );
||> $data{distance}  = substr( $line, 43,  8 );
||> $data{interface} = substr( $line, 52 );
||>
||> # cleanup, stripping spaces
||> $data{$_} =~ s/^\s+|\s+$//g
||> for keys %data;
||>
||> # reformat or reinterpret data
||> $data{flags} = [ split( //, $data{flags} ) ];
||>
||> use Data::Dumper;
||> print Dumper( \%data );
||> }
||>
||>
||>
||> __END__
||>  0  S 0.0.0.0/0  r 198.19.0.2  1SERVER-CORE
||>  1  S 196.0.0.0/8r 165.146.192.1   1National Gateway
||>  2 DC 198.19.1.0/24  r 0.0.0.0 0WIRELESS-CORE
||>  3 Ib 198.19.0.0/24  u 0.0.0.0 200  (unknown)
||>  4 DC 198.19.0.0/24  r 0.0.0.0 0SERVER-CORE
||>  5 DC 192.168.1.0/24 r 0.0.0.0 0INTERNAL-CORE
||>  6 DC 165.146.192.1/32   r 0.0.0.0 0National Gateway
||>
||>
||
||
||--
||To unsubscribe, e-mail: [EMAIL PROTECTED]
||For additional commands, e-mail: [EMAIL PROTECTED]
|| 
||
||
|
|
|*
|Disclaimer:
|
|This message (including any attachments) contains
|confidential information intended for a specific
|individual and purpose, and is protected by law.
|If you are not the intended