contributing to perl

2008-03-20 Thread Sharan Basappa
Hi, I was thinking of contributing a utility function to perl. Want to know what is the procedure. Also, note that I dont have exposure to oops concept of perl (though I have exposure to general oops concept) Regards -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:

Re: get the matching regex pattern

2008-03-20 Thread [EMAIL PROTECTED]
On Mar 20, 6:01 am, [EMAIL PROTECTED] (Ram Prasad) wrote: > I have a somewhat strange requirement > I want to find if a regex matched what exactly matched > > to reproduce this > > -- > my @x; > $x[0] = 'chi+ld*'; > $x[1] = '\sjoke'; > > $_=getinput(); # for test assum

Re: parsing CSV files with control and extended ASCII characters

2008-03-20 Thread Gunnar Hjalmarsson
David Newman wrote: I have some CSV input files that contain control and extended ASCII characters, The Text::CSV or Tie::Handle::CSV modules don't like these characters; the snippets below both return errors when they get to one. my $csv = Text::CSV->new(); In the docs for Text::CSV,

parsing CSV files with control and extended ASCII characters

2008-03-20 Thread David Newman
I have some CSV input files that contain control and extended ASCII characters, including: - vertical tabs (0x0B) - acute and grave accents - tildes - circumflexes - umlauts - nonbreaking spaces (0xA0) The Text::CSV or Tie::Handle::CSV modules don't like these characters; the snippets bel

RE: FW: How to install Date::Manip on cygwin perl?

2008-03-20 Thread Bob McConnell
Normally the installer will show "C:\Program Files\ActiveState\Perl", or something similar as the location where it will put the package. I change that to "D:\perl" before proceding. The entire tree, including CPAN will be installed at that location. You may have to remove the package and reinstall

RE: FW: How to install Date::Manip on cygwin perl?

2008-03-20 Thread Siegfried Heintze (Aditi)
Ah! Good idea! How do I do that with CPAN? -Original Message- From: Bob McConnell [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 18, 2008 12:46 PM To: Gunnar Hjalmarsson; beginners@perl.org Subject: RE: FW: How to install Date::Manip on cygwin perl? I have always avoided the "Program File

Re: find an entry in hash array

2008-03-20 Thread Dr.Ruud
"John W. Krahn" schreef: > my %hash; > > @hash{ @array } = (); Example: $ perl -MData::Dumper -wle ' my @array = qw/x t 3 u 77 y r/; my %hash; @hash{ @array } = (); print Dumper(\%hash); ' $VAR1 = { 'y' => undef, 'u' => undef, 'r' => undef,

Re: Package???

2008-03-20 Thread Gunnar Hjalmarsson
Chas. Owens wrote: On Thu, Mar 20, 2008 at 1:13 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: Chas. Owens wrote: First off, don't do that. Messing around with another package's variables ties you to that version of the module and is bad juju. Not sure I understand how the OP's question

Re: find an entry in hash array

2008-03-20 Thread John W. Krahn
Sharan Basappa wrote: On Thu, Mar 20, 2008 at 9:19 PM, Andrew Curry <[EMAIL PROTECTED]> wrote: %hash = map { $_ => 1 } @array; is just a funny way to write %hash = (); foreach $_ (@array) { $hash{$_} = 1;

Re: get the matching regex pattern

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 2:02 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > > print '$x[', $1 ? '0' : '1', "] matched.\n"; > >print "\$x[", @- - 1, "] matched.\n" snip That only works if we assume that $x[0] and $x[1] are free of captures themselves: #!/usr/bin/perl use

Re: get the matching regex pattern

2008-03-20 Thread John W. Krahn
Gunnar Hjalmarsson wrote: Ram Prasad wrote: I want to find if a regex matched what exactly matched to reproduce this -- my @x; $x[0] = 'chi+ld*'; $x[1] = '\sjoke'; $_=getinput(); # for test assume $_="This is a joke"; if(/($x[0]|$x[1])/){ print "Matched '

Re: get the matching regex pattern

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 1:30 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: snip > if ( /($x[0])|($x[1])/ ) { > print '$x[', $1 ? '0' : '1', "] matched.\n"; > } snip Since you cannot necessarily predict what $x[0] will hold, you should probably be testing $1 for definedness n

Re: get the matching regex pattern

2008-03-20 Thread Gunnar Hjalmarsson
Just posted to clpmisc: Original Message Subject: Re: get the matching regex pattern Date: Thu, 20 Mar 2008 18:44:23 +0100 From: Gunnar Hjalmarsson <[EMAIL PROTECTED]> Newsgroups: comp.lang.perl.misc Ram Prasad wrote: I have a somewhat strange requirement ... You had posted

Re: Package???

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 1:13 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: snip > > First off, don't do that. Messing around with another package's > > variables ties you to that version of the module and is bad juju. > > Not sure I understand how the OP's question motivates that remark. sni

Re: get the matching regex pattern

2008-03-20 Thread Gunnar Hjalmarsson
Ram Prasad wrote: I want to find if a regex matched what exactly matched to reproduce this -- my @x; $x[0] = 'chi+ld*'; $x[1] = '\sjoke'; $_=getinput(); # for test assume $_="This is a joke"; if(/($x[0]|$x[1])/){ print "Matched '$1' \n"; }

Re: Package???

2008-03-20 Thread Gunnar Hjalmarsson
Chas. Owens wrote: On Thu, Mar 20, 2008 at 5:26 AM, sanket vaidya <[EMAIL PROTECTED]> wrote: use warnings; use strict; my $name = "sanket"; $fred::name = "Fred; print "In main name = $name\n"; package Fred; print "Now name = $name"; The output is In main name = sanket Now name = s

Re: context?

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 11:28 AM, Joel <[EMAIL PROTECTED]> wrote: > > > my_function "foo", "bar"; > > > > > my_function is a list operator which has a very low precedence so the > > > parentheses are not required. > > > > Sometimes, i.e. if the sub is not predeclared, they are required. > > >

Re: find an entry in hash array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 12:05 PM, Sharan Basappa <[EMAIL PROTECTED]> wrote: > ok. thats what I wanted to confirm. I my crude code, I was doing > exactly that and was > wondering if there is some other way to make an entry without really > adding value. > Maybe, perl has to do it internally but

Re: find an entry in hash array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 11:46 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: > Can you throw some light on this statement: > > my %hashset = map { $_ => 1 } @array; snip The map* function takes a block of code and a list to process. It runs the block of code on every item in the list returning a l

Re: find an entry in hash array

2008-03-20 Thread Sharan Basappa
ok. thats what I wanted to confirm. I my crude code, I was doing exactly that and was wondering if there is some other way to make an entry without really adding value. Maybe, perl has to do it internally but will be much more optimal than the one I am simply forcing a value of 1 Regards On Thu,

Re: context?

2008-03-20 Thread Joel
> > my_function "foo", "bar"; > > > my_function is a list operator which has a very low precedence so the > > parentheses are not required. > > Sometimes, i.e. if the sub is not predeclared, they are required. > yes this is true, because perl doesn't know that my_function is actually a function ca

RE: find an entry in hash array

2008-03-20 Thread Andrew Curry
%hash = map { $_ => 1 } @array; is just a funny way to write %hash = (); foreach $_ (@array) { $hash{$_} = 1; } -Original Message- From: Sharan Basappa [mailto:[EMAIL PROTECTED] Sent: 20 March 2008 1

Re: find an entry in hash array

2008-03-20 Thread Sharan Basappa
Can you throw some light on this statement: my %hashset = map { $_ => 1 } @array; On Thu, Mar 20, 2008 at 9:14 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > On Thu, Mar 20, 2008 at 11:35 AM, Sharan Basappa > > <[EMAIL PROTECTED]> wrote: > > > Well here is what I am trying to do. > > I have an arr

Re: find an entry in hash array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 11:35 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: > Well here is what I am trying to do. > I have an array (generated from somewhere) I would like to convert > this into an associative array and then based on some other input > I would like to see if an entry exists in

Re: find an entry in hash array

2008-03-20 Thread Sharan Basappa
Well here is what I am trying to do. I have an array (generated from somewhere) I would like to convert this into an associative array and then based on some other input I would like to see if an entry exists in the asso array. As you can see the value does not really matter. What matters is whethe

Re: find an entry in hash array

2008-03-20 Thread Sharan Basappa
i am sorry. I really meant asso array .. On Thu, Mar 20, 2008 at 8:32 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > > On Thu, Mar 20, 2008 at 10:50 AM, Sharan Basappa > <[EMAIL PROTECTED]> wrote: > > Is there a way to find out if an entry exists in a hash array? > > e.g. I have a hash array and

Re: find an entry in hash array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 10:50 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: > Is there a way to find out if an entry exists in a hash array? > e.g. I have a hash array and another normal array. I would like loop > though regular array and see if the entries defined in this array exist > in hash

find an entry in hash array

2008-03-20 Thread Sharan Basappa
Is there a way to find out if an entry exists in a hash array? e.g. I have a hash array and another normal array. I would like loop though regular array and see if the entries defined in this array exist in hash array. Regards -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands,

RE: dialog box in perl

2008-03-20 Thread Bob McConnell
> From: nag [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 20, 2008 9:59 AM > To: zentara > Cc: beginners@perl.org > Subject: Re: dialog box in perl > > hi ,getting error like this for the script.. > > couldn't connect to display ":0" at > /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-m

Re: get the matching regex pattern

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 9:01 AM, Ram Prasad <[EMAIL PROTECTED]> wrote: > I have a somewhat strange requirement > I want to find if a regex matched what exactly matched > > to reproduce this > > -- > my @x; > $x[0] = 'chi+ld*'; > $x[1] = '\sjoke'; > > $_=getinput();

get the matching regex pattern

2008-03-20 Thread Ram Prasad
I have a somewhat strange requirement I want to find if a regex matched what exactly matched to reproduce this -- my @x; $x[0] = 'chi+ld*'; $x[1] = '\sjoke'; $_=getinput(); # for test assume $_="This is a joke"; if(/($x[0]|$x[1])/){ print "Matched '$1' \n";

Re: dialog box in perl

2008-03-20 Thread nag
hi ,getting error like this for the script.. couldn't connect to display ":0" at /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-multi/Tk/MainWindow.pm line 55. MainWindow->new() at ./dialog.pl line 5 please let me know if there are other perl codes for dialog boxes and radio buttons. On T

Re: xml::twig help

2008-03-20 Thread mirod
ken Foskey wrote: > Updated to fix memory problem, you have to purge. Takes over 30 > minutes for 120K records. > > I am sure that the whole process can be done better with a good > understanding of the module. Will benchmark XML::Rules though. Not knowing the structure of the XML you are pr

Re: measuring performance

2008-03-20 Thread Sharan Basappa
ok, here is the issue I am having measuring the performance of a unix process I am trying to execute within perl. Within per because I want to use benchmark module to see how long it takes to execute this process. Here is the code snippet: #!/usr/bin/perl use Benchmark; # declare array my @data;

Re: How to make all files in one directory to an array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 9:16 AM, Süleyman Gülsüner <[EMAIL PROTECTED]> wrote: > Hi, > > You can use opendir, readdir and may play with grep as below; > > opendir $dir, '/tmp' or > @list = grep ! /^\.\.?$/, readdir($dir); > grep to remove '.' and '..' snip This isn't anymore efficient than

Re: measuring performance

2008-03-20 Thread John W. Krahn
Chas. Owens wrote: On Thu, Mar 20, 2008 at 9:15 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: Thanks, this is really helpful. In addition, is there a way to print the cpu cycles taken from *ux command prompt? I have worked with tools that, at the end of their job, print out the cpu cycles it

Re: measuring performance

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 9:15 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: > Thanks, this is really helpful. In addition, is there a way to print > the cpu cycles taken from *ux command prompt? > I have worked with tools that, at the end of their job, print out the > cpu cycles it took for them.

Re: How to make all files in one directory to an array

2008-03-20 Thread Süleyman Gülsüner
Hi, You can use opendir, readdir and may play with grep as below; opendir $dir, '/tmp' or @list = grep ! /^\.\.?$/, readdir($dir); grep to remove '.' and '..' @list = grep ! /^\.+/ # you can remove '.' , '..' and hidden files @list = grep /\.txt$/ # only txt files etc suleyman On

Re: measuring performance

2008-03-20 Thread Sharan Basappa
Thanks, this is really helpful. In addition, is there a way to print the cpu cycles taken from *ux command prompt? I have worked with tools that, at the end of their job, print out the cpu cycles it took for them. I would assume that they use some command from *ux to do this. Regards On Thu, Mar

Re: Package???

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 5:26 AM, sanket vaidya <[EMAIL PROTECTED]> wrote: > > > Hi all, > > I am having some questions regarding following codes: > > use warnings; > > $name = "sanket"; > $fred::name = "Fred; > > print "In main name = $name\n"; > > package Fred; > print "Now name = $name";

Re: How to make all files in one directory to an array

2008-03-20 Thread Ken Foskey
On Thu, 2008-03-20 at 18:20 +0530, sivasakthi wrote: > Hi all, > > How to form array by using the files available in particular directory ? > > for example, /tmp contains the following files.. > > #ls /tmp > example.txt > file1.txt > file2.txt > file3.txt > sample.txt > www.txt > zzz.txt > >

Re: Using Perl to parse comma diliminated fields ---

2008-03-20 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Thanks for the repsponse guys!!! With your help ( really the direct answer ) I was able to get this going! Below is my final script that works like a charm. The only question for learning purposes is, what does "=~ /[-+]?[\d.]+/ g;" actually do? =~ is the binding opera

Re: How to make all files in one directory to an array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 8:50 AM, sivasakthi <[EMAIL PROTECTED]> wrote: > Hi all, > > How to form array by using the files available in particular directory ? snip my @list_of_files = ; However, this is not a good idea. Do you know how many files are in that directory? If it is an extraordinari

Re: measuring performance

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 7:21 AM, Sharan Basappa <[EMAIL PROTECTED]> wrote: snip > I am implementing two algos to solve same problem. I would like to > measure the performance of these 2 algos > (in terms of CPU cycles or wall clock etc.) > I have seen some explanation in some library document in pe

Re: measuring performance

2008-03-20 Thread Jenda Krynicky
Date sent: Thu, 20 Mar 2008 16:51:52 +0530 From: "Sharan Basappa" <[EMAIL PROTECTED]> To: beginners@perl.org Subject:measuring performance > * Haven't done this before, so need help * > > Hi, > > I am implementing two algos to so

How to make all files in one directory to an array

2008-03-20 Thread sivasakthi
Hi all, How to form array by using the files available in particular directory ? for example, /tmp contains the following files.. #ls /tmp example.txt file1.txt file2.txt file3.txt sample.txt www.txt zzz.txt i want to take all the above files in to one array? how to do that? Thanks, Siva

RE: diff of two files

2008-03-20 Thread Ken Foskey
Sounds like homework not a genuine work query. On Thu, 2008-03-20 at 15:14 +0530, [EMAIL PROTECTED] wrote: > Hi All, > > Can somebody please help me on this??? > > Regards, > Irfan > > > -Original Message- > From: Sayed, Irfan > Sent: Monday, March 17, 2008 7:52 PM > To: beginners@per

Re: Q: how to rename file with space in filename

2008-03-20 Thread John W. Krahn
ciwei wrote: # ls -l -rw-r--r-- 1 root other 0 Mar 19 16:24 this is the first file -rw-r--r-- 1 root other 0 Mar 19 16:24 this is the second file -rw-r--r-- 1 root other 0 Mar 19 16:24 this is the third file I want to rename the files, to say, first, second, etc # ls -1 | perl -ne 'pri

Re: bitwise xor operator - array

2008-03-20 Thread Chas. Owens
On Thu, Mar 20, 2008 at 2:17 AM, Rajanikanth Dandamudi <[EMAIL PROTECTED]> wrote: > > Hi Chas. Owens, > > Thanks a lot for the clarification. Finally I would like to understand how > to find that the character \x{01} is getting printed. It is not visible onto > the standard output display. snip

measuring performance

2008-03-20 Thread Sharan Basappa
* Haven't done this before, so need help * Hi, I am implementing two algos to solve same problem. I would like to measure the performance of these 2 algos (in terms of CPU cycles or wall clock etc.) I have seen some explanation in some library document in perl the comparison between different alg

Re: Using Perl to parse comma diliminated fields ---

2008-03-20 Thread google
On Mar 18, 5:46 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: > [EMAIL PROTECTED] wrote: > > Hey Perl Guru's:) > > I'm hoping that someone can help me out... I have a regular'ol ASCII > > file which I'll need to read only the first line, and parse the three > > numbers that are seperated by commas a

Q: how to rename file with space in filename

2008-03-20 Thread ciwei
# ls -l -rw-r--r-- 1 root other 0 Mar 19 16:24 this is the first file -rw-r--r-- 1 root other 0 Mar 19 16:24 this is the second file -rw-r--r-- 1 root other 0 Mar 19 16:24 this is the third file I want to rename the files, to say, first, second, etc # ls -1 | perl -ne 'print $1,"\n" if

RE: diff of two files

2008-03-20 Thread Irfan.Sayed
Hi All, Can somebody please help me on this??? Regards, Irfan -Original Message- From: Sayed, Irfan Sent: Monday, March 17, 2008 7:52 PM To: beginners@perl.org Subject: diff of two files Hi All, I want to compare the two files in Perl. The requirement is that file 1 has 20 lines a

Package???

2008-03-20 Thread sanket vaidya
Hi all, I am having some questions regarding following codes: use warnings; $name = "sanket"; $fred::name = "Fred; print "In main name = $name\n"; package Fred; print "Now name = $name"; The output will be as expected: In main name = sanket Now name = Fred Now if I use "strict" then code

Package??

2008-03-20 Thread sanket
Hi all, I am having some questions regarding following codes: use warnings; $name = "sanket"; $fred::name = "Fred; print "In main name = $name\n"; package Fred; print "Now name = $name"; The output will be as expected: In main name = sanket Now name = Fred Now if I use "strict" then code be

Re: Using Perl to parse comma diliminated fields ---

2008-03-20 Thread google
Thanks for the repsponse guys!!! With your help ( really the direct answer ) I was able to get this going! Below is my final script that works like a charm. The only question for learning purposes is, what does "=~ /[-+]?[\d.]+/ g;" actually do? My Perl Cookbook doesn't explain ( or I just don't k

Re: Client-Server Architecture script

2008-03-20 Thread Süleyman Gülsüner
Hi, You can fork for multiple connections. and define $SIG{INT} for ctrl-c: Here is an example; $SIG{INT} = \&destroy_server; #ctrl -> destroy_server ... ... ... die "can not fork: $!" unless defined ($kid_pid=fork()); if ($kid_pid) { while(<$new_sock>) { print $_;