Re: Pop-up window

2001-06-08 Thread Aaron Craig

The answer would be completely off topic here, since it's a JavaScript 
question -- try subscribing to [EMAIL PROTECTED]


At 17:43 07.06.2001 -0700, you wrote:
>Hi,
>
>Any pointers on how to best create a pop-up window with some selection
>(radiobuttons) in it and then get the result back and deal with them.
>
>
>Im familiar with javascript's window.open and the POST-ing of a form,
>but I don't know how to get my form in the newly opened window (basically
>how to exchange the data).
>
>Thanks,
>Philip
>
>___
>To get your own FREE ZDNet Onebox - FREE voicemail, email, and fax,
>all in one place - sign up today at http://www.zdnetonebox.com

Aaron Craig
Programming
iSoftitler.com




RE: the ENV command? parameter?

2001-06-08 Thread Aaron Craig

At 12:13 07.06.2001 -0400, you wrote:
>Progress!! now I understand what the 'QUERY_STRING' is!
>
>and a little
>
>foreach(@key = keys(%ENV))
>{
> print "$_: $ENV{$_}\n";
>}
except you should write

foreach(keys %ENV)
 {
 print ...
 }

or
foreach my $key (keys %ENV)
 {
 print "$key: $ENV{$key}";
 }

or, my favorite

print "$_ => $ENV{$_}\n" foreach keys %ENV;


Aaron Craig
Programming
iSoftitler.com




Re: [META] Rants (was:Re: space)

2001-06-08 Thread Aaron Craig

At 10:33 08.06.2001 -0400, you wrote:
>On Thu, Jun 07, 2001 at 10:55:28PM -0500, Karen Cravens wrote:
> > On 7 Jun 2001, at 19:49, Mark S wrote:
> >
> > > Please reply to the list for the benefit of others.
> >
> > Is there a standard rant about lists that don't use a reply-to, or do I
> > have to write my own?
> >
>
>Nah. Just get a Mail UA that knows how to handle lists. I'm personally
>on the "List Manager Setting Reply-To Considered Harmful" side of that
>argument. If you use a decent MUA, you can tell it to do list replies
>("L" in mutt, for example) and tell it in the configuration what lists
>you're subscribed to. That leaves the Reply-To field avaiable for
>individual posters to set when appropriate without it being stomped on
>by the list manager.

I've got to take issue with this.  I use Eudora, which for just about 
everything else is a nice program.  Though it's not 100% free of problems 
and bugs -- it does not have any options for handling lists -- I don't 
think I should be forced to switch mail clients just so that I can avoid 
copying and pasting the list address into my reply every time.  As a side 
note, perl-beginners and beginners-cgi are the *only* two lists of the many 
lists I'm subscribed to that don't automatically set the reply-to to the 
list address.  Since 99% of the time one responds a mail from the list, the 
response is meant for the list as a whole, I think the labor of changing 
the recipient should go to the few times you want to respond to one 
person.  Am I the only one that replies mostly to the list?



Aaron Craig
Programming
iSoftitler.com




RE: the ENV command? parameter?

2001-06-08 Thread Aaron Craig

At 11:15 08.06.2001 -0400, you wrote:
>I am totally lost on this one. What is the difference?
> >
> >foreach(@key = keys(%ENV))
> >{
> > print "$_: $ENV{$_}\n";
> >}
>except you should write
>
>foreach(keys %ENV)
>  {
>  print ...
>  }

The @key = keys(%ENV)) is extraneous -- keys %ENV already gives you a list, 
and since you're only interested in it for the scope of the foreach 
statement (at least in this example) there's no need to set the list to a 
variable -- besides which, your @key array would die outside of the foreach 
loop anyway -- if you're using strict, which you should be :)

Aaron Craig
Programming
iSoftitler.com




Re: [META] Rants (was:Re: space)

2001-06-11 Thread Aaron Craig

At 19:18 08.06.2001 -0700, Peter Scott wrote:

>I use Eudora also, and it works just fine.  To reply to the person who 
>sent the message, I hit Reply.  To reply to that person and the list, I 
>hit Reply To All.  To reply to just the list and not the sender would be 
>rude, but if I wanted to do it, I'd do Reply To All and delete their name 
>from the To: line.

Good move -- I hadn't tried reply to all.
Aaron Craig
Programming
iSoftitler.com




Re: [META] Rants (was:Re: space)

2001-06-11 Thread Aaron Craig

At 19:18 08.06.2001 -0700, Peter Scott wrote:

>I use Eudora also, and it works just fine.  To reply to the person who 
>sent the message, I hit Reply.  To reply to that person and the list, I 
>hit Reply To All.  To reply to just the list and not the sender would be 
>rude, but if I wanted to do it, I'd do Reply To All and delete their name 
>from the To: line.


Except I always get two copies of every message in this way -- one from the 
sender and one from the list :)

Aaron Craig
Programming
iSoftitler.com




Re: [META] Rants (was:Re: space)

2001-06-11 Thread Aaron Craig

At 19:48 08.06.2001 -0700, Peter Scott wrote:

>>Saves on bandwidth, and doesn't
>>fill up a users mailbox with duplicate messages.  I personaly hate
>>checking my email to find it filled with messages that should have
>>been sent into the folders for that mailing list.
>
>Mine all get sent to the same folder, because I have a filter that says 
>they go there if To: contains [EMAIL PROTECTED] OR Cc: contains 
>[EMAIL PROTECTED]


But I still have to download two messages for every one -- I just got done 
downloading 200 some odd messages, of which a portion are unnecessary 
duplicates.

Aaron Craig
Programming
iSoftitler.com




Re: [META] Rants (was:Re: space)

2001-06-11 Thread Aaron Craig


>At 23:24 08.06.2001 -0500, you wrote:
>
>If you don't know how to manage your mail or aren't willing to learn then
>you probably don't have any business joining a mailing list and then
>whining about it on the list.



Doesn't this run dangerously close to an elitist attitude that we of the 
Perl community are trying to rid ourselves of?  I don't think the fact that 
many email clients have advanced filtering features means that a list 
should force you to discover what all of them are.  As has been said here 
by others, of all the lists I'm subscribed to, this is the only one 
configured in this way.
Aaron Craig
Programming
iSoftitler.com




Re: [META] Rants (was:Re: space)

2001-06-11 Thread Aaron Craig

At 01:22 11.06.2001 -0800, you wrote:

>If the reply issue is really difficult for new users to deal with, why is it
>everyone who is complaining about it has already found a workaround?

My whole issue with the thing is that we've been forced to find a 
workaround.  If one of the goals of good programming is to do away with 
unnecessary bullox, then shouldn't this list, as an example to beginning 
programmers, be configured *better* then the other lists out there?  If 
none of us that know how to program decently would ever write code that 
required users to find workarounds, why does the list get sent in such a 
way that in order to reply to the list we have to come up with a workaround?

I agree that this thread probably isn't the most pressing issue facing the 
Perl community today, but it does bring up one of my pet peeves about the 
programming world, which is where the elitist issue came up.  I agree with 
you that there should be levels of distinction between programmers -- 
someone who doesn't have the knowledge to understand what's going on in a 
conversation should keep their mouth shut and listen, and not clutter up 
the conversation with basic questions that would be better asked 
elsewhere.  This isn't elitism, this is organization.

Perhaps elitism isn't even the correct word.  It just seems to me that we, 
being techy people, often get into a techy frame of mind, which lead us to 
setting things up in a way that causes us to push more buttons, just so 
that we do it differently from the rest of the world.  I'm sure that's not 
the situation with this list, but the reply-to conversation brought the 
tech issue to mind, and perhaps that's why I joined in the fray in the 
first place.

I didn't mean to write a book :)

Aaron Craig
Programming
iSoftitler.com




Re: checking for the @ symbol

2001-06-12 Thread Aaron Craig

At 09:29 12.06.2001 -0500, you wrote:

>i am printing to the file currently via:
>
>   open(FILE, ">>$filename");
> print FILE "$add_alias\@$domain\t$add_destination\n";
>   close(FILE);
>
>so i am appending the appropriate domain to the new alias they are
>entering. overall, i want to ensure that $add_alias is composed
>strictly of a-z,A-Z,0-9,.,- and _ and nothing else.

then it doesn't sound like you're worried about finding a '@', it sounds 
like you're worried about finding anything that is not A-Za-z0-9\.\-_ which 
fits nicely into the following regular expression

print "You're cheating!" if($add_alias =~ /[^A-Za-z0-9\.\-_]/g);

or even more concise

print "You're cheating!" if($add_alias =~ /[^\w\.\-]/g);  # \w Match a 
"word" character (alphanumeric plus "_")



Aaron Craig
Programming
iSoftitler.com




Re: use of split command

2001-06-12 Thread Aaron Craig

I don't imagine you pick up all that much extra speed by reading the whole 
file into an array first (anyone?).

I would do something like

open(ACCS, "Accession.txt") || die "blah";
my %values;
while()
 {
 chomp $_;
 my($col1, $col2) = split(/\t/, $_); # you better be sure that 
there are only two cols or you'll lose data this way --
 #either add error checking or 
throw it all into an array and then grab the values you want
 # then, since you have two cols, you probably want to do something 
like throw the thing into a hash
 $values{$col1} = $col2;
 # though you may want to do something totally different :)
 }
close ACCS
print "$_ => $values{$_}\n" foreach keys %values;

At 15:58 12.06.2001 +0100, you wrote:
>I am trying to read a quite large file (ca 13000 lines) directly into an
>array (for speed)
>like this
>
>open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
>open Accessions file";
>@ets=;
>$ets_count=@ets;
>
>the actual data is a 2 column tab delimited file like:
>
>  <<...OLE_Obj...>>
>etc
>I have been looking at the directions on using the split command in the
>"Perl -in a nutshell book", but really can't figure out how to split the
>@ets array into 2 separate arrays (say--@etsOrig + @etsRefSeq). I feel this
>is probably simple but err...not to me.
>
>Alternatively if you can tell me how to reference just the second part of
>the line  in a loop like e.g.
>for($i=0; $i < $ets_count; $i++)
>{
>seq->some_function_of(the second column of @ets[$i}
>}
>
>maybe that would be quicker???

Aaron Craig
Programming
iSoftitler.com




Re: checking for the @ symbol

2001-06-12 Thread Aaron Craig

At 11:50 12.06.2001 -0400, Chas Owens wrote:

>\w includes _.  The \w character set is anything that can be included
>in a variable name.  On the topic of shortening the regexp: "." in a
>character class does not need to be escaped so you can write it like
>this
>
>  print "You're cheating!" if($add_alias =~ /[^\w.\-]/);


thanks for pointing that out!
Aaron Craig
Programming
iSoftitler.com




references for making regexes go faster

2001-06-15 Thread Aaron Craig

references for making regexes go faster

I saw this mentioned in another post.  Care to elaborate anyone?
Aaron Craig
Programming
iSoftitler.com




Utf8 and length()

2001-06-15 Thread Aaron Craig

Using Utf8:

use Utf8;

If I have some text:

my $text = "abcdefghiæ"; # note the æ

and I convert it to a fake Unicode string (fake, because you couldn't do 
this with real Unicode charsets like Chinese) by sticking nulls in between 
letters:

sub AnsiToUnicode($$)
   {
   my ($sAnsi) = @_;
   my $lLength = length($sAnsi);
   my $sUnicode = "";
   for(my $i = 0; $i < $lLength; $i++)
 {
 $sUnicode .= substr $sAnsi, $i, 1;
 $sUnicode .= "\0";
 }
   return $sUnicode;
   }

my $uni_text = AnsiToUnicode($text);

Then, I convert it to Utf8 ( I know, why not go straight from ansi to 
utf8?, it's a long story -- basically, we work in Unicode here, so I've 
never had to go from ansi to utf8, but for the sake of the question, let's 
do it this way)

sub UnicodeToUtf8($$$)
{
my($bIsBigEndian, $sText) = @_;
my $sReturn = "";
my $lLength = length($sText);
for(my $i = 0; $i < $lLength; $i += 2)
{
my $sChar = substr($sText, $i, 2);
my $lByte1;
my $lByte2;
if($bIsBigEndian == 0)
{
$lByte1 = ord(substr($sChar, 1, 1));
$lByte2 = ord(substr($sChar, 0, 1));
}
else
{
$lByte1 = ord(substr($sChar, 0, 1));
$lByte2 = ord(substr($sChar, 1, 1));
}
my $lUni = ($lByte1 * 0x100) + $lByte2;
  if ($lUni < 0x80)
{
$sReturn .=  chr($lUni);
}
elsif ($lUni < 0x800)
{
$sReturn .= chr(0xc0 | $lUni >> 6);
$sReturn .= chr(0x80 | $lUni & 0x3f);
}
elsif ($lUni < 0x1)
{
$sReturn .= chr(0xe0 | $lUni >> 12);
$sReturn .= chr(0x80 | $lUni >> 6 & 0x3f);
$sReturn .= chr(0x80 | $lUni & 0x3f);
}
elsif ($lUni < 0x20)
{
$sReturn .= chr(0xf0 | $lUni >> 18);
$sReturn .= chr(0x80 | $lUni >> 12 & 0x3f);
$sReturn .= chr(0x80 | $lUni >> 6 & 0x3f);
$sReturn .= chr(0x80 | $lUni & 0x3f);
}
}
return $sReturn;
}

my $utf8_text = UnicodeToUtf8(0, $uni_text); # false BigEndian parameter 
since I'm on Win2000

now, we finally get to the heart of the problem.

print $utf8_text; # produces abcdefghiæ

that is, two characters for the æ character in the string.  This is due, 
I'm assuming, to weirdness with the Utf8 pragma.  The problem is this -

print length($utf8_text) . "\n"; # 11 !

Anyone have any experience with this?  I've checked the utf8 manpage, but 
they gloss over length(), including it in a list of functions that should 
continue to operate on characters, not bytes.  In fact, this is the problem 
-- utf8 seems to consider æ two characters.

Thanks in advance
Aaron Craig
Programming
iSoftitler.com




Re: combining lines in a tagged text file

2001-06-19 Thread Aaron Craig

Try this.

* warning * assumes all your input files will look like your example -- ie 
a bunch of text to copy directly over to the output file followed by a 
chunk of 's followed by more stuff to copy

__start code__

 open(IN, "in.txt") || die("Could not open file $!");
 open(OUT, "out.txt") || die("Could not open file $!");
 my $sBefore = "";
 my $sAfter = "";
 my $rhLnks = {};
 while()
 {
 chomp($_);
 if($_ !~ /([^<]+)]+)>([^<]+)/)
 {
 $sBefore .= "$_\n" if(scalar(keys %{ $rhLnks }) < 1);
 $sAfter .= "$_\n" if(scalar(keys %{ $rhLnks }) < 1);
 next;
 }
 my $by = $1;
 my $param = $2;
 my $content = $3;
 $by =~ s/\s+by\s+//;
 print "content: $content\n";
 if(exists $rhLnks->{$content})
 {
 $rhLnks->{$content}->{by} .= " and $by";
 }
 else
 {
 $rhLnks->{$content} =
 {
 by  => "$by",
 param   => "$param",
 };
 }
 }
 print OUT $sBefore;
 print OUT "$rhLnks->{$_}->{by} by 
{$_}->{param}>$_\n" foreach (keys %{ $rhLnks });
 print OUT $sAfter;
 close IN;
 close OUT;

__end code__

At 08:40 18.06.2001 -0400, [EMAIL PROTECTED] wrote:
>Input example:
>
>!EC
>1999 TNT 230-4
>!CU
>Administrative Rulings
>!CU
>Administrative Rulings
>!CS
>IRS Revenue Rulings
>!DN
>Doc 1999-37669 (3 original original pages)
>!TS  #each of the following pairs should be combined because the strings match
>Modified by Rev. Rul. 2000-4
>Amplified by Rev. Rul. 2000-4
>Superseded by Rev. Rul. 2000-56
>Supplemented by Rev. Rul. 2000-56
>!GI
>United States
>!IA
>Internal Revenue Service
>!DP
>30 Nov 1999
>!PD
>01 Dec 1999
>. . .
>=
>
>Output example:
>
>!EC
>1999 TNT 230-4
>!CU
>Administrative Rulings
>!CU
>Administrative Rulings
>!CS
>IRS Revenue Rulings
>!DN
>Doc 1999-37669 (3 original original pages)
>!TS  #notice that the first of the two lines remain, and the second is 
>properly
>removed
>  #the lines are also combined as I want them. The 'old' and 'new' 
> tags are
>for my viewing
>old Modified by Rev. Rul. 2000-4
>new Modified and Amplified by Rev. Rul. 2000-4
>old Superseded by Rev. Rul. 2000-56
>new Superseded and Supplemented by Rev. Rul.
>2000-56
>!GI
>United States
>!IA
>Internal Revenue Service
>!DP
>30 Nov 1999
>!PD
>01 Dec 1999
>. . .

Aaron Craig
Programming
iSoftitler.com




Re: combining lines in a tagged text file

2001-06-19 Thread Aaron Craig

Try this.

* warning * assumes all your input files will look like your example -- ie 
a bunch of text to copy directly over to the output file followed by a 
chunk of 's followed by more stuff to copy

__start code__

 open(IN, "in.txt") || die("Could not open file $!");
 open(OUT, "out.txt") || die("Could not open file $!");
 my $sBefore = "";
 my $sAfter = "";
 my $rhLnks = {};
 while()
 {
 chomp($_);
 if($_ !~ /([^<]+)]+)>([^<]+)/)
 {
 $sBefore .= "$_\n" if(scalar(keys %{ $rhLnks }) < 1);
 $sAfter .= "$_\n" if(scalar(keys %{ $rhLnks }) < 1);
 next;
 }
 my $by = $1;
 my $param = $2;
 my $content = $3;
 $by =~ s/\s+by\s+//;
 print "content: $content\n";
 if(exists $rhLnks->{$content})
 {
 $rhLnks->{$content}->{by} .= " and $by";
 }
 else
 {
 $rhLnks->{$content} =
 {
 by  => "$by",
 param   => "$param",
 };
 }
 }
 print OUT $sBefore;
 print OUT "$rhLnks->{$_}->{by} by 
{$_}->{param}>$_\n" foreach (keys %{ $rhLnks });
 print OUT $sAfter;
 close IN;
 close OUT;

__end code__

At 08:40 18.06.2001 -0400, [EMAIL PROTECTED] wrote:
>Input example:
>
>!EC
>1999 TNT 230-4
>!CU
>Administrative Rulings
>!CU
>Administrative Rulings
>!CS
>IRS Revenue Rulings
>!DN
>Doc 1999-37669 (3 original original pages)
>!TS  #each of the following pairs should be combined because the strings match
>Modified by Rev. Rul. 2000-4
>Amplified by Rev. Rul. 2000-4
>Superseded by Rev. Rul. 2000-56
>Supplemented by Rev. Rul. 2000-56
>!GI
>United States
>!IA
>Internal Revenue Service
>!DP
>30 Nov 1999
>!PD
>01 Dec 1999
>. . .
>=
>
>Output example:
>
>!EC
>1999 TNT 230-4
>!CU
>Administrative Rulings
>!CU
>Administrative Rulings
>!CS
>IRS Revenue Rulings
>!DN
>Doc 1999-37669 (3 original original pages)
>!TS  #notice that the first of the two lines remain, and the second is 
>properly
>removed
>  #the lines are also combined as I want them. The 'old' and 'new' 
> tags are
>for my viewing
>old Modified by Rev. Rul. 2000-4
>new Modified and Amplified by Rev. Rul. 2000-4
>old Superseded by Rev. Rul. 2000-56
>new Superseded and Supplemented by Rev. Rul.
>2000-56
>!GI
>United States
>!IA
>Internal Revenue Service
>!DP
>30 Nov 1999
>!PD
>01 Dec 1999
>. . .

Aaron Craig
Programming
iSoftitler.com




RE: PERL PROGRAM HELP!

2001-06-21 Thread Aaron Craig

At 11:35 20.06.2001 +0100, Govinderjit Dhinsa wrote:
>Iv been givin this program to modify, but I can not astblish what some parts
>of the program are doing.   From
>
>printf
>to
>}
>
>Can any body help please and run through it with me pls!
>
>
>
>open iscd,"<$ARGV[0]" or die "Cannot open $ARGV[0]",$!;

this opens a file that's been typed in at the command line

>open sortcode,">$ARGV[1]";

this opens the second file that's been typed in at the command line

>while($line=){
> chomp $line;
> @fields=split "\t",$line;

this grabs one line at a time from the first file and splits it out into an 
array -- the line is apparently a tab delimited list

> printf sortcode
>"\n%6.6s%8.8s%3.3s%27.27s%20.20s%35.35s%35.35s%10.10s%1.1s%1.1s%2.2s%2.2s%2.
>2s%2.2s%2.2s%2.2s%2.2s%2.2s%2.2s%2.2s%1.1s%1.1s%6.6s%35.35s%4.4s%4.4s%10.10s
>%8.8s",
>
>$fields[0],$fields[1],$fields[2],$fields[4],$fields[5],$fields[6],$fields[7]
>,$fields[11],$fields[14],$fields[25],
>
>$fields[26],$fields[27],$fields[28],$fields[29],$fields[30],$fields[31],$fie
>lds[32],$fields[33],
>
>$fields[34],$fields[35],$fields[58],$fields[60],$fields[61],$fields[64],
>$fields[76],$fields[77],$fields[78],$fields[79];
>}

this formats the data from the line and prints it out to the second 
file.  There's probably a cleaner and easier-to-read way to do 
this.  However, if you look at the docs for printf, and compare the input 
and output files you should be able to figure out exactly how the lines are 
getting formatted and printed.

Aaron Craig
Programming
iSoftitler.com




Re: Recursive subrutines

2001-06-21 Thread Aaron Craig

At 10:54 20.06.2001 +0200, Dalløkken, Espen wrote:
>I'm trying to wirte a recursive subroutine that recives an array, does some
>processing and then calls itself with a new array.
>The problem is that I never get to retrive the array after the subroutine
>has ran once. When it runs the second time it doesn't get the correct set of
>items in the passed in array.
>So I'm wondering if I'm calling the subroutine in the wrong way, or if I'm
>retriving the parameters incorrectly.
>
>---
>&buildBranch(@someNodes);

You don't have to use & anymore.  I'd call your routines like this:
buildBranch(@someNodes);
also, you probably want to get into the habit of passing references to 
structures instead of the structure itself.  That means you don't have to 
return the structure if you change it inside your function, and it's faster 
because you're not making copies of structures all over the place.

That said:

buildBranch(\@someNodes);  # \@ passes a reference to the array, not a copy 
of the array.  changes made inside buildBranch() will effect @someNodes.

sub buildBranch($) # I know that prototyping is controversial, so maybe 
we'll get a good thread going out of this sub declaration
 {
 my($raNodes) = @_; # if you're not using strict, the gods of Perl 
will grumble -- and besides, it's better.
 foreach my $node (@{ $raNodes }) # I'm changing your variable name 
to something a little more descriptive
 {
 if($node->getTagName() eq "branch") # could this just be a 
property of node? like $node->{TagName} ?  just an idea
 {
 # fetch parameters from the XML file
 ... # this looks cool
 CreateBranch();
 # no reason to right the same code twice, so we'll 
move the child nodes stuff outside the if
 }
 my $raChildNodes = $node->GetChildNodes(); # you'll have 
to change GetChildNodes() to return an array ref instead of an array
 buildBranch($raChildNodes) if(scalar(@{ $raChildNodes }) > 
0); # as long as GetChildNodes() returns a proper array of child nodes, it 
should work as is.  what specific errors are you getting?
 }
 }

>sub buildBranch()
>{
> @numNodes = @_;
> foreach $item (@numNodes)
> {
> # if the node is a branch tag, create branch
> if ($item->getTagName() eq "branch")
> {
> # fetch parameters from the XML file
> $branchName = $item->getAttribute("name");
> $vpath = $item->getAttribute("vpath");
> $comment = $item->getAttribute("comment");
> $edition = $item->getAttribute("edition");
> $owner = $item->getAttribute("owner");
> $groupForSharing =
>$item->getAttribute("groupForSharing");
>
> &createBranch();
> @childBRNodes = $item->getChildNodes();
> if (scalar(@childBRNodes) > 0)
> {
>         &buildBranch(@childBRNodes);
> }
> }
> @childNodes = $item->getChildNodes();
> if (scalar(@childNodes) > 0)
> {
> &buildBranch(@childNodes);
> }
> }
>}

Aaron Craig
Programming
iSoftitler.com




Re: compilation errors in win98

2001-06-21 Thread Aaron Craig

At 21:49 20.06.2001 +0100, james crease wrote:
>I have a perl script which generates many compilation errors which scroll 
>off the DOS window perl is running in. How do I capture (or recover) the 
>lines that have scrolled away?
>--
>james crease
>

Use EditPlus2 as your editor.  You can capture perl output in an output 
window inside the program, copy and paste it, as well as double click a 
line number and get taken directly to that line in your code, among many 
other helpful features.

www.editplus.com

It's shareware that doesn't expire, though the program is really worth the 
35 bucks.
Aaron Craig
Programming
iSoftitler.com




Re: compilation errors in win98

2001-06-22 Thread Aaron Craig

At 09:55 22.06.2001 +0100, james crease wrote:
>I still think it odd that the distribution of Perl for Windows doesn't 
>mention this problem when using the standard M$ command window.

The problem disappears with Win2000, fwiw.

Aaron Craig
Programming
iSoftitler.com




Re: output in specified order

2001-06-22 Thread Aaron Craig

At the risk of being over simplistic, can you just add a number_ to the 
front of your hash key?

my $rhHash =
 {
 '4_B' => "Fourth element",
 '2_A' => "Second element",
 '1_D' => "First element",
 '3_F' => "Third element",
 };

print "$rhHash->{$_}\n" foreach sort(keys %{ $rhHash });

At 15:01 21.06.2001 -0400, Yacketta, Ronald wrote:
>Folks,
>
>I have a the following hash that _MUST_ be outputed in a specified order
>every time.
>
>hash:
>
>my %lookFor = (
> "ORA-"=>  "ORACLE errors   (various
>Oracle errors)",
> "Fault 2-001" =>  "Host/server down or
>unresponsive",
> "Fault 2-002" =>  "no orbix daemon or
>unresponsive",
> "Fault 2-003" =>  "Can not bind to
>Authorization Object (ACF2/Message Broker)",
> "Fault 2-004" =>  "Can not bind to Contract
>Object (CMS/Get Q/Message Broker)",
> "Fault 2-005" =>  "Can not bind to Order
>Object (Order Submit/Message Broker)",
> "Fault 2-006" =>  "Authorization Object
>fault (ACF2/Message Broker)",
> "Fault 2-007" =>  "Contract Object fault
>(CMS/Get Q/Message Broker)",
> "Fault 2-008" =>  "Order Object fault (Order
>Submit/Message Broker)",
> "Fault 2-009" =>  "CHI 3270 session fault
>(Customer Information/TRG)",
> "Fault 2-010" =>  "CAPS 3270 session fault
>(Trade-in Information/TRG)",
> "Fault 2-011" =>  "Sale Range 3270 session
>fault (Negotiated Credit Info/TRG)",
> "Fault 2-012" =>  "Oracle DBMS offline",
> "Fault 2-013" =>  "Oracle DBMS is out of
>critical resource",
> "Fault 2-015" =>  "Factory Server failed to
>start Session Server",
> "Fault 2-016" =>  "CAPS Broker failure
>(Serial, Order Information/TRG)",
> "Fault 2-017" =>  "CAPS Broker fault
>(Serial, Order Information/TRG)",
> "Fault 2-018" =>  "Pooling Broker failure
>(Pooling Information/TRG)",
> "Fault 2-019" =>  "Pooling Broker fault
>(Pooling Information/TRG)",
> "\\w+Bin\\w+Factory"  =>  "Bind to Factory failure",
> "SystemError" =>  "SystemError",
> "SystemException" =>  "SystemException",
> "\\w+Communication\\w+failure"=>  "Communication failure",
> "\\w+ORBA"=>  "ORB problem",
> "Get Q Error" =>  "(Message Broker).",
> "Test App Finished"   =>  "Number of clients
>Finished"
>);
>
>
>the order
>
>print SFN "Date/Time Stamp,ORA-1: unique constraint violation,";
>print SFN"Fault 2-001,Fault 2-002,Fault 2-003,Fault 2-004,Fault 2-005,";
>print SFN "Fault 2-006,Fault 2-007,Fault 2-008,Fault 2-009,Fault 2-010,";
>print SFN "Fault 2-011,Fault 2-012,Fault 2-013,Fault 2-015,";
>print SFN "Bind to Factory Failure,SystemException,Communication failure,";
>print SFN "ORB problem,Get Q Error,# of clients still running,";
>print SFN "# of PricingSessions still running,# of clients Finished Test,";
>print SFN "smtx / syscl,user %,sys %,wt %,idl %,current load average\n";
>
>seeing that this is a hash, there is absolutely no guarantee that the output
>will be
>correct when it is printed. I could sort the hash, but the order is still
>wrong.
>
>any suggestions?
>
>Regards,
>Ron
>
>P.S
>don't be to critical of the print's above, yes there are a few extra
>elements in it.
>Those are generated outside the hash and can be plopped into the output
>where need be. I am
>mainly concerned with the proper output of the hash in the order
>specified

Aaron Craig
Programming
iSoftitler.com




Komodo

2001-06-22 Thread Aaron Craig

Has anyone tried the Komodo development environment from ActiveState?  Must 
you have ActiveState perl in order to make it work?  I've just downloaded 
and installed it.  I'm using my own build of perl, not ActiveState, and 
none of the debugging features (breakpoints, etc.) work.  Any ideas?
Aaron Craig
Programming
iSoftitler.com




RE: Komodo

2001-06-22 Thread Aaron Craig

At 06:46 22.06.2001 -0500, Steve Howard wrote:
>Komodo's beta's work OK, but they don't always recognize common PERL syntax
>like opening a file. The previous Beta did work OK with debugging, etc, but
>the current version does not. Actually, the previous version was tolerable,
>but the current version is a definite step backwards. Any version is large,
>and slow.
>
>Steve Howard

Thanks.  I figured as much.  Unfortunately, I continue to be underwhelmed 
by Mozilla products.  We're still a long way from driving a stake through 
the heart of the M$ beast.

Has anyone come out with a working environment for perl.  print "my error 
message" and print "my variable value" is great, but I'd love to be able to 
step through a perl script and watch my variables as I go.
Aaron Craig
Programming
iSoftitler.com




Re: 2 regex questions

2001-06-22 Thread Aaron Craig

At 09:49 22.06.2001 -0400, Yacketta, Ronald wrote:
>Folks,
>
>Is this syntax correct for finding multiple words in a line?
> $results{$test}++ if /$test/ && /Factory/ && /failed/;

Looks good.

>also, what would the syntax be to find a word in a line that does
>not contain another word? something similar to
> grep joe output | grep -v fred

$results{$test}++ if($_ =~ /joe/ && $_ !~ /fred/);
Aaron Craig
Programming
iSoftitler.com




Re: 2 regex questions

2001-06-25 Thread Aaron Craig

At 08:14 22.06.2001 -0800, Michael Fowler wrote:
>On Fri, Jun 22, 2001 at 04:26:43PM +0200, Aaron Craig wrote:
> > $results{$test}++ if($_ =~ /joe/ && $_ !~ /fred/);
>
>Or, more succinctly:
>
> $results{$test}++ if /joe/ && !/fred/;

I'm still trying to get my brain used to Perlese.  :)
Aaron Craig
Programming
iSoftitler.com




Re: I need some help ...

2001-06-25 Thread Aaron Craig

I would do something like this:

use strict; # very important, and saves a lot of headache!

open (SERV, "c:\\perl\\bin\\liste.txt") || die "Could not open liste.txt: 
$!"; # added error checking
my @serveurs = ;
close (SERV);
open (RESULT, ">>c:\\resultat.txt") || die "Could not open resultat.txt: 
$!"; # added error checking;
foreach my $ligne (@serveurs)
{
my @fichiers =
(
"$ligne\\f\$\\cmd\\active.vbs",
"$ligne\\f\$\\universe\\data\\exp\\upr\\upe_dsms.000",
"$ligne\\f\$\\universe\\data\\exp\\upr\\upe_psms.000",
"$ligne\\g\$\\common\\bin\\upecbootnt.cmd",
);
# this loop does exactly what you were doing before, but is a little less 
verbose, and easier to maintain.
#Remember, when you catch yourself copying and pasting code, it's probably 
time for a loop or a function.
#I've taken the four files that you want to check, and stuck them in the 
array above.
#Now we'll loop through the array and check each file.
#Want to check another file in the future?  Add it to the array, and 
you're done!
foreach my $fichier (@fichiers)
{
my $result = (-e $fichier)? "$fichier fait (stat $fichier)[7] 
octets\n" : 
"$fichier inexistant \n";
print RESULT $result;
}
 }
close RESULT;
Aaron Craig
Programming
iSoftitler.com




Re: Opening a file, but adding the date to the name

2001-06-25 Thread Aaron Craig

At 15:33 24.06.2001 -0500, Tim Grossner wrote:
>I want to open a file:
>
>open (CONFIG, ">/tftpboot/$_");
>chmod (0777, "/tftpboot/$_");
>
>but i want to make the filename be $_."the current date"
>
>the localtime function doesnt look very promising, as the output is not
>very human readable :-)
>
>Any thoughts?

I actually prefer to keep the time format in the number format returned by 
time(), until I need to render it human readable -- especially for things 
like file names.  Numbers are typically safer to hand around than strings, 
and a file name composed of numbers is always guaranteed to be legal, while 
a string may contain characters that aren't allowed in file names by the 
operating system.
Aaron Craig
Programming
iSoftitler.com




Re: /g

2001-06-25 Thread Aaron Craig


>On Jun 25, Sally said:
>
> >when evaluating strings what exactly does /g do at the end of a lot of
> >evaluation expressions eg:
> >
> >$string =~ /(.)/g

my $string = "abcd a bcd ab cd";
$string =~ /a/; # finds the first "a" - the a in 'abcd'

$string =~ /a/g; # finds all "a"'s in the string

The second example is mostly useful if you want to find out how many times 
a pattern is repeated in a string:
my $lCount = () = $string =~ /a/g; # $lCount now equals how many times the 
string matched, in this case 3

of if you want an array of all the substrings that are the matches:
my @asMatches = $string =~ /a/g; # @asMatches is now an array containing 3 
elements, each of which is equal to "a"


Aaron Craig
Programming
iSoftitler.com




Re: I need some help ...

2001-06-25 Thread Aaron Craig

At 11:43 25.06.2001 +0200, [EMAIL PROTECTED] wrote:
>En réponse à Aaron Craig <[EMAIL PROTECTED]>:
>
> >   foreach my $fichier (@fichiers)
> >   {
> >   my $result = (-e $fichier)? "$fichier fait (stat $fichier)[7]
> > octets\n" :
> > "$fichier inexistant \n";
> >   print RESULT $result;
> >   }

>  It's still not checking the size .. :-(
>
>I dont know what to do .. ?

oops -- that's what I get for not checking the code before sending it out :()

you'll have to do this:

foreach my $fichier (@fichiers)
 {
 my @asFileStats = stat $fichier;
 my $result = ($asFileStats[7] ne "")? "$fichier fait 
$asFileStats[7] octets\n" :  "$fichier inexistant \n";
 print RESULT $result;
 }

Aaron Craig
Programming
iSoftitler.com




Re: types of datas

2001-06-25 Thread Aaron Craig

Unlike strongly typed languages, Perl doesn't distinguish between types of 
scalar data, or rather, it massages it into the proper data depending on 
the context you're in.  Meaning if I do this:

my $sum = 1 + 1;

now, $sum contains a number: 2;

if I know say:
print "$sum\n";
Perl automatically changes the data type of $sum to a string for the print 
function.

This means you have to be careful when you compare data.  To force a 
variable into number context you can do
$sum += 0;

Now sum is a number (if it only contains a number, if it contains data 
which cannot be made into a number, then you get zero);
To be sure you have only numbers in your variable, you can use a regular 
expression:
print "Not a number!\n" if($sum =~ /[^\d]/);

Now, you can use the proper operators to check your data
for numbers, use + - > < == !=, etc
print "Sum is 0\n" if($sum == 0);
print "Sum is less than 5\n" if($sum < 5);

for strings use eq, ne, lt, gt, etc
print "Sum is 'foo'" if($sum eq "foo");


At 15:05 25.06.2001 +0200, Stéphane JEAN BAPTISTE wrote:

>Hi!
>
>I get a value from a URL and I put it into a variable.
>I have a loop (while) with a value which have different values.
>The problem is that when I compare the first and the second value: If
>they're really equals, the program say they are'nt.
>
>Is ther a function to convert a value into an integer ?
>
>tks
>
>(sorry for my english :-) )

Aaron Craig
Programming
iSoftitler.com




Re: to copy a file (with perl)

2001-06-25 Thread Aaron Craig

In the spirit of TMTOWTDI -

At 07:20 25.06.2001 -0700, Paul wrote:
>the brute force approach: =o)
>
>   open  IN,  $fileor die $!;
>   open  OUT, ">$new"  or die $!;
>   print OUT $line while defined($line=);
>   close OUT;
>   close IN;

print OUT $_ while ();
Aaron Craig
Programming
iSoftitler.com




Re: Reading Code

2001-06-25 Thread Aaron Craig

At 15:59 25.06.2001 +0100, [EMAIL PROTECTED] wrote:
>Can anyone tell me how to read this bit of code in english ?

Basically it takes an array, checks certain values and returns an error if 
it doesn't like the value.  If it likes all the values that it checks, it 
returns the return value of yet another function.

Does that help?

> > sub accum_cycle_count
> > {
> >  # @acc_fields are:
> >  #0 - Cycle Counting Order
> >  #1 - Warehouse
> >  #2 - Location
> >  #3 - Item Code
> >  #4 - Container
> >  #   5 - Lot Code
> >  #   6 - Storage Unit
> >  #   7 - Counted Inventory
> >  #8 - Counting Date
> >
> >  local(@acc_fields) = @_;
> >  return(-810) if ( $acc_fields[0] == 0 || $acc_fields[0] eq '' );
> >  return(-811) if ( $acc_fields[1] eq "" );
> >  return(-812) if ( $acc_fields[2] eq "" );
> >  return(-813) if ( $acc_fields[7] < 0 );
> >  $acc_fields[8] = &get_date if ( $acc_fields[8] eq '' );
> >
> >  return(&send_ddc("tdilc5110b000","accum_cycle_count",@acc_fields));

Aaron Craig
Programming
iSoftitler.com




Re: chomp ?

2001-06-26 Thread Aaron Craig

At 16:34 26.06.2001 +0200, Stéphane JEAN BAPTISTE wrote:
>What is chomp ?
>
>tks

It chops off the new line/return character when reading in a file.  It's 
kind of magical, in that in changes the character it looks for depending on 
the system its run on.


Aaron Craig
Programming
iSoftitler.com




Re: chomp ?

2001-06-26 Thread Aaron Craig

At 11:03 26.06.2001 -0400, Kevin Meltzer wrote:
>I think this is a very contradictory answer.. since if we were to RTFF
>(last F for FAQ) we would know not to answer in this way. It is not
>useful.

Which FAQ?  (seriously) :)


Aaron Craig
Programming
iSoftitler.com




Re: Debugging the CGI - Application

2001-06-27 Thread Aaron Craig

Simple approach:

sub Debug($)
 {
 my($sMessage) = @_;
 open(DEBUG, "debug.txt") || die("Couldn't open debug file $!");
 print "$sMessage\n";
 close DEBUG;
 }

Debug("This is a debug message");
then you can read your messages after you've run the program.  I do that a 
lot when developing websites, as I do a lot of dynamic generation of pages 
that make heavy use of style sheets and positioning, etc.  Debugging prints 
to the browser screw up the look, which is sometimes the thing I'm trying 
to get debugged, or they may break the page altogether.


At 12:02 27.06.2001 +0800, Rajeev Rumale wrote:
>Thanks again.
>
>Thats a very Nice piece of information ?
>But unfortunatelly I am using IIS on Win2k platform.
>I still condsider it as a very useful and important piece of information on
>this list.
>
>with regards
>
>Rajeev Rumale
>
>~~~
>Rajeev Rumale
>MyAngel.Net Pte Ltd.,Phone  :
>(65)8831530 (office)
>#04-01, 180 B, The Bencoolen,   Email  :
>[EMAIL PROTECTED]
>Bencoolen Street, Singapore - 189648 ICQ: 121001541
>Website : www.myangel.net
>~~~
>
>
>
>
>- Original Message -
>From: "Me" <[EMAIL PROTECTED]>
>To: "Rajeev Rumale" <[EMAIL PROTECTED]>; "'Beginner Perl'"
><[EMAIL PROTECTED]>
>Sent: Wednesday, June 27, 2001 11:13 AM
>Subject: Re: Debugging the CGI - Application
>
>
> > > Any more suggestion ?
> >
> > If you are allowed to modify your web server's setup, then:
> >
> > http://www.masonhq.com/docs/manual/Mason.html
> >
> > and prepare for your world to be turned upside down...
> >
> >

Aaron Craig
Programming
iSoftitler.com




Re: Converting Unix paths to windows

2001-06-27 Thread Aaron Craig

At 10:22 27.06.2001 -0500, Daryl Hoyt wrote:
>Hi,
> I am writing a script to be used on Windows and many different flavors
>of Unix.  I am looking for a good way to convert Unix paths to Windows.  Any
>Ideas?

What do you mean exactly.  If you just mean converting "\" to "/"  and 
getting rid of the drive you can do this:

my $sPath = "C:\\foo\\bar";
$sPath =~ s/^[a-z]+://i;
$sPath =~ s/\\/\//g;
print $sPath;
Aaron Craig
Programming
iSoftitler.com




Re: Joining variables

2001-06-27 Thread Aaron Craig

Just to make it longwinded:

my $stuff = { $var1 => "-" , $var2 => "-" , $var3 => "-" };
my $newvar = "";
$newvar .= "$_$stuff->{$_}" foreach keys %{ $stuff };


At 11:45 27.06.2001 -0400, Chas Owens wrote:
>On 27 Jun 2001 10:06:28 -0400, Chas Owens wrote:
> > On 27 Jun 2001 14:37:14 +0100, Pierre Smolarek wrote:
> > > > On Wed, Jun 27, 2001 at 02:07:22PM +0100, Pierre Smolarek wrote:
> > > > > $newvar = $var1."-".$var2."-".$var3;
> > > >
> > > > or $newvar = "$var1-$var2-$var3";
> > >
> > > or
> > >
> > > $concat = '-';
> > > $newvar .= $var1;
> > > $newvar .= $concat;
> > > $newvar .= $var2;
> > > $newvar .= $concat;
> > > $newvar .= $var3;
> > >
> > > dude, you should really look this up in a book.. its pre-basic perl
> > >
> > >
> > or
> >
> > $newvar = join "-", ($var1, $var2, $var3);
> >
> > TMTOWTDI
> >
> > --
> > Today is Pungenday, the 32nd day of Confusion in the YOLD 3167
> > Wibble.
> >
> >
> >
>
>or
>
>$newvar='';$newvar .= "$_-" foreach ($var1, $var2, $var3); chop $newvar;
>
>or
>
>$newvar = sprintf "%04d-%02d-%02d", $var1, $var2, $var3;
>
>or
>
>$newvar =~ s/.*/$var1-$var2-$var3/;
>
>I think I need a life.
>
>--
>Today is Pungenday, the 32nd day of Confusion in the YOLD 3167
>Kallisti!

Aaron Craig
Programming
iSoftitler.com




Re: confusing Perl idioms and practices

2001-06-29 Thread Aaron Craig

At 11:01 28.06.2001 -0700, Peter Scott wrote:

>"Readable" is like "obscene" (in more ways than one, in some code I've 
>seen).  I spent a little time in my book (one day I hope to have to say 
>which book :-) going over pros and cons of different takes on this.  But 
>as it stands, "readable" is simply meaningless, and guaranteed to cause 
>friction.  Your elaboration doesn't help either.  "Readable" is only 
>meaningful in a context of how the code is going to be used and what your 
>tactical and strategic goals are.  Debating it in a virtual vacuum like 
>this is what I call a "pinhead" discusssion - how many angels can dance on 
>the head of a pin...

If you define "readable" as "simple enough for the extreme beginner to 
understand", I agree.  This is not only obscene, it also makes it 
impossible to take full advantage of the language, as some constructs are 
necessarily complicated, and require a firm understanding of Perl to decipher.

However, I think a general level of non-obfuscation can be reached.  When 
working in groups, it becomes a necessity.  It's a matter of finding a 
common style in the group.  This saves time when someone is on vacation and 
you have to fix a bug in their code.  If they go around naming variables $x 
and $y instead of $names and $sizes (or, even better, $raNames and 
$raSizes), you spend a lot of time just figuring out what's going on.  Many 
will argue (correctly) that no decent programmer would name his or her 
variables $x and $y outside of a for loop.  However, rejecting readability 
out of hand as catering to beginners leads to similar behavior.  I always 
prefer an extra line of code in the spirit of readability.  If nothing 
else, it saves me from getting phone calls when I should be laying on the 
beach :)


Aaron Craig
Programming
iSoftitler.com




Re: is this a structure of some kind?

2001-06-29 Thread Aaron Craig

ALL_CAPS:
is a label that sets off a block of code.  A more obvious use for it would 
be to emulate the switch structure in C++:
SWITCH:
 {
 if($var == 1)
 {
 do something
 last SWITCH; # skip the rest of this block
 }
 if($var == 2)
 {
 do something else
 last SWITCH; # skip the rest of this block
 }
 do some default thing
 }

basically, a string followed by a colon is a point in the code that you can 
tell the program to go to using keywords like next, last, etc.

somewhere in your script, there must be a reference to ALL_SESSIONS and 
ALL_STUDIES -- hopefully not using the dreaded goto! :)
At 09:10 29.06.2001 -0500, Humberto Varela wrote:
>sorry to ask such a simple question, but i can't find reference to this 
>syntax in a couple of my Perl reference books (i think it's time i bought 
>the Camel book)
>
>--
>
>
>ALL_SESSIONS: foreach $session_dir (@ARGV) {
> @studies = `ls -1 "$session_dir" `;
> @session_path = split /\//, $session_dir ;
> $session = $session_path[$#session_path] ;
> print "\n Checking $session:" ;
>
> ALL_STUDIES: foreach $study (@studies) {
> chomp $study;
> $numfound = 0;
> @hits = (); # new list
>
>--
>
>the items in CAPS: are some kind of structure, right?
>
>i just haven't seen the CAPS: notation yet.
>
>thanks.

Aaron Craig
Programming
iSoftitler.com




Re: Web Page Interaction...

2001-06-29 Thread Aaron Craig

CGI.pm is the most advanced module around for dealing with forms.

At 13:44 29.06.2001 -0400, Craig S Monroe wrote:
>All,
>
>I have done some searching, looking for a module for interacting with web 
>pages.
>The only module, that appears to be related is LWP.  I read through those 
>docs,
>and, I am a novice, so they are a little confusing. Does anyone know of a 
>good tutorial,
>resource for an explanation on how to interact with different types of web 
>pages.
>For example, dealing with login dialog boxes, forms, etc. ?
>
>Thank you for any direction you can point me in..
>
>Craig
>[EMAIL PROTECTED]
>Pager
>Numeric: 1-877-895-3558
>Email pager: [EMAIL PROTECTED]
>--
>You will never find time for anything.
>If you want time, you must make it.
>
>Charles Buxton

Aaron Craig
Programming
iSoftitler.com




Re: binaries of DBI, DBD::mysql, CGI

2001-06-19 Thread Aaron Craig


> > HTML and the Database. Now I want to use Perl as language that does the
> > cgi-stuff. I know, I ought to use the modules DBI, DBD::mysql and CGI,
> > but my test-server runs on my desktop-pc with windows on it. As the
> > modules come as sourcecode, i would have to compile them to use them. My

I think you may be confused about modules and Perl compilation in 
general.  You don't have to compile the modules, you simply use them.  If 
they have dependencies, you'll want to "install" them by running makefile 
(correct me if my term is wrong) on them -- this allows them to set 
themselves up in the proper directory with the proper files where they need 
to be.  However, you do not need to compile them -- this gets done at run 
time by the Perl compiler itself.
Aaron Craig
Programming
iSoftitler.com




Re: conversion Perl<->HTML

2001-07-02 Thread Aaron Craig

You have to double escape \n -- try this

my $text = "First Line \n Second Line";
$text = s/\n/\\n/g;
print $text;

At 12:28 02.07.2001 +0200, Stéphane JEAN BAPTISTE wrote:
>HI.
>
>On the first side, I have a line of text into a file.
>On the other side, I want to write this text in a "textarea" Tag.
>In the text which is coming from the file, I have "\n", to have a trailing 
>newline.EX: "First line \n Second Line".
>I get the text from the file and I put it into the variable "$texte".
>When I write (In Perl) : print "cols=\"50\">$texte"; : in the "textarea", there is "First line 
>\n Second Line" but I want:
>First line
>Second Line".
>
>But, if a write $texte="First line \n Second Line" before the HTML code, 
>the text is correct.
>
>How can I convert the text from the file to the "textarea"?
>
>
>tks.
>

Aaron Craig
Programming
iSoftitler.com




Re: Windows2000

2001-07-03 Thread Aaron Craig

I would call back server Admin and ask them to take off FrontPage Extensions :)

However, Windows2000 is pretty good at transferring files in the correct 
format.  I actually use the Windows Explorer as my ftp client, and it 
handles cgi and pl scripts just fine.

Plus, if you're using Network Places to transfer data around, it means 
you're going through the local network, which means you're transferring 
files in much the same way as you move them from one folder to another -- 
ie, you've got nothing to worry about :)

At 00:27 03.07.2001 -0500, RL Autry wrote:
>Hello everyone:
>
>We are new to the list and need to find out the following:
>Our server Admin just told us that we are now on Windows2000 with 
>FrontPage Extensions installed.
>They warned us about using FTP in order to transfer files. They said FTP 
>would corrupt the FrontPage Extensions.
>
>They advised us to use our "Network Places" instead for file transfer.
>
>Does anyone know how we can tell our Windows2000 Professional Operating 
>system (Network Places) that it is moving a .pl or .cgi, ect file so that 
>we can be sure it does it in ASCII?
>
>
>
>Thanks,
>RL
>

Aaron Craig
Programming
iSoftitler.com




RE: Editor

2001-07-04 Thread Aaron Craig

At 20:00 03.07.2001 -0500, RL Autry wrote:
>We are very new to programming and especially to Perl.
>We were following this thread closely and only saw a couple
>of replies. Wondering if there are any other editors that would
>do all that is needed for Perl and possibly even C++, Java, Visual Basic, ect

I use a different editor for different languages.

Perl, HTML, JavaScript =>  EditPlus2 (www.editplus.com) is a great editor 
for scripting languages.  It features fully customizable auto-complete, 
templates, color-coding, project management, etc. etc.  It even has a 
little ftp function for uploading your scripts.  It is not free, but the 
trial version is actually a full-blown version that never expires.  This 
editor is so cool, though, that it's worth the $30 fee.

For C++ and Visual Basic I use M$ Visual Studio, which I like, more or 
less.  I use it 'cause that's the program the company I work for bought, 
and now I'm used to it.  I recently gave Borland a look, and I liked what I 
saw, though it's tough to switch once you're used to one programs foibles.

>The reason for this is we are actually at the same time trying to decide
>which language is going to give us the most flexibility and power.

You say that like you only want to learn one language :)  I use a mixture 
of Perl and C++ for the guts of a program, and Visual Basic and 
JavaScript/HTML for the interface part, depending on where the program has 
to live.

Aaron Craig
Programming
iSoftitler.com




Re: error

2001-07-04 Thread Aaron Craig

At 17:12 03.07.2001 -0500, RL Autry wrote:
>This was originally on a UNIX machine.
>How can you know when you have a script that will work with your operating 
>system?
>In this case Windows2000 Server.


You shouldn't have many problems going from UNIX to Win2000 -- I regularly 
do the opposite, develop on Windows and transfer to *nix.  However, I do 
use Apache on my Windows machine, which handles things in a more Unix way 
-- I highly recommend using Apache over the Win2000 server, as my 
experience with that server has been that it wants to do too much stuff for 
you, and insist on using Windows "features", which you may or may not want.
Aaron Craig
Programming
iSoftitler.com




Re: Loops - Killing of Process on Win2k.

2001-07-04 Thread Aaron Craig

I have the same problem with Apache / Win2000 if I run Apache as a 
service.  If I run Apache by itself (ie, start up from the command line, 
not from the Services menu) I can shut down Apache if I get Perl in an 
infinite loop, and then Task Manager allows me to shut down the Perl process.

I recently installed a newer version of Apache, and it seems to only run as 
a service, so I, too, have to reboot the system every time I write poorly 
checked code.  Which brings up the point of why we get infinite loops 
anyway -- for me, at least, it's usually because of sloppy 
coding.  However, when I really get stuck and can't figure out why the darn 
thing won't work, I usually use a debug variable to force me out of the 
loop after a while:

my $debug = 0;
while((condition that may never become false) && $debug < 1000)
 {
 code...
 $debug++;
 }

At 11:42 04.07.2001 +0800, Rajeev Rumale wrote:
>Hi,
>
>I have a win2k server running IIS.
>Because of some programming error I tend to get caught into some infinit
>loop while testing the scripts.
>
>We know each such request for he script will start a new process for
>"perl.exe". The process in not dieing by itself after timeout.  And also am
>unable to kill it using Task manager.  The only way i get rid of this is by
>rebooting the system.
>
>Kindly advice if there  better option for killing the process or testing
>such loops which might get into infinit loop.
>
>regards
>
>Rajeev Rumale
>
>~~~
>Rajeev Rumale
>MyAngel.Net Pte Ltd.,Phone  :
>(65)8831530 (office)
>#04-01, 180 B, The Bencoolen,   Email  :
>[EMAIL PROTECTED]
>Bencoolen Street, Singapore - 189648 ICQ    : 121001541
>Website : www.myangel.net
>~~~

Aaron Craig
Programming
iSoftitler.com




RE: \r

2001-07-05 Thread Aaron Craig

At 14:13 05.07.2001 +0100, Govinderjit Dhinsa wrote:
> What is the code please to get, after field 6;
> \r (carriage return)
>
> I tried this, but no luck;
> $fields[6] =~ s\r//;

try $fields[6] =~ s/\r//;
^
|
|
note added front slash

>Any help would be much appreciated!!!
>Thanks,
>GD
>
> #
> PROGRAM:
>
> #!/path/to/perl -w
> use strict;
>
> open CSV," open NEW,">vt04-07-01.csv-changed";
> while (){
> chomp;
>
> my @fields = split ',';
>
> splice @fields, 2, 1;
>
> splice @fields, 5, 1;
>
> $fields[6] =~ s\r//;
>
> for (@fields) { print NEW "$_" }
> }
> close CSV;
> close NEW;
> exit;
>
> [End of file]
> 

Aaron Craig
Programming
iSoftitler.com




Re: Absolute Path

2001-07-06 Thread Aaron Craig

There are two different things you have to keep in mind when working with 
paths from the cgi-bin on a Windows machine -- access for Perl, and access 
for the web.

When I want to give Perl access to something, I usually use Windows style 
paths -- this avoids the confusion that can arise with permissions using 
Unix style relative paths.  You have to be careful with this way of doing 
things, because you're bypassing all of the checks that the server does to 
make sure that the cgi-bin user is authorized to access a certain directory.

When you're producing HTML links on a web page that will give access to 
files, you obviously have to use URL paths.  Which is where your problem is 
arising, I believe.  Try:

print qq~ftp://path/to/ftp/files";>Link Text~;

note the URL does not use relative paths, and has forward slashes.

Also, as a pure style note, you should be using a foreach loop, instead of 
a while loop, and you can avoid your check for "." and ".." if you get your 
file list using grep{}



my $sDirectory = "C:\My\Directory";
my $sURLRoot = "ftp://My/Directory";;
opendir(DIR, $sDirectory) || die("Couldn't open directory $sDirectory: $!");
my @asFiles = grep{ $_ =~ /\.zip$/ } readdir DIR; # change regular 
expression to suit your needs
closedir DIR;
print qq~$_\n~ foreach @asFiles;





At 18:40 05.07.2001 -0500, SAWMaster wrote:
>Hi group!
>
>Little bit of background.  I made a perl cgi that scans a directory for 
>files and auto generates a html page with hyperlinks to download whatever 
>files are in the directory.  I don't
>know if there's an easier way to do this than what I did (built it from 
>scratch) but I'm doing this to learn Perl, not to make things easy.  I had 
>this working locally through
>localhost, using the full path to the files, but it won't work if someone 
>tries to access it remotely.  Anyway, on to the problem.
>
>I'm having trouble writting my absolute path for a link to a .zip file in 
>a cgi script.
>
>Here's my code.
>
>while($i < ($#filelist))
>{
> if ((@filelist[$i] ne '.') && (@filelist[$i] ne '..'))
> {
> print " \"ftp\\public\\downloads\\assortedfiles\\@filelist[$i]\">@filelist[$i]";
> print "\n";
> }
> $i++;
>}

Aaron Craig
Programming
iSoftitler.com




Re: I did it!!!

2001-07-06 Thread Aaron Craig

At 16:02 05.07.2001 -0500, Humberto Varela wrote:
>you have an error in your syntax:
>
>
> >print STDOUT "The result you ignorant fool is: $result\n";
>
>should be:
>
>print STDOUT "The result, you ignorant fool, is: $result\n";
>
>commas help emphasize that "pause" in the print statement.
>
>: )

or how about a real dramatic pause?

use strict;

my ($number,$mult,$result);


print "Enter a number:  ";
chomp($number = );
print "Enter a multiplier:  ";
chomp($mult = );
$result = $number * $mult;
print "The result,";
sleep(2);
print " you ignorant fool,";
sleep(2);
print " is: $result\n";

Aaron Craig
Programming
iSoftitler.com




Re: How to print char '\' ?

2001-07-06 Thread Aaron Craig

That's because the backslash character is also the escape character.  If 
you want to print the string
$string (where $string is NOT a variable)
you write
print "\$string"; # prints $string

In your code below, you've escaped the closing quote, and therefore you 
don't tell Perl where the string ends.  To avoid this, you have to escape 
the backslash:
print "\\"; # prints \


At 15:18 06.07.2001 +0500, Berkeley Altiev wrote:

>my print '\'; string give me:
>Can't find string terminator "'" anywere befor EOF at ./file line 2.
>
>How i may print that symbol ? Perl running on Linux console.

Aaron Craig
Programming
iSoftitler.com




Re:Menu

2001-07-06 Thread Aaron Craig

Dynamic?  In a web page, you have to use JavaScript (or another web 
scripting language) to effect changes in real time to your page.  That 
discussion would be beyond the scope of this list, but if you want some 
help on this, email me.

At 11:43 06.07.2001 +0200, Jorge Goncalvez wrote:
>Hi , I wanted to do a dynamic menu ie when a user select the language I 
>want to
>change the title of the labels with the right traduction.
>
>They can choose with checkbuttons 2 language, i Tried this:
>
>if ($GENERIC eq 'true'){
> $language='Client Ethernet adress';
> }
>
>if ($FRENCH eq 'true'){
> $language='Adresse Ethernet du Client';
> }
>
>$mw->Label(-textvariable=>\$language)->pack(-anchor=>'w');
>
>
>--Menu subroutines
>
>..
>
>my $cc = $mnu1->cascade(-label=>'~Language');
>
>$cc-> checkbutton (-label=>'Generic Alcatel', -variable => \$GENERIC);
>$cc-> checkbutton (-label=>'French', -variable => \$FRENCH);
>
>
>But now I have nothing displayed,neither Client ethernet adress nor Adresse
>Ethernet du Client.
>
>Why ? Thanks

Aaron Craig
Programming
iSoftitler.com




Re: I did it!!!

2001-07-06 Thread Aaron Craig

At 08:31 06.07.2001 -0400, Jeff 'japhy' Pinyan wrote:
>On Jul 6, Aaron Craig said:
>
> >print "The result,";
> >sleep(2);
> >print " you ignorant fool,";
> >sleep(2);
> >print " is: $result\n";
>
>You'd have to turn off output buffering for STDOUT.
>
>   $| = 1;

Interesting, it worked as expected on Win2000.
Aaron Craig
Programming
iSoftitler.com




Re: NET::IRC

2001-07-06 Thread Aaron Craig

At 16:05 06.07.2001 +0100, Kris G Findlay wrote:
>i have a script
>
># perl script ##
>#!e:\perl\bin\perl
>
>   use Net::IRC;
>
>   my $irc = new Net::IRC;
>
>   my $conn = $irc->newconn(Nick => 'GH-[bot]',
>Server   => 'some.server.com',
>Port => 6668);
>
>
>   $self->add_global_handler('376', \&on_connect); # global
>
>   $self->add_handler('msg', \&on_msg);# local
>
>  # What to do when the bot successfully connects.
> sub on_connect {
> $self = shift;
>
>
> print "Joining #chat...";
> $self->join("#chat");
> $self->privmsg("#chat", "Hi there.");
> }
>
>$irc->start;
>
># end perl script ##
>
>and when i run it i get this error
>
>Can't connect to some.server.com:6668! at E:/Perl/site/lib/Net/IRC.pm line
>192

I would guess that you have to change the parameters on line 192 to 
something valid

some.server.com probably be changed to whatever server is hosting this 
connection -- and I'd be that Nick should be changed to a valid nickname.

>   my $conn = $irc->newconn(Nick => 'GH-[bot]',
>Server   => 'some.server.com',
>Port => 6668);

Aaron Craig
Programming
iSoftitler.com




Re: Loading a comma delimited file into a hash.

2001-07-06 Thread Aaron Craig

At 11:53 06.07.2001 -0400, Aaron Petry wrote:
> I have a comma delimited file like this:
>"field1","field 2","Some longer field 3 here","And some field 4"
>.I want to ask my users how many fields there are and populate that to a 
>scalar, then ask them what the field titles are and shove that input into 
>an array.  Then I want to ask them which field (asking for the number, not 
>the title) has a key value.  I want to then take that input, use it to 
>make a hash of each record, then a hash of those hashes so that I have all 
>the records.  I'm fine until that last step, and I keep thinking I've 
>worked it out, and then I run into another snag.  Here's what I have so far.

I think I know what you're trying to do :)

>use strict;
>
>my($file1, $f1fnum, @f1fname, $f1namef, $f1key);
>
>#First, get the path of the file that has the names that need to be compared.
>#The first line prints the question, the second line assigns the typed 
>response, less the newline
>#to a variable name.
>
>print "What is the path of the file that needs to be matched?  ";
>chomp($file1 = );
>open(FILE1,'$file1') || die "I can't seem to find that file.  Here's why: $!";
>
>#Now, check to get information about the file itself.
>
>print "\nHow many fields are there in this file? ";
>chomp($f1fnum = );
>
>print "\nPlease type the field names (no spaces) separated by commas. \n 
>For example, Name, Address1, City, etc.: ";

you say no spaces, and then your example uses spaces :)

>chomp(@f1fname = );

I would do this:
my $line = ;
chomp $line;
@f1fname = split(/,/, $line);

and then some error checking:

print "Field counts do not match!\n" if(scalar(@f1fname) != $f1fnum);

>print "\nWhich field (1, 2, 3, 4, etc.) has the name filed to be compared? ";
>chomp($f1namef = );
>--$f1namef;
>
>print "\nWhich field (1, 2, 3, 4, etc.) has some unique identifier for 
>each record? ";
>chomp($f1key = );
>--$f1key;
>
>print "\nThat's all I need for file 1, but now I have some questions about 
>the file you will be comparing to.\n";
>
>my($i, %hfile1);
>#Now, we'll need to load the file into two hashes of hashes.  I know that 
>I will need to loop through line by
>#line, so...
>while (){
>#Now, I know that I need to match each field with it's name from the array 
>to make the inner hash.
>#I also need to then add that to the outer hash, and start with the next 
>line.  I just don't know how
>#to do that part.
 untested! 
my $raRecords = [];
while()
 {
 my $rhNameValues = {};
 chomp;
 my @asFields = split(/,/, $_);
 if(scalar(@asFields) != scalar(@f1fname) # make sure the field 
counts line up
 {
 print "malformed line\n";
 close FILE;
 exit;
 }
 my $lCount = 0;
 foreach my $sFieldName (@f1fname)
 {
 $rhNameValue->{$sFieldName} = $asFields[$lCount];
 $lCount++;
 }
 push(@{ $raRecords }, $rhNameValue);
 }
now you've got an array ref $raRecords with n hash refs $rhNameValue.  Each 
hash ref contains a key for each field your user defined, with its value 
being the field it grabbed out of the file

Aaron Craig
Programming
iSoftitler.com




Re: download a file

2001-07-07 Thread Aaron Craig

Why don't you just do

print qq~http://my.host.com/name_of_file.xxx";>Click to get file~;

and let the browser handle the rest for you.

At 16:12 06.07.2001 -0400, [EMAIL PROTECTED] wrote:
>This problem might not be entirely related to Perl, but I'm pretty sure 
>Perl can help solve it.
>
>Here is the thing :
>
>I want to be able to download a file (any kind of file) directly from my 
>browser. I'm using this code below :
>
>#!/usr/bin/perl
>
>my $size = 19456 # 19k * 1024;
>my $fileName = "budget.xls"; # name of the file
>my $file = "../files/edi/kfred/200104311315547.xls"; # location of the 
>file on the server
>
># Send the header
>print "Content-Type: application/octet-stream\n";
>print "Content-Disposition: attachment;filename=$fileName\n";
>print "Content-Length: $size\n\n";
>print read_file($file); # read the file from the server
>
>sub read_file {
>my($fname) = @_;
>my($content);
>open(FILE, "<$fname") || return '';
>while() { $content .= $_; }
>close(FILE);
>$content; }
>
>It works well with Netscape 4.7 but IE 5.5 gives me a problem.
>
>Let say I'm on a page called test.html. The only thing this page does is 
>offer a link to the script above (download.pl). If I click on the link 
>Explorer will ask me what I want to do with the file (since I've put the 
>application/octet-stream Content-type) :
>
>"Save it to disk or open it"
>
>But if I choose to save it it will save test.html AND NOT budget.xls as it 
>should!
>
>On the other hand, if I call download.pl directly from the location bar or 
>if I make test.html automaticly open a new window on load
>[ onload=void(window.open('download.pl')) ] it does the trick!?
>
>Opening a new window would not be such a problem if I wouldn't get the 
>"Page cannot be displayed" message in this new window, wich is not very 
>pretty... And calling the script from the location bar is not very 
>usefull, since what I want is to have a list of all my files in my browser 
>window and simply be able to click on one to download it to my disk.
>
>Anyone can Help ? If you want more information to help just ask.
>
>Thank you very much for your time.
>
>Frédéric Fortin,
>[EMAIL PROTECTED]
>TPC Communications

Aaron Craig
Programming
iSoftitler.com




Re: Loading a comma delimited file into a hash.

2001-07-07 Thread Aaron Craig

At 13:24 06.07.2001 -0400, Aaron Petry wrote:
Oops.

>>>chomp(@f1fname = );
>>
>>I would do this:
>>my $line = ;
>>chomp $line;
>>@f1fname = split(/,/, $line);
>>
>>and then some error checking:
>>
>>print "Field counts do not match!\n" if(scalar(@f1fname) != $f1fnum);
>
>Actually, if I had been thinking in these terms, it would be easier to 
>make Perl count how many fields they entered, rather than having them 
>count it.  So...
>scalar(@f1fname)=$f1fnum;
>might be better...

Do you mean
$f1fnum = scalar(@f1fname);
?


Aaron Craig
Programming
iSoftitler.com




Re: R: download a file

2001-07-09 Thread Aaron Craig

At 12:59 07.07.2001 -0400, Fred Fortin wrote:
> >> Why don't you just do print qq~
> >>http://my.host.com/name_of_file.xxx";>Click to getfile~;
> >>and let the browser handle the rest for you.
> >>
> >>Because in that case, files like .txt or .html would appear in the browser
> >>instead of being downloaded to my harddrive. This is not very helpfull
> >>(having those files displayed in the browser) when what I want to do is
> >>get them on my HD from one place to an other (at work and at home)...
> >>
> >>I need to be able to save to disk...
>
> >Why don't you just do
> >print qq~http://my.host.com/name_of_file.xxx";>Shift-click to get
> >file~;
> >then? :-)

Safest of all

print qq~http://my.host.com/name_of_file.xxx";>Right-click and 
select "Save Target As..." to get file~;
Aaron Craig
Programming
iSoftitler.com




Re: diff bet list and an array

2001-07-09 Thread Aaron Craig

At 16:30 09.07.2001 +0530, baby lakshmi wrote:
>hi,
>What is the difference between list and an array??
>May be this very small question. but i would like to know the difference.
>The help in this regard is appreciated.
>Thank you
>Regards
>babylakshmi

There isn't one.


Aaron Craig
Programming
iSoftitler.com




Re: remplace ...

2001-07-09 Thread Aaron Craig

At 13:05 09.07.2001 +0200, [EMAIL PROTECTED] wrote:
>Hi,
>
>I want to remplace all the word "html" in "php" in some web pages ...
>
>I tried this but nothing is happening :
>
>open (TRANS, "c:\\test\\test.txt");
>
>@transformation=;
>
>foreach $ligne (@transformation)
>{
>chomp($ligne);
>$transform=$ligne;
>$transform=~s/html/php/g;
>};
>
>close (TRANS);

You're not doing anything with $transform.

open (TRANS, "c:\\test\\test.txt") || die("Couldn't open 
c:\\test\\test.txt: $!"); # added error check
open (OUT, "c:\\test\\test_output.txt") || die("Couldn't open 
c:\\test\\test_output.txt: $!");
while()
 {
 $_ =~ s/html/php/g;
     print OUT $_;
 }

close TRANS;
close OUT;

now, you have a new file, test_output.txt, which contains the substituted text
Aaron Craig
Programming
iSoftitler.com




Re: diff bet list and an array

2001-07-09 Thread Aaron Craig

At 14:53 09.07.2001 +0200, Paul Johnson wrote:
>On Mon, Jul 09, 2001 at 04:48:42PM +0530, baby lakshmi wrote:
> > >>What is the difference between list and an array??
> > >>May be this very small question. but i would like to know the difference.
> > >>The help in this regard is appreciated.
> > >>Thank you
> > >>Regards
> > >>babylakshmi
> > >
> > >There isn't one.
>
>Well, actuallly that's not quite right.  There is quite a bit of
>difference.  See perlfaq4, copied here.

You are correct -- I should have read the documention :)  However, in every 
day programming-speak, list and array get tossed about in such a way that 
they become synonymous.  A list and an array seem to be effectively the 
same thing -- except that a list is constant and an array is not.  You 
might even say that a list is an array that you can't mess with.

Which brings up a question on my part.  Are there any examples of the use 
of an array and the use of a list where labelling them differently make 
something different happen?  IE

foreach (0..9); # list, correct?
foreach (@array); # array

to the average programmer, how does calling 0..9 an array screw them up?


Aaron Craig
Programming
iSoftitler.com




Re: diff bet list and an array

2001-07-09 Thread Aaron Craig

At 04:29 09.07.2001 -0800, Michael Fowler wrote:
>On Mon, Jul 09, 2001 at 01:59:28PM +0200, Aaron Craig wrote:
> > You are correct -- I should have read the documention :)  However, in 
> every
> > day programming-speak, list and array get tossed about in such a way that
> > they become synonymous.
>
>They shouldn't be.  The distinction can be important (see further down).
>Part of being a programmer is being very exact in what terms one uses.  This
>stems from the fact that computers require exact input.

Which is exactly my point.  I've been hanging around this list a while, and 
programming Perl for a lot longer, and this is the first time the issue has 
ever come up -- I admit that I didn't even know there was a difference 
until today.  If there was such an important distinction between the two, I 
wonder why the issue was never raised before now.

I admit that I still have a lot to learn about the intricate details of 
Perl, but this point seems to be on the verge of hairsplitting.


>Even if the distinction isn't important except in academic circles (and
>that's a big if), we are effectively -in- an academic circle; we're teaching
>people how to use Perl, so we need to be consist in our terminology.

I agree completely.  I should have looked the term up myself before 
responding to the question.  My only defense is that as it's something that 
has never caused me a problem, I never had a need to look it up in the docs :)

At any rate, your points are taken, and I'll be more careful about Perl 
basics in the future :)


Aaron Craig
Programming
iSoftitler.com




RE: newbie whitespace question

2001-07-10 Thread Aaron Craig

At 15:49 09.07.2001 -0700, Wagner-David wrote:
>   Change:if ( /^Kilobytes:(.*)$/ ) to if ( /^Kilobytes:\s*(\d*)$/ )
>
> where $1 will have your count without leading spaces.  You may want
>a test to verify that you did get a hit on digits.
>
>Wags ;)
>

That only works if the text following Kilobytes: is always some spaces and 
then a string of numbers.  What if you've got non-numbers?

how about:

if(/^Kilobytes:[\s\t]*([^\s\t]+)$/)

which adds the possibility of tabs being used instead of spaces (just in 
case :)


>Hi,
>
>I have a newbie whitespace question. Say I have a regular variable that has
>a string in it with something like "  text". I just want to reassign the
>variable to the text inside the double quotes above. or, given the
>snippet...
>
>my $var="";
>while (  ) {
>if ( /^Kilobytes:(.*)$/ ) {
>   $var = $1 ;
>}
>}
>
>This will set $var to "   3452" for example, I want to strip out the
>whitespace to only get "3452".
>
>Any thoughts appreciated,
>
>-Nat

Aaron Craig
Programming
iSoftitler.com




Re: PRELOADING IMAGES FOR A WEB SITE

2001-07-10 Thread Aaron Craig

At 01:13 10.07.2001 -0700, Morgan Mackenzie wrote:
>PERL newbie here!
>
>I am using Javascript to preload my images for a web site I am working on.
>If I can use PERL for everything, I would love too.  Any thoughts where I
>can get information on how to do this (if it's possible. . . what am I
>saying, w/ PERL everything is possible).
>
>Morgan

I don't think that is possible.  Perl works on the server, and doesn't have 
any control over what's going on on the client (apart from the data it 
sends as an html response).

Besides, what's wrong with using JavaScript for doing the job it was 
created for -- that is, controlling dynamic content on a web page.  My more 
involved pages often use a mix of Perl on the server, and JavaScript and 
C++ (in the form of a plug in) on the page.  Just for kicks, I throw some 
Flash and ActionScript in for good measure :)
Aaron Craig
Programming
iSoftitler.com




RE: newbie whitespace question

2001-07-10 Thread Aaron Craig


>At 15:49 09.07.2001 -0700, Wagner-David wrote:
>>   Change:if ( /^Kilobytes:(.*)$/ ) to if ( /^Kilobytes:\s*(\d*)$/ )
>>
>> where $1 will have your count without leading spaces.  You may want
>>a test to verify that you did get a hit on digits.
>>
>>Wags ;)
>
>That only works if the text following Kilobytes: is always some spaces and 
>then a string of numbers.  What if you've got non-numbers?
>
>how about:
>
>if(/^Kilobytes:[\s\t]*([^\s\t]+)$/)
>
>which adds the possibility of tabs being used instead of spaces (just in 
>case :)


Before everyone jumps, the tabs/spaces foot in my mouth has already been 
pointed out to me.

I won't even try to make an excuse...there is none :)


Aaron Craig
Programming
iSoftitler.com




Re: Help: Searching an array question++

2001-07-10 Thread Aaron Craig

At 08:32 10.07.2001 -0700, Bob Bondi wrote:
>Yep, another newbie at Perl. I have come to a wall. What I need to do is
>open a file, find a value in the file and substitute a value.
>I've gotten to the point of what to do with an open file. I have been trying
>the @array =  statement.
>I then wanted to verify the contents of the array and tried printing it,
>print("$array\n");
>
>But there is no output is unexpected! 0: is the output.
>
>Also, the substitute thingie is, well, odd. Say, I define $sFind="this.gif",
>and $sSwap="that.gif".
>And say I have an array with each line of a file tucked away in it. What the
>heck is the syntax for it

... untested, but the comments are what counts :) ...


#\perl\bin

use strict; # use strict! It will save you many headaches

open(TESTFILE, "/Inetpub/wwwroot/date.htm") || die "Can't open 
/Inetpub/wwwroot/date.htm: $!"; # changing open() to read-only
#@array = ;
# here, you've read the entire file into an array -- this may or may not be 
what you want to do.  If the file is big, you may be
# leaving yourself open to memory problems.  The best bet is usually to 
read through the file one line at a time.

# first, we'll declare your gif variables -- using my now, because we're 
using strict.
my $sFindGIF = "this.gif";
my $sSwapGIF = "that.gif";
my $sNewData = ""; # initialize a string that will contain our new data, at 
the end of the substituting, we'll close TESTFILE and
 # re-open it for writing (I find that easier than 
dealing with file pointers
 # or you may want to save the data to a new file 
(always a good idea)
while()
 {
 # this will loop through the file, grabbing one line at a time and 
throwing it into the $_ variable
 print; # this will print your line -- if I don't specify what I 
want to print(), Perl assumes $_
 # now we do your substitution
 s/$sFindGIF/$sSwapGIF/g; # again, Perl assumes $_
 $sNewData .= $_; # add the new string to $sNewData
 }
close TESTFILE;
open(TESTFILE, ">/Inetpub/wwwroot/date.htm") || die "Can't open 
/Inetpub/wwwroot/date.htm: $!"; # now open() with write permission
print TESTFILE $sNewData;
close TESTFILE;



Just FYI
usually, if you want to loop through an array, you want to use foreach, ie
foreach my $element(@array)
 {
 }
for ($index = 0; $index<=$#index; $index++) {

if ($array[$index] =~ /sFindGIF/) {

Here, your searching for the string "sFindGIF", not the value contained in 
the variable $sFindGIF

print ("$index: $_\n");
$s = $array[$index];

why do you create the variables and then not use them?  Use $sFindGIF and 
$sSwapGIF here.

$s =~ s/this.gif/that.gif/;
close (TESTFILE);


Aaron Craig
Programming
iSoftitler.com




Re: Is there an alternative to CGI ???

2001-07-11 Thread Aaron Craig

You may be confusing your terms here.  CGI (Common Gateway Interface) is a 
general term that is used to describe the various methods used to 
communicate between a host computer and a client through a network.  There 
are many languages that can be used to handle this communication, such as 
Perl and even C++ (does anyone do that anymore?).  However, if you're 
talking internet, you're talking CGI, no matter what you use to run your 
communication.

At 13:52 11.07.2001 +0530, George S Pereira wrote:

>Hi all,
>
> Using CGI as a bridge between Perl and the Internet has some
>disadvantages, prominent is the increased use of memory.
>
> Is there another alternative for connecting Perl with the Internet
>other than CGI  (Like maybe using Perl with ASP!!!)
>
>
>George Savio Pereira
>^^^^^^^^
>Email : [EMAIL PROTECTED]

Aaron Craig
Programming
iSoftitler.com




Re: Is there an alternative to CGI ???

2001-07-11 Thread Aaron Craig

At 01:14 11.07.2001 -0800, Michael Fowler wrote:
>On Wed, Jul 11, 2001 at 10:28:46AM +0200, Aaron Craig wrote:
> > You may be confusing your terms here.  CGI (Common Gateway Interface) is a
> > general term that is used to describe the various methods used to
> > communicate between a host computer and a client through a network.  There
> > are many languages that can be used to handle this communication, such as
> > Perl and even C++ (does anyone do that anymore?).  However, if you're
> > talking internet, you're talking CGI, no matter what you use to run your
> > communication.
>
>Yow, you're confusing your terms.  CGI is not a general term to describe
>internet communications, it's a very specific protocol between a web server
>and an application, an application executed by the web server for handling a
>request.

"very specific protocol between a web server and an application" ie 
internet communications

Sorry, I forgot to check my Internet Nitpickers Dictionary before posting.  :)
Aaron Craig
Programming
iSoftitler.com




RE: Is there an alternative to CGI ???

2001-07-11 Thread Aaron Craig

At 10:22 11.07.2001 +0100, John Edwards wrote:
>If you're going to post to the list, get it right first time round or
>prepare to be corrected by others on the list. No good complaining that
>people are nitpicking your posts if there are fundamental errors in them.

You have a point -- apologies for the quick response.
Aaron Craig
Programming
iSoftitler.com




[OT] in my own defence (was RE: Is there an alternative to CGI ???)

2001-07-11 Thread Aaron Craig

A colleague just pointed out this link for me, and I may have accidentally 
gotten the correct definition for CGI in my generalization.  At any rate, 
for those who are interested:

http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html

Aaron Craig
Programming
iSoftitler.com




RE: printf

2001-07-12 Thread Aaron Craig

At 09:52 12.07.2001 +0100, Govinderjit Dhinsa wrote:
>Does any body know why the printf is not printing anything out!
>
>I tested the rest of the script by replacing the printf line with,
>##
>print "$line";
>##
>the file prints (with out any changes to the file, as expected). So
>everything else is working apart from the printf.
>
>Any help would be much appreciated.
>Thanks.
>GD

first of all, add the following line to the top of your script:

use strict;

which will immediately cause everything to stop working :)

However, it will force you to declare your variables in the scope you're 
using them in, which is a lot safer and will save you problems down the road.


>

Re: multiple entry/exit points

2001-07-12 Thread Aaron Craig

At 11:28 12.07.2001 -0400, Kurt Edmiston wrote:
>Here's a topic for discussion:
>
>Coming from C++-land, I've always been taught over and over again that all 
>subroutines/functions/blocks/etc should have only a single entry point and 
>a single exit point.  "It's just good programming practice."  But now in 
>the world of Perl, I've observed that a "Perl-ish" thing to do is to place 
>multiple return/exit/etc statements in certain blocks of code or in 
>conditional blocks.  (Then again, maybe it isn't Perl-ish, but I've had to 
>sort through many perl scripts like this.)
>
>I guess I'm just curious to know what other more experienced Perl 
>programmers think about this.  I still adhere strictly to the "one way in, 
>one way out" philosophy, mainly for the sake of readability.  But I 
>understand how much easier it can make a programmer's task to write 
>something like "if (some condition) { exit; }"
>
>Also, I was wondering if exiting prematurely like this from a program has 
>any adverse affects on the execution of the program.
>
>Thanks,
>Kurt
>

This is an interesting discussion topic,

I do C++ myself, and have no qualms about exiting early if I run into a 
problem -- either by returning an error code, or exiting the program 
altogether, if the error is something I can't recover from -- in Perl, C++, 
JavaScript, or any other language I happen to be writing in.

I've seen a lot of code with 10's of embedded blocks, all with conditions 
that guide the flow to a final destination -- it's so ugly!  What's wrong 
with putting all of your error checking at the top of your function, and 
then jumping out if you run into something you don't like.  It makes the 
meat of the function easier to read.
Aaron Craig
Programming
iSoftitler.com




Re: C & Perl for loops

2001-07-13 Thread Aaron Craig

At 07:09 13.07.2001 -0400, Busse, Rich wrote:
>In C, I can do something like this:
>
> char ch ;
> char sz [] = "?:\\dir\\myfile.ini" ;
> for ( ch = 'c' ; ch <= 'z' ; ch++ )
> {
> sz[0] = ch ;
> . . .
>
>to spin thru all the possible drives on a Windows NT box. But Perl complains
>about trying to compare/increment a non-numeric. Any way around this?

use strict;

my $drive = "a";
my $path = ":\\path\\to\\file.xxx";
foreach (0..25)
 {
 print "$drive$path\n";
 $drive++;
 }

since incrementing a string in perl is possible.  Forget about looking at 
strings like an array :)
Also, Perl style likes foreach() over for() usually.

If you want to do it in a really perly way:

print $drive++."$path\n" foreach (0..25);

>Also, to look at each character in a string, I can do:
>
> int i ;
> char sz [] = "A string" ;
> for ( i = 0 ; i < strlen (sz) ; i++ )
> {
> ch = sz [i] ;
> . . .
>
>How do I access each character in a string with Perl? TIA...

check out perldoc perlfunc -- there's a whole section on built in string 
functions

to get the length of a string use length (surprised?)

my $sString = "foo bar";
print length($sString)."\n";



Aaron Craig
Programming
iSoftitler.com




Re: getting first character of item

2001-07-13 Thread Aaron Craig

At 21:55 13.07.2001 +1000, Mal Beaton wrote:

>I am stuck on the foreach loop getting the first character of $user
>
>foreach $user (keys %{users{abc}}){
>### trying to get the first character of $user here

my $fc = substr($user, 0, 1); # $fc now contains the first character of $user


Aaron Craig
Programming
iSoftitler.com




Re: looking at rows in text files

2001-07-18 Thread Aaron Craig

How about:

use strict;

open(IN, "file.txt") || die("RRRGGGHHH $!");
while() # loop through file setting each line to $_
 {
 chomp; # lose newline
 /^([^\s]+)\s/; # look for anything at the beginning of the string 
up to the first space or tab character and remember it
 print "$1\n"; # print the match
 }
close IN;



At 08:43 18.07.2001 -0500, Tyler Longren wrote:
>Hello everyone,
>
>I have a file that contains a few domain names, and their dns servers (kind
>of like a zonefile).  Here's the format:
>my.comdns1.blah.com
>me.comdns1.blah.com
>we.comdns1.blah.com
>you.com   dns1.blah.com
>
>How can I get ONLY the domain's out of that file, and print each domain to
>the screen.  I used this to search through httpd.conf once:
>open(APACHE_CONF, "/usr/local/apache/conf/httpd.conf") or die "Could not
>open Apache config file:\n$!\n";
> my @servernames;
> while() {
> push (@servernames, $1)
> if/ServerName\swww.(.*)/;
> }
>
>Can anyone help me?
>
>Thanks once again,
>Tyler
>
>
>--
>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: Comparing Arrays

2001-07-19 Thread Aaron Craig

At 15:21 19.07.2001 +0200, Diego Riaño wrote:
>Hi everybody
>
>I have two array, like this
>
>@array1=(one, two, three);
>@array2=(one,tww,three);
>
>Is there some way to compare the two arrays?
>I was trying with the eq and ne operations inside an IF statement but i
>does not work
>
>Could someone help me.
>
>
>Thanks
>
>Diego

This is a lot easier to do if you start out with a hash:

use strict;

my %hash1 = (one => 1, two => 1, three => 1);
my %hash2 = (one => 1, tww => 1, three => 1);
my @unique = grep{ !exists $hash2{$_} } keys %hash1;
print "$_\n" foreach (@unique);



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




Re: Help - Rookie question on Arrays

2001-05-18 Thread Aaron Craig

I haven't really played with grep at all, except for doing the standard 
stuff on dirs.

Your example is wonderfully concise -- is there any way that you can expand 
on this to get more information out of the test, ie which member of the 
array matches, or returning the member if this were in a function?

At 13:16 17.05.2001 -0700, you wrote:
>$TEST1 = "030";
>@HOLDER = ("020", "040", "034", "056", "030");
>
> > I need to find out if "030" is present in the array HOLDER
>
>print "gotit\n" if grep /^$TEST1$/, @HOLDER;

Aaron Craig
Programming
iSoftitler.com




Re: elegant REGEX

2001-05-18 Thread Aaron Craig

my $sLine = "test case total : 32456 allocated : 12000 from tech";
$sLine =~ /(\d+)[^\d]+(\d+)/;
my $lNumber1 = $1;
my $lNumber2 = $2;
print "number 1: $lNumber1 and number 2: $lNumber2";

At 02:34 18.05.2001 +0300, you wrote:
>Hi guys,
>can any one suggest me a REGEX to catch the numbers in the following
>input line:
>test case total : 32456 allocated : 12000 from tech
>
>I want to catch the two numbers and insert them to vars
>thx.

Aaron Craig
Programming
iSoftitler.com




Re: Help - Rookie question on Arrays

2001-05-18 Thread Aaron Craig

I've answered my own question:

my $ID = "020";

my $rh1 = {id => 1, value => "020", name => "one"};
my $rh2 = {id => 2, value => "040", name => "two"};
my $rh3 = {id => 3, value => "034", name => "three"};
my $rh4 = {id => 4, value => "056", name => "four"};
my $rh5 = {id => 5, value => "030", name => "five"};

my @HOLDER = ($rh1, $rh2, $rh3, $rh4, $rh5);

my @tester = grep($_->{value} eq $ID, @HOLDER);

Dump(\@tester, "tester", 0);

sub Dump($$$)
 {
 my($thing, $name, $lLevel) = @_;
 my $sTab = "\t" x $lLevel;
 $lLevel++;
 print "$sTab"."dumping $name\n";
 if(ref($thing) eq "ARRAY")
 {
 print "$sTab"."found array:\n";
 my $lCount = 0;
 foreach my $item (@{ $thing })
 {
 Dump($item, "element $lCount", $lLevel);
 $lCount++;
 }
 }
 elsif(ref($thing) eq "HASH")
 {
 print "$sTab"."found hash:\n";
 foreach my $key (sort(keys %{ $thing }))
 {
 Dump($thing->{$key}, $key, $lLevel);
 }
 }
 else
 {
 print "$sTab$thing\n";
 }
 }

At 09:50 18.05.2001 +0200, you wrote:
>I haven't really played with grep at all, except for doing the standard 
>stuff on dirs.
>
>Your example is wonderfully concise -- is there any way that you can 
>expand on this to get more information out of the test, ie which member of 
>the array matches, or returning the member if this were in a function?
>
>At 13:16 17.05.2001 -0700, you wrote:
>>$TEST1 = "030";
>>@HOLDER = ("020", "040", "034", "056", "030");
>>
>> > I need to find out if "030" is present in the array HOLDER
>>
>>print "gotit\n" if grep /^$TEST1$/, @HOLDER;
>
>Aaron Craig
>Programming
>iSoftitler.com
>

Aaron Craig
Programming
iSoftitler.com




Re: Testing Perl CGI scripts under Windows 98 & Personal Web Server

2001-05-18 Thread Aaron Craig

I have had personal experience with Personal Web Server -- I switched to 
Apache.

At 10:30 18.05.2001 -0500, you wrote:

>I'm trying to test my program under Personal Web Server, and when the Perl
>script runs (called from an HTML page, with passed parameters), it opens a
>DOS window and prompts for input.  Now, if I run it from a DOS window, with
>parameters, it runs, but prints to the DOS window.  If I redirect my output
>to an HTML file, then open THAT in the browser, I get what I want.  I've
>checked the script paths in the registry, and they're fine.  I can't think
>what else is wrong, but obviously it's something in the Personal Web Server
>or the configuration of the browser itsefl.  I are SO cornfuzzied.  Any
>ideas, hints, tips, suggestions, comments, wild Canadian waterfowl of
>cantankerous disposition?
>___
>Kristopher Cook (mailto:\\[EMAIL PROTECTED])
>e-Commerce Director
>Galyan's Trading Company
>(317) 532-0200 x239
>(317) 532-0258 (fax)

Aaron Craig
Programming
iSoftitler.com




Re: copying an array

2001-05-19 Thread Aaron Craig

As long as we're on the topic, what's the story on efficiency between using 
an array and an array ref.  Ex:

sub PassAnEntireArray(@)
 {
 my(@array) = @_;
 ...do some stuff...
 }

sub PassAnArrayRef($)
 {
 my($ar) = @_;
 ... do some stuff...
 }

I assume passing array refs (and hash refs for that matter) would be faster 
and more efficient -- does anyone have any definitive answer?

At 14:04 18.05.2001 -0400, you wrote:

>Edson Manners wrote:
>: I'm currently copying two 1-dimensional arrays using
>: for loops. Is there an easier way as this may tag my
>: cpu due to the huge numbers I am using.
>
>@copyOfArray = @array;
>
>is the usual way to copy arrays. Question., though: Is it absolutely
>necessary to copy the arrays for what you're doing? If they're large,
>this might be worth thinking about.
>
>-- tdk

Aaron Craig
Programming
iSoftitler.com




Re: GIF error

2001-05-19 Thread Aaron Craig

Could we have a look at the code?

At 05:52 19.05.2001 -0700, you wrote:
>I wrote a cgi script in perl that successfully calls a program which
>returns a gif image, but the image is not returned to the browser,
>rather it ends up in script_log and a I get a broken image place
>holder in the browser?!
>
>Any clues?
>
>  --jab
>
>=
>John Bollinger, CFA, CMT
>www.BollingerBands.com
>
>__
>Do You Yahoo!?
>Yahoo! Auctions - buy the things you want at great prices
>http://auctions.yahoo.com/

Aaron Craig
Programming
iSoftitler.com




Re: GIF error

2001-05-19 Thread Aaron Craig

At 05:52 19.05.2001 -0700, you wrote:
>I wrote a cgi script in perl that successfully calls a program which
>returns a gif image, but the image is not returned to the browser,
>rather it ends up in script_log and a I get a broken image place
>holder in the browser?!
>
>Any clues?
>
>  --jab


>#!/usr/bin/perl -w
>
>
># SingleChart.pl
># generate a chart in HTTP response format, i.e. it contains HTTP
># mime header and the image binary data.
>

Though it doesn't have anything to do with your problem, I highly recommend 
using 'strict' -- it keeps silly typo errors for popping up, among other 
things.

>require("./cgi-lib.pl") ||  die "can't locate cgi-lib.pl";
>require("./share-lib.pl") ||  die "can't locate share-lib.pl";

If you do use strict, you'll probably have problems requiring the above 
scripts -- this is a good thing.  You'll notice that if you have two 
functions with the same name in your SingleChart.pl and in one of the above 
required scripts, things will get funky.  Using strict also forces you to 
keep your namespace clean.

>&ReadParse(*para);
>$| = 1;
>#&checkSCode;
>foreach $name ( keys(%para) ) {
> push(@query, "$name=$para{$name}");
>}
>$comline = join("\\\&", @query);
>#print $comline;
># generate the chart by calling 'gifChart'
>system("./gifChart $comline");

I notice that you don't send anything back to the browser.  I don't know 
what your gifChart program does.  Have you tried setting some variable to 
the output that you get from gifChart and then sending that back to the 
browser?


Aaron Craig
Programming
iSoftitler.com




Re: GIF error

2001-05-20 Thread Aaron Craig

It's probably got something to do with gifChart.  The log has the word 
stdout immediately before what I assume must be the gif is printed.  These 
may lead us to believe that gifChart is trying to print its gif out to 
stdout, though that may not be necessarily the case.

It's difficult to see exactly what's happening just from the small chunk of 
code you sent.  The problem probably lies in where the gifChart program is 
being told to send its output to.  I notice that the $comline variable 
holds all of your switches and commands for gifChart.  Have you double 
checked to make sure they are all correct?  Is there a switch that tells 
gifChart where to send its output to?

At 08:45 19.05.2001 -0700, you wrote:


> > I notice that you don't send anything back to the browser.  I
>don't
> > know
> > what your gifChart program does.  Have you tried setting some
> > variable to
> > the output that you get from gifChart and then sending that back to
> > the
> > browser?
>
>gifChart simply returns a gif.
>
>This script is called muliple times by another script that provides
>an HTML wrapper for the gifs, but the ouput from this script is
>ending up in apache's script_log while the boilerplate goes to the
>browser.

Aaron Craig
Programming
iSoftitler.com




Re: GIF error

2001-05-20 Thread Aaron Craig

At 14:19 19.05.2001 -0700, you wrote:
>--- Jos I Boumans <[EMAIL PROTECTED]> wrote:
>
> > a good time to start modularising it to provide better and safer
> > access
>
>I though it was pretty modulerised as is. Perhaps I miss your point?
>My problem is that the output is ending up in script_log, not in the
>calling procedure.


Modularizing in this case means making those .pl scripts that you're 
including into actual modules (.pm scripts) so that they are in separate 
namespaces, and you don't them stomping all over each other's memory.  For 
now, you're not having problems, but it's a guarantee that you eventually 
will have problems setting up your scripts the way you have them now.  I 
know -- not long ago I wrote a web site management program using requires 
all through it -- I didn't know how to make a Perl module at the time.  I'm 
in the process of re-writing the whole entire program.  I learned the hard 
way that when you don't set things up in a safe way, you leave yourself 
open to all sorts of problems.

As for your problem at hand, are you sure that the two scripts you include 
do not change STDOUT in any way?  They may be redirecting your gif to the 
log file.




Aaron Craig
Programming
iSoftitler.com




Re: copying an array

2001-05-21 Thread Aaron Craig

At 12:49 20.05.2001 -0400, you wrote:

>Before I answer your question, I have to ask you to not use subroutine
>prototypes.  9 out of 10 Perl programmers use them incorrectly or don't
>know what they do.
>
>That being said, there are TWO really useful uses:
>
>   sub my_map (&@) {
> my $code = shift;
> my @return;
> push @return, $code->($_) for @_;
> return @return;
>   }
>
>That makes a function that allows for a naked block as its first argument:
>
>   @results = my_map { $_ * 2 } (1,2,3,4);
>
>And the other use:
>
>   sub my_push (\@@) {
> my $aref = shift;
> push @$aref, @_;
>   }
>
>That allows you to send an array to the function BY REFERENCE, without
>typing the backslash when the function is called:
>
>   my_push @foo, 1, 3, 5, 7;

I also like prototyping for its debugging and safety net behavior.  It 
kindly catches erroneous parameter passing.



Aaron Craig
Programming
iSoftitler.com




Re: regarding pragmas

2001-05-21 Thread Aaron Craig

You do have the appropriate modules in your perl\lib directory?

At 09:55 21.05.2001 +0530, you wrote:
>hi
>i am very new to perl. now iam in the process of learning modules.
>I am not able to use the following in my program:
>use strict;
>use warnings;
>use dumper; etc
>these r the only things i have tried to use.
>can any one eloborate on it in detail. it wil be really helpful for me to 
>continue learning perl
>Thank you
>Regards
>babylakshmi
>
>
>_
>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>

Aaron Craig
Programming
iSoftitler.com




Re: Beginner question

2001-05-22 Thread Aaron Craig



At 11:09 21.05.2001 -0700, you wrote:
>if ($oldLot[1] == 0)
>{
>   $arpCount = $arp{$lot};   ==> Part 1
>}
>else
>{
>   $arpCount = "-";  ==> Part 2
>}
>
>printf "%3s %3d   ", $arpCount, $count;
>
>My problem occurs in the  "printf" at the "%3s". Here
>is the situation: When $oldLot[1] == 0, $arpCount is
>equal to an integer, but when $oldLot[1] != 0
>$arpCount is equal to a character. the printf
>foramtting will only allow me to print 'either' a
>character or an integer. how can I do both or how can
>I change the integer into a character variable so that
>it will work under the %s?


I know this is really un-Perl, but I always try to keep my number variables 
separate from my string variables.  It keeps things clean, and debugging is 
a lot easier, because you don't have to worry about whether or not Perl is 
turning a number into a letter for you, or vice-versa.  Call it my C++ 
influence, but I find mixing numbers and strings in the same variable a 
rather risky business.


Aaron Craig
Programming
iSoftitler.com




Re: use lib directive

2001-05-22 Thread Aaron Craig

I have the same problem with a client of mine -- unfortunately, unless you 
have your own server, your stuck with their setup.

I've gotten around the problem using the I switch in the shebang line:

#!/usr/bin/perl -I./lib

after than, I can include any module living in my lib directory the same 
way I include those in the regular lib directory:

use strict;
use X;
use Web::X; # which is in a directory called Web in my lib directory

This has worked for me both with UNIX type servers, as well as with Windows 
(ugh!) servers.

At 14:23 21.05.2001 -0400, you wrote:
>Hello, I am attempting to develop my first module.  Because of 
>permissions/security, etc..  I cannot store the module in the standard 
>perl lib directories.  So it is currently living in a subdir called lib in 
>my home directory.  I use a "use lib" directive to add this directory to 
>@INC.  this works , but when I try then to use another module that does 
>reside in the standard lib directories, I get a "Can't locate object 
>method "new" in module "X" at path-specified-in -use-lib-directive.
>
>When I print the elements of @INC all of the standard directories are 
>printed as is the new one I've specified.  I've also tried putting the 
>directory into @INC using push, but I get the same error message.
>
>I am using Perl 5.00501 on SunOS 5.6.
>
>Thanks!
>
>
>Peter Cline
>Inet Developer
>New York Times Digital
>

Aaron Craig
Programming
iSoftitler.com




Re: Win32::API

2001-05-22 Thread Aaron Craig

Read up on pack() and unpack().  We use it to get C++ structures from a dll 
and throw them into a hash ref and vice versa.

The basic concept would be for your dll or whatever to pass a pointer to 
your perl script.  Your perl script would then unpack() it as a long into a 
variable.  For perl, that's the same thing as a string which happens to be 
a number.  If you know how much memory each of your members of your 
structure takes up, you can then (probably using another dll) get back into 
memory and read off the memory piece by piece.  Convoluted?  Definitely -- 
we have way too much time on our hands :)

At 23:06 21.05.2001 -0700, you wrote:
>Hello,
>
>
>I would like to know how to use win32 functions which
>take structures as their parameter.
>For example, the API 'SHBrowseForFolder' take the
>following structure:
>
>typedef struct _browseinfo {
> HWND hwndOwner;
> LPCITEMIDLIST pidlRoot;
> LPTSTR pszDisplayName;
> LPCTSTR lpszTitle;
> UINT ulFlags;
> BFFCALLBACK lpfn;
> LPARAM lParam;
> int iImage;
>};
>
>How do i 'translate' this structure and use this
>function with Win32::API module?
>
>Any sample code?
>
>Thanks in Advance,
>
>
>H3li0
>
>
>______
>Do You Yahoo!?
>Yahoo! Auctions - buy the things you want at great prices
>http://auctions.yahoo.com/

Aaron Craig
Programming
iSoftitler.com




Re: Dynamic regular expressions

2001-05-22 Thread Aaron Craig

Try this:

my $stringToMatch = "hello";
my $runtimeRegExp = "he";
print $stringToMatch." world" if($stringToMatch =~ /$runtimeRegExp/gi);

At 09:23 22.05.2001 -0400, you wrote:

>Hi people,
>
> I need to match string against regular expressions that are only
>known at run-time. I'm having problems doing it so I made a small test
>script like the following :
>
>#!/net/tcmvega35/data1/automation/perl/bin/perl -w
>
>use strict;
>die "test.pl [string] [regex]" unless $#ARGV == 1;
>
>if ($ARGV[0] =~ $ARGV[1])
>{
> print "$ARGV[0] matches $ARGV[1]\n";
>}
>else
>{
> print "$ARGV[0] does not match $ARGV[1]\n";
>}

Aaron Craig
Programming
iSoftitler.com




RE: Multiple submit buttons CGI question

2001-05-22 Thread Aaron Craig

I believe multiple submit buttons only send off the information for the 
form they are a part of.  If you have multiple forms, clicking one submit 
button will only get you that form sent off.

At 10:18 22.05.2001 -0700, you wrote:
>In the html:
>
>
>the 'value' attribute just set's up what the button text is, not a unique
>identifier for the button, so like tdk wrote, you need a name attribute to
>get the behavior you want.

Aaron Craig
Programming
iSoftitler.com




Re:[OT]function prototyping (was: copying an array)

2001-05-23 Thread Aaron Craig

At 15:12 22.05.2001 -0700, you wrote:

> > > The problem is:  PROTOTYPES MUST BE SEEN BEFORE THE FUNCTION IS
> > > CALLED. So few people realize that (for one reason or another[1]).
>
>For that reason, I usually do my function definitions at the top of my
>programs. That way they've already been thoroughly parsed before ever
>being called. I used to do that in my C code, too.

I did that too, but I got annoyed at having to remember to change the 
prototype at the top of the script whenever I changed my sub down below.


Aaron Craig
Programming
iSoftitler.com




Re: Require

2001-05-23 Thread Aaron Craig

I always that that modules were the domain of real Perl gurus, so I did a 
lot of requiring in my first Perl scripts.  After running into all sorts of 
problems with namespace, especially for global variable names, I decided to 
check out modules.  Surprise, surprise, they're simple!!

Without going into all of the theory behind them (which I didn't know the 
first thing about when I started using them), here is a module.

The file name of the module is MyModule.pm, and it lives in the lib 
directory off your root Perl directory.
___
package MyModule;

# this tells perl that it is the MyModule module

# all modules must return a value when they compile, so stick this line 
somewhere in your module -- I usually put it at the end of all my 
declarations and before the main code.
return 1;

# now we can start our subroutines

# this subroutine is required to make a module a module.  I won't go into 
exactly what it does -- suffice to say that it creates an object
# in memory that your script can have access to.  Copy and past this into 
your own module.

sub new()
   {
   my ($proto) = @_;
   my $class = ref($proto) || $proto;
   my $self = {};
   bless ($self, $class);
   return $self;
   }

# the rest of your subroutines go here.
# let's put in a dummy one, just to make sure everything is working
sub GetValue()
 {
 my($self) = @_;
 # what's this $self stuff?  Don't worry about it for now.  But the 
first parameter of any subroutine that you want visible to
 # the outside world should be $self.
 return 1;
 }

sub EchoInput()
 {
 my($self, $input) = @_;
 return $input;
 }
_

Now, you'll want to use your new module.

Let's say we have a script called MyScript.pl.  Here it is:

___
#! perl
# above is the shebang line, and you'll all notice I'm on a M$ OS :)

# let's get access to our module
# this command tells perl to grab the module and stick into memory
use MyModule;

# we still can't use it though -- we have to assign it to a variable:
my $mod = MyModule->new();

# now, $mod contains all of our subroutines in the MyModule module, which 
we call like this
my $value = $mod->GetValue();

# the arrow (->) means that referring to a pointer, to use C++ terminology. 
Without going into great detail, the line above in plain English
# means "set the variable $value to whatever you get back from the 
subroutine GetValue inside the $mod object"

print "The value is $value\n";

my $echo = $mod->EchoInput("hello world");
print "The echo is $echo\n";
__

See how easy modules are?

At 06:33 23.05.2001 +1000, you wrote:


>Hello All,
>
>I am new to Perl and putting together a script that needs about 20 reasonably
>complex subroutines.
>
>To keep the code as modular and managable as possible I would prefer not to
>define all the routines in the main script.
>
>It seems like using 'require' is the way to go (since I don't have the time or
>experience to do modules at the moment).

Aaron Craig
Programming
iSoftitler.com




Re: Require

2001-05-24 Thread Aaron Craig

At 09:33 23.05.2001 -0700, you wrote:

> >
> > # all modules must return a value when they compile, so stick this
> > line
> > somewhere in your module -- I usually put it at the end of all my
> > declarations and before the main code.
> > return 1;
>
>This is why, when you look at someone else's module, the last line of
>"code" is usually
>  1;

Oops - you have a point.  I use plain old 1 as well -- quick typing will 
always get you in trouble :)

>new() is NOT required to make a module.
>Some sort of constructor is a good idea if you're making an object
>class, but you don't have to do objects to make a module.
>Admittedly, most of the modules I write *are* OO, but it's not
>*necessary*.
>
> > sub new()
> >{
> >my ($proto) = @_;
> >my $class = ref($proto) || $proto;
> >my $self = {};
> >bless ($self, $class);
> >return $self;
> >}

You're right - but in 99% of the modules you use, they have a 
constructor.  Makes it nice and easy to keep your code straight and simple, 
since now you can say $mod->Function() instead of Module::Function.  I like 
thinking in pointers :)

>A module can be as simple as myFoo.pm:
>
>   package myFoo;
>   sub foo { print "bar!\n" }
>   1;
>
>which can be used by foo.pl:
>
>   use myFoo;
>   myFoo::foo;
>
>now say
>   perl foo.pl
>and it should respond with
>   bar!
>
>That's the simplest gist of it, though you can always use Exporter and
>objects and bootstrap some XS if you like. It's just not *required*.
>=o)

My idea was to give a template for a real-world module that a beginner 
could play around with immediately.  That's what I used for my first 
module, and it made my life so easy.  I didn't know what bless() did, but I 
did enjoy the benefits of bless()ing long before I got around to learning 
about what it actually does.  Having a guide for the more complicated stuff 
allows you to avoid future pitfalls because you've done things the safe 
way, without yet knowing why you did it that way.  Since I do this stuff 
for a living, most of the time the important thing is to get the project 
working -- figuring out how I got it to work is done on Saturday over a 
cold beer :)



Aaron Craig
Programming
iSoftitler.com




Re: Return values from Module

2001-05-24 Thread Aaron Craig

At 08:46 24.05.2001 +1000, you wrote:
>

>  $sth->finish;
>  #print "sumSales:\t$sales, $count\n\n";
>  if (@row){return @row};
>}

Probably has nothing to do with your problem, but as a matter of habit, I 
like passing around references instead of entire arrays or hashes.

Try returning \@row, which will give you a reference to that array in your 
call, ie.
my $sales = myMod::sumSales(@arg);

now $sales (if your function returns correctly) is an array which you can 
access by using $sales->[0]

>The sub is called like:
>
>my @sales = myMod::sumSales(@arg)
>  || die "Unable to complete sumSales routine: $!\n";
>where @arg only has one element.
>
>The doco about return says "The supplied expersion will be evaluated in the
>context of the subroutine invocation.  That is, if the subroutine was 
>called in
>a scalar context , EXPR is also evaluated in a scalar context.  If the
>subroutine was invoked in a list context then EXPR is also evaluated in a
>listcontext and can return a list value."
>
>I'm guessing that this is the problem but have no idea what it means...
>
>Any help would be appreciated.
>
>Thanks
>
>
>john

Aaron Craig
Programming
iSoftitler.com




Interesting? regexp

2001-05-24 Thread Aaron Craig


Here's a reg exp problem that's got me up at night.  I'm looking for 
currency and numbers in various formats.  The currency symbol and the 
actual character code of the number I'm looking for may vary, depending on 
the file I'm looking at, as we're working in Unicode and looking at 
languages from all over the world.  I'm also using utf8.

Basically valid formats would be:
$123
$ 123
123$
123 $

and up to here, I'm okay:

my $sText = "Foo $ 123 bar 123$ hello $123 world 123 $";
my $reNumber   = "\x{0030}-\x{0039}"; # these may be different depending on 
the language, but let's work with English
my $reCurrency = "\\x{0024}|\\x{00a3}"; # just to keep it simple
my @asCurrencies = $sText =~ 
/[$reNumber]?\x{0020}?[$reCurrency]\x{0020}?[$reNumber]?/g;
foreach my $currency (@asCurrencies)
 {
 print "$currency\n";
 }

ok.

I want to add in the text for currency symbols, like "dollar" and "pound", 
so that I match on either a currency symbol or a currency word and grab the 
numbers to the left of to the right.

Here are the strings for those already formatted for utf8:

my $string = 
"(\x{0064}\x{006f}\x{006c}\x{006c}\x{0061}\x{0072}\x{0073})|(\x{0070}\x{006f}\x{0075}\x{006e}\x{0064}\x{0073})";
 
# (dollar)|(pound)

I've tried all sorts of variations on parentheses etc. in the reg exp, to 
no avail.  I've checked the docs on forward and backward checking, and 
messed around with it some, but either that's not what I need, or I haven't 
completely grasped the concept yet.

Any ideas?


Aaron Craig
Programming
iSoftitler.com




Re: run perl in Win 2000 ?

2001-05-29 Thread Aaron Craig

At 13:20 28.05.2001 -0500, you wrote:
> > The #! operator does not work.
>
>Yes, the #! operator doesn't help in getting perl
>to execute (though you should still use it to set
>execution options like -w etc.)

you need to use

#! perl (followed by whatever switches you want to use)

and have perl in your path
To set perl in your path go to:
Start > Settings > Control Panel
In the control panel go to System
Click the upper right tab "Advanced"
Click the middle button "Environment Variables"
The bottom text box contains your system variables.  Find Path, highlight 
it, and click Edit...
At the end of the path type a semi-colon and the path to your perl.exe

>On Windows, you should use the usual Windows
>ways of doing this sort of thing. I think the most
>common Windows idiom is to give all perl scripts
>a particular extension, say .pl, and then create a
>file association from .pl to the perl interpreter.

Actually, all my perl extensions (.pl, .pm, .cgi) are associated with my 
text editor -- to make them run, perl has to be set in the path.


Aaron Craig
Programming
iSoftitler.com




Re: run perl in Win 2000 ?

2001-05-29 Thread Aaron Craig

At 11:22 29.05.2001 +0100, you wrote:
> > you need to use
> >
> > #! perl (followed by whatever switches you want to use)
>The shebang is a typical UNIX thing, Windows doesn't use it.
>It mentions the "shell" used to execute the code below.
>Like mentioned before, you're explorer needs to be properly configgered.
>Some webservers on Windows DO look at that line (altho I don't know why)
>Apache & IIS don't need it, Xitami ,AFAIK, does.

You're right - except when you want to include other lib paths or use switches.

Since you often don't have control over the modules that are on a given 
server, I tend to install my own in a directory /lib off the cgi-bin 
directory.  That means I have to tell perl where to look for the modules 
I'm using that may not be included in the servers main lib directory.  So, 
I have to do something like
#! perl -I./lib

I end up using #! perl out of habit, even if I don't end up using switches.



Aaron Craig
Programming
iSoftitler.com




Re: How to delete an element in array?

2001-05-30 Thread Aaron Craig

At 11:12 29.05.2001 -0700, you wrote:

>Uh, careful.  This got added to 5.6.1 to support pseudo-hashes and is
>probably coming back out when pseudo-hashes get removed in 5.10.
>("Death to pseudo-hashes!")

pseudo-hash?
Aaron Craig
Programming
iSoftitler.com