RE: Split based on length

2003-09-19 Thread NYIMI Jose (BMB)
IMHO
$string =~ /.{1,$len}/g;
Is the best suggestion i have seen so far ;)

I have an other request : "code review" :-)
Below is my final code.
I'm sure that you guys will find
Some better style to write it ...

#!/usr/local/bin/perl -w
use strict;
#--
#Global variables
#--
my $group_len=64;
my $index_len='A1';
my $name_len='A6';
my $way_len='A3';
my $delim_len='x1';
my $meas_len='A5';
my $nof_meas=9;
#--
#Main
#--
my $file=$ARGV[0];
open(FH,$file) || die "can not open $file : $! \n";

while(my $line=){
next if $. < 3;
 
my($date,$dummy,$str)=$line=~/(\d{2}-\d{2}-\d{4}:\d{3})\s+(\d{2})(.+)/;
  for( &split_len($str,$group_len) ){
 print $date."\t", join( "\t",&get_fields($_) ),"\n";
  }
}
close(FH);
#
#Subroutines
#
sub split_len{
  my ($str, $len) = @_;
  $str =~ /.{1,$len}/g;
}

sub get_fields{
  my($str)[EMAIL PROTECTED];
  my $format="$index_len $name_len $way_len";
  $format.=" $delim_len $meas_len" x $nof_meas;
  unpack($format,$str);
}



-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 12:17 AM
To: Bob Showalter
Cc: Stephen Hardisty; [EMAIL PROTECTED]
Subject: RE: Split based on length


On Sep 18, Bob Showalter said:

>Stephen Hardisty wrote:
>> > for(split(/(..)/, $string)) { print "*$_" if $_; }
>>
>> Gorgeous :o)
>
>@parts = grep length, split /(..)/, $string;

WHY are we using split() for this?  Why are we using a method that
returns a list twice the size that we want, that we then have to filter
through?

  @parts = $string =~ /.{1,$len}/sg;

and you're done.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]
http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/
http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of
course. [  I'm looking for programming work.  If you like my work, let
me know.  ]


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



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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



avoid repitive code while sorting hash arrays

2003-09-19 Thread Ramprasad A Padmanabhan
suppose I have a hash like

 %users =(
  'cvs' => {
   'uname' => 'cvs',
   'uid' => 582,
   'gid' => 500
 },
'radvd' => {
 'uname' => 'radvd',
 'uid' => 75,
 'gid' => 75
   },
'goofy' => {
 'uname' => 'goofy',
 'uid' => 515,
 'gid' => 515
   },
 );
Now I want to sort on either of the fields 'uname' 'uid' 'gid'
and  ascending or descending Then my sort function is pretty repitive 
code. I have to check if the field is numeric or not and then if the 
sorting is ascending or descending.

assume $hash = \%users;
..
 if($sortkey eq 'uname'){
	if($direction eq 'a'){
	@allunames = sort{ $$hash{$a}{$sortkey} cmp $$hash{$b}{$sortkey} } 
keys %hash;
	} else {
	@allunames = sort{ $$hash{$b}{$sortkey} cmp $$hash{$a}{$sortkey} } 
keys %hash;
	}
} else {
	if($direction eq 'a'){
	@allunames = sort{ $$hash{$a}{$sortkey} <=> $$hash{$b}{$sortkey} } 
keys %hash;
	} else {
	@allunames = sort{ $$hash{$b}{$sortkey} <=> $$hash{$a}{$sortkey} } 
keys %hash;
	}
}
..

Can someone suggest a better way.
Thanks
Ram


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


WIN32 Services / Scheduled Tasks

2003-09-19 Thread Jones, Jeremy

Hi-All

I'm trying to find a way (IF any exists) to influence the properties of
Windows Services and the Scheduled Tasks; i.e. : 
The ability to enable/disable (and possibly set as Start Automatic)
a Windows Service from Perl,and approximatly the same with
the Task Scheduler (Set Tasks to enable or disable).

Any info would be MUCH appreciated!

preemptive Thanx!  

Jeremy

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



Read Directory Name

2003-09-19 Thread Dumitru Orza
Hello all,
is there any way to assign names of directories to a list ?
Ideea is to check the existance of some directories and not create them again.
Thank you,
Orza



Re: WIN32 Services / Scheduled Tasks

2003-09-19 Thread Jenda Krynicky
From: "Jones, Jeremy" <[EMAIL PROTECTED]>
> I'm trying to find a way (IF any exists) to influence the properties
> of Windows Services and the Scheduled Tasks; i.e. : 
>  The ability to enable/disable (and possibly set as Start Automatic) a
> Windows Service from Perl,

perldoc Win32::Service

> and approximatly the same with
>  the Task Scheduler (Set Tasks to enable or disable).

Sorry, don't know. Maybe you can do this via Win32::OLE and WMI 
(Windows Management Interface).

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


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



Re: avoid repitive code while sorting hash arrays

2003-09-19 Thread Rob Dixon
Ramprasad wrote:
> suppose I have a hash like
>
>   %users =(
>'cvs' => {
> 'uname' => 'cvs',
> 'uid' => 582,
> 'gid' => 500
>   },
>  'radvd' => {
>   'uname' => 'radvd',
>   'uid' => 75,
>   'gid' => 75
> },
>  'goofy' => {
>   'uname' => 'goofy',
>   'uid' => 515,
>   'gid' => 515
> },
>   );
>
> Now I want to sort on either of the fields 'uname' 'uid' 'gid'
> and  ascending or descending Then my sort function is pretty repitive
> code. I have to check if the field is numeric or not and then if the
> sorting is ascending or descending.
>
> assume $hash = \%users;
> ..
>   if($sortkey eq 'uname'){
> if($direction eq 'a'){
> @allunames = sort{ $$hash{$a}{$sortkey} cmp $$hash{$b}{$sortkey} }
> keys %hash;
> } else {
> @allunames = sort{ $$hash{$b}{$sortkey} cmp $$hash{$a}{$sortkey} }
> keys %hash;
> }
>  } else {
> if($direction eq 'a'){
> @allunames = sort{ $$hash{$a}{$sortkey} <=> $$hash{$b}{$sortkey} }
> keys %hash;
> } else {
> @allunames = sort{ $$hash{$b}{$sortkey} <=> $$hash{$a}{$sortkey} }
> keys %hash;
> }
>  }
> ..
>
> Can someone suggest a better way.

Hi Ram.

Will this do?

sort {
  my ($va, $vb) = map $$hash{$_}{$sortkey}, $direction eq 'a' ? ($a, $b) : ($b, $a);
  $sortkey eq 'uname' ? $va cmp $vb : $va <=> $vb;
} keys %$hash;

Cheers,

Rob



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



TK

2003-09-19 Thread Paul Kraus
I saw someone mention that tk was the better route to go for a UI then a
web interface. I have several office applications that I have written
that I was going to write html interfaces for. I would love to avoid
having to learn web development to :) Can anyone give me a break down on
what tk is and how easy it is to pick up? I have several projects that
are just about finished minus any real GUI. Also any web resources or
book recommendations would be nice. Thanks

Paul


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



RE: instance variables?

2003-09-19 Thread NYIMI Jose (BMB)
If you are tired typing "my $self = shift;"
There are modules out there that can build class for you.
http://search.cpan.org/search?query=Class%3A%3AStruct&mode=module

I'm using Class::Struct module coming with perl.

José.
-Original Message-
From: Kevin Pfeiffer [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 18, 2003 11:03 PM
To: [EMAIL PROTECTED]
Subject: RE: instance variables?


In article <[EMAIL PROTECTED]>, Rob Hanson wrote:

>> But I'm wondering if there is another way
>> (like the Java "private variable") to say
>> "all class variables declared here are unique
>> to each instance"?
> 
> It sounds like you are trying to link how OO-Perl works with 
> OO-Java... and that is only going to make your head spin.  What you 
> really need to do is understand what bless really does, and that 
> OO-Perl isn't really OO in the usual sense (but it works like it is).
[...]

> Now when you talk about instance variables, realize that there is no 
> true object instance in Perl.  It is just a reference tagged with a 
> "type"... the rest is all smoke and mirrors.
> 
> So to emulate instance variables you can use a hash reference instead 
> of a scalar reference, like this:

And this actually works quite fine I think...

> I hope that helps a little.
> 
> Rob

Thanks, that helped a lot! (Thank you also to others who responded.)

Meanwhile my "naive ticketMachine" is chugging along. And I like doing the Perl 
version of something else; it's good practice for me (though I'm getting tired of 
typing "my $self = shift;").  ;-)

-K

-- 
Kevin Pfeiffer
International University Bremen


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



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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



Re: Apache 1.3 config problem

2003-09-19 Thread Robert J Taylor

- Original Message - 
From: "Robert J Taylor" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, September 17, 2003 2:28 PM
Subject: Re: Apache 1.3 config problem

Sorry - at least one error : "/www/myfirstweb/htdocs" should have been
"/home/devin-com/public_html" (I first was going to generalize the answer,
then switched to trying to make it specific to your case and forgot to
change at least this line)

> - Original Message - 
> From: "Devin B. Hedge" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, September 17, 2003 2:32 PM
> Subject: Apache 1.3 config problem
>
>
> > Greetings all!
> >
> > I am having a problem with my Apache config in order to run perl scripts
> > (*.pl) outside of the cgi-bin directory in a vHost arrangement. I have
> root
> > on the box. Perl is corrrectly cofigured and working on the box. I have
> > several Perl sistes running scripts out of cgi-bin. Here is my vHost
file:
> >
> > 
> > ServerAdmin [EMAIL PROTECTED]
> > DocumentRoot /home/devin-com/public_html/
> > ServerName devin-com.devinhedge.net
> > #
> > # DirectoryIndex index.pl index.html
> > #
> > #
> > SetHandler perl-script
> > PerlHandler Apache::Registry
> > PerlSendHeader On
> > Options +ExecCGI
> > 
> > HostnameLookups On
> > ErrorLog /home/devin-com/logs/error_log
> > CustomLog /home/devin-com/logs/access_log common
> > 
> >
>
> Are you trying to run mod_perl or do you mean to run CGI scripts using
perl?
> If the latter, you're confusing directives. If the former, you have other
> problems. I will assume you mean to run CGI scripts using perl.
>
> To enable a directory to run CGI scripts using Perl under Apache 1.3.x you
> can do this (I'm taking the liberty to change "Location" tags to
"Directory"
> tags for simplicity (Location tags use a regex whereas Directory tags use
> file system directories, which is probably what you meant):
>
> 
> DocumentRoot /home/devin-com/public_html/
>
> ServerName devin-com.devinhedge.net
> Port80
> ScriptAlias/perl/ /path/to/perl # I'm guessing it is really here:
> #ScriptAlias/perl/ /home/devin-com/perl # this is probably what you
> meant, right?
>
> 
>   AllowOverride none
>   Options -Indexes FollowSymLinks +ExecCGI
>   order allow,deny
>   allow from all
> 
>
>  # likely "/home/devin-com/perl"
>  AllowOverride none
>  Options -Indexes +IncludesNOEXEC +ExecCGI
>  Order allow,deny
>  Allow from all
> 
>
> 
>
> My guess is you're just trying to get your scripts to work and aren't
> looking for the most optimal implementation at this time. The above should
> get you working (but I haven't tested it). BTW, using a ScriptAlias
> directory implies that every resource reachable in that ScriptAlias is a
> script to be executed. You don't have to use any extension with this
setup.
> (Or, for fun, use arbitrary ones, like ".php" or ".jsp" or ".aspx" or
> ".cobol" or ".logo" or ".abacus"... impress your boss with your
multi-vendor
> implementations :)
>
> If you just want to run *.pl files as perl files, whereever they are
> encountered, add this line instead of your Location section:
>
> AddHandler cgi-script .pl
>
> Then be sure to have a valid reference to perl on your system in the
> sha-bang line of your scripts. (#!/usr/bin/perl -w)
>
> If this doesn't make sense, explain your file layout (filesystem
directories
> as such) and how you want your site to appear to web users (URLs).
>
> HTH.
>
> Robert Taylor
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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



RE: Apache 1.3 config problem

2003-09-19 Thread Robert J Taylor
- Original Message - 
From: "Devin B. Hedge" <[EMAIL PROTECTED]>
To: "'Robert J Taylor'" <[EMAIL PROTECTED]>
Sent: Wednesday, September 17, 2003 3:38 PM
Subject: RE: Apache 1.3 config problem


> Robert,
> Thanks for your help. I've been struggling with describing my intent for a
> few days. Let me see if I can clear it up.
>

Sorry, I've been in Sequoia National Park / Forest for the past few days and
decided to not try to catch up with what I missed. I saw this as the first
post.

> I'm trying to run Perl scripts (*.pl) using mod_perl.
>

Aha! Question: does your hosting provider have mod_perl built into Apache
(statically or linked dynamically) or did you do it for them?

> The index.pl file is in the htdocs directory. It is not in its own
directory
> structure.
>

No problem. Although I recommend PerlRun versus Registry for handling
unweildy CGI-Scripts written in Perl gracefully.

Try this (untested - I use a similar setup using the Directory section, but the File 
section should work similarly; it matches based on the regex you specify). You do need 
to use the PerlModule statement...

PerlModule Apache::PerlRun # or put this in httpd.conf before including your virtual 
host directory

SetHandler perl-script
PerlHandler Apache::PerlRun
PerlSendHeader On
PerlSetVar PerlRunOnce On



> so I'm trying to run http://www.devinhedge.com/index.pl from
> /home/devin-com/public_html/index.pl
>
> I think I posted the incorrect configuration file. I'm not using /perl as
a
> Location. I did that to try and move index.pl around to see if it
mattered.
> The correct location would be the root of the ~/html_public directory.
>
> The current behavior is that Apache just serves index.pl as a text file to
> be downloaded.
>
> Devin.
>

Robert

more perlboot questions

2003-09-19 Thread sfryer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thanks to Jeff and George for help with my last question!

Now, say I make an instance as follows...

{ package Generic;
  sub MakeInstance {
my $class = shift;
my $name = shift;
bless \$name, $class;
  }
}
{ package MyClass;
  use base qw(Generic);
}
my $blessed_ref = MyClass->MakeInstance('my string');

Assuming I don't know .. how can I determine which class $blessed_ref
was blessed into? I was thinking I could simply shift off the class
using some method and return the result. That would produce something
like "MyClass=REF(0xf00ba7)" which I could s/=\(\w+\)// to get the
class name, but that seems like a horrible kludge to me (not to
mention it may not work). Is there a better way?

Next question. I want to make a series of methods to dereference
instances for me automagically as follows...

{ package Generic;
  sub ReturnDeref {
ref $_[0]
  ? Deref_($_[0])
  : $_[0];
  }
  sub Deref_ {
if(ref($_[0]) eq 'SCALAR') { $$_[0] }
elsif (ref($_[0]) eq 'ARRAY')  { @$_[0] }
elsif (ref($_[0]) eq 'HASH')   { %{$_[0]} }
# etc... for each ref type.
  }
}

The above *seems* to be okay (at least returns no errors, warnings or
diagnostics). Where I'm having the trouble is when getting the data in
and out as below...

my @names_array = qw/ tom dick harry /;
my $array_instance = MyClass->MakeInstance([EMAIL PROTECTED]);
print ref $array_instance->ReturnDeref, "\n"; # \n is optional

This is clearly wrong, since it prints nothing. I would have expected
STDOUT like "ARRAY". What am I doing wrong?

I'm guessing that instead of Generic->MakeInstance, I should perhaps
have a Generic->BlessScalar, Generic->BlessArray, & Generic->BlessHash
etc. But I was sort of hoping for a compact one-size-fits-all solution
if that's possible. Any ideas? Am I on the right track or way off base
or what?

- -- 
=
 Shaun Fryer
=
 http://sourcery.ca/
 ph: 905-529-0591
=

Science is like sex: occasionally something useful
comes out of it, but that's not why we do it.
- -: Richard Feynmann
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (OpenBSD)
Comment: http://sourcery.ca/sfryer-public_pgp_key.txt

iD8DBQE/aPg12rKegHkuEpoRAuubAJ4lXLOr2+bbSsbO5E1UZmOlph4aYACcCEQq
HKw4Yk1uGA+KESvdt9gemas=
=uiPD
-END PGP SIGNATURE-


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



Re: more perlboot questions

2003-09-19 Thread sfryer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Okay ... ignore my last questions. Seems the list-server is a bit slow
today, so after a few hours banging away, I figured it out by a
combination of trial & error + RTFMs  (solution below).

{ package Generic;
  sub MkInstance {
my $class = shift;
my $var   = shift;
bless \$var, $class;
  }
  sub ReturnPkgName {
my $ref = shift;
ref $ref ? ref $ref : $ref;
  }
  sub DeBless {  # was "Curse", but too close to `curses (3)`
my $scalar = shift;
ref $scalar  # is it a class or instance (blessed reference)?
  ? $$scalar # it's an instance, return dereferenced value
  : $scalar; # it's a class, return generic
  }
}
{ package Guy;
  use base qw(Generic);
}

my $scalar_ref = Guy->MkInstance("Bubba");
print $scalar_ref->DeBless, "\n";

my @names_array = qw/ Tom Dick Harry /;
my $array_ref = Guy->MkInstance([EMAIL PROTECTED]);

###
## 1 ##
### Answer:

print "Class = ", $array_ref->ReturnPkgName, "\n";

###
## 2 ##
### Answer:

print "Ref_Type = ", ref $array_ref->DeBless, "\n";
print "Instance = qw/ ", join ' ', @{$array_ref->DeBless}, "/\n";

### Combined...
foreach my $var (@{$array_ref->DeBless}) {
  print "Some ", $array_ref->ReturnPkgName, " named $var.\n";
}

I'm still working on how to properly bless then dereference hashes
using Generic->methods. The saga continues...

Any pointers are welcomed of course. ;)

- -- 
=
 Shaun Fryer
=
 http://sourcery.ca/
 ph: 905-529-0591
=

Science is like sex: occasionally something useful
comes out of it, but that's not why we do it.
- -: Richard Feynmann



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (OpenBSD)
Comment: http://sourcery.ca/sfryer-public_pgp_key.txt

iD8DBQE/aUmx2rKegHkuEpoRAgTjAKCkqWvaROMfaCXPqoe7ioUmqRXdZgCeKvGe
mu9WkR5LvSdjmsLw1o28SwQ=
=ingE
-END PGP SIGNATURE-


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



RE: list-parsing problem

2003-09-19 Thread EUROSPACE SZARINDAR
Hi Marcus

Just look at the perldoc perlreftut. What you are looking for is the exact
exemple of the paper.

Michel


-Message d'origine-
De: Marcus Claesson [mailto:[EMAIL PROTECTED]
Date: jeudi 18 septembre 2003 11:26
À: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Objet: list-parsing problem


Hi People,

I have a silly little list-parsing problem that I can't get my head
around, and I'm sure some of you have come across it before.

I have a list like this:

1   a
2   b
2   c
3   a
4   d
4   d
4   e
4   f
5   g

and I want to make the first column non-redundant and collect the second
column values on the same line, like this:

1   a
2   b,c
3   a
4   d,e,f
5   g

Please note that line 4 only has one 'd'.

I've tried with both hashes and arrays (don't want to confuse you so I
won't display them here), but nothing really works...

I would really appreciate any help!

Marcus




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

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



RE: list-parsing problem

2003-09-19 Thread Thomas Bätzler
Marcus Claesson [mailto:[EMAIL PROTECTED] asked:
> I have a silly little list-parsing problem that I can't get my head
> around, and I'm sure some of you have come across it before.

Sure. Looks like homework ;-)

HTH,
Thomas

#!/usr/bin/perl -w

use strict;

my %unique;

while(  ){
  my( $key, $value ) = split;
  
  $unique{$key}->{$value}++
}

foreach my $key ( sort keys %unique ){
  print "$key: " . join( ", ", sort keys %{$unique{$key}} ) . "\n";
}

__DATA__
1   a
2   b
2   c
3   a
4   d
4   d
4   e
4   f
5   g

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



Re: avoid repitive code while sorting hash arrays

2003-09-19 Thread Chuck Fox
Rob and all the other perl wonder workers who contribute to this list,

Awesome,  While I have been reading and writing perl for a few years 
now, I am always amazed at the code reduction that can occur when you 
properly apply the power of perl. This is the most instructive forum 
that I have ever joined.  Thanks to you and all the others that post to 
this forum.

Chuck

[EMAIL PROTECTED] wrote:

Ramprasad wrote:
 

suppose I have a hash like

 %users =(
  'cvs' => {
   'uname' => 'cvs',
   'uid' => 582,
   'gid' => 500
 },
'radvd' => {
 'uname' => 'radvd',
 'uid' => 75,
 'gid' => 75
   },
'goofy' => {
 'uname' => 'goofy',
 'uid' => 515,
 'gid' => 515
   },
 );
Now I want to sort on either of the fields 'uname' 'uid' 'gid'
and  ascending or descending Then my sort function is pretty repitive
code. I have to check if the field is numeric or not and then if the
sorting is ascending or descending.
assume $hash = \%users;
..
 if($sortkey eq 'uname'){
if($direction eq 'a'){
   @allunames = sort{ $$hash{$a}{$sortkey} cmp $$hash{$b}{$sortkey} }
keys %hash;
} else {
   @allunames = sort{ $$hash{$b}{$sortkey} cmp $$hash{$a}{$sortkey} }
keys %hash;
}
} else {
if($direction eq 'a'){
   @allunames = sort{ $$hash{$a}{$sortkey} <=> $$hash{$b}{$sortkey} }
keys %hash;
} else {
   @allunames = sort{ $$hash{$b}{$sortkey} <=> $$hash{$a}{$sortkey} }
keys %hash;
}
}
..
Can someone suggest a better way.
   

Hi Ram.

Will this do?

sort {
 my ($va, $vb) = map $$hash{$_}{$sortkey}, $direction eq 'a' ? ($a, $b) : ($b, $a);
 $sortkey eq 'uname' ? $va cmp $vb : $va <=> $vb;
} keys %$hash;
Cheers,

Rob



 



RE: list-parsing problem

2003-09-19 Thread EUROSPACE SZARINDAR

Hi, 

Be careful with the "sort keys %unique" because if the list is bigger like
that :

 __DATA__
 1  a
 2  b
 2  c
 3  a
 4  d
 4  d
 4  e
 4  f
 5  g
 8  f 
 10   e
 10   y

you will get :

 1  a
 10   e,y   <== I don't think you are looking for that , no ?
 2  b,c
 3  a
 4  d,e,f
 5  g
 8f


Look at the "perldoc -f sort" to have the numerical order

Michel

-Message d'origine-
De: Marcus Claesson [mailto:[EMAIL PROTECTED]
Date: jeudi 18 septembre 2003 11:56
À: Thomas Bätzler
Cc: [EMAIL PROTECTED]
Objet: RE: list-parsing problem


Homework's sorted ;)! Thanks a lot Thomas, it worked fine!
Marcus

On Thu, 2003-09-18 at 10:41, Thomas Bätzler wrote:
> Marcus Claesson [mailto:[EMAIL PROTECTED] asked:
> > I have a silly little list-parsing problem that I can't get my head
> > around, and I'm sure some of you have come across it before.
> 
> Sure. Looks like homework ;-)
> 
> HTH,
> Thomas
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my %unique;
> 
> while(  ){
>   my( $key, $value ) = split;
>   
>   $unique{$key}->{$value}++
> }
> 
> foreach my $key ( sort keys %unique ){
>   print "$key: " . join( ", ", sort keys %{$unique{$key}} ) . "\n";
> }
> 
> __DATA__
> 1 a
> 2 b
> 2 c
> 3 a
> 4 d
> 4 d
> 4 e
> 4 f
> 5 g


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

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



Re: avoid repitive code while sorting hash arrays

2003-09-19 Thread Ramprasad A Padmanabhan
Rob Dixon wrote:
Ramprasad wrote:

suppose I have a hash like

 %users =(
  'cvs' => {
   'uname' => 'cvs',
   'uid' => 582,
   'gid' => 500
 },
'radvd' => {
 'uname' => 'radvd',
 'uid' => 75,
 'gid' => 75
   },
'goofy' => {
 'uname' => 'goofy',
 'uid' => 515,
 'gid' => 515
   },
 );
Now I want to sort on either of the fields 'uname' 'uid' 'gid'
and  ascending or descending Then my sort function is pretty repitive
code. I have to check if the field is numeric or not and then if the
sorting is ascending or descending.
assume $hash = \%users;
..
 if($sortkey eq 'uname'){
if($direction eq 'a'){
   @allunames = sort{ $$hash{$a}{$sortkey} cmp $$hash{$b}{$sortkey} }
keys %hash;
} else {
   @allunames = sort{ $$hash{$b}{$sortkey} cmp $$hash{$a}{$sortkey} }
keys %hash;
}
} else {
if($direction eq 'a'){
   @allunames = sort{ $$hash{$a}{$sortkey} <=> $$hash{$b}{$sortkey} }
keys %hash;
} else {
   @allunames = sort{ $$hash{$b}{$sortkey} <=> $$hash{$a}{$sortkey} }
keys %hash;
}
}
..
Can someone suggest a better way.


Hi Ram.

Will this do?

sort {
  my ($va, $vb) = map $$hash{$_}{$sortkey}, $direction eq 'a' ? ($a, $b) : ($b, $a);
  $sortkey eq 'uname' ? $va cmp $vb : $va <=> $vb;
} keys %$hash;
Cheers,

Rob


Gr8 Now the code looks more neat.
Thanks
Do you think doing an explicit
 'if($direction eq 'a') { ...} else { ...}
Will be less expensive
Because in that case the $direction is checked only once here It is 
checked in every loop. That means bigger the hash  , heavier the code 
will become

Can I not dynamically create my sort function , without the ifs ,  to 
suit the parameters on the fly and then use the sort function on the 
entire hash

Well anyway my actual data is not very big.
   If I have to compromise on some cpu-cycles versus the 
code-readability I will go for better code-readability.

Thanks
Ram




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


Slide Show

2003-09-19 Thread Joseph Ruffino
Hi,

I've looked in a few books, but can't seem to find what I want.  Can 
someone point me in the right direction to create a multi-image slide show.

I know I can open a directory and readin in the data, but how can I or 
should I put the image in a  box to view either on an html page or just 
in windows?

If anyone could help it would be greatly appreciated.

--
Joseph A. Ruffino
Gail Borden Public Library District
Automated Systems Assistant
200 N. Grove Ave
Elgin, Il 60120   [EMAIL PROTECTED]
Phone: (847) 742-2411 ext 367
Fax: (847) 742-0485


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


Re: Single and Double quotes in SQL

2003-09-19 Thread Robert J Taylor
Since you're sending this to the Perl list I will assume you're using
DBI::mysql to interface with MySQL.

Use the DBI method "quote()",
as in:
# assuming:
# my $dbh = DBI->connect(...) has gone before
$dbh->quote($Value);

Here's a little sub routine I picked up from CodeCharge a while back; I use
it for quick RAD development:

#---
# Convert value for use with SQL statement
#---
sub ToSQL {
  my ( $Value, $sType ) = @_;
  if ( $Value eq "") {
if ($sType eq "notnull") {
  return $dbh->quote(" ")
} else {
  return "Null"
}
  } else {
if ( $sType eq "Number" ) {
  return 0+replace($Value, ",", ".");
} else {
  return $dbh->quote($Value);
}
  }
}

#---


- Original Message - 
From: "Pablo Fischer" <[EMAIL PROTECTED]>
To: "Perl Beginners" <[EMAIL PROTECTED]>
Sent: Saturday, September 20, 2003 2:34 PM
Subject: Single and Double quotes in SQL


> Hi!
>
> I need to save some HTML text in a DataBase (MySql, using DBI). However
> some HTML text will have single and double quotes, so.. how can I save
> them?, for example:
>
> It's so funny
>
> Thanks!
> Pablo
> -- 
> Pablo Fischer Sandoval (pablo -arroba- pablo.com.mx)
> http://www.pablo.com.mx
> http://www.debianmexico.org
> GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
> Firma URL: http://www.pablo.com.mx/firmagpg.txt
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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



Re: Single and Double quotes in SQL

2003-09-19 Thread Robert J Taylor
Since you're sending this to the Perl list I will assume you're using
DBI::mysql to interface with MySQL.

Use the DBI method "quote()",
as in:
# assuming:
# my $dbh = DBI->connect(...) has gone before
$dbh->quote($Value);

Here's a little sub routine I picked up from CodeCharge a while back; I use
it for quick RAD development:

#---
# Convert value for use with SQL statement
#---
sub ToSQL {
  my ( $Value, $sType ) = @_;
  if ( $Value eq "") {
if ($sType eq "notnull") {
  return $dbh->quote(" ")
} else {
  return "Null"
}
  } else {
if ( $sType eq "Number" ) {
  return 0+replace($Value, ",", ".");
} else {
  return $dbh->quote($Value);
}
  }
}

#---


- Original Message - 
From: "Pablo Fischer" <[EMAIL PROTECTED]>
To: "Perl Beginners" <[EMAIL PROTECTED]>
Sent: Saturday, September 20, 2003 2:34 PM
Subject: Single and Double quotes in SQL


> Hi!
>
> I need to save some HTML text in a DataBase (MySql, using DBI). However
> some HTML text will have single and double quotes, so.. how can I save
> them?, for example:
>
> It's so funny
>
> Thanks!
> Pablo
> -- 
> Pablo Fischer Sandoval (pablo -arroba- pablo.com.mx)
> http://www.pablo.com.mx
> http://www.debianmexico.org
> GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
> Firma URL: http://www.pablo.com.mx/firmagpg.txt
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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



bitwise xor of two long bitstrings

2003-09-19 Thread Jian Kang

I got a problem of finding the difference of two
bit(binary) strings,

eg:
$a = "01";
$b = "11";

differs by: 1

Is there a good way to solve this when $a and $b are
very long, like:
$a = "00111010011110010"
$b = "1110110101011110010010010"

I used 'vec' function to extract each bit and compare,
the code is really ugly, please, if you have some
better idea. Thanks.

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Re: bitwise xor of two long bitstrings

2003-09-19 Thread Jeff 'japhy' Pinyan
On Sep 18, Jian Kang said:

>eg:
>$a = "01";
>$b = "11";
>
>differs by: 1

So why can't you use the ^ (xor) operator?

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



checking for anything other than a number

2003-09-19 Thread dan
i have a string $limit and i need to check it contains numbers and nothing
else.

i thought ($limit !~ /\d/) did the job, since i used to be good at this,
i've slacked the last 6 months or so, and forgotten some of the more obvious
things. when i find out, i'll probably slap myself and go "ahh that's it!"

thanks in advance

dan



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



Re: avoid repitive code while sorting hash arrays

2003-09-19 Thread Rob Dixon

Ramprasad wrote:
>
> Rob Dixon wrote:
> >
> >
> > Will this do?
> >
> > sort {
> >   my ($va, $vb) = map $$hash{$_}{$sortkey}, $direction eq 'a' ? ($a, $b) : ($b, 
> > $a);
> >   $sortkey eq 'uname' ? $va cmp $vb : $va <=> $vb;
> > } keys %$hash;
> >
> > Cheers,
> >
> > Rob
> >
> >
>
> Gr8 Now the code looks more neat.
> Thanks
>
> Do you think doing an explicit
>   'if($direction eq 'a') { ...} else { ...}
> Will be less expensive, because in that case the $direction is
> checked only once here It is checked in every loop. That means
> bigger the hash, heavier the code will become
>
> Can I not dynamically create my sort function , without the ifs ,  to
> suit the parameters on the fly and then use the sort function on the
> entire hash
>
> Well anyway my actual data is not very big.
> If I have to compromise on some cpu-cycles versus the
> code-readability I will go for better code-readability.

Precisely. A dynamic subroutine would be only be more efficient
if the compilation overhead of an 'eval' is less than the total
of all the additional tests. My guess is that you'd need quite
a lot of data for that to be true, but the only way to tell for
sure is to benchmark it.

Anyway, I always say that you should start by writing code so that
works, and then only optimise it if it is running too slowly. No-one
will thank you for writing a command-line utility that runs in 50ms
instead of 150ms.

However, it is an interesting exercise, so here's my effort below.

Cheers,

Rob



my $sub = '$$hash{$a}{$sortkey} <=> $$hash{$b}{$sortkey}';
if ($direction ne 'a') {
  $sub =~ s/\$b/\$a/;
  $sub =~ s/\$a/\$b/;
}
$sub =~ s/<=>/cmp/ if $sortkey eq 'uname';
$sub = eval "sub { $sub }";

my @keys = sort $sub keys %$hash;




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



Re: checking for anything other than a number

2003-09-19 Thread Jeff 'japhy' Pinyan
On Sep 19, dan said:

>i have a string $limit and i need to check it contains numbers and nothing
>else.
>
>i thought ($limit !~ /\d/) did the job, since i used to be good at this,
>i've slacked the last 6 months or so, and forgotten some of the more obvious
>things. when i find out, i'll probably slap myself and go "ahh that's it!"

You can use

  if ($limit =~ /^\d+$/) {
# it's only digits (and a possible newline at the end)
  }

or

  if ($limit !~ /\D/) {
# $limit does NOT have a NON-digit
  }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: checking for anything other than a number

2003-09-19 Thread Rob Dixon
Dan wrote:
> i have a string $limit and i need to check it contains numbers and nothing
> else.
>
> i thought ($limit !~ /\d/) did the job, since i used to be good at this,
> i've slacked the last 6 months or so, and forgotten some of the more obvious
> things. when i find out, i'll probably slap myself and go "ahh that's it!"

Hi Dan.

  $limit !~ /\d/

will be true if $limit contains no numeric characters at all.
You want

  $limit !~ /\D/

which will be true if it contains no non-numeric characters.

Don't slap too hard :)

Rob



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



Re: bitwise xor of two long bitstrings

2003-09-19 Thread Rob Dixon
Jian Kang wrote:
>
> I got a problem of finding the difference of two
> bit(binary) strings,
>
> eg:
> $a = "01";
> $b = "11";
>
> differs by: 1
>
> Is there a good way to solve this when $a and $b are
> very long, like:
> $a = "00111010011110010"
> $b = "1110110101011110010010010"
>
> I used 'vec' function to extract each bit and compare,
> the code is really ugly, please, if you have some
> better idea. Thanks.

Type one hundred times "I must never use $a and $b as
variable names" :)

If you use Jeff's suggestion of bitwise-oring the whole
string you will get a string of bytes with values zero
and one, rather then the characters '0' and '1'. To make
this printable just 'or' in a string of zeroes of the
right length. See below.

Beware that you must make sure that both string are the
same length before you do this, otherwise it won't work.
(Add leading zeroes to the shorter string to correct it.)

HTH,

Rob


use strict;
use warnings;

my $aa = "00111010011110010";
my $bb = "1110110101011110010010010";
my $dd = $aa ^ $bb;
$dd |= '0' x length $dd;

print map "$_\n", ($aa, $bb, $dd);

**OUTPUT**

00111010011110010
1110110101011110010010010
111011101001000101010




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



Re: Split based on length

2003-09-19 Thread Rob Dixon
Nyimi Jose wrote:
>
> IMHO
> $string =~ /.{1,$len}/g;
> Is the best suggestion i have seen so far ;)
>
> I have an other request : "code review" :-)
> Below is my final code.
> I'm sure that you guys will find
> Some better style to write it ...
>
> #!/usr/local/bin/perl -w
> use strict;
> #--
> #Global variables
> #--
> my $group_len=64;
> my $index_len='A1';
> my $name_len='A6';
> my $way_len='A3';
> my $delim_len='x1';
> my $meas_len='A5';
> my $nof_meas=9;
> #--
> #Main
> #--
> my $file=$ARGV[0];
> open(FH,$file) || die "can not open $file : $! \n";
>
> while(my $line=){
> next if $. < 3;
>
> my($date,$dummy,$str)=$line=~/(\d{2}-\d{2}-\d{4}:\d{3})\s+(\d{2})(.+)/;
>   for( &split_len($str,$group_len) ){
>  print $date."\t", join( "\t",&get_fields($_) ),"\n";
>   }
> }
> close(FH);
> #
> #Subroutines
> #
> sub split_len{
>   my ($str, $len) = @_;
>   $str =~ /.{1,$len}/g;
> }
>
> sub get_fields{
>   my($str)[EMAIL PROTECTED];
>   my $format="$index_len $name_len $way_len";
>   $format.=" $delim_len $meas_len" x $nof_meas;
>   unpack($format,$str);
> }

Well you did ask :) How about this.

Cheers,

Rob


use strict;
use warnings;

use constant GROUP_LEN  => 64;
use constant INDEX_LEN  => 1;
use constant NAME_LEN   => 6;
use constant WAY_LEN=> 3;
use constant DELIM_LEN  => 1;
use constant MEAS_LEN   => 5;
use constant NOF_MEAS   => 9;

my $format = join ' ', map "A$_", (
  INDEX_LEN,
  NAME_LEN,
  WAY_LEN,
  (DELIM_LEN, MEAS_LEN) x NOF_MEAS
);

{
  local @ARGV = $ARGV[0];

  while (<>) {

next if $. < 3;

my ($date, $str) = / (\d{2}-\d{2}-\d{4}:\d{3}) \s+ \d\d (.+) /x;

foreach ( split_len ($str, GROUP_LEN) ) {
   print join ("\t", $date, unpack $format, $str), "\n";
}
  }
}

sub split_len{
  my ($str, $len) = @_;
  $str =~ /.{1,$len}/g;
}



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



RE: Split based on length

2003-09-19 Thread NYIMI Jose (BMB)
I need some explanation on following:

1. my skill of perl tells me so far to handle exceptions and write :
open(FH,$file) || die "can not open $file : $! \n";
I've tried your code with a wrong file_name and got following message:
"Can't open in.txt1: No such file or directory at parser2.pl line 22."
How do you magically handle exception without writting any code for that ? :-)

2. where are you reading here : while(<>) ?
There is no file handle ?
Link to perldoc appreciated...

3. why did you put the main loop into a lexical scope ?

{
  local @ARGV = $ARGV[0];
  while (<>) {
  }
}

4. why have you added the 'x' at
/ (\d{2}-\d{2}-\d{4}:\d{3}) \s+ \d\d (.+) /x

5. the $format from your code is :
'A1 A6 A3 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5'

What i want is :
'A1 A6 A3 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5'
Skip the delimeter!
Could you make the change here please ?

Thanks,

José.


-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 4:47 PM
To: [EMAIL PROTECTED]
Subject: Re: Split based on length


Nyimi Jose wrote:
>
> IMHO
> $string =~ /.{1,$len}/g;
> Is the best suggestion i have seen so far ;)
>
> I have an other request : "code review" :-)
> Below is my final code.
> I'm sure that you guys will find
> Some better style to write it ...
>
> #!/usr/local/bin/perl -w
> use strict;
> #--
> #Global variables
> #--
> my $group_len=64;
> my $index_len='A1';
> my $name_len='A6';
> my $way_len='A3';
> my $delim_len='x1';
> my $meas_len='A5';
> my $nof_meas=9;
> #--
> #Main
> #--
> my $file=$ARGV[0];
> open(FH,$file) || die "can not open $file : $! \n";
>
> while(my $line=){
> next if $. < 3;
>
> my($date,$dummy,$str)=$line=~/(\d{2}-\d{2}-\d{4}:\d{3})\s+(\d{2})(.+)/;
>   for( &split_len($str,$group_len) ){
>  print $date."\t", join( "\t",&get_fields($_) ),"\n";
>   }
> }
> close(FH);
> #
> #Subroutines
> #
> sub split_len{
>   my ($str, $len) = @_;
>   $str =~ /.{1,$len}/g;
> }
>
> sub get_fields{
>   my($str)[EMAIL PROTECTED];
>   my $format="$index_len $name_len $way_len";
>   $format.=" $delim_len $meas_len" x $nof_meas;
>   unpack($format,$str);
> }

Well you did ask :) How about this.

Cheers,

Rob


use strict;
use warnings;

use constant GROUP_LEN  => 64;
use constant INDEX_LEN  => 1;
use constant NAME_LEN   => 6;
use constant WAY_LEN=> 3;
use constant DELIM_LEN  => 1;
use constant MEAS_LEN   => 5;
use constant NOF_MEAS   => 9;

my $format = join ' ', map "A$_", (
  INDEX_LEN,
  NAME_LEN,
  WAY_LEN,
  (DELIM_LEN, MEAS_LEN) x NOF_MEAS
);

{
  local @ARGV = $ARGV[0];

  while (<>) {

next if $. < 3;

my ($date, $str) = / (\d{2}-\d{2}-\d{4}:\d{3}) \s+ \d\d (.+) /x;

foreach ( split_len ($str, GROUP_LEN) ) {
   print join ("\t", $date, unpack $format, $str), "\n";
}
  }
}

sub split_len{
  my ($str, $len) = @_;
  $str =~ /.{1,$len}/g;
}



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



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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



Re: TK

2003-09-19 Thread Dan Anderson
> 1. Get the book Mastering Perl/Tk.  It is very good. You can get
> it on Safari if you are in a hurry or want an online version.

Get it on safari no matter what.  $15 a month for 10 books is so much
better then shelling out $50 a computer book every time you need to
learn some new tricks.  safari.oreilly.com <-- Check it out.

Heck, there's even a free 14 day trial, so you could try it and print
out up to 10 books and leave.  And that wouldn't be very hard if you
wrote a small script to parse the HTML and throw it into a file (i.e.
strip out the O'reilly tables).

-Dan


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



Re: bitwise xor of two long bitstrings

2003-09-19 Thread Dan Anderson
Could you just create two arrays, @comp1 and @comp2 .

Then run a foreach loop for every char in the string and push @comp1,
@char_from_a, do the same for $b, and then foreach pop out the front see
whether they compare?

-Dan

On Fri, 2003-09-19 at 00:47, Jian Kang wrote:
> I got a problem of finding the difference of two
> bit(binary) strings,
> 
> eg:
> $a = "01";
> $b = "11";
> 
> differs by: 1
> 
> Is there a good way to solve this when $a and $b are
> very long, like:
> $a = "00111010011110010"
> $b = "1110110101011110010010010"
> 
> I used 'vec' function to extract each bit and compare,
> the code is really ugly, please, if you have some
> better idea. Thanks.
> 
> __
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com


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



RE: TK

2003-09-19 Thread NYIMI Jose (BMB)
Are limitations of Perl/Tk listed some where ?

José.

-Original Message-
From: zentara [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 5:27 PM
To: [EMAIL PROTECTED]
Subject: Re: TK


On Fri, 19 Sep 2003 08:13:19 -0400, [EMAIL PROTECTED] (Paul Kraus)
wrote:

>I saw someone mention that tk was the better route to go for a UI then 
>a web interface. I have several office applications that I have written 
>that I was going to write html interfaces for. I would love to avoid 
>having to learn web development to :) Can anyone give me a break down 
>on what tk is and how easy it is to pick up? I have several projects 
>that are just about finished minus any real GUI. Also any web resources 
>or book recommendations would be nice. Thanks
>
>Paul

I'm no Tk expert, but I'm picking it up slowly but surely.
It's pretty easy to understand after you get the idea of
how the Tk MainLoop runs, and the object oriented interface.

1. Get the book Mastering Perl/Tk.  It is very good. You can get
it on Safari if you are in a hurry or want an online version.


2. Subscribe to the newsgroup comp.lang.perl.tk
 The experts are always there to answer questions, they expect
 you to read the book though.

3. Check out http://perltk.org  if you havn't already.

Tk has some limitations, but the experts on comp.lang.perl.tk will often offer 
workaround solutions.



Our body's 20 milligrams of beta radioactive Potassium 40
emit about 340 million neutrinos per day, which go at lightspeed to the ends of the 
universe!..even thru the earth. 

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



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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



Re: Split based on length

2003-09-19 Thread Rob Dixon
Nyimi Jose wrote:
>
> I need some explanation on following:
>
> 1. my skill of perl tells me so far to handle exceptions and write :
> open(FH,$file) || die "can not open $file : $! \n";
> I've tried your code with a wrong file_name and got following message:
> "Can't open in.txt1: No such file or directory at parser2.pl line 22."
> How do you magically handle exception without writting any code for that ? :-)
>
> 2. where are you reading here : while(<>) ?
> There is no file handle ?
> Link to perldoc appreciated...

When the null filehandle is used to read files named on the
command line the files are opened implicitly and a warning
is issued for any open failure.

Take a look at

  perldoc perlop (search for 'null filehandle')

> 3. why did you put the main loop into a lexical scope ?
>
> {
>   local @ARGV = $ARGV[0];
>   while (<>) {
>   }
> }

So that I could use 'local' to save the original command-line
parameters. I'm discarding all parameters after the first, which
will be replaced at the end of the scope in case later code
requires anything else from the command line.

> 4. why have you added the 'x' at
> / (\d{2}-\d{2}-\d{4}:\d{3}) \s+ \d\d (.+) /x

For the same reason you put spaces in the 'unpack' format. The
/x modifier makes whitespace irrelevant within the regex so that
it can be used for layout. If you need to match real spaces you
have to use \x20 (or \s which will match any whitespace character
including space).

> 5. the $format from your code is :
> 'A1 A6 A3 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5 A1 A5'
>
> What i want is :
> 'A1 A6 A3 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5 x1 A5'
> Skip the delimeter!
> Could you make the change here please ?

Sorry, I missed that. Try this.

  my $format = join ' ', map "A$_", (INDEX_LEN, NAME_LEN, WAY_LEN);
  $format = join ' x ', $format, map "A$_", (MEAS_LEN) x NOF_MEAS;

I've used 'x' instead of 'x1' as the '1' isn't needed.

HTH,

Rob



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



RE: TK

2003-09-19 Thread Paul Kraus
First of I never even knew about safari until today :( Talk about money
I could have saved At any rate.

I can't seem to find tk via ppm for AS perl. Any suggestions on where to
get it? I can't really compile on w32. I am missing the c libraries and
a compiler. 

Am I able to write a network app say on one of my Linux servers? Then
provide a gui that would run on the w32 workstations? Do I have to
install perl / tk on all of the workstations to do this?

Paul

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 11:33 AM
To: zentara
Cc: [EMAIL PROTECTED]
Subject: Re: TK


> 1. Get the book Mastering Perl/Tk.  It is very good. You can get
> it on Safari if you are in a hurry or want an online version.

Get it on safari no matter what.  $15 a month for 10 books is so much
better then shelling out $50 a computer book every time you need to
learn some new tricks.  safari.oreilly.com <-- Check it out.

Heck, there's even a free 14 day trial, so you could try it and print
out up to 10 books and leave.  And that wouldn't be very hard if you
wrote a small script to parse the HTML and throw it into a file (i.e.
strip out the O'reilly tables).

-Dan


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


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



RE: TK

2003-09-19 Thread Dan Anderson
On Fri, 2003-09-19 at 12:17, Paul Kraus wrote:
> First of I never even knew about safari until today :( Talk about money
> I could have saved At any rate.
HeheheI feel your pain.  I calculated the price of my entire bookshelf when I 
found safari and nearly broke down into tears.

> I can't seem to find tk via ppm for AS perl. Any suggestions on where to
> get it? I can't really compile on w32. I am missing the c libraries and
> a compiler. 

Did you try CPAN?

> Am I able to write a network app say on one of my Linux servers? Then
> provide a gui that would run on the w32 workstations? Do I have to
> install perl / tk on all of the workstations to do this?

I remember somebody saying that you can but you would need to have an X
Server for windows or something.  Don't quote me on that though.  TK
applications are portable across platforms though.  I can't tell you
much more -- don't quite know about TK.

-Dan


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



RE: TK

2003-09-19 Thread Akens, Anthony
I think that TK is included in AS perl for windows.  I copied
Paul privately with a sample Perl TK script to try, so he'll know
if he has it.  (I was surprised to find that I did!)

Didn't want to copy it on to the list, it's a bit large (20k) to
flood the list with. (It's the game "Same Game" done in TK, I got
it from the perlmonks site)

Tony

-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED]
Sent: Friday, September 19, 2003 11:18 AM
To: 'Dan Anderson'; 'zentara'
Cc: [EMAIL PROTECTED]
Subject: RE: TK


First of I never even knew about safari until today :( Talk about money
I could have saved At any rate.

I can't seem to find tk via ppm for AS perl. Any suggestions on where to
get it? I can't really compile on w32. I am missing the c libraries and
a compiler. 

Am I able to write a network app say on one of my Linux servers? Then
provide a gui that would run on the w32 workstations? Do I have to
install perl / tk on all of the workstations to do this?

Paul

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 11:33 AM
To: zentara
Cc: [EMAIL PROTECTED]
Subject: Re: TK


> 1. Get the book Mastering Perl/Tk.  It is very good. You can get
> it on Safari if you are in a hurry or want an online version.

Get it on safari no matter what.  $15 a month for 10 books is so much
better then shelling out $50 a computer book every time you need to
learn some new tricks.  safari.oreilly.com <-- Check it out.

Heck, there's even a free 14 day trial, so you could try it and print
out up to 10 books and leave.  And that wouldn't be very hard if you
wrote a small script to parse the HTML and throw it into a file (i.e.
strip out the O'reilly tables).

-Dan


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


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


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



RE: TK

2003-09-19 Thread Paul Kraus
Yep. Thanks. I just assumed it would not have been included.

Paul

-Original Message-
From: Akens, Anthony [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 12:53 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: TK


I think that TK is included in AS perl for windows.  I copied Paul
privately with a sample Perl TK script to try, so he'll know if he has
it.  (I was surprised to find that I did!)

Didn't want to copy it on to the list, it's a bit large (20k) to flood
the list with. (It's the game "Same Game" done in TK, I got it from the
perlmonks site)

Tony

-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED]
Sent: Friday, September 19, 2003 11:18 AM
To: 'Dan Anderson'; 'zentara'
Cc: [EMAIL PROTECTED]
Subject: RE: TK


First of I never even knew about safari until today :( Talk about money
I could have saved At any rate.

I can't seem to find tk via ppm for AS perl. Any suggestions on where to
get it? I can't really compile on w32. I am missing the c libraries and
a compiler. 

Am I able to write a network app say on one of my Linux servers? Then
provide a gui that would run on the w32 workstations? Do I have to
install perl / tk on all of the workstations to do this?

Paul

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 19, 2003 11:33 AM
To: zentara
Cc: [EMAIL PROTECTED]
Subject: Re: TK


> 1. Get the book Mastering Perl/Tk.  It is very good. You can get
> it on Safari if you are in a hurry or want an online version.

Get it on safari no matter what.  $15 a month for 10 books is so much
better then shelling out $50 a computer book every time you need to
learn some new tricks.  safari.oreilly.com <-- Check it out.

Heck, there's even a free 14 day trial, so you could try it and print
out up to 10 books and leave.  And that wouldn't be very hard if you
wrote a small script to parse the HTML and throw it into a file (i.e.
strip out the O'reilly tables).

-Dan


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


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


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


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



Re: list-parsing problem

2003-09-19 Thread John W. Krahn
Marcus Claesson wrote:
> 
> Hi People,

Hello,

> I have a silly little list-parsing problem that I can't get my head
> around, and I'm sure some of you have come across it before.
> 
> I have a list like this:
> 
> 1   a
> 2   b
> 2   c
> 3   a
> 4   d
> 4   d
> 4   e
> 4   f
> 5   g
> 
> and I want to make the first column non-redundant and collect the second
> column values on the same line, like this:
> 
> 1   a
> 2   b,c
> 3   a
> 4   d,e,f
> 5   g
> 
> Please note that line 4 only has one 'd'.
> 
> I've tried with both hashes and arrays (don't want to confuse you so I
> won't display them here), but nothing really works...
> 
> I would really appreciate any help!


Here is one way to do it:

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

my %data;
while ( <> ) {
my ( $key, $val ) = split or next;
if ( exists $data{ $key } ) {
$data{ $key }{ $val }++;
}
else {
print "[EMAIL PROTECTED] join ',', sort keys %{$data{$_}} ]}\n" for keys %data;
%data = ( $key => { $val, 0 } );
}
}
print "[EMAIL PROTECTED] join ',', sort keys %{$data{$_}} ]}\n" for keys %data;

__END__



John
-- 
use Perl;
program
fulfillment

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



manipulate Win2K IP/subnet/DNS?

2003-09-19 Thread Chris McMahon


Hello again...
Jenda pointed me to the Win32::FileOp module (thanks!) to manipulate
drives; now I wonder if it's possible to manipulate the local "Internet
Protocol (TCP/IP)" settings: IP address; Subnet mask; Default gateway; DNS
servers.   
I've been surfing CPAN without success-- any suggestions would be
welcome.   
-Chris   

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



Re: Read Directory Name

2003-09-19 Thread John W. Krahn
Dumitru Orza wrote:
> 
> Hello all,

Hello,

> is there any way to assign names of directories to a list ?

opendir DIR, '.' or die "Cannot open the current directory: $!";
my @dirs = grep -d, readdir DIR;
closedir DIR;


> Ideea is to check the existance of some directories and not create them again.

perldoc -f -d


John
-- 
use Perl;
program
fulfillment

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



Re: Recursively scanning a directory on Mac OS X for size & Timestap

2003-09-19 Thread John W. Krahn
Shishir Saxena wrote:
> 
> Hi,

Hello,

> I'm doing the following and the purpose is to genrate a HTML log file. But
> the script says "Can not apply stat : No such file or directory found"
> Can someone plz tell me where I'm going wrong ?

use warnings;
use strict;

> use File::Find;
> use File::stat;
> 
> open (OUT,">./out.html");

You should _ALWAYS_ verify that the file opened correctly.

open (OUT,">./out.html") or die "Cannot open out.html: $!";


> $Root = $ARGV[0];
> print $Root;
> 
> my $var;
> 
> print OUT '
> 
> 
> 
> 
> 
> 
> Path of File
> 
> 
> 
> 
> 
>   
> Path of
> File
> File
> Version
> Build
> Number
> Size on
> Disk
> Timestamp
>   ';
> 
> find (\&wanted,"$Root");

You don't need to enclose scalar variables in quotes, $Root is already a
string.

  find( \&wanted, $Root );


> print OUT '  
>  
> 
> 
> 
> ';
> 
> sub wanted()
^^
Why are you using a prototype here?


> {
>if (-d $File::Find::name)
>{
> return;
> }
>$file = $File::Find::name;
>$file =~ s/\//\\/g;

You are changing all the slashes to backslashes so of course stat can't
find the file.


>$st = stat($file);
>$size = $st->size;
>$size = ($size/1024)."KB ($size bytes)";
>$time = scalar localtime $st->mtime;

If you remove the "use File::stat;" line at the top you can do what you
want like this:

sub wanted {
my $time = scalar localtime ( stat )[ 9 ];
return if -d _;
my $size = -s _;
$size = ( $size / 1024 ) . "KB ($size bytes)";
my $file = $File::Find::name;


> print OUT '
>   
> '."$file".'
> Not Available
> Not Available
> '."$size".'
> '."$time".'
> ';


John
-- 
use Perl;
program
fulfillment

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



install Tk800.025 no 'ClientWin.o' file

2003-09-19 Thread Ying Liu
Hi all,

I am trying to install the Tk800.025 package, it told me:
ar: ClientWin.o: No such file or directory
make[1]: *** [libpTk.a] Error 1
make[1]: Leaving directory `/mz/hd/liuyi/local/Tk800.025/pTk'
make: *** [pTk/libpTk.a] Error 2


I use gcc and it said 'unrecognized option'-KPIC'. What's that mean? Anyone can 
help? 

Thanks,
Ying


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



Re: TK

2003-09-19 Thread Todd W.

"Paul Kraus" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

>
> Am I able to write a network app say on one of my Linux servers? Then
> provide a gui that would run on the w32 workstations? Do I have to
> install perl / tk on all of the workstations to do this?
>
Sure you can, if you like maintenance and upgrade headaches. The problems
involved in doing what you propose are why web apps were invented.

If you are going to write a desktop GUI that is nothing more than a thin
client that connects to the application server, you will be writing a
program called a web browser. You'll not only be reinventing the wheel,
you'll be reinventing the internet. Good luck.

Todd W.



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