Re: Debugging and passing constant value at run time

2015-07-07 Thread Ron Bergin
Using a DEBUG constant and assigning its value via an environment variable are 
both common, but has a drawback and would not be my choice of approach. I 
prefer to use a lexical var (with file scope) and assign it via command line 
option. 

Let's assume you have multiple scripts using the DEBUG constant where some (or 
possibly all) are run from cron jobs. If you set the debug mode based on an 
environment variable, then that could/would affect the running of all of the 
scripts, which you may or may not want. If you set the debug mode based on 
command line option(s), then you could be much more selective not only one 
which script(s) have debug enabled, but also (optionally) the level of 
verbosity. 

#!/usr/bin/perl 

use 5.010; 
use warnings; 
use strict; 
use Getopt::Long; 

my $DEBUG = 0; 
my $VERBOSE = 0; 

GetOptions( 
'D' = \$DEBUG, 
'v=i' = \$VERBOSE 
); 

if( $DEBUG ){ 
say 'hello'; 
say 'goodbye' if $VERBOSE  1; 
} 

Ron 

From: Sharanbasappa Raghapur, ERS, HCLTech shar...@hcl.com 
To: Perl Beginners beginners@perl.org 
Sent: Tuesday, July 7, 2015 4:40:35 AM 
Subject: Debugging and passing constant value at run time 



Hi, 



I am using constant mainly to enable printing of debugging messages (e.g. use 
constant DEBUGGING_L1 = 0;) 

Normally, the value is ‘0’ and when I need to see debug messages, I make this 1 
and run the script. 



Is there a way to allocate value to constants at run time so that I can avoid 
editing the script again and again? 

Also, is there a better way to handle debugging? 



Regards, 

Sharan 




::DISCLAIMER:: 

 

The contents of this e-mail and any attachment(s) are confidential and intended 
for the named recipient(s) only. 
E-mail transmission is not guaranteed to be secure or error-free as information 
could be intercepted, corrupted, 
lost, destroyed, arrive late or incomplete, or may contain viruses in 
transmission. The e mail and its contents 
(with or without referred errors) shall therefore not attach any liability on 
the originator or HCL or its affiliates. 
Views or opinions, if any, presented in this email are solely those of the 
author and may not necessarily reflect the 
views or opinions of HCL or its affiliates. Any form of reproduction, 
dissemination, copying, disclosure, modification, 
distribution and / or publication of this message without the prior written 
consent of authorized representative of 
HCL is strictly prohibited. If you have received this email in error please 
delete it and notify the sender immediately. 
Before opening any email and/or attachments, please check them for viruses and 
other defects. 


 


Re: Debugging and passing constant value at run time

2015-07-07 Thread Ron Bergin
Which means that neither approach is perfect.  I still prefer the variable over 
the constant.

I have never done any benchmark tests to see if there is any significant 
performance difference.  Have you?


Ron

- Original Message -
From: Shawn H Corey shawnhco...@gmail.com
To: beginners@perl.org
Cc: Ron Bergin r...@i.frys.com
Sent: Tuesday, July 7, 2015 7:41:34 AM
Subject: Re: Debugging and passing constant value at run time

On Tue, 7 Jul 2015 07:27:49 -0700 (PDT)
Ron Bergin r...@i.frys.com wrote:

 Using a DEBUG constant and assigning its value via an environment
 variable are both common, but has a drawback and would not be my
 choice of approach. I prefer to use a lexical var (with file scope)
 and assign it via command line option. 

Using a variable has the drawback that the debug code is compiled.
Using a constant sub means the debug code is not compiled.


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Make scalar tainted

2014-12-06 Thread Ron Bergin
Артём Варнайский wrote:
  Hello again!
 Prompt me please elegant and 'vanilla' way to taint some scalar. My vars
 lost their taint when I just split external string with regexp on
 param/val pairs, without checking them for correctness.
 And What do you say about this:
 $foo.=substr($ENV{PATH},0,0); #$foo tainted if $ENV{PATH} is tainted
 Thank, and sorry for my runglish :)



I have not used it myself, but the Taint::Util module looks like it does
just what you want.
http://search.cpan.org/~avar/Taint-Util-0.08/Util.pm

-- 
Ron Bergin



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Need more helpful error messages from Perl

2014-11-19 Thread Ron Bergin
Kevin Walzer wrote:
 Running this code in Perl:

 use LWP::Simple;
 my $url= http://mywebsite.com/foo.ini;;
 my $page = get($url);

 produced this error:

 sh: -c: line 0: unexpected EOF while looking for matching `''
 sh: -c: line 1: syntax error: unexpected end of file

Those error messages are coming from your shell, not perl i.e., your sh
shell is attempting to run the script and not perl.

Do you have a shebang line in the script and is it pointing to perl?

How did you execute the script?


 The error message in question refers to unbalanced quotes, but there
 were no unbalanced quotes in my code.

 This error was driving me crazy until I tried to see what was happening
 using curl. This was more helpful:

 curl http://mywebsite.com/foo.ini  foo.ini

 yielded a 404 error:  the page was missing.

 OK, that explains the unexpected EOF. But why the mismatched quote
 error in Perl? Is there any way to get more helpful error messages, i.e.
 missing page?

 --Kevin


 --
 Kevin Walzer
 Code by Kevin/Mobile Code by Kevin
 http://www.codebykevin.com
 http://www.wtmobilesoftware.com

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/






-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: using string as module

2014-11-08 Thread Ron Bergin
Patton, Billy N wrote:
 I currently have something like this
 use MyFoo::ABCBar;
 use MyFoo::DEFBar;
 use MyFoo::HIJBar;
 my $fooABC = MyFoo::ABCBar-new();
 …

 What I would like to do is

 foreach $pgm ( ‘ABC’ , ‘DEF’ , ‘HIJ’) {
   my $foo = MyFoo::{$pgm}Bar-new;
   …
 }

 This gives me an error.
 What is the correct syntax?

I don't see any valid reason why you'd want to do that, but if that's what
you want, you could accomplish it with the use of eval.

my $foo = eval MyFoo::${pgm}Bar-new;


-- 
Ron Bergin



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: using string as module

2014-11-08 Thread Ron Bergin
Uri Guttman wrote:
 On 11/08/2014 10:40 AM, Ron Bergin wrote:
 you could accomplish it with the use of eval.

 my $foo = eval MyFoo::${pgm}Bar-new;

 ewww. never use string eval for something as simple as that.

 my $foo = MyFoo::${pgm}Bar-new() ;

 that is just fine there. the class in a class method call is just a
 string or a bareword so there is no need for eval.

 uri

You're right.  Using eval is a poor solution for this task.  In fact, I
almost never use or suggest using eval.  It was just the first thing that
popped into my mind.

-- 
Ron Bergin



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Apologetic request for simple one-off script

2014-07-17 Thread Ron Bergin
Shawn H Corey wrote:
 On Thu, 17 Jul 2014 17:36:28 +0300
 Lars Noodén lars.noo...@gmail.com wrote:

 David's example with the autosplit seems much better but if a slice
 were done instead, what would be the more elegant (least inelegant?)
 way of doing it?

 I wouldn't use a slice at all:

 perl -nE'say((split/\s+/)[-1])' file


 --
 Don't stop where the ink does.
   Shawn

You say you wouldn't use a slice but then go ahead and use a slice?

According to the perldata documentation, that is a list slice.  Maybe you
meant to say you wouldn't use an array slice?

---
Ron Bergin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Creating a hash of arrays from DATA

2014-07-10 Thread Ron Bergin
SSC_perl wrote:
   If someone could explain what I'm doing wrong, I'd appreciate it.  I 
 just
 can't see it.

 Thanks,
 Frank

 --

 use strict;
 use warnings;
 use 5.010;

 use Data::Dumper;

 my %entries;

 while (my $line = DATA) {
   chomp $line;
   my($state, $zipcodes) = split (/=/, $line);
   push( @{ $entries{$state} }, split( /,/ = $zipcodes) )
 }

 foreach my $state (sort keys %entries) {
 say The Zip Codes of $state are;
 foreach (@{$entries{$state}}) {
 print Dumper (@{$entries{$state}});
 }
 }


 __DATA__
 AK=995,996,997,998,999


Others have already pointed what you were doing wrong, so I'll point out
something else.

Instead of using 2 separate split statements, I'd use a single split
statement to assign $state and a @zipcodes array.

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

my %entries;

while (my $line = DATA) {
chomp $line;
my($state, @zipcodes) = split /[=,]/, $line;
push @{ $entries{$state} }, \@zipcodes;
}

foreach my $state (sort keys %entries) {
say The Zip Codes of $state are;
say Dumper $entries{$state};
}


__DATA__
AK=995,996,997,998,999
CA=95122,95035,95112

---

Outputs:
The Zip Codes of AK are
$VAR1 = [
  [
'995',
'996',
'997',
'998',
'999'
  ]
];

The Zip Codes of CA are
$VAR1 = [
  [
'95122',
'95035',
'95112'
  ]
];

--
Ron Bergin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Creating a hash of arrays from DATA

2014-07-10 Thread Ron Bergin
Ron Bergin wrote:

 Others have already pointed what you were doing wrong, so I'll point out
 something else.

 Instead of using 2 separate split statements, I'd use a single split
 statement to assign $state and a @zipcodes array.

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

 my %entries;

 while (my $line = DATA) {
 chomp $line;
 my($state, @zipcodes) = split /[=,]/, $line;
 push @{ $entries{$state} }, \@zipcodes;

I kept your original hash data structure, but in this case I think we
should simplify it a bit.

$entries{$state} = \@zipcodes;

 }

 foreach my $state (sort keys %entries) {
 say The Zip Codes of $state are;
 say Dumper $entries{$state};
 }


 __DATA__
 AK=995,996,997,998,999
 CA=95122,95035,95112

 ---

 Outputs:
 The Zip Codes of AK are
 $VAR1 = [
   [
 '995',
 '996',
 '997',
 '998',
 '999'
   ]
 ];

 The Zip Codes of CA are
 $VAR1 = [
   [
 '95122',
 '95035',
 '95112'
   ]
 ];

 --
 Ron Bergin




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: script to match a valid email id

2014-07-10 Thread Ron Bergin
Sunita Pradhan wrote:
 I want to write a script which will verify a valid email address .
 Could anybody give some ideas , how to write a pattern for this ?

 -Sunita


Take a look at the Email::Valid module.
http://search.cpan.org/~rjbs/Email-Valid-1.194/lib/Email/Valid.pm


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: script to match a valid email id

2014-07-10 Thread Ron Bergin
Sunita Pradhan wrote:
 I do not want to use Cpan modules .

 -Sunita


What do you have against using a cpan module?

If you don't want to use the module, then why not simply copy/use the
regex that it uses to do the validation?

$RFC822PAT = 'EOF';
[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\
xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xf
f\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)@,;:.\\\[\]\000-\037\x80-\x
ff]+(?![^(\040)@,;:.\\\[\]\000-\037\x80-\xff])|[^\\\x80-\xff\n\015
]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015]*)*)[\040\t]*(?:\([^\\\x80-\
xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80
-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*
)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\
\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\
x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\x8
0-\xff]+(?![^(\040)@,;:.\\\[\]\000-\037\x80-\xff])|[^\\\x80-\xff\n
\015]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015]*)*)[\040\t]*(?:\([^\\\x
80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^
\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040
\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([
^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\
\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\
x80-\xff]+(?![^(\040)@,;:.\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-
\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()
]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\
x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\04
0\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\
n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\
015()]*)*\)[\040\t]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\x80-\xff]+(?!
[^(\040)@,;:.\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\
]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\
x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\01
5()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*|(?:[^(\040)@,;:.
\\\[\]\000-\037\x80-\xff]+(?![^(\040)@,;:.\\\[\]\000-\037\x80-\xff]
)|[^\\\x80-\xff\n\015]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015]*)*)[^
()@,;:.\\\[\]\x80-\xff\000-\010\012-\037]*(?:(?:\([^\\\x80-\xff\n\0
15()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][
^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)|[^\\\x80-\xff\
n\015]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015]*)*)[^()@,;:.\\\[\]\
x80-\xff\000-\010\012-\037]*)*[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?
:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-
\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:@[\040\t]*
(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015
()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()
]*)*\)[\040\t]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\x80-\xff]+(?![^(\0
40)@,;:.\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\
[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\
xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*
)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80
-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x
80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t
]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\x80-\xff]+(?![^(\040)@,;:.\\
\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])
*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x
80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80
-\xff\n\015()]*)*\)[\040\t]*)*)*(?:,[\040\t]*(?:\([^\\\x80-\xff\n\015(
)]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\
\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*@[\040\t
]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\0
15()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015
()]*)*\)[\040\t]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\x80-\xff]+(?![^(
\040)@,;:.\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|
\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80
-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()
]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x
80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^
\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040
\t]*)*(?:[^(\040)@,;:.\\\[\]\000-\037\x80-\xff]+(?![^(\040)@,;:.
\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff
])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\
\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x
80-\xff\n\015()]*)*\)[\040\t]*)*)*)*:[\040\t]*(?:\([^\\\x80-\xff\n\015

Re: Need to Grep only fail count from the Pattern.

2014-06-24 Thread Ron Bergin
Uday Vernekar wrote:
 Dear All,

 Slight Correction Made in Above Code.
 I am grepping this Pattern depending on run count which will Always same
 Pass count and Fail count will Vary.
 |  72| Traffic Test  |1|  561|

 [Code]
 #!/usr/bin/perl

 use 5.10.0;
 use strict;
 use warnings;

 my $var=`grep -nr |  72| Traffic Test  |1|  561|
 /tmp/EO-PCPE-23-10GT`;
 print $var;
 my $failed = (split /\|/, $var)[6];

 print failed=$failed\n;

 $failed =~ s/^\s+//;

 print failed=$failed\n;


 if ($failed) {
 say 'Failed';
 }
 else {
 say 'Sucsess';
 }

 [code]




 output: for Fail condition

 43629: |  72| Traffic Test  |1|  561|  560|1|
 (none)
 failed=1
 failed=1
 Failed


 output:for pass condition

 43629: |  72| Traffic Test  |1|  561|  561|0|
 (none)
 failed=0
 failed=0
 Sucsess


 Please suggest..

 with Regards
 Uday V G

Why shell out to the grep command when Perl is perfectly capable of doing
the same?

Here's an example that uses split and tests the relevant fields.  This
could also be accomplished with a regex, but I think the split approach is
cleaner.

[code]
#!/usr/bin/perl

use 5.10.0;
use strict;
use warnings;

# throw away the first 3 lines
DATA for 1..3;

while (my $line = DATA) {
my ($test, $run, $failed) = (split /\|/, $line)[1,4,6];
next unless ($test == 72 and $run == 561);

print Line $.:$line;
$failed =~ s/^\s+//;
say failed=$failed;
say $failed ? 'Failed' : 'Success';
}



__DATA__
U/A/S|Test|Test   |Loop  | Run |Pass |Fail| 
Arguments
 |  Name |Count|Count|Count|Count |
-++---+-+-+-+-+--+---
 |  72| Traffic Test |  1|  11| 11|  
0| (none)
 |  72| Traffic Test |  1|  561| 11|  
1| (none)
[/code]

If you need to process multiple files in a directory tree as the -r option
in your grep command implies, then make use of the File::Find module.

http://search.cpan.org/~rjbs/perl-5.20.0/ext/File-Find/lib/File/Find.pm


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Need to Grep only fail count from the Pattern.

2014-06-23 Thread Ron Bergin
Uday Vernekar wrote:
 Hi All,


 I have following Pattern from which I need to grep only the Fail count and
 store that in a variable.

 U/A/S|Test|Test   |Loop  | Run |Pass |Fail|
 Arguments
  |  Name |Count|Count|Count|Count |
 -++---+-+-+-+-+--+---
  |  72| Traffic Test |  1|  11| 11|
 0| (none)

 based on fail count value need to print

 if 0--Sucess
 if 0--Fail


 with Regards
 Uday V G

 --

This is how I'd do it.

#!/usr/bin/perl

use 5.10.0;
use strict;
use warnings;

# throw away the first 3 lines
DATA for 1..3;

# grab the wanted row of data
my $data = DATA;

# extract the failed field i.e., 6th field
my $failed = (split /\|/, $data)[5];

# strip leading spaces
$failed =~ s/^\s+//;


if ($failed) {
say 'Failed';
}
else {
say 'Sucsess';
}


__DATA__
U/A/S|Test|Test   |Loop  | Run |Pass |Fail| 
Arguments
 |  Name |Count|Count|Count|Count |
-++---+-+-+-+-+--+---
 |  72| Traffic Test |  1|  11| 11|  
0| (none)



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: check list if values meet criteria

2014-02-25 Thread Ron Bergin
Bill McCormick wrote:
 On 2/25/2014 4:30 PM, Bill McCormick wrote:
 What would be the perl'ish way using map or some other sugar to check if
 a list of values meet some criteria? Instead of doing something like

 my @issues = qq(123,456,a45);
 my $max = 999;

 for (@issues) {
die if $_  0 or $_  $max;
 }

 Revision:

 for(@issues) {
print issue=[$_]\n;
die $_ not a number\n if $_ ne $_+0;
die $_ not in range\n if $_  0 || $_  $max;
 }



 ---

Are you sure you want to die the first time an issue doesn't fall within
the requirements?


use Number::Range;
use Scalar::Util qw(looks_like_number);

my @issues = (123,456,'a45');
my $range = Number::Range-new(0..999);

for my $value (@issues) {
print issue=[$value]\n;
unless (looks_like_number($value) and $range-inrange($value)) {
warn Issue '$value' is either not a number or is out out of
range\n;
}
}

---
Ron


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: mv Is Not Working the Same Way Under System as Under a Shell.

2014-01-30 Thread Ron Bergin
Martin G. McCormick wrote:
   I have a perl script that I run as root which needs to
 move a file from where it is to another directory.

   I keep getting the Usage  help message and a
 permission denied. If I su to root and manually make the move,
 it works.

   The perl script is not trying to run suid to root. I am
 root when I call it. The line in question reads:

 system(
 mv $directories$filename \$directories\deleted_keys/
 );

 $directories and $filename are correctly set at the time. The
 output from the script is:

 usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
 /var/named/etc/namedb/dynamic/okstate.edu/deleted_keys/: Permission denied


As has already been mentioned, part of the problem is your quoting.

What is the value of $directories and more specifically, does it end with
a forward slash?  Personally, I prefer to leave off the trailing dir
separator because IMO it makes it more clear later when the $filename is
added.

Why are you using a system call instead of the more portable move() of
mv() function from File::Copy, which is a core module?

use File::Copy qw(cp mv);

...
...

mv($directories/$filename, $directories/deleted_keys)
  or warn qq(Failed to move $directories/$filename to
$directories/deleted_keys $!);


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: module versions

2013-05-15 Thread Ron Bergin
shawn wilson wrote:
 I asked this in #perl-help and was told that by the time perl checked
 the version, the module was already loaded - is there a way to check
 the version without completely loading the module so that when one
 failed, I could move on to another module of the same name whose
 version might succeed?


Why not specify the minimum version number that your script requires in
the use statement?  If that version is not available, then what's the
point of going forward?

If you don't want to do that, then you could use Module::Load::Conditional
to test if the desired version is loadable.

http://search.cpan.org/~bingos/Module-Load-Conditional-0.54/lib/Module/Load/Conditional.pm

-- 
Ron Bergin




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Can't close filehandle

2013-05-01 Thread Ron Bergin
Manfred Lotz wrote:
 Hi there,
 I have a script where I log stuff to a file and the same time displays
 it to stdout using Log4perl.

 Here is a minimal example where I log a command which fails.

 snip-
 #! /usr/bin/perl

 use strict;
 use warnings;

 #use autodie;
 use Log::Log4perl qw(:easy);

 Log::Log4perl-easy_init(
   { level = $DEBUG, file =  test.log, },
   { level = $DEBUG, file = 'STDOUT', }
 );

 my $cmd = 'uname';
 my $parms = '-f'; # invalid parm

 INFO( Issuing [$cmd $parms] );
 open my $fh, '-|', $cmd $parms 21 or die open: $!;
 INFO( $_ ) while $fh;
 close $fh;

 snap-

 This works great. Output is like this:
 2013/05/01 16:16:40 Issuing [uname -f]
 2013/05/01 16:16:40 uname: invalid option -- 'f'
 2013/05/01 16:16:40 Try 'uname --help' for more information.


 However, if I add autodie then I get:

 2013/05/01 16:16:33 Issuing [uname -f]
 2013/05/01 16:16:33 uname: invalid option -- 'f'
 2013/05/01 16:16:33 Try 'uname --help' for more information.
 Can't close(GLOB(0x2554c80)) filehandle: '' at ./test02.pl line 20


 close does not fail if the command is ok, e.g. 'uname -a'. Can anybody
 explain to me why close fails in the example above?



 --
 Thanks,
 Manfred

If you test the return code of the close call, you'll see that it fails in
both cases.

I'm not sure why it's failing, but personally I'd use IPC::Open3 instead
of opening the pipe as you are currently doing.  That way, you could
capture the stdout and stderr separately and log the stderr as WARN or
ERROR.

Ron Bergin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: destroy widget

2012-09-05 Thread Ron Bergin
Irfan Sayed wrote:
 please find the attached .
 what i am looking for is, need to destroy the window $mw1 once the text
 entered in scrolled text window
 i just want to destroy $mw1 and not entire application


 please suggest .


 regards,
 irfan



 
  From: Shlomi Fish shlo...@shlomifish.org
 To: Perl Beginners beginners@perl.org
 Sent: Tuesday, September 4, 2012 6:07 PM
 Subject: Re: destroy widget

 Hi Irfan,

 On Tue, 4 Sep 2012 05:01:11 -0700 (PDT)
 Irfan Sayed irfan_sayed2...@yahoo.com wrote:

 hi,

 i have following code to get the user input :

 $mw1 = MainWindow-new;
    $mw1-geometry( 200x100 );
    $mw1-title(Client Workspace);
    $mw1-Label(
            -text = Enter the Perforce client name:
        )-pack(-anchor='center');
       



You're looking for the -withdraw()method.

# Hide main window
$mw1-withdraw();

...
...

# Sometime later in the app show main window again
$mw1-deiconify();
$mw1-raise();



Ron Bergin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Win32::Watir on strawberry Perl

2012-09-04 Thread Ron Bergin
Gary Stainburn wrote:

 I still have a problem, and it seems to be the install of Watir that
 didn't
 work. Below is the session. Does anyone know what I need to do to get this
 sorted?

 C:\Documents and Settings\user1\My Documentsperl watir_test.pl
 [3408]: DEBUG: _find_autoitx_dll:
 C:/strawberry/perl/site/lib/Win32/Watir/AutoIt
 X3.dll
 Undefined subroutine Win32::MSgBox called at
 C:/strawberry/perl/site/lib/Win32/
 Watir.pm line 1370.


There is a typo in that line of the module.

my $_ret = Win32::MSgBox($message,$mode,$title)

That line (1370) should be:
my $_ret = Win32::MsgBox($message,$mode,$title)

 --


Ron Bergin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to set session variable (not session cookie) using perl CGI

2012-08-07 Thread Ron Bergin

-- 
Rajeev Prasad wrote:
 I am using CGI.pm on my website, but I generate my pages using TT
 (template Toolkit).
  
 I have few questions:
  
 0. how to have a session variable (not a session cookie)? If I do not want
 to use cookie, do i have to store session data in a temp file on server
 and check it with each page load?
  
  
 1.  How do I pass a cookie to the page I am displaying using tt ? is
 following ok?
  
 print Content-type: text/html\n\n;
 print $q-header(-cookie=$mycookie);
 ...further code to generate page using tt
  
 2. another related issue is: How do I send a redirect URL to the browser
 client, based on some conditions in the logic?
  
 ty.
 Rajeev

 --

http://search.cpan.org/~markstos/CGI-Session-4.48/lib/CGI/Session.pm

---
Ron Bergin



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: one liner for removing string from an element of string array

2012-07-13 Thread Ron Bergin
Nemana, Satya wrote:
 Hi

 I have written a small program like this to just print file2 from the
 second element of the array by removing the .template from the entry (the
 name file2 can change and can be longer or shorter)

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

 my @templates = (
 /a/b/c/d/e/f/file1.template,
 /a/b/c/d/e/f/file2.template
 );

 my @tokens=split( /\//, $templates[1]);
 print(\n.substr($tokens[$#tokens],0,-9));

 However I want this to be more efficient and want to do this in a single
 line as I have to do this several times.
 How can I do that?

 TIA,

 Regards,
 Satya

I assume you're working with file paths and you want to extract the
filename without the ext.

You can use a regex, but I'd probably prefer to use the File::Basename
module.
http://search.cpan.org/~rjbs/perl-5.16.0/lib/File/Basename.pm

#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;
use Data::Dumper;

my @templates = (
/a/b/c/d/e/f/file1.template,
/a/b/c/d/e/f/file2.template
);

my ($name,$path,$suffix) = fileparse($templates[1], '.template');
print Dumper ($name,$path,$suffix);

outputs:
$VAR1 = 'file2';
$VAR2 = '/a/b/c/d/e/f/';
$VAR3 = '.template';

-- 
Ron Bergin



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to do a reference to a func in Math::Trig

2012-06-23 Thread Ron Bergin
Charles Smith wrote:

[snip]

 But this pgm fails:

 #!/usr/bin/env perl
 use Math::Trig;
 my $a = \Math::Trig::cos;
 $a(0);

 Undefined subroutine Math::Trig::cos called at modfunctor line 7.


The cos sub is defined in Math::Complex, which Math::Trig loads.

Try this:

use strict;
use Math::Trig;

my $cos = \Math::Complex::cos;
print $cos-(0);



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to get a sequence of 01 02 ..

2012-06-11 Thread Ron Bergin
lina wrote:
 Hi,


 $  for i in `seq -f '%02g' 1 10` ; do echo $i ; done
 01
 02
 03
 04
 05
 06
 07
 08
 09
 10

 I wonder how can I get something like above in the perl.

perl -e for (1..10){printf(qq(%02d\n), $_)}

Ron


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I extract the lines after A

2012-03-12 Thread Ron Bergin
lina wrote:
 On Sun, Mar 11, 2012 at 11:15 PM, Ron Bergin r...@i.frys.com wrote:
 lina wrote:
 On Sun, Mar 11, 2012 at 10:45 PM, lina lina.lastn...@gmail.com wrote:

 What I have come up so far :

 #!/usr/bin/env perl

 use strict;
 use warnings;

 my $filename = try.txt;

 open my $fh, '', $filename or die Couldn't read $filename;

 You should include the reason it failed in the die statement.

 open my $fh, '', $filename or die Couldn't read $filename $!;



 while (my $line = $fh){
       if ($line =~ /^A$/){

 Use the range operator to delimit the section you want to extract.
 You can read about in 'perldoc perlop'

 if ($line =~ /^A$/ .. $line =~ /^C$/) {

               ## Here I don't know how to proceed further
               print $line;

 You'll want to skip over the 'A' and 'C' lines before printing the line.
 I'll leave that to you.
 Thank you Ron, I never known how amazing $line =~ /A$/ .. $line =~ /C$/
 can do.
 I don't know how to skip the 'A' and 'C' lines, the only way I could
 think of using grep -v in the output file.
 check the next, but not so sure how to do this,

 #!/usr/bin/env perl

 use strict;
 use warnings;

 my $filename = $ARGV[0];
 my $outfile = $ARGV[1];

 open my $fh, '', $filename or die Couldn't open '$filename' for reading:
 $!;

 open my $OUT, '', $outfile or die Couldn't open '$outfile' for writing:
 $!;


 while (my $line = $fh){

   if ($line =~ /C$/ .. $line =~ /Si$/){

   print $OUT $line;
   }
   #if ($line =~ /^C/..$line =~ /^A$/){
   #   print $line;
   #}
 }


 $ perl calculate_COM.pl com.txt A.txt

 $ more com.txt
 Si
 5 3 1 0 0 0 0 1 0 0 0 0 0
 5 5 1 0 0 0 0 5 0 0 0 0 0
 3 6 1 0 0 0 0 6 0 0 0 0 0
 C
 8 3 1 0 0 0 0 1 0 0 0 0 0
 3 5 1 0 0 0 0 4 0 0 0 0 0
 1 6 1 0 0 0 0 6 0 0 0 0 0
 C
 1 3 1 0 0 0 0 2 0 0 0 0 0
 5 5 1 0 0 0 0 5 0 0 0 0 0
 3 6 1 0 0 0 0 6 0 0 0 0 0
 Si
 1 3 1 0 0 0 0 1 0 0 0 0 0
 2 5 1 0 0 0 0 5 0 0 0 0 0
 3 6 1 0 0 0 0 6 0 0 0 0 0

 I changed the examples to make is simple and readable.

 Thanks with best regards,


       }
 }

 Thanks

 --
 --

Which section(s) in that last example do you want to extract?

while (my $line = $fh) {
if ($line =~ /^C$/ .. $line =~ /^Si$/) {
print {$OUT} $line unless $line =~ /^(C|Si)$/;
}
}

or flip it to get the other 2 sections

while (my $line = $fh) {
if ($line =~ /^Si$/ .. $line =~ /^C$/) {
print {$OUT} $line unless $line =~ /^(C|Si)$/;
}
}


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I extract the lines after A

2012-03-11 Thread Ron Bergin
lina wrote:
 On Sun, Mar 11, 2012 at 10:45 PM, lina lina.lastn...@gmail.com wrote:
 A
 7.803481E-01   8.228973E-01   7.515242E-01    2      1833
 -5.50     308.3889771284     5   0   7     1.7084151661
 1.6790503987       2.75458
 53558
  7.866901E-01   8.410519E-01   9.981456E-01    2     14485
 -5.50     269.6201271260    39   4   7    -2.5561279716
 -3.5975355928       1.5117
 155069
 C
  7.735338E-01   9.981671E-01   7.735798E-01    2     11514
 -5.50     289.1918534266    31   1   7    -5.6311359613
 -0.0502358314       0.0768
 146957
  5.907322E-02   6.045568E-02   3.388628E-02    1        28
 -6.50     336.0228260493     1   2   7     0.8177802191
 3.9634621584      -3.0314
 370501
 A
 2.764127E-02   3.230161E-02   1.633790E-02    1        51
 -6.50     319.7604886848     1   3   7     0.7583797888
 3.5176580829      -1.87872
 93439
  5.960780E-02   2.111333E-02   1.066835E-01    1        62
 -6.50     297.7363059936     1   1   7     2.2257828331
 3.7887567121      -3.4478
 600377


 I am so troubled with extract the lines after A but not the lines
 under C out, so the final result is

 7.803481E-01   8.228973E-01   7.515242E-01    2      1833
 -5.50     308.3889771284     5   0   7     1.7084151661
 1.6790503987       2.75458
 53558
  7.866901E-01   8.410519E-01   9.981456E-01    2     14485
 -5.50     269.6201271260    39   4   7    -2.5561279716
 -3.5975355928       1.5117
 1550692.764127E-02   3.230161E-02   1.633790E-02    1        51
 -6.50     319.7604886848     1   3   7     0.7583797888
 3.5176580829      -1.87872
 93439
  5.960780E-02   2.111333E-02   1.066835E-01    1        62
 -6.50     297.7363059936     1   1   7     2.2257828331
 3.7887567121      -3.4478
 600377


 Thanks for you suggestions,

 What I have come up so far :

 #!/usr/bin/env perl

 use strict;
 use warnings;

 my $filename = try.txt;

 open my $fh, '', $filename or die Couldn't read $filename;

You should include the reason it failed in the die statement.

open my $fh, '', $filename or die Couldn't read $filename $!;



 while (my $line = $fh){
   if ($line =~ /^A$/){

Use the range operator to delimit the section you want to extract.
You can read about in 'perldoc perlop'

if ($line =~ /^A$/ .. $line =~ /^C$/) {

   ## Here I don't know how to proceed further
   print $line;

You'll want to skip over the 'A' and 'C' lines before printing the line.
I'll leave that to you.

   }
 }

 Thanks

 --


Ron Bergin


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: rmdir

2011-06-27 Thread Ron Bergin
Irfan Sayed wrote:
 even i tried windows del command
 but it prompts for confirmation to delete the files
 do u know how to suppress these prompts ? i did not find any switch which
 allows you to suppress

 pls suggest.

 regards
 irfan


You need to use the /s and /q and /f options.

  /FForce deleting of read-only files.
  /SDelete specified files from all subdirectories.
  /QQuiet mode, do not ask if ok to delete on global wildcard

-- 
Ron Bergin



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: rmdir

2011-06-27 Thread Ron Bergin
Irfan Sayed wrote:
 i need that command which will delete all files and directoreis
 recursivley along with root dir and read only files

 i did in this way

 C:\del /F /S /Q c:\test

 but c:\ still has test folder and subfolder
 using above command only files are getting deleted and not empty folders

 plz suggest




 
 From: Ron Bergin r...@i.frys.com
 To: Irfan Sayed irfan_sayed2...@yahoo.com
 Cc: Shlomi Fish shlo...@shlomifish.org; pa...@laposte.net
 pa...@laposte.net; Perl Beginners beginners@perl.org
 Sent: Monday, June 27, 2011 8:39 PM
 Subject: Re: rmdir

 Irfan Sayed wrote:
 even i tried windows del command
 but it prompts for confirmation to delete the files
 do u know how to suppress these prompts ? i did not find any switch
 which
 allows you to suppress

 pls suggest.

 regards
 irfan


 You need to use the /s and /q and /f options.

   /F            Force deleting of read-only files.
   /S            Delete specified files from all subdirectories.
   /Q            Quiet mode, do not ask if ok to delete on global wildcard

 --

Since rmdir doesn't have  the /F switch, simply use 2 commands.  The first
one uses del /s /f /q to delete the files and the second uses rmdir /s
/q to delete the directories.

--
Ron Bergin
aka Fishmonger


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to trap print() errors?

2011-01-16 Thread Ron Bergin
On Jan 16, 3:52 pm, dpchr...@holgerdanske.com (David Christensen)
wrote:
 beginners:

 After RTFM, STFW, etc., I realized that print() was issuing a warning
 and continuing.

 I came up with two solutions:

 1.  perldoc -f print() states Returns true if successful.  So:

         print $s @_ or die $!;

 The downside is that the warning still gets printed:

         print() on unopened filehandle NOSUCH at trap-print-errors2.pl line 
 12.

 And $! isn't very meaningful:

         trapped error Bad file descriptor at trap-print-errors2.pl line 12.

 2.  The warnings pragmatic module has an option for turning warnings
 into errors:

         use warnings FATAL = 'all';
         print $s @_;

 This eliminates the warning message and gives me a meaningful $@:

         trapped error print() on unopened filehandle NOSUCH at
 trap-print-errors2.pl line 24.

 Much better!  :-)

 HTH,

 David

 2011-01-16 15:47:28 dpchrist@p43400e ~/sandbox
 $ cat trap-print-errors2.pl
 #!/usr/bin/perl
 use strict;
 use warnings;
 $| = 1;

 sub myprint($@)
 {
      my $s = shift;
      eval {
         ###  circumvent Can't use string (*STDOUT) as a symbol ref...
         no strict 'refs';
         print $s @_ or die $!;
      };
      print trapped error $@ if $@;

 }

 sub myprint2($@)
 {
      my $s = shift;
      eval {
         ###  circumvent Can't use string (*STDOUT) as a symbol ref...
         no strict 'refs';
         use warnings FATAL = 'all';
         print $s @_;
      };
      print trapped error $@ if $@;

 }

 myprint  '*STDOUT', hello, world!\n;
 myprint2 '*STDOUT', hello, world!\n;
 myprint  '*NOSUCH', goodbye, cruel world!;
 myprint2 '*NOSUCH', goodbye, cruel world!;
 print all done\n;

 2011-01-16 15:48:02 dpchrist@p43400e ~/sandbox
 $ perl -c trap-print-errors2.pl
 trap-print-errors2.pl syntax OK

 2011-01-16 15:48:09 dpchrist@p43400e ~/sandbox
 $ perl trap-print-errors2.pl
 hello, world!
 hello, world!
 print() on unopened filehandle NOSUCH at trap-print-errors2.pl line 12.
 trapped error Bad file descriptor at trap-print-errors2.pl line 12.
 trapped error print() on unopened filehandle NOSUCH at
 trap-print-errors2.pl line 24.
 all done

It's interesting that you found the warning message to be meaningless,
but the exact same message was helpful when you told the pragma to
raise the level of warnings to be fatal.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to trap print() errors?

2011-01-16 Thread Ron Bergin
Ron Bergin wrote:
         print $s @_ or die $!;

 The downside is that the warning still gets printed:

         print() on unopened filehandle NOSUCH at trap-print-errors2.pl
 line 12.

 And $! isn't very meaningful:

         trapped error Bad file descriptor at trap-print-errors2.pl line
 12.

 2.  The warnings pragmatic module has an option for turning warnings
 into errors:

         use warnings FATAL = 'all';
         print $s @_;

 This eliminates the warning message and gives me a meaningful $@:

         trapped error print() on unopened filehandle NOSUCH at
 trap-print-errors2.pl line 24.


 It's interesting that you found the warning message to be meaningless,
 but the exact same message was helpful when you told the pragma to
 raise the level of warnings to be fatal.


I should have said nearly the same message.  Both messages told you where
the problem was located and with that info it should have been easy to
find/fix the problem.  In my mind that's not meaningless.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: install a package on windows

2010-12-15 Thread Ron Bergin
Jeff Peng wrote:
 Hi,

 I have intalled activeperl 5.10 on windows and try to install a perl
 package.
 But I can't find the package in activeperl's perl package manager
 though this package does exist in CPAN.
 Also my windows doesn't have gcc/gmake installed.
 So how to install this kind of package? Thanks.

 Regards.


Start by adding additional repositories
http://win32.perl.org/wiki/index.php?title=PPM_Repositories#Perl_5.10

You could also install the MinGW module which is in ActiveStates
repository and which provides the needed compiler so you can build/install
modules using cpan.

Ron


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: error opening file with open function

2010-11-07 Thread Ron Bergin
Cross thread posted at
http://forums.devshed.com/perl-programming-6/error-opening-csv-file-with-open-function-761095.html

J M wrote:
 I was able to figure it out. Here is the update (probably not final) code
 for anyone interested:


 [code]
 #! /usr/bin/perl
 #
 use DBI;
 use DBD::mysql;
 use Text::CSV;
 use strict;
 #configure variables
 my $host = localhost;
 my $db = global_stats;
 my $table = station_information;
 my $user = globalstats;
 my $password = algoreliesLOL;
 #connect to the database
 my $dbc = dbi:mysql:$db:$host;
 my $dbh;
 if($dbh = DBI-connect($dbc, $user, $password) or die Can't connect to
 the
 database: $DBI::errstr\n) {
 print Connected to the database!;
 }
 #setup parser
 my $csv = Text::CSV-new();
 print What is the name of the file? (ENTER for default) :  ;
 chomp(my $file = STDIN);
 if($file -eq \n) {
 $file = '/home/jmd9qs/global_stats/ish-history.csv';
 }
 open CSV, , $file or die Can't open the file \$file\: $!;
 while(CSV) {
 next if ($. == 1);
 if ($csv-parse($_)) {
 my @columns = $csv-fields();
 my $myquery = $dbh-do(insert into station_information

 (station_number,WBAN_number,station_name,country,fips,state,ICAO_callsign,lattitude,longitude,elevation)
 values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?), {}, $columns[0],
 $columns[1], $columns[2], $columns[3], $columns[4],
 $columns[5],
 $columns[6], $columns[7], $columns[8], $columns[9]);
 } else {
 my $err = $csv-error_input;
 print Failed to parse line: $err;
 }
 }
 close CSV;
 $dbh-disconnect();
 [\code]

 Thanks again for the help.

 jmd9qs


D:\perlperl -c jmd9qs.pl
syntax error at jmd9qs.pl line 24, near -eq
jmd9qs.pl had compilation errors.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Elements to Avoid Document on http://perl-begin.org/

2010-10-11 Thread Ron Bergin
On Oct 10, 12:59 am, shlo...@iglu.org.il (Shlomi Fish) wrote:
 On Sunday 10 October 2010 03:09:21 Ron Bergin wrote:



  On Oct 7, 3:07 pm, shlo...@iglu.org.il (Shlomi Fish) wrote:
   Hi all,

   after being tired of telling Perl newcomers about the same problems with
   their code times and times again, I've decided to create this page
   detailing Perl Elements to avoid:

  http://perl-begin.org/tutorials/bad-elements/

  [quote]
  C-style for loops

  Some beginners to Perl tend to use C-style-for-loops to loop over an
  array's elements:
  [/quote]

  Have you considered including an example were it would be appropriate
  to use the C-style for loop, such as when the iterator needs to change
  by some value other than 1?

 Well, in this case, PBP recommends to use a while/continue loop:

This is one area where I disagree with PBP, at least in most cases.

The  while/continue loop is more verbose and to the beginner more
difficult to understand.


 But it's a good idea to show both versions. Thanks!

I would agree that showing both versions would be best.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Elements to Avoid Document on http://perl-begin.org/

2010-10-09 Thread Ron Bergin
On Oct 7, 3:07 pm, shlo...@iglu.org.il (Shlomi Fish) wrote:
 Hi all,

 after being tired of telling Perl newcomers about the same problems with their
 code times and times again, I've decided to create this page detailing Perl
 Elements to avoid:

 http://perl-begin.org/tutorials/bad-elements/

[quote]
C-style for loops

Some beginners to Perl tend to use C-style-for-loops to loop over an
array's elements:
[/quote]

Have you considered including an example were it would be appropriate
to use the C-style for loop, such as when the iterator needs to change
by some value other than 1?


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Opposite benchmark results between Linux and Windows

2010-08-10 Thread Ron Bergin
While doing some benchmark testing on both Windows and Linux, the
results of the exact same code was reversed.  A slight difference in
the percentages is understandable, but I fail to see why the results
would be reversed.  Could someone shed some light on this issue?

First the benchmark results:

C:\TEMPtimestamp.pl
 Rate Matt  Ron
Matt 162840/s   -- -37%
Ron  257003/s  58%   --


[r...@099vicidial101 ~]# ./timestamp.pl
 Rate  Ron Matt
Ron  110132/s   -- -29%
Matt 155763/s  41%   --


The code:

#!/usr/bin/perl

use strict;
use warnings;
use POSIX qw(strftime);
use Benchmark qw(:all);

my $count = 1_000_000;

cmpthese($count, {
Matt = \matt,
Ron  = \ron,
});


sub matt {
my $now_date_epoch = time();
my $BDtarget = ($now_date_epoch - 5);
my ($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst)
= localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon  10) {$Bmon = 0$Bmon;}
if ($Bmday  10) {$Bmday = 0$Bmday;}
if ($Bhour  10) {$Bhour = 0$Bhour;}
if ($Bmin  10) {$Bmin = 0$Bmin;}
if ($Bsec  10) {$Bsec = 0$Bsec;}
my $BDtsSQLdate = $Byear$Bmon$Bmday$Bhour$Bmin$Bsec;
}

sub ron {
my $BDtsSQLdate = strftime(%Y%m%d%H%M%S, localtime(time() -
5) );
}


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Data migration

2010-07-27 Thread Ron Bergin
On Jul 26, 5:58 pm, ca...@cajuninc.com (M.Lewis) wrote:
 I'm migrating an old RedHat server to a new Debian server. In migrating
 the data there's a problem in that on the RH server the UID starts at
 500, on the Debian server the UID starts at 1000. Resulting in something
 like this:

 Old     User    New
 UID     Name    UID

 500     Moe     1000
 501     Larry   1001
 502     Curley  1002
 503     Shemp   1003

 I've tossed this around in my head and haven't really arrived at a good
 method to correct the UID's on the new server. I presume there will be a
 similar problem with GID's as well, although I've not yet confirmed that.

 I'm hopeful that someone will give me an idea that will give me a
 kick-start so to speak.

 Thanks,
 Mike

If you don't want to use the original UID's, then the first thing that
I can think of is to:

1) use useradd to create the new account

2) scp or rsync the original home directory to the new server

3) chown the user's files to reset the user/group id's


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Nested if and elsif and else

2010-04-15 Thread Ron Bergin
On Apr 15, 9:21 am, rea...@newsguy.com (Harry Putnam) wrote:
 r...@i.frys.com writes:
  Here's an example I gave in a similar question in another
  forum.

 Thanks...

 I'm sorry to ask more but if someone asked to be shown an
 if/elsif/else construct being replaced by a dispatch table, I don't
 really see how that answered there question.  It didn't for me.

 Where is the comparable if/elsif/else construct that is being replaced
 by the dispatch table?

 Visualizing how it would go is a little beyond my grasp I guess.

Sorry for not posting the if/elsif/else block, but to me that part
appeared to be obvious, but I guess it wasn't.

I see that Jim has posted the if/elsif/else part, so I won't duplicate
it.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Strawberry Perl capabilities?

2010-03-06 Thread Ron Bergin
On Mar 5, 4:39 pm, dpchr...@holgerdanske.com (David Christensen)
wrote:
 Shlomi Fish wrote:
  Actually, Strawberry Perl is preferable over AS Perl:
 http://strawberryperl.com/

Shlomi,

If using AS, then simply install MinGW which gives you the missing
compiler and proper cpan setup.  After that, AFAIK you'll have the
same functionality as Strawberry.

http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite

Likewise, if using Strawberry, you can install the PPM module.
Although, I don't know if it provides the GUI interface; it may only
use the command line.

I've not used Strawberry, but given the above info, why is Strawberry
preferred?


  From memory, AS makes (commercial) Perl tools for creating stand-alone
 Windows executables and single-file Windows Installer packages.  I also
 recall a Perl .NET toolchain.  Does Strawberry Perl have any of these
 capabilities?  Must Strawberry Perl be installed first on end-users'
 machines?

You can install PAR::Packer and use the pp utility to package
standalone executables.  However, that may not be as good as the
commercial AS tools.


 It's my understanding that Strawberry Perl provides a C compiler and a
 working CPAN environment.  This is well and good for pure Perl
 applications, but I also write Perl software that drives GNU
 command-line tools (ssh, tar, gzip, rsync, etc.) and/or is driven by
 other GNU tools and/or Apache.  I have found Win32 binaries for some of
 the pieces, but only Cygwin seems to have everything I need.  How does a
 Strawberry Perl developer deal with these cases?

I've never found the need to use cygwin.  If cpan doesn't have the
required module, or if you really need the *nix tool, then install the
Windows port of the *nix GNU tools.

http://gnuwin32.sourceforge.net/


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Strawberry Perl capabilities?

2010-03-06 Thread Ron Bergin
On Mar 6, 10:38 am, r...@i.frys.com (Ron Bergin) wrote:
 If using AS, then simply install MinGW which gives you the missing
 compiler and proper cpan setup.  After that, AFAIK you'll have the
 same functionality as Strawberry.

 http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite

I probably should have mentioned that MinGW is in the AS repository,
so it's a simple install.

C:\ppm install MinGW


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Getting USER env variable in Windows -- How to?

2009-12-09 Thread Ron Bergin
On Dec 9, 7:01 am, tony1234567...@yahoo.co.uk (Tony Esposito) wrote:
 I need to get the current USER env var in a Windows Perl program.  Does 
 anyone know how this is done?  I have done it on UNIX/Linux.

 Thx.

perl -e print $ENV{'USERNAME'}


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: connecting to multiple hosts using Net::SSH2

2009-03-10 Thread Ron Bergin
On Mar 9, 3:37 am, que...@gmail.com (Jerald Sheets) wrote:
 On Mar 8, 2009, at 1:29 PM, Ron Bergin wrote:



  #!/usr/bin/perl -w

  It's better to use the warnings pragma, instead of the -w switch

 Another note on this...  I just perldoc'ed it to see what it had to say:

 DESCRIPTION
 The warnings pragma is a replacement for the command line  
 flag -w,
 but the pragma is limited to the enclosing block, while the  
 flag is
 global.  See perllexwarn for more information.

 If the pragma is limited to the enclosing block but the flag is global  
 *AND* it is considered best practice to remove the pragma when  
 distributing your program:

 ote that it may still be appropriate to comment out the use warnings  
 line when your application or module is deployed, especially if non-
 technical users will interact with it, or if it will run in a CGI or  
 other embedded environment. Issuing warnings in these contexts can  
 needlessly alarm users, or cause server errors.

You seem to be picking out an exception (which in my experience,
rarely occurs) and applying that as the primary rule/guideline.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: connecting to multiple hosts using Net::SSH2

2009-03-09 Thread Ron Bergin
On Mar 4, 4:46 am, que...@gmail.com (Jerald Sheets) wrote:

 I really think you're doing yourself a disservice by just throwing  
 your program commands on lines, not indenting according to best  
 practices.  It makes your code unreadable, and can make it very hard  
 to debug the more involved your programs get.

[snip]

 Consider picking up Damian's book:

 http://oreilly.com/catalog/9780596001735/index.html

 It'll serve you well and is a must have for the serious perl programmer.

I agree, however your code as shown below doesn't follow Perl Best
Practices.

You use improper indentation, and failed to use vertical whitespace
making it harder to read/follow.

 #!/usr/bin/perl -w

It's better to use the warnings pragma, instead of the -w switch

 use Net::SSH2;
 use strict;

 # Set up variables to use
 my $hostlist  =  /path/to/hostlist.txt;
 my @hosts = ();

 # open the hostlist filehandle, and read in values
 open (hostlist_fh, , $hostlist)

better written as:
open my $hostlist_fh, '', $hostlist

     # fail gracefully if something happens
     or die Couldn't open $hostlist for reading:  $!;
       # while reading the list
        while (hostlist_fh) {

Why the added indentation?
The initialization of the while loop should be at the same level as
open.

          # clean up the values
           chomp;
              # stuff them into an array
              push(@hosts, $_);
        }
Same indentation issue here, push should be at the same level as
chomp.
Why loop over that data twice, once when building the array and again
in the below foreach loop?

 # for each element of the array
 foreach my $host (@hosts) {
     # clean it up again

Why clean it up again?  Was it not done properly the first time?

     chomp($host);
        # do the SSH stuff
        my $ssh2

              { all your code here.  host variable is $host }

 }

The code below is the direction of style that I'd use, most of which
is borrowed from Rob's and Ruud's recommendations.

#!/usr/bin/perl

use strict;
use warnings;
use Net::SSH2;
use Readonly;

Readonly::Scalar my $buflen = 10_000;
my $input = 'input.txt';

# I'm creating the ssh object here because
# I don't see the need to recreate it at each iteration of the while
loop
my $ssh2 = Net::SSH2-new();

open my $hosts, '', $input or die Failed to open '$hosts' $!;

while ( my $host = $hosts ) {

chomp $host;

eval {
$ssh2-connect($host) };
1;  # success
}
or do {
my $err = $@ || [unknown error];
warn Unable to connect host $host: $err and next;
};

$ssh2-auth_password('username','password');

my $chan = $ssh2-channel;
$chan-exec('ls -al');

my $buf;
my $read = $chan-read($buf, $buflen);
die More than $buflen characters in listing if $read = $buflen;

print BUF:$buf\n;
$chan-exec('exit');
$ssh2-disconnect;
}


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: CPAN install module problem

2009-03-02 Thread Ron Bergin
On Feb 27, 9:03 pm, howac...@gmail.com (Howa) wrote:
 Hi,

 Why sometimes I can use a command to install Perl module, e.g.

 perl -MCPAN -e install Digest::MD5

 But sometimes can't?

 e.g.

 perl -MCPAN -e install Archive::Zip

  Can't locate object method install via package Archive::Zip at -e line 
  1.

 Are there any reason?

 Thanks

Since you're using double quotes, I assume that you're on Windows.  I
suspect it has something to do with the way cmd is parsing the command
before passing it to perl.

If you enter the cpan shell and then issue install command, you can
avoid this problem.

e.g.,
this doesn't work, as you already know
C:\testperl -MCPAN -e install Archive::Zip
Can't locate object method install via package Archive::Zip at -e
line 1.

this does work
C:\testperl -MCPAN -e shell

cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support enabled


cpan install Archive::Zip
CPAN: Storable loaded ok
Going to read C:\Perl\cpan\Metadata
  Database was generated on Sun, 01 Mar 2009 11:26:52 GMT
Running install for module Archive::Zip
Running make for A/AD/ADAMK/Archive-Zip-1.26.tar.gz
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
  
ftp://cpan-sj.viaverio.com/pub/CPAN/authors/id/A/AD/ADAMK/Archive-Zip-1.26.tar.gz
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
  ftp://cpan-sj.viaverio.com/pub/CPAN/authors/id/A/AD/ADAMK/CHECKSUMS
CPAN: Compress::Zlib loaded ok
Checksum for C:\Perl\cpan\sources\authors\id\A\AD\ADAMK\Archive-
Zip-1.26.tar.gz ok
Scanning cache C:\Perl\cpan\build for sizes
Archive-Zip-1.26/





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Slow connexion with Net::SSH::Perl

2009-02-04 Thread Ron Bergin
On Feb 3, 12:38 pm, jul.col...@gmail.com (Julien Collas) wrote:
 Hi everyone,

 I made a script using Net::SSH::Perl and I'm faced to some slow
 connexion times.
 I use rsa key to connect and it seems to be very slow, but not all the time.
 Sometimes it's very quick ( 1sec ), sometimes not (few minutes).
 I tried to use password instead of a key, and it seems to be quicker.
 You may have an idea to help me 
 Thanks


I had the same problem and fixed by installing these 3 modules.

Math::BigInt
Math::BigInt::GMP
YAML

They should be part of the required dependencies, but they're not, or
at least they weren't when I installed it in 2007.  It was a know
issue back then and this was the solution given to me in mailing list
for the module.
http://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How do I print something out in color on windows cmd?

2009-02-03 Thread Ron Bergin
On Feb 1, 11:43 pm, psars...@ptc.com (Paryushan Sarsamkar) wrote:
 I wanted to print some text on windows cmd in different colors, below is the 
 code that I am using which works fine on unix but not on windows L

 #!/usr/bin/perl

 use strict;

 use warnings;

 use Term::ANSIColor;

 print color(red), Stop!\n, color(reset);

 print color(green), Go!\n, color(reset);

 output -

 ←[31mStop!

 ←[0m←[32mGo!

 ←[0m

 Thanks,

 Paryushan

You need to add:

use Win32::Console::ANSI;


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Neater way to declare variables

2009-01-08 Thread Ron Bergin
On Jan 8, 3:56 am, andrew.tayl...@hmrcaspire.com (Andrew Taylor)
wrote:
 Hello

 I have a script that is (at one point) reading through a file.  The file
 is processed line by line and each line split into an array like so:

 while ($TESTFILE)

 {

   my $cur_line=$_;

   chomp ($cur_line);

while (my $cur_line = $TESTFILE) {
 chomp $cur_line;

   my @split_line = split( /$t_delim/, $cur_line );

 # In a number of places, I have code that looks like the following.

   my $default_type;

   if( $split_line[0] eq DEFAULT_INPUT )

   {

     $default_type = INPUT;

   }

   if ( $split_line[0] eq DEFAULT_OUTPUT )

   {

     $default_type = OUTPUT;

   }

snip


 This works OK, but I'm trying to avoid declaring variables seperately
 from assigning them (wherever possible), and trying to keep the size of
 the script down without losing human legibility.  

 Is there a neater/cleverer way of doing this?


my $default_type = $split_line[0] =~ /INPUT/ ? 'INPUT' : 'OUTPUT';


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: which module is suitable for logging into cisco devices

2008-11-25 Thread Ron Bergin
On Nov 23, 1:17 pm, [EMAIL PROTECTED] (Monnappa Appaiah) wrote:
 i forgot to mention that, i'l be running the script from the windows machine
 ..so pls let me know the module which can login to cisco devices
 using ssh, execute certain commands and give me the output.

 Thanks,
 Monnappa

 On Sun, Nov 23, 2008 at 11:51 PM, monnappa appaiah [EMAIL PROTECTED]wrote:

  Hi all,

I'm looking for a module which can login to cisco devices using
  ssh, execute certain commands and give me the output.can
  somebody suggest me
  the module which is best suitable for loggin into cisco devices via ssh.

  Thanks,
  Monnappa

Have you looked at any of the cisco modules on cpan?

http://search.cpan.org/search?m=allq=ciscos=1

Here's 1 possiblity.
Net::Telnet::Cisco::IOS
http://search.cpan.org/~kraken/Net-Telnet-Cisco-IOS-0.6beta/lib/Net/Telnet/Cisco/IOS.pm


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Trying to modify Perl script

2008-09-23 Thread Ron Bergin
On Sep 22, 10:16 am, [EMAIL PROTECTED] (Stephen Reese) wrote:
 John,

 I made many of the changes but what is the addition of the 'next' statement
 for? I tried to add the additional code but the script dies mentioning that
 it is not terminated correctly. If I comment out the next statement the
 script runs fine.

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

[snip]

 #next unless /IPACCESSLOGP: list $acl denied ([tcpud]+)
 ([0-9.]+)\([0-9]+\)\s*-\s*([0-9.]+)\(([0-9]+)\), ([0-9]+) \;

next unless /IPACCESSLOGP: list $acl denied ([tcpud]+) ([0-9.]+)\
([0-9]+\)\s*-\s*([0-9.]+)\(([0-9]+)\), ([0-9]+) /;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Understanding Perl script functionality

2008-09-21 Thread Ron Bergin
On Sep 19, 10:07 pm, [EMAIL PROTECTED] (Stephen Reese) wrote:
 I am working on modifying a script that previously parsed Cisco ACL's
 and changing it to parse IPS information.

 Here is an example of the two log formats.

 Sep 19 15:44:29 172.16.2.1 59800: 3725router: Sep 19 19:44:39: %SEC-6-
 IPACCESSLOGP: list 104 denied udp 93.144.187.255(13157) -
 68.156.63.111(49615), 1 packet
 Sep 19 15:44:29 172.16.2.1 59801: 3725router: Sep 19 19:44:40: %IPS-4-
 SIGNATURE: Sig:3051 Subsig:1 Sev:4 TCP Connection Window Size DoS
 [194.255.113.170:59920 - 68.156.63.111:49615]

 Here is the original 
 script:http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/...

 Here is what I have been able to come up with. It runs but of course
 there is no output. Any hints about where I should go next to debug
 would be great. Thanks.

 #!/usr/bin/perl
 #
You're missing 2 very important pragmas that should be in every script
you write.

use warnings; #
use strict;   # forces you to declare your vars prior to their use.

 #
 # Set behaviour
 $log=/var/log/cisco.log;
my $log = '/var/log/cisco.log';

 $ntop=10;
my $ntop = 10;
my (%quad, %port);

 #
 chomp ($sig=$ARGV[0]);
 if ($sig eq ) { $sig=.*};
Personally, I'd reduce those 2 lines to:
chomp ( my $sig = $ARGV[0] || '.*' );


 open(LOG , $log) or die;
It's preferable/better to use a lexical var for the filehandle instead
of the bareword and to use the 3 arg form of open and include the
reason it failed in the die statement.
open my $LOG, '', $log or die Can't open $log $!;

 while (LOG) {
while ($LOG) {
  if (/SIGNATURE: Sig:$sig Subsig:$subsig Sev:$sev $message \[([0-9.]+):
 ([0-9]+)\s*-\s*([0-9.]+)([0-9]+)\] /)
 {
The warnings pragma will point out the following problems in the
regex.
Name main::subsig used only once: possible typo at 
Name main::message used only once: possible typo at 
Name main::sev used only once: possible typo at 

Once you fix those issues, the script will probably work as expected,
but if not, you'll need to tweak the regex.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: search and replace command with output

2008-08-19 Thread Ron Bergin
On Aug 13, 1:44 pm, [EMAIL PROTECTED] wrote:
 Hi,

 I am trying to search  replace a string in a file using the below
 perl command on unix.

 perl -pi -e 's/OLD/NEW/g' repltest.txt

 But I want the above command to display what lines were replaced.  Is
 it possible using some switch options?  If it is not possible using
 any of the switches, I don't mind couple of lines of code.

 unix version: SunOS 5.9 Generic_122300-22 sun4u sparc SUNW,Netra-T12

 Thanks in advance.

Try:
perl -pi -e 'print STDERR $. $_ if s/OLD/NEW/g' repltest.txt


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: hash of arrays

2008-08-19 Thread Ron Bergin
On Aug 18, 1:03 pm, [EMAIL PROTECTED] (Anjan Purkayastha)
wrote:
 hi,
 i'm struggling with a hash of arrays problem.
 suppose i create the following HOA:
 $HOA{$key}= [qw(a,b,c,d)];

I doubt that the results of that assignment is what you want/expect.

#!/usr/bin/perl

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

$key = 'key';
$HOA{$key}= [qw(a,b,c,d)];
print Dumper \%HOA;

outputs:
Possible attempt to separate words with commas at C:\test\perl-2.pl
line 8.
Possible attempt to separate words with commas at C:\test\perl-2.pl
line 8.
Possible attempt to separate words with commas at C:\test\perl-2.pl
line 8.
$VAR1 = {
  'key' = [
 'a,b,c,d'
   ]
};

I suspect you wanted this:
$HOA{$key}= [qw(a b c d)];

which will give you:
$VAR1 = {
  'key' = [
 'a',
 'b',
 'c',
 'd'
   ]
};


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: getting process id under NT

2008-08-03 Thread Ron Bergin
On Aug 1, 9:43 am, [EMAIL PROTECTED] (Epanda) wrote:
 I have tried your pm and it works well on XP but does not on my NT
 platform.

 I have the following error : Error - Variant '$_[0]' support status is
 unknown. This can happen if
 you 'use Win32::Process::Info ();'. Please do not do that.
 eod

 When I set the environment variables I have Windows_NT has OS.
 So it should work no ?

 Happytown a écrit :

  On Jul 30, 11:09 am, [EMAIL PROTECTED] (Ron Bergin) wrote:
   On Jul 29, 9:12 am, [EMAIL PROTECTED] (Epanda) wrote:

Hi HappyTown

I have seen your web link but I don't think it can show me the PID if
I give the name of an existing and running Win NT application.

On 28 juil, 05:24, [EMAIL PROTECTED] (Happytown) wrote:

 On Jul 26, 3:14 am, [EMAIL PROTECTED] (Epanda) wrote:

  Hi,

  I would like to know if it is possible to get win32 process ID under
  Windows NT without using Win32::OLE because this one does not work
  under NT.

  Thanks

 Maybe, this module can help 
 you:http://search.cpan.org/~cosimo/Win32-API-0.55/API.pm

   Win32::API will do what you need, however, it's not the easiest to
   use. Getting the process info requires calling several (about 5)
   different C functions in kernel32.dll and setting up the function
   calls can be tricky.

   It would be easier and better to use Win32::Process::Info (which uses
   Win32::API) and let it deal with setting up the function 
   calls.http://search.cpan.org/~wyant/Win32-Process-Info-1.012/lib/Win32/Proc...Hide
quoted text -

   - Show quoted text -

  Yes, you're right.

Does your use statement look like this:
use Win32::Process::Info ();

or this:
use Win32::Process::Info;


What result do you get from this little test script?

#!perl

use Win32;
print Win32::IsWinNT();


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: getting process id under NT

2008-07-29 Thread Ron Bergin
On Jul 29, 9:12 am, [EMAIL PROTECTED] (Epanda) wrote:
 Hi HappyTown

 I have seen your web link but I don't think it can show me the PID if
 I give the name of an existing and running Win NT application.

 On 28 juil, 05:24, [EMAIL PROTECTED] (Happytown) wrote:

  On Jul 26, 3:14 am, [EMAIL PROTECTED] (Epanda) wrote:

   Hi,

   I would like to know if it is possible to get win32 process ID under
   Windows NT without using Win32::OLE because this one does not work
   under NT.

   Thanks

  Maybe, this module can help 
  you:http://search.cpan.org/~cosimo/Win32-API-0.55/API.pm

Win32::API will do what you need, however, it's not the easiest to
use.  Getting the process info requires calling several (about 5)
different C functions in kernel32.dll and setting up the function
calls can be tricky.

It would be easier and better to use Win32::Process::Info (which uses
Win32::API) and let it deal with setting up the function calls.
http://search.cpan.org/~wyant/Win32-Process-Info-1.012/lib/Win32/Process/Info.pm


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: losing variable in CGI.pm redirect

2008-01-23 Thread Ron Bergin
On Jan 22, 1:31 pm, [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
 Hi,
 Hopefully this appropriate question for this group.  I am trying to
 redirect to a website:

 print $query-redirect(-location=test.cgi?ID=$value, -
 method='GET');

 Unfortunately the $value never gets passed and I end up with test.cgi?
 ID=  .

 Thanks,
 J

http://search.cpan.org/~lds/CGI.pm-3.33/CGI.pm#GENERATING_A_REDIRECTION_HEADER

quoted from the cpan doc:
You should always use full URLs (including the http: or ftp: part) in
redirection requests. Relative URLs will not work correctly.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Manually installing perl modules on windows

2007-11-24 Thread Ron Bergin
On Nov 23, 7:26 am, [EMAIL PROTECTED] (Andy) wrote:
 Hi,

 I am trying to talk to a programmable oven over serial port for heat
 testing of a PCB.

 I am using ActiveState perl v5.8.8 on Windows XP. I am trying to
 install the Win32:SerialPort package using Activestates Perl Package
 Manager (PPM). Unfortunatley, I cant see it anywhere,in the package
 repository. I checked active states website and sure enough they say
 its not available :-(

 I have used packages before on a unix system and installed them
 manually using make, make test, make install. But i dont have a make
 utility on my windows system, is there an easy way to install modules
 that PPM doesnt have on a windows system?

 many thanks in advance, sorry if this is a dumb question

 Andy

C:\ppm install http://www.bribes.org/perl/ppm/Win32-SerialPort.ppd


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Building a string to contain a \

2007-11-18 Thread Ron Bergin
On Nov 16, 1:12 pm, [EMAIL PROTECTED] (AndrewMcHorney) wrote:
 Hello

 I am trying to build a string that contains the following text dir
 c:\ /S so I can get a complete directory of all the files on drive C
 and put them into an array with the following line of code -
 @dir_list = 'dir c:\ /S`;
The backslash is the escape char.  If you need a literal \ in the
command, then you'll need to escape it by doubling it up i.e.,
my @dir_list = `dir c:\\ /S`;


 Right now I have the following working:

 However, it is now working:

 @dir_list = 'dir c: /S`; which gives me all the files in the
 directory that is being pointed to at the moment for C: and all the
 subdirectories.

 Andrew

Rather than using the backticks to execute the dir command which you
then need to parse, a better approach would be to use the File::Find
module (or one of its cousins).
http://search.cpan.org/search?query=file%3A%3Afindmode=all

use strict;
use warnings;
use File::Find;

my @file_list;
my $dir = 'c:/';

find(\file_listing, $dir);

sub file_listing {
   return if -d;  # skip over directory entries

   # add file name onto the array
   push @file_list, $_;

   # or add filename with path info onto array
   #push @file_list, $File::Find::name;
}

print scalar @file_list  files in/under $dir;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How can I assign system() call to a Variable

2007-11-14 Thread Ron Bergin
On Nov 13, 7:11 pm, [EMAIL PROTECTED] (Marco) wrote:
 Hi...

 Can someone help me on this? Actually I can get the dara from the
 system()...But it shows 0 when I print the $result...How can I
 assign the system() to $result ?Thanks...

 here below is the code...

 $inact = cat /proc/meminfo | grep -w Inactive | sed 's/^.*Inactive: //
 g' | sed 's/kB//';
 $result = system(cat /proc/meminfo | grep -w Inactive | sed 's/
 ^.*Inactive: //g' | sed 's/kB//');
 print $result;

If you prefer to not use the Linux::MemInfo module, you can do the
following (but I think the module is a better approach):

open my $meminfo, '/proc/meminfo' or die $!;
while( $meminfo ) { print $1 if /Inactive:\s+(\d+)/; }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How can I assign system() call to a Variable

2007-11-14 Thread Ron Bergin
On Nov 13, 7:11 pm, [EMAIL PROTECTED] (Marco) wrote:
 Hi...

 Can someone help me on this? Actually I can get the dara from the
 system()...But it shows 0 when I print the $result...How can I
 assign the system() to $result ?Thanks...

 here below is the code...

 $inact = cat /proc/meminfo | grep -w Inactive | sed 's/^.*Inactive: //
 g' | sed 's/kB//';
 $result = system(cat /proc/meminfo | grep -w Inactive | sed 's/
 ^.*Inactive: //g' | sed 's/kB//');
 print $result;

If you want to write Perl scripts, then learn its methods.  If all you
want is shell calls, then do shell scripting.

#!/usr/bin/perl

use strict;
use warnings;
use Linux::MemInfo;

my %meminfo = get_mem_info;
print $meminfo{'Inactive'};


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: SSH with PERL

2007-11-02 Thread Ron Bergin
On Nov 2, 6:06 am, [EMAIL PROTECTED] (Lerameur) wrote:
 On Nov 1, 9:29 pm, [EMAIL PROTECTED] (Tom Phoenix) wrote:



  On 11/1/07, lerameur [EMAIL PROTECTED] wrote:

   I wrote a small script, the manual upload of a file works, but gives
   me an error message:unable to initialize mechanism library [/usr/lib/
   gss/gl/mech_krb5.so]
   Could some tell me what this is about? it does end up transferirng the
   file.

  As near as I can guess, that library file (which, I'd further guess
  has something to do with Kerberos authentication) is borked. Exactly
  what's wrong with it is anyone's guess. Probably there's something
  else that succeeds as a fallback, since the file gets transferred; so
  you could perhaps configure it somehow to not even try using Kerberos.
  You might be able to turn on a debugging mode to find out more
  information; check the documentation for the modules you're using.
  (When you post a question, mention which modules you're using, and we
  may be able to give you more specific help.)

 I am having success with manually transfering my files between the two
 servers. Unfortunately I do not have root access to the other server
 and the .ssh directory is hidden.
You don't need root access to access/edit your ssh files.

 manually:
 Server1200:/input/spamscp 20071102093215.txt 174.34.34.34:/home/input/
 traffic_log
 [EMAIL PROTECTED]'s password:
 20071102093215.txt   |  42MB | 6.0MB/s | TOC: 00:00:07 | 100%
 Server1200:/input/spam

 here the SCP part of my script:

 .
 $SCP=Net::SCP-new($host,Timeout=240) or $newerr=1;  #Establishing the
 connectiong
   push @ERRORS, Can't SCP to $host: $!\n if $newerr;
   myerr() if $newerr;
 print Connected\n;

 $SCP-login($user,$password) or $newerr=1;
The Net::SCP module uses ssh keys for its authentication.
If you want to pass the password, you'll want to use Net::SCP::Expect
http://search.cpan.org/perldoc?Net%3A%3ASCP%3A%3AExpect

 print Getting file list\n;
   push @ERRORS, Can't login to $host: $!\n if $newerr;
   $SCP-quit if $newerr;
   myerr() if $newerr;
 print Logged in\n;

 $SCP-cwd($directory) or $newerr=1;
   push @ERRORS, Can't cd  $!\n if $newerr;
   myerr() if $newerr;
   $SCP-quit if $newerr;

 $SCP-put($file_to_put) or die $SCP-{errstr};   # DIES
 HERE...
   print Putting file and quitting \n;

 The directory exists, I do not know why, any ideas?
 anything else would be needed?

 thanks
 ken



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Include variables from external perl script

2007-11-01 Thread Ron Bergin
On Oct 30, 6:50 pm, [EMAIL PROTECTED] (Howa) wrote:
 On 10 30 ,   9 38 , [EMAIL PROTECTED] (Ron Bergin) wrote:

  On Oct 30, 3:34 am, [EMAIL PROTECTED] (Jeff Pang) wrote:

  In addition to changing 'my' to our' in Config.pl, you'll also need to
  add the 'our $value;' to Script.pl

 yes you are right, I need to include `our` twice to make the code work
 if using strict.

 however, this seems to be a little dummy to declare the same variable
 twice, any better method(s)?

 thanks,

First, you need to ask yourself 1) why you want to use an external
config file, and 2) is using an external config file the best
approach?

If an external config file is what you need, then you should look into
using one of the CPAN module's suited for this purpose.
http://search.cpan.org/search?query=configmode=all
http://search.cpan.org/search?query=inimode=all


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: array within array

2007-10-30 Thread Ron Bergin
On Oct 29, 11:09 am, [EMAIL PROTECTED] (John W . Krahn) wrote:
 On Monday 29 October 2007 06:42, Mike Tran wrote:

  Hey all,

 Hello,

  I'm new with Perl and need help with this simple script. I'm still
  playing around with the script below to get a feel for Perl. My
  script below is incomplete and I'm doing an array within an array
  which is incorrect. Please help.

 You are not using arrays you are using hashes.



  Here's what I want to do; I have to flat files (pipe delimited,
  export from a database) that I want to parse through and assign
  variables for each column. Basically, I want to parse through
  exclude_bases.txt and do: if base_no in exclude_bases.txt equals to
  base_no in base.txt then search in the description field of
  base.txt for the string listed in the keyword field in
  exclude_bases.tx and replace with new_keyword in exclude_bases.txt
  and write the out put into a new file called new_bases.txt.

  Any suggestions on how I could accomplish the above task is greatly
  appreciated. Thanks all.

  Flat Files:

  base.txt:
  base_no|name|description
  1|test|test desc
  10001|test2|test desc 2
  10002|test3|test desc 3

  exclude_bases.txt:
  base_no|keyword|new_keyword|
  1|test desc|testdesc|0
  10001|test desc 2|testdesc2|0
  10002|test desc 3|testdesc3|1

[snip]

 It looks like you may want something like this:

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

 my $exclude_bases = 'exclude_bases.txt';
 my $current_base  = 'base.txt';
 my $output= 'new_bases.txt';

 open EXCLUDE, '', $exclude_bases or die Could not open
 '$exclude_bases' $!;

 my %exclude_bases;
 while ( EXCLUDE ) {
 next if $. == 1;  # exclude header
 chomp;
 my ( $exbase_no, $keyword, $new_keyword ) = split /\|/;
 $exclude_bases{ $exbase_no } = { from = qr/\Q$keyword/, to =
 $new_keyword };
 }
Since you're not taking into account the blank lines, you'll be
generating these warnings:

Use of uninitialized value in quotemeta at C:\test\JohnKrahn.pl line
17, EXCLUDE line 2.
Use of uninitialized value in hash element at C:\test\JohnKrahn.pl
line 17, EXCLUDE line 2.
Use of uninitialized value in quotemeta at C:\test\JohnKrahn.pl line
17, EXCLUDE line 4.
Use of uninitialized value in hash element at C:\test\JohnKrahn.pl
line 17, EXCLUDE line 4.


 close EXCLUDE;

 open BASE, '', $current_base  or die Could not open '$current_base'
 $!;
 open OUT,  '', $outputor die Could not open '$output' $!;

 while ( BASE ) {
 my ( $base_no, $name, $description ) = split /\|/;
 if ( exists $exclude_bases{ $base_no } ) {
 $description =~
 s/$exclude_bases{$base_no}{from}/$exclude_bases{$base_no}{to}/g;
 $_ = join '|', $base_no, $name, $description;
 }
 print OUT;
 }
Again, blank lines are not taken into account, but no warnings since
the printing is being handled within the conditional block.

Since a complete solution, to what appears to be a homework question,
has already been provided, I guess I'll show mine.

#!/usr/bin/perl

use warnings;
use strict;

my %base;

open (my $new, '', 'new_bases.txt') || die new_bases.txt $!;
open (my $exclude, '', 'exclude_bases.txt') || die exclude_bases.txt
$!;
open (my $base, '', 'base.txt') || die base.txt $!;

while ($base) {
  next if /^\s*$/;  # skip over blank lines
  print and next if $. == 1; # print header
  chomp;
  my @fields = split /\|/;
  $base{$fields[0]} = [EMAIL PROTECTED];
}
close $base;

while ($exclude) {
  next if /^\s*$/; # skip over blank lines
  chomp;
  my @fields = split /\|/;
  if ( exists $base{$fields[0]} and $fields[1] eq $base{$fields[0]}
[2]) {

$base{$fields[0]}[2] = $fields[2];

# if you want to retain the empty lines between records,
# you can use \n\n in the print statement,
# or reassign the output record separator
print $new join('|', @{$base{$fields[0]}}), \n;
  }
}
close $exclude;
close $new;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Hash Variables

2007-10-30 Thread Ron Bergin
On Oct 29, 8:25 pm, [EMAIL PROTECTED] (Kaushal Shriyan) wrote:
 Hi

 I am referring to perldoc perlintro
 my %fruit_color = (apple, red, banana, yellow);

 You can use whitespace and the = operator to lay them out more nicely:

my %fruit_color = (
apple  = red,
banana = yellow,
);

 I know to use the Fat Comma Operator, How can one use the whitespace to lay
 the Hash Key/Values Pair. Please explain me with the above example.

 Thanks and Regards

 Kaushal

 On 10/29/07, Kaushal Shriyan [EMAIL PROTECTED] wrote:



  Hi,

  I have a sample code

  

  #!/usr/bin/perl -w

  %states = ( California,Sacramento, Wisconsin,Madison, New York,
  Albany);

  print Capital of California is  . $states{California} . \n\n;

  

  I did not understand the statement $states{California} in the above
  print statement of the code

  I know the the dot is a concatenation operator and \n is a newline
  character

  Thanks in Advance.

  Thanks and Regards

  Kaushal

#!/usr/bin/perl

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

my %fruit_color = qw(apple red banana yellow);
print Dumper \%fruit_color;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Include variables from external perl script

2007-10-30 Thread Ron Bergin
On Oct 30, 3:34 am, [EMAIL PROTECTED] (Jeff Pang) wrote:
 On 10/30/07, howa [EMAIL PROTECTED] wrote:

  Consider the example below...

  Config.pl
  ==

  #!/usr/bin/perl -w

  my $value = abc;

 change 'my' to 'our'.



  1;

  Script.pl
  ==
  require Config.pl;
In addition to changing 'my' to our' in Config.pl, you'll also need to
add the 'our $value;' to Script.pl

  print $value; # How to do this, beside using .pm?

  Thanks.

Here's another option.

Config.cfg
==
$value = abc;


Script.pl
=
#!/usr/bin/perl

use strict;
use warnings;

our $value;
do 'config.cfg';
print $value;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Include variables from external perl script

2007-10-30 Thread Ron Bergin
On Oct 30, 7:50 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
 On Oct 30, 9:38 am, [EMAIL PROTECTED] (Ron Bergin) wrote:

   On 10/30/07, howa [EMAIL PROTECTED] wrote:

Consider the example below...

Config.pl
==

#!/usr/bin/perl -w

my $value = abc;
  In addition to changing 'my' to our' in Config.pl, you'll also need to
  add the 'our $value;' to Script.pl

 Blatantly untrue.  The OP was not using strict.  'our' is only
 required to be able to refer to global variables without qualifying
 them when strict 'vars' is in use.  If there is no strict, 'our' is a
 no-op.

 Paul Lalli

I wouldn't say that it was Blatantly untrue.  However, I did neglect
to include my normal qualification instructing the person to always
use the strict and warnings pragmas like I did in the optional method
that I posted.  With the inclusion of the strict pragma, then the use
of 'our' in Script.pl would be needed.

The OP didn't show us the shebang for the Script.pl, but since the -w
switch is being used in Config.pl, it's a fair assumption that it's
being used in Script.pl.  Assuming that to be true, failing to use
'our' in Script.pl will generate the following warning.

Name main::value used only once: possible typo at 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: array within array

2007-10-29 Thread Ron Bergin
On Oct 29, 6:42 am, [EMAIL PROTECTED] (Mike Tran) wrote:
 Hey all,

 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My script
 below is incomplete and I'm doing an array within an array which is
 incorrect. Please help.

 Here's what I want to do; I have to flat files (pipe delimited, export
 from a database) that I want to parse through and assign variables for
 each column. Basically, I want to parse through exclude_bases.txt and
 do: if base_no in exclude_bases.txt equals to base_no in base.txt then
 search in the description field of base.txt for the string listed in
 the keyword field in exclude_bases.tx and replace with new_keyword
 in exclude_bases.txt and write the out put into a new file called
 new_bases.txt.

 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all.
This sounds like a homework assignment, so I won't provide a complete
solution, but I will give a few pointers and maybe a little code.

 Flat Files:

 base.txt:

 base_no|name|description

 1|test|test desc

 10001|test2|test desc 2

 10002|test3|test desc 3

 exclude_bases.txt:

 base_no|keyword|new_keyword|

 1|test desc|testdesc|0

 10001|test desc 2|testdesc2|0

 10002|test desc 3|testdesc3|1
Your description of your required output doesn't say what you want to
do with the 4th field in the exclude_bases.txt.

 #!/usr/bin/perl

 use strict;

 use warnings;

 my $exclude_bases = exclude_bases.txt;

 my $current_base = base.txt;

 my $output = new_bases.txt;

 my %exclude_bases;

 my $exclude_text;

 my $exbase_no;

 my $keyword;

 my $new_keyword;
You don't really need most of those and the following global vars.
You should define the vars in the smallest scope that they require.

 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);
Why didn't you use the $exclude_bases var that you previously defined?
You should use the 3 arg form of open and include $! in the die
statement which will tell you why it failed.

 %exclude_bases=EXCLUDE;
Why are you slurping the data into a hash?  If you use the
Data::Dumper module to output that hash, I think you'll find that it's
not in the format that you wanted.

 close(EXCLUDE);

 my $base_no =;

 my $name=;

 my $description=;

 my $current_base=;

 my $base_text=;

 my %bases;

 open(BASE,base.txt)|| die(Could not open file!);

 %bases=BASE;

 close(BASE);
See my previous comments.

 #choping lines and assign variables to base.txt

 foreach $base_text (%bases)

 {

   chop($base_text);
use chomp instead of chop

   ($base_no,$name,$description)=split(/\|/,$base_text);

 #choping lines and assign variables to exclude_bases.txt

 foreach $exclude_text (%exclude_bases)

 {

   chop($exclude_text);

   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);

   if ($exbase_no=$base_no) {

   $keyword =~ s/$keyword/$new_keyword/g;}

 }
 }

 ~

Here's how I'd load the hash.

my %base;

open (my $base, '', 'base.txt') || die base.txt $!;
while ($base) {
  next if /^\s*$/;
  chomp;
  my @fields = split /\|/;
  $base{$fields[0]} = [EMAIL PROTECTED];
}
close $base;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-26 Thread Ron Bergin
On Oct 25, 9:38 pm, [EMAIL PROTECTED] (mAyur) wrote:
 On Oct 23, 6:55 pm, [EMAIL PROTECTED] (Paul Lalli) wrote:



  On Oct 22, 3:27 pm, [EMAIL PROTECTED] (Ayesha) wrote:

   Hi all

   I wrote this code to read a file (in the same directory as the script)
   on Win XP
   ***­­
   #!/usr/local/bin/perl
   use strict;
   use warnings;

   open(READFILE1,./Sample_text_file.txt) or die (Cannot open the
   given file);

[snip unrelated stuff]

  Not relevant to the problem at hand, but you should also be using
  lexical filehandles instead of global barewords, and get into the
  habbit of using the three-argument form of open:

  open my $READFILE1, '', './Sample_text_file.txt' or
 die Cannot open the given file: $!;


 Some suggestions:
 1. Instead of using $! for displaying error messages, use $^E. U will
 get more descriptive error messages.
 2. Quickly going thru this digest i observerd usage of '\' in double
 quotes, this is not recommended. always escape '\' in double quotes
 like this \\. Heres an example where things can go wrong, lets say
 ur file/directory name starts with 'n' and u say somthing like open
 FILE, .\newFile; \n is interpreted as special character by perl
 or for that matter any other language. Correct way would be open
 FILE, .\\newFile;

 ~emptee.

Your #2 suggestion is not the best in this case/example.
Why did you use a forward slash instead of backslash for the path
separator?

Better advise would be to:
1) Use double quotes (or the qq() operator) only when needed i.e.,
when you need variable interpolation.
2) Use the 3 arg form of open as Paul showed.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-25 Thread Ron Bergin
On Oct 23, 6:57 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
 On Oct 23, 12:27 am, [EMAIL PROTECTED] (Ayesha) wrote:

  I was not in the right directory, but I learnt about forward and
  backward slashed also. Thanks to all who replied

 Arg.  This is exactly what I was afraid of.  The post about forward vs
 backwards slashes was wrong.  Do not follow it.  You should ALWAYS use
 front slashes, regardless of Windows vs Unix.   The only thing in
 Windows that requires backslashes is the cmd.exe or command.com

That's not entirely correct.  As log as you use proper quoting, you
can use forward slashes in the cmd shell.

Try this:
C:\cd c:/Program Files

C:\Program Files


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-25 Thread Ron Bergin
On Oct 23, 6:57 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
 On Oct 23, 12:27 am, [EMAIL PROTECTED] (Ayesha) wrote:

  I was not in the right directory, but I learnt about forward and
  backward slashed also. Thanks to all who replied

 Arg.  This is exactly what I was afraid of.  The post about forward vs
 backwards slashes was wrong.  Do not follow it.  You should ALWAYS use
 front slashes, regardless of Windows vs Unix.   The only thing in
 Windows that requires backslashes is the cmd.exe or command.com
 shells.  You are not using these shells when you write a Perl program.

 Paul Lalli

My first reply hasn't propagated yet, so I'll post this update.

The cmd shell excepts both types of slashes.  I first thought that you
needed to use quotes when using forward slashes, but I was wrong.  Try
this simple test.

C:\notepad c:/boot.ini


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How do I replace a part of huge text file

2007-10-25 Thread Ron Bergin
On Oct 22, 1:52 am, [EMAIL PROTECTED] (Anand Shankar) wrote:
 Hi,

 I would like to replace a part of a really big (4GB) text file. And
 the contents that I want to change is really a small but continuous
 portion. Could some one please help me with the best way I can do this
 in perl?

 Thanks,

use Tie::File;

http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Array Manipulation

2007-10-25 Thread Ron Bergin
On Oct 25, 1:59 am, [EMAIL PROTECTED] (Irfan Sayed) wrote:
 Hi All,

 I have one array say my @test=(1,2,3,4,5);
 if I print this array it will print like this
 print @test\n;
 and the output is
 1 2 3 4 5

 now my req. is that I want to store these array values in another array
 in such a fashion where I can print like
 1
 2
 3
 4
 5

 so I mean to say that if I type print @test1\n;
 then output should come as
 1
 2
 3
 4
 5

 I have used push function also but it is not giving expected result.

 Please guide.

 Regards
 Irfan.

print $_,$/ for @test;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Can I modify the contents of a file, without creating a new one?

2007-10-12 Thread Ron Bergin
On Oct 11, 2:37 am, [EMAIL PROTECTED] (PeiYu Zeng) wrote:
 Hello,

 Can I modify the contents of a file, without creating a new one?

 Now, the method that I modify the contents of a file is:
 open( READHANDLE , sourceFile );
 open( WRITEHANDLE, destiFile );

 foreach my $line (READHANDLE) {
 if it accords with my rules {
 modify $line;
 print(WRITEHANDLE $line);
 }
 }

 close(...);

 Is there a method that I could not create a new file to store the modified
 informations?

 Thanks,
 Zen

use Tie::File;
http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Can I modify the contents of a file, without creating a new one?

2007-10-12 Thread Ron Bergin
On Oct 11, 4:25 am, [EMAIL PROTECTED] (Jeff Pang) wrote:
 2007/10/11, PeiYu Zeng [EMAIL PROTECTED]:

  Hello,

  Can I modify the contents of a file, without creating a new one?

 Yes.You can use perl one-liner to do that,

 perl -pi.bak -e 'modify the current line if it match some conditions' file

 But actually this has been creating a new file,you just wouldn's see it.

Since you added .bak to the -i option, you'll end up with both
versions, so you will see it.  If you're on a *nix system, you could
leave of the .bak in which case you'll end up with just the one file.
For some reason, adding the ext to keep the original is required on
Windows (ActiveState Perl).


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: undef in data dumper output

2007-09-26 Thread Ron Bergin
On Sep 24, 8:38 pm, [EMAIL PROTECTED] wrote:
 I'm using html::tokeparser::simple and will next place desired data
 into hashes, but I'm having problems getting to the individual pieces
 of data.

 After using html::tokeparser::simple, then using a regex and pushing
 data into a new array, I can't access individual elements of the
 array. Using data dumper, I see several variables that are undefined,
 in addition to the 3 digit wind directions that I'm looking to access
 individually via $wnddir[2] etc.
 My goal is to only have what I'm trying to parse (wind directions of 3
 digits each in this case) in my array that I'm pushing to. Here's my
 code:

 #!/usr//bin/perl

 use warnings;
 use strict;
 use CGI qw(:standard);
 use CGI::Carp qw(fatalsToBrowser);
 use LWP::Simple qw(!head);
 use HTML::TokeParser::Simple;
 use Data::Dumper;

 print header;
 print start_html(WindshftObs);
 my @wnddir = ();
 my @times = ();
 my $sjc=sjc;
 my $sfo=sfo;
 my $sql=sql;

 #call sub to loop through ob data and parse wnd direction and time of
 #observation
 my @data = Winds($sfo, $sjc);

 foreach my $datum (@data)  {
my ($wnds) = $datum =~ (/(\d{3})+\d{2}KT|(\d{3})+\d{2}G\d{2}KT/);
push @wnddir, $wnds;
my ($Offtime) = $datum =~ (/\d{2}(\d{2})\d{2}Z/);
push @times, $Offtime;}

 print Dumper @wnddir;
 print @wnddirbr;

 sub Winds  {
return Error: No argument sent to Winds unless @_;
my @apt = @_;
my @data;

foreach my $icao (@apt)  {
   my $url = http://www.wrh.noaa.gov/mesowest/getobext.php?
 wfo=sid=K$icaonum=3raw=3dbn=mbanner=off;
   my $content= get($url) or die Error getting file: $!;
   my $p = HTML::TokeParser::Simple-new(\$content) || die Can't
 open: $!;

   while (my $token = $p-get_token) {
  next unless $token-is_text;
  push @data, $token-as_is;
   }

}
 return @data;

 }

 print end_html;

 And here's my results:
 $VAR1 = undef; $VAR2 = undef; $VAR3 = undef; $VAR4 = '280'; $VAR5 =
 '280'; $VAR6 = '340'; $VAR7 = undef; $VAR8 = undef; $VAR9 = undef;
 $VAR10 = undef; $VAR11 = '330'; $VAR12 = '330'; $VAR13 = '340'; $VAR14
 = undef; 280 280 340 330 330 340

 Thanks for your time and any explanations you can give...
 Shad

Besides the correction that John showed (which is the same as the one
I showed in your CF question), you should also only push onto @data
the tokens that have the required data.

Change:
push @data, $token-as_is;

To:
push @data, $token-as_is if $token-as_is =~ /^k$icao/i;

Also, since you seem to only want the wind direction numbers, the
building of the @wnddir and @times should be done in the sub.  If you
go that direction, I'd build a hash of arrays or possibly a hash of
hashes of arrays.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: want to make a list of all users connected to a network

2007-09-09 Thread Ron Bergin
On Sep 8, 4:52 pm, [EMAIL PROTECTED] wrote:
 How would I make a script that gets a list of all the computer names
 and ip addresses, internal 192.168..., of the computers attached to my
 wired network? Or is there a program that will do this already? Thanks

The program that you're looking for is called nmap.
http://insecure.org/nmap/

There are several Perl modules that can be used to interface with
nmap.
http://search.cpan.org/search?query=nmapmode=all


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: want to make a list of all users connected to a network

2007-09-09 Thread Ron Bergin
On Sep 9, 11:56 am, [EMAIL PROTECTED] wrote:
 On Sep 9, 8:46 am, [EMAIL PROTECTED] (Ken Foskey) wrote:

  On Sat, 2007-09-08 at 16:52 -0700, [EMAIL PROTECTED] wrote:
   How would I make a script that gets a list of all the computer names
   and ip addresses, internal 192.168..., of the computers attached to my
   wired network? Or is there a program that will do this already? Thanks

  Probably a reverse DNS lookup.  I would start with a search.cpan.org on
  DNS.

  --
  Ken Foskey
  FOSS developer

 A reverse DNS lookup would find a name based on an ip address I want
 something that finds all computer names (not login names) on a current
 network. If a good way to do this there is not, then how would I find
 the name of the computer from looking at all ip addresses
 192.168.1.xxx. like how would I know that 192.168.1.105 is comp1 on my
 network?

As long as the name can be resolved via DNS or WINS, nmap will be able
to give you the hostname.
http://insecure.org/nmap/
http://search.cpan.org/search?query=nmapmode=all

Here's an example:

C:\nmap -sP 192.168.0.0/24

Starting Nmap 3.95 ( http://www.insecure.org/nmap ) at 2007-09-09
12:58 Pacific Daylight Time
Host 192.168.0.1 appears to be up.
MAC Address: 00:09:5B:18:81:B0 (Netgear)
Host graphic (192.168.0.2) appears to be up.
Host rt.dev.com (192.168.0.10) appears to be up.
MAC Address: 00:11:5B:55:1E:20 (Elitegroup Computer System Co. (ECS))
Host 192.168.0.128 appears to be up.
MAC Address: 00:20:00:18:16:40 (Lexmark International)


If you want to use a Perl script as a front-end to the nmap command,
you'd want to use the Nmap::Scanner module.
http://search.cpan.org/author/MAXSCHUBE/Nmap-Scanner-1.0/lib/Nmap/Scanner.pm


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Variable $i count a lot numbers...

2007-09-02 Thread Ron Bergin
On Sep 1, 5:03 pm, [EMAIL PROTECTED] (Rodrigo Tavares) wrote:
 Hello,

 I have a problem with  a counter.

 #!/usr/bin/perl

 use strict;
 use warnings;

 print Write a number:;
 my $number= STDIN;

 my @array;
 my $div = $number * 2 ;
 my $i=0;

 while ($div  0)
  {
   $div = $div / 2;
   $array[$i]=$div;
   $i++;
  }

  print Value i is: $i\n;

   print $array[0]\n;
   print $array[1]\n;
   print $array[2]\n;
   print $array[3]\n;
   print $array[4]\n;

 When I run the script:

 Write a number:23
 Value i is : 1081
 23
 11.5
 5.75
 2.875
 1.4375

 Why did script show the value ?

Because you asked it to.

 The counter must be six.

Why would you think that?
Instead of the 5 individual print statements of the array elements,
print the entire array and you'll see why it's not 6.

print $_\n for @array;
print Value i is: $i\n;

Then rerun the script after changing:
while ($div  0)

to this:
while ($div  1)


 Best regards,

   Flickr agora em português. Você clica, todo mundo 
 vê.http://www.flickr.com.br/


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Parsing qmail-qread data

2007-09-02 Thread Ron Bergin
On Aug 31, 6:05 pm, [EMAIL PROTECTED] (Chris E. Rempola) wrote:
 I'm trying to parse qmail-qread data, but don't know how to find the
 number of occurrences after a particular string.  Here is the data:

 +++ Beginning of data +
 28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]

28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
  End of Data ++

 How would I make it look for the (#) sign and count every occurence of
 the word(remote) below it?  So the script would know that
 '[EMAIL PROTECTED]' sent 10 emails and that '[EMAIL PROTECTED]' sent
 5 emails.  Any help appreciated.  Thank you.

 -Chris

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

my $key;
my %remote;

while(my $line = DATA) {
   $key = $1 if $line =~ /#[\d ]+([^]+)/;
   $remote{$key}++ if defined $key and $line =~ /done  remote/;
}
print Dumper \%remote;

__DATA__
28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]

28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Parsing qmail-qread data

2007-09-02 Thread Ron Bergin
On Aug 31, 6:05 pm, [EMAIL PROTECTED] (Chris E. Rempola) wrote:
 I'm trying to parse qmail-qread data, but don't know how to find the
 number of occurrences after a particular string.  Here is the data:

 +++ Beginning of data +
 28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]

28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
done  remote  [EMAIL PROTECTED]
  End of Data ++

 How would I make it look for the (#) sign and count every occurence of
 the word(remote) below it?  So the script would know that
 '[EMAIL PROTECTED]' sent 10 emails and that '[EMAIL PROTECTED]' sent
 5 emails.  Any help appreciated.  Thank you.

 -Chris

I posted this last night about 7:30 but for some reason it doesn't
show up.  Maybe there's something wrong with using groups.google.com
web portal to this group.

For something this trivial, where you're using if elsif blocks that
only contain 1 simple line as shown by others, I prefer to condense it
a little to 2 slightly more complex statements, but are still easily
understood.  I'm sure others here will disagree with my approach.

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

my ($key, %remote);

while( my $line = DATA ) {
   $key = $1 if $line =~ /#[\d ]+([^]+)/;
   $remote{$key}++ if defined $key and $line =~ /done  remote/;
}

print Dumper \%remote;


__DATA__
 28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]

   28 Aug 2007 17:00:47 GMT  #8807850  41428  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]
   done  remote  [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: File::Find

2007-09-01 Thread Ron Bergin
On Aug 28, 10:10 pm, [EMAIL PROTECTED] (Omega -1911) wrote:
 Ha! Here is a snippet that I use on a windows machine. It works!!!

 use File::Find;

 sub rm();
 $count = 0;
 @directories = (F://Hindi/RHTDM);
 find(\rm, @directories);

 sub rm() {
 $count++;
 my ($filename) = $_;
 if ($filename =~ /jpg/) {
   print $count\t$filename\n;
   }
 print \n\n--- ALL DONE---;

I posted a followup to this earlier, but it seams to have vanished, so
I'll post it again with a slight change.  It's just a cleaned up
version.

use strict;
use warnings;
use File::Find;

my @dir = 'F:/Hindi/RHTDM';
my $cnt;

find( sub{print ++$cnt .  $_\n if /\.jpg$/}, @dir);
print \n\n--- ALL DONE---;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: File::Find

2007-09-01 Thread Ron Bergin
On Aug 28, 10:10 pm, [EMAIL PROTECTED] (Omega -1911) wrote:
 Ha! Here is a snippet that I use on a windows machine. It works!!!

 use File::Find;

 sub rm();
 $count = 0;
 @directories = (F://Hindi/RHTDM);
 find(\rm, @directories);

 sub rm() {
 $count++;
 my ($filename) = $_;
 if ($filename =~ /jpg/) {
   print $count\t$filename\n;
   }
 print \n\n--- ALL DONE---;

Here's a cleaned up version:

use strict;
use warnings;
use File::Find;

my @dir = 'F:/Hindi/RHTDM';
my $cnt;

find( sub{++$cnt and print $cnt $_\n if /\.mp3$/}, @dir);
print \n\n--- ALL DONE---;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/