Re: 1-line text file with numbers, need to add to them

2010-02-05 Thread Frank
For instance, the below is your data file --data.txt
12~s1~s314~s5677~s899~s0~s
Here are the codes:

#!/usr/bin/perl
open(DATA,"data.txt");
while() {
  $number=$_;
 # print $number;
  while ($number =~ /([0-9]+)~s/g){
printf ("%d\n","$1");
  }
}
close(DATA);


On Feb 4, 7:27 am, cacogg...@gmail.com (Chris) wrote:
> I need some help with this problem.
> I've got a text file datafile with 1 line of data comprised of 30
> different numbers delimited with ~s.
>
> I need to open this file, grab this line of data, split it into
> individual numbers, perform some simple math (addition) on each
> number, and then put the new values back into the datafile, replacing
> the original data that was there.
>
> I have tried for two days to figure out what I'm doing wrong, but I
> keep getting "needs a package name" errors for every variable
> nomenclature I try to work with. I've declare arrays and variables
> until my fingers are numb and nothing is working. I'm using Perl 5.008
> if that matters.
>
> Can somebody please help?


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




Re: 1-line text file with numbers, need to add to them

2010-02-05 Thread Frank
On Feb 4, 4:35 pm, jwkr...@shaw.ca ("John W. Krahn") wrote:
> Chris wrote:
> > I need some help with this problem.
> > I've got a text file datafile with 1 line of data comprised of 30
> > different numbers delimited with ~s.
>
> > I need to open this file, grab this line of data, split it into
> > individual numbers, perform some simple math (addition) on each
> > number, and then put the new values back into the datafile, replacing
> > the original data that was there.
>
> perl -i.bak -pe's/(\d+)/ $1 + 3 /eg' yourdatafile
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity.               -- Damian Conway

For instance, the below is your data file--- data.txt.
12~s1~s314~s5677~s899~s0~s
Here is the codes:
#!/usr/bin/perl
open(DATA,"data.txt");
while() {
  $number=$_;
 # print $number;
  while ($number =~ /([0-9]+)~s/g){
printf ("%d\n","$1");
  }
}
close(DATA);



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




a problem about GD

2005-05-09 Thread Frank
Sorry if my question is stupid or too simple.  I have google the answer 
but got too much information

I test my GD module to check whether it can be used since there are too 
many errors when install GD.

the test program is copied from a website:
**
#!/usr/bin/perl -w
use strict;
use GD;
use GD::Graph::linespoints;
print "Content-type: image/png\n\n";
my @data = ( [qw(Jan Feb Mar April May June July August Sep)],
[undef, 52,53,54,55,56,undef,58,59],
[60, 61,61,undef,68,66,65,61,undef],
);
my $chart = GD::Graph::linespoints->new(700,500);
$chart->set_x_label_font("/apile/AVBKV.TTF",10);
$chart->set_y_label_font("/apile/AVBKV.TTF",10);
$chart->set_x_axis_font("/apile/AVBKV.TTF",10);
$chart->set_y_axis_font("/apile/AVBKV.TTF",10);
$chart->set_title_font("/apile/AVBKV.TTF",16);
$chart->set(
  x_label   => 'Month',
  y_label   => '# Sell',
  title => 'First three quarters, 2000',
  y_long_ticks  => 1,
  markers   => [1,5],
  marker_size   => 8,
  line_types=> [4,1],
  line_width=> 3,
);
$chart->set_legend('outlet 1', 'outlet 2');
my $gd_object = $chart->plot([EMAIL PROTECTED]);
#make sure we are writing to a binary stream
binmode STDOUT;
# Convert the image to PNG and print it on standard output
print $gd_object->png;

When I run the program, it said:
***
Can't load 
'/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/auto/GD/GD.so' 
for module GD: libgd.so.2: cannot open shared object file: No such file 
or directory at 
/usr/lib/perl5/5.8.6/i386-linux-thread-multi/DynaLoader.pm line 230.
at test-GD.pl line 5
Compilation failed in require at test-GD.pl line 5.
BEGIN failed--compilation aborted at test-GD.pl line 5.


I check with CPAN by "perl -MCPAN -e shell"
cpan> install GD
GD is up to date.
cpan> r GD
All modules are up to date for GD
***
I have updated the following package accrording to the README of GD module:
freetype-1.3.1.tar.gz 
gd-2.0.33.tar.gz 
jpegsrc.v6b.tar.gz 
libpng-1.2.8.tar.bz2 
zlib-1.2.2.tar.gz

What I can do now?  many thanks!! please also recommend some useful 
books or website for me to learn how to produce figure with perl, thanks.


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



Re: a problem about GD

2005-05-13 Thread Frank
Thanks, Zentara,
The problem was fixed.

zentara wrote:
On Tue, 10 May 2005 12:31:34 +0800, [EMAIL PROTECTED] (Frank) wrote:
 

Sorry if my question is stupid or too simple.  I have google the answer 
but got too much information

I test my GD module to check whether it can be used since there are too 
many errors when install GD.
   

What errors did you get?
 

When I run the program, it said:
***
Can't load 
'/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/auto/GD/GD.so' 
for module GD: libgd.so.2: cannot open shared object file: No such file 
or directory at 
/usr/lib/perl5/5.8.6/i386-linux-thread-multi/DynaLoader.pm line 230.
at test-GD.pl line 5
Compilation failed in require at test-GD.pl line 5.
BEGIN failed--compilation aborted at test-GD.pl line 5.


I check with CPAN by "perl -MCPAN -e shell"
cpan> install GD
GD is up to date.
cpan> r GD
All modules are up to date for GD
***
I have updated the following package accrording to the README of GD module:
freetype-1.3.1.tar.gz 
gd-2.0.33.tar.gz 
jpegsrc.v6b.tar.gz 
libpng-1.2.8.tar.bz2 
zlib-1.2.2.tar.gz

What I can do now?  many thanks!! please also recommend some useful 
books or website for me to learn how to produce figure with perl, thanks.
   

I would say to download the latest source for the GD perl module, and
make it yourself.  If it makes properly with
perl Makefile.PL
make 
make test
make install

and your test program dosn't run, post again and tell us what the error
is.


 


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



how to get data from an array

2005-05-15 Thread Frank
Hi, all,
  I am a newbie for perl. I am learning perl for my biological data 
analysis.  Now, I have a data look like this:

>I do not need-1
.(dots mean data here)
.
.
>I do not need -2
..
.
>What I need-1
.
...
.
.
>what I need-2
..
...
...
>>I do not need-3
.
..
...
...
Because there are more than 20,000 items of "what I need" in the source 
file.  I need write a perl script to extract all the items of "what I 
need" and their data. That's means, I need produce a file contains all 
the following data:

>What I need-1
.
...
.
.
>what I need-2
..
...
...
My program is like this, I do not know how to get the data below the 
">what I need-*".  Can you kindly give me some suggestions?

#!/usr/bin/perl -w
use strict;
my $outfile = "test..res";
my $infile= "Source_data";
my @source;
my $line;
open INPUT, "$infile" or die "can not open $infile";
open OUTPUT, ">$outfile" or die "can not write $outfile";
@source = ;
foreach $line(@source){
if ($line =~ /What I need/){
print OUTPUT "$line";
..?..
..?
}
}
close INPUT;
close OUTPUT;   

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



How to get the numeric index of a element in an array

2005-05-15 Thread Frank
Hi, all
If i know the element of array, can I get the numeric index  of this 
element?

Thanks
Frank
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to get the numeric index of a element in an array

2005-05-15 Thread Frank
Ing. Branislav Gerzo wrote:
Frank [F], on Sunday, May 15, 2005 at 19:45 (+0800) typed:
F> If i know the element of array, can I get the numeric index  of this
F> element?
Exist a way, but it is better using hash. In arrays you have to
iterate over every element.
 

~~~Pls tell me the way. possibly I need use it. I need get the 
elements from an array after some specific element. Say, I find a 
elements contains the word I want by regular expression ($_ =~ /word1/), 
and then I need get the following element untill another words appears 
($_ =~ /word2/). I thought the best way for me is to get the numeric 
index of the elements and get the elements i want. Do you have any 
suggestions?

  
 

Thanks,
Frank

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



Re: How to get the numeric index of a element in an array

2005-05-15 Thread Frank
Thanks Octavian,   I do need analyze element by element.  but the 
problem for me is  like this

my @array = (
">blue"
"sky"
"skirt"
"sea"
">white"
"paper"
"flower"
">red"
"face"
"flower"
">green"
"grand"
"tree"
)
Say, I need get all elements after ">white" before ">red". Be notice, 
any new color begin with ">",  so, I think I can

my $element;
foreach ($element(@array)){
if ($element =~ /white/){
# find the element contains word "white" and print it;
print "$element";  
my $index = /numeric index of $elements/;
my $n = 1;
if ($array[$index+$n] =~ /!^>/){
# get the nex element by numeric index and check whether it begins with 
">", if not, print it;
print "$array[$index+$n]"; 
$n +=1;
}else {
# if the element begins with ">",  end the loop
last;
}
}
}

But I do not how to get the numeric index of $elemnet.Or is there 
any other way to jump into next element?

 any suggestions are appreciated!
Frank
Octavian Rasnita wrote:
Hi,
Let's say you have the following array:
my @array = (
'blue',
'white',
'red',
'blue',
'green',
'blue',
);
And let's say you want to get the index for the 'blue' element.
I guess it is obvious that you need to analyse element by element, in order
to be able to find if that array contains dupplicates and if you will find
dupplicates, you might need to return a list of indexes.
foreach(@array) {
if ($_ eq 'blue') {
#do something
}
}
Teddy
- Original Message - 
From: "Frank" <[EMAIL PROTECTED]>
To: "Ing. Branislav Gerzo" <[EMAIL PROTECTED]>
Cc: 
Sent: Sunday, May 15, 2005 6:34 PM
Subject: Re: How to get the numeric index of a element in an array

 

Ing. Branislav Gerzo wrote:
   

Frank [F], on Sunday, May 15, 2005 at 19:45 (+0800) typed:
F> If i know the element of array, can I get the numeric index  of this
F> element?
Exist a way, but it is better using hash. In arrays you have to
iterate over every element.
 

~~~Pls tell me the way. possibly I need use it. I need get the
elements from an array after some specific element. Say, I find a
elements contains the word I want by regular expression ($_ =~ /word1/),
and then I need get the following element untill another words appears
($_ =~ /word2/). I thought the best way for me is to get the numeric
index of the elements and get the elements i want. Do you have any
suggestions?
   

 

Thanks,
Frank

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


 


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



Re: How to get the numeric index of a element in an array

2005-05-16 Thread Frank
Hi, thanks all!   I have solve my problem.   But I have another question 
now,

How to determin whether I reach the end of file  in Perl program?   Also 
, can you tell me where I can get these informations .  I scan the 
"programing perl " by Larry Wall,  But it is diffculty to find what I 
want from such a cyclopaedia.

Thanks
Frank
bright true wrote:
hello ,
 
you can do something like the following
 
my $counter = -1;
foreach (@array){
$counter++;
if($_ =~m/$word/){
print "Element ID is $counter";}
}

 
On 5/15/05, *Frank* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

Ing. Branislav Gerzo wrote:
>Frank [F], on Sunday, May 15, 2005 at 19:45 (+0800) typed:
>
>F> If i know the element of array, can I get the numeric
index  of this
>F> element?
>
>Exist a way, but it is better using hash. In arrays you have to
>iterate over every element.
>
>
~~~Pls tell me the way. possibly I need use it. I need get the
elements from an array after some specific element. Say, I find a
elements contains the word I want by regular expression ($_ =~
/word1/),
and then I need get the following element untill another words appears
($_ =~ /word2/). I thought the best way for me is to get the numeric
index of the elements and get the elements i want. Do you have any
suggestions?
>
>
>
Thanks,
Frank
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
<http://learn.perl.org/> <http://learn.perl.org/first-response>


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



Re: How to get the numeric index of a element in an array

2005-05-16 Thread Frank
Thanks!  Mr. Clarkson's  program really works.  but because my array 
(data) is more complex. So I made an adjustment but it did not work very 
well.

BTW: John W. Krahn suggested I can change  Input Record Separator, it 
does work and help me to solve the problem!   But I just wonder why the 
following program can not work very well and what's wrong with it!.   
Thanks very much!

# there is a  trailing record separator "\n" at end of every elemnet
my @items = qw(
   >blue
sky
skirt
sea
   >common_white
   paper
   flower
   feather
   >red
face
flower  
   >milk_white
   milk
   ivory
   >green
   grand
   tree
);

my $after_white;
foreach my $item ( @items ) {
$after_white = 1 if $item =~ /white$/;
   if ( $after_white ) {
   print "$item\n";
   next if $item =~ /^>/;
   $after_white = undef;
   }
}
__END___
The results given like this, it seems the loop works only for one time
>common_white
paper
>milk_white
milk

:-)THANKS
Charles K. Clarkson wrote:
my @items = qw(
   >blueskyskirtsea
   >white   paper  flower   >red
   face flower >green   grand   tree
);
my $after_white;
foreach my $item ( @items ) {
   if ( $after_white ) {
   last if $item =~ /^>?red$/;
   print "$item\n";
   }
   $after_white = 1 if $item =~ /^>?white$/;
}
__END__
HTH,
Charles K. Clarkson
 


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



a question about print in array

2005-05-24 Thread Frank

I met an interesting problem recently and am expecting your kind advice.

my input file (for_test)  is like as follows.   I wish add a ">"  to the 
first line (before the word blue) and remove ">" at the last line.


# ---begining of the file, this line is not included in the file---#
blue
sky
skirt
sea
>white
paper
flower
mine
>red
face
flower
>milk_white
milk
ivory
>green
grand
tree
>
#___END,this line is not included in the file__#

my program is as this :

# to add the > to the first line and remove > at last line

#!/usr/bin/perl -w
use strict;

my $infile = for_test;

open (INPUT, "$infile") || die " can not open $infile";
open OUTPUT, ">test.res" ||die "can not open test.res";

my @items = ;

my $item = ">$items[0]";
shift (@items);
unshift (@items, $item);
pop (@items);
chomp ($items[-1]);
print OUTPUT "@items\n";

close OUTPUT;
close INPUT;
#___END_#



After execute the program.  The result was not as what I expected since 
the ">" add a new column at the left side. 

Iin the first line ">blue" ,  ">" is added by the program.  But it also 
add a new column to the file at the left side.  This is not what I 
expected becuase this also add a space to  other element at the left 
side when print it. 



>blue
 sky
 skirt
 sea
 >white
 paper
 flower
 mine
 >red
 face
 flower
 >milk_white
 milk
 ivory
 >green
 grand
 tree





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




Tk::FontDialog

2002-03-29 Thread frank

Hi. I' m trying to use the Tk::FontDialog package. I' ve installed and the only 
documentation i colud find is this:

use Tk::FontDialog;
$font = $top->FontDialog->Show;

This just doesn' t work. I get this message from perl:

wrong # args: should be "font actual font ?-displayof window? ?option?" at 
c:/Perl/site/lib/Tk/Submethods.pm line 19.

Can anyone help me, maybe just writing a short sample program that uses 
Tk::FontDialog? Thank you very much



Re: thanks for the info on removing control m's

2001-12-06 Thread Frank

On Thu, Dec 06, 2001 at 08:21:30AM -0600, Booher wrote:
> I am wondering how you would use the VB equivalents of Left$ and Right$ with
> perl.

TIMTOWTDI:

index, rindex are functions that do the same.

more graceful? are regexes using anchors ^ for the start or $ fro the
end. ie.  /^\w{3}/ or /\w{3}$/

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Regex help

2001-12-07 Thread Frank

On Fri, Dec 07, 2001 at 02:09:25PM +0100, Jorge wrote:
> I have this line in a file :
> host clin09 {
> hardware ethernet 00:80:9F:2E:3F:5E

Is this all on one line or is it two, it looks like two here.

if it's two either set $/=undef; to slurp all the lines in the file 
into one scalar variable ($) or set a flag to say I've got host, next
line should have /hardware ethernet/ in it.

A regex you could use is:

/hardware ethernet / && $MAC_ADR= $';

this checks to match the contents of the line to "hardware ethernet "
and sets MAC_ADR to the remainder of the line after the match.

This has an overhead since using $&,$` or $' in one regex means they're
populated on ALL subsequent regexes, also true of $1..$9 an alternative
is to use negative lookbehinds or even just plain old:

$line =~s/hardware ethernet //;$MAC_ADR=$line;
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: System COmmand's in Perl

2001-12-07 Thread Frank

On Fri, Dec 07, 2001 at 07:59:53AM -0500, Craig wrote:
> system "tail -f /var/log/messages";
> 
> or
> 
> exec "tail -f /var/log/messages";

or

`tail -f /var/log/messages`

Although this won't fork your program and -f means it follows the file
updates.

For this you can use the CPAN module File::Tail

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Finding 'probable' duplicate records

2001-12-07 Thread Frank


perhaps:

use Digest::MD5

or check out the Guttman Rosler transform:
http://raleigh.pm.org/sorting.html

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: renaming files - fatuous newbie query

2001-12-07 Thread Frank

On Fri, Dec 07, 2001 at 11:41:05AM -0500, McCarney, wrote:
> Ok team, here's the deal. 
> I am *not* a programmer or a sysadmin, so be gentle. ;)
> 
> Here is the code--checked it out in perldoc -q. Wow, it works...
> My platform: Windows 2000
> 
> #! perl -w
> use strict;
> use File::Copy;
opendir (I,'somedir') or die "Ack $!\n";

for (grep{ /nm.*\.html/ }readdir I){
s/\..*//; # remove suffix
> move("$_.txt", "$_.txt");
}
> 
> That's great, but I have umpteen scores of files that are named nm*.html and
> nm*.gif.

You want to change the names of gifs too? 
grep /nm.*\.(gif)|(html)/

for recursing dirs try Find::File

> Stumped and need some advice please...
> BTW: I get the list in digest format, so if you do reply please 'cc' me.

Noted ;0)

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: help with reading a txt file

2001-12-10 Thread Frank

On Mon, Dec 10, 2001 at 08:12:42AM -0800, Lance wrote:
> If I want to read through a text file and parse out the information in order
> to sort or compare data how would I begin to tackle this task?
> 
> I understand logically how I it would work just not sure how to do it in
> perl.
---end quoted text---

open I, 'somefile.txt' or die "Cannot open somefile $!\n";
@_=;
# @_ now contains all the lines from somefile.txt 
# to change the record delimiter change $/ to the required value
# the default is $/="\n";

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Shift and "=>"

2001-12-17 Thread Frank

On Mon, Dec 17, 2001 at 11:36:30AM +1000, Lorne wrote:
> I don't understand this line..
> 
> $session = Net::SNMP->session(-hostname => "10.0.0.100", -community =>
> "public");

The parameters are a hash: -hostname=>'10.0.0.100' is the same as:
'-hostname','10.0.0.100'... 

so you could pass:
$session = Net::SNMP->session('-hostname','10.0.0.100','-community','public');

and SNMP->session would be none the wiser, however => makes the
parameters more legible to users.

The variables are read into the array  @_ as soon as they get into a
function. then to render it useful and allow the params to be passed in
any order, it'll do something like this:

%_=@_;

now parameters can be accessed like this =
print "hostname: $_{-hostname}\n"; # NB " used here since I interpolate.

> Particularly, the way data is presented to the function..
> 
> I.E : -data => "text"

an advantage of => is that data to the left of it is wrapped in quotes, 
so you don't have to.

The - prefix means it's a private variable, IIRC. meaning people who
feel the need to alter this value after creating the object have been
given due warning that the Author is no longer responsible for your
actions, if you need to alter these values do it through the (Mutator)
methods provided.

> Also, why the use of the "shift" as in:
> (from the original example)
> 
>($session, $error) = Net::SNMP->session(
>   -hostname  => shift || '10.0.0.100',
>   -community => shift || 'public',
>   -port  => shift || 161
>);

Using || in such examples is a bit of a gamble, due to the low
precedence of , and ||. 

What you appear to be doing is saying you should have 3 variables,
in the absence of 1 you will not have any of the following either.

So the permutations you expect are:

hostname, community, port
hostname, community
hostname
none

perhaps better to establish your parameters before calling:

# Set up defaults.
my %params= ( -hostname=>'10.0.0.100', -community=>'public', -port=>'161');

# Based on params repopulate the hash.
for (0..$#_){ # @_ is the array of passed params or @ARGV for commandlines
$params{ (qw/ -hostname -community -port )[$_] } = $_[$_];
}

If you are running this from the commandline, consider using GetOptions,
if not consider using a hash as SNMP does, it's good practice.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: ARGV

2001-12-18 Thread Frank

On Mon, Dec 17, 2001 at 10:31:43PM -0600, Michael wrote:
> I cant seem to get the ARGV to work right via web I get not found error but
> it works via command line. whats the trick?
> 
> It works if I do this get_file.pl test1.txt test2.txt
> 
> but it wont work via http://www.host.com/cgi-bin/get_files.pl test1.txt
> test2.txt
---end quoted text---

For CGI stuff, best to use CGI.pm and in particular:

$q = new CGI;
$foo = $q->param('foo');

otherwise you'll need to handle GET and POST methods and a raft of stuff
that people obviate by using CGI to save time and reinventing the wheel.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: STDIN Formating

2002-01-03 Thread Frank

On Sat, Dec 08, 2001 at 04:22:44PM +0800, Hubert wrote:
> Hello,
>  Say I have I loop 
> while ()
>  {
> print ..
>  }
> Is there a way for me to format whatever values/text are in STDIN so 
>that I can just select which lines to print?
> 
> Thanks
> Hubert
>
---end quoted text---

what input values do you get?
Which values do you want to keep?
What do you want the values to look like?

The reason I ask is Perl covers a lot of things, and better
understanding of the context of your question will help us
to answer it.

hth.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: split, ignoring spaces

2002-01-09 Thread Frank

On Wed, Jan 09, 2002 at 03:55:38PM +0100, Jon wrote:
> but it will also split on \n,\t so / +/ would be better if it's just
> space you wanna split on
---end quoted text---

Check out the default settings for split ;-)

ie.

use Data::Dumper
$_="mary  had   a littlelamb";
@_=split;
print Dumper \@_;


it'll give you what I think you want:

$VAR1 = [
 'mary',
 'had',
 'a',
 'little',
 'lamb'
];

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: hiding file data

2002-01-09 Thread Frank

On Tue, Jan 08, 2002 at 07:26:42PM +, Stuart wrote:
> Hi All,
> 
> I have a few perl files that I need to send out to a client. However, we do 
> not want them seeing what are in the files for obvious reason. Is there any 
> way that I can hide the info in the files, or should I creat an executable.
---end quoted text---

Hi Stuart,

Are you saying that there is sensitive data enclosed in the file like:

$database='deepthought';
$password='l3tm3In'; 

Say for use with databases that your company owns?


If there is sensitive data like this, consider using a seperate file to store
the settings in and then encrypting it using a standard Perl module from CPAN,
(http://www.cpan.org/ it's where we share the fruits of our labour ;) something
like DES cyphers should be more than adequate. Or roll-yer-own, I worked
in a S/W house that used rot 13 of all things, something like:

tr/a-nm-zA-NM-Z/m-za-nM-ZA-n/;

should replicate that but I'd not recommend it.


If the Perl code itself is what you want to conceal then consider:

1) Perl is open source, so anything written with it should be too.
Check the legality, I've never written Perl code to resell so
don't know.

2) Having source code viewable to all, means it has to be secure in
better ways. Remember "obscurity is not security". If you compiled
the code people could still strace it and see what you were doing.

3) Owning software is bad mmmkay; better to make it open-source
and let others test/debug/submit patches to make robust code at
the slight cost of not being able to charge for the code, just
the support and development time.

A metric of this is Red-Hat (I don't like RH but it's an example):
when Red-Hat 7.0 was release several thousand bugs were logged by
users, within a fortnight almost all were resolved: compare that
to the rate of bug-fix in Windows. The trick is users were submitting
fixes.

>From your post I assumed the former (hiding sensitive data) was what you wanted
and the latter is redundant, from the replies it seemed people thought you meant
the latter. I'm hoping it's a misunderstanding.

Randal's book "Learning Perl" deals with seperating config data. For
rolling your own cyphers to encrypt stuff, you'll need something like
"Algolrithms in Perl" or to trust CPAN.

All the best.   

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: ^M's in file

2002-01-09 Thread Frank

cat file | perl -pe 's/\r//' > foo

should work
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: foreach, while and flipping $_ !!!!!

2002-01-09 Thread Frank

On Wed, Jan 09, 2002 at 05:05:34PM -, Parker, wrote:
> Hi all,
> 
> I have an array of filenames.
> 
> I want to read through each of the files.
> 
> I want to try and match a word at the beginning of the line, if the word is
> not matched, I want to display an error and stop processing.
> 
> SO...
> 
> 
> foreach @array_of_files
> {
>   unless (-r $_ && -w $_)
>   {
>   print"***Error : Cannot find file $_\n";
>   }
>   OPEN(FILE, $_) or die etc...
>   while ()
>   {
>   /^\b$word\b/ && $wordfound++;
>   }
>   close (FILE);
>   unless ($wordfound)
>   {
>   print"*** Error : word not found in file $_\n";
>   }
>   $wordfound = 0;
> }

> Oh, and if anyone can suggest any 'better' ways of doing the above, please
> let me know.

$/=undef; # slurp mode

for (@array_of_files) {

my @wordfound =();

print"***Error : Cannot find file $_\n" unless -r && -w;

open(FILE, $_) or die "$_:$!\n";
my $file_contents =; # get all the file

@wordcount = ($file_contents =~/^\b($word)\b/g);
close (FILE);

print"Word found $#wordfound times in file $_\n";
}
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: foreach, while and flipping $_ !!!!!

2002-01-09 Thread Frank

On Wed, Jan 09, 2002 at 05:26:41PM +, beginners wrote:
 1>$/=undef; # slurp mode
 2> 
 3>for (@array_of_files) {
 4> 
 5> my @wordfound =();
 6> 
 7> print"***Error : Cannot find file $_\n" unless -r && -w;
 8> 
 9> open(FILE, $_) or die "$_:$!\n";
10> my $file_contents =; # get all the file
11> 
12> @wordcount = ($file_contents =~/^\b($word)\b/g);
13> close (FILE);
14> 
15> print"Word found $#wordfound times in file $_\n";
16>}
---end quoted text---

Ack, I forgot to explain that :(

1. unsets the record seperator variable (usually "\n") so there's no
need to loop for each line, smart for small files / dumb for really big
files.

3. Removing the While loop means I can still use $_, although Japhy is
right in what he says.

5. The array I use is locally scoped so is flushed every loop, I
initialise it to stop complaints if using -w.

12. using () in a regex puts the values in $1-$9 and returns each item
matched to an array (@wordcount).

15. $#wordcount returns the number of the last index in the array not
the number of elements ( so 4 elements $#wordcount = 3 IIRC ) so that
needs a check like defined $wordcount[0] to check that there is at least
one match.

It's just another way, it's not better for all instances.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Regexp and lower case

2002-01-10 Thread Frank

On Thu, Jan 10, 2002 at 10:38:50AM +0100, Jorge wrote:
> Hi, I have this:
> if (/hardware ethernet /) {   
>   $_=(split/\{/)[1];  
>   s/[^\d:A-F]//g; # remove anything not 0..9,A..F 
>   #print "$_\n";
>   
>   }
>   
> It works but I dont want to remove th eletter between a-f if it is in lower 
> case.
> How can I do to have the upper and th elower case.
> Thanks
>   
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
---end quoted text---
how about s/[^\d:A-Fa-f]//g ?
or s/[^\d:a-f]//ig ?

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: excluding comments in a line

2002-01-14 Thread Frank

On Mon, Jan 14, 2002 at 12:44:34PM -0500, Yacketta, wrote:
> Folks,
> 
> I am reading in a .cfg file and exclude comments (#) and spaces at the
> beginning of the line
> how would I lop off any comments in a line?
> 
> IE:
> 
> Key "value" # comment here
---end quoted text---

while(){
next if /^\s*(#.*)?$/;  # Skip it if just comment or blank
s/#.*$//;   # remove comments
($key,$value)=split/\s+/,$_,2; # Get exactly two values out
$config{$key}=$value;   # Load into a hash for use.
}

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: silly beginners problem :)

2002-01-15 Thread Frank

On Tue, Jan 15, 2002 at 06:23:28PM +0100, Martin wrote:
> im trying to make a script to read a textfile with the following format:"
> 
> TITLE
> Welcome to Carcinoma in Situ
> 
> "
> i want my script to recognice the TITLE tag and save the following line(s) in $TITLE:
> 
> heres what i have done:
> 
> while (<>) {
>   chomp;
>   if (/TITLE\s*([A-Za-z]+)/) {
>  $TITLE=$1;
>   }
> }
> print $TITLE;
> 
> upon script textfile.txt > outputfile i get this error:
> Use of uninitialized value in concatenation (.) or string in line (the one with 
>print $TITLE in it)
> 
> i think my regex is not doing what i want it to do??? why?
---end quoted text---

$/ is the record delimiter. It's default is "\n". Each line will be read
in thus:

line1: TITLE\n
line2: Welcome to Carcinoma in Situ\n

so your loop will say :
line1: yup got TITLE, um no later match for regex :( so $1 is unset.
line2: nope it doesn't match.

either set $/ to undef
or set a flag in the loop when the regex is matched and clear it when a
value is added:

while (<>){
if ($next_line_is_title) { # this line is a title
chomp;
$TITLE=$_;
$next_line_is_title=0;
}
/TITLE/ and $next_line is title;
}

HTH.
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: 2 simple questions - update:

2002-01-15 Thread Frank

On Mon, Jan 14, 2002 at 10:45:35PM -0600, Chris wrote:
> On the path issue:
> 
> What I need to do is to verify if a specific directory  exists in the 
> current directory:
> 
> if exists($PWD/ThisDir) then
>print "WH00T"
> End If
---end quoted text---

$_='/home/frank/';
print "foo" if -e "$_/todo"

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Maintaining a Cache of Hash References

2002-01-15 Thread Frank

On Tue, Jan 15, 2002 at 11:41:28AM -0600, Tomasi, wrote:
> I'm trying to maintain a cache of hashes to reduce database hits.  What I
> want is to determine if I've retrieved the data from the DB before, if so,
> just pass back the copy of information used last time, otherwise read it
> from the DB and make a note of it.  It would seem I'm not copying the
> information in to the $user arg properly.  Something like this:
> 
---end quoted text---

There is the Memoize module that caches the results of a function

sub somefunc {
# hit db
return $results;
}

use Memoize;
memoize('somefunc');

IIRC it then seemlessly caches in the background, for DB stuff also
checkout the expiring caches, in case values change in the DB.

Documentation here: 
http://theoryx5.uwinnipeg.ca/CPAN/data/perl/Memoize.html

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Random Access Numbers

2002-01-17 Thread Frank

On Wed, Jan 16, 2002 at 10:25:35PM +, Naveen wrote:
> Is there is a built in function in Perl for generating random access #s?
> 
> How would that function be used?
---end quoted text---

I've just google'd "Random access numbers" and there is very little
there. Nothing that seems related to any of the other articles. 

Could you explain what you mean by Random Access Numbers and what you
want them to do in your program?

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Regex Assistance

2002-01-17 Thread Frank

On Thu, Jan 17, 2002 at 05:42:31PM -, John wrote:
> -- code --
> my ($name, $ext) = split(/\./,$fileoutname);
> 
> if ($name =~ /\((\d{1,1})\)$/) { # Looks for (1) on the end for example
> my $number = $1;
> $number++;
> $name =~ tr/\(\d\)/\($number\)/;
> } else {
> $name .= "(1)";
> }
> 
> $fileoutname = "$name\.$ext";

> my ($name, $ext) = split(/\./,$fileoutname);

Is this on windows? Or could you have name.some.more.ext?


my $num= ($name=~/\((\d+\)/)?$1:1;
$num++ while(-e "$name($num).$ext");


Is a bit more robust as it checks the directory and loops till it
doesn't find a match for the file. IMO FWIW ;)

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Regex Assistance

2002-01-17 Thread Frank

On Thu, Jan 17, 2002 at 06:16:08PM +, Frank goofed:
> my $num= ($name=~/\((\d+\)/)?$1:1;
> $num++ while(-e "$name($num).$ext");
---end quoted text---

Ah, forgot to paste the tested version back in my bad.

#!/usr/bin/perl
use strict;

my($name,$ext)=('test','foo');

my $num= $name=~/\((d+)\)/?$1:1;# get number or make it 1.

$num++ while -e "$name($num).$ext"; # while the file exists incr num

open O,">$name($num).$ext"; # Make shiny new file.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: How to make it more perlish

2002-01-18 Thread Frank

On Fri, Jan 18, 2002 at 11:39:11AM +0100, Jorge wrote:
> Hi, I have this piece of code and i wanted to simplify it and make it more 
> perlish.
> thanks

Ok, 
Howabout?
Use an array for the items.
Making the code more scalable by replacing each call with a loop?

my @PROG=(
"c:\\OXE\\cygwin\\bootp\\linux\\$_Globals{LX_VERSION}",
'c:\\OXE\\cygwin\\bootp\\linux\\install', 'etc...');

my @LINK=qw(the same idea);

for (0..$#PROG){
system ($LINK[$_]) unless -e $PROG[$_]
}


-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: $~ ?

2002-01-21 Thread Frank

On Sat, Jan 19, 2002 at 11:40:14PM +0800, yun wrote:
> I found in perl samples many strange signs, I'm really
> confused by them and the study process is seriousl
> blocked, would you like to recommend some good method
> to pass this basic step? some quick lookup or some
> common-used cmd? Thanks a lot!
---end quoted text---

The best advice I can give is :
1) perldoc perlvar
2) go out and buy the perl pocket reference from oreilly, it's good. 

btw $~ is a rarely used variable for Perl formats ( part of Perl's
reporting past, that people rarely use these days) it's more than
likely to be someone refusing to declare a variable when there is one
free to bend to their use.

However that said, they might be using formats; look for lines like:
1) write .
2) format somename= 

I like formats, but I'm in a minority ;)

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: object orientation :- please help

2002-01-21 Thread Frank

On Sat, Jan 19, 2002 at 04:23:38AM +, padu wrote:
> I am newbie at Perl.
[snip]
> Is it anyway possible to Extend the above program with
> constructors for rectangle and circle and a
> non-virtual function "move" to change the reference
> point of any of these objects.  
> 
> Can anybody help me with it..
---end quoted text---

Simple answer is "yes", however writing Perl OO is um...
1) Easier than writing OO in Java
and
2) Harder than writing OO in Java

For a start read:

perldoc perlobj
perldoc perlboot
perldoc perltoot
perldoc perltootc
perldoc perlbot

and for the hardcore:
perldoc perltie

An excellent book on the subject is "Object Oriented Perl" by Damien Conway.

Without detracting from my fondness of Perl, it's not an OO language in
as much that OO is immediately easy to do, and things like inheritance
and polymorphism have to be handled. All the best.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Count Words

2002-01-22 Thread Frank

On Tue, Jan 22, 2002 at 07:39:31AM -0800, Peter wrote:
> If we accept the set of word characters as being defined by \w, your 
> problem can be solved with this code:
> 
> my %word;
> while (<>) {
>   $word{$_}++ for /(\w+)/g;
> }
---end quoted text---

Not to forget Perls default settings for split (the same as \w+).

while(<>){
$_{$_}++ for split;
}

(It saves about 1 CPU Second for 9 iterations on my laptop YMMV).

This saves the price of using regex and especially () matches, since
once summoned Perl'll generate $1..$9 for all subsequent regexes, regardless
of if they're needed. 

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Count Words

2002-01-22 Thread Frank

On Tue, Jan 22, 2002 at 12:47:02PM -0500, Jeff wrote:
> [Peter: what does "Aspirat primo Fortuna labori" mean?  I've gotten a
> partial translation, but I'm not satisfied with it.]

It means "Fortune favours your first effort".. Mia Culpa

> Yours does not match the same "words", though.  Peter's code matches the
> words `words' and `though', whereas yours would match `"words",' and
> `though.' -- the punctuation makes all the difference.

Granted and I should have read the post a bit better before responding,
although it may be cheaper to remove the punctuation and drop the case
to get a better word match. I like regexes, but sometimes the alternatives
are worth considering.

> A thorough word-regex might be needed here, but let's not get into that.

I'll shut up then ;)

> >This saves the price of using regex and especially () matches, since
> >once summoned Perl'll generate $1..$9 for all subsequent regexes, regardless
> >of if they're needed. 
> 
> Not true.  You are confusing $1, $2, etc., with $& and friends.  If you
> use $& once, Perl will prepare it for every regex.  $1 incurs the same
> penalty, but only for the regex it is generated from.

Cool, this I did not know. That's five things I've picked up from this
list today (2 from this post)

> I can give you a more thorough explanation of this (or probably any
> other) regex query if you'd like.

Great! How does this work?

$|=1;
$_=1;
(1x$_) !~ /^(11+)\1+$/ && print "$_\n"  while $_++;

-- 
 Frank Booth - node 7824. 

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




Re: Help with file

2002-01-24 Thread Frank

On Thu, Jan 24, 2002 at 11:59:05PM +1100, Stuart wrote:
> Hi
> Please help if you can.
> Kind Regards
> Stuart Clark
>  
>  
> How do I make the number between the "a" and the "z"  take up 10
> positions within the line by adding zero's in front. 
> The numbers between the "a" and "z" are not always the same length but
> they always start at the 24th position in the line.
>  
> # start of file test
> 3034364717283459322a15.32zM042001H
> 3045434551648534245a243.56zM040532H
> 3053232540927543293a2.45zM040332H
> # end of file test
>  
>  
>  
> open (IN,"test")  ||  die "Could not open the test file\n";
> open (OUT,">result")  || die "Error could not create the output
> file\n";
>  
> while () {
> 
> s/a.*?z/WHAT GOES HERE?/;   

s/a([0-9]+.[0-9])+z/sprintf("8.2%f",$1)/e
> 
> 
> print OUT $_;
> }
>  
> close(IN)   || die "Error cannot close test file\n";
> close(OUT)|| die "Error cannot close output file\n";
>  
>  
>  
> # output file must look like this
> 30343647172834593220015.32M042001H
> 30454345516485342450243.56M040532H
> 30532325409275432930002.45M040332H
>  
>  
---end quoted text---

Try "perldoc -f sprintf", 

#!/usr/bin/perl

open IN,'test' or die "test: $! \n";
open OUT,'>result' or die "result: $!\n";

while () {
s/a([0-9]+\.?[0-9]+)z/sprintf("%011.2f",$1)/e;
print OUT
}

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: simple perl question

2002-01-25 Thread Frank

On Fri, Jan 25, 2002 at 01:58:00PM +1100, Stuart wrote:
> Hi
> Please help if you can.
> Thanks again
> Stuart Clark
>  
>  
> How do I add all the number between the "a" and the "z"
> My output file only gives me the instances of the matching pattern and
> not the total
>  
> # start of file test
> 3034364717283459322a15.32zM042001H
> 3045434551648534245a243.56zM040532H
> 3053232540927543293a2.45zM040332H
> # end of file test
>  
> open (IN,"test")  ||  die "Could not open the test file\n";
> open (OUT,">total")  || die "Error could not create the output
> file\n";
>  
> while () {
> 
> $total += /a([\d.]+)z/;
> }
>  
> print OUT $total;
>  
> close(IN)   || die "Error cannot close test file\n";
> close(OUT)|| die "Error cannot close output file\n";
>  
> # output file must look like this
> 261.33
>  
> # At the moment it gives me this
> 3
---end quoted text---

> $total += /a([\d.]+)z/;

this will match the number of matches in the regular expression, not the
values matched. Try:

/a+([\d.]+)z and $total=$1;

instead.

however please note that this regex [\d.] will also match IP addresses
since multiple '.' are allowed, it's probably not important in this
instance.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: CPAN locks up my hard drive.

2002-01-25 Thread Frank

On Thu, Jan 24, 2002 at 10:24:16AM -0800, Shaun wrote:
> I have used the CPAN network at least 6 times and every single time, about 2 hours 
>after I finish
> I my hard drives lock up and the system goes down. It is a Maxtor 7200 RPM 30G 
>drive, on Red Hat
> 7.2. 
> It has a 1.2 Ghz processor and loads of memory.
> 
> Can anyone think of anything that I could do to stop this problem? 
---end quoted text---

How are you using CPAN? 

perl -MCPAN -e shell?

I really don't know why this should be, maybe strace it and run top and
df -h to see what's happening. I'd also list all the other programs
you're running too...

I doubt the following:

1) Anyone could diagnose the problem given the present data.
2) This is an undiscovered bug on CPAN, it's open source goddammit :)
3) This is a bug on CPAN for the same reason.

Given my experience of RedHat (5.2-7.2) I'd change to Debian... just
kidding (well not really, but it's friday and too late in the week for
an OS War ;)... I'd check on the bug list for RedHat if I were you.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: use strict

2002-02-05 Thread Frank

On Tue, Feb 05, 2002 at 09:18:17AM -0800, Octavian wrote:
> Hello all,
> I am a new member. please tell me what is used for the following line in a
> script:
> 
> use strict;
> 
> I saw that if I use it, this make sometimes my scripts to have errors and
> without it, they works.
---end quoted text---

use strict means that strict programming rules are applied to your code.
One example is you need to declare variables using 'my' as in:

my $a="value";

if you are using Unix, try this on the command-line, it should report a
description of what strict does.

perldoc strict
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Return multiple arrays

2002-02-05 Thread Frank

On Tue, Feb 05, 2002 at 11:09:03AM -0500, Brett wrote:
> my $arrayref1 = [1, 2, 3];
> 
> my ($arrayref2, $arrayref3) = sub2($arrayref1);
> 
> sub sub2 {
> 
>   my($arrayref5, ...);
>   my $arrayref1 = shift;
> 
>   return $arrayref6, $arrayref7;
> }
---end quoted text---

A really nice piece of syntactic sugar, I like, is:

@a= qw/foo bar baz/;
@b= qw/1 2 3/;
@c=\(@a,@b);# <-- this line ;o)

# @c is now an array of references to arrays.
# if you used Data::Dumper you'd see:

print Dumper \@c


$VAR1 = [
[
'foo',
'bar',
'baz'
],
[
'1',
'2',
'3'
]
   ];

neat eh?

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: A more perlish way

2002-02-06 Thread Frank

On Wed, Feb 06, 2002 at 03:05:29PM +0100, Jorge wrote:
>  I tried this:
>   @Symlink=("$program_path\\install.lnk",
>"$program_path\\linux.ram.lnk",
>"$program_path\\alize\\install.lnk",
>"$program_path\\alize\\startup.txt.lnk");
> 
>   foreach (@Symlink)
>   {
>   if (-e $_)
>   {
> 
>   system "rm $_";
> 
>   }
>}
>
>   but it seems not to work?Why?

I _think_ the \\ want to be / since rm is a Unix command.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Inserting and array into an Oracle db

2002-02-07 Thread Frank

On Wed, Feb 06, 2002 at 06:12:38PM -0500, McElwee, wrote:
> Hi,
> 
> I'm capturing data from a proprietary database to a flat file and I want to
> create tables and insert rows of data into those tables. From what I've read
> as long as the number of columns matches the number of elements in a row I
> should be able to do wholesale inserts into the oracle database. I just need
> direction on how best to approach this. I was thinking of using a sql
> statement of the order:
> 
>  @row = $sth->dump_results(80, "\n", ':',\*CONTENT);
> 
>   foreach $x (@row){
> $sql = "insert into $i values($x);
> $sth = $dbh2->prepare($sql);
> $sth->execute or die "Can't execute SQL statement: ",
> $sth->errstr(), "\n";
> 
> I know this won't work but am I moving in the right direction? Should I be
> using fetchrow_arrayref() to reference the rows? How would I use this in a
> sql statement? Perhaps I'm moving down a cul de sac, so any pointers in the
> right direction would be appreciated.
---end quoted text---

Look at late binding in Oracle it'll speed up the input of data since
the SQL template is optimised and stored in a buffer, since Oracle has
been informed that it is going to be reused many times. Of course it
depends on the number of inserts as to whether it pays dividends.

Personally I'd use fetchall_arrayref instead of dump_results but that
may be due to habit.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Complete Beginner Looking for Advise!

2002-02-07 Thread Frank

On Wed, Feb 06, 2002 at 08:59:36PM -0500, RunningBarrels wrote:

> Also which books would you recommend to someone with limited programming 
> experience and no perl?

Learning Perl is a good place to start. I still use my copy if I forget
something. It's a good read, like most of the O'Reilly books.

> If you have any other advise or tidbits, like what you wish you had done 
> different when you were learning perl, or if I should learn another language 
> before perl, etc, etc, please let me know.  My ultimate goal is to be able to 
> build a classified page for my website to my liking, however that is quite a 
> task and I realize it will be a while before I am able to do that.  I want to 
> learn the basics well, and go on from there.

Perl is what's called a "loosely-typed language": it doesn't have defined
integer, floating point or character variables, unlike Java or C. This can make it
somewhat confusing if you're used to languages like Java OR are learning the two
simultaneously.

All the best.
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: reg exp question

2002-02-07 Thread Frank

On Thu, Feb 07, 2002 at 11:10:14PM +1100, Stuart wrote:
> How do I match a pattern that starts with a 4 and has 16 numbers in it.
>  
> I try /^4\d{16}/;

If it consists of 16 numbers try:
/^4\d{15}/; 

> Also  how do I match a 16 digit number that starts with either 6565 or
> starts with a number in the range of  555000-555100
>  
>  
> /(^6565(\d{16})|^{555000-555100}(\d{16}))/
---end quoted text---

/^(6565\d{12})|(555[10]00\d{10})/

Perhaps..

not tested mind.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: reg exp question

2002-02-07 Thread Frank

On Thu, Feb 07, 2002 at 12:17:42PM +, 'Perl wrote:
> 
> /^(6565\d{12})|(555[10]00\d{10})/
> 
> Perhaps..
> 
> not tested mind.

evidently.. 

/^(6565\d{12})|(555[10]\d{12})/

will manage numbers in the range 555000-555199, not ideal

/^((6565\d{2})|(555(0\d{2})|(100))\d{10})/

will manage the right range, I think.

(6565\d{2}) will match 6 numbers
as will (555 ..
(0\d{2}) matches 000-099
(100)   matches 100
)
\d{10} grab the remainder.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: simple question

2002-02-07 Thread Frank

On Fri, Feb 08, 2002 at 01:44:17AM +1100, Stuart wrote:
> Hi all,
> Can anyone help please?
>  
> # example values
> $Charge = "55";
> $CreditCard = "423452345654532";

> $VisaCard = /^4\d{15}/;
> $BankCard = /^(6565\d{12})|(555[10]00\d{10})/;

does something like: 

$okayflag = /^4\d{15}/ || /^(6565\d{12})|(555[10]00\d{10})/;

work?

>  
>  
> if ($Charge > 0 && (($VisaCard|$BankCard),$CreditCard) ) { # This bit
> doesn't work?

if( ($Charge > 0 ) && ( defined($BankCard) || defined($VisaCard) ){


I think if you used strict and -w you'd find it'd complain about not
using uninitialised variables and may have flagged other points in the
code.

HTH
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Insert delimiter between number and alpha

2002-02-07 Thread Frank

On Thu, Feb 07, 2002 at 11:27:53AM -0600, Frank wrote:
> All, 
> 
> My input looks like this
> ==
> 5544#1341343BORIS
> 6200#321BOWSER
> 89232652#6213VERONICA
> ===
> I want to put a delimiter (#) between the rightmost number and the left most
> alpha
> Resulting in 
> 
> 5544#1341343#BORIS
> 6200#321#BOWSER
> 89232652#6213#VERONICA
> 
> Any suggestions for a regex that will do this?
> 
> Thanks,
> Frank
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
---end quoted text---

while (){
s/(?<=\d)\W(?=[a-z]/#/i; # look-aheads/behinds
    print OUT;
}

this could be a one liner if you used perl -pi ;)

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: more reg exp

2002-02-11 Thread Frank

On Mon, Feb 11, 2002 at 07:11:17PM +1100, Stuart wrote:
> 
> 54.35
> 435.23
> 1.98
> 57
> 
> to this
> 
> 5435
> 00043523
> 0198
> 0057
> 
> This is what i am trying to use.
> 
> print (s\.\\,(sprintf"%09.2f",$number));
> 
> I thought that perl would complete the inside brackets first
> Then the s\.\\ would operate on the result.
---end quoted text---

howabout :

/([0-9]*\.?[0-9]+)/ and printf("%09.2f",$1/);
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: finding max value

2002-02-13 Thread Frank

On Wed, Feb 13, 2002 at 01:17:50PM +0100, Andrea wrote:
> In article <[EMAIL PROTECTED]> wrote "Jeff 
>'Japhy' Pinyan"
> <[EMAIL PROTECTED]>:
> 
> >>I have a set of functions that give numeric results, and I need to compare  them 
>and choose the
> >>maximal value. Is there any simple way of finding max?
> 
> Don't think about it,
> just use the CPAN module List::Util.
> 
> Then you only have to write 
> my $max = max @values;
---end quoted text---

or:
$max= (sort @values)[-1];

Personally, I'd prefer Japhy's method for efficiency.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: [Fwd: Returned mail]

2002-02-13 Thread Frank

On Wed, Feb 13, 2002 at 08:59:57AM -0500, Susan wrote:
> 
> What is the fastest or best way to sort a file alphabetically, the
> rewrite it to a file.
> 
---end quoted text---

A few questions:
1) How big is the file?
2) Fastest Sorting method or quickest piece of code to write?
3) Is this homework?

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: finding max value

2002-02-13 Thread Frank

On Wed, Feb 13, 2002 at 02:08:23PM +0100, Jon wrote:
> Frank wrote:
> > 
> > On Wed, Feb 13, 2002 at 01:17:50PM +0100, Andrea wrote:
> > > In article <[EMAIL PROTECTED]> wrote 
>"Jeff 'Japhy' Pinyan"
> > > <[EMAIL PROTECTED]>:
> > >
> > > >>I have a set of functions that give numeric results, and I need to compare  
>them and choose the
> > > >>maximal value. Is there any simple way of finding max?
> > >
> > > Don't think about it,
> > > just use the CPAN module List::Util.
> > >
> > > Then you only have to write
> > > my $max = max @values;
> > ---end quoted text---
> > 
> > or:
> > $max= (sort @values)[-1];
> 
> That doesn't seems like a good sollution,
> 
> @a = (-1, -5, -3);
> $max= (sort @a)[-1];
> 
> gives -5 as max, it is max min but not max :)

Yeah, my bad.. I shoulda tested it:
$max=(sort{$a<=>$b}@a)[-1];

sort's default is a lexical comparison, need specify numeric.
me-- for impulse replying ;)

> > 
> > Personally, I'd prefer Japhy's method for efficiency.
> same here, it's straightforward
Yep, it's a good algorithm and it's clear what it does in any language.

-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: urgent info required

2002-02-14 Thread Frank

On Thu, Feb 14, 2002 at 03:26:13PM +0530, Sreemathi_M wrote:
> hi,
> 
> i want to know how to replace a single \ (back slash)  with
> single  / (forward slash) .
> 
> regards,
> sreemathi
---end quoted text---

Well the best way to know is to take some time and read some
documentation or books. 

A Short-term solution to your needs is this:

$_='s\s\s\s\s\s';   # the original string
print "$_\n";   # print the original string
s!\\!/!;# use a regex (! used for clarity)
print "$_\n";   # show the changes.

I'm not even sure if this is exactly what you want.

You could have meant:
1) All instances of \ not \\: s!\\([^\])!/$1!g; *
2) All instances of \   : s!\\!/!g;
3) One instances of \ not \\: s!\\([^\])!/$1!; *
4) Only a single instances of \ : s!\\!/!;

I've opted for the latter (4).

The best advice I can _really_ give, and I hope it's not patronizing, is
to spend some time phrasing your question, quite often you'll find the
answer as you're writing the email; if not we're in a better postion to
help. It saves time in the end.

* not tested.
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: print stock market page every so often

2002-02-14 Thread Frank

On Wed, Feb 13, 2002 at 05:01:33PM -0800, Peter wrote:
> hi guys, just wondering if I can use perl to email me
> a text based copy of a web page, maybe copy and paste
> to a file then e-mail the info.  I can probably use
> something like a macro in windows nt to create a
> procedure or somethingany ideas? thanks...maybe
> someone has done this before.  I would like to get
> periodic updates on my stocks.
---end quoted text---

For this I'd recommend:

LWP::Simple;# To get the page (presuming no cookie or password needed
HTML::Parser or a regex # To grab the pertinent stuff

I'm not sure how mail works on NT but I'd check CPAN for that IIWY.


-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: sorting an array

2002-02-18 Thread Frank

On Mon, Feb 18, 2002 at 11:03:33AM -0500, Yacketta, wrote:
> Folks,
> 
> I have an array which contains data as such
> 
> psych|Sun Feb 17  2002|0:35:59|1523882|HLHack|UG-CS Central-Hell's Kitchen
> uenlon|Sun Feb 17  2002|3:31:17|127244|HLHack|UG-CS Central-Hell's Kitchen
> uenlon|Sun Feb 17  2002|3:31:19|127244|HLHack|UG-CS Central-Hell's Kitchen
> juihung|Sun Feb 17  2002|7:4:56|1149357|HLHack|UG-CS Central-Hell's Kitchen
> juihung|Sun Feb 17  2002|7:4:57|1149357|HLHack|UG-CS Central-Hell's Kitchen
> S02|Sun Feb 17  2002|7:13:18|831398|HLHack|UG-CS Central-Hell's Kitchen
> S02|Sun Feb 17  2002|7:13:20|831398|HLHack|UG-CS Central-Hell's Kitchen
> 
> and would like to sort it by the second and third field (the date IE "Sun
> Feb 17  2002 7:13:20")
> I have tried several different methods including the use of Date::Manip
> etc..
> no matter what I do the date is not sorted in descending order
> (http://www.sampier.com/busted.php)
---end quoted text---

how-about splitting the fields and converting to an epoch time? 
you'll need Time::Local

$epochtime=timelocal($sec,$min,$hours,$mday,$mon,$year);

for the rest use split or a nice regex ;)
-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Re: Size of Array

2002-02-18 Thread Frank

On Mon, Feb 18, 2002 at 09:17:50AM -0800, Agustin wrote:
> Quick one.. is there a way to evaluate the size of an array?  Right now I'm
> writing the arrays to a file and then doing an "ls -l" to compare sizes. The
> array is of type $array[0][0] and not $array[0] (if anyone has the proper
> terminology on this, I'd appreciate it).

try scalar(@array)
or scalar(@{$array[0]})

perldoc perldata
perldoc perllol


-- 
 Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)

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




Unicode::Collate string replacements and whitespace

2010-03-31 Thread Frank Müller
dear all,
I'm making some string replacements with Unicode::Collate which
generally works fine but for whitespace. I have the following simple
code (adopted from the module documentation):

my $myCollator = Unicode::Collate->new( normalization => undef, level
=> 1 );
my $str = "Camel donkey zebra came\x{301}l CAMEL horse cAm\0E\0L...";
  $myCollator->gsubst($str, "camel horse", sub { "$_[0]" });
print $q->p($str);

this doesn't find the search string "camel horse" - if I search for
"camel" the desired replacemts work. How can I get this working with
whitespace in the search string?
Thanks for any hints,
Frank


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




install patch to module Text::LevenshteinXS

2010-07-20 Thread Frank Müller
dear all,
I want to make use of the module Text::LevenshteinXS, I installed it
via perl -MCPAN -e 'shell'. While using it I noticed that the module
isn't UTF safe, so I searched the internet and found:

https://rt.cpan.org/Public/Bug/Display.html?id=36685

There one can download a patch for this module. How do I install this
patch? I found out that using linux I need to make use of the command
tool "patch". But how and where? The module files have been stored by
installation process in 2 different places:

/usr/lib/perl5/site_perl/5.10.0/i586-linux-thread-multi/Text/
LevenshteinXS.pm

and the rest of the files under:
/root/.cpan/build/Text-LevenshteinXS-0.03-XqVYyk/

how do I apply the patch? and after invoking the patch command, do I
need to recompile the module?

Any ideas? or an alternative to this module? it needs to be UTF8 save
so taht rules out e.g. Text::WagnerFischer. the module String::Approx
isn't good for me either as it does string matching not comparing
using substrings.

thanx in advance for any hints!


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




Search and replace w/ ignoring arbitrary characters

2011-08-08 Thread Frank Müller
dear all,

i want to make some search and replace within a string where I can
define a set of characters, especially parenthesis, brackets etc.,
which are to be ignored.

For example, I have the following string:

sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs  sjfh sdkj
sdjkfh sdjfh ska

A search and replace for 'foobar' should result in the following
string:

sdjfh sdf sjkdfh sdkjfh sdjkf ##f[o]o(bar)## hsdkjfh sdkljfhs  sjfh
sdkj sdjkfh sdjfh ska

I tried doing this with Unicode::Collate but with this module the
search and replace is very slow and lacks some flexibility.

Is it possible to make this kind of search and replace with a regular
expression, or does somebody know of an existing perl module which can
do this?

tia,
Frank


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




Re: Search and replace w/ ignoring arbitrary characters

2011-08-10 Thread Frank Müller
hi,
thank you for your solution which works perfect for the data i have
given.
the trouble is: my data looks a little more complex as I have lots of
accented characters so with your code I need to specify each of those
characters in the tr/// part. I reckon the other way around would be
more usefull: speceifying all characters that can be irgnored for
matching. Is there any chance of doing this?
And a second small issue: is it possible to change the code so that
not only full words are marked by the double ##-characters but also
parts of it, e.g. searching for 'ooba' would result in
f[##o]o(ba##r)  ?
again, thanks for any ideas and hints,
Frank


On 9 Aug., 02:34, jwkr...@shaw.ca ("John W. Krahn") wrote:
> Frank Müller wrote:
> > dear all,
>
> Hello,
>
> > i want to make some search and replace within a string where I can
> > define a set of characters, especially parenthesis, brackets etc.,
> > which are to be ignored.
>
> > For example, I have the following string:
>
> > sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs  sjfh sdkj
> > sdjkfh sdjfh ska
>
> > A search and replace for 'foobar' should result in the following
> > string:
>
> > sdjfh sdf sjkdfh sdkjfh sdjkf ##f[o]o(bar)## hsdkjfh sdkljfhs  sjfh
> > sdkj sdjkfh sdjfh ska
>
> $ perl -le'
> $_ = "sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs  sjfh
> sdkj sdjkfh sdjfh ska";
> print;
> s{ ( \S+ ) }{ ( $x = $1 ) =~ tr/a-zA-Z//cd; "foobar" eq lc $x ? "##$1##"
> : $1 }xeg;
> print;
> '
> sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh sdkljfhs  sjfh sdkj
> sdjkfh sdjfh ska
> sdjfh sdf sjkdfh sdkjfh sdjkf ##f[o]o(bar)## hsdkjfh sdkljfhs  sjfh sdkj
> sdjkfh sdjfh ska
>
> John
> --
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction.                   -- Albert Einstein


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




Need help getting data from a structure..

2011-09-28 Thread Frank Kleinburg
Hello list,

I've been playing with perl going back to the 4.x days, mostly simple
scripts to monitor server or application daemons, kick off and manage
backups, or read log files.. While some of these programs are fairly
complicated, none have more than just tickled the more sophisticated
features of perl.. You don't need a Maserati if you're only going to the
store for bread and eggs.. Lately I took on a new project in which I have to
be able to deal with a fairly complicated data set, and I need to get that
fancier car running.. 

To be able to manipulate the information, I created a simple data structure
of 3 parts.. A top level structure which has a hash containing the second
level structure.. This hash contains additional structures of which one is a
hash, leading to the bottom level structure.. Though what I am using is a
bit more involved, for sake of simplicity consider the structure as follows:

$Policy = {
NAME => $PlcyName,
DESCRPT => $PlcyDesc, 
INSTNCE => { %Instance }, 
};

%Instance = (
$CondID => {
DESCRPT => $InstDesc,
ACTIONS => {%PlcyActions},
},
);

%PlcyActions = (
START => {
SEVRTY  => $Severity,
TEXT=> $MsgText,
AUTACTS => $AutoAct,
},
 CONT => {
SEVRTY  => $Severity,
TEXT=> $MsgText,
AUTACTS => $AutoAct,
},
END => {
SEVRTY  => $Severity,
TEXT=> $MsgText,
AUTACTS => $AutoAct,
},
);

I need to be able to write to and read from the structure at any point.. I
can access either of the scalars in the top level fairly easily.. 

print $Policy->{NAME}

prints the value assigned to $PlcyName.. The problems develop when I try to
access the second level structure.. 

If want to access the value stored in $InstDesc, I can through
$Instance{$CondID}{DESCRPT}.. However I can't access the $InstDesc scalar
from the top.. If I try to print the obvious (at least to me):

$Policy->{INSTNCE}{$CondID}{DESCRPT}

I get the "use of an uninitialized in concatenation" warning.. If I try to
print the following:
 
$Policy->{INSTNCE}->$Instance{$CondID}{DESCRPT}
 
  I'd get:
 
HASH(0x235f34)->BadIncident
(Note: "BadIncident" is current value of $InstDesc)
 
I've read chapters 8 & 9 of the camel book so many times I can't tell you,
and chapter 5 a few times from Randal Schwartz's llama book.. I also done
more   Google searches than I care to remember.. So please don't reply with
links to FAQ's or docs if that is all you have to say..

Can someone explain how to access $InstDesc?? Also please explain how I
would access (that is read from or write to) to the $Severity scalar on the
bottom structure..

Thanks in advance.. flk 

p.s. I need to get this working or the boss has threatened to have it
written in vb script.. Please help..

flk k


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




RE: Need help getting data from a structure..

2011-09-29 Thread Frank Kleinburg
List,

First I would like to thank all who provided input.. With the help of the
this list, I was able to figure out what I needed to change to get it all
working.. And we have successfully kept VB out (Yippy!).. 

Now to the solution (note: I have copied the little test code and its output
below.. Please pardon the misspelt words in the scalar text..)..  

Both hashes (%Instance and %PlcyActions) need to be defined as a reference..
So %Instance should have been defined in the Top level structure as:

INSTNCE =>  \%Instance

This assigns a reference to the hash to the key INSTNCE.. The hash in the
second level structure was redefined in the same way.. This makes perfect
sense, and once I saw that, I knew how to get to the data on all levels.. 

Now to access it, one additional change was needed.. To access the scalar in
the top level I use:

$Policy->{INSTNCE}{$CondID}->{DESCRPT}

To go all the way to the bottom, I use:

$Policy->{INSTNCE}{$CondID}->{ACTIONS}{START}{SEVRTY}

Again, one the answer was discovered, it all made perfect sense.. 

Rob, the keys are set to the same values for the test.. I will try the data
dumper.. As I start filling out the structure.. The test code posted is just
the tip of the iceberg so to speak.. The real structure is a lot more
complicated.. This whole piece is actually just a subset of the entire
structure.. 

Flk k

P.S. My back ground.. Been programming going back to assembler in the 70's..
I always use the "use strict" declarative, and run perl with the "-w"
command line switch.. I do unless I am dealing with code someone else wrote,
and I have'nt had the chance to clean it up (I've redone scores at my
current employer).. 

Also I grew up in the days before the internet.. As such I tend to RTFM
(Read The 'Friendly" Manual) long before I go to any list.. I have more
books on perl than you can imagine (as well as C, Python, etc.,  etc.).. And
then only post after hours of reading FAQ's and posts.. As I said in my
post..

Code follows:

#!perl -w
use strict;

my %Instance;
my %PlcyActions;
my $Policy;
my $PlcyName = "My Most Exelent Good Policy";
my $PlcyDesc = "A good descrition for a policy";
my $Interval = "10h:20m:15s";
my $SourceShortName = "Coda";
my ($CondID, $InstDesc, $Object, $Threshold, $NewOne);
my ($Severity, $MsgText, $AutoAct);

$Policy = {
NAME => $PlcyName,
DESCRPT => $PlcyDesc,
INTERVL => $Interval,
CODA=> $SourceShortName,
INSTNCE => \%Instance,
};

$InstDesc  = "BadIncident";
$CondID= "12345678";
$CondID= "CONDID_".$CondID;
$Object= "To get this thing to print";
$Threshold = "How much pain can I take";

%Instance = (
$CondID => {
DESCRPT => $InstDesc,
OBJECT  => $Object,
THRESHD => $Threshold,
ACTIONS => \%PlcyActions,
},
);

$Severity = "SupperDupperHigh";
$MsgText  = "Head for the hills";
$AutoAct  = "Shut her down";

%PlcyActions = (
START => {
SEVRTY  => $Severity,
TEXT=> $MsgText,
AUTACTS => $AutoAct,
},
CONT => {
SEVRTY  => $Severity,
TEXT=> $MsgText,
AUTACTS => $AutoAct,
},
END => {
SEVRTY  => $Severity,
TEXT=> $MsgText,
AUTACTS => $AutoAct,
},
);

print "\n-\n";
print "Top level access..\n";
print "\t\$Policy->{NAME}:\n\t\t\"$Policy->{NAME}\"..\n";
print "\t\$Policy->{DESCRPT}:\n\t\t\"$Policy->{DESCRPT}\"..\n";
print "\t\$Policy->{INTERVL}:\n\t\t\"$Policy->{INTERVL}\"..\n";
print "\t\$Policy->{CODA}:\n\t\t\"$Policy->{CODA}\"..\n";
print "-\n";
print "-\n";
print "Second level access..\n";
print "\n\t\$Policy->{INSTNCE}:".
  "\n\t\t\"$Policy->{INSTNCE}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}:".
  "\n\t\t\"$Policy->{INSTNCE}{$CondID}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{THRESHD}:".
  "\n\t\t\"$Policy->{INSTNCE}{$CondID}->{THRESHD}\"..\n";
print "-\n";
print "-\n";
print "All the way..\n";
print "\n\t\$Policy->{INSTNCE}:".
  "\n\t\t\"$Policy->{INSTNCE}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}:".
  "\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}{START}{SEVRTY}:".
  "\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}{START}{SEVRTY}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}{CONT}{TEXT}:".
  "\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}{CONT}{TEXT}\"..\n";
print "\n\t\$Policy->{INSTNCE}{\$CondID}->{ACTIONS}{END}{AUTACTS}:".
  "\n\t\t\"$Policy->{INSTNCE}{$CondID}->{ACTIONS}{END}{AUTACTS}\"..\n";
print "-\n";



Program output:
==
Microsoft Windows XP [V

Re: Run perl scripts in Windows

2011-10-18 Thread frank cui
i believe most group policy deployments doesn't allow personal created files
on root directory of system disk.

On Tue, Oct 18, 2011 at 5:16 PM, Natxo Asenjo wrote:

> On Oct 18, 2011 3:07 PM, "Remy Guo"  wrote:
> >
> > hi all,
> > I have a Perl script in Windows but my system administrator doesn't allow
> me
> > to install ActivePerl nor i guess anything that will change rigistry on
> the
> > machine.
>
> You do not need to install anything on that host. You can install the msi
> in
> another windows host and copy the c:\perl folder (if you choose to standard
> location) to the host where you need to run the script.
>
> After doing that, you can run your Perl scripts from a cmd prompt. Open
> cmd.exe and in there type the path to perl.exe (if you have copied it to
> c:\perl, it will be c:\perl\bin\perl.exe) and the path to your script.
>
> So if you have your script in d:\scripts\test.pl, you type in cmd.exe:
>
> c:\perl\bin\perl.exe d:\scripts\test.pl
>
> If you want to associate the extension pl with perl.exe, then you need to
> follow the instructions in here:
>
> http://technet.microsoft.com/en-us/library/bb490912.aspx
>
> When you install the active state msi, those things are automatically done
> for you, that is the only difference.
>
> --
>
> natxo
>


File health check on *nix system using stat

2011-12-10 Thread frank cui
hi,

I'm reading the book of "automating system administration with perl" and
having doubts about this code snippets about file health check.

# attempt to read the directory entry for this file
my @stat = stat($name);
if ( !$stat[4] && !$stat[5] && !$stat[6] && !$stat[7] && !$stat[8] ) {
return 0;# according to the code context, here it
is saying the file is NOT ok
}

here $name refers to the file name and it's checking the stat of this file.

stat[4:8] refers to the following from the "perldoc -f stat"

4 uid  numeric user ID of file's owner
5 gid  numeric group ID of file's owner
6 rdev the device identifier (special files only)
7 size total size of file, in bytes
8 atimelast access time in seconds since the epoch

so here the code is actually saying if all the above entries is 0 or
undefined, then we declare this file to be NOT ok .
and my question would be about this logic, why are we checking all of them
with a AND relationship rather than OR, or maybe something else(like
checking all the 0-12 entries) ?

Thanks
Frank


Re: File health check on *nix system using stat

2011-12-11 Thread frank cui
Thanks John and Peter for the reply.

Ok, to make this question more specific, the author of this book is making
a program to check if the files can be read off from the disk.
And he does so by checking two steps, first is making sure the meta data of
this file looks fine, and secondly by reading byte by byte from this file
to actually check the file's content readability.

this is the whole subroutine for checking the file :

sub CheckFile {
my $name = shift;
print STDERR 'Scanning ' . cwd . '/' . $name . "\n";
# attempt to read the directory entry for this file
my @stat = stat($name);
if ( !$stat[4] && !$stat[5] && !$stat[6] && !$stat[7] && !$stat[8] ) {
return 0;
}
# attempt to open this file
open my $T, '<', "$name" or return 0;

# read the file one byte at a time, throw away actual data in $discard
for ( my $i = 0; $i < $stat[7]; $i++ ) {
my $r = sysread( $T, $discard, 1 );
if ( $r != 1 ) {
close $T;
return 0;
}
}
close $T;
return 1;
}

and I cut the meta data checking part in the previous post.

Thanks
Frank


On Sun, Dec 11, 2011 at 12:39 AM, Peter Scott  wrote:

> On Sat, 10 Dec 2011 11:11:15 -0400, frank cui wrote:
> > # attempt to read the directory  entry for this file my @stat =
> > stat($name);
> > if ( !$stat[4] && !$stat[5] && !$stat[6] && !$stat[7] && !$stat[8] ) {
> > return 0;# according to the code context, here
> > it is saying the file is NOT ok
>
> What is the program trying to accomplish?  What does "ok" mean for a file
> in the context of this exercise?  The empirical derivation from the code
> doesn't seem useful.
>
> --
> Peter Scott
> http://www.perlmedic.com/ http://www.perldebugged.com/
> http://www.informit.com/store/product.aspx?isbn=0137001274
> http://www.oreillyschool.com/certificates/perl-programming.php
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


local commands in Win2008R2

2012-02-02 Thread Frank Kleinburg
Folks,

 

Forever I have used the following to run an external command on a Winders
box:

 

`cluster group "$Name"`   (where name is the name of the cluster group in
question)

 

But today I had to run a script which works on previous versions of Windows,
is failing on Windows 2008 R2.. 

Debuging the command, I see the command is coming back "cluster" command not
found.. OK so I tell myself, R2 doesn't have the correct path, and so I
added the fully qualified path, including adding the ".exe" at the end of
the local command name (i.e. `c:\\windows\\system32\\cluster.exe group group
"$Name"`;).. Still same problem..

 

Any ideas why this is failing in Windows 2008 R2?? 

 

Flk k 

 

 



RE: local commands in Win2008R2

2012-02-03 Thread Frank Kleinburg
I appreciate your suggestions.. Thanks for taking the time to reply..
Obviously this problem is a real rear end kicker as there have not been many
replies.. Perhaps most are lucky not to have to work in winders
environments.. 

 

But I was looking for answers as to why this doesn't work in Windows 2008
but works in previous versions of Windows.. 

 

A couple of things first since you asked.. 

 

The double quotes are required since the scalar $Name can contain spaces and
the double quotes make sure the value is passed as one command line
argument.. 

 

The back ticks are a simple way to capture the output of the command to a
scalar as in $output = `cluster group "$Name"`; (less typing).. 

 

Now to the problem..

 

My first thoughts were to provide the full path to the cluster command (i.e.
c:\\windows\\system32\\cluster.exe) but this also returned the same
results.. 

 

I did some research and found the problem to be related to the way the 64bit
"stuff" works in winders.. 

 

I found the following web link which defines the problem and the fix.. 

 

http://www.tipandtrick.net/2008/how-to-suppress-and-bypass-system32-file-sys
tem-redirect-to-syswow64-folder-with-sysnative/

 

So my thoughts about providing the full path were correct, I just had to use
the fake path as shown below.. 

 

`%windir%\\Sysnative\\cluster.exe group "$Name"`;

 

So now I get to add a block to lots of code to be moved to Windows 2008 to
check for windows version info and set the path accordingly.. lots of fun..

 

Anyway thanks again for the reply and I sure hope what I found helps someone
in the future..

 

Flk k

 

From: timothy adigun [mailto:2teezp...@gmail.com] 
Sent: Friday, February 03, 2012 2:35 PM
To: Frank Kleinburg
Subject: Re: local commands in Win2008R2

 

Hi Frank,
  
  Try system("cluster group $Name"); why use backtick?
   

On Thu, Feb 2, 2012 at 6:02 PM, Frank Kleinburg  wrote:

Folks,



Forever I have used the following to run an external command on a Winders
box:



`cluster group "$Name"`   (where name is the name of the cluster group in
question)

  1. Why use backtick? Try system("cluster group $Name"); 
  2. Why put $Name in a double quote?


But today I had to run a script which works on previous versions of Windows,
is failing on Windows 2008 R2..
 

Debuging the command, I see the command is coming back "cluster" command not
found.. OK so I tell myself, R2 doesn't have the correct path, and so I
added the fully qualified path, including adding the ".exe" at the end of
the local command name (i.e. `c:\\windows\\system32\\cluster.exe group group
"$Name"`;).. Still same problem..



Any ideas why this is failing in Windows 2008 R2??


I don't use Windows 2008 R2, try the above and if that doesn't work you
might have to state the error message you are getting.


Flk k









-- 
Tim



String to Character Array

2004-12-06 Thread Frank Westfield
Is there a Perl equivalent of Java String.toArray method?
I need to get an Alpha-Numeric string (16 plus consecutive characters) into 
an array or hash of characters to allow manipulation of the individual 
characters.  The use of substr to extract each characters is unweildy.

Any suggestions would be welcome.
Regards
Frank Westfield - Managing Consultant
--
FW Associates - IT Consultants
Address: 4 Dell Close, Broadstone, Dorset BH18 9NL UK
Phone: +44(0)1202-656000  Fax: +44(0)1202-656009
EMail: [EMAIL PROTECTED]
Regards
Frank Westfield - Managing Consultant
--
FW Associates - IT Consultants
Address: 4 Dell Close, Broadstone, Dorset BH18 9NL UK
Phone: +44(0)1202-656000  Fax: +44(0)1202-656009
EMail: [EMAIL PROTECTED]
Regards
Frank Westfield - Managing Consultant
--
FW Associates - IT Consultants
Address: 4 Dell Close, Broadstone, Dorset BH18 9NL UK
Phone: +44(0)1202-656000  Fax: +44(0)1202-656009
EMail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



String to Character Array

2004-12-06 Thread Frank Westfield
Is there a Perl equivalent of Java String.toArray method?
I need to get an Alpha-Numeric string (16 plus consecutive characters) into 
an array or hash of characters to allow manipulation of the individual 
characters.  The use of substr to extract each characters is unweildy.

Any suggestions would be welcome.
Regards
Frank Westfield - Managing Consultant
--
FW Associates - IT Consultants
Address: 4 Dell Close, Broadstone, Dorset BH18 9NL UK
Phone: +44(0)1202-656000  Fax: +44(0)1202-656009
EMail: [EMAIL PROTECTED]
Regards
Frank Westfield - Managing Consultant
--
FW Associates - IT Consultants
Address: 4 Dell Close, Broadstone, Dorset BH18 9NL UK
Phone: +44(0)1202-656000  Fax: +44(0)1202-656009
EMail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: String to Character Array

2004-12-06 Thread Frank Westfield
At 23:48 06/12/2004, you wrote:
On Mon, 6 Dec 2004, Frank Westfield wrote:
> Is there a Perl equivalent of Java String.toArray method?
>
> I need to get an Alpha-Numeric string (16 plus consecutive characters)
> into an array or hash of characters to allow manipulation of the
> individual characters.  The use of substr to extract each characters
> is unweildy.
split ?
What are you ultimately trying to do here ?
Whatever the problem might be, you can probably do it the way you're
setting out on here, but it won't be idiomatic Perl and therefore it
won't play into Perl's best strengths as a string manipulation language.
If you describe what you're really trying to do, rather than just the
mechanism by which you're trying to do it, we might be able to come up
with a cleaner approach than treating the string as an array of chars.
And by "might", I mean "nearly no question whatsoever" :-)
Sorry if what I said was not clear enough.
I have a string of between 16 and 24 consecutive characters - no spaces or 
other non-alphanumeric characters which split can work on (as I understand 
split).  I need to process each character and reorder the resulting 
manipulated characters into a new string.

This is an existing perl application which I did not design so unless I 
redesign the whole thing I cannot change the process.  (If I did it would 
not be in Perl I think)  Hence the wording of my original question.

In Java I simply create a String Object and call the toArray method and its 
all done - a nice array full of characters.  I am surprised that Perl with 
strong manipulation reputation doesn't have similar functionality.   

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



Re: Problem with Foreach in If Statement...

2005-06-04 Thread Frank Lee
please try this one:

#tested in linux
#!/usr/bin/perl -w
use strict;

my @names = qw( fred barney betty wilma dino );
print "Enter some numbers 1 to 5, one per line, then press ctrl D:\n";
chomp (my @numbers = );
foreach (@numbers){
  if ($_ < 6){
   print "$names[$_ - 1]\n";
   }else{
print "Error: choose numbers less then 6!\n";
}
 }




On 6/4/05, Hakim Singhji <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> Hi All,
> 
> This is my first post at beginners. I am working with Learning Perl
> (Llama!) and I like to tweak some of the problems and create more
> creative solutions to some things. I cannot figure out why this is not
> working. Can anyone point out an error in my code.
> 
> #! Perl
> 
> @names = qw( fred barney betty wilma dino );
> print "Enter some numbers 1 to 5, one per line, then press ctrl Z:\n";
   
 ctrl + D should be used
> chomp (@numbers = );
> ~  if (@numbers > 5) {
   @number > 5 means the number of element in array @number 
is large than 5.
 it does not mean the element is large than 5.

>   print "Error: choose numbers less then 6!\n";
> ~  } else {
>   foreach (@numbers); {
  ~~~ no ; here 
>   print "$names[ $_ - 1 ]\n";
>   }
   need another } here to comparable with "if (@numbers > 5) {"
> Best,
> - --
> Hakim Singhji
> New York University
> [EMAIL PROTECTED]
> http://i5.nyu.edu/~hzs202
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.2.5 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFCoTsjs2AZ6g3dZu8RAtAdAJ44jsNG/TUOiP4kDyuZWN3tWIrrFQCdFB+V
> WKsRYfcrHasOTOB4lhrlMOg=
> =K40v
> -END PGP SIGNATURE-
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 


-- 
Do not guess who  I am.  I am not Bush in BlackHouse

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




how to use perl module to do Z-scores test (Say, Wilcoxon)

2005-06-06 Thread Frank Lee
Can anybody give me some ideas about how to use perl module to do
Z-scores test (Say, Wilcoxon).?

Thanks very much!


-- 
Do not guess who  I am.  I am not Bush in BlackHouse

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




Re: how to use perl module to do Z-scores test (Say, Wilcoxon)

2005-06-06 Thread Frank Lee
Hi, Chris,  

That's very nice!  It is very helpful for me.  I can use the Z-test in
the Mastering Algorithms with Perl.  Thanks very much!

Frank

On 6/7/05, Chris Devers <[EMAIL PROTECTED]> wrote:
> On Tue, 7 Jun 2005, Frank Lee wrote:
> 
> > Can anybody give me some ideas about how to use perl module to do
> > Z-scores test (Say, Wilcoxon).?
> 
> 1. Find the module.
> 
> 2. Look up the Perldoc that describes how to use it.
> 
> 3. Use it.
> 
> 
> I'll be glad to help you a bit with step #1 there.
> 
> 
> A search for Z-score on search.cpan.org --
> 
><http://search.cpan.org/search?query=z-score&mode=all>
> 
> -- turns up a number of hits, all of which seem to be applying the
> concept of Z-scores to different problem domains. Depending on what
> you're doing, one of these may be helpful to you. To pick one at random,
> the Bio::Search::HSP::HMMERHSP module has the following:
> 
>Plus Bio::Seach::HSP::GenericHSP methods
>   [...]
>   -score => score value for HSP (typically z-score but
>  depends on analysis)
> 
><http://search.cpan.org/dist/bioperl/Bio/Search/HSP/HMMERHSP.pm>
> 
> That may or may not be useful to you.
> 
> If you need something more generic, maybe a search for "statistics" will
> provide a more general-purpose module. Sure enough, this turns up:
> 
>Bundle::Math::Statistics
>
> <http://search.cpan.org/~smueller/Bundle-Math-Statistics-1.01/Statistics.pm>
> 
> That, in turn, includes modules like Statistics::Contingency, et al.
> 
>
> <http://search.cpan.org/~kwilliams/Statistics-Contingency-0.06/Contingency.pm>
> 
> Maybe that'll help.
> 
> As a search for "Wilcoxon" doesn't seem to turn up any hits, you may be
> running out of options. If you're still stuck, the next place to look
> may be the book _Mastering Algorithms with Perl_, which has a chapter or
> two on statistical programming in Perl. Unfortunately, I don't see
> Z-score in the index, but I do see Z-test; my statistics are too rusty
> for me to remember if these are the same thing or not.
> 
><http://www.oreilly.com/catalog/maperl/inx.html#Z>
> 
> But there's a bunch of samples of statistical algorithms in that book,
> along with explantions of how they work & how to use them. If all else
> fails, that might be enough to help you get started on rolling your own.
> 
> Helpful?
> 
> Sorry to only provide pointers rather than direct help, but as I, err,
> don't remember much about Z-scores, I can't be more concrete than that.
> If none of this has helped, then maybe it would help if you could
> describe the basic algorithm & the list readers can help show you how to
> implement it in Perl... :-/
> 
> 
> 
> --
> Chris Devers
> 


-- 
Do not guess who  I am.  I am not Bush in BlackHouse

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




RE: What does $$ mean ?

2013-05-17 Thread Frank K.
Gosh, I always thought "$$" is what you have to pay when you get a divorce 
.. flk k

-Original Message-
From: Dr.Ruud [mailto:rvtol+use...@isolution.nl] 
Sent: Friday, May 17, 2013 7:47 AM
To: beginners@perl.org
Subject: Re: What does $$ mean ?

On 17/05/2013 14:39, *Shaji Kalidasan* wrote:

> [CODE1]
> keys %{$$disk_type_ref{$pool}};
> [/CODE1]
>
> Moreover, what does $$ mean here

   %{$$disk_type_ref{$pool}};

can also be written as

   %{ $disk_type_ref->{ $pool } };

See further perldsc.

> --
> - Your talent is God's gift to you. What you do with it is 
> your gift back to God.
> --
> -

https://www.facebook.com/pages/David-Bowie-is-GOD/133491090062327

--
Ruud


-- 
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: Fw: Please exempt the book Modern Perl from Web Commercials on http://perl-begin.org/

2013-06-26 Thread Frank Vino
Dear All,

  Could you please recommend good beginners book to start, and also looking
for videos.


Thanks,
Vino


On Wed, Jun 26, 2013 at 4:30 PM, Rob Dixon  wrote:

> On 26/06/2013 10:18, Franklin Lawerence wrote:
>
>>
>> Hi,
>>
>>   Could you please let me know how to reverse a string without using built
>> in function.
>>
>
> Hi Franklin
>
> Is this homework? I can think of no other reason to need what you are
> asking for.
>
> It is best to say if you are asking for help with homework, as the
> answers will be phrased to help you to learn instead of helping you out
> of a hole.
>
>
> Rob
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Please exempt the book Modern Perl from Web Commercials on http://perl-begin.org/

2013-06-26 Thread Frank Vino
Thanks a lot Shlomi.. :)

Regards,
Vino


On Wed, Jun 26, 2013 at 4:55 PM, Shlomi Fish  wrote:

> Hi Vino,
>
> On Wed, 26 Jun 2013 16:43:38 +0530
> Frank Vino  wrote:
>
> > Dear All,
> >
> >   Could you please recommend good beginners book to start, and also
> looking
> > for videos.
>
> Please see:
>
> * http://perl-tutorial.org/
>
> * http://www.perl-begin.org/ (my own link).
>
> Regards,
>
> Shlomi Fish
>
> --
> -
> Shlomi Fish   http://www.shlomifish.org/
> Chuck Norris/etc. Facts - http://www.shlomifish.org/humour/bits/facts/
>
> There is no IGLU Cabal. The problem of founding an IGLU Cabal has been
> proven,
> in a surprise move, to be equivalent to the question of the existence of
> God,
> fully‐tolerant religions and NP‐complete oracles.   — Omer Zak
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Getting Started.

2013-06-26 Thread Frank Vino
Thank you All

-Vino


On Wed, Jun 26, 2013 at 9:31 PM, Chankey Pathak wrote:

> John is right.
>
> You should go for "Beginning Perl by Ovid". It's really a nice book for a
> beginner in Perl.
>
> -Chankey
>
>
> On Wed, Jun 26, 2013 at 9:27 PM, John SJ Anderson 
> wrote:
>
>> Hi Frank.
>>
>> Based on your "Dear all" salutation, I suspect you meant to send this
>> to the whole list, not just me -- so I'm replying to the whole list.
>>
>> IMO the best Perl "beginner" book at the moment is Curtis "Ovid" Poe's
>> "Beginning Perl".
>>
>> chrs,
>> john.
>>
>>
>> On Wed, Jun 26, 2013 at 4:02 AM, Frank Vino  wrote:
>> > Dear all,
>> >
>> > Please recommend good books for beginners.
>> >
>> > Thanks
>> > VF
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>
>
> --
> Regards,
> Chankey Pathak <http://www.linuxstall.com>
>


Hello

2013-07-11 Thread Frank Vino
Could you please let me know the perl script how to find DNS IP address of
system.?

Thanks,
-Vino


Need to login/logout for Domain Users

2013-08-13 Thread Frank Vino
Hi All,

   Here is my requirement could you please help on this.

  I have Domain Controller for 100 users, and i have client PC (windows 7),
i would like to login with multiple users for every 5 minutes in a same
client PC.

Thanks,
Vino


Kind Help

2013-10-03 Thread Frank Vino
Hi All,


Here is my request,

I would like to hit my firewall with IP address and Domain users for 100
Users. I have firewall and active directory(100 Users) but i do not have
100 Client PC's. I am planning to do a SSH/Remote session to hit the
firewall with IP address and Doamin Users. I would automate this, Could you
please provide some code where i can achieve this.


Warm Regards,
Vino.


Re: Kind Help

2013-10-04 Thread Frank Vino
Thanks for your help.

-Vino.


On Fri, Oct 4, 2013 at 10:14 AM, Shlomi Fish  wrote:

> Hi Vino,
>
> On Fri, 4 Oct 2013 09:12:20 +0530
> Frank Vino  wrote:
>
> > Hi All,
> >
> >
> > Here is my request,
> >
> > I would like to hit my firewall with IP address and Domain users for 100
> > Users. I have firewall and active directory(100 Users) but i do not have
> > 100 Client PC's. I am planning to do a SSH/Remote session to hit the
> > firewall with IP address and Doamin Users. I would automate this, Could
> you
> > please provide some code where i can achieve this.
> >
>
> I'm not going to write your code for you (unless you pay me for my time)
> but I
> will give you a few leads:
>
> I give a list of some of the prominent SSH modules on CPAN here:
>
> http://perl-begin.org/uses/remote-login-and-commands/#ssh
>
> (**Note**: perl-begin.org is maintained by me. Are you happy now, Rob
> (Dixon)? )
>
> Some of these modules have bindings for event-driven / multitasking
> frameworks
> such as https://metacpan.org/search?q=anyevent ,
> https://metacpan.org/search?q=io%3A%3Aasync ,
> https://metacpan.org/search?q=reflex , or the older and more baroque
> https://metacpan.org/search?q=poe , etc. and you can use them to open
> several
> connections at once and deal with them as they need attention. Maybe
> search for
> one of them along with SSH and see what you get.
>
> Regards,
>
> Shlomi Fish
>
> --
> -
> Shlomi Fish   http://www.shlomifish.org/
> "Humanity" - Parody of Modern Life - http://shlom.in/humanity
>
> COBOL is the old Java.
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: OO perl programming

2014-02-06 Thread Frank Landry
any of the oreilly books



On Thu, Feb 6, 2014 at 9:50 AM, lesleyb  wrote:

> On Wed, Feb 05, 2014 at 11:52:39PM -0600, Sam wrote:
> > On 02/05/2014 04:30 PM, kavita kulkarni wrote:
> > >Can somebody suggest me good book to learn/practice object oriented Perl
> > >programming.
> > >
> > >
> > >Regards,
> > >Kavita :-)
> >
> >
> > Beginning Perl by Curtis Poe is a really good read. Also there are
> > many tutorials for perl moose online.
> >
> I haven't reread the perldoc object oriented stuff in ages but I would
> agree
> that learning Moose for Perl OO is your best bet for modern Perl OO
> practice.
>
> Here's a URL for it
> http://search.cpan.org/dist/Moose/
>
> perldoc Moose will be your friend.
>
> Kind regards
>
> Lesley
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Frank N. Landry


Planning to buy Hard Copy Book

2014-06-11 Thread Frank Vino
Hi Team,

  Could you please let me know which publisher and author name are good in
Perl Book, I am planning to buy a hard copy.

Thanks,
Vino


Re: Planning to buy Hard Copy Book

2014-06-11 Thread Frank Vino
Thanks a lot guys..:)

-Frank


On Wed, Jun 11, 2014 at 7:30 PM, Sam  wrote:

> Depends on your level. I enjoyed "Beginning Perl" by Curtis Poe. It covers
> alot of areas in perl, from the different object frameworks to a really
> nice section on testing.
>
> If you really want to get serious, get a copy of the larger "Programming
> Perl" as well.
>
> --Sam
>
>
> On 06/11/2014 05:23 AM, Frank Vino wrote:
>
>> Hi Team,
>>
>>Could you please let me know which publisher and author name are good
>> in Perl Book, I am planning to buy a hard copy.
>>
>> Thanks,
>> Vino
>>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


reading a hash of arrays

2014-11-19 Thread Frank K.
Have a hash of arrays.. i.e.

 

$hash{one}[0] = "value 10";

$hash{one}[1] = "value 11";

$hash{one}[2] = "value 11";

$hash{one}[3] = "value 13";

$hash{one}[0] = "value 20";

$hash{one}[1] = "value 21";

$hash{one}[2] = "value 22";

$hash{one}[3] = "value 23";

 

If I had two arrays and wanted to make them contain the same "stuff" I could
type:

 

@array1 = @array2..

 

Yet if I try to take one of the elements of my hash of arrays (which by the
way is an array) and do the same I get an error..

 

I can't do @array1 = @hash{one};

 

Thinking about it, will adding parentheses fix it (I am away from my real
computer - I was going to shoot it with a big bazooka gun so I felt it best
).. 

 

   i.e @array1 = (@hash{one});

 

or should I just go and do some heavy drinking??

 

Thanks in advance.. flk 



RE: reading a hash of arrays

2014-11-19 Thread Frank K.
Thanks for the hint.. And I was looking forward to a night of heavy
drinking.. Oh well, might as well code into the night.. 

Thanks again.. flk k

-Original Message-
From: Shawn H Corey [mailto:shawnhco...@gmail.com] 
Sent: Wednesday, November 19, 2014 5:09 PM
To: beginners@perl.org
Subject: Re: reading a hash of arrays

On Wed, 19 Nov 2014 17:03:40 -0600
"Frank K."  wrote:

> I can't do @array1 = @hash{one};

@array1 = @{ $hash{one} };

$hash{one} contains a reference to an array. By dereferencing it with @{ ...
}, you get the array.


--
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/




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




Unable to call SSH module.

2015-03-12 Thread Frank Vino
Hi,

  Here is my code. In Cpan i have installed ssh in linux and windows still
i am getting the error, Can anybody provide for opening a ssh by using perl?

#!/usr/bin/perl

use Net::SSH::Perl;
 my $ssh = Net::SSH::Perl->new('10.10.10.10');
 $ssh->login(admin, password);
 my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

Output:

Can't locate Net/SSH/Perl.pm in @INC (you may need to install the
Net::SSH::Perl
 module) (@INC contains: C:/Perl64/site/lib C:/Perl64/lib .) at ssh.pl line
3.
BEGIN failed--compilation aborted at ssh.pl line 3.

-Frank


Re: Unable to call SSH module.

2015-03-12 Thread Frank Vino
Thank you so much let me try

On Thu, Mar 12, 2015 at 10:23 PM, Zach Tuttle 
wrote:

> You need to install the ssh module on windows
>
> Sent from my iPhone
>
> On Mar 12, 2015, at 9:25 AM, Frank Vino  wrote:
>
> Hi,
>
>   Here is my code. In Cpan i have installed ssh in linux and windows still
> i am getting the error, Can anybody provide for opening a ssh by using perl?
>
> #!/usr/bin/perl
>
> use Net::SSH::Perl;
>  my $ssh = Net::SSH::Perl->new('10.10.10.10');
>  $ssh->login(admin, password);
>  my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
>
> Output:
>
> Can't locate Net/SSH/Perl.pm in @INC (you may need to install the
> Net::SSH::Perl
>  module) (@INC contains: C:/Perl64/site/lib C:/Perl64/lib .) at ssh.pl
> line 3.
> BEGIN failed--compilation aborted at ssh.pl line 3.
>
> -Frank
>
>


Which Is Good?

2015-03-12 Thread Frank Vino
Activeperl or Strawberry Perl. = Which is good to use?

-Frank


Regular Expression Help.

2015-03-24 Thread Frank Vino
Hi Team,

How to understand Regular Expression in a easy way?

Thanks,
Frank


Re: Regular Expression Help.

2015-03-25 Thread Frank Vino
Thanks a lot Simon

-Frank

On Wed, Mar 25, 2015 at 5:44 PM, Simon Reinhardt 
wrote:

> Hi Frank,
>
> when first learning regexps I read the section "In the World of Regular
> Expressions" in the Lama-Book [1]. If you find this introduction to
> slow, you might also take a look at chromatic's Modern Perl, which is
> available for free [2].
>
> Regards, Simon
>
> Am 25.03.2015 um 06:01 schrieb Frank Vino:
> > Hi Team,
> >
> > How to understand Regular Expression in a easy way?
> >
> > Thanks,
> > Frank
>
> [1] Learning Perl, Sixth Edition by Randal L. Schwartz, brian d foy, and
> Tom Phoenix
>
> [2] http://onyxneon.com/books/modern_perl/
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Module Not Getting Installed

2015-03-27 Thread Frank Vino
Hi Team,

  When i trying to install FWConfig.pm from cpan it is saying that unable
to locate. Could you please let me know how to download this module?

-Franklin


Re: Module Not Getting Installed

2015-03-27 Thread Frank Vino
Sorry Shlomi it is our own module, i am still working on this. once it is
update i will get the details.

 -Franky

On Fri, Mar 27, 2015 at 3:58 PM, Shlomi Fish  wrote:

> Hi Franklin,
>
> On Fri, 27 Mar 2015 14:00:05 +0530
> Frank Vino  wrote:
>
> > Hi Team,
> >
> >   When i trying to install FWConfig.pm from cpan it is saying that unable
> > to locate. Could you please let me know how to download this module?
> >
>
> I cannot find FWConfig.pm either here -
> https://metacpan.org/search?q=FWConfig
> or here - https://www.google.com/search?q=%22FWConfig.pm%22&gws_rd=ssl .
> Where
> do you see the "use" or "require" statement that requires it?
>
> Regards,
>
> Shlomi Fish
>
> --
> -
> Shlomi Fish   http://www.shlomifish.org/
> Buffy Factoids - http://www.shlomifish.org/humour/bits/facts/Buffy/
>
> Medusa’s gaze can turn people into stone. Buffy’s gaze can turn Medusa into
> stone.
> — http://www.shlomifish.org/humour/bits/facts/Buffy/
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Doubt

2015-03-29 Thread Frank Vino
When i try to install Alias.pm file from environment i was getting an error
message as cannot locate alimas.pm file, then i checked in cpan it was
showing, In case how to fix this and update the Alias.pm file.

Frank


read/write to command line opened as a file

2015-04-20 Thread Frank K.
Ok, I am trying to do something I initially thought would be fairly easy to
do but am running into lots of trouble.

 

I have a db2 instance running on a Windows 2k8r2 Enterprise server, using
ActivePerl V5.8..

 

I wanted to open a file handle in read/write mode to run cmd.exe.. I then
need to write several commands to the handle and read the output of each
command.. 

 

Would someone suggest a solution which would allow me to "open" a read/write
session to a command line??

 

Thanks in advance.. flk k



Storing Output file.

2016-01-28 Thread Frank Larry
Hi Team,

 could you please let me? i have a file which contains "Debug", i would
like to replace debug to "Error", when i ran the below program the out
showing Error message but how to save the output with new changes. Could
you please tell me how to fix it?

open(FILE, "){
   print "Before substituting: ", $line ,"\n";
$line =~ s/Debug/Error/g;
print "After substituting : ", $line , "\n";
}

close(FILE);


-Franky


Re: Storing Output file.

2016-01-28 Thread Frank Vino
Thank a lot brothersi will try all the things and update you..

-Frank

On Thu, Jan 28, 2016 at 11:27 PM, Jonathan Harris via beginners <
beginners@perl.org> wrote:

> Hi,
> I found that this works, assuming that the module is installed.
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Slurp qw ( :edit );
> #
> my $file_to_edit = 'path-to-file.txt';
> #
> my $word_to_edit = "Debug";
> my $new_word = "Error";
> #
> edit_file { s/$word_to_edit/$new_word/g } ( $file_to_edit );
> #
>
> This will work if you have the word Debug, Debug_ etc etc
> You can just use s/Debug/Error/g but I like the variables as it allows
> flexibility if the script was to expand to further uses
>
> Hope that helps,
> Jon
>
>
> On Thu, Jan 28, 2016 at 3:41 PM, Jim Gibson  wrote:
>
>>
>> > On Jan 28, 2016, at 1:37 AM, Frank Larry 
>> wrote:
>> >
>> > Hi Team,
>> >
>> >  could you please let me? i have a file which contains "Debug", i would
>> like to replace debug to "Error", when i ran the below program the out
>> showing Error message but how to save the output with new changes. Could
>> you please tell me how to fix it?
>>
>> The way to do this within a larger Perl program is to open a new output
>> file, copy all of the possibly-modified lines to this file. Then you can
>> rename the new file to the same name as the old file, and perhaps rename
>> the old file as well and keep it around as a backup.
>>
>> >
>> > open(FILE, ">
>> The three-argument version of open is preferred here, and let’s put the
>> file name in a variable and use a lexical variable for the file handle
>> (untested):
>>
>> my $filename = ‘filter.txt’;
>> open( my $in, ‘<‘, $filename ) or die(“Can’t open $filename for reading:
>> $!”);
>>
>> # create a new file
>> my $newfile = $filename . ‘.new’;
>> open( my $out, ‘>’, $newfile ) or die(“Can’t create $newfile: $!”);
>>
>> >
>> > while($line = ){
>>
>> while( $line = <$in> ) {
>>
>> >
>> >print "Before substituting: ", $line ,"\n";
>> > $line =~ s/Debug/Error/g;
>> > print "After substituting : ", $line , "\n”;
>>
>> print $out $line;
>> >
>> > }
>> >
>> > close(FILE);
>>
>> close($in);
>> close($out) or die(“Error writing to output file $newfile: $!”);
>>
>> # rename the old file
>> my $savefile = $filename . ‘.sav’;
>> rename $filename, $savefile;
>>
>> # rename the new file
>> rename $newfile, $filename;
>>
>> Jim Gibson
>> j...@gibson.org
>>
>>
>>
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>


  1   2   3   >