RE: Output has HEX values??

2002-06-14 Thread David Gray

 I'm using the following command to output the results to screen and a 
 output file:
 
 open(F,tee $2 @ARGV[0].txt CON:);
 
 This works great but the output file created filename.txt 
 has a box 
 ascii character. Looks like a carraige return also.
 How can I remove this?

This sounds like an interesting problem... Could you post some more code
please? Where do you get $2 from?

Cheers,

 -dave



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




RE: Controlling Novell products with Perl

2002-06-14 Thread David Gray

 Does anyone have experience of using Perl to control any 
 Novell products such as Netware, eDirectory (NDS) etc.
 
 I don't have a specific requirement at present but we do a 
 lot of Novell stuff and I am interested to know what can 
 be/has been done.
 
 Apologies if this question is a bit general but I am hoping 
 someone will come up with something cool :-)

http://www.google.com/search?hl=enq=perl%20control%20novell

Turned up:

ctrl-f for perl:
http://developer.novell.com/research/howto.htm

http://www.theorem.com/mjl/webserv.htm
http://www.theorem.com/mjl/perl.htm

http://developer.novell.com/research/appnotes/2001/august/05/a010805.ht
m
http://developer.novell.com/research/appnotes/2001/june/04/a010604.htm

Good Luck,

 -dave



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




RE: remove the stop words

2002-06-04 Thread David Gray

 Is there a good method to do this? I need to remove the stop 
 words from the comment field of every record. There are about 
 20,000 records. The comments look like this: 
 
 Yersinia pestis strain Nepal (aka CDC 516 or 369 isolated 
 from human) 16S-23S in tergenic region amplified with 16UNIX 
 and 23UNII primers. Sequencing primers were UNI1 and UNI2   5/25/99^^
 
 I should remove 'and' 'in' 'with' 'The', etc. I have set up 
 the stop words array. Is there a efficient way to do this?

How about:

 code
 #!perl -w
 use strict;
 
 my ($r,$tmp) = '' x 2;
 my $input = 'blah srand and spin in with within the their';
 my @s_words = qw(and in with the);
 
 for(@s_words) {
   $tmp .=  \\b$_\\b;
   $tmp .= '|' unless $_ eq $s_words[$#s_words];
 }
 $r = qr/$tmp/is;
 print $r;
 
 print \n\n$input\n\n;
 $input =~ s/$r//g;
 print $input\n;
 end

It builds a regex using your search words and then applies it to a
string.

HTH,

 -dave



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




RE: Regex Problem!!- SOS

2002-05-31 Thread David Gray

 if ($var =~ /^$var1/) {

 if($var =~ /^\Q$var1\E/) {

Should solve your problem -- the \Q and \E tell the regex to stop (and
start again) interpolating any regex characters it finds in the
variable.

HTH,

 -dave



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




RE: union of times algorithm

2002-05-30 Thread David Gray

 I'm trying to come up with an algorithm that seems like it 
 ought to be really easy, but it's turning out to be pretty tough...
 
 Basically I have three pairs of start/stop times, e.g.:
 
3, 5
4, 10
   15, 20
 
 I want the total time covered by all these ranges.  I can't 
 just say (5-3 + 10-4 + 20-15) because the 3,5 and 4,10 ranges 
 overlap.  The desired answer for this case is 13, 3 to 10 and 
 15 to 20.  I have the start times in two arrays, @starts and @stops.
 
 I have to do this probably a million+ times.  Any ideas on 
 how I could go about this?

Building on Janek's response:

 Let's change my algorithm from:
 
 my %timings;
 $timings{$_}++ for (3 .. 5, 4 .. 10, 15 .. 20);
 my $total_time = scalar values %timings;
 
 to:
 
 my %timings;
 $timings{$_}++ for (4 .. 5, 5 .. 10, 16 .. 20);
 my $total_time = scalar values %timings;

And adding some code from Felix from a while ago:

 #! /usr/bin/perl -w
 use strict;
 
 sub generator {
   my $lref = shift;
   my $minseq = shift;
   my $nextfun = shift;
   my $curpos  = 0;
   my $lastpos = scalar(@$lref)-1;
   return sub { 
 while ($curpos = $lastpos) {
   my $result = [$lref-[$curpos]];
   push @$result, $lref-[$curpos] 
 while ++$curpos=$lastpos  
   $lref-[$curpos] == $nextfun-($lref-[$curpos-1]);
   return $result if scalar(@$result) = $minseq;
 }
 return;
   }
 }
 
 my @list = (1, 2, 3, 4, 10, 14, 15, 16, 20, 34, 35, 36);
 my $iter = generator(\@list, 3, sub {$_[0]+1});
 while (my $r = $iter-()) {
 print Found: @$r\n;
 }

We end up with:

 begin code
 #!perl -w
 use strict;

 my %timings = ();
 # load up this array with your input
 my @pairs = ( [3,5], [4,10], [15,20] );
 for my $ra (@pairs) {
   # load up hash using slice syntax
   @timings{($ra-[0]..$ra-[1])} = 1;
 }
 
 my @list = sort {$a=$b} keys %timings;
 my $num_ranges = 0;
 # use sequence detector with 2 as minimum sequence
 my $iter = generator(\@list, 2, sub {$_[0]+1});
 while (my $r = $iter-()) {
   # echo matches
   print Found: @$r\n;
   $num_ranges++;
 }

 my $timeunion = scalar @list - $num_ranges;
 print Time Union is: $timeunion\n;

 sub generator {
   my $lref = shift;
   my $minseq = shift;
   my $nextfun = shift; 
   my $curpos  = 0;
   my $lastpos = scalar(@$lref)-1;
   return sub { 
 while ($curpos = $lastpos) {
   my $result = [$lref-[$curpos]];
   push @$result, $lref-[$curpos] 
 while ++$curpos=$lastpos  
   $lref-[$curpos] == $nextfun-($lref-[$curpos-1]);
   return $result if scalar(@$result) = $minseq;
 }
 return;
   }
 }
 end code

I'll leave the benchmarking alone unless someone else feels like it...

Good Luck,

 -dave



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




RE: Help with parsing output

2002-05-30 Thread David Gray

  while (INPUTDATA) {
  chomp;
  s/^\s+//;
  next if (m/^$/ || (1 .. /^NPROC/));
 
  what does the range thing do?
  wouldn't just ... || /^NPROC/   be enough?
 
 ok. opposite sense:   || ! /^NPROC/

So that would be:

 next if (m/^$/ || ! /^NPROC/);

Which means skip processing the line if it's an empty line or if the
line doesn't begin with NPROC...

What (1 .. /^NPROC/) does is it returns true until it matches /^NPROC/
and then returns false every time it's called after that.

[snip from perldoc perlop]
In scalar context, .. returns a boolean value. The operator is
bistable, like a flip-flop, and emulates the line-range (comma)
operator
of sed, awk, and various editors. Each .. operator maintains its
own
boolean state. It is false as long as its left operand is false.
Once
the left operand is true, the range operator stays true until the
right
operand is true, *AFTER* which the range operator becomes false
again.
It doesn't become false till the next time the range operator is
evaluated. It can test the right operand and become false on the
same
evaluation it became true (as in awk), but it still returns true
once.
If you don't want it to test the right operand till the next
evaluation,
as in sed, just use three dots (...) instead of two. In all other
regards, ... behaves just like .. does.
 ...
If either operand of scalar .. is a constant
expression, that operand is implicitly compared to the $.
variable,
the current line number. Examples:

As a scalar operator:

if (101 .. 200) { print; }  # print 2nd hundred lines
next line if (1 .. /^$/);   # skip header lines
s/^/ / if (/^$/ .. eof()); # quote body
[/snip]

Cheers,

 -dave



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




RE: cgi script that takes in data then runs script on different host

2002-05-28 Thread David Gray

First of all, don't cross-post please. One list is quite sufficient, and
many people are subscribed to more than one list, so duplicate messages
are quite often completely ignored.

 I've got a cgi form that takes in data.  Then, I want the 
 data to be passed to a script that's waiting on a DIFFERENT host.
 
 So, say I have this pseudo-code:
 
 cgi script on host 1pass $name to host 2  script on host 2
 # get $name ---  print 
 hi there $name!\n;

Could you pass $name in the query string? Like this:

 --script 1--
 #!/usr/bin/perl -w
 use strict;
 use CGI;
 my $cgi = new CGI;

 my %F = ();
 # get all values passed to this script
 # assuming no multi-valued form elements
 $F{$_} = $cgi-param($_) for $cgi-param();

 # rebuild the query string to stick on the
 # end of whatever script you want to send
 # these values to
 my $query_string = '?';
 $query_string .= $_=$F{$_}\ for keys %F;

 my $host2 = 'http://www.host2.com/script.cgi';
 print Location:$host2$query_string\n\n;
 --end script 1--


 --script 2--
 #!/usr/bin/perl -w
 use strict;
 use CGI;
 my $cgi = new CGI;

 my %F = ();
 # get all values passed to this script
 # assuming no multi-valued form elements
 $F{$_} = $cgi-param($_) for $cgi-param();

 # print them to make sure they're there
 print 'pre';
 print \$F{$_} == $F{$_}\n for keys %F;
 print '/pre';

 # do stuff with the values passed to the first script
 --end script 2--

HTH,

 -dave



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




RE: pattern matching

2002-05-28 Thread David Gray

 I have a list of the following format that I want to 
 parse:-
 
 ((sa1 da1 sp1 dp1 p1) (sa2 da2 sp2 dp2 p2)  (saN daN 
 spN dpN pN)  )
 
 there are N entries.  There are many such lists and N 
 varies in each list.  One way to parse this is to use 
 brute force and use sth like the following for each 
 tuple (for simplicity let's assume there are only two 
 elements, x and y, instead of five):-
   /\(\s*(\S+)\s*(\w+)\s*\)(.*)/
 
 This will yeild x=$1, y=$2 and remainingTuples=$3.  I 
 can put this in a loop until all tuples are parsed.
 
 I was wondering if there is a single-shot method of 
 parsing the whole thing.  Any comments or ideas are 
 appreciated.

You could create an array of arrays (perldoc perllol) like so:

 --begin code--
 #!perl -w
 use strict;

 my @data = ();
 my $data = '((sa1 da1 sp1 dp1 p1) (sa2 da2 sp2 dp2 p2))';

 # this regex works for the sample data, but you
 # might want to expand it for your own purposes
 while($data =~ /\(([^()]*)\)/g) {
   push @data,[split /\s+/,$1];
 }

 for(@data) {
   print @$_\n\n;
 }
 --end code--

You could then check the number of elements in the Nth list like so:

 my $nth_length = scalar @{$data[N]};

Or grab dp1 from the Nth list like so:

 my $nth_dp1 = $data[N]-[3];


Hope that helps,

 -dave



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




RE: Can someone Help me out with this

2002-05-24 Thread David Gray

 Problem:
 ci_cmd1=abcdef,  // line1
 ci_cmd2=ghijk, // line2
 ci_cmd3=lmnop,   // line3
 ci_cmd4=pqrst, // line4
 
 I want to delete line 1 and 2 and the above should look like 
 as shown below:
 
 ci_cmd1=lmnop,
 ci_cmd2=pqrst,

Where are these lines? Are they in a file? Are they in a variable? Can
you post some code that you've tried?

Cheers,

 -dave


 Regards.,
 Avi

Like Avi from Snatch? =P
Got anything to declare?
Yeah, don't go to England.



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




Can someone Help me out with this

2002-05-24 Thread David Gray

you should try this.
$old=abcdef;
$new=lmnop;
$ci_cmd1 = s/$old/$new/;#this substitutes the old value with the
new one.

regards,
Ian



David Gray wrote:

  Problem:
  ci_cmd1=abcdef,  // line1
  ci_cmd2=ghijk, // line2
  ci_cmd3=lmnop,   // line3
  ci_cmd4=pqrst, // line4
 
  I want to delete line 1 and 2 and the above should look like as 
  shown below:
 
  ci_cmd1=lmnop,
  ci_cmd2=pqrst,

 Where are these lines? Are they in a file? Are they in a variable? Can

 you post some code that you've tried?

 Cheers,

  -dave

  Regards.,
  Avi

 Like Avi from Snatch? =P
 Got anything to declare?
 Yeah, don't go to England.

 --
 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: Need help in Regular Expression

2002-05-24 Thread David Gray

  ...
  Date: Thu, 23 May 2002 19:47:50 +0530 
  ...

 $header = $1 if /^Date: (.*)/; 
 This should do what you want. 

Two things:
 1) should anchor this regex to the end of the line to make sure you get
the entire line in $1
 2) should use the //m switch to treat your string as multiple lines[1]
(assuming you have the entire header in one string)

 $header = $1 if /^Date: (.*)$/m;

Cheers,

 -dave


[1] from perldoc perlre: /m Treat string as multiple lines. That is,
change ^ and $ from matching the start or end of the string to
matching the start or end of any line anywhere within the string.



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




RE: RFC for the three levels of beginnerNeff

2002-05-22 Thread David Gray

 { my other OCD is formalization of systems }

http://www.acronymfinder.com/af-query.asp?String=exactAcronym=ocd

Just because of you, drieux, I have a new appreciation for my
bookmarklets that send me racing off across the web in search of these
new and intriguing acronyms and words that you seem to spend most of
your time inventing and cataloging.

Now I'm just wondering whether you meant Obsessive Compulsive Disorder
or Order of Discalced Carmelites or Organized Crime Division...

Mail me offlist if you'd like a hit off the bookmarklet hooka.
DISCLAIMER: They tend to be a bit more effective (read: work) on Win32
and M$IE, because that's where I use them. I'd love it if someone would
take my hack and develop more cross-browser and/or cross-platform
bookmarklets.

Regards,

 -dave



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




RE: regular expression

2002-05-17 Thread David Gray

 code  

 for(@text) {
   /(d+)$/; # Match only the numbers at the end of the string
 ^^
  this should actually be (\d+)

I would actually conditionally print also, like so:

 print $1 if /(\d+)$/;

And depending on the size of the file, instead of reading the whole
thing into memory with

 my @text = (FILE);

I would do:

 while(FILE) {
   print $1 if /(\d+)$/;
 }

# and store them in '$1' to be printed out on the
# next line followed by a new line character

  @text # contains values of a phone directory
  $text[0] contains john=012345678
  
  $phone1 = ?
  
  let say i wanted to grab just the values'012345678'.
  how should i go on truncating the values?

Cheers,

 -dave



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




RE: Help!

2002-05-15 Thread David Gray

 Please help me!
 I'm going crazy!

For cocoa puffs?

 It's perfect but I need something more.I need also the 
 qw001234 with the
 passwd that's in another file in format:
 
 qw001234 rfvcde
 
 And I want it for all lines of all files.

Of ALL files?

 I'm obviously a beginner in perl so I don't know if it is 
 possible. Bye and many thanks for your help.

Ok so from the previous posting, we have

 ($pw0,$uid1,$pw1,$uid2,$pw2) = split(/\s+/, $line);

It looks to me like the $pw0 should be $uid0 instead:

 ($uid0,$uid1,$pw1,$uid2,$pw2) = split(/\s+/, $line);

So how about storing all the $uid0's in a hash so we can assign them
passwords later, a la:

  %uid0s{$uid0} = ''; # each time through your loop

And later in your program:

  open OTHER,/path/to/other/file
or die couldn't open file: $!\n;
  while(OTHER) {
my ($uid0,$pw0) = split /\s+/;
$uid0s{$uid0} = $pw0 if defined $uid0s{$uid0};
  }
  close OTHER;

  for my $uid0 (keys %uid0s) {
print NEWFILE $uid0 $uid0s{$uid0} \n;
  }

HTH,

 -dave



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




RE: Help!

2002-05-15 Thread David Gray

   %uid0s{$uid0} = ''; # each time through your loop

Should be:
 $uid0s{$uid0} = ''; # till v6 *sigh*

 -dave



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




RE: pass values to another scipt

2002-05-14 Thread David Gray

 Hi Sven,
 
 Sorry, I thought you knew that one.
 
 But how to proceed if you don't want those ugly/insecure 
 params in your location bar ?

Use a form and an input type=image

HTH,

 -dave



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




RE: CGI and frames

2002-05-14 Thread David Gray

 Sorry, I chose the wrong words..
 my script works similar to the way you described below. Depending on 
 which fields are filled out and which button is pressed, a different 
 subroutine is called, creating the page.

Ok... Could you post some code or pseudocode that describes the problem
you're trying to solve?

 -dave



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




RE: Perl IDE

2002-05-14 Thread David Gray

  Well, Mr. Subscriber (if that _is_ your real name)-
  If you just want syntax highlighting, you can check out VIM.

Or code-genie http://www.code-genie.com/ or nedit
http://www.nedit.org/

 I am looking for a freeware Perl IDE for wind0ze. I have done 
 a search and 
 so far only came up with OpenIDE. Is there anything else. 
 What would you
 
 guys recommend and why?

http://www.google.com/search?hl=enq=freeware+perl+ide has a bunch of
IDEs I've never heard of, also.

I use code-genie and like it well enough.

 -dave



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




RE: File Search - String Match - String Count

2002-05-13 Thread David Gray

 I am trying to accomplish the following and have been unable 
 to find a good 
 routine (or build one) which does an adequate job.
 
 1.  Paste a big text file into an html text box which contains email 
 addresses scattered throughout.

You can use the CGI module for this. I'm not sure of the syntax, but I'm
sure someone else will be able to help you out with that.

 2.  Upon form submission, perl routine will put that text 
 file into an 
 array for processing.

Same as above, the CGI module will help you with this.

 3.  Perl will search the array for email addresses and pull 
 out.
 4.  Perl will verify that the email addresses are in 
 valid syntax.
 5.  Perl save the good emails and bad emails 
 into separate variables.
 6.  Perl will report the number of 
 good emails and bad emails found in text 
 file.
 7.  I then want to be able to process the good emails as needed.

http://search.cpan.org/search?mode=modulequery=email
Check out Email::Valid -- that should be able to do most of what you
need. However, a paste from the Email::Valid documentation:

Please note that there is no way to determine whether an address is
deliverable without attempting delivery (for details, see perlfaq 9 [aka
perldoc -q valid mail address])

Good luck,

 -dave



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




RE: CGI QUESTION

2002-05-13 Thread David Gray

 I have a question regarding passing variables from a HTML 
 form to a CGI script.  I have never worked with CGI in the 
 past and assumed that if I included the variables with in the 
 form and on submit called the CGI script that the variable 
 would be amiable to it.  That doe not see, to be the case. Is 
 my assumption correct?
 
 I am attempting to use the variables by the following code:
 
 (param('account'))
 
 Is that correct?

Are you using the CGI module? When I grab what's passed by a form
submission, I usually save a copy of them in a hash (assuming no
multi-valued form elements will be present) like so:

-
use CGI;
my $cgi = new CGI;

our %F = ();
$F{$_} = $cgi-param($_) for $cgi-param();
-

You can now access your form values with $F{account}

Please post more code (from your cgi script where you're trying to
access the values passed from the form) if this doesn't fix your
problem.

HTH,

 -dave



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




RE: How to a parse a string in perl

2002-05-10 Thread David Gray

  I want to slice up this variable into a single variable and 
 loop until its empty The variable is seperated via  !  
 explnation points and I want the numbers. This string can be 
 various in length ? Note it doesnt end with that delimiter. Help
  
 example 
  
   $jims = !23!45!67

How about:

my $jims = !23!45!67;
my @nums = ();
push @nums,$1 while $jims =~ /!?(\d+)/g;

If that doesn't solve your problem, could you please post more data or
examples of what you've tried that hasn't worked?

Cheers,

 -dave



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




RE: a href Vs Form post

2002-05-06 Thread David Gray

 I am strugling with my program that list the contents of a 
 directory. Ones the directory contains files and you have 
 permission it shows you a doc icon else it will show a 
 directory-map followed by it's name as an a href
 
 The problem I have now is that using the a href command 
 will have to show all important variables in the browsers 
 Location. Of course, you would say. But is there a nice 
 possibility to keep using the a href statement without 
 defining the variables in the href, So I can work with the :
 
 use CGI qw(:standard);
 $userid = param(userid);
 ...
 
 
 And get the variables without all users seeing what I need ?
 
 Using the input type=submit, always generates a button, (I 
 believe), that is what I don't like to have, 20 dirs, with 20 
 different submit buttons. Does anyone have an idea ?

Maybe you could use one big form and have a checkbox by each directory
instead of having twenty forms.

 Many Thanks in advance !!!
 
 Location example: 
 http://stage-www/cgi-bin/david/index.cgi?base=/user/web/apache
/stage/htdocs/david/IPlab?header=IPlab?pwuser=gaard?group=icgrp

That URL won't work for us because we're not local to your network...
Could you post some code?

 -dave



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




RE: rmtree

2002-05-06 Thread David Gray

 I have a directory Abs with a file abc in it.
 I am using rmtree to rm this dir as follows
 
 use File::Path;
 rmtree(Abs,1,1) or die dir not del;
 print done;
 
 
 The output is
 
 unlink ../htdocs/store/newpages/Abstract/abc
 
 
 It neither prints the die statement nor the done - ofcourse 
 it doesn't 
 actually delete the file and the dir at all.

You might want to try putting a hard return in your die to make sure it
flushes (even if that's not the problem, it's a good habit), and also
checking the actual error message, like so:

my $dir = 'Abs';
rmtree($dir,1,1) or die couldn't rmtree [$dir]: $!\n;

HTH,

 -dave



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




RE: A very beginner

2002-05-06 Thread David Gray

Good Lord, you're gonna scare away the beginners who have questions
about perl!


  Hi,
  I'm a beginner that doesn't even have perl yet.
  I woul like to know whether Perl is faster or Java for business 
  applications.
 
 Paul has already provided the correct Party Line from the 
 typical Perl Advocate. So I'll be stuck trying to defend the 
 grey beards position.
 
 As for KH's variation on the theme, now we start to move 
 towards the place where we have some parameters to really work with.
 
 To save some space I will try to 'speak in uri' -
 
 One of the places I have been ranting on this is:
 
   http://www.wetware.com/drieux/CS/SoftEng/GP/funcOrNotFunc.html
 
 Where I discuss the matters of code reuse - the OO process 
 by means of 'class/sub_class' - in Proceduralist languages 
 this is the library - in Perl it is the Module - the problem 
 in perl is that the perl5 OO implementation is not as good as 
 it can be, perl6 may 'solve all of that' - and we will see at 
 what costs.
 
 If you want to be way trendy then you of course want to be 
 looking at the Objective Caml Language:
 
   cf: http://www.ocaml.org/
 
 Since this is a language where first order functionality 
 exists and it allows for the use of OO in the few possible 
 edge cases where that may actually have some 'requiredNeff'.
 
 Assuming that one were truly seeking 'ubiquity' for 'human 
 interface' then of course one has already come to understand 
 that one is either going to be writing CGI or mod_perl and/or 
 apache modules - since of course no 'real Operating System' 
 can exist but that it is fully integrated into a webBrowser. 
 { and we thought the emacs folks were a bit over the edge. } 
 At which point one is really talking in terms of what 
 specific type of Tomcat Servlet v. mod_perl v. apache module 
 were you really planning to write
 
 { old guys of course will be thinking in terms of Perl/Tk - 
 because they do not understand that Operating Systems that 
 are not a part of a webBrowser are passe and still have 
 this irrational belief that there were kernels that were not 
 browser plug-ins. }
 
 { for those of you new to writing device drivers - please, do 
 not assume that simply because your VB based device driver 
 allowed you to use 'standard IO' reads of flat files for 
 configurations - that this will allowed in an adult Operating 
 System - and no, you can not put 'printf()' or 'fprintf()' 
 statements in to do your kernel debugging. Nope - Not an option. }
 
 As for the specific question of Large Database - we of course 
 must pause and ask whether or not the system is a 'data 
 mining' project where it will be used for secondary 'decision 
 matrix analysis' - and speed is not the issue - or are we 
 talking in terms of an OLTP - at which point the real 
 question is who is doing the database design and shielding 
 the running daemons from the DB itself by doing the 
 appropriate stored procedures and transaction abstractions 
 - at which point we're also wondering why you want to do the 
 API to that in anything but 'c' because you really want to 
 have the most portable 'assembler code' processing system 
 that works from statically linked compile time code re-use - 
 because you are not at all interested in engaging in the 
 run-time dynamically loadable link level library hassles of 
 version skew as the libfoo.2.so really is not backwardly 
 compatible with the libfoo.1.so and you are not too sure how 
 to fully back out all of the code that needs to use the old 
 form since the process installed them as
 
   libfoo.so - libfoo.int.so
 
 and there can only be ONE!
 
 At which point we could get into the discussions about 
 whether polymorphism is a good idea, as well as whether or 
 not java - which expressly avoids multiple class inheritance 
 - fully got away from all of that with the 'implements' that 
 allows the maze of twisty little passages as you find that 
 there are 'structural' issues getting the extends stuff to 
 work and play well with the implements stuff
 
 We should of course write up the problems associated with the 
 whole process of 'kargo kulting' - In which the blind pass 
 along what they heard to help the deaf find a way to smell a 
 fart... Which has more to do with whether or not you 
 personally should be wearing the trendy T-shirt that says:
 
   WARNING: does not work and play well with others.
 
 Especially if you keep hacking out work arounds for what the 
 'realCoders[tm]'
 were supposedly 'developing' and finding that this is so much 
 more pathetically stoopidly implemented and maintained in 
 perl than in one of those 'real coding languages' that are 
 the topic of hotBuzz.
 
 Hence - just as you should have learned at least one 
 assembler language to know why you write that stuff in 'c' - 
 you need to know Perl so that you know why you don't write 
 'fast code' in an object oriented programming paradigm - 
 since you really do not want to 

RE: Running PubDrills - Re: dynamic variable declaration?

2002-05-06 Thread David Gray

  To appease the powers that be, does anyone know if you can bind 
  columns to a hash:
 
  i.e. $sth-bind_columns(undef,\$val{a},\$val{b},\$val{c}); # ?

 All of which leaves me scritching my head as to why that would be
 a case of 'dynamic variable declaration'

If I didn't ask a question whose answer would provide an alternative to
the dynamic variable solution, that wouldn't be very open-minded, now
would it? ;)

Don't ask, don't tell.

 -dave



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




RE: Sorting problem-part2

2002-05-06 Thread David Gray

 Now I've got an array of hashes, where each hash can have  
 different keys e.g.,
 
 @aoh = ( {H3 =234, H1 =127, DNA =1, p135 =167},
 {H4=24,  H3=1550, DNA =25, p39 =67},
 {H3 =34, H2A =125, DNA =5, p32 =7},
 {H3 =24, H4 =156, DNA =123, p12 =13}
 ) 
 And I'd like to order the array elements by virtue of the 
 biggest value in the hash. 
 
 1. H3 1550
 2. H3 234
 3. H4 156
 4. H2A 125
 
 Is there a quick one liner for this or do I need to find 
 the max in each hash, store them in an array, and then sort 
 the array of hash maxima separately, while maintaining the 
 key/value associations?

perldoc -q sort a hash

 -dave



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




RE: dynamic variable declaration?

2002-05-02 Thread David Gray

 I'm trying to do something that i'm not sure is even 
 possible.  I want to cycle thru an array of MySQL fieldnames 
 and dynamically declare variables based on those fieldnames. 
 
 I can create the array of fieldnames no problem, by just 
 using describe with DBI.
 
 But I can't figure out the declaration part.  THis is what 
 i've tried...
 
 foreach $i (@fieldlist) {
   $$i = $session-get_query_value('$i');
   }
 
 That doesn't work, although that's the gist of what I'm after. 
 Fieldnames are like order_id, bill_fname, ship_lname, etc.  
 
 If I were to hard-code these declarations, I would have about 
 40 lines that look like:
 
 $order_id = $session-get_query_value('order_id');
 $customer_id = $session-get_query_value('customer_id');
 $bill_prefix  = $session-get_query_value('bill_prefix');
 $bill_fname = $session-get_query_value('bill_fname');
 
 The $session- bit is a function that grabs data of the same 
 name as my fieldnames from an outside sessionfile.
 
 I am just trying to avoid having to hardcode this stuff in 
 there, because a) it's alot of code and b) the 
 fieldnames/session variables will grow and I don't want to 
 have to edit the script every time.  
 
 Any help is appreciated!

Is this a CGI script? How big is it? Are you familiar with the DBI
function bind_columns? If not, here's a link to my favorite DBI/DBD
reference:
http://mysql.turbolift.com/mysql/DBD_3.21.X.php3

To appease the powers that be, does anyone know if you can bind columns
to a hash:

i.e. $sth-bind_columns(undef,\$val{a},\$val{b},\$val{c}); # ?

 -dave



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




RE: Beyond Book Learning - the problem of Re: array numerical name...

2002-04-30 Thread David Gray

 On Tuesday, April 30, 2002, at 07:32 , David Gray wrote:
 [..]
  my $fred = 'one,two,three,four';
  my $a = 0;
  @{array$a} = split ',', $fred;
 
  for(0..3) {
print ${array$a}[$b]
  }
 
 File untitled text 2; Line 21:  Name main::b used only
 once: possible 
 typo
 File untitled text 2; Line 18:  Can't use string (array0) 
 as an ARRAY 
 ref while strict refs in use
 
 
 yeah I can clean that up with
 
   my $fred = 'one,two,three,four';
   my $a = 0;
   no strict 'refs';
   @{array$a} = split ',', $fred;
 
   foreach my $b(0..3) {
   print ${array$a}[$b] .\n
   }
 
 so as to get the output
 
   one
   two
   three
   four

Yeah, that would be a clever typo, like it says in the cryptic error
message. Sorry about that.

 All of which drives me back to the question - why did we compel 
 ourselves to have to insert the
 
   no strict 'refs';
 
 given the quandery:
 
  basically i want to name an array with  a subscript ie
  world0[0] and world1[0]   the 0/1 being a variable, i have tried to
   produce a simple example
 
 
 why take the convolutions???

http://www.m-w.com/cgi-bin/dictionary?book=Dictionaryva=quandery
Question, perhaps?
http://www.m-w.com/cgi-bin/dictionary?book=Dictionaryva=convolutions
3. a complication or intricacy of form, design, or structure

I don't use these convolutions of perl for large programming projects
or for sensitive cgi scripts, unless they are in a very otherwise static
and controlled environment, like in that example. I also find that it's
only more confusing to be sesquipedalian in response to posts that only
need a simple, clear answer.

 What have we added to the long term maintainability of the
 code by carbuncling it like this

http://www.m-w.com/cgi-bin/dictionary?book=Dictionaryva=carbuncling
I'll assume you mean that code is confusing. But it's not. It's very
simple. It's a very easy way to perform aggregate functions on several
sets of data, as long as you're careful to make sure your code doesn't
have any stupid side effects, like what Jeff described.

 Why not compel the author down the road to understanding
 how to do good data structures???

Everyone else who responded to the thread did that, and very well I
thought. Perhaps, however, the OP has a simple script that would be
simplified even more if he knew how to use dynamic variables. Sometimes,
when a simple script is the easiest solution to the problem, it's worth
more to just get it working than to spend time developing a complex data
structure.

 -dave




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




RE: Please Help

2002-04-30 Thread David Gray

 I am a student an I'm new to Perl. For a university 
 assignment I need to read the contents of a text file in an 
 array. I am using Windows. The code I am writing is:
 
 $file = /test.txt;
 open (INFO, $file);

Always check to make sure your filehandle was actually opened:

open (INFO, $file) or die couldn't open [$file]: $!\n;

That should help you find the problem.

 @lines = INFO;
 close(INFO);
 
 Altough this is supposed to work, I am getting a ''readline() 
 on closed filehand INFO at line 3' message when I interpret 
 it with perl -w. Please Help

Cheers,

 -dave



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




RE: Brand New Perl Beginner - trouble using activePerl

2002-04-30 Thread David Gray

 I am learning perl now for use with CGI.
 
 I installed active Perl on both windows Millenium AND windows 
 XP systems.
 
 Both of the fail to run a .pl file.  I see a window flash on 
 the screen for a part of a second and then disappear.the 
 window looks like it is a DOS command window.
 
 Anyway, I do not see the program run.  Of course I am doing 
 something very basic wronganyone know what it is???  Thanks !!!

If you want your program to pause during execution if, for example, you
have a lot of output you could insert statements like this:

{ my $trash = STDIN; }

What this does is waits for you to hit enter and takes whatever you
typed (if anything) and puts it into the variable $trash, which then
goes out of scope because the block it's in ends.

Sometimes when I want to quit out of a loop, I'll do:

{ my $trash = STDIN;
  last if $trash =~ /q/;
  exit if $trash =~ /x/; }

But the more simple example will probably work for what you want.

Hope that helps,

 -dave



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




RE: Sorting

2002-04-30 Thread David Gray

 John,
 Could you please comment/explain the following lines please?
 my @sorted = map { (split/\0/)[1] }
   sort
   map { @{[(split)[1,0,2]]}\0$_ }
   @array;

It's fun trying to figure out what the heck John's code does :)

Split each element of @array on whitespace (/\s+/), re-order, and pass
right like so:

468X60  31472  1.49\031472  468X60  1.49
468X60  31473  2.18\031473  468X60  2.18
180X60  31488  1.39\031488  180X60  1.39
468X60  31476  1.58\031476  468X60  1.58
120X60  33472  2.49\033472  120X60  2.49
468X60  32473  4.38\032473  468X60  4.38

It then sorts the list so we have:

120X60  33472  2.49\033472  120X60  2.49
180X60  31488  1.39\031488  180X60  1.39
468X60  31472  1.49\031472  468X60  1.49
468X60  31473  2.18\031473  468X60  2.18
468X60  31476  1.58\031476  468X60  1.58
468X60  32473  4.38\032473  468X60  4.38

And then, finally, splits on \0 and takes the second part of that line,
which is the part ordered as the OP wanted it:

33472  120X60  2.49 
31488  180X60  1.39 
31472  468X60  1.49 
31473  468X60  2.18 
31476  468X60  1.58 
32473  468X60  4.38 

HTH,

 -dave



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




RE: associative array not looking like I thought it would

2002-04-26 Thread David Gray

 This was all written by a vendor and I am trying to learn 
 PERL to modify what they did.  When you say I must print it 
 explicitly, what exactly do you mean?

You have to _sort_ it explicitly. In Timothy's example, he was sorting
the hash alphabetically based on the keys. The keys function returns a
temporary array which contains the ...*dramatic pause*... keys of the
hash, which are then sorted alphabetically and used to access the hash.

Perl internally optimizes and re-orders hashes, so if you want them to
be in the same order they were inserted in, consider using an array of
arrays, like so:

@Error=( [Error=[$ciTDF{'#errval_V'}]: $ciTDF{'#errtext_V'}],
 ['Document Name'=$ciTDF{'DOC_NAME_V'}],
 [Revision=$ciTDF{'DOC_REV_V'}],
 [Desc=Issuing-could not index to vault],
 [Notes=Clean Vault Log] );

If you plan to do it this way, or if you're just curious, you should
read the perlreftut manpage by typing 'perldoc perlreftut' at the
command line. You can then access your variables like this:

$Error[2]-[0]; # access the first value
# of the third element inserted


And print them sorted alphabetically by the first value like so:

foreach(sort {$a-[0] cmp $b-[0]} @Error) {
  print '$_-[0]' = '$_-[1]'\n;
}

HTH,

 -dave



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




RE: Parsing a line - part 2

2002-04-25 Thread David Gray

   @keys{ qw/P ST U SL D/ } = \( $Proc, $Start, $Url, 
 $Sleep, $Drive );
  
  This is a shortcut for defining the values of a hash -- it creates 
  $keys{P} == $Proc, $keys{ST} == $Start, etc.
 
 $keys{P} = \$Proc, $keys{ST} = \$Start, etc.

Okay... Fair enough. Maybe I'm missing something, but why in the world
would you want to make something a hash of references to scalars when a
hash of scalars would work just as well?

 From the OP's post, the data is:
 
 q[P=IcwRcsm D=D: SL=20 ST=d:\icw\rcsm\StartSv.bat Parm1 Parm2 
 U=http://uslv...];
 
 /(\S+)=(.+?)(?=\s+\S+=|\z)/g  will match:
 (P)=(IcwRcsm)(?= D=)
 (D)=(D:)(?= SL=)
 (SL)=(20)(?= ST=)
 (ST)=(d:\icw\rcsm\StartSv.bat Parm1 Parm2)(?= U=)
 And finally:
 (U)=(http://uslv...)(?=\z)
 
 The (?=\s+\S+=) pattern ensures that the data captured in $2 
 has no trailing whitespace.

Alright, thanks for that explanation, I see how that would work for
every case but the last one - what if there was trailing whitespace
after the value for U and before the end of the string? (?=\s+\S+=)
seems like it would pick up the trailing whitespace in that case because
it needs a non-whitespace character to complete the match for the group.
How about:

/(\S+)=(.+?)(?=\s+\S+=|\s+|\z)/g
  

To catch trailing whitespace at the end of the line of data?

  After the code is executed, you'd end up with:
  
  $P == 'IcwRcsm D=D:'
  $SL == '20 ST=d:\icw\rcsm\StartSv.bat'
 
 Wrong.  Run the code I posted and see for yourself.

Yeah, my mistake, I just typed that wrong :)

Cheers,

 -dave



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




RE: Parsing a line - part 2

2002-04-25 Thread David Gray

 How about:
 
 /(\S+)=(.+?)(?=\s+\S+=|\s+|\z)/g
   
 
 To catch trailing whitespace at the end of the line of data?

Actually, I meant:

/(\S+)=(.+?)(?=\s+\S+=|\s*\z)/g
   ^^^

 -dave



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




RE: exiting correctly

2002-04-24 Thread David Gray

 below is a snipet of the code.  the most relavant part.  when 
 i enter some bad data in or mysql has problems, it should go 
 to error_handler()  at the bottom of my script.  well it 
 does, then it returns unless i put an exit at the end of 
 error_handler.

How about:

mysub('param1','param2');
mysub('parma1','param2');

sub mysub {
  my ($p1,$p2) = @_;
  print in mysub\n;
  $p1 eq 'param1' or err_h(invalid param: [$p1]\n) or return 0;
  print passed: [$p1] [$p2]\n;
}

sub err_h {
  print $_[0] and return 0;
}

HTH,

 -dave



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




RE: sort regex trouble!

2002-04-24 Thread David Gray

  im trying to sort out this sort routine:
  the sub by_number_of_citations works
  but if i try to make a sort alphabetically, my regex fails?
  how should it be done?
 
  # sting to match: trtd1212/tdtdCited 
  Work/tdtd12/tdtd1232 /tdtd1999/td/tr
 
  # sort routine
  #
  sub by_number_of_citations
  {
 $a =~ /\td\(.*?)\\/td\/;
 my $A = $1;
 $b =~ /\td\(.*?)\\/td\/;
 my $B = $1;
 
 $B = $A;
  }

May I suggest:
(my $A = $a) =~ s/^trtd(\d+)\/td/$1/;
(my $B = $b) =~ s/^trtd(\d+)\/td/$1/;

  # sort routine
  #
  sub alphabetically
  {
 $a =~ /^\tr\\td\\d+\\/td\\td\(.*)\\/td\/;
 my $A = $1;
 $b =~ /^\tr\\td\\d+\\/td\\td\(.*)\\/td\/;
 my $B = $1;
 
 $A cmp $B;
  }

Again:
(my $A = $a) =~ s/^trtd\d+\/tdtd(.*?)\/td/;
(my $B = $b) =~ s/^trtd\d+\/tdtd(.*?)\/td/;

But notice the (.*?) group... I think that might have been your problem.
Let me know if that works, and if it doesn't, please post more data that
you're comparing.

 you haven't shown where you get the strings $a and $b which 
 you pass as 
 arguments to your subs.

He's doing:

sort by_number_of_citations @list
sort alphabetically @list

Which implicitly passes $a and $b into the custom sort subroutines.
Neat, eh? :)

Cheers,

 -dave



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




RE: question

2002-04-24 Thread David Gray

 When I put this in my script I get an error 
 
 Name main::NAME used only once: possible typo at 
 ubrstate2.pl line 521.

That's not an error, that's a warning. It should go away once you have
another statement in your program that uses the filehandle (main::NAME)
you're defining.

HTH,

 -dave



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




RE: sort regex trouble!

2002-04-24 Thread David Gray

 May I suggest:
 (my $A = $a) =~ s/^trtd(\d+)\/td/$1/;
 (my $B = $b) =~ s/^trtd(\d+)\/td/$1/;
 
 That's not what he's doing.  He's doing:
 
   my ($A) = $a =~ m{^trtd(\d+)/td};
   my ($B) = $b =~ m{^trtd(\d+)/td};
 
 Yours leaves everything after the /td tacked onto the end 
 of $A; mine and his only store the number in $A.

Argh, good catch. I usually do that kind of thing like:

my $A = $1 if $a =~ m{^trtd(\d+)/td};

But I didn't that time :)

Let us know if any of this fixes your problem, Martin...

 -dave



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




RE: Patterm Matching

2002-04-24 Thread David Gray

 Actually, \n's are the one thing that the $ anchor doesn't 
 work exactly right on.  Usually it's not a huge deal, but 
 Perl will still match a line that has a \n after the part 
 that you are trying to match if you use $ to anchor.  This is 
 normally very useful, as in the case of a line of text being 
 read from a file.  Without this behavior you would have to 
 put a \n at the end of all of your regexes.  So:
 
 $radentry =~ /\n\n$/;
 
 will match \n\n and \n\n\n 
 
 To fix this problem, you should remember the \Z anchor, which 
 matches only the end of a string.  
 
 $radentry =~ /\n\n\Z/;

From perldoc perlre:

 \Z  Match only at end of string, or before newline at the end
 \z  Match only at end of string

Should be:

$radentry =~ /\n\n\z/;

To match two newlines at the end of $radentry.

 -dave



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




RE: Parsing a line - part 2

2002-04-24 Thread David Gray

 Thank you, John. This code does exactly what I want. Problem 
 is, I only understand about 30% of what's going on. I can 
 figure out the use of the hash, some of the pattern matching 
  $1/$2. But can someone elaborate on:
 
 @keys{ qw/P ST U SL D/ } = \( $Proc, $Start, $Url, $Sleep, $Drive );

This is a shortcut for defining the values of a hash -- it creates
$keys{P} == $Proc, $keys{ST} == $Start, etc.

 /(\S+)=(.+?)(?=\s+\S+=|\z)/g
^^^   ^^^ ^^^   
 1 2   3  4

1) match one or more non-whitespace characters, followed by a literal
'='

2) match one or more anythings, non-greedy

3) a zero-width positive look-ahead assertion (check out perldoc
perlre for more info on this, basically checks that a pattern exists
ahead of what you're currently examining in your regex)

4) this part doesn't make sense to me -- I would think it should be:

(?=\s+=|\z)

instead... I see no cases where there would be any whitespace after your
parameter list is finished, and between, for example, 'ST' and '=',
which is what this sequence allows for...

 ${$keys{uc $1}} = $2;

First of all, $1 and $2 are automatic variables set by backreferences in
the previously evaluated regular expression, the one discussed above.
The 'uc $1' part makes sure that whatever characters are in $1 are
uppercase. It's then read as: take the variable named $keys{uc $1} and
set it to $2. Check out perldoc perlref for more information about this,
especially the section titled: 'Using References'.

After the code is executed, you'd end up with:

$P == 'IcwRcsm D=D:'
$SL == '20 ST=d:\icw\rcsm\StartSv.bat'

HTH,

 -dave



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




RE: remove duplicate values from array

2002-04-22 Thread David Gray

 Can anyone tell me the best method for removing duplicate 
 array values.
 
 eg:
 
  @array = qw( a a a b b b c);
 
 becomes after some operation I cant seem to figure:
 
 @new_array_or_same = (a b c); 

In this situation, I usually use a hash instead of an array so I can
create highly useful statistics of how often each value occurs.

So I would do:

$hash{a}++ or $hash{b}++ or $hash{c}++

And then, like Jeff said, you could look in the manpage and get your
array from this hash you've created using the keys function like so:

@array = keys %hash;

Cheers,

 -dave



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




RE: Complicated RegEx

2002-04-22 Thread David Gray

 I have the following line in a text file 
 
 Total  3250 5 0 0 0 0  879717 
 0 0 0   
   0  926418 0 0 0 0  920714   
   0 0 0 
 0  692510 0 0 0 0
 
 (this is the entire line, but  it's just wrapped)
 
 I have a regex that will get the values after the four digit 
 numbers( (5, 17, 
 18, 14 and 10).it is
 
 ^Total\s+\d+\s+(\d+)(?:\s+\d+){5}\s+(\d+)(?:\s+\d+){5}\s+(\d+)
 (?:\s+\d+){5}\s+(\d+)(?:\s+\d+){5}\s+(\d+)
 
 (they won't always be four digit numbers so I can't put that 
 in my regex) 
 
 Now, this is great, when I have 5 numbers that I need to 
 retrieve. but if 
 the line looked like
 
 Total  3250 5 0 0 0 0  879717 
 0 0 0   
   0  926418 0 0 0 0 
 
 then there wouldn't be a match.  Anyone have ideas of how 
 this can be adapted 
 to say that if there are at least 2 sets of numbers (a set 
 would be 3250 5 0 
 0 0 0 - in the case above there are 3 sets and at the top 
 there are 5) and 
 a maximum of 6 sets of numbers it would get the number in the second 
 placein this case it would get 5, 17 and 18.

You could use an array, like so:

my @second_places = ();
while(FILE) {
  chomp;
  my @values = split /\s+/;
  my $i = 2;
  while(defined $values[$i]) {
push @second_places,$values[$i];
$i += 6;
  }
}

This splits your line on whitespace and saves every sixth element, if it
is defined, starting with the third one.

HTH,

 -dave



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




RE: Errors Running Learning Perl in Win32 Scripts

2002-04-16 Thread David Gray

 Thanks! I think your advice may apply to the following code 
 that I'm having trouble with:
 
 use Win32::NetAdmin;
 $username = Win32::LoginName;
 Win32::NetAdmin::UserGetAttributes(, $username, $password,
 $passwordage, $privilege, $homedir, $comment, $flags, 
 $scriptpath);
 print The homedir for $username is $homedir\n;

Perldoc is your best friend. Try running the command 'perldoc
Win32::NetAdmin', which lists the available documentation for the module
Win32::NetAdmin that you're using. The example at the end of that
listing looks like what you're looking for to get rid of the warnings.

 I tried this but got similar errors but I played with it and 
 tried to add the other $'s to the print statement but the 
 only thing that will print is the username (I'm logged onto 
 NT Server 4 as Admin). 

What were the error messages? What exactly did you try?

 Here's the other code that I'm having trouble with and it's 
 indicative of the problems that I'm having with the 
 IO::Socket::INET-new statement: 
 
 use IO::Socket;
 $remote = IO::Socket::INET-new(
 Proto = tcp;
 PeerAddr = localhost;
 PeerPort = daytime(13),
 )
 or die Can't connect to daytime port at localhost;
 while ($remote) {print}
 
 Now, I'm getting syntax errors: 
 
 syntax error at 415b.pl line 3, near tcp;
 syntax error at 415b.pl line 7, near )
 
 
 Any ideas? Remember, I'm a beginner. :-) (no flaming!)

One question per thread please.

HTH,

 -dave



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




RE: Need help getting started using hashes

2002-04-16 Thread David Gray

 First let's let the other list member in on the code:
 
 use DBI;
 use strict;
 my $dbname = test;
 my $host = localhost;
 my $dbuser = '';
 my $dbpw = '';
 my $mscs = dbi:mysql:dbname=$dbname;host=$host;;
 my $dbh = DBI-connect($mscs, $dbuser, $dbpw) or die Connect fails to
 $dbname\nError = , $DBI::errstr;
 my $sql = select * from method;

#replace prev. line with:
my $sql = 'select methodid,method,sname from method';
   $sql .= 'order by methodid';

 my $sth = $dbh-prepare($sql) or die Prepare fails for
 stmt:\n\t\t$sql\nError = , $DBI::errstr;
 my $rv;
 unless ($sth-execute) {
  print\n\tExecute fails for stmt:\n\t\t$sql\nError = , $DBI::errstr;
  $sth-finish;
  $dbh-disconnect;
  die \n\t\tClean up finished\n;
 }
 print \t\t$rv\n\n if $rv;
 my %thehash;
 my @row_ary;
 my $row_ary;
 my $key;
 
 while (@row_ary  = $sth-fetchrow_array) {
  $key = $row_ary[0];
  $thehash{$key} = $row_ary[1];

#replace prev. two lines with:
$ra{$row_ary[0]} = [$row[1], $row[2]];

 }
 $sth-finish;
 $dbh-disconnect;

This builds a hash of n two-element arrays, where n is select
count(methodid) from method. You can access the hash using (as the
first index) the methodid you want, and the second index will be either
0 or 1, depending whether you want the method or sname (respectively)
for that methodid:

#based on the table printout from the first post:
print $ra-{2}-[0];
# prints 'Progestin-Only Ocs'
Print $ra-{2}-[1];
# prints 'POC'

The reason I picked a hash of arrays is so it doesn't matter whether
there are always as many rows as max(methodid) (i.e. no gaps in the
sequence, otherwise you could use an array - see below), and the
two-element array because you don't need the associative array
functionality. You could just as easily create two local variables
($method,$sname) = (0,1) and access the array using the variables as the
index.

If you wanted an array of arrays:

$ra[$row_ary[0]] = [$row[1], $row[2]];

#based on the table printout from the first post:
print $ra-[2]-[0];
# prints 'Progestin-Only Ocs'
Print $ra-[2]-[1];
# prints 'POC'

Would do the trick. Either way should work, it just depends on how you
want to access your data :) check out
http://www.perldoc.com/perl5.6.1/pod/perlreftut.html.

Hope that helps,

 -dave



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




RE: Need help getting started using hashes

2002-04-16 Thread David Gray

  my $sql = select * from method;
 
 #replace prev. line with:
 my $sql = 'select methodid,method,sname from method';
$sql .= 'order by methodid';

#second line should be
$sql .= ' order by methodid';

 -dave



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




RE: Errors Running Learning Perl in Win32 Scripts

2002-04-16 Thread David Gray

 Change this line
 
($name, $aliases, $addrtype, $length, @addrs) = 
 gethostbyname($host);
 
 To
 
(undef, undef, undef, undef, @addrs) = gethostbyname($host);

I think mine is prettier, at least (see below)... Is there a reason why
this might be considered Better than doing:

@addrs = (gethostbyname($host))[4];

?

 -dave



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




RE: Errors Running Learning Perl in Win32 Scripts

2002-04-16 Thread David Gray

   Change this line
   
  ($name, $aliases, $addrtype, $length, @addrs) =
   gethostbyname($host);
   
   To
   
  (undef, undef, undef, undef, @addrs) = gethostbyname($host);
  
  I think mine is prettier, at least (see below)... Is there a reason 
  why this might be considered Better than doing:
  
  @addrs = (gethostbyname($host))[4];
  
  ?
 
 Of course there is. Those two are different. Notice that the fifth 
 variable in the list is not a scalar but an array. It is supposed to 
 slurp all items starting with the fifth. While usually the 
 gethostbyname() will return only one address it may return several. 
 At least according to the docs.
 
 Example:
 
   sub foo { (0,1,2,3,4,5,6,6,8,9) };
 
   (undef,undef,undef,undef,@a1) = foo();
   @a2 = (foo())[4];
 
   print join(, , @a1),\n;
   print join(, , @a2),\n;

Oh, hehe, right... Silly me!

 -dave



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




RE: splitting / regex / trend etc

2002-04-12 Thread David Gray

 If I only want to get the numbers sold for lets say apples, 
 oranges and 
 grapefruit, for both stores How would I go about it? 
 
 File for Store A 
 apples, oranges, pears, lemons, grapefruit 
 5, 0, 4, 6, 2 
 2, 6, 2, 0, 0
 4, 7, 2, 1, 0
 
 File for Store B 
 apples, melon, oranges, pears, coconut, lemons, grapefruit
 4, 3, 2, 7, 1, 4, 0
 3, 1, 4, 4, 0, 0, 1
 0, 4, 0, 0, 4, 5, 0  

open F,'/path/to/your/file.txt';
chomp(my $fruits = F);
my @fruits = split /,\s*/,$fruits;
my $count = 0;
while(F) {
  chomp;
  my @currvals = split /,\s*/;
  for(0..scalar @fruits - 1) {
$dayvals[$count++]-{$fruits[$_]} = $currvals[$_];
  }
}
close F;

Then for day x, you can access the fruit totals like so:

$dayvals[1]-{melon}

The above code builds an array of hashes, one for each line (day). I
suppose if you're after totals, you could use a hash instead, like so
(re-using the above code where not specified):

my %totals = ();
while(F) {
  chomp;
  my @currvals = split /,\s*/;
  for(0..scalar @fruits - 1) {
$totals{$fruits[$_]} += $currvals[$_];
  }
}

So now you can access the totals for each file by:

$totals{melon}

HTH,

 -dave



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




RE: Problem with replacing text in a variable...

2002-04-12 Thread David Gray

 OK!
 
 my script works! But when I use:
 
 my $rvar = STDIN;
 
 I have the same problem! Jesus, that's a hard one :-)

After you read it in, do you have a '$' in the string? If so, you need
to escape it like so:

$rvar =~ s/\$/\\\$/g;

That should fix the problem. If it doesn't, could you paste more of the
code you're using?

 -dave

 An update on previous post...
 It seems that I typed some errors :-(
 
 This is a small rewrite of my script...
 #!/usr/bin/perl
 
 use warnings;
 
 my $var  = test;
 my $rvar = \$interface;
 my $cmd  = int \$interface\n;
 
 print $var\n;
 print $cmd\n;
 
 $cmd =~ s/$rvar/$var/g;
 
 print $cmd\n;
 
 If you run this, the $interface in the variable $cmd isn't
 replaced by 
 test...
 
 Why?
 
 
 If you change
 
 my $rvar = \$interface;
 
 To
 
 my $rvar = '\$interface';
 
 It works like I think you want it to. The reason it wasn't working 
 before is because the regex was seeing:
 
 $cmd =~ s/$interface/test/;
 
 Because when you declared $rvar, it saved the string '$interface', 
 which then got interpolated by the regular expression.
 
 HTH,
 
  -dave
 
 
 
 
 
 
 -- 
 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: Help with MIME::Lite module

2002-04-12 Thread David Gray

 my $msg = MIME::Lite-new(
From   = '[EMAIL PROTECTED]'
 mailto:'[EMAIL PROTECTED]' ,
To = '[EMAIL PROTECTED]'
 mailto:'[EMAIL PROTECTED]' ,
Cc = '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' ,
Subject= 'Morning Trouble Call report',
Type   = 'text/html',
Data   = '$rhtmlpage'
  
   );
  
 $msg-send();

That doesn't look like it would work... Your hash values are
single-quoted, and the hash values also contain single-quotes... using
double quotes like Nikola suggested should fix your problems.

 -dave



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




RE: Find and replace a word or characater in a the same file.

2002-04-12 Thread David Gray

 I would like to find a word or character in a file and
 replace it with another word or character, while
 leaving others untouched.  Currently, I am using the
 following method
 
 #!/bin/perl -Dr -w
 open(FILE,$ARGV[0]) || die Can't open $ARGV[0]:
 $!\n;
 open(FILE2,$ARGV[0].spi) || die Can't open
 $ARGV[0]_new: $!\n;
 while (FILE)
 {
   if (/(^VV\d+ )(TA)x(\d)x(.*)/)
   {
 print FILE2 $1,,$2,[,$3,],$4,\n;
   }
  else
   {
 print FILE2 $_;
   }
 }
 close FILE;
 close FILE2;

So you want to update FILE with the search and replace changes, right?
That means you either need a copy of the file in memory or you need to
rename the file that you create by writing to FILE2.

To rename the file:

use File::Copy qw(move);
# create backup of original file
move($ARGV[0],$ARGV[0].bak);
# rename file you created
move($ARGV[0].spi,$ARGV[0]);

To work with the file in memory:
OVERWRITES THE FILE YOU PASS AS A PARAMETER, SO MAKE SURE YOU HAVE A
BACKUP!

open FILE,$ARGV[0]
  or die couldn't open $ARGV[0]: $!\n;
my @file = FILE; close FILE;
foreach my $line (@file) {
  $line =~ s/(^VV\d+ )(TA)x(\d)x(.*)$/$1$2\[$3\]$4/;
}
open FILE,$ARGV[0]
  or die couldn't open $ARGV[0] for write: $!\n;
print FILE join '',@file;

HTH,

 -dave



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




RE: splitting / regex / trend etc

2002-04-12 Thread David Gray

 @fruitname = split /[,\s]+/ = DATA;
 ...
@fruit{ @fruitname } = split /[,\s]+/ = $_ ;

Mr. Big Fancy Comma Man ;)

That's cool, an extra step of simplification... Very nicely done.

 -dave



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




RE: pattern match

2002-04-12 Thread David Gray

 for e.g : 
 
 (not showing the new lines..)
 
  
 word1.word1.word1word2word1...word2wor
 d2word2
 .

You're gonna want to check out (in the perldoc perlre manpage) (??{ code
}), which is an example of a recursive regular expression. They have an
example that matches nested parenthesis correctly.

Cool stuff :)

 -dave



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




RE: Problem with replacing text in a variable...

2002-04-11 Thread David Gray

 I have a problem with substitutions...
 In the piece of code, here below,
 display $var1, $var' should be display val1, val2;
 I don't see why, but the if condition doesn't seems to 
 work... and if I remove the if condition, the replacement 
 doesn't occur... Does any of you know why?
 
 $VarValue{$var1} = val1;
 $VarValue{$var2} = val2
 $Cmd = display $var1, $var2;

The previous line evaluates to 'display , ' when the perl interpreter
hits it because it looks for the variables $var1 and $var2, but can't
find them, so it uses '' (the string value of undef) instead. You might
want to try:

$Cmd = 'display $var1, $var2';

Same thing for the hash you're creating... If you want to do what I
think you want to do, you need to define that hash as:

$VarValue{'$var1'} = 'val1';
$VarValue{'$var2'} = 'val2';

HTH,

 -dave



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




RE: Problem with replacing text in a variable...

2002-04-11 Thread David Gray

 An update on previous post...
 It seems that I typed some errors :-(
 
 This is a small rewrite of my script...
 #!/usr/bin/perl
 
 use warnings;
 
 my $var  = test;
 my $rvar = \$interface;
 my $cmd  = int \$interface\n;
 
 print $var\n;
 print $cmd\n;
 
 $cmd =~ s/$rvar/$var/g;
 
 print $cmd\n;
 
 If you run this, the $interface in the variable $cmd isn't 
 replaced by 
 test...
 
 Why?

If you change

my $rvar = \$interface;

To

my $rvar = '\$interface';

It works like I think you want it to. The reason it wasn't working
before is because the regex was seeing:

$cmd =~ s/$interface/test/;

Because when you declared $rvar, it saved the string '$interface', which
then got interpolated by the regular expression.

HTH,

 -dave



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




RE: Execute .bat file from perl?

2002-04-10 Thread David Gray

 New to this - need to execute a .bat file from a perl script.
 
 Any suggestions?

Look into the system command:

perldoc -f system

Hope that helps,

 -dave



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




RE: default value

2002-04-10 Thread David Gray

   $question = $default if $question eq '';

You could possibly shorten this last line to:

$question ||= $default;

This will set $question to $default if $question logically evaluates to
false (which includes the case where $question is the empty string). If
you only want to reset $question when it contains nothing, however, the
previous solution is exactly what you want to do.

 -dave



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




RE: File Paths and file names

2002-04-10 Thread David Gray

 I would like to write a perl program to run on NT to go 
 through a list of files, with full path and extract just the 
 file name. The path is random in length likewise so is the file name.

You could use a regular expression like:

$filename =~ s/[\\\/]([^\\\/])$/$1/;

To replace the full path with only what comes after the last '/' or '\'.

Hope that helps,

 -dave



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




RE: Oracle sequences

2002-04-10 Thread David Gray

 I'm attempting to load an oracle database and am struggling 
 with how to retrieve a sequence for a table.
 
 in SQL, the value is net_seq.nextval
 how do i use this in a perl script??

Do you have DBI installed? What have you tried? Can we see some code?

AFAIK, you can't directly retrieve the value of a sequence... The only
way I've ever used sequences is by setting something to either
net_seq.currval or net_seq.nextval - if there is a way to directly get
the current value with a select statement, I don't know the syntax for
it...

HTH,

 -dave



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




RE: Scope of my() declared variables WAS( Re: -e $filename...)

2002-04-10 Thread David Gray

 Here's the part I still don't understand, and maybe some of 
 you can show me the light.  What is the difference between 
 local() and my()?  I have never used local(), the only 
 examples I've ever been given involve scoping $_, and if I am 
 ever tempted to do that, I can usually trace it back to a bad 
 algorithm.

perldoc -q lexical

 -dave



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




RE: use of package in a script

2002-04-10 Thread David Gray

 Unless someone can come up with a really HOT idea as to why 
 one would want to put a 'package declaration' in an 
 application - and I have tried, but for the life of me, can 
 not come up with a good reason to go there...

How about as a mnemonic device, or to sort variables by category?
Consider:

$DEFAULT::DEBUG_LEVEL = 5;
@TMP::fileContents = FILE;

Then you can do things like:

for(keys %TMP::) {
  ${TMP::$_} = ''
}

Or

for(keys %DEFAULT::) {
  $$_ = ${DEFAULT::$_} unless defined $$_
}

I know there are other ways to do things like that, but purely for the
sake of argument ;)

 -dave



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




RE: rewrite without using two functions?

2002-04-09 Thread David Gray

 is there a way to write this without using map AND grep AND 
 without making
 it longer than it is?
 @must = map { m/(.*)\/\*/; $1 } grep m/\/\*/, @recomp;
 
 where  @recomp = qw( stuff/stuff.c
   crap/*
   morestuff/*
   stuffy/stuff_stuff.c
   stuffy/suffering.c
   ); # and more of the similar

Hmm. Have you tried:

@must = map { /^(.*)\/\*$/ } @recomp;

If so, is there a big speed loss when you remove the grep?

Interested,

 -dave



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




RE: rewrite without using two functions?

2002-04-09 Thread David Gray

 map returns the result of the last evaluated statement...
 @must would have ones and zeros... I want the $1 portion but 
 only if it ends in '/*' there really isn't a speed issue... 
 it's more a can i make this line look sweeter?
 
   is there a way to write this without using map AND grep AND
   without making
   it longer than it is?
   @must = map { m/(.*)\/\*/; $1 } grep m/\/\*/, @recomp;
   
   where  @recomp = qw( stuff/stuff.c
 crap/*
 morestuff/*
 stuffy/stuff_stuff.c
 stuffy/suffering.c
 ); # and more of the similar
  
  Hmm. Have you tried:
  
  @must = map { /^(.*)\/\*$/ } @recomp;

Those two lines were working exactly the same way when I tested them...
I'm on a Win2000 Pro box with ActivePerl 5.6.1

Are they not working the same way on your system?

 -dave



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




RE: rewrite without using two functions?

2002-04-09 Thread David Gray

 Why are there still no empty elements in the returned array 
 for the items that didn't match the pattern? @must == 2
 
 I am just befuddled but this paradox
  
  Thus, map { m!(.*)/\*! } LIST will return $1 or () for each
  element of the
  LIST.

When you have

LIST2 = map { m!^(.*)/\*$! } LIST1

It's shorthand for a loop like:

foreach my $el (@LIST1) {
  if($el =~ m!^(.*?)/\*$!) {
push @LIST2,$1
  } else {
push @LIST2,()
  }
}

So when the regular expression doesn't match, it pushes an empty list,
which adds nothing to the array.

 -dave



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




RE: asp from perl

2002-04-08 Thread David Gray

 hello everyone,i am trying to execute an asp script from a 
 perl cgi and i have the following problem
 
 I am  using something like this to get user's input and the 
 pass it to the asp
 
 ReadParse (*input);
 
 my $pin;
 my $passwd;
 
 my @input;
 
 $pin = $input {'pin'};
 
 $passwd = $input {'passwd'};
 
 my $page_url = 10.0.0.4/Validation.asp?pin=$pinpasswd=$passwd;
 
 the problem that i seem to be having is that i can not get 
 the values passed to the asp in the form of  
 variables,because the values of $pin and $passwd are no 
 actually being passed to the asp..,therefore it gives  back 
 an empty answer Does anoyone knows  how to pass the actual 
 variables values to the asp?

Check out the cgi module:

perldoc cgi

You're gonna want to do something like:

use CGI;
my $cgi = new CGI;
for($cgi-param()) {
  $F{$_} = $cgi-param($_);
}

Watch out for multivalued form inputs though. This is covered in the
CGI.pm documentation.

Hope that helps a bit,

 -dave



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




RE: Variable question

2002-04-08 Thread David Gray

 I believe it is as simple as:
 
 $count = () = $string =~ /,/g;

I can't seem to get my brain around what's happening here... would
someone be kind enough to explain?

 -dave



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




RE: How to remove 3 lines from a file

2002-04-08 Thread David Gray

 Hi, I have a file like this:
 
 .
 # PXE Class
 vendor-class PXEClient {
 default-lease-time 1800;
 max-lease-time 1800;
 option dhcp-class-identifier PXEServer;
 
   filename /bootp/linux/3.0/alize/startup.txt;
   option vendor-encapsulated-options
   S G:/dhs3mgr/e15011.ae ;
 } 
 
 ..
 
 and i would like to have this:
 
 # PXE Class
 vendor-class PXEClient {
 default-lease-time 1800;
 max-lease-time 1800;
 option dhcp-class-identifier PXEServer;
 
   
 } 
 ...

my $good_file = '';
while(FILE) {
  if(/^vendor-class/i){
$good_file .= $_;
my $end_group = 0;
while(FILE) {
  $good_file .= $_ unless $end_group;
  $end_group = 1 if /^\s*$/;
  last if /^\}/;
}
$good_file .= }\n;
  }
}
print $good_file;

This loops over an open filehandle, starts a group for each line that
starts with 'vendor-class', saves everything within vendor-class until
the first blank line to $good_file, and breaks out of the inner while
when it finds a '}' by itself on a line.

Hope that helps,

 -dave



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




RE: Variable question

2002-04-08 Thread David Gray

  $count = () = $string =~ /,/g;
 
  $string =~ /,/g;
 
  assigns the result in a list context - the anonymous list '()'. by 
  assigning this to a scalar, $count, we get a value that is 
 the size 
  of the list, which is the number of matches that the regex 
 made. that 
  empty list thingy is confusing. it is more comprehensible if you 
  assign it to a named array: $count = @arr = $string =~ /,/g;
  the matches are in @arr which consists of the comma of the match.
  then $count is the size of the array.
 
  With the downside that you have an array that you never 
 use.  Using () 
  to force list context is one of those strange little quirks 
 that you 
  just get used to.  These days I read () as the array equivalent of 
  scalar().
 
 
 agreed. i didn't mean to actually use a named array. i was 
 suggesting it 
 as a way to understand what was happening. definitely no 
 sense to actually 
 name the array in your working code.

Question answered, much appreciated.

 -dave



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




RE: Read in from STDIN

2002-04-04 Thread David Gray

 Could anyone help I am having trouble reading in information 
 from STDIN
 
 For coding see attached file
 
 Using a while loop I want to do the following:
 Read info in from STDIN
 Read in any number of name/value pairs,
 Read in names in pairs of two, and compute their sum.
 Choose the maximum of all those pairs and print it.
 At the same time choose the minimum and print it.

Your code looks fine to me - what exactly is going wrong? How are you
giving the data to STDIN (you do know that you have to hit enter each
time you want STDIN to read what you've typed, right?)?

 -dave



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




RE: Internal server error

2002-04-04 Thread David Gray

 I'm having problems with the old Internal Server Error 
 issue. I know that this is generally due to permissions. I 
 have used chmod go+rx -R *, but no joy. The html now works 
 but not the cgi. Thoughts?

Try inserting the line

use CGI::Carp (fatalsToBrowser);

At the beginning of your script. And try running it from the command
line.

Hope that helps,

 -dave



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




RE: IP Address

2002-04-04 Thread David Gray

  David == David Gray [EMAIL PROTECTED] writes:
 
  How do I get the IP address from a POST form.
  
  Let me make myself more clear: I have a form that uses POST,
  and I would like to get users' IP address for avoiding the 
  same user to fake my pool's result.
 
 David You can check $ENV{REMOTE_ADDR}, which will contain 
 the remote IP 
 David of the user hitting your page.
 
 And that's still insufficient and incorrect.
 
 Repeat after me:
 
 A user is not an IP address
 A user is not an IP address
 A user is not an IP address
 
 Specifically, the largest userbase on the planet, AOL, comes 
 into the Internet proper via Web Proxies.  On every hit, a 
 different proxy is used, so these hits show up as coming from 
 completely different addresses.  Even the main page and the 
 image fetches for that page will all show up as different 
 addresses.  And then of course, those same 
 small-number-of-proxies are used for millions of users.
 
 So again, I repeat:
 
 A user is not an IP address
 
 Get it through your head that using IP address for vote 
 blockout is just ... WRONG.

Message received, ZERO distortion. Are you saying, then, that it's
impossible to build an accessible cgi-based voting system (which allows
more than one user to access the system from within a large network)
without using cookies or forcing each user to log in?

AOL RuLeZ,

 -dave



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




RE: IP Address

2002-04-03 Thread David Gray

 How do I get the IP address from a POST form.
 
 Let me make myself more clear: I have a form that uses POST, 
 and I would like to get users' IP address for avoiding the 
 same user to fake my pool's result.

You can check $ENV{REMOTE_ADDR}, which will contain the remote IP of the
user hitting your page.

 -dave



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




RE: file handles in cgi

2002-04-03 Thread David Gray

 this is the perl script :  abc.pl(say) -- this is in my cgi-bin...
 
 #!/usr/bin/perl
 print content-type: text/html\n\n; 
 
 open (IN, abc.txt);
 $x = ($inputs{name});
 print IN $x;  
 close (IN);
 
 open (IN, abc.txt);
 @arr = IN;
 print @arr;
 close (IN);
 
 and this is the html ... abc.html(say) in the httpd/html 
 
 html
 head/head
 body
 
 form method=post action=/cgi-bin/abc.plEnter the name: 
 input type=text name=name 
 input type=submit value=click
 /form
 
 /body
 /html
 
 
  if i run the .pl from command prompt with perl abc.pl , i t 
 works fine and the abc.txt is created..now if i delete the 
 abc.txt and run the script from the browser, the abc.txt is 
 not created at all. i think there is something else that i 
 might have to configure to be able to use files in cgi...help 
 please...

You need to print html headers when you're printing to a browser, i.e.

print Content-type:text/html\n\n;

 -dave



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




RE: file handles in cgi

2002-04-03 Thread David Gray

  this is the perl script :  abc.pl(say) -- this is in my cgi-bin...
  
  #!/usr/bin/perl
  print content-type: text/html\n\n;
 
 You need to print html headers when you're printing to a browser, i.e.
 
 print Content-type:text/html\n\n;
 
  -dave

I must be blind this morning... Capitalization might matter, though
*shrug*

 -dave



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




Win32 Perl editors (was: Perl 6?)

2002-04-03 Thread David Gray

For all you win32 perl hackers, I've been using a really cool editor
called Code-Genie:
http://code-genie.com/
for about a month now, which allows customizable nested syntax
highlighting! I definitely recommend it, and I'll post my syntax
customization file if anyone's interested.

Cheers,

 -dave



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




RE: Limit floating point numbers?

2002-04-02 Thread David Gray

   I have got most everything working ok. Now I need to go back over 
   almost 2500 lines of code and fix my floating point 
 number so they 
   read 1.25 instead of 1.2556. Which should round out to 1.26
 
  What text editor are you using? Can you just do a search 
 and replace? 
  If that's not what you mean, please provide more useful information.
 
   -dave
 
 I am using Kedit that came standard with Red Hat Open Linux. 
 I have only had RD Linux 7.2 for almost 3 Months. As to the 
 previous question, I have not found the answer. In C++ one 
 would use sprintf($var, %.2f, $var2); or something like 
 that. In Perl I am not sure.

Check out perldoc -f sprintf

 -dave



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




RE: Creating variables of a string

2002-04-02 Thread David Gray

 Michael Stearman wrote:
  
  Right now it is not working and I was wondering if I sent the code 
  maybe someone with more experience with this will see the 
 problem.  I 
  am very new to this.  The line I am trying to create the variables 
  from is
  
  C6xxxSimulator(TI)  61  1
  
  and the code is
  
  $word = DATA; #Assign the next line to the $word variable chomp 
  $word; print $word\n;
  my ($target, $count, $num) = $word = ~ 
 /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/;
 
 my ($target, $count, $num) = split ' ', $word;

I think that needs to be:

my ($target,$count,$num) = split /\s+/, $word;

to handle multiple spaces between the values.

Cheers,

 -dave



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




RE: Filehandles named with a variable

2002-04-02 Thread David Gray

 So, I'm trying to 'open ($1,$file)', where $1 is a string 
 like cbQosCMPrePolicyPktOverflow.
 
 Obviously, with use strict this does not work. How can I make 
 it work? I need arbitrarily named filehandles. I know, it 
 could get rended with gobbleworts if the data gets out of hand...

Have you tried using eval, like:

eval open ($1 $file);select $1;

One caveat: you might end up using a lot of eval statements, which will
probably slow down your code.

Hope that helps,

 -dave



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




RE: Writing Dir Names into a File

2002-04-01 Thread David Gray

Good morning,

 So I have modified my script a bit and it works. However, now 
 I want to not 
 read in the . and .. directories. How can I do this?? I am having 
 problems with this part.

I usually use the following code to do this:

opendir DIR,'$mydir'
  or die couldn't open dir [$mydir]: $!\n\n;
# grep file listing
my @fl = grep { $_ ne '.' and $_ ne '..' }, readdir DIR;
closedir DIR;

Cheers,

 -dave



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




RE: html to perl vars

2002-03-29 Thread David Gray

Hi Jerry,

 How does one convert html:
 
  td width=77%input type=text name=T1 size=20/td
 
 to a Perl?
 
 $value_1 = T1;

You're going to want to look into the CGI module. (perldoc cgi)

Hope that helps,

 -dave



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




RE: Substitution: How do I say ...

2002-03-29 Thread David Gray

 er...
 s/\t(?!454354)/br/g;
  
  s/\t454354/br/g;
  
   replace every \t (tab character) which is NOT
  immediately proceeded
  by '454354' with 'br'?
  
  Thanks. I suspect this is any easy one, but I've been staring
  at it for
  an hour, and I can't figure it out. Brain not working well today.

Preceeded by the number would be

s/(?!454354)\t/br/g;

 -dave



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




RE: Resubmit?

2002-03-28 Thread David Gray

 Is it possible to have a form submit without waiting for a 
 user to click submit? All my parameters are hidden, that's why I ask.

You could meta-refresh with all the form parameters in the query string,
or maybe javascript.submit() the form, or use a lonely continue button
:)

 -dave



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




RE: counter script and chmod 755

2002-03-28 Thread David Gray

 I am putting a counter on a website for the first time. I 
 undstand that because the server is Unix that I will need to 
 se permission for the counter.
 
 I believe this can be done within the Perl script using the line:
 
 chmod (0755, counter.cgi);
 
 right within the counter.cgi script itself.
 
 Is this correct and where in the script should it be placed.

There is a much easier way to do that if you have shell access to the
server. You can type

chmod 755 counter.cgi

at the command prompt.

I'm not sure if you would be able to set the permissions from within the
script, I've never tried that. If you try all of your options and
nothing's working, please let us know what you've tried and what errors
you get.

Hope that helps,

 -dave



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




RE: remove part of a string - unterminated tags

2002-03-26 Thread David Gray

 I understand that by using:
 
 $s=~s/[^]*(?!.*?)// 
 
 the negative character class ( [^]* ) seems redundant... 
 
 But, strange, If I remove it (then we go to the one I wrote 
 on my first 
 message):
 
 $s=~s/(?!.*?)// 
 
 it only removes the last orphan  character without its content.

Oh, right :) Sorry, my mistake there.

I really don't think you need to use (?!) if what you're trying to do is
replace what you're matching. When you do that, your look-ahead
assertion ends up actually matching nothing, which is why I asked if you
understand what (?!) does... (perldoc perlre)

Cheers,

 -dave



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




RE: extraction of filenames in a string

2002-03-26 Thread David Gray

  I have a string for example:
 
  directory/subdirectory/subsubdirectory/filename.gz
  
  How do I extract the filename.gz part for testing,
  the number of subdirectories is not fixed?
 
 use File::Basename;
 
 my $file = directory/subdirectory/filename.gz;
 print basename($file);
 
 Jonathan Paton

Or you could do:

$file = $1
  if $filepath =~ /\/([^\/]*)$/;

 -dave



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




RE: Regex sub moron problem

2002-03-26 Thread David Gray

 I have a file with some settings, and I want to change some 
 of them. But when I write the file, I lose everything after a 
 certain point.
 
 Can someone point out my moronic mistake?
 Everything after ROOT = is lost but it changes ROOT = to 
 the correct value.
 
 # perl here
   $out = ;
   open(TMPL, $tree_path/$file);
   {
   local $/ = ;
   $out = TMPL;
   }
   close TMPL;
 
   open(NEW, $tree_path/$client_uc/$patch/$file);
   $out =~ s/^ROOT\s*=\s*.*?$/SUMMITROOT=$tree\/$extra/m;  
 # replace
 root line
   $out =~ s/^#(un)?def(ine)?\s+REFROOTDIR.*?$/#define REFROOTDIR
 $old$extra/m; #replace refrootdir line
   print NEW $out;
   close NEW;
   print Edited $tree_path/$file\n;
 
 __END__

When you do a multi-line match, I'm pretty sure $ matches the end of the
entire string. Try matching \n instead of $ - I think that should do it.

 -dave



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




RE: remove part of a string - unterminated tags

2002-03-25 Thread David Gray

  I have strings like the following one:
  my $s=The bL/bibraryb of font color...;
  
  I want to truncate the string, to become
  The bL/bibraryb of ...
  (that is remove 'unterminated' html tags - tags that open but
  there is no 
  '' at the end, and add ... if necessary)
  ...
  
  In an 'unterminated' tag, you would find either the end of 
 the string 
  or a '', right? How about:
  
  $s =~ s/[^]*(?:|$)//;
  
  
  Hope that helps,
  
   -dave
   
 
 Thank you for your reply,
 
 what about:
 
 $s=~s/[^]*(?!.*?)//;

Ok, well if that works, great :) do you understand what you're doing
there? (zero-width negative look-ahead assertion) You're looking for ''
followed by zero or more non-'' characters, followed by a sequence that
isn't '.*?'.

You can remove the negative character class ( [^]* ) if you want,
that's a bit redundant if you're going to use the negative look-ahead.

 -dave



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




RE: Newbie reference question

2002-03-25 Thread David Gray

 I am trying to make a two dimentional array. I have a 
 function that returns an array. The following code works:
 
 @x = f();
 push(@y, \@x);
 
 and then I can reference it @{@y[$i]}[$j};
 
 Is this the best way to make two dimentional arrays; I.e., 
 using push and reference to arrays?
 
 Also, I was wondering if I can construct the array without a 
 variable x. I tried: push(@y, \f()); push(@y, \@{f()}); The 
 second line does something but not what I intended to do.
 
 Can I make a two dimentional array without using the variable x?

Yes, you can create it by assigning something to it, i.e.

$y[0][0] = 'whatever';

Or, in a loop:

for my $o (1..20) {
  for my $i (1..5) {
$y[$o][$i] = 'whatever';
  }
}

Hope that helps a bit,

 -dave



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




RE: Printing frequency of word occurence in paragraph

2002-03-22 Thread David Gray

 In the program below I don't know when to stop the loop.
  (CTRL + d ) will just terminate the program, leaving the 
 data via STDIN unattended, this is my problem.
 
 Lets define what I want to do:
 I want to print the frequency of every word at the beginning. 
 and every word at the end of a line.
 
 This could mean two things:
 1) one line of text to be read in and on pressing enter 
 code below will analyse the input.
 2) a paragraph containing a number of lines get adressed.
 
 I think my code adress 2) but problem with this is that I 
 don't know when my coding should jump out of the loop?
 
 Any ideas
 
  #!/usr/bin/perl
  while (STDIN) {
if (/(\b[^\W_\d][\w-]+\b)/g) {
  $gotit{$1}++;
}
if (/(\b[^\W_\d][\w-]+\b\Z)/g) {
  $found{$1}++;
}
 
  }
  while (($wrd,$cnt)= each %gotit){
  print $cnt $wrd\n;
  }#end of while
 
  foreach my $yes (keys (%found)){
  print $found{$yes} $yes\n;
  }#end foreach

while(STDIN) will create an infinite loop, so you do need some sort of
sentinel value to break out of the loop if you encounter it in the user
input. For example, you could do:

while(STDIN) {
  last if /^\-1/;
  print
}

Which terminates the loop when the user enters -1 at the beginning of a
line. Or you could read from a file which would make it easier to test
for the end of input.

Hope that helps,

 -dave



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




RE: Printing frequency of word occurence in paragraph

2002-03-22 Thread David Gray

I think this is a prime example of TMTOWTDI (There's More Than One Way
To Do It) - you now have two choices for how to indicate the end of
input to your while(STDIN) loop:

1) pressing ^Z instead of ^D
2) breaking out of your loop when you see certain input indicating end
of input

 -dave

ps - I think the word 'non-obvious' is quite befuddling as well.



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




RE: how to sort, in to out

2002-03-21 Thread David Gray

 I am trying to figure out an easy way to sort out a array of numbers:
 2 20 38 56 75 93 -17 -35 -53 -72 -90
 Into the following:
 -90 -72 -53 -35 -17 2 20 38 56 75 93
 I have done the following:
   @x_step  = grep { ! $x_step_t{ $_ }  ++ } @x_step_t;
   @x_step = sort {$a == $b} @x_step;

You're really close:

@x_step = reverse sort {$a=$b} @x_step;

 -dave



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




RE: precompile regular expressions?

2002-03-21 Thread David Gray

Do you mean:

my ($c,@compiled) = ();
for(@accept) {
  $compiled[$c++] = qr/$_/;
}


? then you can loop over @compiled instead of @accept, and it should be
quite a bit faster. It sounds like that's what you're looking for. There
is a big section on compiling regular expressions in O'Reilly
Programming Perl, 3rd edition, if you have that available.

 -dave

 -Original Message-
 From: Nikola Janceski [mailto:[EMAIL PROTECTED]] 
 Sent: Thursday, March 21, 2002 1:50 PM
 To: Beginners (E-mail)
 Subject: precompile regular expressions?
 
 
 Is there a way to precompile regular expressions?
 
 I have an array of acceptable matches, and an array of items 
 to grep from. I want to avoid recompiling the regular 
 expression over and over again, for each loop.
 
 ie. (imagine these lists are much longer).
 
 @stuff = (
   Micheal,
   Marko,
   Marcy,
   Rebecca,
   Bob,
   Jancy,
   Jill,
   Jamie,
   Jack,
   );
 @accept = qw( Ja Ma );
 
 my @goodstuff;
 foreach my $item (@stuff){
   foreach my $accept (@accept){
   push @goodstuff, $accept if $item =~ /$accept/; 
  ## my problem is this might take long recompiling each time
   }
   }
 
 print @goodstuff\n;
 
 __END__
 
 # alternative is:
 foreach my $accept (@accept){
   push @goodstuff, grep /$accept/, @stuff;
   }
 # but this isn't better because in my script @accept is much 
 bigger/longer than @stuff
 
 
 Nikola Janceski
 
 Here it is my time, 
 Where there are no crimes, 
 Only I exist here, 
 And have no fear.
 -- Riddles
 
 
 --
 --
 
 The views and opinions expressed in this email message are 
 the sender's own, and do not necessarily represent the views 
 and opinions of Summit Systems Inc.
 
 
 -- 
 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]




Regex peculiarity

2002-03-21 Thread David Gray

I'm matching a list of 4 measurments (i.e. 4pc,4pc,4pc,4pc) that all
have to have some sort of unit specification (i.e. 4pc6,4in,4px,4pt) and
I'm running into a bit of an oddity...

If I use the regular expression:

/^(?:\d+\w+\d*,?){4}$/

to match the above sequence, it matches the string '10,10,10,10' or any
sequence of 4 2-digit numbers separated by commas, but not one-digit
numbers... The only thing I can think of is that the \w is matching the
commas somehow, but that doesn't make any sense...

I've been staring at this for too long, and it works the way I want it
to if I use:

/^(?:\d+\w{2}\d*,?)$/

instead, but I can't figure out what I'm doing wrong in the other
regex... Anyone have any ideas?

 -dave



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




RE: Regex peculiarity

2002-03-21 Thread David Gray

 I'm not clear on what you're trying to match for. Is it: 
 Exactly one digit, followed by exactly any two characters, 
 followed by zero or more digits?

One or more digits, followed by one or more characters, followed by zero
or more digits, followed by  zero or more commas, four times. (doesn't
match correctly)

 /^(?:\d+\w+\d*,?){4}$/

One or more digits, followed by two characters, followed by zero or more
digits, followed by zero or more commas, four times. (matches
correctly...)

 /^(?:\d+\w{2}\d*,?)$/

Should match:
10pc,10pc,10pc,10pc
4pc6,10in,12px,42pc634

Shouldn't match:
10,10,10,10 (matches on first one, but not on second one)
10pc,10pc,10,12in



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




RE: Regex peculiarity

2002-03-21 Thread David Gray

 10,10,10,10
 nope.. \d+ matches the first digit \w+ matches the second 
 digit nothing for
 \d* then ,
 
 
 try this:
 /^(?:\d+[a-z]+\d*,?){4}$/

*ack* thanks :)

\w matches alphaNUMERIC and _

Silly me.

 -dave



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




RE: Since when is $_ a read-only variable?

2002-03-20 Thread David Gray

 I'm trying to process a list like so:
  foreach (photoshare, mmc, popline, popline/www, popline/db,
 netlinks) {
  ...
  s#/#.#g;
  system($apath/analog -m +g${acfgpath}/${_}.analog.cfg
 +F$YY${MM}01 +T$YY${MM}31 +O${aout
 path}/index.html); 
   } #end for each subject area
 
 In other words, I want to 
 substitute . for / in the magic variable $_ in each foreach loop.
 
 When I try to run this, I get Modification of a read-only 
 value attempted at ./2001.analogall.pl line 81. The print 
 statement in line 80, just above the substitution statement, 
 shows the contents of $_ to be photoshare like I expected.

It's because you're looping over a temporary anonymous list. I would
guess it's stored as constant to make it more efficient. You're gonna
have to save a copy to play with, like:

foreach('photoshare','mmc') {
  ... # stuff
  my $tmp = $_;
  $tmp =~ s#/#.#g;
  system(...${tmp}.analog.cfg...);
}

Hope that makes some sense,

 -dave



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




Help on debugging

2002-03-18 Thread David Gray

Hi all,

Please don't respond directly to that last email I sent. It has an
incorrect email address on it that isn't checked that often. Please post
back to the list directly or to [EMAIL PROTECTED]

Thanks,

 -dave



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




RE: strange error message on exiting script

2002-03-18 Thread David Gray

 I am receiving a strange error on exiting a script: Attempt 
 to free unreferenced scalar during global destruction.  It 
 only occurs after I make a DBI connection and run an SQL 
 statement.  I am undefing the statement handle and 
 disconnecting the database handle.  Does anyone have a clue 
 what this might be?

My guess is that because you're undef-ing $sth instead of just doing
$sth-finish(), the destructor for whatever package $sth belongs to is
getting mad when the object it's trying to clean up isn't there. I'm
pretty sure this has been suggested already, but why can't you let $sth
go out of scope (or force it to)?

 -dave



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




RE: Bit reversal of MAC Address bytes...

2002-03-18 Thread David Gray

   1. How do I brake the MAC Address up into bytes?

I'm not exactly sure what format you're getting the MAC address in, but
it looks like you're just splitting it into two-character chunks... To
split that, you could do:

my $c = 0;
while($mac =~ /(.{2})/g){
  $mac[$c++] = $1;
}

   2. How to convert to binary and put it in a variable?  I think I
   have seen sprintf to convert, but how to get that into the var...

perldoc perlfunc | grep binmode

   3. Then how to convert back to hex?

To convert to hex, you can use the aptly named hex() function, and check
out perldoc -f sprintf using the %d option to convert to decimal (or %x
to hexadecimal).

Hope that helped a bit, please provide more specific info if I'm
misunderstanding your questions.

 -dave



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




RE: Parsing CGI data to another page...

2002-03-15 Thread David Gray

 Just wondering how I would go about having this URL
 www.mydomain.com/cgi-bin/test.cgi?data=test
 
 Would be parsed to...
 
 www.mydomain.com/cgi-bin/test2.cgi
 
 From test2.cgi I would like to be able to read that data = test from
test.cgi.

In test.cgi, do the following

=code
use CGI;
my $cgi = new CGI;
my ($domain,$script,$c) = ($cgi-server_name,'/cgi-bin/test2.cgi',0);
my $url = 'http://$domain$script?';
for($cgi-param()) {
  # this if won't be run the first time through the loop
  if($c++) { $url .= ''; }
  $url .= $_.'='.$cgi-param($_);
}

print Location:$url\n\n;
=code

It loops over all of the variables passed to your script and re-creates
the query string, then passes it to your new script.

 -dave



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




  1   2   >