Help - Search - Member List - Calendar
Full Version: combinations
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44
Support our Sponsors!


Rob Dixon
"David Byrne" <[Email Removed]> wrote in message news:[Email Removed]...
QUOTE
I am fairly new to Perl and haven't approached a scipt
this complex or computation this intensive.  So I
would certainly appreciate any advice.

I have successfully created a hash of arrays
equivalent to a 122 x 6152 matrix that I want to run
in 'pairwise combinations' and execute the 'sum of the
difference squares' for each combination.

In other words:
columns: y1...y122
rows:      x1...x6152

so...
comb(y1,y2):
{( y1[x1] - y2[x1] ) ^2 + ( y1[x2] - y2[x2] ) ^2 + ...
+ ( y1[x122] - y2[x122] ) ^2};

comb(y1,y3):
{( y1[x1] - y3[x1] ) ^2 + ( y1[x2] - y3[x2] ) ^2 + ...
+ ( y1[x122] - y3[x122] ) ^2};.
.
.
comb(y1,y6152)
comb(y2,y3)
.
.
comb(y2,y6152)
comb(y3,y4)
.
.
etc.

This is going to be very large.  According to the
combinations formula (nCk, n=6152, k=2), the output
will be a hash (with, for example, 'y1y2' key and
'd^2' value) of about 19 million records.

I think my next step is to create a combinations
formula, but I'm having problems doing so.

Hi David.

This should do the trick, although without sight of your
original data structure I can't be sure. I assume you
have a hash of array references.

This works by grabbing a list of all the hash keys
into an array and then executing two nested loops.
The outer loop shifts the first key value off the
array (y1) and assigns it to $ya. The inner loop
just cycles $yb through the remaining values in the
list (y2, y3 etc). Next time around the outer loop
the next value (y2) is assigned to $ya and $yb will
be set to y3, y4 etc. The very inner loop just scans
through the data calculating the sum of squared
differences for each value pair and stuffs the answer
into hash %results using a key formed by concatenating
$ya and $yb.

I haven't tested this as it would be a pain to set up
some data, so I'll let you test it for me. I know it
compiles OK!

HTH,

Rob


use strict;
use warnings;

my %data;
my @keys = keys %data;
my %results;

while ( @keys ) {

my $ya = shift @keys;

foreach my $yb (@keys) {

my @xa = @{$data{$ya}};
my @xb = @{$data{$yb}};

for (my $i = 0; $i < @xa and $i < @xb; ++$i) {

$results{$ya.$yb} += ($xa[$i] - $xb[$i]) * ($xa[$i] - $xb[$i]);
}
}
}

Jeff 'Japhy' Pinyan
On Aug 5, Vinay Thombre said:

QUOTE
I am novice to Perl and learning very basic things. I want to replace a text
in a file with new text. I want to do it programatically. How can I do that?

I hope you've got a good book or two, such as "Learning Perl" (the llama
book) published by O'Reilly.

The basic setup you'll want to use is this:

open INPUT, "< in.txt" or die "can't read in.txt: $!";
open OUTPUT, "> out.txt" or die "can't write out.txt: $!";
while (my $line = <INPUT>) {
# do something to $line
print OUTPUT $line;
}
close OUTPUT;
close INPUT;

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

Smith Jeff D
Doh!!

Makes me humble every time.....

Thanks for your help.

-----Original Message-----
From: [Email Removed] [mailto:[Email Removed]]
Sent: Tuesday, August 05, 2003 12:54 PM
To: Smith Jeff D; '[Email Removed]'
Subject: RE: Structuring Data in Perl



------------------------------------------------
On Tue, 5 Aug 2003 12:03:34 -0400 , Smith Jeff D
<[Email Removed]> wrote:

QUOTE
Thanks for the response-I think that's got it.  I must have tried
everything but the correct approach, which looks so obvious after the
fact.

One small question.  In your sample code below, what format can I use
to refer to the individual members of the array referenced by $array
in the "each" loop?

--I know that @$array will produce all members of the array within the
hash--how do I refer to the individual members of this array
reference, however big it might be--1 to whatever number of elements.
In other words, if @$array for server01 contains "SUCCESS Today's Date
Other Details" and "WARNING Today's date Other", how do I refer to
array0 and array1 properly in a loop so I can deal with each one
separately---I know it isn't @$array[0] and @array$[1] because of the
errors I get, so it must be something else, ->[0], ->[1] but see the
following warning even though it gives me a result (this is a loop
following the grabbing of the $server and $array in the while/each
loop snippet you sent----

foreach my $i (@$array) {

Right here you have alraedy stored the array reference to $array, so when
you foreach over the array you are actually getting each element (detail
line) into $i. So...

QUOTE
  print "Detail: @$array->[$i]n";  #Produces the following
warning:

In the above you are trying to index into an array using the value from that
array rather than an index.

In other words what you are trying to retrieve is already in $i. If you want
to access individual elements of the array by index you need to loop over an
index range, not the array values themselves.

For instance,

foreach (0 .. @$array) {
print $array->[$_];
}

QUOTE
    Argument "SUCCESS06/01/2003What wasn't done
beforen" isn't numeric in array ele
  ment at
C:localwin32appEventLogEventDumperinPerlha.pl line 29, <DATA> line
  5.
  Detail: WARNING06/01/2003Here are some details


Now the really cool thing is that you can remove (if you want) the temporary
array dereference and access the elements directly, say you want the first
element of the 'server1's log...

$servers->{'server1'}->[0];

Or the first 5 elements of each of the servers...

- Untested -
foreach my $servername (keys (%$servers)) {
my @first5lines = $servers->{$servername}->[0 .. 4];
}

There are any number of ways to access into the data structure directly.
Experience is about the only way to truly "get it" and once you do you won't
lose it again, and the doors will seemingly flood open to its uses, and of
course there is Perl OOP...

http://danconia.org

Tim Johnson
I think your pattern match will only catch a literal AZ_OK, not the
constant. And I'm not sure, but AZ_OK might evaluate to 0. At least I
think I remember having trouble with that module because it returns 0 on
success, and I kept testing for TRUE/FALSE based on the return status.

-----Original Message-----
From: Dan Muey [mailto:[Email Removed]]
Sent: Tuesday, August 05, 2003 2:32 PM
To: [Email Removed]
Subject: Archive::Zip funnny return status


use Archive::Zip;
...
my $member = $zip->memberNamed($zippedfile);
my $rc = $member->extractToFileNamed($unzippedfile);
if($rc =~ m/AZ_OK/) { print "ok -$rc-n; } else { print "Bad
-$rc-n"; }

The code above *always* prints:
Bab -0-

But $unzippedfile is created properly, everytime, even if I delete it first
and run it again!!! So shouldn't $rc have AZ_OK in it or even better be 1 on
success? Or is writing the text file in the zip archive to a local text file
not success? What could I be doing wrong/missing?

TIA

Dan

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

David
Hamish Whittal wrote:

QUOTE
Hi all,

I have a stored procedure that is defined as follows:
PROCEDURE Add_ComponentDetails(
p_ComponentID IN number,
p_PollingID IN number,
p_Answer  IN varchar2,
p_ASNNumber IN varchar2)

In my perl code, I exec the following:
my $plsql_params = "'" . join("', '", $ASNNameHash->{compID},
$pollID,$answer, $asnNum) . "'" ;
my $sql = qq{BEGIN
DEVICE_MANAGEMENT.ADD_COMPONENTDETAILS($plsql_params); END;};
print qq(n*****-->$sql<--*****n) if $debug;
$sth = $$dbh->prepare($sql); # End of the prepare
$sth->execute();


is this what you have in your code: "$$dbh->prepare($sql)"?

david

Jeff 'Japhy' Pinyan
On Aug 5, Jakob Kofoed said:

QUOTE
1  5001
2  5002
3  5003
[snip]


Are those line numbers actually in the file too? If so, that might cause
problems for you.

QUOTE
open IN, "<", "num2.txt";
my @in = <IN>;

At this point, @in holds all the lines of the file...

QUOTE
push @col1, $in[0];

.... but here, you only store the FIRST line (the first element of @in) in
the @col1 array.

Other people have suggested better approaches; I'm just pointing out the
flaw in your program.

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

this is a long shot, but I read today about false 'no space left' errors
occuring due to chmod settings being 777 on the directories.

I don't know if this has any direct tie to your problem, but you can
look at:
http://www.yabbforum.com/community/YaBB.pl...;num=

in case it helps

Katy Brownfield wrote:
QUOTE
I'm modifying an existing script that has been moved to a new domain and
a new ISP. It opens a DBM file like this

dbmopen %fileinfo, "../data/fileinfo", 0644
or die "cannot open fileinfo: $!n";

This fails intermittently with

[Thu Jul 31 00:46:16 2003]  [error] [client 53.259.56.55] cannot open
fileinfo: No space left on device, referer: https://.....

No filesystem was full when I checked, while the error was happening,
but the tech support folks at the ISP found that /var was 100% full
earlier today, cleared some space, tested the script when it wasn't
failing and pronounced the problem solved. My skepticism was justified,
because now it's happening again.

Is it likely that DBM puts temporary files in /var/tmp? The DBM file
contains only a little test data. Could the device in the error message
be something other than a filesystem? A red herring?

Could this have anything to do with something that's under my control?

I'd appreciate any insights.

Katy



Dan Muey
QUOTE
I'm wanting to setup a module that will export whatever is in
@EXPORT (if anythign) and ':basic'

IE  I want
use Monkey;
To be identical to
use Monkey qw(:basic);

So if I have this on the module which of 3 ways I'm trying to
accoomplish that are valid (if any)?

%EXPORT_TAGS = {
':basic' =>    [qw(fred wilma barney dino)],
};

Sorry about the mess there, Let me fix it:

$EXPORT_TAGS{':DEFAULT'} = $EXPORT_TAGS{':basic'};

Or

$EXPORT_TAGS{':DEFAULT'} .= $EXPORT_TAGS{':basic'};

Or

$EXPORT_TAGS{':DEFAULT'} = > ($EXPORT_TAGS{':basic'},@EXPORT);

There that's more readable!


QUOTE

TIA

Dan

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]



Charles K. Clarkson
Dan Muey <[Email Removed]> wrote:
:
: I'm wanting to setup a module that will export whatever is in
: @EXPORT (if anythign) and ':basic'
:
: IE I want
: use Monkey;
: To be identical to
: use Monkey qw(:basic);

Seems like you really need is a way to test this
for yourself. Here's a quickie I just wrote. I'm sure
it fails for some modules, but . . .

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

print Dumper imported( 'CGI', ':html' );

sub imported {
my( $module, @import ) = @_;
require "$module.pm";
my @previous_keys = keys %::;
import $module @import;

my %symbol_table = %::;
delete @symbol_table{ @previous_keys };
return [ keys %symbol_table ];
}


HTH,

Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists


Perlwannabe
QUOTE
Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400:

On Wed, Aug 06, 2003 at 11:49:20PM -0400, perlwannabe wrote:
I have made the script as simple as possible and cannot get
unlink to work.

unlink ("c:testdir*030977*.*") || die "unlink failed: $!";

You'd need to expand the wildcards yourself:

my $pat = 'c:testdir*030977*.*';
foreach (glob($pat)) {
unlink or warn "Couldn't unlink '$_': $!";
}

Or if you want to write it as a one liner,
you can exploit that unlink also takes a list as its arguments:

unlink glob "c:/testdir/*030977*.*" or die "No files unlinked: $!";

Neither of these worked. I am beginning to think that there is something
wrong with ActivePerl and WinXP.

Try this. Make a sample text file named "testfile.txt" and put it in
directory "c:testdir"

then try this script...don't add anything like use File::glob and see if
it works:

my $test = ("c:\testdir\testfile.txt");
unlink glob ($test) || die "unlink failed: $!";

This simple little script does not delete testfile.txt from my machine. Why?

Steve Grazzini
On Thu, Aug 07, 2003 at 11:00:07PM -0400, perlwannabe wrote:
QUOTE
Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400:
my $pat = 'c:testdir*030977*.*';
^


That looks like trouble. Using forward slashes, as Janek has
done below, would have been smarter.

QUOTE
foreach (glob($pat)) {
unlink or warn "Couldn't unlink '$_': $!";
}

Or if you want to write it as a one liner,
you can exploit that unlink also takes a list as its arguments:

unlink glob "c:/testdir/*030977*.*" or die "No files unlinked: $!";

That's not very good error-reporting. Maybe unlink failed
ninety-nine times and succeeded once...

QUOTE
Neither of these worked.

Did they give any error messages?

QUOTE
my $test = ("c:\testdir\testfile.txt");
unlink glob ($test) || die "unlink failed: $!";
^^


And that's the wrong "or". If you use the alphabetical "or",
you'll at least get an error message.

unlink $test or die "unlink: $test: $!";

--
Steve

Vinay Thombre
I want in.txt and out.txt file to be same.
That is I want to replcae text insa me file and do not want to create a new
file.
Thanks,
Vinay
----- Original Message -----
From: "Jeff 'japhy' Pinyan" <[Email Removed]>
To: "Vinay Thombre" <[Email Removed]>
Cc: <[Email Removed]>
Sent: Tuesday, August 05, 2003 10:52 PM
Subject: Re: How to replace a text in a file


QUOTE
On Aug 5, Vinay Thombre said:

I am novice to Perl and learning very basic things. I want to replace a
text
in a file with new text. I want to do it programatically. How can I do
that?

I hope you've got a good book or two, such as "Learning Perl" (the llama
book) published by O'Reilly.

The basic setup you'll want to use is this:

open INPUT, "< in.txt" or die "can't read in.txt: $!";
open OUTPUT, "> out.txt" or die "can't write out.txt: $!";
while (my $line = <INPUT>) {
# do something to $line
print OUTPUT $line;
}
close OUTPUT;
close INPUT;

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



Bob Showalter
Dan Muey wrote:
QUOTE
I'm wanting to setup a module that will export whatever is in
@EXPORT (if anythign) and ':basic'

IE  I want
use Monkey;
To be identical to
use Monkey qw(:basic);

So if I have this on the module which of 3 ways I'm trying to
accoomplish that are valid (if any)?

%EXPORT_TAGS = {
':basic' =>    [qw(fred wilma barney dino)],
};
$EXPORT_TAGS{':DEFAULT'} = $EXPORT_TAGS{':basic'}; # this would do it
right? Or
$EXPORT_TAGS{':DEFAULT'} .= $EXPORT_TAGS{':basic'}; Or
$EXPORT_TAGS{':DEFAULT'} = ($EXPORT_TAGS{':basic'},@EXPORT);

Probably this will work (haven't tried it):

$EXPORT_TAGS{':DEFAULT'} = [ @{$EXPORT_TAGS{':basic'}}, @EXPORT ];

But I would do this instead:

my @basic = qw(fred wilma barney dino);
our @EXPORT = (qw/foo bar baz/, @basic);
our %EXPORT_TAGS = (':basic' => @basic);

I don't think defining :DEFAULT for yourself is what the author of Exporter
had in mind...

Rob Hanson
QUOTE
Any suggestions on how I can do this?

Yes.

# init the hash key
$hash{four} = {} unless exists $hash{four};

# store access the internal hash by following the reference "->"
$hash{four}->{uid} = "uid4";
$hash{four}->{cn} = "cn4";
$hash{four}->{group} = "Group4";


Rob


-----Original Message-----
From: Tim Musson [mailto:[Email Removed]]
Sent: Friday, August 08, 2003 8:31 AM
To: [Email Removed]
Subject: Another reference question (hash of hash references)


beginners,

I am trying to build a hash of hash references. My problem is that I
need to be able to add a key/value pair to the internal hashes...

,----- [ Here is my test code (yes, I am working with LDAP) ]
#!perl
use strict;
use warnings;

my %hash = (
one => { uid => "uid1", cn => "cn1", group => "Group1" },
two => { uid => "uid2", cn => "cn2", group => "Group2" },
);
$hash{"three"} = { uid => "uid3", cn => "cn3", group => "Group3" };

$hash{"four"} = { uid => "uid4" };
$hash{"four"} = { cn => "cn4" };
$hash{"four"} = { group => "Group4" };

my $key;
foreach $key (sort keys %hash) {
my $iHash = $hash{$key};
print "
key: $key
hash-HRef: $hash{$key}
HRef: $iHash
hash/hash{uid}: $iHash->{uid}
hash/hash{cn}: $iHash->{cn}
hash/hash{group}: $iHash->{group}
";
}
`----- [ End of my test code ]

So, I add the keys "one" and "two" when I initialize the hash, then I
add "three" after. That works just fine, but I need to do something like
"four", and all I get in the output is "Group4" because the third time I
write the anon reference to the hash, it overwrites of course...

Any suggestions on how I can do this? I don't think I can really use an
array, and push to it because of how we plan to access the top level
hash.

Background, I am doing an LDAP query for a couple of attributes in one
DN, then another LDAP query in a different part of the LDAP tree for
some other attributes. The output for each query needs to be grouped by
something like UID (I will replace "one", "two", etc with the UID/CN
value as I extract it). Yes, it is a messed up LDAP structure, but I
can't do anything about that... :-(

Thanks for any help!

--
Tim Musson
Flying with The Bat! eMail v1.62q
Windows 2000 5.0.2195 (Service Pack 3)
Contrary to popular belief, Unix is user friendly. It just happens to be
selective about who it makes friends with


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

William M West
QUOTE
From: Tassilo von Parseval [mailto:[Email Removed]]


QUOTE
Subject: Re: data recovery ext3 (was RE: Recover zip file via Archive::Zip)

On Thu, Aug 07, 2003 at 03:09:06PM -0400 West, William M wrote:

i am not sure what all the components do anymore- i did not document it
well
:P

Let me help. :-)

why thank you :)



QUOTE
now that i've looked at it, it's really for getting to files that are
unlinked etc..... so i am not sure it will do you any good.

Partly it might. The only problem with your script is that it cannot
deal with data that is spanning more than 12 inodes (those were usually
not in one block but fragmented over the harddisk). A line like this
shows such a trickier example:

99526      0 100644 676132    1/1027 Sat Feb  2 09:11:58 2002

well.. this is interesting- i am not sure how to interpret this line
properly. also, i assume that even split inodes will all get shoved through
the script... so, perhaps there is a way to concatonate/rename the split
inodes? or is there no way to see which belongs to which group?


QUOTE

I don't by hard know what to do with it, but it is laid out in the ext2
undeletion how-to.

well- this gives me a place to start looking. :)

QUOTE

to bring this more on topic, i would like to see what ways something like
this can be improved- it served useful to me in the past, but i'm sure it
can be made more useful:::


#!/usr/bin/perl

# added proper things when retyping it:
use warnings;
use diagnostics;
use strict;
#-------------------

my $cfile = "/tmp/commands.file";
my $filesystem ="/dev/hda6";
my @path = ("/tmp/recover","","/recover","",".ebu");  #making a path to
put
my $date="Oct"; #just files from October  #stuff later

open (OUT,">$cfile");
print OUT "open $filesystemn";# i wonder what this is for?

Debug message?

no-> i wasn't all that sophisticated.. *shrug*

QUOTE

foreach (`/sbin/debugfs -R lsdel /dev/hda6`){#why did i hard code
/dev/hda6?

#debugfs let's me list a bunch of inodes and i stick the list in a file

m/(d+)/;
$path[3]=$1;  #had to split this regex to dead with some edge
case
$1=~m/(d)/; # but i can't recall what....

$path[1]=$1;
my $quatch = join("",@path);
my $place= "path[0]$path[1]";
print OUT("dump <$path[3]> $quatchn") if ((m/$date/));

Essentially, from a line like

2210070  1000 100600  22843    2/  6 Wed Jul 23 09:26:10 2003

you extract the inode (2210070) and from that turn

my @path = ("/tmp/recover","","/recover","",".ebu");

into

@path = ("/tmp/removed", 2, "/recover", 2210070, ".ebu");

So the deleted inode gets dumped into

/tmp/removed/2/recover/2210070.ebu
    ^^^^^^^--- typo!  *laugh*

This could have been done more easily:

@path[3,1] = /((d)d+)/;

fantastic! i have never been terribly good with regexes and am trying to
avoid learning them again until perl6 *laugh* i must to too darn lazy!!


QUOTE

`mkdir $place`;
}



QUOTE


-----------------

then i chmod 755 command.file?  or is it a file used by another tool???

command.file is the list of dump directives. It's supposedly a shell
script that you can run later. So the above Perl script just generates
another script. I am just not sure about

print OUT "open $filesystemn";

open /dev/hda6

is not a meaningful command in shell scripts AFAIK.


i agree- but something is nagging at the back of my head, telling me that it
was useful.... perhaps it is readable by another command... instead of using
mount... *sigh* i don't know :P




QUOTE
Tassilo


i'll try to rewrite it... see if i can get it to work again :)

Eurospace Szarindar
Hi,

You can use

my $LastValue = $ARRAY[ $#ARRAY-1 ];

The pop function suppress the last value of the ARRAY.


Michel

-----Message d'origine-----
De: [Email Removed] [mailto:[Email Removed]]
Date: vendredi 8 aot 2003 12:57
: [Email Removed]
Objet: Last value in a array?


Hi,

I have a couple of arrays which have different number of values - I need
only the last value in each - are there a command to do that?

e.g

$array[LAST] :-)

or maybe a way to count each value in a given array? and then feed the
$array[??] with that?

Thanks,
Jakob

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

Pablo Fischer
Thanks!

After sending my question I found in a website the topic of 'private' methods,
and shows code like this:


my $method_name = sub {
my $this = shift;

_blablabla_
};


And to access it :

$this->$method_name("Arg1");

Now, this it really works for 'private' methods?

Thanks!
--
Pablo Fischer Sandoval ([Email Removed])
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

Biju Ramachandran
Please, anybody...

Biju


QUOTE
From: "Biju Ramachandran" <[Email Removed]
To: [Email Removed]
Subject: pid->memory usage
Date: Thu, 07 Aug 2003 11:23:33 -0400

Hi there

I just  want to know is there any way to find out the PID ans how much a
process is using
the physical and virtual memory, as it is show by the Windows NT task
manager.

Thanks

Biju

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]


_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus

Stephen Gilbert
QUOTE
-----Original Message-----
From: Biju Ramachandran [mailto:[Email Removed]]
Sent: Friday, August 08, 2003 8:56 AM
To: [Email Removed]
Subject: Re: pid->memory usage - Any takers


Please, anybody...

Biju


From: "Biju Ramachandran" <[Email Removed]
To: [Email Removed]
Subject: pid->memory usage
Date: Thu, 07 Aug 2003 11:23:33 -0400

Hi there

I just  want to know is there any way to find out the PID
ans how much a
process is using
the physical and virtual memory, as it is show by the
Windows NT task
manager.

Thanks

Biju

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]


_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]


Well your Process id is $$, But I haven't any ideas on retieving the physical/virtual mem.

Tim Musson
Thanks Rob,

My MUA believes you used Internet Mail Service (5.5.2653.19)
to write the following on Friday, August 8, 2003 at 8:43:43 AM.

HR> # store access the internal hash by following the reference "->"
$hash{four}->>{uid} = "uid4";
$hash{four}->>{cn} = "cn4";
$hash{four}->>{group} = "Group4";

I knew there would be an easy way, don't know why I didn't try that!

Thanks again!

--
Tim Musson
Flying with The Bat! eMail v1.62q
Windows 2000 5.0.2195 (Service Pack 3)
As I said before, I never repeat myself.

William Black
Hello All,

I have an array with the following lines, that always follow this format. I
need a regular expression that will just pull the data at the end of the
sentence. For example, only AZID, IA, KSOK, MO, NVUT, OR.

The Wall will tell ME to update AZID.
The Wall will tell ME to update IA.
The Wall will tell ME to update KSOK.
The Wall will tell ME to update MO.
The Wall will tell ME to update NVUT.
The Wall will tell ME to update OR.

William Black

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail

Rob Dixon
"William Black" <[Email Removed]> wrote in message news:[Email Removed]...
QUOTE
Hello All,

I have an array with the following lines, that always follow this format.  I
need a regular expression that will just pull the data at the end of the
sentence.  For example, only AZID, IA, KSOK, MO, NVUT, OR.

The Wall will tell ME to update AZID.
The Wall will tell ME to update IA.
The Wall will tell ME to update KSOK.
The Wall will tell ME to update MO.
The Wall will tell ME to update NVUT.
The Wall will tell ME to update OR.

Hi William.

What you write depends on whether you want to /check/ the contents
of the data or simply extract the final word.

This program will extract the last complete word from any array of
strings, but won't check that the string started with

'The Wall will tell ME to update '

is this what you want?

HTH,

Rob



use strict;
use warnings;

my @array = (
'The Wall will tell ME to update AZID.',
'The Wall will tell ME to update IA.',
'The Wall will tell ME to update KSOK.',
'The Wall will tell ME to update MO.',
'The Wall will tell ME to update NVUT.',
'The Wall will tell ME to update OR.',
);

my @lastword = map /.*b(w+)/, @array;

print "$_n" foreach @lastword;

OUTPUT

AZID
IA
KSOK
MO
NVUT
OR

William M West
QUOTE
now that i've looked at it, it's really for getting to files that are
unlinked etc..... so i am not sure it will do you any good.

Partly it might. The only problem with your script is that it cannot
deal with data that is spanning more than 12 inodes (those were usually
not in one block but fragmented over the harddisk). A line like this
shows such a trickier example:

99526      0 100644 676132    1/1027 Sat Feb  2 09:11:58 2002

I don't by hard know what to do with it, but it is laid out in the ext2
undeletion how-to.


well, the undeletion howto is a little old (1999) but interesting to look
through...


http://tldp.org/HOWTO/Ext2fs-Undeletion.html#toc9


QUOTE

to bring this more on topic, i would like to see what ways something like
this can be improved- it served useful to me in the past, but i'm sure it
can be made more useful:::


#!/usr/bin/perl

# added proper things when retyping it:
use warnings;
use diagnostics;
use strict;
#-------------------

my $cfile = "/tmp/commands.file";
my $filesystem ="/dev/hda6";
my @path = ("/tmp/recover","","/recover","",".ebu");  #making a path to
put
my $date="Oct"; #just files from October  #stuff later

open (OUT,">$cfile");
print OUT "open $filesystemn";# i wonder what this is for?

Debug message?


no! :) debugfs -f /filepath :) open opens the filesystem without
mounting it... then dump does its thing- all inside debugfs!!


QUOTE

command.file is the list of dump directives. It's supposedly a shell
script that you can run later. So the above Perl script just generates
another script. I am just not sure about

print OUT "open $filesystemn";

open /dev/hda6

is not a meaningful command in shell scripts AFAIK.


and the mystery is solved!!!


now i would like to look into using this to make a perl script to automate
file recovery.... well, someday at anyrate!

willy

:)

David
QUOTE
"Sharad Gupta" <[Email Removed]> wrote in message
news:[Email Removed]...
Hi All,

I am really tired now:

--------------------------------------
package Foo;

use strict;
use LWP::UserAgent;


sub new {
return bless {},shift;
}


sub Foo::INC {
my ($self,$filename) = @_;
my @paths = "http:/me.com";
my @urls = map{$_ . "/" . $filename}@paths;
my $ua = LWP::UserAgent->new();
foreach my $url(@urls) {
my $request    = HTTP::Request->new($url);
my $response = $ua->request($request);
if($response->is_success()) {
return $response->content();
}
}
return undef;
}
--------------------------------------


What i am trying to do is hook into the @INC so that i can find the
modules via http, but a simple test like:

--------------
#!/usr/local/bin/perl

BEGIN { push @INC,Foo->new() }
use Bar;
-------------

Cannot find Bar.pm.


Any ideas??.

interesting. without you providing much background information, purpose
(actually you did say you are trying to hook into @INC but i don't really
know what you mean by that), etc, i can only guess that you are trying to
build, compile and include some other modules when your users say "use Foo".
below is a toy program that hopefully will get you closer to what you need:

package Foo;

END{ unlink @ms }

our @ms;

sub new{
return bless {} => shift;
}

sub hi{
print "hin";
}

#--
#-- dynamicly build and include whatever modules the users requested
#--
sub import{

my $class = shift;

for(@_){

open(NM,">$_.pm") || die $!;

push(@ms, "$_.pm");

print NM qq/
package $_;
sub new{
return {} => shift;
}
sub $__say_hi{
print "$_ says hi\n";
}
1;
/;

close(NM);

require "$_.pm";
}
}

1;

__END__

a driver:

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

#--
#-- Foo.pm builds Bar.pm and Ber.pm and Bee.pm and use it
#-- in fact, you can put as many module names here and Foo.pm will build it
for you
#--
use Foo qw(Bar Ber Bee);

my $f = Foo->new; $f->hi;

#--
#-- no need to 'use Bar' or 'use Ber' or 'use Bee' because Foo.pm does that
for us per request
#--
my $bar = Bar->new; $bar->Bar_say_hi;
my $ber = Ber->new; $ber->Ber_say_hi;
my $bee = Bee->new; $bee->Bee_say_hi;

__END__

prints:

hi
Bar says hi
Ber says hi
Bee says hi

in fact, if you look around, you wouldn't even find Bar.pm, Ber.pm or Bee.pm
anywhere because they only exist during your program runs and are deleted
automatically when your program ends. the user never know the existance of
them but are available for use when they need it! a pretty neat idea but
kind of dangerous (especially if you are downloading the modules from the
Net). you can use this technique (if you really want to do that and know
exactly what you are doing) to build arbitary complex class on the fly. the
idea is very simply though. again, without knowing what you are really
trying to accomplish, i can't recommand anything else.

david

Sharad Gupta
Ur examples are cool. I never knew i can do that.

But my problem was:

I was trying to port some of my scripts to Windows.
I know i can get all of the modules which my already written scripts would be using via http. And i did'nt wanted to map the drive on *all* the windows machines and add it to to @INC before using them.

So, i thought may be i can put something in @INC so that I never care where the modules/scripts are coming from.

Now with my implementation, my idea is i would ask my sysadmin to have a system wide:
PERL5OPTS = -MFoo

variable set.

So that whenever anybody says :

#<path to perl>

use Bar;

They get a copy of Bar w/o copying it locally.



Hope i stated my problem well.


Now another question:

In ur examples u r are unlinking the files in the END block, and i was unlinking them in the DESTROY method. Any differences??

-Sharad

-----Original Message-----
From: david [mailto:[Email Removed]]
Sent: Saturday, August 09, 2003 12:27 AM
To: [Email Removed]
Subject: Re: Ok I am tired


QUOTE
"Sharad Gupta" <[Email Removed]> wrote in message
news:[Email Removed]....
Hi All,

I am really tired now:

--------------------------------------
package Foo;

use strict;
use LWP::UserAgent;


sub new {
return bless {},shift;
}


sub Foo::INC {
my ($self,$filename) = @_;
my @paths = "http:/me.com";
my @urls = map{$_ . "/" . $filename}@paths;
my $ua = LWP::UserAgent->new();
foreach my $url(@urls) {
my $request    = HTTP::Request->new($url);
my $response = $ua->request($request);
if($response->is_success()) {
return $response->content();
}
}
return undef;
}
--------------------------------------


What i am trying to do is hook into the @INC so that i can find the
modules via http, but a simple test like:

--------------
#!/usr/local/bin/perl

BEGIN { push @INC,Foo->new() }
use Bar;
-------------

Cannot find Bar.pm.


Any ideas??.

interesting. without you providing much background information, purpose
(actually you did say you are trying to hook into @INC but i don't really
know what you mean by that), etc, i can only guess that you are trying to
build, compile and include some other modules when your users say "use Foo".
below is a toy program that hopefully will get you closer to what you need:

package Foo;

END{ unlink @ms }

our @ms;

sub new{
return bless {} => shift;
}

sub hi{
print "hin";
}

#--
#-- dynamicly build and include whatever modules the users requested
#--
sub import{

my $class = shift;

for(@_){

open(NM,">$_.pm") || die $!;

push(@ms, "$_.pm");

print NM qq/
package $_;
sub new{
return {} => shift;
}
sub $__say_hi{
print "$_ says hi\n";
}
1;
/;

close(NM);

require "$_.pm";
}
}

1;

__END__

a driver:

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

#--
#-- Foo.pm builds Bar.pm and Ber.pm and Bee.pm and use it
#-- in fact, you can put as many module names here and Foo.pm will build it
for you
#--
use Foo qw(Bar Ber Bee);

my $f = Foo->new; $f->hi;

#--
#-- no need to 'use Bar' or 'use Ber' or 'use Bee' because Foo.pm does that
for us per request
#--
my $bar = Bar->new; $bar->Bar_say_hi;
my $ber = Ber->new; $ber->Ber_say_hi;
my $bee = Bee->new; $bee->Bee_say_hi;

__END__

prints:

hi
Bar says hi
Ber says hi
Bee says hi

in fact, if you look around, you wouldn't even find Bar.pm, Ber.pm or Bee.pm
anywhere because they only exist during your program runs and are deleted
automatically when your program ends. the user never know the existance of
them but are available for use when they need it! a pretty neat idea but
kind of dangerous (especially if you are downloading the modules from the
Net). you can use this technique (if you really want to do that and know
exactly what you are doing) to build arbitary complex class on the fly. the
idea is very simply though. again, without knowing what you are really
trying to accomplish, i can't recommand anything else.

david



--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

Quenten Griffith
Disregard I had an extra space after the glob $file
part once I made it (glob $file) instead of (glob
$file ) it worked. Odd very odd.
--- Quenten Griffith <[Email Removed]> wrote:
QUOTE
Hello all,

For somereason I have a bit of code that will not
write out to the log file when it finds my array
empty


#Start of upload Files
    } elsif ( $ARGV[1] eq "-p" ) {
      $log->write("<INFO> Ok we have been passed the
-p so we will be putting files to $site");
my $ftp = Net::FTP->new("$site") or
$log->write("<ERROR> Could not est. connection to
$site: $@n");  #makes the connection the site or
logs
      $ftp->login("$user","$password") or
$log->write
("<ERROR> Bad user name or password");
      $ftp->cwd("$dir") or $log->write( "<ERROR
could
not cd to $dir" );
chdir ("/ftp/pathlor/outgoing") or die
"could not cd"; #where we get the files from to send
my @mput_files = (glob "$file" );
    print "@mput_files";
    if (!@mput_files) { $log->write("<ERROR> $file
not
found for upload");
}
      foreach my $put_files ( @mput_files  ) {
$ftp->put("$put_files");
$log->write("<INFO> U/L $put_files")
}
}
}
}


Right here is where it should log
my @mput_files = (glob "$file" );
print "@mput_files";
if (!@mput_files) { $log->write("<ERROR> $file not
found for upload");
}

I added the print function just to see what
@mput_files returns and it returns nothing but I do
get an error from the glob on the command line
"Cannot open Local file : A file or directory in the
path name does not exist" I am wondering if this is
some how messing up my check.  Basically what I am
doing is looking at a dir. of files and looking for
files that match my $file variable which usually is
$file = *.txt  I am trying to find a way to use wild
card charcters to find the files I want in a dir and
upload them to a ftp server.  Thanks for your help.


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

--
To unsubscribe, e-mail:
[Email Removed]
For additional commands, e-mail:
[Email Removed]



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

Michele Ouellet
"Jayson Prichard" <[Email Removed]> wrote in message
news:[Email Removed]...
Does anyone know where I can find the interfaces to Visio?

Hi!

I have read Visio properties, but I am not sure it has Custom Properties. At
any rate, this URL should get you started. Good luck,

ms-help://MS.MSDNQTR.2002APR.1033/dnvbdev01/html/vb01j1.htm

Michle Ouellet.

Perlwannabe
In my zeal for making things simple I may have created a problem. OK,
here is the lowdown:

the real file names I am trying to delete from the directory are rather
lengthy and complicated and look like:

partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042997-0-0
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042995-0-0
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042882-0-0
.. . .

I cut the names down in my previous posts to 'item997' for ease and
simplicity, this was a mistake on my part as I am a true "beginner." It
appears that unlink does not like something in the real file name and is
having trouble deleting such a long file name.

If I drop to command prompt and type "del *997*.* the file
"partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042997-0-0" is deleted.
So I tried to use the unlink and it did not work. However, I then renamed
the lengthy file name to "5item997.txt" and used the unlink to "*997*.*"
AND IT WORKED!!!

This means that there is something with the original filename (the really
long one) that the unlink command does not like...perhaps the length, or
the underscores, or the - (dashes), etc.

Sorry for the problem. All of the previous responses worked and everyone
was helpful. My description was lacking...a mistake I will not make
again.

Is there some magical command that unlink needs to delete such a long file
name? Are there characters in the filename that is giving unlink a
problem?
Man, I am so close I can taste it. Again, thank you for all of your help.

Tim Musson
Hey John,

My MUA believes you used Mozilla 4.79 [en] (X11; U; Linux 2.4.4-4GB i586)
to write the following on Thursday, July 24, 2003 at 1:49:25 PM.

QUOTE
I wonder is there an official tech slang acronym site?

JWK> This is probably as close as you are going to get:

JWK> http://catb.org/~esr/jargon/

I like http://www.acronymfinder.com/

--
Tim Musson
Flying with The Bat! eMail v1.62q
Windows 2000 5.0.2195 (Service Pack 3)
Why is it that doctors call what they do "practice"?

Zentara
On Fri, 8 Aug 2003 09:06:25 -0400, [Email Removed] (Stephen
Gilbert) wrote:

QUOTE
-----Original Message-----
From: Biju Ramachandran [mailto:[Email Removed]]
Subject: Re: pid->memory usage - Any takers
Please, anybody...

I just  want to know is there any way to find out the PID
ans how much a
process is using
the physical and virtual memory, as it is show by the
Windows NT task
manager.

Well your Process id is $$, But I haven't any ideas on retieving the physical/virtual mem.

You ought to be looking at the Proc::ProcessTable module.
I don't know about your NT requirement, but the following
is a sample that works well under linux.

#!/usr/bin/perl -w
use strict;
use Proc::ProcessTable;

my $t = new Proc::ProcessTable();

foreach my $p (@{$t->table}){
print $p->pid," ",$p->cmndline," ",$p->size,"n";
}
__END__

Dave Arnold
In article
<YW50aWdvbmU=[Email Removed]>,
perlwannabe <[Email Removed]> wrote:
[Snip]
QUOTE
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042997-0-0
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042995-0-0
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042882-0-0
[Snip]
So I tried to use the unlink and it did not work.  However, I then
renamed the lengthy file name to "5item997.txt" and used the unlink to
"*997*.*" AND IT WORKED!!!

Just a suggestion, but could it be because unlink is taking the delete
"*.*" literally and expecting the file to contain a dot, whereas the shell
"knows" about DOS extensions and removes files without them?

Dave.

Steve Grazzini
On Fri, Aug 08, 2003 at 10:49:39PM -0700, Gupta, Sharad wrote:
QUOTE
sub Foo::INC {
my ($self,$filename) = @_;
my @paths = "http:/me.com";
my @urls = map{$_ . "/" . $filename}@paths;
my $ua = LWP::UserAgent->new();
foreach my $url(@urls) {
my $request = HTTP::Request->new($url);
my $response = $ua->request($request);
if($response->is_success()) {
return $response->content();

You're supposed to return a filehandle:

open my $fh, '<', ($response->content);
return $fh;

QUOTE
}
}
return undef;
}

I'd also suggest caching the downloaded modules and letting
the constructor take a list of base urls.

And by the way, does anybody know offhand why the subroutine
name needs to be fully-qualified in the declaration? I haven't
really looked at this feature, but it seems like an strange
requirement.

--
Steve

Perlwannabe
QUOTE
This works - i've tried it...

print 'Deleted ' , unlink (<*997*>) , ' files.n';

good luck
Duncan

Yes, it does. But it does not work when reading from a variable.

my $temp = '*997*';
print 'Deleted ' , unlink (<$temp>) , ' files.n';

This very simple variation of your example does not work.

The problem is that I have to read from a file and put the value from the
file into a variable. Although your "hard coded" example does work, it
doesn't work for a value read in from an external file and into a
variable. Any other ideas? I am all ears and out of ideas.

Sharad Gupta
QUOTE
You're supposed to return a filehandle:

Yep. But i am using the temp files for doing that. And i would love to get rid of the temp files altogether.

open my $fh, '<', ($response->content);

Seems like we are opening a filehandle to a string. Very difficult to convince my sysadmin to get to 5.8 soon. Any other suggestions to get rid of those temp files. I hate them.


QUOTE
I'd also suggest caching the downloaded modules

Give me a little of your magical sight -:)


QUOTE
letting the constructor take a list of base urls.
Yes, thats what i would be doing in production.



QUOTE
And by the way, does anybody know offhand why the subroutine
name needs to be fully-qualified in the declaration?

Require says:

If the hook is an object, it must provide an INC method, that will be called as above, the first parameter being the object itself. (Note that you must fully qualify the sub's name, as it is always forced into package main.)


Thanx,
-Sharad

-----Original Message-----
From: Steve Grazzini [mailto:[Email Removed]]
Sent: Saturday, August 09, 2003 1:51 PM
To: Gupta, Sharad
Cc: [Email Removed]
Subject: Re: Ok I am tired


On Fri, Aug 08, 2003 at 10:49:39PM -0700, Gupta, Sharad wrote:
QUOTE
sub Foo::INC {
my ($self,$filename) = @_;
my @paths = "http:/me.com";
my @urls = map{$_ . "/" . $filename}@paths;
my $ua = LWP::UserAgent->new();
foreach my $url(@urls) {
my $request = HTTP::Request->new($url);
my $response = $ua->request($request);
if($response->is_success()) {
return $response->content();

You're supposed to return a filehandle:

open my $fh, '<', ($response->content);
return $fh;

QUOTE
}
}
return undef;
}

I'd also suggest caching the downloaded modules and letting
the constructor take a list of base urls.

And by the way, does anybody know offhand why the subroutine
name needs to be fully-qualified in the declaration? I haven't
really looked at this feature, but it seems like an strange
requirement.

--
Steve

Steve Grazzini
On Sat, Aug 09, 2003 at 08:57:54PM -0700, Gupta, Sharad wrote:
QUOTE
You're supposed to return a filehandle:

Yep. But i am using the temp files for doing that. And i
would love to get rid of the temp files altogether.

open my $fh, '<', ($response->content);

Seems like we are opening a filehandle to a string. Very
difficult to convince my sysadmin to get to 5.8 soon. Any
other suggestions to get rid of those temp files. I hate
them.

IO::Stringy (non-core module) was the old way to do it...

QUOTE
I'd also suggest caching the downloaded modules

Give me a little of your magical sight -:)

It's not secure, but in a safe environment you could write
$res->content to some cache directory. Then before downloading
anything, just check the cache.

QUOTE
And by the way, does anybody know offhand why the subroutine
name needs to be fully-qualified in the declaration?

Require says:

Note that you must fully qualify the sub's name, as it is
always forced into package main.

Yeah, that seems strange.

I suppose that *INC is "special", for the sake of %INC and
@INC... But I didn't expect it to force the subroutine
declaration into main:: as well.

--
Steve

David
"Perlwannabe" <[Email Removed]> wrote in message
news:YW50aWdvbmU=[Email Removed]...
QUOTE
This works - i've tried it...

print 'Deleted ' , unlink (<*997*>) , ' files.n';

good luck
Duncan

Yes, it does.  But it does not work when reading from a variable.

my $temp = '*997*';
print 'Deleted ' , unlink (<$temp>) , ' files.n';

This very simple variation of your example does not work.

the reason why YOUR version won't work is because when Perl sees '<$temp>',
it's trying to read from the file handle '*997*'. it's NOT doing glob for
you. example:

my $s = '*.pl';
my @c = ('*.pl');

#--
#-- even though the following 2 lines seems identical and should work to
give you
#-- all file names ending with *.pl in the current directory, only the
second version really works
#--
my @files1 = <$s>; #-- this does not work because Perl is trying to read
from the '*.pl' file handle!
my @files2 = <$c[0]>; #-- this does work. see reason below

for(@files1){
print "@files1: $_n";
}

for(@files2){
print "@files2: $_n"; #-- only this get print out.
}

to make the long story short: Perl consider $s to be a simple scalar (and
yes that's the official term) and whenever a simple scalar is put inside
'<>', Perl assumes it's a file handle that you are trying to read from.
otherwise, you can't even:

open(my $file,'some.txt') || die;
while(<$file>){ #-- doing glob or reading from $file?
#-- code
}
close($file);

it's reading from $file (the file handle) because $file is a considered to
be a simple scalar. now if you were to change your script to look like:

my $temp = '*997*';
print 'Deleted ' , unlink (<@{[$temp]}>) , ' files.n';

it will work because that tells Perl the stuff inside '<>' is not a file
handle so it should be handed to the glob function.

QUOTE

The problem is that I have to read from a file and put the value from the
file into a variable.  Although your "hard coded" example does work, it
doesn't work for a value read in from an external file and into a
variable.  Any other ideas?  I am all ears and out of ideas.


if you were really "all ears out", you should have tell us where all of your
files live and how (and where) you execute your script. i still think your
problem is largely related to Perl not able to find the files because you
are running the script from a different directory.

david

R. Joseph Newton
Rob Dixon wrote:

QUOTE
But the version he already has installed is free too, and there's probably nothing
wrong with it!

So, thaz more important does Kenneth still is looking in this thread, rather than
me. I am not sure if he gave me further reply or not. But I sure that if he think
have to pay for Perl and giving it up, thaz a LOSS.

Are you still here Kenneth? Feel free to go on if you need any help =)

I also got a personal mail from Ken, saying that he had found and downloaded
Perl from ActiveState. But he also said that he had found strict.pm in his installation,
and I am very wary of encouraging an upgrade when it isn't necessary. Is the
build of Perl that's installed with Oracle even an ActiveState version? If
not there may be a number of differences apart from the Perl release version
which Oracle relies on in some way.

Rob

Hi Rob,

I am going to take issue with you on this one, on general principle. Oracle does not have
the best interests of Perl programmers in mind. There is really no good reason for someone
interested in Perl programmeing to settle for a default bundled version of Perl.

As a support technician, I frequently come across bundled versions of standard utilities that
are simply inadequate. Either they are outdated, or they only install the subset of
functionalities neded for that one program. Only as a last resort, for software that simply
cannot run without obsolete versions of such utilities, will I accede to the default install.

Much better to install each basic application discretely. Oracle is not among the standard
sources for a good Perl installation. It may be that some configuaration changes in Oracle
will be required in order to accomodate a antive Perl. Better to do that than to cripple
along on a quirky non-standard special-purpose Perl.

It is also possible that the Oracle installation is set to use its own Perl under any
circumstances. If not, and if it cannot accomodate the presence of a current full version of
Perl, then Oracle is broken and needs to be fixed.

Under any circumstances, I would recommend that a person starting into perl start out with
the current, and full version, from a Perl-oriented source.

Joseph

Shawn Milochik
excellence_personified@
hotmail.com To: [Email Removed]
cc:
08/10/2003 11:17 PM Subject: Re: document creation.











----- Original Message -----
From: "Wiggins D'Anconia" <[Email Removed]>
Newsgroups: perl.beginners
To: "Chris Knipe" <[Email Removed]>
Cc: <[Email Removed]>
Sent: Saturday, August 09, 2003 5:07 PM
Subject: Re: document creation.


QUOTE
Chris Knipe wrote:
Lo all,

I want to create large number of documents (mainly invoices) using
perl.

In
QUOTE
a couple of months, I should be creating a few hundred documents per
month
with a few million records in total for the documents (Telecoms
implementation).

Now, preferably, I wanted to create MS Word documents for this, but
alas, a
stick was shoved into that idea.  Win32::OLE doesn't work from *Nix,
and
RTF::Document has like zero documentation (very help full thanks)...


MS Word, thats portable, not to mention the size and lack of revision
control, ick.  Open source is your friend. Not enough documentation,
open the code and have a look yourself...


What's my alternatives???


What is your end goal? You just say that you need to create documents,
etc for storage but you don't say how they will be used.

Please keep in mind where possible, I'd like to automatically print the
invoices prior to archiving the hard documents.  The documents is also
quite
complex layout wise, with allot of graphs (Images) and about 95% table
based... Is HTML really the only alternative here??  I'm not sure
whether
printing HTML will be a very good idea...


HTML is one option but not the only one. XML would be the naturally most
portable and upgradeable probably.

XML probably is your best bet assuming you are proficient in the use of
XSL.
I'll assume you're not when I say you'd do best using SGML, but then you
may
not be proficient in that either. Deprived of alternatives, learn the
basics of CSS. Page breaks do work in CSS, and there are many quick and
dirty tutorials online if you need it soon. So your documents will be HTML
and CSS, which isn't your very best bargain but which you can still work
with.

K.P.
_____________________________________________________





--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]



Just in case this is helpful to anyone:

HTML/CSS page breaks. This is the easiest way I've found to do this.

How to make a printer do a form feed using HTML, in order
to allow the browser app to do page-breaks.

If the following CSS exists:

<STYLE TYPE="text/css">
#break
{
page-break-AFTER: always;
}
</STYLE>


Then the following HTML will force a page break while printing:


<p ID='break'>



Shawn




**********************************************************************
This e-mail and any files transmitted with it may contain
confidential information and is intended solely for use by
the individual to whom it is addressed. If you received
this e-mail in error, please notify the sender, do not
disclose its contents to others and delete it from your
system.

**********************************************************************

Stephen Gilbert
QUOTE
-----Original Message-----
From: SilverFox [mailto:[Email Removed]]
Sent: Sunday, August 10, 2003 4:58 PM
To: [Email Removed]
Subject: Net::Telnet


hey anyone know how to check if a file exists using the Telnet module?

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

try:

$file_exists = $t->cmd("perl -e 'print 1 if (-s "file")'") or warn "Unable to execute command: $!n";
if ($file_exists) {
# do whatever
}

Silverfox
Jeff Westman wrote:

QUOTE

--- SilverFox <[Email Removed]> wrote:
Hey can someone help me figure out why the value of $file_exists won't
change even when the file is mssing???? Thx.

#!/usr/bin/perl -w
$out="/home/laptop/scripts/perl/logs/resetmf.log";
open OUT, ">>$out" or die "Unable to open $out :$!";

@site=("Machine1","Machine2");
#telnet
use Net::Telnet;
$t = new Net::Telnet (Timeout=>10,
Errmode=>'die',
Prompt=>'/$ $/i');
foreach (@site) {
$t->open($_);
$t->login('username','passwd');
print OUT scalar(localtime), " Conn EST: $_.n";


$dir="pf/working/output/Channel_status";
@newdir=("/Machine1/$dir","/Machine2/$dir","/Machine9/$dir");

for($x=0; $x <= $#newdir; $x++) {


$file_exists = $t->cmd ("perl -e 'print 1 if (-s "$newdir[$x]")'") or
warn "Unable to execute: $!n";

if ($file_exists) {
print "Found itn";
}else{
print "File Missingn";

}
}
}


When I tried to run your cmd/perl line simply to test that part, I got:

$file_exists = $t->cmd ("ksh: syntax error: `(' unexpected

Alternatively, you might try something simpler like:

$file_exists = $t->cmd("test -f $newdir[$x] && print 1 || print 0");



-JW


hmmm....I'm still getting the same results. Think it have something to do

with my shell (/usr/bin/sh).

Pinku Bhatnagar
Hey Jerry,

I have a one quick solution for you.

str = ""q4171","(08/11/03 23:30:48)",""";
@array = split(/,/,$str);
foreach (@array)
{
s/"//g ;
}


HTH
Pinku


Jerry Preston wrote:
QUOTE
Hi!,

I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|"]/;#"

but I get many parts of the array that are empty.

All I want is in between the "'s.

Thanks,

Jerry


Pinku Bhatnagar
hi Jerry,

On second thought, I have a better solution for you.

$str = ""q4171","(08/11/03 23:30:48)",""";
@array = $str =~ /"([^"]*)"/g;

HTH
Pinku

Jerry Preston wrote:

QUOTE
Hi!,

I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|"]/;#"

but I get many parts of the array that are empty.

All I want is in between the "'s.

Thanks,

Jerry


Tor Hildrum
perlwannabe wrote:
QUOTE
Now that I have, with all of you helping, dealt with the unlink problem.
I am now faced with a new problem.

I have a file, myfile.txt, that consists of various text items that are
repetitive.  I am trying to replace many of the repetitive items with a
place holder. Here is an example of myfile.txt:

From the script under you are just replacing lines with a static
line/value.

<snip>

QUOTE
Perhaps I am attacking this problem wrong by using hex, but it seems
easier to use then text which has carriage returns, tabs, and spaces.

I don't see any reason to use hex.
There is a common idiom to use when searching for repetitions/uniqueness.
## untested example :)

@array = qw(one two one three four);

for (@array) {
if (defined($unique{$_}) {
s/$_/replacement/;
} else {
$unique{$_}++; ## $unique{$_} is now defined and true.
} ## and will be replaced if it comes up again

This works equally well for files, it's just a matter of s/@array/<FH>/
There *might* be a question of memory usage though, depending on
the size of the file your working with.

Also, sort -u would be faster and more efficient if you have large files,
but didn't need the replacement text.

Tor

Bob Showalter
perlwannabe wrote:
QUOTE
Now that I have, with all of you helping, dealt with the unlink problem.
I am now faced with a new problem.

I have a file, myfile.txt, that consists of various text items that are
repetitive.  I am trying to replace many of the repetitive items with a
place holder. Here is an example of myfile.txt:

This is a long file with sentences, paragraphs and returns.  Certain
portions of the file never change and are simply repetitive. I would like
to replace all of the repetitive items with a placeholder...call it
placey."
_END FILE_

I would like to replace "This ... items" with "placey" so the above would
look like:

placey with a placeholder...call it "placey."

When attacking this problem I thought it would be best to use hex values
so as not to deal with returns, etc.  myfile.txt in hex is:

54 68 69 73 20 69 73 20 61 20 6C 6F 6E 67 20 66 69 6C 65 20 77 69 74 68 20
73 65 6E 74 65 6E 63 65 73 2C 20 70 61 72 61 67 72 61 70 68 73 20 61 6E 64
20 72 65 74 75 72 6E 73 2E 20 20 43 65 72 74 61 69 6E 20 70 6F 72 74 69 6F
6E 73 0D 0A 6F 66 20 74 68 65 20 66 69 6C 65 20 6E 65 76 65 72 20 63 68 61
6E 67 65 20 61 6E 64 20 61 72 65 20 73 69 6D 70 6C 79 20 72 65 70 65 74 69
74 69 76 65 2E 20 20 49 20 77 6F 75 6C 64 20 6C 69 6B 65 20 74 6F 20 72 65
70 6C 61 63 65 20 61 6C 6C 0D 0A 6F 66 20 74 68 65 20 72 65 70 65 74 69 74
69 76 65 20 69 74 65 6D 73 20 77 69 74 68 20 61 20 70 6C 61 63 65 68 6F 6C
64 65 72 2E 2E 2E 63 61 6C 6C 20 69 74 20 22 70 6C 61 63 65 79 2E 22

Here is the little script that I am working with and, obviously, is not
working:

my $filefirst = "c:/perl/myfile.txt";
open(FILE,"<$filefirst") || die "Could not open file for reading!  $!";
open(TEMP,">$filefirst.tmp") || die "Could not open file for writing!
$!";
# I have used the . . . to show that the entire hex string is really there
my $hextostr = 'x54x68x69x73 . . . x79x2Ex22';
while(<FILE>){
$_ =~ s/$hextostr/placey/gi;
print TEMP $_;
}

You don't need the hex business (although it will work). Assuming your
long literal is in a variable $string, just:

s/Q$string/placey/gi;

will work (do you need /i?)

The problem appears to be that you are reading the file line by line,
but want to search and replace over multiple lines. If you set $/ to
undef, you can read the whole file into a single string and perform
the replacement that way.

QUOTE


Perhaps I am attacking this problem wrong by using hex, but it seems
easier to use then text which has carriage returns, tabs, and spaces.

How so?

$string = "Here is texttwithnnnewlines and tabstand spaces.n";

Jeff 'Japhy' Pinyan
On Aug 12, Jerry Preston said:

QUOTE
I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|"]/;#"

Either use the Text::CSV module from CPAN (or perhaps Text::CSV_XS), or
else use a regex like the following:

@fields = $str =~ m{ " [^"]* " | [^,]+ }xg;

If you also want to strip quotes, you can do:

@fields = map { s/^"// and s/"$// } $str =~ m{ ... }xg;

(Just fill the regex in.)

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

Zentara
On Tue, 12 Aug 2003 01:29:39 -0400 (EDT), [Email Removed]
(Perlwannabe) wrote:

QUOTE
Here is the little script that I am working with and, obviously, is not
working:

my $filefirst = "c:/perl/myfile.txt";
open(FILE,"<$filefirst") || die "Could not open file for reading!  $!";
open(TEMP,">$filefirst.tmp") || die "Could not open file for writing!  $!";

#are you using windows?
binmode FILE; #need binmode under windows
binmode TEMP;

QUOTE
# I have used the . . . to show that the entire hex string is really there
my $hextostr = 'x54x68x69x73 . . . x79x2Ex22';
while(<FILE>){
$_ =~ s/$hextostr/placey/gi;
print TEMP $_;
}


Perhaps I am attacking this problem wrong by using hex, but it seems
easier to use then text which has carriage returns, tabs, and spaces.

I hope this explains the situation.


Bob Showalter
Dan Muey wrote:
QUOTE
Howdy,

I realize that $ENV{'REMOTE_HOST'} and $ENV{'REMOTE_ADDR'} are handled
differently and can be spoofed so don't worry I'm not basing any
security on them.

I'm no security expert, but how can these be spoofed? They don't come from
the request headers, but are derived from the TCP connection itself.

Furthermore, how useful are these anyway? For example, I'm currently sitting
behind a NAT proxy along with 300 or so other folks, so you'll see the same
REMOTE_ADDR for any of us who visit your site. Or is that what you mean by
"spoof"?

Bob Showalter
Dan Muey wrote:
QUOTE
Dan Muey wrote:
Howdy,

I realize that $ENV{'REMOTE_HOST'} and $ENV{'REMOTE_ADDR'} are
handled differently and can be spoofed so don't worry I'm not
basing any security on them.

I'm no security expert, but how can these be spoofed? They
don't come from the request headers, but are derived from the
TCP connection itself.

Well I'm not sure, I always thought what you said was true,

OMG! don't assume that! :~)

QUOTE
but you
always hear folks saying that so I was trying to avoid the pummeling
I felt would be inevitable.

:~)

QUOTE


Furthermore, how useful are these anyway? For example, I'm
currently sitting behind a NAT proxy along with 300 or so
other folks, so you'll see the same REMOTE_ADDR for any of us
who visit your site. Or is that what you mean by "spoof"?


True, what I was logging was the ip that certain scripts were called
from. I have some websites that use LWP to call a script on my server.
So basically that means that, unless, something is changed on their
server, my server will always see them as coming from the same ip
address. If there are discrepencies I can look into it if it matters.

As much as like to be able to only allow access from certain
IP address I don't do it because everyone rants on and on
about $ENV beinag able to be spoofed so easily.

Well, it can't be spoofed in the sense of being faked. If I'm connecting
from 206.107.121.3, There's no way to convince your server that I'm really
connecting from 66.118.101.132, AFAIK.

However, If I can use an intermediate system as a proxy, I can convince you
that I'm coming from a different host than I "actually" am.

QUOTE

So correct me if I'm wrong but if I have a script that runs on a
server that I am the only user on and I am the only person allowed to
put anythign on it then $ENV{'REMOTE_ADDR'} may be a fairly reliable
way to limit access?? (barring my hero Kevin Mitnick and friends ;p)

No, if by "server" you mean the server on which you are looking at
REMOTE_ADDR. REMOTE_ADDR is the client address. You don't want to build any
scheme based on the supposed hardness of the client system.

But because of proxies, you may have a "good guy" and a "bad guy" using the
same proxy. So you can't use REMOTE_ADDR alone to distinguish between the
two for identification purposes.

If it matters, you need some way for the client to pass you some credentials
with the request that you can validate. You may even want to do this in
combination with REMOTE_ADDR, to decrease the risk that the credentials have
been compromised and are being used to attempt to gain access from an
unexpected host.

QUOTE


die "You not allowed freako!n" unless $ENV{'REMOTE_ADDR'} =~
m/^1.2.3.4$/; die "You gots to be logged in jack!n" unless
$ENV{'REMOTE_USER'} =~ m/^w+$/;


Dan Muey
I think what I'll do is just log $ENV{'REMOTE_HOST'} and $ENV{'REMOTE_USER'}
into a mysql database so I can review that info to watch for abusers.

Since they are logging in that will help verify most everybody and if a
user wants to give out his login info to other folks then just watching my little log
should help identify that, investigate it a bit, and then cancel their account if they
are actually being stupid.

Anywho thanks for your time and inpout Bob, I apprciate it!

Dan


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.