Re: Packages, run modes, and scopes, oh my

2003-06-28 Thread Andrew Brosnan
On 6/27/03 at 11:40 PM, [EMAIL PROTECTED] (Scot Robnett) wrote:

 I was wondering if anyone can point me to newbie-type tutorials on
 any of the following (including but not limited to which perldocs I
 can read):
 
   - Definition of 'lexical' and 'canonical'
   - Differences between 'my' and 'local'
   - Good overview of packages and namespaces
   - How to build modules
   - Effective re-use (building subroutines for
 efficiency and portability)
   - Why do I '@_ = shift;' on subroutines?

Get Randal Schwartz's new book 'Learning Perl Objects References and
Modules' from O'Reilly. 

http://www.oreilly.com/catalog/lrnperlorm/

Andrew



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



Re: Why not Class Objects

2003-06-28 Thread drieux
On Friday, Jun 27, 2003, at 07:22 US/Pacific, Daniel J. Rychlik wrote:

Thank you sir for the response, I will have a look.  I love 
programming in
perl, but Im getting used to the idea of developing class objects and
instances in PHP.

class thisclass {

}

class otherclass extends thisclass {

}

Object oriented programming is a great way to reuse code.
you might want to do

	perldoc perl

to start with and pay attention to

perldoc perlboot
perlobj
etc

the class hierachy model is different in perl.

From a specific class extension that I have

package Wetware::Hq::Web::RCI;  
.
use Wetware::RCI;

our @ISA = qw(Wetware::RCI);
.
this way when i do things like

	my $rci = new Wetware::Hq::Web::RCI;

it inherits all the song and dance of the base class...



ciao
drieux
---

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


Re: Why should I create an object?

2003-06-28 Thread drieux
On Thursday, Jun 26, 2003, at 23:45 US/Pacific, Octavian Rasnita wrote:
[..]
You should create an object because you might import more modules in 
your
application that export the param() function/method.
In that case the program won't know which of those param() functions 
to use.
I guess this is just one reason, but I am sure there are more.
[..]

This is probably the best reason

it's a simpler way to manage 'name space' issues.

This of course presumes that one does something like

my $cgi= new CGI;
my $wombat = new Wombat;

	my $cgi_param_foo = $cgi-param('input');

if ( $wombat-param($cgi_param_foo) )
{
# right wombat
$wombat-HappyHappyJoyJoy($cgi);
} else {
#
# another waste of money brains and talent
# that has to be fixed
#
$wombat-sullen_wombat_must_fix_earther($cgi);
}
#
# cgi stuff now fixed up
#

Basically, if you do not have total control over the
libraries you work with, it is important to work out
a strategy to avoid collisions...
Another strategy of course is to be explicit

	my $input = CGI::param('input');

This way one knows that the param is the param() that
one means there is some trade off here, in that
one only imports the methods that one means to import...
ciao
drieux
---

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


make CPAN::Shell-i; print to a filehandle

2003-06-28 Thread Harry Putnam
How do I go about making the output from 
CPAN::Shell-i; go into a file handle
Instead of STDOUT like it does in this formulation:

$target = somefile;
if($opt_r){
  open(FH,$target) or die Cannot open $target: $!;  
print FH CPAN::Shell-i;  
  } 
} 


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



scalar to list conversion

2003-06-28 Thread Ling F. Zhang
say I have a string scalar $s
I would like to convert it @s in such a way that qw
would do it...
i.e.
if $s = rabbit hole\t goes\tall the way\n
then
@s = (rabbit,hole,goes,all,the,way\n)

notice that I preserved the \n at the end, but I
would settle for a solution that doesn't preserve
it...thanx


__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



Re: scalar to list conversion

2003-06-28 Thread John W. Krahn
Ling F. Zhang wrote:
 
 say I have a string scalar $s
 I would like to convert it @s in such a way that qw
 would do it...
 i.e.
 if $s = rabbit hole\t goes\tall the way\n
 then
 @s = (rabbit,hole,goes,all,the,way\n)

@s = split ' ', $s;


 notice that I preserved the \n at the end, but I
 would settle for a solution that doesn't preserve
 it...thanx

If you want the same behaviour as qw() then the newline will be removed,
however you can append it later.

$s[ -1 ] .= \n;



John
-- 
use Perl;
program
fulfillment

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



pattern matching in stream...

2003-06-28 Thread Ling F. Zhang
I have the following problem:

I just read in a file FILE...
in ONE of line of the file, there is a word I need to
substitute...
but I realize that:
$a = FILE would assign $a the first line of the file
@a = FILE world assign each line of the file as an
element of @a...
now...s/search/replace/ only works for string...
is there a way to avoid looping through the file (or
elements of @a to do this search/replace?)
now the way I am doing is:

foreach $m (@a){
 $m =~ s/search/replace/;
}

is there way to avoid this loop? (such as reading the
whole file into a single scalar?)

__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



Re: pattern matching in stream...

2003-06-28 Thread lmail
At 09:01 28/06/2003, you wrote:

I have the following problem:

I just read in a file FILE...
in ONE of line of the file, there is a word I need to
substitute...
but I realize that:
$a = FILE would assign $a the first line of the file
@a = FILE world assign each line of the file as an
element of @a...
now...s/search/replace/ only works for string...
is there a way to avoid looping through the file (or
elements of @a to do this search/replace?)
now the way I am doing is:

foreach $m (@a){
 $m =~ s/search/replace/;
}


can you not add global
ie s/search/replace/g 


is there way to avoid this loop? (such as reading the
whole file into a single scalar?)

__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



---
pased check
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003

---
Outgoing mail was scaned pased Virus free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003

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

file io and html

2003-06-28 Thread fuzzy
i need to know how do file i/o.

i know c, c++, php, 5 different vb, so i'm not new to programming, just 
to perl.

i'm going to be send stuff to this script using a html form via ACTION=, 
so i need to know how to pull them in, smush them into a string in a 
format and write it (in append mode) to a file. i know how to do this in 
php, but php runs as 'nobody' and i dont want to leave this file with 
world write access

here's the final format i need
00-00-00,00:00,file.ext,title with spaces in quotes
the first part is a date
second is a time
3rd is a file name
fourth is a string in quotes, the quotes are important
in php i would use
$outout = sprintf(%s,%s,%s,\%s\, $date, $time, $file, $title);
someone please help

-fuzzy

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


Re: scalar to list conversion

2003-06-28 Thread Shlomi Fish
On Sat, 28 Jun 2003, Ling F. Zhang wrote:

 say I have a string scalar $s
 I would like to convert it @s in such a way that qw
 would do it...
 i.e.
 if $s = rabbit hole\t goes\tall the way\n
 then
 @s = (rabbit,hole,goes,all,the,way\n)


@s = (split /\t/, $s);

Hope it helps.

Regards,

Shlomi Fish

 notice that I preserved the \n at the end, but I
 would settle for a solution that doesn't preserve
 it...thanx


 __
 Do you Yahoo!?
 SBC Yahoo! DSL - Now only $29.95 per month!
 http://sbc.yahoo.com





--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

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



Re: file io and html

2003-06-28 Thread Shlomi Fish
On Sat, 28 Jun 2003, fuzzy wrote:

 i need to know how do file i/o.

 i know c, c++, php, 5 different vb, so i'm not new to programming, just
 to perl.

 i'm going to be send stuff to this script using a html form via ACTION=,
 so i need to know how to pull them in, smush them into a string in a
 format and write it (in append mode) to a file. i know how to do this in
 php, but php runs as 'nobody' and i dont want to leave this file with
 world write access

 here's the final format i need
 00-00-00,00:00,file.ext,title with spaces in quotes

 the first part is a date
 second is a time
 3rd is a file name
 fourth is a string in quotes, the quotes are important

 in php i would use
 $outout = sprintf(%s,%s,%s,\%s\, $date, $time, $file, $title);


This will work in Perl as well.

To write it to a file, use the following code:

open O, myfile.txt; ##  is for append
print O $outout;
close(O);

For more information refer here:

http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/lecture2/files/
http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/lecture4/system-funcs/
perldoc perlopentut

Regards,

Shlomi Fish

 someone please help

 -fuzzy






--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

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



Re: How can i make this faster?

2003-06-28 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote:

 the program works fine for a small directory, but as soon as the
 directory is bigger, it takes a long time to start. do you have any
 idea how to make this faster?

 ---

 #!/usr/bin/perl
 use diagnostics;
 use strict;
 use Tk;
 use Tk::HList;
 use Tk::Tree;
 use File::Basename;

 my $mw = tkinit;
 my $hl = $mw-ScrlTree(-separator= '/',
-drawbranch   = 1,
-scrollbars   = 'osoe',
-selectmode   = 'extended',
-selectforeground = 'red',
   )
 -pack(-fill = 'both',
-expand   = 1
   );

 open SD,'/tmp/LIST' or die Couldn't open all: $!\n;
 #my %hash = reverse map split, SD;

 my %hash = reverse map split, DATA; #SD;
 print Datei '$_' belegt '$hash{$_}'.\n for sort keys %hash;

 $hl-add('/');
 $hl-item('create', '/', 0, -text = '/');
 for my $file (sort keys %hash) {
 print file: '$file'\n;
 my @path = split '/', $file;
 shift @path; # leeren Eintrag vorn entfernen
 print path: '@path'\n;
 my $path = ;
 for my $pt (@path) {
 print inpatharray: $pt\n;
 $path .= /$pt;
 print path: $path\n;

 if (! $hl-info('exists', $path)) {
 my $realFile= fileparse($file);
 if (-d $path) {
 $hl-add($path);
 $hl-item('create',
   $path,
   0,
   -text  = $path,
   -image = $hl-Getimage('folder'),
  );
 $hl-autosetmode;
 }
 else {
 $hl-add($path);
 $hl-item('create',
   $path,
   0,
   -text  = $path,
   -image = $hl-Getimage('file'),
  );
 $hl-autosetmode;
 }
 }
 else {
 print weder noch\n;
 }
 }
 }
 ---

 to create the LIST file, simply do:

 du -h -a /usr /tmp/all 2/dev/null --or /var or any big directory
 sort +1 /tmp/all  /tmp/LIST

 zhis should generate a file called LIST in the /tmp directory. i hope
 someone has an idea because this is really important.


The issue is performance?  Have you tried commenting out all print
statements?

Koseph


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



Re: pattern matching in stream...

2003-06-28 Thread Rob Dixon
Ling F. Zhang wrote:
 I have the following problem:

 I just read in a file FILE...
 in ONE of line of the file, there is a word I need to
 substitute...
 but I realize that:
 $a = FILE would assign $a the first line of the file
 @a = FILE world assign each line of the file as an
 element of @a...
 now...s/search/replace/ only works for string...
 is there a way to avoid looping through the file (or
 elements of @a to do this search/replace?)
 now the way I am doing is:

 foreach $m (@a){
  $m =~ s/search/replace/;
 }

 is there way to avoid this loop? (such as reading the
 whole file into a single scalar?)

Hi Ling.

Yes, there is, but I don't understand why you want to avoid the
loop. The processing will be the same whether you expand it
in-line (by processing one Very Big Record instead of many
bite-size ones) or hide it syntactically (behind something like
'map'). It also depends on what you want to do with the data
once you've modified it. As you say,

  my @a = FILE

reads the entire file as records into an array, but this is
more than likely unnecessary and should be attempted only if
you can guarantee that your file is a reasonable size compared
with your available memory. (For production code you should
check the file's size before you read it.) There is a simple
way to read the file into a single scalar, but you probably
don't need it.

It looks like you probably want to edit an existing file and
write a modified version, in which case you need something like

  open OUT,  newfile or die $!;

  while (defined (my $m = FILE)) {
$m =~ s/search/replace/;
print OUT $m;
  }

  close OUT;

which processes the file one record at a time with negliglible
speed penalty. It can be written more idiomatically and succinctly
using the $_ variable instead of your own $m

  open OUT,  newfile or die $!;

  while (FILE) {
s/search/replace/;
print OUT;
  }

  close OUT;

I hope this helps. if this isn't what you want, come back and we'll
try again.

Oh, and

  use strict;   # always
  use warnings; # usually

:)

Rob




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



Re: scalar to list conversion

2003-06-28 Thread Rob Dixon
John W. Krahn wrote:
 Ling F. Zhang wrote:
 
  say I have a string scalar $s
  I would like to convert it @s in such a way that qw
  would do it...
  i.e.
  if $s = rabbit hole\t goes\tall the way\n
  then
  @s = (rabbit,hole,goes,all,the,way\n)

 @s = split ' ', $s;

  @s = split for $s

:)

Rob




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



File::Find

2003-06-28 Thread Ashish Srivastava
How can i restrict scanning by find function to a specified depth.
eg. only 4 level or 3 level.
Thanks in advance 
 
 
 
Ashish Srivastava
 

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



Re: scalar to list conversion

2003-06-28 Thread Steve Grazzini
On Sat, Jun 28, 2003 at 11:04:33AM +0100, Rob Dixon wrote:
 John W. Krahn wrote:
 
  @s = split ' ', $s;
 
   @s = split for $s

(*s,*_) = \($_,@s);

split;

-- 
Steve

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



need help

2003-06-28 Thread anthony
Hi,

I'm really struggling with my scripts for the moment.
What I have is a config file, for the moment a config.pl
which i'm trying to change to config.ini using Config::IniFiles module.
But here is the header of my programs

#!/usr/bin/perl
use CGI qw(:standard);
use DBI;
require /home/sites/prog/www/config.pl;
use lib '/home/sites/prog/www/Module';
use AccForm;
use ErrTemp;
use SB_Function;

Now the modules AccForm, ErrTemp and SB_Function uses config.pl but the
problem is that the variables in config.pl doesn't go into accForm, ErrTemp
and SB_function.
So what i have done is declare config,pl in each module, but then it seems
to cancel out, what i mean is that AccForm will use config.pl but not
ErrTemp and Sb_function,
if I do
use ErrTemp;
use SB_Function;
use AccForm;
then only ErrTemp, will use the varibles. as well as the general script.

So is there a way in which I can declare one time config.pl and it can go to
all the module???

Thank You
Anthony




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



Re: scalar to list conversion

2003-06-28 Thread Steve Grazzini
On Sat, Jun 28, 2003 at 06:38:34AM -0400, Steve Grazzini wrote:
 On Sat, Jun 28, 2003 at 11:04:33AM +0100, Rob Dixon wrote:
  John W. Krahn wrote:
  
   @s = split ' ', $s;
  
@s = split for $s

Erm, never mind my last post. :-)

  *_ = *s; split;

-- 
Steve

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



Re: Why Global symbol require explicit package name

2003-06-28 Thread Kevin Pfeiffer
In article [EMAIL PROTECTED], John W. Krahn wrote:
[...]
 Perhaps this article may help you understand.
 
 http://perl.plover.com/FAQs/Namespaces.html

I've read this before (but it pays to reread it) and this time I also read the Seven 
Useful Uses of local. One thing MJD demonstrates is a clever wayt that one can write 
one's one map and grep-like methods/functions. Only problem is that I can't get it 
to work.

I get the error: 
Use of uninitialized value in concatenation (.) or string at ./sub_print_hash line 20.
Can't call method printhash without a package or object reference at 
./sub_print_hash line 20.

Here is my code:

#!/usr/bin/perl
use warnings;
use strict;

# sub_print_hash

# from MJD's Seven Useful Uses of local - http://perl.plover.com/local.html
# very useful technique for building your own grep and map-like functions!


my %capitals = (
Athens =   Greece,
Moscow =   Russia,
Helsinki = Finland,
   );
foreach (keys %capitals) {
   print $_ = $capitals{$_}\n;
}

printhash { $a, } %capitals;

#printhash { $a = $b\n } %capitals;

sub printhash (\%) {

   my $code = shift;
   my $hash = shift;
   local ($a, $b);

   while (($a, $b) = each %$hash) {
  print $code();
   }
}


-- 
Kevin Pfeiffer

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



Re: Always on Top.. TK

2003-06-28 Thread zentara
On Sat, 28 Jun 2003 08:47:33 +1200, [EMAIL PROTECTED] (Voodoo Raja)
wrote:

Hi all..

Just a quick one..

Is it possible to force my TK application to on top of all the windows that 
are present on the screen.. or rather set the window to be always visible 


use $mw -overrideredirect(1);

###
#!/usr/bin/perl
use Tk;
$mw = tkinit;
$t = $mw-Toplevel;  
$t-withdraw;
$t-Label(-text = Testing...)-pack;
$t-Button(
   -text = Withdraw,
   -command = sub {$t-withdraw},
)-pack;
$t -overrideredirect(1); #to top on all virtual desktops
$mw-Button(
   -text = 'Test',
   -command = sub {
   $_-deiconify, $_-raise for $t;
   },
)-pack;
MainLoop; 
#




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



Re: Why Global symbol require explicit package name

2003-06-28 Thread Paul Johnson
On Sat, Jun 28, 2003 at 03:51:49PM +0200, Kevin Pfeiffer wrote:
 In article [EMAIL PROTECTED], John W. Krahn wrote:
 [...]
  Perhaps this article may help you understand.
  
  http://perl.plover.com/FAQs/Namespaces.html
 
 I've read this before (but it pays to reread it) and this time I also read the 
 Seven Useful Uses of local. One thing MJD demonstrates is a clever wayt that one 
 can write one's one map and grep-like methods/functions. Only problem is that I 
 can't get it to work.
 
 I get the error: 
 Use of uninitialized value in concatenation (.) or string at ./sub_print_hash line 
 20.
 Can't call method printhash without a package or object reference at 
 ./sub_print_hash line 20.
 
 Here is my code:
 
 #!/usr/bin/perl
 use warnings;
 use strict;
 
 # sub_print_hash
 
 # from MJD's Seven Useful Uses of local - http://perl.plover.com/local.html
 # very useful technique for building your own grep and map-like functions!
 
 
 my %capitals = (
 Athens =   Greece,
 Moscow =   Russia,
 Helsinki = Finland,
);
 foreach (keys %capitals) {
print $_ = $capitals{$_}\n;
 }
 
 printhash { $a, } %capitals;
 
 #printhash { $a = $b\n } %capitals;
 
 sub printhash (\%) {
 
my $code = shift;
my $hash = shift;
local ($a, $b);
 
while (($a, $b) = each %$hash) {
   print $code();
}
 }

The only problem is that you have used printhash before declaring it,
and in this case the declaration is important.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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



Re: File::Find

2003-06-28 Thread Rob Dixon
Ashish Srivastava wrote:
 How can i restrict scanning by find function to a specified depth.
 eg. only 4 level or 3 level.

Whenever your 'wanted' callback routine is called with
a directory name in $_, if you set

  $File::Find::prune = 1

then 'find' won't look at any files in that directory or below.
You'll have to calculate the current directory level yourself but,
if you're on a Unix-like filing system, then in general you can just
count the slash characters like this

  my $level = $File::Find::dir =~ tr#/##;
  $File::Find::prune = 1 if $level = 3;

which will process everything down to, say, /usr/bin/perl
but nothing beneath it.

HTH,

Rob







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



Number search

2003-06-28 Thread Phillips, Wesley
Hi all,
  I have been working on a problem and worked out a solution, but am
wondering if there is an easier(more elegant?) way of doing it. I am
automatically generating configuration files for a Quality Of Service(QOS)
device, and each pipe in the QOS has a policy number attached to it. The
policy numbers must be unique, so I have to find an unused number. The
system never has more than 200 or so policies. I am pulling the preexisting
policy numbers out of a database and placing them into an array(@addarr)
Here is my code:


#!/usr/bin/perl

use Mysql;

$db = Mysql-connect('localhost', 'dbase', 'user', 'password');
$query = $db-query(SELECT policy FROM Table);
while ( $policy = $query-fetchrow_array()) {
  $addarr[$policy] = $policy;
}
for ($i = 1; $i  1001; $i++) {
  if (defined($addarr[$i])) {
next;
  } else {
$newaddr = $i;
last;
  }
}

where $newaddr would be the new, as yet unused, number

Thanks 
Wes Phillips




here document question

2003-06-28 Thread burningclown

Hi -

I am grinding through =Programming Perl= and came to the section on Here 
Documents in Chapter 2 (forgive me, I can't think of the term Here documents 
without thinking that there must be a dog somewhere named Documents).

Anyhoo, I tried typing some of the examples at the keyboard. They stick in my 
memory better that way. I'm wondering why

print  x 10;
The camels are coming!

only seems to work if there is a blank line (e.g. a carriage return) after the 
string to be printed. If I don't put that blank line in, I get the error

Can't find string terminator anywhere before EOF at ./perlcamel.pl line 3

(perlcamel.pl is what I called this).

I'm sure this is a basic question, but the book does not seem anyway to mention 
a need for a blank terminating line.

Thanks,

Glenn Becker

-- 
+-+
There are no motionless targets
+-+


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



Re: here document question

2003-06-28 Thread Kevin Pfeiffer
Hi,

In article 
[EMAIL PROTECTED], 
[EMAIL PROTECTED] wrote:

 
 Hi -
 
 I am grinding through =Programming Perl= and came to the section on Here
 Documents in Chapter 2 (forgive me, I can't think of the term Here
 documents without thinking that there must be a dog somewhere named
 Documents).

Coming from [EMAIL PROTECTED] ;-)

 Anyhoo, I tried typing some of the examples at the keyboard. They stick in
 my memory better that way. I'm wondering why
 
 print  x 10;
 The camels are coming!
 
 only seems to work if there is a blank line (e.g. a carriage return) after
 the string to be printed. If I don't put that blank line in, I get the
 error
 
 Can't find string terminator anywhere before EOF at ./perlcamel.pl line 3
 
 (perlcamel.pl is what I called this).
 
 I'm sure this is a basic question, but the book does not seem anyway to
 mention a need for a blank terminating line.

From perldoc perlop:

   If the terminating identifier is on the last line
   of the program, you must be sure there is a new­
   line after it; otherwise, Perl will give the warn­
   ing Can't find string terminator END anywhere
   before EOF

I'm not familiar (haven't read Programming Perl, yet) with this form of the 
here-document (self-terminating?), but I think it's the same problem 
mentioned in the citation.

-K


-- 
Kevin Pfeiffer
International University Bremen

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



Re: Re : Compilation Errors

2003-06-28 Thread R. Joseph Newton
Derek Byrne wrote:

 Last question on this, but, is there anything I should be aware of if I code
 the Fred prog like this :

Yes

 #!perl -w

use strict; #  always
use warnings;   #  unless you fully understand why you are turning them off.

The strict and warnings commands will save you a lot of trouble.  They may also
make things harder at first, as you will have to code correctly or raise errors.

 my $add = 4;

use my to indicate that each variable you declare belongs to the current scope,
rather than being inherited from some outer scope.  Always scope your variables
as narrowly as possible.  Also, the coding conventions in Perl call for
lowercase variable names for lexically scoped variables.

 $mul = 2;# ditto
 ...

Joseph


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



find uniq paths in @INC

2003-06-28 Thread Harry Putnam
I've stumbled around with this before and someone posted something
that came close but still doesn't quite do what I want.

Maybe it isn't important enough to get this involved with it.

Here is the problem:

Summary run home made tools against only the uniq paths that might contain
perl *.pm files.

In my case: 
$ perl -e 'print $newINC = join(\n,@INC),\n;'
/usr/local/lib/perl5/5.8.0/i686-linux
/usr/local/lib/perl5/5.8.0
/usr/local/lib/perl5/site_perl/5.8.0/i686-linux
/usr/local/lib/perl5/site_perl/5.8.0
/usr/local/lib/perl5/site_perl
/usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl
/usr/lib/perl5/Text
/usr/lib/perl5/vendor_perl/5.6.1
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.6.1/i386-linux
/usr/lib/perl5/site_perl/5.6.1/i386-linux
/usr/lib/perl5/vendor_perl/5.6.1/i386-linux

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



Re: here document question

2003-06-28 Thread Harry Putnam
[EMAIL PROTECTED] writes:

 print  x 10;
 The camels are coming!

Here documents always need a termination.  Maybe you'd see it better
if you use a more visible one:

$ perl -e 'print EOM x 10;
The camels are coming!
 EOM'

Note (sort of starndard) terminator used here is EOM.
Thats how here docs work.  They puke out everything between Start
mark (EOM) and end mark (EOM)


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




Re: file io and html

2003-06-28 Thread John W. Krahn
Fuzzy wrote:
 
 i need to know how do file i/o.

perldoc perlopentut
perldoc perlsyn


 i know c, c++, php, 5 different vb, so i'm not new to programming, just
 to perl.
 
 i'm going to be send stuff to this script using a html form via ACTION=,
 so i need to know how to pull them in, smush them into a string in a
 format and write it (in append mode) to a file.

perldoc CGI


 i know how to do this in
 php, but php runs as 'nobody' and i dont want to leave this file with
 world write access

Any process that your web server runs, whether written in C, C++, VB or
Perl, is run as 'nobody'.


 here's the final format i need
 00-00-00,00:00,file.ext,title with spaces in quotes
 
 the first part is a date
 second is a time
 3rd is a file name
 fourth is a string in quotes, the quotes are important
 
 in php i would use
 $outout = sprintf(%s,%s,%s,\%s\, $date, $time, $file, $title);

It is exactly the same in perl.  Or you could write it like this:

$outout = sprintf '%s,%s,%s,%s', $date, $time, $file, $title;

Or like this:

$outout = join ',', $date, $time, $file, qq($title);


TMTOWTDI   :-)

John
-- 
use Perl;
program
fulfillment

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



Re: Number search

2003-06-28 Thread Rob Dixon
Wesley Phillips wrote:
 Hi all,
   I have been working on a problem and worked out a solution, but am
 wondering if there is an easier(more elegant?) way of doing it. I am
 automatically generating configuration files for a Quality Of Service(QOS)
 device, and each pipe in the QOS has a policy number attached to it. The
 policy numbers must be unique, so I have to find an unused number. The
 system never has more than 200 or so policies. I am pulling the preexisting
 policy numbers out of a database and placing them into an array(@addarr)
 Here is my code:


 #!/usr/bin/perl

 use Mysql;

 $db = Mysql-connect('localhost', 'dbase', 'user', 'password');
 $query = $db-query(SELECT policy FROM Table);
 while ( $policy = $query-fetchrow_array()) {
   $addarr[$policy] = $policy;
 }
 for ($i = 1; $i  1001; $i++) {
   if (defined($addarr[$i])) {
 next;
   } else {
 $newaddr = $i;
 last;
   }
 }

 where $newaddr would be the new, as yet unused, number

Hi Wes.

First of all,

  use strict;   # always
  use warnings  # usually

Secondly the Mysql module is now deprecated in favour of DBI together with
its DBD::mysql driver.

However I can well believe that either or both of these points are dictated
by your employer, so here's the answer...

It looks like you want the smallest number in 1 .. 1000 which doesn't already
exist in the 'policy' column of 'Table'. What I'd do is to start by setting
up a hash with all of the valid values as keys. Then simply drag in all of
the current values of this column into an array and use it to delete the
corresponding elements of the hash. The number you want is then the first
of the sorted list of remaining hash keys. It looks like this:

  use strict;
  use warnings;

  use Mysql;

  my $db = Mysql-connect('localhost', 'dbase', 'user', 'password');

  # Set up the hash with 1000 elements
  #
  my %policy;
  @policy{1 .. 1000} = ();

  # Delete all those currently in use
  #
  my @current = $db-query(SELECT policy FROM Table)-fetchcol;
  delete @[EMAIL PROTECTED];

  # The next one to use is the first of those left
  #
  my $next = (sort keys %policy)[0];


HTH,

Rob




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



Re: file io and html

2003-06-28 Thread John W. Krahn
John W. Krahn wrote:
 
 Fuzzy wrote:
 
  in php i would use
  $outout = sprintf(%s,%s,%s,\%s\, $date, $time, $file, $title);
 
 It is exactly the same in perl.  Or you could write it like this:
 
 $outout = sprintf '%s,%s,%s,%s', $date, $time, $file, $title;
 
 Or like this:
 
 $outout = join ',', $date, $time, $file, qq($title);
 
 TMTOWTDI   :-)

Or even just:

$outout = qq($date,$time,$file,$title);


John
-- 
use Perl;
program
fulfillment

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



Re: here document question

2003-06-28 Thread burningclown

 Here documents always need a termination.  Maybe you'd see it better
 if you use a more visible one:

thanks to those who responded to my question :)

here, document!

glenn

+-+
There are no motionless targets
+-+


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



Re: here document question

2003-06-28 Thread Rob Dixon
[EMAIL PROTECTED] wrote:
 Hi -

 I am grinding through =Programming Perl= and came to the section on Here
 Documents in Chapter 2 (forgive me, I can't think of the term Here documents
 without thinking that there must be a dog somewhere named Documents).

 Anyhoo, I tried typing some of the examples at the keyboard. They stick in my
 memory better that way. I'm wondering why

 print  x 10;
 The camels are coming!

 only seems to work if there is a blank line (e.g. a carriage return) after the
 string to be printed. If I don't put that blank line in, I get the error

 Can't find string terminator anywhere before EOF at ./perlcamel.pl line 3


Hi Kevin.

The text of a 'here' document is everything up to a line containing the string
following '' on a line on its own (with a terminating newline). You can delimit
that string with quotes (in which case it can be any text you want) but if you
don't it will be delimited by the first whitespace after ''. I tour example
your '' is immediately followd by a space, so the terminating text is a null
string (a blank line). I you enable warnings you will get the message

  Use of bare  to mean  is deprecated

which is basically telling you that if you really mean a null string you should
make it visible.

With quotes, any amount of whitespace is allowed before or after the string,
like this:

  print   TRAIN x 10;
  The camels are coming!
  TRAIN

but a non-null string straight after the '' is more usual:

  print TRAIN x 10;
  The camels are coming!
  TRAIN

(Note that this code is indented by two spaces. The actual terminating
string must be flush left.)

HTH,

Rob




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



Re: here document question

2003-06-28 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
 
 Hi -

Hello,

 I am grinding through =Programming Perl= and came to the section on Here
 Documents in Chapter 2 (forgive me, I can't think of the term Here documents
 without thinking that there must be a dog somewhere named Documents).
 
 Anyhoo, I tried typing some of the examples at the keyboard. They stick in my
 memory better that way. I'm wondering why
 
 print  x 10;
 The camels are coming!
 
 only seems to work if there is a blank line (e.g. a carriage return) after the
 string to be printed. If I don't put that blank line in, I get the error
 
 Can't find string terminator anywhere before EOF at ./perlcamel.pl line 3
 
 (perlcamel.pl is what I called this).
 
 I'm sure this is a basic question, but the book does not seem anyway to mention
 a need for a blank terminating line.

That is because your example uses  for the terminator.

print  x 10;
The camels are coming!

Is exactly the same as:

print  x 10;
The camels are coming!

So a blank line is required to terminate the string.


John
-- 
use Perl;
program
fulfillment

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



Re: find uniq paths in @INC

2003-06-28 Thread Rob Dixon
Harry Putnam wrote:
 I've stumbled around with this before and someone posted something
 that came close but still doesn't quite do what I want.

 Maybe it isn't important enough to get this involved with it.

 Here is the problem:

 Summary run home made tools against only the uniq paths that might contain
 perl *.pm files.

 In my case:
 $ perl -e 'print $newINC = join(\n,@INC),\n;'
 /usr/local/lib/perl5/5.8.0/i686-linux
 /usr/local/lib/perl5/5.8.0
 /usr/local/lib/perl5/site_perl/5.8.0/i686-linux
 /usr/local/lib/perl5/site_perl/5.8.0
 /usr/local/lib/perl5/site_perl
 /usr/lib/perl5/5.6.1
 /usr/lib/perl5/site_perl/5.6.1
 /usr/lib/perl5/site_perl
 /usr/lib/perl5/Text
 /usr/lib/perl5/vendor_perl/5.6.1
 /usr/lib/perl5/vendor_perl
 /usr/lib/perl5/5.6.1/i386-linux
 /usr/lib/perl5/site_perl/5.6.1/i386-linux
 /usr/lib/perl5/vendor_perl/5.6.1/i386-linux

Hmm. Did I blink or didn't you get to the question yet?

Rob




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



RE: find uniq paths in @INC

2003-06-28 Thread SPENCERS


-Original Message-
From: SPENCERS [mailto:[EMAIL PROTECTED]
Sent: Saturday, June 28, 2003 12:37 PM
To: Harry Putnam
Subject: RE: find uniq paths in @INC


Hello, Harry.

   Is this what you are looking for?

#!/usr/bin/perl -w


# list all of the perl modules installed

use strict;
use File::Find ;

for (@INC) { find(\modules,$_) ; }

sub modules 
{
if (-d  /^[a-z]/) { $File::Find::prune = 1 ; return }
return unless /\.pm$/ ;
my $fullPath = $File::Find::dir/$_;
$fullPath =~ s!\.pm$!!;
$fullPath =~ s#/(\w+)$#::$1# ;
print $fullPath \n;
}

-Original Message-
From: news [mailto:[EMAIL PROTECTED] Behalf Of Harry Putnam
Sent: Saturday, June 28, 2003 11:12 AM
To: [EMAIL PROTECTED]
Subject: find uniq paths in @INC


I've stumbled around with this before and someone posted something
that came close but still doesn't quite do what I want.

Maybe it isn't important enough to get this involved with it.

Here is the problem:

Summary run home made tools against only the uniq paths that might contain
perl *.pm files.

In my case: 
$ perl -e 'print $newINC = join(\n,@INC),\n;'
/usr/local/lib/perl5/5.8.0/i686-linux
/usr/local/lib/perl5/5.8.0
/usr/local/lib/perl5/site_perl/5.8.0/i686-linux
/usr/local/lib/perl5/site_perl/5.8.0
/usr/local/lib/perl5/site_perl
/usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl
/usr/lib/perl5/Text
/usr/lib/perl5/vendor_perl/5.6.1
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.6.1/i386-linux
/usr/lib/perl5/site_perl/5.6.1/i386-linux
/usr/lib/perl5/vendor_perl/5.6.1/i386-linux

-- 
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: Number search

2003-06-28 Thread John W. Krahn
Rob Dixon wrote:
 
 Wesley Phillips wrote:
  Hi all,
I have been working on a problem and worked out a solution, but am
  wondering if there is an easier(more elegant?) way of doing it. I am
  automatically generating configuration files for a Quality Of Service(QOS)
  device, and each pipe in the QOS has a policy number attached to it. The
  policy numbers must be unique, so I have to find an unused number. The
  system never has more than 200 or so policies. I am pulling the preexisting
  policy numbers out of a database and placing them into an array(@addarr)
  Here is my code:
 
 
  #!/usr/bin/perl
 
  use Mysql;
 
  $db = Mysql-connect('localhost', 'dbase', 'user', 'password');
  $query = $db-query(SELECT policy FROM Table);
  while ( $policy = $query-fetchrow_array()) {
$addarr[$policy] = $policy;
  }
  for ($i = 1; $i  1001; $i++) {
if (defined($addarr[$i])) {
  next;
} else {
  $newaddr = $i;
  last;
}
  }
 
  where $newaddr would be the new, as yet unused, number
 
 Hi Wes.
 
 First of all,
 
   use strict;   # always
   use warnings  # usually
 
 Secondly the Mysql module is now deprecated in favour of DBI together with
 its DBD::mysql driver.
 
 However I can well believe that either or both of these points are dictated
 by your employer, so here's the answer...
 
 It looks like you want the smallest number in 1 .. 1000 which doesn't already
 exist in the 'policy' column of 'Table'. What I'd do is to start by setting
 up a hash with all of the valid values as keys. Then simply drag in all of
 the current values of this column into an array and use it to delete the
 corresponding elements of the hash. The number you want is then the first
 of the sorted list of remaining hash keys. It looks like this:
 
   use strict;
   use warnings;
 
   use Mysql;
 
   my $db = Mysql-connect('localhost', 'dbase', 'user', 'password');
 
   # Set up the hash with 1000 elements
   #
   my %policy;
   @policy{1 .. 1000} = ();
 
   # Delete all those currently in use
   #
   my @current = $db-query(SELECT policy FROM Table)-fetchcol;
   delete @[EMAIL PROTECTED];
 
   # The next one to use is the first of those left
   #
   my $next = (sort keys %policy)[0];

You are sorting numbers so you should use a numerical sort otherwise
'20' will be sorted after '100' etc.

   my $next = (sort { $a = $b } keys %policy)[0];

Or you could use an array:

my @policy = 0 .. 1000;
delete @policy[ @current ];
my $next;
$next = $_ and last for @policy;


John
-- 
use Perl;
program
fulfillment

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



Re: make CPAN::Shell-i; print to a filehandle

2003-06-28 Thread Mark G

- Original Message - 
From: Harry Putnam [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, June 28, 2003 2:20 AM
Subject: make CPAN::Shell-i; print to a filehandle


 How do I go about making the output from 
 CPAN::Shell-i; go into a file handle
 Instead of STDOUT like it does in this formulation:
 
 $target = somefile;
 if($opt_r){
   open(FH,$target) or die Cannot open $target: $!;  
 print FH CPAN::Shell-i;  
you can try IPC::Open2.

Mark g

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


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



RE: find uniq paths in @INC

2003-06-28 Thread Charles K. Clarkson
Harry Putnam said:
:
: Here is the problem:
: 
: Summary run home made tools against only the
: uniq paths that might contain perl *.pm files.

Harry, that doesn't' make a bit of sense.
Could you rephrase the question?


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



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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
Harry Putnam [EMAIL PROTECTED] writes:

 I've stumbled around with this before and someone posted something
 that came close but still doesn't quite do what I want.

 Maybe it isn't important enough to get this involved with it.

 Here is the problem:

 Summary run home made tools against only the uniq paths that might contain
 perl *.pm files.

 In my case: 
 $ perl -e 'print $newINC = join(\n,@INC),\n;'
 /usr/local/lib/perl5/5.8.0/i686-linux
 /usr/local/lib/perl5/5.8.0
 /usr/local/lib/perl5/site_perl/5.8.0/i686-linux
 /usr/local/lib/perl5/site_perl/5.8.0
 /usr/local/lib/perl5/site_perl
 /usr/lib/perl5/5.6.1
 /usr/lib/perl5/site_perl/5.6.1
 /usr/lib/perl5/site_perl
 /usr/lib/perl5/Text
 /usr/lib/perl5/vendor_perl/5.6.1
 /usr/lib/perl5/vendor_perl
 /usr/lib/perl5/5.6.1/i386-linux
 /usr/lib/perl5/site_perl/5.6.1/i386-linux
 /usr/lib/perl5/vendor_perl/5.6.1/i386-linux

Very strange but some how that message got curtailed.  I'm not sure
what happened to it.

The rest of it said something like:
I want to pull out only the uniq paths from @INC programmatically.
Maybe its not a big deal but running my tools against all the paths
above seems like it really wastes energy.  Maybe perl doesn't care..
I'm on a P4 with 512mb ram.

One way would be to just run all *.pm hits into a hash and only the
uniq ones would survive.  Very labor intensive I'd think.

Its easy to spot the base paths by eye:
   /usr/local/lib/perl5
   /usr/lib/perl5/

On some machines there might be more.  But how to kick them out
programmatically?


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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
SPENCERS [EMAIL PROTECTED] writes:

 Hello, Harry.

Is this what you are looking for?

Well it gives the right results.  I think I'm making a mountain where
there was only a molehill.   Thanks


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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
Charles K. Clarkson [EMAIL PROTECTED] writes:

 Harry Putnam said:
 :
 : Here is the problem:
 : 
 : Summary run home made tools against only the
 : uniq paths that might contain perl *.pm files.

 Harry, that doesn't' make a bit of sense.
 Could you rephrase the question?

You can say that again... Must be heavy senior moments today.
Not counting the misfired unfinished post that started the thread.
Its still just plain wrong through and through.
SPENCERS straightened me out.

Having shot myself in the foot from the gate,  I guess I might as
well reveal the true depths of my ignorance and ask a remaining
question.

There were also typos in my initial post.  I meant `*.pod' instead of
`*.pm' but that doesn't really change the required coding.

I've butched the hell out of SPENCER's code in an attempte to get
sorted output (sort on non-absolute *.pod) and am getting duplicates
in the output.  Probably some really unorthodox technique (or lack
there of).  I often find that I code like an illiterate hillbilly.
Probably because that is what I am anyway:

I stuck the little uniquifier gimmick in there to prevent dups but
can't really see why I would be getting dups.  Maybe @INC does need
further processing

What is causing duplicates in the output.  Not everthing but only a
few. (The debug file, ./debug will have a number of dups in it)

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

use strict;
my (%name, @sorted, @unsorted, $absolute );
use File::Find ;

open(DBG,./debug) or die cannot open DBG: $!;
 
find(\wanted,@INC);
 
sub wanted {
   if (/\.pod$/){
  print DBG $File::Find::name\n;
 
  if ($name{$File::Find::name}++ == 0){
push @unsorted, $_ $File::Find::name;
  }
   }
}
@sorted = sort @unsorted;
for(@sorted){
  $absolute = (split(/ /,$_))[1];
  print $absolute\n;
}
close(DBG);


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



Re: make CPAN::Shell-i; print to a filehandle

2003-06-28 Thread Harry Putnam
Mark G [EMAIL PROTECTED] writes:


 $target = somefile;
 if($opt_r){
   open(FH,$target) or die Cannot open $target: $!;  
 print FH CPAN::Shell-i;  
 you can try IPC::Open2.

That looks like the stuff.  Apparently the pod author felt it was
criminal to supply even a very basic example.   Thereby creating a
situation where anyone not already a programmer must stumble around
endlessly trying to figure out the syntax to get some use of it.

I really do appreciate those few outlaws who put usefull examples in
the documentation.

Its not clear to me what to do after this:
$pid = open2($wtr, $rdr, 'CPAN::Shell-i');

while(WHAT GOES HERE){
  print AND_HERE $_\n;
}
FH is not normally represented as a scalar variable.
What role does $pid play?


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



Re: find uniq paths in @INC

2003-06-28 Thread John W. Krahn
Harry Putnam wrote:
 
 Charles K. Clarkson [EMAIL PROTECTED] writes:
 
  Harry Putnam said:
  :
  : Here is the problem:
  :
  : Summary run home made tools against only the
  : uniq paths that might contain perl *.pm files.
 
  Harry, that doesn't' make a bit of sense.
  Could you rephrase the question?
 
 You can say that again... Must be heavy senior moments today.
 Not counting the misfired unfinished post that started the thread.
 Its still just plain wrong through and through.
 SPENCERS straightened me out.
 
 Having shot myself in the foot from the gate,  I guess I might as
 well reveal the true depths of my ignorance and ask a remaining
 question.
 
 There were also typos in my initial post.  I meant `*.pod' instead of
 `*.pm' but that doesn't really change the required coding.
 
 I've butched the hell out of SPENCER's code in an attempte to get
 sorted output (sort on non-absolute *.pod) and am getting duplicates
 in the output.  Probably some really unorthodox technique (or lack
 there of).  I often find that I code like an illiterate hillbilly.
 Probably because that is what I am anyway:
 
 I stuck the little uniquifier gimmick in there to prevent dups but
 can't really see why I would be getting dups.  Maybe @INC does need
 further processing
 
 What is causing duplicates in the output.  Not everthing but only a
 few. (The debug file, ./debug will have a number of dups in it)
 
 ^
 #!/usr/local/bin/perl -w
 
 use strict;
 my (%name, @sorted, @unsorted, $absolute );
 use File::Find ;
 
 open(DBG,./debug) or die cannot open DBG: $!;
 
 find(\wanted,@INC);
 
 sub wanted {
if (/\.pod$/){
   print DBG $File::Find::name\n;
 
   if ($name{$File::Find::name}++ == 0){

The initial value in $name{$File::Find::name} will be undef not zero so
comparing it to zero will not work.

if ( $name{ $File::Find::name }++ ) {


 push @unsorted, $_ $File::Find::name;

You are using a space character as field separator however file and
directory names can have spaces in them.


   }
}
 }
 @sorted = sort @unsorted;

You probably should use the keys of %name which are unique.

my @sorted = sort keys %name;


 for(@sorted){
   $absolute = (split(/ /,$_))[1];
   print $absolute\n;
 }
 close(DBG);


John
-- 
use Perl;
program
fulfillment

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



Re: find uniq paths in @INC

2003-06-28 Thread John W. Krahn
John W. Krahn wrote:
 
 The initial value in $name{$File::Find::name} will be undef not zero so
 comparing it to zero will not work.
 
 if ( $name{ $File::Find::name }++ ) {

Sorry, my mistake, it does work.


John
-- 
use Perl;
program
fulfillment

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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
John W. Krahn [EMAIL PROTECTED] writes:

 John W. Krahn wrote:
 
 The initial value in $name{$File::Find::name} will be undef not zero so
 comparing it to zero will not work.
 
 if ( $name{ $File::Find::name }++ ) {

 Sorry, my mistake, it does work.

Whew, for a minute there I thougt I'd screwed that up too.  But why
are there dups to begin with?

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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
John W. Krahn [EMAIL PROTECTED] writes:

 Harry Putnam wrote:
 
 Charles K. Clarkson [EMAIL PROTECTED] writes:
 
  Harry Putnam said:
  :
  : Here is the problem:
  :
  : Summary run home made tools against only the
  : uniq paths that might contain perl *.pm files.
 
  Harry, that doesn't' make a bit of sense.
  Could you rephrase the question?
 
 You can say that again... Must be heavy senior moments today.
 Not counting the misfired unfinished post that started the thread.
 Its still just plain wrong through and through.
 SPENCERS straightened me out.
 
 Having shot myself in the foot from the gate,  I guess I might as
 well reveal the true depths of my ignorance and ask a remaining
 question.
 
 There were also typos in my initial post.  I meant `*.pod' instead of
 `*.pm' but that doesn't really change the required coding.
 
 I've butched the hell out of SPENCER's code in an attempte to get
 sorted output (sort on non-absolute *.pod) and am getting duplicates
 in the output.  Probably some really unorthodox technique (or lack
 there of).  I often find that I code like an illiterate hillbilly.
 Probably because that is what I am anyway:
 
 I stuck the little uniquifier gimmick in there to prevent dups but
 can't really see why I would be getting dups.  Maybe @INC does need
 further processing
 
 What is causing duplicates in the output.  Not everthing but only a
 few. (The debug file, ./debug will have a number of dups in it)
 
 ^
 #!/usr/local/bin/perl -w
 
 use strict;
 my (%name, @sorted, @unsorted, $absolute );
 use File::Find ;
 
 open(DBG,./debug) or die cannot open DBG: $!;
 
 find(\wanted,@INC);
 
 sub wanted {
if (/\.pod$/){
   print DBG $File::Find::name\n;
 
   if ($name{$File::Find::name}++ == 0){

 The initial value in $name{$File::Find::name} will be undef not zero so
 comparing it to zero will not work.

 if ( $name{ $File::Find::name }++ ) {


 push @unsorted, $_ $File::Find::name;

 You are using a space character as field separator however file and
 directory names can have spaces in them.

Not here but I take your point.


   }
}
 }
 @sorted = sort @unsorted;

 You probably should use the keys of %name which are unique.

How cool, I hadn't realized this expression:
   if ($name{$File::Find::name}++ == 0){
Actually put a value in that slot of %name.

But it doesn't really give the results I was after either.  I wanted
the sort on short *.pod name.  Other wise I have things like:
   /usr/lib/perl5/5.6.1/Win32.pod
coming first.

So my formulation may be better in that regard.


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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
Harry Putnam [EMAIL PROTECTED] writes:

 Whew, for a minute there I thougt I'd screwed that up too.  But why
 are there dups to begin with?

Gets us right back to SPENCERS who had it right from the start.
I wish I knew better what this code is doing:

  if (-d  /^[a-z]/) { $File::Find::prune = 1 ; return }
 return unless /\.pod$/ ;

Not quite able to piece it together from File::Find and not sure what
role /^[a-z]/ is playing there.  None of the components of @INC can
start with ^[a-z] anyway.  But somehow this code takes the duplicate
paths in @INC out of play.  Taking away the dups produced by searches
on directories like:

/usr/local/lib/perl5/5.8.0/i686-linux
/usr/local/lib/perl5/5.8.0



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



Re: find uniq paths in @INC

2003-06-28 Thread John W. Krahn
Harry Putnam wrote:
 
 John W. Krahn [EMAIL PROTECTED] writes:
 
  Harry Putnam wrote:
 
  @sorted = sort @unsorted;
 
  You probably should use the keys of %name which are unique.
 
 How cool, I hadn't realized this expression:
if ($name{$File::Find::name}++ == 0){
 Actually put a value in that slot of %name.

Yes it has to or the expression $name{$File::Find::name}++ would always
be zero.  Lookup the word autovivification in the docs.


 But it doesn't really give the results I was after either.  I wanted
 the sort on short *.pod name.  Other wise I have things like:
/usr/lib/perl5/5.6.1/Win32.pod
 coming first.
 
 So my formulation may be better in that regard.

Populate the hash like this:

$name{ $File::Find::name } = $_;

And then get the sorted list like this:

@sorted = sort { $name{ $a } cmp $name{ $b } } keys %name;



John
-- 
use Perl;
program
fulfillment

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



Re: find uniq paths in @INC

2003-06-28 Thread Harry Putnam
John W. Krahn [EMAIL PROTECTED] writes:

 But it doesn't really give the results I was after either.  I wanted
 the sort on short *.pod name.  Other wise I have things like:
/usr/lib/perl5/5.6.1/Win32.pod
 coming first.
 
 So my formulation may be better in that regard.

 Populate the hash like this:

 $name{ $File::Find::name } = $_;

 And then get the sorted list like this:

 @sorted = sort { $name{ $a } cmp $name{ $b } } keys %name;

I've seen that in books and stuff but was never able to fathom out
how it does what it does.  So never actually used it in code.
I still don't see how it does what it does but at least an up close
and personal example of what it does Thanks


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



Re: How to write to a file at certain position?

2003-06-28 Thread R. Joseph Newton
LI NGOK LAM wrote:

 
  You will probably want to open the file with a mode of +.
 

 Yes and thank you! That does what I want now. Thank you very much !!

 But I found new problem now. I did what I want if I try on a bitmap file,
 but for text file, my new contents will overwrite the whole file, what's
 that about

That's right.  And if you add two and two you will get four mo matter how
badly you want five.

Text is sequential.
Character data, including that of which text is composed, may be treated as
simple binary arrays, in which elements can be addressed at any point, but
only by byte-for-byte replacement of existing data.

Read [filename],
Write [filename]
and Append [filename]
modes are sequential, text-oriented modes.  None of them allow for in-place
replacement of data.

Binary [_] mode does allow for replacemnt in place.  This replacement must
be on a byte for byte basis, though.

You can't have your cake and eat it too.  If you are replacing data
byte-for-byte, you can edit any kind of data in-place.  If you need the
flexibility to replace data with data of another length, add new data
anywhere but at the end, or delete data anywhere but at the end, you MUST use
sequential, mode, which will clobber the file being written to.

Perl does have in-place editing modes, which may abstract the
copying/renaming process somewhat. Nevertheless, the same work is done under
the surface.

Joseph


 or where I should refer to now?

 
  --
  Paul Johnson - [EMAIL PROTECTED]
  http://www.pjcj.net
 
 

 --
 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: File size problem

2003-06-28 Thread R. Joseph Newton
Vasudev.K. wrote:

 Hi,
 I have this rather critical problem, I am trying to download quite huge
 files from a remote server through ftp. (The file being in a zipped
 format). I have an array which stores the names of the files to be
 downloaded. I am opening each of them up at my end and extracting data
 out of it and storing it in my oracle database.

 Q1. After unzipping, the file is huge (even the zipped one is :(( )..
 almost 5GB. The system throws an errorFile too large and exits.
 How do I get around this ache? One way I want to do it is unzipped file
 into many parts and process each part separately but cant get to write a
 code for it. Is there any better solution?

This sounds like a [rpblem with your sip application, or perhaps the
limitatins of the format.

 Q2. Is there a way I can parallely do all these things? i.e
 downloading.unzippingdata extraction... database operations.

 Here is the script.. if somebody can help me optimize it.

I'm not sure about optimixations at this point, because there are some
formatting issues that make it unnecessarily difficult to follow the code.
Herewith some tips on indentation:

 
 


use strict;
use warnings;


 @filenames=(A.gz,B.gz,, ...,.);
 #lose this, nd all other meaningless blank lines

#use vlank lines only when they signal some meaningful transition in the
flow of executtion.

 open(ZP,database_zipped_archive.dat);


 while (@filenames)

 {

All code within this block should be indented by however many spaces you are
using as your standard.  Use spaces, not tabs.

 [EMAIL PROTECTED];
 $ftp-get($ftpfile);

 $unzippedftpfile=unzipped.txt;

 open IN,gzip -d  $ftpfile $unzippedftpfile |;

 close(IN);

 $subst=substr($_,0,2);

 open(ZNP,tempfile.txt) or die tempfilenot ready.f: $!\n;;
 while (ZNP)  # This line should not be indented

The control statement of the while loop is in the main flow of execution, as
is the opening brace.

Anyway, I am sorry that I cannot take the time to read this code for
content.  Please clean up the indentation so that it is not random, but
rather reflects the logic of program execution.  Then re-post the code.
Here are the basics:

Choose a number of space characters as a standard indent increm,ent.  Taste
vary, but choose a standard and stick with it.
Any time you have an opening brace for a set of lines, this should be a
signal to indent the following line by one increment.
Unindent by one increment on the line that has the closing brace.  The
closing brace should always have a line to itself.

Here is a sample usng a 4-space indent. [and one space for line
continuance].  Some people prefer up to eight spaces.  I personally use
two.  Just be consistent with whatever you choose.


sub add_interior_children {
my $self = shift;
my ($roots, $class_system, $resolved,
 $unresolved, $to_close) = @_;

while (my $key = shift @{$unresolved}) {
my $parent = $class_system-get_parent($key);
next unless $parent;
if ($resolved-{$parent}) {
$self-add_interior_child($key, $parent,
 $class_system, $resolved, $to_close);
} else {
push @{$unresolved}, $key;
}
}
}

When you can look at the code from arms length and tell, without reading it,
how the general flow of execution goes, repost it, and you should get plenty
of help with the logic.

Joseph



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



Re: find uniq paths in @INC

2003-06-28 Thread John W. Krahn
Harry Putnam wrote:
 
 John W. Krahn [EMAIL PROTECTED] writes:
 
  And then get the sorted list like this:
 
  @sorted = sort { $name{ $a } cmp $name{ $b } } keys %name;
 
 I've seen that in books and stuff but was never able to fathom out
 how it does what it does.  So never actually used it in code.
 I still don't see how it does what it does but at least an up close
 and personal example of what it does Thanks

keys %name passes a list of the keys from the %name hash to sort. 
Inside the sort code block the $a and $b variables contain the current
keys to be sorted and we use those keys to reference the current values
of %name and sort those.  Then the list of keys sorted by values is
stored in the @sorted array.


John
-- 
use Perl;
program
fulfillment

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