manipulating X clipboard

2004-02-16 Thread Paul William
Hi,

Does anyone know if there are any perl modules that will allow me to 
manipulate the X clipboard. I have searched cpan.org but didnt find 
anything.

Thanks

Paul

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



RE: Looking up values in arrays?

2004-02-16 Thread David le Blanc

use List::Util "first";

sub has_element($$)
{
my( $aref, $value ) = @_;
first { $aref->[$_] eq $value } 0..$#$aref
}

?


-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Monday, 16 February 2004 10:57 PM
To: [EMAIL PROTECTED]
Subject: Re: Looking up values in arrays?

Paul Johnson wrote:
>
> > Is there a function to find out if a given value exists in an array?
> >
> > What I think of is something like &has_element([EMAIL PROTECTED], $value), 
> > which should return either a boolean value or the index containing 
> > the value (undef if $value is not found).
> > I'm sure something like this exists. Or do I need to write this
myself?
>
> Something close exists.  I think I'd probably code it as:
>
> use List::Util "first";
>
> sub has_element
> {
> my ($array, $value) = @_;
> first { $_ eq $value } @$array
> }

Except that this will return the /value/ of the element for which the
block returns true, which isn't obvious from the call. It's identical to

  sub has_element {

my ($array, $value) = @_;

foreach (@$array) {
  return $_ if $_ eq $value;
}

return;
  }

which, to my mind, is preferable as it is clearer what's going on. It's
certainly no slower.

Rob



--
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: data filtering

2004-02-16 Thread David le Blanc

Aha.   The problem here is 
*how do I implement a parser to process a table of data based on a user
supplied query*

Ok, look at the following:-

#!/usr/bin/perl

use strict; - matter of style
use warnings;   - and again

# This DATASET has the following columns, with these names in this
order.
my @col = qw( x1 x2 x3 y1 y2 y3 y4 );

# Fabricate a set of functions (subs) in the 'filter' name space which
parallel
# the column names, and enchant each with the ability to look up a data
element.
# Note the use of 'my $i=$_' This tweaks some magic in perl and causes
the automatically
# generated functions to be *closures* and not just normal functions.  

map{ my $i=$_; no strict 'refs'; *{"filter::$col[$i]"} = sub{$_->[$i]} }
0..$#col;

# This is your data set.  If you want 'line number as the first col
remember to add it to
# '@col' above.

my @data=(
   [qw(   0.20   0.20   0.20   0.76568575881.9
29289.3 -46592.6)],
   [qw(   0.200345   0.20   0.200345   0.9175766.0
29268.4 -46497.6)],
   [qw(   0.20   0.200345   0.20   0.76603075867.1
29259.8 -46607.4)],
   [qw(   0.359575   0.253987   0.359575   1.27101943898.7
19675.6 -24223.1)],
   [qw(   0.359921   0.253987   0.359921   1.27199543861.3
19666.1 -24195.2)]
);

# Perform filtering.  First parameter is a $coderef which is passed to
GREP for the
# actual filtering task.
sub filterdata($@)
{
my $cref=shift;
grep &$cref,@_
}

# Build the coderef for the specified data filter.  The (only) parameter
is the
# text string 'x1 > 5'  etc.
sub filterspec
{
my $e = shift;
map{ $e =~ s/\b$_\b/filter::$_()/g } @col;
eval "sub{ $e }"
}

# Here goes...

# I want to filter according to the following spec:
my $expr = "x1 > 0.2 && x1 < 0.3 && y1 > 0.8 && y3 > 15000 && y3 <
3";

# Compile the spec into a handler... The DIE will catch errors compiling
the filter.
# This usually occurs because you do silly things, call non-existent
functions, or 
# use column names which don't exist.

my $filter_handler = filterspec( $expr ) or die $@;

# Perform the filter using the handler.
my @result = filterdata $filter_handler,@data;

# Display the table of results.
print join("$/",map{join(" ",@$_)[EMAIL PROTECTED]).$/;

This outputs one row:
0.200345 0.20 0.200345 0.91 75766.0 29268.4 -46497.6

Now remember. I fiddled the data and expression so they that WOULD match
one line.  Your sample data matched nothing.

How does this help?  I'm sorry if it is less readable than the specific
implementation of a particular filter.

--

Thanks Mr.David for the response. 
I want the same logic in a generalized manner, because the conditions
keep changing as the data changes. Also in each condition string, the
delimiters  can be anything (like  <, >, <=, >=, or =). Hence I would
like to have a more generalized way.  

Your solution has given me a way to think further ahead. Further help in
this regard is solicited. 

Thanks
Regards
Guruguhan
EACoE, India.

-Original Message-
From: David le Blanc [mailto:[EMAIL PROTECTED]
Sent: Monday, February 16, 2004 6:34 PM
To: N, Guruguhan (GEAE, Foreign National, EACOE); [EMAIL PROTECTED]
Subject: RE: data filtering



Guruguhan,

Can I assume you have the data in memory?
Can I further assume the data is contained in an array of arrays?
Can I also further assume that the conditions you mentioned are AND'd?
(ie
  the final result is the intersection of all conditions?)

Thus $data[0][0] = 0.20 (aka, X1 from row 1)

Consider the following:  (purposely written in readable perl)

my @filtered = ();
for( @data ){
push @filtered,$_ if
$$_[0] > 0.2 && $$_[0] < 0.3 && # 0.2 < x1 < 0.3
$$_[3] > 0.8 &&   # y1 > 0.8
$$_[5] > 15000 && $$_[5] < 3;   # 15000 < y3 < 3
}

[EMAIL PROTECTED] data contains filtered result result.

Is that what you were thinking of?

Regards,

David le Blanc

--  
Senior Technical Specialist 
I d e n t i t y   S o l u t i o n s 

Level 1, 369 Camberwell Road, Melbourne, Vic 3124   
Ph 03 9813 1388 Fax 03 9813 1688 Mobile 0417 595 550
Email [EMAIL PROTECTED] 

-Original Message-
From: N, Guruguhan (GEAE, Foreign National, EACOE)
[mailto:[EMAIL PROTECTED]
Sent: Monday, 16 February 2004 10:47 PM
To: [EMAIL PROTECTED]
Subject: data filtering

Hi All,
  I have a data set ( only a portion) as follows:
   No. x1 x2 x3y1  y2y3
y4
   1   0.20   0.20   0.20   0.76568575881.929289.3
-46592.6
   2   0.200345   0.20   0.200345   0.7175766.029268.4
-46497.6
   3   0.20   0.200345   0.20   0.76603075867.129259.8
-46607.4
   4   0.359575   0.253987   0.359575   1.27101943898.719675.

Re: Help with array, hashes and objects

2004-02-16 Thread James Edward Gray II
On Feb 16, 2004, at 2:46 PM, george wrote:

I want to parse a long ns log text file, and I've attempted to write 
some
perl code to do that. I am a newbie, and I haven't managed to get my 
code
working.
I'll provide some general comments below.

Basically, the ns file contains information about TCP connections and 
I want
to create a perl object for each connection, and gather some data. The 
code
that I created is the following:
Is that one object per line/entry?  That sounds like a lot to me.

Have you considered making a Log object that stores all the information 
and provides summery information for it?

Just out of curiosity, why objects, over say a hash?

Please post some sample log data, so we can see what we're talking 
about here.  Help us help you.  ;)

package Connection;

sub new {
my ($class) = @_;
my $self = {
_packet_ids=> {},
_bytes_per_second => [],
_source_node => undef,
_destination_node => undef
};
bless $self, $class;
return $self;
}
I like my constructors like this:

sub new {
my $class = shift;
my $self = {
_packet_ids=> {},
_bytes_per_second => [],
_source_node => undef,
_destination_node => undef,
@_
};
return bless $self, $class;
}
Which is the same as you have it, except I can override default 
parameter choices at object creation.  I do realize that you're using 
the "_ Means Don't Touch" hint, so this may not be helpful in your 
case.  I'm pretty lax with object "security".  I prefer functionality 
and setting parameters in a constructor just makes sense to me.

sub addToBytesPerSecond {
my ( $self, $currentBytesPerSecond) = @_;
my $atLocation = $self->{_seconds_counter};
$self->{_bytes_per_second}[$atLocation] = 
$currentBytesPerSecond;
print "";
}
I think we can simplify that a little.  You just want to push an entry 
onto that array, right?

sub addToBytesPerSecond {
my $self = shift;
push @{ $self->{_bytes_per_second} }, @_;
}
How's that?  You can even add a whole list at once now.

sub printBytesPerSecond {
my ($self) = @_;
my $loopCounter = 0;
my $length = scalar($self->{_bytes_per_second});
while ($loopCounter < $length) {
print "$self->{bytes_per_second}[$loopCounter]\n";
$loopCounter++;
}
}
Good rule of Perl thumb:  If you're typing that much for something 
simple, like an output loop, you're probably taking the hard road.  
Easy things are easy in Perl.

sub printBytesPerSecond {
my $self = shift;
print "$_\n" foreach @{ $self->{_bytes_per_second} };
}
sub sourceNode {
my ( $self, $sourceNode ) = @_;
$self->{_source_node} = $sourceNode if defined($sourceNode);
return $self->{_source_node};
}
Using objects for everything... names like "sourceNode"...  You a Java 
guy?  :D

Perl style for subroutine names is generally "source_node".  We think 
it reads a little better and is easier on our eyes.  Just FYi.  Use 
whatever you like, of course.

Us Perl guys are also pretty allergic to extra variables we don't need. 
 We're weird that way.  He's how we generally write the above:

sub source_node {
my $self = shift;
$self->{_source_node} = shift if @_;
return $self->{_source_node};
}
sub destinationNode {
my ( $self, $destinationNode) = @_;
$self->{_destination_node} = $destinationNode if 
defined($destinationNode);
return $self->{_destination_node};
}
I'll let you trim that one, if you like.

The sourceNode and destinationNode functions work fine. But the
printBytesPerSecond and the addToBytesPerSecond functions do not work.
I can't understand what's wrong with them. Moreover, as you can see I 
also
want to have a hashtable with the packetIds that have been seen while
parsing, so as to filter duplicate packets. I didn't even attempt that,
because I couldn't understand how to insert a scalar into the hash, 
and how
to retrieve the value.
See if that gets you going.  If not, come back with sample data and 
usage code and we'll get you straightened out.

Good luck.

James

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



Re: LWP Logging or the such..

2004-02-16 Thread R. Joseph Newton
Martin R Morales wrote:

> Good Morning/Afternoon Everyone,
>
> I have been reading up on LWP::UserAgent and HTTP::Request of the LWP package.
> This is good stuff.
> But I am still confused about a couple of things. Here is ther senario. I have
> a file I want to download from
> my server and I can do that with LWP. But what I'm confused on is One: how do
> I save the file to a certain
> directory

That is not exactly the question at this point, because the response received
does not constitute a file while in transit.  When LWP::UserAgent receives a
response, it puts it into an HTTP::Response object   This object provides te
method content() to get the returned html. The request method, though, does
provide a means to automatically store this data to file.  The scond parameter
of request can be a string scalar, in which case the module uses this string as
the filename to save the data to.  The specific directory that you want to store
this data in is just part of the filename.

> once I have started the GET process; insted of it dumping to stdout?

Does LWP::UserAgent dump to STDOUT?  I don't think so.  The get and request
methods both return response objects, which the calling script can query and
print to STDOUT.

> The other part I am unclear on
> is this: if the site does not contain the file I am looking to GET, then I
> should receive the standard web response
> of 'file does not exist' or other responses like 'forbidden', etc. I am
> unclear how to 'log' these responses or redirect
> them to a file for later examination insted of dumping to stdout.

Like this:

Greetings! E:\d_drive\perlStuff>perl -MLWP::UserAgent
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET',
'http://www.isp.org/~some_user/missing_page.htm');
my $response = $ua->request($request);
print $response->content;
^Z


404 Not Found

Not Found
The requested URL /~some_user/missing_page.htm was not found on this server.

Apache/1.3.26 Server at members.isp.org Port 80


HTH,

Joseph


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




RE: another directory search, yet many subdirs

2004-02-16 Thread Matt Matijevich

under each of these suddirs, I need all the eml files deleted but there

are thousands of them and the actual file name is "training 2001.eml"
so my questions still remain, 

Can I have this search recursively down under all the pc subdir
names?


File::Find will do what you need.  Google can help you find some good
examples.


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




Re: How to rearrange an array by a hash

2004-02-16 Thread Jan Eden

John W. Krahn wrote:

>Shiping Wang wrote:
>> 
>> Hi,
>
>Hello,
>
>> How can I rearrange an array in a specific order based on the order of a
>> hash? Something like this:
>> 
>> my @a = qw(Mary John Dan);
>> print join "\t", @a, "\n";
>> 
>> my %b = ( John => 0,
>> Dan => 1,
>> Mary => 2);
>> 
>> print "$_ => $b{$_}\n" for (keys %b);
>> print "$_-$b{$_}\t" foreach sort {$b{$a} <=> $b{$b}} keys %b;
>> 
>> The final order for @a expect:  John Dan Mary
>
>
>$ perl -le'
>my @a = qw( Mary John Dan );
>my %b = qw( John 0 Dan 1 Mary 2 );
>print "@a";
>@a = sort { $b{ $a } <=> $b{ $b } } @a;
>print "@a";
>'
>Mary John Dan
>John Dan Mary
>
Smart. But the sort pattern might be easier on the eye the array and hash are not 
named @a and %b.

$ perl -le'
my @array = qw( Mary John Dan );
my %hash = qw( John 0 Dan 1 Mary 2 );
print "@array";
@array = sort { $hash{ $a } <=> $hash{ $b } } @array;
print "@array";
'
Mary John Dan
John Dan Mary

This is mainly for my own better understanding.

- Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho 
Marx

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




RE: another directory search, yet many subdirs

2004-02-16 Thread DBSMITH
David, 

under each of these suddirs, I need all the eml files deleted but there 
are thousands of them and the actual file name is "training 2001.eml"
so my questions still remain, 

Can I have this search recursively down under all the pc subdir names?
Can I create a scalar like "/home/emstat/win32/backup/012004155140/pc*" so 
it will store all the pc subdirs?
Can I use reg exp such as a range of pc80[0-9] pc13[0-9] ?

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





"Wagner, David --- Senior Programmer Analyst --- WGO" 
<[EMAIL PROTECTED]>
02/16/2004 06:02 PM

 
To: <[EMAIL PROTECTED]>, "Perl Beginners" <[EMAIL PROTECTED]>
cc: 
Subject:RE: another directory search, yet many subdirs


  [EMAIL PROTECTED] wrote:
> People of the Perl,
> 
> I am in need of some help!  Here is the info you need for my samba
> mount points.
> 
> directories:  ~emstat/win32/backup/012004155140/pc*,
> ~emstat/win32/backup/01210415175/pc*,  ~emstat/win32/pc*
> files: under each of these subdirs,  pc[#],  I have "training
> 2001.eml" files ( NOTE THE SPACE ) that I need deleted!
> so far this is what I have for my perl program
> 
> /usr/bin/perl -w
> use strict;
> 
> # Open dirs and search for string
> 
> $emdir="/home/emstat/win32/backup/012004155140";
> $emdir2="/home/emstat/win32/backup/012104151751";
> $emdir3=
> opendir(DEREK, "$emdir")
> || die "cannot open directory $!";
> opendir(SMITH, "$emdir2")
> || die "cannot open directory $!";
> 
> while (defined ($readdir = DEREK))
> 
> 
> My questions are how can I have this search recursively down under
> all the pc subdir names?
> Can I create a scalar like
> "/home/emstat/win32/backup/012004155140/pc*" so it will store all the
> pc subdirs? 
> Can I use reg exp such as a range of pc80[0-9] pc13[0-9] ?

 It si not clear in my mind the setup you have. The 
process you want to use is probably File::Find which comes as standard portion of all 
Perl installs.  If I could picture 
the setup in my mind, I could give you a better picture of what to do.

 Sorry.
Wags ;)
> 
> please help!
> 
> thank you,
> 
> 
> 
> Derek B. Smith
> OhioHealth IT
> UNIX / TSM / EDM Teams



**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.






RE: another directory search, yet many subdirs

2004-02-16 Thread Wagner, David --- Senior Programmer Analyst --- WGO
  [EMAIL PROTECTED] wrote:
> People of the Perl,
> 
> I am in need of some help!  Here is the info you need for my samba
> mount points.
> 
> directories:  ~emstat/win32/backup/012004155140/pc*,
> ~emstat/win32/backup/01210415175/pc*,  ~emstat/win32/pc*
> files: under each of these subdirs,  pc[#],  I have "training
> 2001.eml" files ( NOTE THE SPACE ) that I need deleted!
> so far this is what I have for my perl program
> 
> /usr/bin/perl -w
> use strict;
> 
> # Open dirs and search for string
> 
> $emdir="/home/emstat/win32/backup/012004155140";
> $emdir2="/home/emstat/win32/backup/012104151751";
> $emdir3=
> opendir(DEREK, "$emdir")
> || die "cannot open directory $!";
> opendir(SMITH, "$emdir2")
> || die "cannot open directory $!";
> 
> while (defined ($readdir = DEREK))
> 
> 
> My questions are how can I have this search recursively down under
> all the pc subdir names?
> Can I create a scalar like
> "/home/emstat/win32/backup/012004155140/pc*" so it will store all the
> pc subdirs? 
> Can I use reg exp such as a range of pc80[0-9] pc13[0-9] ?

It si not clear in my mind the setup you have. The process you want to use is 
probably File::Find which comes as standard portion of all Perl installs.  If I could 
picture the setup in my mind, I could give you a better picture of what to do.

Sorry.
Wags ;)
> 
> please help!
> 
> thank you,
> 
> 
> 
> Derek B. Smith
> OhioHealth IT
> UNIX / TSM / EDM Teams



**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



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




another directory search, yet many subdirs

2004-02-16 Thread DBSMITH
People of the Perl, 

I am in need of some help!  Here is the info you need for my samba mount 
points.

directories:  ~emstat/win32/backup/012004155140/pc*, 
~emstat/win32/backup/01210415175/pc*,  ~emstat/win32/pc*
files: under each of these subdirs,  pc[#],  I have "training 
2001.eml" files ( NOTE THE SPACE ) that I need deleted!
so far this is what I have for my perl program

/usr/bin/perl -w
use strict;

# Open dirs and search for string

$emdir="/home/emstat/win32/backup/012004155140";
$emdir2="/home/emstat/win32/backup/012104151751";
$emdir3=
opendir(DEREK, "$emdir")
|| die "cannot open directory $!";
opendir(SMITH, "$emdir2")
|| die "cannot open directory $!";

while (defined ($readdir = DEREK))


My questions are how can I have this search recursively down under all the 
pc subdir names?
Can I create a scalar like "/home/emstat/win32/backup/012004155140/pc*" so 
it will store all the pc subdirs?
Can I use reg exp such as a range of pc80[0-9] pc13[0-9] ?
 
please help!

thank you, 



Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



Re: LWP Logging or the such..

2004-02-16 Thread Rob Dixon
 Martin R Morales wrote:
>
> Martin R Morales wrote:
> >
> > I have been reading up on LWP::UserAgent and HTTP::Request of the LWP
> > package. This is good stuff.
> > But I am still confused about a couple of things. Here is ther
> > senario. I have a file I want to download from
> > my server and I can do that with LWP. But what I'm confused on is One:
> > how do I save the file to a certain
> > directory once I have started the GET process; insted of it dumping to
> > stdout? The other part I am unclear on
> > is this: if the site does not contain the file I am looking to GET,
> > then I should receive the standard web response
> > of 'file does not exist' or other responses like 'forbidden', etc. I
> > am unclear how to 'log' these responses or redirect
> > them to a file for later examination insted of dumping to stdout.
> >
> > Thus far I have a script that will do what I want it to do, but now I
> > need to understand how to save my file(s)
> > to disk insted of dumping to stdout, and logging the responses to a
> > file for review. Let me know if I have made myself unclear. I look
> > forward to hearing from
> > you all soon with your input and ideas.
> >
>
> I have figured out how to save to file ..
> I have to open a file handle .. duh? yeah .. i know.
> Okay, but I would still like suggestions on saving my http responses to
> file .. like a log file
> of what the script was trying to do on execute.

Hi Martin.

There are a few different ways you could be using the LWP library.
I don't understand how you got the output 'dumping to STDOUT' in the
first place. Have you check out the LWP::UserAgent::mirror method?

As for logging, what you're likely to want to do is

  print $request->as_string;

and

  print $response->status_line

where $request and $response are and HTTP::Request object and
an HTTP::Response object, respectively. More than that I can't
help without knowing what you want and what you're tried.

HTH,

Rob





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




Help with array, hashes and objects

2004-02-16 Thread george
I want to parse a long ns log text file, and I've attempted to write some
perl code to do that. I am a newbie, and I haven't managed to get my code
working.
Basically, the ns file contains information about TCP connections and I want
to create a perl object for each connection, and gather some data. The code
that I created is the following:

package Connection;

sub new {
my ($class) = @_;
my $self = {
_packet_ids=> {},
_bytes_per_second => [],
_source_node => undef,
_destination_node => undef
};
bless $self, $class;
return $self;
}

sub addToBytesPerSecond {
my ( $self, $currentBytesPerSecond) = @_;
my $atLocation = $self->{_seconds_counter};
$self->{_bytes_per_second}[$atLocation] = $currentBytesPerSecond;
print "";
}

sub printBytesPerSecond {
my ($self) = @_;
my $loopCounter = 0;
my $length = scalar($self->{_bytes_per_second});

while ($loopCounter < $length) {
print "$self->{bytes_per_second}[$loopCounter]\n";
$loopCounter++;
}
}


sub sourceNode {
my ( $self, $sourceNode ) = @_;
$self->{_source_node} = $sourceNode if defined($sourceNode);
return $self->{_source_node};
}

sub destinationNode {
my ( $self, $destinationNode) = @_;
$self->{_destination_node} = $destinationNode if defined($destinationNode);
return $self->{_destination_node};
}

The sourceNode and destinationNode functions work fine. But the
printBytesPerSecond and the addToBytesPerSecond functions do not work.
I can't understand what's wrong with them. Moreover, as you can see I also
want to have a hashtable with the packetIds that have been seen while
parsing, so as to filter duplicate packets. I didn't even attempt that,
because I couldn't understand how to insert a scalar into the hash, and how
to retrieve the value.

I would appreciate any help given.
G.


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




Re: How to rearrange an array by a hash

2004-02-16 Thread John W. Krahn
Shiping Wang wrote:
> 
> Hi,

Hello,

> How can I rearrange an array in a specific order based on the order of a
> hash? Something like this:
> 
> my @a = qw(Mary John Dan);
> print join "\t", @a, "\n";
> 
> my %b = ( John => 0,
> Dan => 1,
> Mary => 2);
> 
> print "$_ => $b{$_}\n" for (keys %b);
> print "$_-$b{$_}\t" foreach sort {$b{$a} <=> $b{$b}} keys %b;
> 
> The final order for @a expect:  John Dan Mary


$ perl -le'
my @a = qw( Mary John Dan );
my %b = qw( John 0 Dan 1 Mary 2 );
print "@a";
@a = sort { $b{ $a } <=> $b{ $b } } @a;
print "@a";
'
Mary John Dan
John Dan Mary



John
-- 
use Perl;
program
fulfillment

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




Re: shorten code

2004-02-16 Thread John W. Krahn
James Kipp wrote:
> 
> Hi

Hello,

> I want to split the string below into rows and then columns. I know i can do
> a couple of splits, push array refs onto a new array, regex it, etc.. But I
> was know the talented people on this list can shorten the code considerably.
> I want to split at each new line for the row, then split the row into
> columns, and get rid of the "%" on the third column. I can post my
> embarrassingly long code if you like.
> Thanks for any help
> Jim
> 
> 
> $str = "
> /var  0.9950%
> /usr  0.5871%
> /tmp  0.49 1%
> "


$ perl -le'
use Data::Dumper;
my $str = "
/var  0.9950%
/usr  0.5871%
/tmp  0.49 1% 
";
print Dumper \$str;
my @new = map [ split ], split /%\s+/, $str;
print Dumper [EMAIL PROTECTED];
'
$VAR1 = \'
/var  0.9950%
/usr  0.5871%
/tmp  0.49 1% 
';

$VAR1 = [
  [
'/var',
'0.99',
'50'
  ],
  [
'/usr',
'0.58',
'71'
  ],
  [
'/tmp',
'0.49',
'1'
  ]
];



John
-- 
use Perl;
program
fulfillment

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




Re: getting in between dates in a hash

2004-02-16 Thread Jan Eden

Joseph Alotta wrote:

>Greetings,
>
>I am having some conceptual problems doing what I think is a fairly
>simple perl task.  It is probably that my mind is just blank on
>this.  Could someone please recommend a strategy for this.
>
>I have a hash of data:
>
>%highest_level = ( 2001-10-14 =>  152, 2002-01-15 => 163, 2003-03-13 => 
>210, 2004-08-07 => 307 );
>
>And I am give some dates in between:
>
>@dates = ( 2001-12-30, 2002-03-19);
>
>I need to find what the highest level was on that date, matching
>between known dates.  This is the answer:
>
>%level = ( 2001-12-30 => 152, 2002-03-19 => 210);
>
>
You mean like this?

for (@dates) {
$level{$_} = $highest_level{$_};
}

HTH,

Jan
-- 
A common mistake that people make when trying to design something completely foolproof 
is to underestimate the ingenuity of complete fools.

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




RE: help on picking up key & values

2004-02-16 Thread Singh, Ajit p
Joseph,

Let me try and explain.
i have a perl script place_order which takes arguments as below:

1. ./place_order -t 
/thus/axioss/serviceID:123
/thus/axioss/supplierProduct:TestStream 500
/thus/axioss/web/installationTelephoneNumber:112237111663 etc

2. I have a source as a hash of key value pairs as in :

/thus/axioss/serviceID:123
/thus/axioss/supplierProduct:TestStream 500
/thus/axioss/web/installationTelephoneNumber:112237111663

3. All I need to do is call the script in 1. and pass these values..Pls note
that what i have in 2. is not a file.
Its a message structure with each line as key value pairs.

4. I dont have a control of either the target script i.e place_order or the
source as in 2.

5.My code needs to pick up this key valuse and invoke the target script.

Thanks for u r time.




regards,

Ajitpal Singh,


-Original Message-
From: R. Joseph Newton [mailto:[EMAIL PROTECTED]
Sent: 13 February 2004 23:56
To: Singh, Ajit p
Cc: 'Rob Dixon'; [EMAIL PROTECTED]
Subject: Re: help on picking up key & values


"Singh, Ajit p" wrote:

> Thanks Rob for your reply...
>
> My problem is :the values i pick up from is actually not a file.(Sorry
about
> that)
>
> The values are stored as an array of structs as key value pairs  i.e
> /thus/axioss/serviceID:123456
> /thus/axioss/supplierProduct:Test Stream 100
> /thus/axioss/web/installationTelephoneNumber:020837111663
>
> I hope i am being clear now.

Not really.  An array of structs has no meaning in Perl directly, AFAIK.
Perl
doesn't use structs.How are these values stored?  How do you get them
into
Perl.  Where do you get the values when you discuss them?  Please, instead
of
describing this in terms of programming structures, tell us what you
actually
have to work with coming in, and what you hope to get out of it.  What does
each
identifier mean, and where does the string come from?

It could be that having a data file with these keys and values stored in it
would be a good idea.  But what are they?  The coding part will probably
come
very simply if you can answer this question clearly.  Using technical
language
incorrectly will not get you closer to your goal

Keep it as simple as possible.  Describe real-world situations in plain
language
first.  This can then serve as a valuable guide to come back to when code
and
coding structures get mixed up.  It's what we call the reality check or
sanity
test.  Once your description makes sense in plain language, the coding part
generally is relatively straightforward.  I think your problem could be
resolved
quite simply, if you can refrain from injecting complication into it.

Joseph


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




Re: LWP Logging or the such..

2004-02-16 Thread Martin R Morales
Update::
I have figured out how to save to file ..
I have to open a file handle .. duh? yeah .. i know.
Okay, but I would still like suggestions on saving my http responses to 
file .. like a log file
of what the script was trying to do on execute.

~Martin

Martin R Morales wrote:

   Good Morning/Afternoon Everyone,

I have been reading up on LWP::UserAgent and HTTP::Request of the LWP 
package. This is good stuff.
But I am still confused about a couple of things. Here is ther 
senario. I have a file I want to download from
my server and I can do that with LWP. But what I'm confused on is One: 
how do I save the file to a certain
directory once I have started the GET process; insted of it dumping to 
stdout? The other part I am unclear on
is this: if the site does not contain the file I am looking to GET, 
then I should receive the standard web response
of 'file does not exist' or other responses like 'forbidden', etc. I 
am unclear how to 'log' these responses or redirect
them to a file for later examination insted of dumping to stdout.

Thus far I have a script that will do what I want it to do, but now I 
need to understand how to save my file(s)
to disk insted of dumping to stdout, and logging the responses to a 
file for review. Let me know if I have made myself unclear. I look 
forward to hearing from
you all soon with your input and ideas.

Thank You,
~Martin




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



LWP Logging or the such..

2004-02-16 Thread Martin R Morales
   Good Morning/Afternoon Everyone,

I have been reading up on LWP::UserAgent and HTTP::Request of the LWP 
package. This is good stuff.
But I am still confused about a couple of things. Here is ther senario. 
I have a file I want to download from
my server and I can do that with LWP. But what I'm confused on is One: 
how do I save the file to a certain
directory once I have started the GET process; insted of it dumping to 
stdout? The other part I am unclear on
is this: if the site does not contain the file I am looking to GET, then 
I should receive the standard web response
of 'file does not exist' or other responses like 'forbidden', etc. I am 
unclear how to 'log' these responses or redirect
them to a file for later examination insted of dumping to stdout.

Thus far I have a script that will do what I want it to do, but now I 
need to understand how to save my file(s)
to disk insted of dumping to stdout, and logging the responses to a file 
for review. Let me know if I have made myself unclear. I look forward to 
hearing from
you all soon with your input and ideas.

Thank You,
~Martin


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



Re: Checking prototype with objects

2004-02-16 Thread R. Joseph Newton
Rob Dixon wrote:

> R. Joseph Newton wrote:
> >
> > l Maldonado Torres wrote:
> >
> > >
> > > I am trying to use prototype functions with object but this seems not
> > > to work, I mean perl does not check for the type of arguments.
> > >
> > > I usually do this.
> > >
> > > sub array_print(\@);
> > > ...sub array_print(\@)
> > >   ...
> >
> > Your immediate problem here is that you are trying to use an expression as a
> > formal argument.  Formal arguments in Perl can only take storage types.  Really,
> > the only meaningful ones are scalar and list.  The list, if it is present, must
> > be the last parameter, and there can only be one, since any list will consume
> > all arguments offered from there on.
> >
> > The formal parmeter expressions you show are both array references.  These are
> > scalars.  They should be prtotyped as $.
>
> Sorry Joseph. This from perldoc perlsub
>
>   Prototypes
>
> Perl supports a very limited kind of compile-time argument checking
> using function prototyping. If you declare
>
> sub mypush (\@@)
>
> then "mypush()" takes arguments exactly like "push()" does.
>
> Cheers,
>
> Rob

Thanks, Rob,

That information actually makes prototypes at least marginally more useful.  If you
can specify the type to which a references refers, that certainly offers more
information than the simplescalar and list types I have seen.  It also provides a way
to set up more complicatedparameters lists and still use prototypes.

Joseph


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




RE: shorten code

2004-02-16 Thread Kipp, James
> 
>   my @data = map { tr/%//d; [split] } split /\n/, $str;
> 
> :)

Clever! but this may be the point where where it may be confusing as you and
Paul mentioned :)


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




Re: shorten code

2004-02-16 Thread Rob Dixon
James Kipp wrote:
>
> > > > $str = "
> > > > /var  0.9950%
> > > > /usr  0.5871%
> > > > /tmp  0.49 1%
> > > > "
> > >
> > >  my @rows = map [split], split /\n/, $str;
> > >  for (@rows) { $_->[2] =~ tr/%//d }
> >
> > Not quite! Because the string starts and ends with newslines
> > this leaves @rows with five elements. Consequently the tr//
> > dies when asked to operate on the undefined $_->[2].
> >
> > I admit that I thought this was more than likely to have come
> > from a file in the first place, but even so the trailing "\n"
> > is more than likely.
> >
>
> Good point. However I must apologize for posting the wrong string. The
> string as it is created does not have beginning and ending new lines, so
> steve's code works.

In which case

  my @data = map { tr/%//d; [split] } split /\n/, $str;

:)

Rob



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




How to rearrange an array by a hash

2004-02-16 Thread Shiping Wang
Hi,
How can I rearrange an array in a specific order based on the order of a 
hash? Something like this:

my @a = qw(Mary John Dan);
print join "\t", @a, "\n";
my %b = ( John => 0,
Dan => 1,
Mary => 2);
print "$_ => $b{$_}\n" for (keys %b);
print "$_-$b{$_}\t" foreach sort {$b{$a} <=> $b{$b}} keys %b;
The final order for @a expect:  John Dan Mary

Thanks,

Shiping

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



Re: How i can get info about CPU ?

2004-02-16 Thread Kenton Brede
On Mon, Feb 16, 2004 at 01:07:50PM +0200, Angel Kolev ([EMAIL PROTECTED]) wrote:
> Exuseme for my bad english.
> How to get info for CPU: overloading, parameters, status .. etc for Windows
> and Linux? I wanna use that in my perl script.

Your English is fine:)

A good place to start for questions such as these is -
http://search.cpan.org/
to check if someone has already solved this problem.

A search for cpu at -
http://search.cpan.org/search?query=cpu&mode=module
netted what looks to be three possibilities for you:

Sys::CPU
Linux::Cpuinfo
Sys::CpuLoad

Another option for some of the info would be to use perl to 
parse the /proc files pertaining to your CPU such as /proc/cpuinfo 
on your Linux system(s).

Windows, sorry, I have no clue.
Kent

-- 
"Efficiency is intelligent laziness."
  -David Dunham

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




RE: shorten code

2004-02-16 Thread Kipp, James
> > > $str = "
> > > /var  0.9950%
> > > /usr  0.5871%
> > > /tmp  0.49 1%
> > > "
> >
> >  my @rows = map [split], split /\n/, $str;
> >  for (@rows) { $_->[2] =~ tr/%//d }
> 
> Not quite! Because the string starts and ends with newslines
> this leaves @rows with five elements. Consequently the tr//
> dies when asked to operate on the undefined $_->[2].
> 
> I admit that I thought this was more than likely to have come
> from a file in the first place, but even so the trailing "\n"
> is more than likely.
>

Good point. However I must apologize for posting the wrong string. The
string as it is created does not have beginning and ending new lines, so
steve's code works. 


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




Re: shorten code

2004-02-16 Thread Rob Dixon
Steve Grazzini wrote:
>
> Kipp, James wrote:
> > I want to split at each new line for the row, then split the row into
> > columns, and get rid of the "%" on the third column.
>
> > $str = "
> > /var  0.9950%
> > /usr  0.5871%
> > /tmp  0.49 1%
> > "
>
>  my @rows = map [split], split /\n/, $str;
>  for (@rows) { $_->[2] =~ tr/%//d }

Not quite! Because the string starts and ends with newslines
this leaves @rows with five elements. Consequently the tr//
dies when asked to operate on the undefined $_->[2].

I admit that I thought this was more than likely to have come
from a file in the first place, but even so the trailing "\n"
is more than likely.

Rob



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




Re: Reg. length of anonymous array

2004-02-16 Thread Shiping Wang
Hi,

How can I rearrange an array in a specific order based on the order of a 
hash? Something like this:

my @a = qw(Mary John Dan);
print join "\t", @a, "\n";
my %b = ( John => 0,
  Dan => 1,  
Mary => 2);
print "$_ => $b{$_}\n" for (keys %b);
print "$_-$b{$_}\t" foreach sort {$b{$a} <=> $b{$b}} keys %b;

The final order for @a expect:

	John Dan Mary	

Thanks,

Shiping

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



RE: shorten code

2004-02-16 Thread Kipp, James
 
> > >  my @rows = map [split], split /\n/, $str;
> > >  for (@rows) { $_->[2] =~ tr/%//d }
> > >
> > 
> > Neat. You saved me 6 lines of code :)
> > Thank You !!
> 
> Make sure its meaningful to you or someone else maintaining 
> it. I would
> rather see 6 extra lines of code and have it mean something to me at a
> glance then to just write code that is short. 
> 

Thanks Paul and I agree with you.  I do think Steve's code is still easy to
follow and with a comment or 2, should be very clear.



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




Weekly list FAQ posting

2004-02-16 Thread casey
NAME
beginners-faq - FAQ for the beginners mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?
Send mail to <[EMAIL PROTECTED]>

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

<[EMAIL PROTECTED]>.

  1.2 -  How do I unsubscribe?
Now, why would you want to do that? Send mail to
<[EMAIL PROTECTED]>, and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

<[EMAIL PROTECTED]>

  1.3 - There is too much traffic on this list. Is there a digest?
Yes. To subscribe to the digest version of this list send an email to:

<[EMAIL PROTECTED]>

To unsubscribe from the digest, send an email to:

<[EMAIL PROTECTED]>

This is a high traffic list (100+ messages per day), so please subscribe
in the way which is best for you.

  1.4 - Is there an archive on the web?
Yes, there is. It is located at:

http://archive.develooper.com/beginners%40perl.org/

  1.5 - How can I get this FAQ?
This document will be emailed to the list once a week, and will be
available online in the archives, and at http://learn.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?
Send an email to <[EMAIL PROTECTED]> with your suggestion.

  1.7 - Is there a supporting website for this list?
Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who do I complain to?
You can send complaints to <[EMAIL PROTECTED]>

  1.9 - Who currently maintains the FAQ?
Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?
Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl beginners.

  1.11 - When was this FAQ last updated?
Feb 04, 2004

2 -  Questions about the 'beginners' list.
  2.1 - What is the list for?
A list for beginning Perl programmers to ask questions in a friendly
atmosphere.

  2.2 - What is this list _not_ for?
* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Monkeys
* Monkeys solicitating homework on non-Perl related SPAM.

  2.3 - Are there any rules?
Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun

  2.4 - What topics are allowed on this list?
Basically, if it has to do with Perl, then it is allowed. You can ask
CGI, networking, syntax, style, etc... types of questions. If your
question has nothing at all to do with Perl, it will likely be ignored.
If it has anything to do with Perl, it will likely be answered.

  2.5 - I want to help, what should I do?
Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?
We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

Please do not quote the documentation unless you have something to add
to it. It is better to direct someone to the documentation so they
hopefully will read documentation above and beyond that which answers
their question. It also helps teach them how to use the documentation.

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?
Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

"perldoc perldoc"

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

  2.8 Is this a high traffic list?
YES! You have been warned! If you don't want to get ~100 emails per day
from this list, consider subscribing to the digest.

  2.9 Other tips before posti

RE: shorten code

2004-02-16 Thread Paul Kraus
> >  my @rows = map [split], split /\n/, $str;
> >  for (@rows) { $_->[2] =~ tr/%//d }
> >
> 
> Neat. You saved me 6 lines of code :)
> Thank You !!

Make sure its meaningful to you or someone else maintaining it. I would
rather see 6 extra lines of code and have it mean something to me at a
glance then to just write code that is short. 

My 2 cents.

PK


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




Re: shorten code

2004-02-16 Thread Rob Dixon
James Kipp wrote:
>
> I want to split the string below into rows and then columns. I know i can do
> a couple of splits, push array refs onto a new array, regex it, etc.. But I
> was know the talented people on this list can shorten the code considerably.
> I want to split at each new line for the row, then split the row into
> columns, and get rid of the "%" on the third column. I can post my
> embarrassingly long code if you like.
> Thanks for any help
> Jim
> 
>
> $str = "
> /var  0.9950%
> /usr  0.5871%
> /tmp  0.49 1%
> "

Hi James.

Don't forget that shortening code is usually more of a pastime
than anything useful, but if your code is /huge/ it can add to
readability.

Does this help? The grep just throws out blank lines.

Cheers,

Rob


  use strict;
  use warnings;

  my $str = "
  /var  0.9950%
  /usr  0.5871%
  /tmp  0.49 1%
  ";

  my @data = map { tr/%//d; [split ' '] } grep /\S/, split "\n", $str;

  use Data::Dumper;
  print Dumper [EMAIL PROTECTED];

**OUTPUT

$VAR1 = [
  [
'/var',
'0.99',
'50'
  ],
  [
'/usr',
'0.58',
'71'
  ],
  [
'/tmp',
'0.49',
'1'
  ]
];




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




RE: shorten code

2004-02-16 Thread Kipp, James

 
>  my @rows = map [split], split /\n/, $str;
>  for (@rows) { $_->[2] =~ tr/%//d }
> 

Neat. You saved me 6 lines of code :)
Thank You !!




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




Re: Checking prototype with objects

2004-02-16 Thread Rob Dixon
R. Joseph Newton wrote:
>
> l Maldonado Torres wrote:
>
> >
> > I am trying to use prototype functions with object but this seems not
> > to work, I mean perl does not check for the type of arguments.
> >
> > I usually do this.
> >
> > sub array_print(\@);
> > ...sub array_print(\@)
> >   ...
>
> Your immediate problem here is that you are trying to use an expression as a
> formal argument.  Formal arguments in Perl can only take storage types.  Really,
> the only meaningful ones are scalar and list.  The list, if it is present, must
> be the last parameter, and there can only be one, since any list will consume
> all arguments offered from there on.
>
> The formal parmeter expressions you show are both array references.  These are
> scalars.  They should be prtotyped as $.

Sorry Joseph. This from perldoc perlsub

  Prototypes

Perl supports a very limited kind of compile-time argument checking
using function prototyping. If you declare

sub mypush (\@@)

then "mypush()" takes arguments exactly like "push()" does.

Cheers,

Rob



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




Re: shorten code

2004-02-16 Thread Steve Grazzini
Kipp, James wrote:
I want to split at each new line for the row, then split the row into
columns, and get rid of the "%" on the third column.

$str = "
/var  0.9950%
/usr  0.5871%
/tmp  0.49 1% 
"
my @rows = map [split], split /\n/, $str;
for (@rows) { $_->[2] =~ tr/%//d }
--
Steve
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Checking prototype with objects

2004-02-16 Thread Randal L. Schwartz
> "Hazael" == Hazael Maldonado Torres <[EMAIL PROTECTED]> writes:

Hazael> I am trying to use prototype functions with object but this seems not
Hazael> to work, I mean perl does not check for the type of arguments.

Exactly.  Prototypes are meant for one thing only: to have a Perl function
emulate a built-in.

They are not meant for "checking argument lists".  And there are no
built-ins that have odd argument processing for method calls, which is
why they don't need to work there either.

Please do not use prototypes until you understand why you should not
use prototypes. :)

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

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




shorten code

2004-02-16 Thread Kipp, James
Hi
I want to split the string below into rows and then columns. I know i can do
a couple of splits, push array refs onto a new array, regex it, etc.. But I
was know the talented people on this list can shorten the code considerably.
I want to split at each new line for the row, then split the row into
columns, and get rid of the "%" on the third column. I can post my
embarrassingly long code if you like. 
Thanks for any help
Jim


$str = "
/var  0.9950%
/usr  0.5871%
/tmp  0.49 1% 
"


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




Re: data filtering

2004-02-16 Thread Rob Dixon
Guruguhan N wrote:
>
>   I have a data set ( only a portion) as follows:
>No. x1 x2 x3y1  y2y3  y4
>1   0.20   0.20   0.20   0.76568575881.929289.3   -46592.6
>2   0.200345   0.20   0.200345   0.7175766.029268.4   -46497.6
>3   0.20   0.200345   0.20   0.76603075867.129259.8   -46607.4
>4   0.359575   0.253987   0.359575   1.27101943898.719675.6   -24223.1
>5   0.359921   0.253987   0.359921   1.27199543861.319666.1   -24195.2
>
> This data set has to be filtered using the following conditions ( example only. in 
> reality this can be anything):
>
> 0.2 < x1 < 0.3
> y1 > 0.8
> 15000 < y3 < 3
>
> I have to filter the data set satisfying all the conditions.

Hi.

Unfortunately none of your data satisfy the criteria! But taking just the
limits on x1 the program below should help. It works by grabbing the column
headers and using them as the keys of a hash for the following data. That allows
you to write the conditions in meaningful terms.

I hope it helps,

Rob



use strict;
use warnings;

my @keys = split ' ', ;

my %data;

while () {

  @[EMAIL PROTECTED] = split ' ';

  next unless
0.2 < $data{x1} && $data{x1} < 0.3; # &&
#$data{y1} > 0.8;
#15000 < $data{y3} && $data{y3} < 3;

  print "@[EMAIL PROTECTED]";

}

__DATA__
   No. x1 x2 x3y1  y2y3  y4
   1   0.20   0.20   0.20   0.76568575881.929289.3   -46592.6
   2   0.200345   0.20   0.200345   0.7175766.029268.4   -46497.6
   3   0.20   0.200345   0.20   0.76603075867.129259.8   -46607.4
   4   0.359575   0.253987   0.359575   1.27101943898.719675.6   -24223.1
   5   0.359921   0.253987   0.359921   1.27199543861.319666.1   -24195.2

**OUTPUT

2 0.200345 0.20 0.200345 0.71 75766.0 29268.4 -46497.6



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




Re: Checking prototype with objects

2004-02-16 Thread R. Joseph Newton
Hazael Maldonado Torres wrote:

> --
> Hi there.
>
> I am trying to use prototype functions with object but this seems not
> to work, I mean perl does not check for the type of arguments.
>
> I usually do this.
>
> sub array_print(\@);
> ...sub array_print(\@)
>   ...

Your immediate problem here is that you are trying to use an expression as a
formal argument.  Formal arguments in Perl can only take storage types.  Really,
the only meaningful ones are scalar and list.  The list, if it is present, must
be the last parameter, and there can only be one, since any list will consume
all arguments offered from there on.

The formal parmeter expressions you show are both array references.  These are
scalars.  They should be prtotyped as $.

Joseph


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




Re: data filtering

2004-02-16 Thread R. Joseph Newton
David le Blanc wrote:

> Guruguhan,
>
> Can I assume you have the data in memory?
> Can I further assume the data is contained in an array of arrays?
> Can I also further assume that the conditions you mentioned are AND'd?
> (ie
>   the final result is the intersection of all conditions?)

I'm afraid the one assumption that you have not specified is the killer
here--that the conditions per field are a constant.  The OP indicated below [why
below?  please bottom-post] that the conditions could be anything.  Therefore a
solution will have to be sufficiently flexible to take an arbitrary number of
rules for any column.

I think your third assumption is pretty fair.  The others can be adjusted fairly
readily, but the and condition would be crucial to the logic.  So the OP needs
at least two stages for this process.  The first would store a hash or array
references keyed to column name.  Each rule to be applied would be pushed into
the array for the relevant column during the first   Of course, he might also
need an array for multifield functions if any conditions are based on
relationships between fields.


Then of course, the second phase would iterate through the records, and reject
any record as soon as it finds one condition that is not met.

Joseph


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




Re: Checking prototype with objects

2004-02-16 Thread Rob Dixon
Hazael Maldonado Torres wrote:
>
>
> I am trying to use prototype functions with object but this seems not
> to work, I mean perl does not check for the type of arguments.
>
> I usually do this.
>
> sub array_print(\@);
>
> ..
> ...
>
> sub array_print(\@)
>{
># my code
>}
>
>
> Then when I call it as:
>
> array_print(@this_array);
>
> Perl is supposed to check the prototype and change the array by its
> reference. Now I try to put this same behavior but with object, and
> then when I call the same function as:
>
> $obj_array->array_print(@this_array);
>
> Perl sends the complete array to the function and not the reference.
> So I need to do this
>
> $obj_array->array_print([EMAIL PROTECTED]);
>
> Does any one knows how to force perl to behave as normal?

There is no way of prototyping object methods as run-time inheritance
means that Perl cannot know which subroutine will provide the
method until it is actually called.

Perl isn't C, and it's hardly ever a good idea to prototype
Perl subroutines. It's far more useful to be able to pass an array,
an array or hash slice, or a list of scalars (or a mixture of these)
to a subroutine that simply expects a LIST.

If you must, you can code

  sub array_print {
my $array = shift;
die unless ref $array eq 'ARRAY';
  }

but I would expect something like 'array_print' to look at
least something like the built-in 'print' operator which
takes a list of values.

HTH,

Rob



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




Re: Updating a text file

2004-02-16 Thread Jan Eden

R. Joseph Newton wrote:

>Jan Eden wrote:
>
>>Hi,
>>
>>[EMAIL PROTECTED] wrote:
>>
>>>I have a text file with a records like:
>>>
>>>smith, James, Dr., 115 Fourth Street, Chicago, IL, 32012, $20.00:
>>>[EMAIL PROTECTED]
>>>
>>>and another text file with placeholders like:
>>>
>>>Hello $last_name, $first_name:
>>>
>>>I want to read the first textfile and update the second one.
>>>
>>>Any ideas!
>>
>>This is a very general question. Have you already tried something?
>>Have your read an Introduction to Perl (O'Reilly's "Learning Perl"
>>is highly recommended)?
>>
>>Basically, what you have is a data file and a template file. You
>>should open the data file and read the data into a hash (using
>>pattern matching), then merge the hash and the template file
>>(replacing your placeholders), putting out a scalar variable for
>>each set of data.
>
>I would do it the other way around.  I am guessing here that the OP
>wants to use the second file as a tameplate, as you suggest also, but
>consider the use of a template.  He probably does not want to
>actually update the original, but to spawn personalized copies for
>each customer/recipient record in the data file.
>
>Since the text of the template is the material that would be repeated
>each time through the loop, the text is what he should slurp.  Then
>he can go through the data-file record by record, making a
>personalized version from the template for each one.
>
You are probably right and that's what I meant. My description was probably a bit 
misleading. The way I do it is create the hash, slurp the template file in a scalar 
and produce an output string for each data set in the hash (which can be written to a 
new file, named after the respective hash key.

- Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho 
Marx

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




Re: Updating a text file

2004-02-16 Thread Mame Mbodji
Thanks, I will give it a try!

"R. Joseph Newton" wrote:
> 
> Jan Eden wrote:
> 
> > Hi,
> >
> > [EMAIL PROTECTED] wrote:
> >
> > >I have a text file with a records like:
> > >
> > >smith, James, Dr., 115 Fourth Street, Chicago, IL, 32012, $20.00:
> > >[EMAIL PROTECTED]
> > >
> > >and another text file with placeholders like:
> > >
> > >Hello $last_name, $first_name:
> > >
> > >I want to read the first textfile and update the second one.
> > >
> > >Any ideas!
> >
> > This is a very general question. Have you already tried something? Have your read 
> > an Introduction to Perl (O'Reilly's "Learning Perl" is highly recommended)?
> >
> > Basically, what you have is a data file and a template file. You should open the 
> > data file and read the data into a hash (using pattern matching), then merge the 
> > hash and the template file (replacing your placeholders), putting out a scalar 
> > variable for each set of data.
> 
> I would do it the other way around.  I am guessing here that the OP wants to use the 
> second file as a tameplate, as you suggest also, but consider the use of a template. 
>  He probably does not want to actually update the original, but to spawn 
> personalized copies for each customer/recipient record in the data file.
> 
> Since the text of the template is the material that would be repeated each time 
> through the loop, the text is what he should slurp.  Then he can go through the 
> data-file record by record, making a personalized version from the template for each 
> one.
> 
> Of course I could be wrong--the OP might really want to modify the template itself.  
> In that case, he would first have to decide which record he would want to take the 
> values from
> 
> For the time being, though, I am assuming that he simply misstated the procdure.  If 
> he has the template in memory as a concatenated string, he can substitute in the 
> proper variables for the place holders with each record
> 
> my $template_string = get_file_contents();
> my $contact = {};
> my $count = 0;
> while () {
>chomp;
>($contact->{'last name'}, $contact->{'first name'} ...$conatact->{'current 
> balance'}) = split /,\s+/, $_;
>(my $inerpolated_string = $template_string) =~ s/%(.*?)%/$contact->{$1}/g;
>open(OUT_FILE, 'boiler_plate' . ++$count . '.txt'
>print OUT_FILE $inerpolated_string;
> }
> 
> This should work alright.  Took a few rounds to get the typos out, but the following 
> worked from the command line:
> my $template_string = 'Hello, %first name% %last name%, how are you';
> 
> my $contact = {};
> my $count = 0;
> while () {
>chomp;
>($contact->{'last name'}, $contact->{'first name'}) = split /,\s+/, $_;
>(my $interpolated_string = $template_string) =~ s/%(.*?)%/$contact->{$1}/g;
>open(OUT_FILE, '>boiler_plate' . ++$count . '.txt');
>print OUT_FILE $interpolated_string;
> }
> __DATA__
> Smith, John
> Doe, Jack
> 
> The file rendered were:
> boiler_plate1.txt
> Hello, John Smith, how are you
> boiler_plate2.txt
> Hello, Jack Doe, how are you
> 
> Joseph
> 
> --
> 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]
 


Checking prototype with objects

2004-02-16 Thread Hazael Maldonado Torres
--
Hi there.
I am trying to use prototype functions with object but this seems not 
to work, I mean perl does not check for the type of arguments.

I usually do this.

sub array_print(\@);

..
...
sub array_print(\@)
  {
  # my code
  }
Then when I call it as:

array_print(@this_array);

Perl is supposed to check the prototype and change the array by its 
reference. Now I try to put this same behavior but with object, and 
then when I call the same function as:

$obj_array->array_print(@this_array);

Perl sends the complete array to the function and not the reference. 
So I need to do this

$obj_array->array_print([EMAIL PROTECTED]);

Does any one knows how to force perl to behave as normal?

Cheers

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



RE: data filtering

2004-02-16 Thread David le Blanc

Guruguhan,

Can I assume you have the data in memory?
Can I further assume the data is contained in an array of arrays?
Can I also further assume that the conditions you mentioned are AND'd?
(ie
  the final result is the intersection of all conditions?)

Thus $data[0][0] = 0.20 (aka, X1 from row 1)

Consider the following:  (purposely written in readable perl)

my @filtered = ();
for( @data ){
push @filtered,$_ if
$$_[0] > 0.2 && $$_[0] < 0.3 && # 0.2 < x1 < 0.3
$$_[3] > 0.8 &&   # y1 > 0.8
$$_[5] > 15000 && $$_[5] < 3;   # 15000 < y3 < 3
}

[EMAIL PROTECTED] data contains filtered result result.

Is that what you were thinking of?

Regards,

David le Blanc

--  
Senior Technical Specialist 
I d e n t i t y   S o l u t i o n s 

Level 1, 369 Camberwell Road, Melbourne, Vic 3124   
Ph 03 9813 1388 Fax 03 9813 1688 Mobile 0417 595 550
Email [EMAIL PROTECTED] 

-Original Message-
From: N, Guruguhan (GEAE, Foreign National, EACOE)
[mailto:[EMAIL PROTECTED] 
Sent: Monday, 16 February 2004 10:47 PM
To: [EMAIL PROTECTED]
Subject: data filtering

Hi All,
  I have a data set ( only a portion) as follows:
   No. x1 x2 x3y1  y2y3
y4
   1   0.20   0.20   0.20   0.76568575881.929289.3
-46592.6
   2   0.200345   0.20   0.200345   0.7175766.029268.4
-46497.6
   3   0.20   0.200345   0.20   0.76603075867.129259.8
-46607.4
   4   0.359575   0.253987   0.359575   1.27101943898.719675.6
-24223.1
   5   0.359921   0.253987   0.359921   1.27199543861.319666.1
-24195.2

This data set has to be filtered using the following conditions (
example only. in reality this can be anything):

0.2 < x1 < 0.3
y1 > 0.8
15000 < y3 < 3

I have to filter the data set satisfying all the conditions. 

Can somebody help me out to do the same. Any help in this regard is
solicited.

Thanks
Regards
Guruguhan
EACoE, India.


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




How i can get info about CPU ?

2004-02-16 Thread Angel Kolev
Exuseme for my bad english.
How to get info for CPU: overloading, parameters, status .. etc for Windows
and Linux? I wanna use that in my perl script.
Thanks



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




Re: Looking up values in arrays?

2004-02-16 Thread Rob Dixon
Paul Johnson wrote:
>
> > Is there a function to find out if a given value exists in an array?
> >
> > What I think of is something like &has_element([EMAIL PROTECTED], $value), which
> > should return either a boolean value or the index containing the value
> > (undef if $value is not found).
> > I'm sure something like this exists. Or do I need to write this myself?
>
> Something close exists.  I think I'd probably code it as:
>
> use List::Util "first";
>
> sub has_element
> {
> my ($array, $value) = @_;
> first { $_ eq $value } @$array
> }

Except that this will return the /value/ of the element
for which the block returns true, which isn't obvious from the
call. It's identical to

  sub has_element {

my ($array, $value) = @_;

foreach (@$array) {
  return $_ if $_ eq $value;
}

return;
  }

which, to my mind, is preferable as it is clearer what's going on. It's
certainly no slower.

Rob



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




data filtering

2004-02-16 Thread N, Guruguhan \(GEAE, Foreign National, EACOE\)
Hi All,
  I have a data set ( only a portion) as follows:
   No. x1 x2 x3y1  y2y3  y4
   1   0.20   0.20   0.20   0.76568575881.929289.3   -46592.6
   2   0.200345   0.20   0.200345   0.7175766.029268.4   -46497.6
   3   0.20   0.200345   0.20   0.76603075867.129259.8   -46607.4
   4   0.359575   0.253987   0.359575   1.27101943898.719675.6   -24223.1
   5   0.359921   0.253987   0.359921   1.27199543861.319666.1   -24195.2

This data set has to be filtered using the following conditions ( example only. in 
reality this can be anything):

0.2 < x1 < 0.3
y1 > 0.8
15000 < y3 < 3

I have to filter the data set satisfying all the conditions. 

Can somebody help me out to do the same. Any help in this regard is solicited.

Thanks
Regards
Guruguhan
EACoE, India.


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




RE: perl and application server..

2004-02-16 Thread NYIMI Jose (BMB)
Hello,

Give a look to this article from perl.com
I contains a lot of interesting infos related to your question:

http://www.perl.com/lpt/a/2001/10/17/etoys.html

HTH,

José.

-Original Message-
From: Joe Echavarria [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 13, 2004 9:25 PM
To: [EMAIL PROTECTED]
Subject: perl and application server..


Hi there,

  Is there a way to work with perl as a Java, with and application server in other to 
separate the presentation from the business logic ?,  Thanks for any help.

__
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online. 
http://taxes.yahoo.com/filing.html

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