Help needed with setting up a SMTP connection

2001-06-13 Thread Adrienne Kotze

Hi there,

I'm trying to setup a SMTP connection to a server. From the Perl Cookbook
I got the following:

1) To start a new connection:

$mailer = Mail::Mailer->new ("smtp", "smtp.mydomain.com") ;

2) To open a connection (this is were the problem is I think), I tried the
following 
three:

$mailer->open ({ From => 'me <[EMAIL PROTECTED]>',
To => 'you <[EMAIL PROTECTED]>',
Subject => 'Test',
}) ;

$mailer->open ( 'From' => 'me <[EMAIL PROTECTED]>',
'To' => 'you <[EMAIL PROTECTED]>',
'Subject' => 'Test'
) ;
 
$mailer->open ( From => 'me <[EMAIL PROTECTED]>',
To => 'you <[EMAIL PROTECTED]>',
Subject => 'Test'
) ;

With the first one, I get this error:
Odd number of elements in hash assignment at lib/Mail/Mailer/smtp.pm line 13.
Died at lib/Mail/Mailer.pm line 270.

With the second and third one, I get this error:
Can't use string ("From") as a HASH ref while "strict refs" in use at
lib/Mail/Mailer.pm line 285. 

3) Then I close my connection with:

$mailer->close () ;

Could someone please point out my error here ?

Thanx.
-- 
Adrienne Kotze -  Technical Consultant - Sintrex Integration Service
Mobile: +27 83 269 6725 - Facsimile: +27 83 8 269 6725
mailto:[EMAIL PROTECTED]




Re: editing a file

2001-06-13 Thread Me

>  # form a script
>  local($^I, @ARGV) = ('.bak', glob("*.c"));
>  while (<>) {
>  if ($. == 1) {
>  print "This line should appear at the top of each
file\n";
>  }
>  s/\b(p)earl\b/${1}erl/i;# Correct typos,
preserving case
>  print;
>  close ARGV if eof;  # Reset $.
>  }

A quick glance shows this is going to read through
*.c files, modifying them (and renaming the old file
to *.c.bak). In each file, it's going to stick a line at
the top and change pearl to perl.

(Both the one liner and this are clearly someone
experimenting.)

>  # form a script

This isn't a complete script in a traditional sense.
Usually a perl script starts with:

#!/usr/bin/perl -w

or similar.

Anyhow:

>  local($^I, @ARGV) = ('.bak', glob("*.c"));

local $foo = "bar";
local ($foo, $bar) = ("foo", "bar");

sets the variables listed on the left to the values
listed on the right. There are four ways to do this:

$foo = "foo";
my $foo = "foo";
our $foo = "foo";
local $foo = "foo";

(ok, there's lots more ways, but these are some
basics.)

our and local should refer to a global variable.
local is a form of our that tells perl to forget the
"local" value when the current {} pair is exited.

@ARGV = (1, 2);
{
local @ARGV = (3, 4);
# @ARGV contains (3, 4)...
}
# @ARGV contains (1, 2)...

In this case, the script is setting $^I and @ARGV.

$^I is the same as the -i switch at a shell prompt /
command line.

Set $^I to '' (null string) to switch inplace editing on,
without backups. Set it to a string to have backups
created with the string added to the backup name.
(You can get clever with this naming. See the doc.)

@ARGV is the list of "arguments" to the script. The
glob() takes its parameter and returns all the matching
directory entries; so in this case, @ARGV will end up
with a bunch of *.c files (presuming there are some to
match).

(When you use something like *.c at a shell prompt,
the shell does something akin to the glob() itself. So
if you do "perl -pi -e 's/foo/bar' *.c" the perl code will
operate on all the directory entries matching *.c in the
current directory.)

So, what the initial local line does is set up the rest of
the script to work on inplace editing a bunch of *.c
files, and it localizes the changes to $^I and @ARGV
just in case this bit of code is embedded in a larger
bunch of perl code that might also make use of these
variables.

>  while (<>) {

A wonderful perl idiom.

This means keep grabbing lines from input, as long
as there are lines to grab. In this case, input is from
the files listed in @ARGV, one by one until all the
lines in all the files are used up, then the while quits.

The current line is stuffed into $_, the default variable
on which things like s/// and print work if not told what
variable to work on.

>  if ($. == 1) {
>  print "This line should appear at the top of each
file\n";

$. is the line number in the current file.

>  s/\b(p)earl\b/${1}erl/i;# Correct typos,
preserving case

A pretty bizarre s/// to change pearl to perl.

\b means word boundary. Which means anywhere that
is in the middle of two characters in a string and on the
left, the character is alphanumeric (or a _) and on the
right it is not. Or vice versa. (\b also matches at the
start or end of a string.)

${foo} is the same as $foo. You usually use it if not using
it would make perl think you are talking about some other
variable than the one you mean. For example:

${foo}bar;
$foobar;

The second one is the variable $foo followed by the
literal text 'bar'.

the /i on the end of the s/// means ignore case.

>  print;

Print $_ (the current line).

>  close ARGV if eof;  # Reset $.

Not usually needed. But in this case, the programmer
wants to reset $. (line number) as each new input file
is opened.

eof tests for end of file on the current file.

(eof() tests for end of file on the last file.)

---

Now, don't DARE tell me you didn't need to know
all this once you knew they were experiments... :>




Re: editing a file

2001-06-13 Thread Me

Oops, hadn't finished.

's/(^\s+test\s+)\d+/ $1 . ++$count /e'

Breaking this down,

s/foo/bar/

means, search $_ ($_ is the current line in many
scripts) for something, and then replace what is
matched with something else.

s/foo(bar)baz/$1/

replaces foobarbaz with bar. Parens "capture"
part of a match. $1 replaces with the captured
bit.

(If you use two parens in the search part, then $2
contains whatever is captured by the second
paren pair, and so on. (Paren pairs can overlap;
the Nth opening parens starts the capture for the
$N variable.) There's lots more subtleties to let
you express what you need, but that can wait. ;>)

s/foo/bar/e

means execute the replacement as if it were perl
expression yielding a result, then use the result of
that as the replacement. (This would be an error
for the example above; bar isn't a perl command.)

s/^foo/bar/

means only match foo at the start of what's in $_.
(Unless you tell perl to be more clever.)

s/\s\d/bar/

means match a white space character, then a
digit.

++$foo

means add one to foo, then use its value.
If $foo is undefined, perl treats it as zero.
So the above comes out as 1 the first time,
2 the second...

$foo . $bar

concatenates $foo and $bar into one string.

So

's/(^\s+test\s+)\d+/ $1 . ++$count /e'

matches any number of white space characters,
the word 'test' then any number of white space
characters, then any number of digits, then
replaces that with everything but the digits,
followed by an incrementing number starting
at 1.

-

So, one line explained...

;>




Re: editing a file

2001-06-13 Thread Me

Simplifying:

>  # Renumber a series of tests from the command line
>  perl -pi -e 's/(^\s+test\s+)\d+/ $1 . ++$count /e'
t/op/taint.t

This is what is called a "one-liner".
One enters the above at a shell prompt (command line).

The "perl -pi -e" combo is a common one for quick one liners.

You use it to read a file line by line, futz with each line
as you get it, then write it back to the file, overwriting it.

So:

perl -pi -e 's/foo/bar/' blah bleh

would, in each of the files blah and bleh,
replace the first foo on each line with bar.

Specifically:
-pread a line; do whatever code; print the line.
-i"inplace edit" input file(s), ie prints overwrite input file(s).
-e"execute" the perl code that follows.




Re: stdout/stderr

2001-06-13 Thread Me

> What would be the easiest way to capture [stderr]?

One way:

$output = `$cmd 2>&1 1>$null`;

$null depends on the os; /dev/null on unix, /nul on an M$ OS.






Re: This is odd to me

2001-06-13 Thread C.J. Collier

Kirk,

The most popular tutorial book for Perl is "Learning Perl" by Randal 
Schwartz et al. .   I started learning from it, and look where I am now 
*grin*

The 3rd edition should be coming out next month, so you may want to hold 
off on it and read some online docs 'till then, as it will probably have 
a lot of good stuff in it.

I personally don't trust any books that include a duration in the title :)

Cheers,
C.J.

>I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
>a couple web pages where you could submit a text file that would be posted
>onto the web (i.e. joke of the day sites).  I've written scripts that have
>taken
>files of lists of labels, compared them, then built a list of the ones that
>were
>in one an not the other file.  I thought that qualified me as a beginner.
>Then
>I join this group, and I get discussions of regexes and XML, etc.  I have
>no idea what a regex is!  What books have you guys (who I assume are
>beginners too, since that's the name of this board) been reading?  Turn
>me into a beginner too!
>
>Kirk
>






editing a file

2001-06-13 Thread Teresa Raymond

I'm having difficulty fully understanding what this code is 
saying/doing...  Could someone please, break it down for me into step 
by step pseudocode?  Thank you in advance.

 # Renumber a series of tests from the command line
 perl -pi -e 's/(^\s+test\s+)\d+/ $1 . ++$count /e' t/op/taint.t

 # form a script
 local($^I, @ARGV) = ('.bak', glob("*.c"));
 while (<>) {
 if ($. == 1) {
 print "This line should appear at the top of each file\n";
 }
 s/\b(p)earl\b/${1}erl/i;# Correct typos, preserving case
 print;
 close ARGV if eof;  # Reset $.
 }

*** Teresa Raymond
*** http://www.mariposanet.com
*** [EMAIL PROTECTED]



stdout/stderr

2001-06-13 Thread Ronald J. Yacketta

Folks,

What would be the easiest way to capture time output?
that is the output from time -p ps -ef > /dev/null,
time prints it output on stderr. I was going to use qx()
but that will not work, seeing qx (to my knowledge) does not
catch stderr correct?

I had another idea, but that is revert back to stupidity ;)
using system and sending the output to a file then open the file ;)

any ideas here?

Regards,
Ron




Re: regex on hash keys?

2001-06-13 Thread Paul Dean

Hya,

At 03:22 PM 13/06/2001 -0700, Hans Holtan wrote:
>Hi everyone,
>
>I'm a bit green, and I'm trying to split a large file into a hash. My 
>problem is that the parts that I want to use as keys are a bit long 
>(100-200 letters), and I will need to pull them out by the presence of 
>certain substrings later. So my actual question is this, how do I retreive 
>a slice from a hash based on substrings in their keys?

The "keys" func in perl will allow you to access the keys of your hash.
See also http://www.perl.com/pub/v/documentation for more helps...

>Thanks for your help.

/* Experience is that marvelous thing that enables you to recognize a 
mistake when you make it again.
Franklin P. Jones */




Re: Initializing / Changing values of @INC

2001-06-13 Thread Peter Scott

At 10:56 AM 6/14/01 +0900, Gupta, Ashish wrote:
> >From where is the value of @INC initialized by Perl ?

It's compiled in when perl is built.  Do a strings `which perl` | grep / 
and you'll see it.

>Can I change the value of @INC from within my program or from the
>environment ?

Both.  The former, with the lib pragma: perldoc lib.  The latter, with the 
PERL5LIB variable; perldoc perlrun and look for the Environment header.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Initializing / Changing values of @INC

2001-06-13 Thread Gupta, Ashish

>From where is the value of @INC initialized by Perl ?
Can I change the value of @INC from within my program or from the
environment ?




*** 
This communication is confidential and is intended only for the person 
to whom it is addressed.  If you are not that person, you are not 
permitted to make use of the information and you are requested to 
notify administrator [EMAIL PROTECTED] immediately that 
you have received it and then destroy/erase the copy/e-mail in your 
possession. 
*** 





FW: use of split command - concession

2001-06-13 Thread Steve Howard

OK, I had to try the two ways again to see how much difference it made. I
created a random contents fixed field file 14500 lines long X 80 columns
wide, and tried processing the lines (using substr($_,)to break lines up
into 4 sections, substitute based on a few patterns, and change a couple of
columns like I had given in my previous real life example) to see if loading
the entire file into an array made as much performance difference as I had
thought previously. The difference on a file that size was so small as to
not be worth mentioning. Either way, it processed the 14,500 line file in
less than three seconds and wrote the new contents to the new file. Granted,
I am using a different OS than when I did that test before, but still, the
difference was virtually indiscernible. Therefore, I'll concede my point
about a significant performance difference.

Steve Howard


-Original Message-
From: Steve Howard [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 5:46 PM
To: Jos Boumans
Cc: Stephen Henderson; [EMAIL PROTECTED]
Subject: RE: use of split command


The reason I preferred to read a file into an array (when it is manageable)
then processing it is because of my understanding of what is occurring with
IO. It seems to bear out in the performance when I have tested the two side
by side. When you are using:

while ()

you are accessing the disk for one line, then processing that line, making
another IO operation if you are writing to another line, then you start over
with another disk IO operation for the next line. Reading the file into an
array in one large chunk then processing it give one IO operation for
reading the file, then almost negligible processing time, and one IO
operation for writing it to another file.

When dealing with files that are too large to handle that way, I try to use
the dbd::csv (since I'm a DBA who works primarily on conversions, I usually
get nicely delimited files). or I have used files reading in about 1000
lines at a time to try to minimize the IO operations without killing my
available RAM.

Your point is well taken about putting error trapping, and using strict and
declaring local variables - those are things normally practiced, but things
I suppose I wrongly assumed to be outside the scope of the question asked
when responding here.

Steve Howard


-Original Message-
From: Jos Boumans [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 6:55 AM
To: Steve Howard
Cc: Stephen Henderson; [EMAIL PROTECTED]
Subject: Re: use of split command


I'd like to make a few adjustments on this code, and give you some things
you might want
to concider using:

open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
open Accessions
file ", $!;
# this will produce also the error returned by the system call... usefull
for figuring out
*why* the file wasnt opened
# you might want to concider putting the location in a var name, like $loc
and have open
operate on $loc... makes it easy if you use that file more often in the
script.

# depending on size of the file, you will probably want to do one of the
following:

#this will read the entire file into a string and will save you somewhere
around 24 bytes
per line compared to an array
#quick math says that saves you ~2.4mb of ram on 100k lines
#putting it in a string is nice for doing s///, m// operations and passing
it around to
subroutines etc
*** Option 1 ***
my $in;
{local $/; $in =  }
while(split "\n", $in) {
my ($one, $two) = split "\t";#assuming a tabdelimited list again
# do something with those vars
}

#however, you might just want to lower memory load and use:
*** Option 2 ***
while () {
my ($one, $two) = split "\t";#assuming a tabdelimited list again
# do something with those vars
}

doing as mentioned below is not very smart, seeing it first copies all the
info to an
array, and then handles it one line at a time anyway in the for loop
this has the memory load of option 1, while it has the functionality of
option 2... the
worst of both worlds so to speak

last remark i want to make is that it's always good to run 'use strict' and
force yourself
to use lexicals (my'd vars).

hope this helps,

Jos Boumans

> open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
> open Accessions file";
> @ets=;
>
> foreach (@ets) {
>
> ($first, $second) = split(/\t/, $_);#(Splits current
on a tab: \t)
>
> # do what you need with the two variables
>
> }
>
> you are right, that is a very fast way to deal with files.
>
> If you have regularly delimited files, and would prefer to work with them
> using SQL like syntax, you might look at DBD::CSV for another alternative.
>




Re: uninitialized value in numeric error

2001-06-13 Thread Michael Fowler

On Wed, Jun 13, 2001 at 04:30:01PM -0700, David Kenneally wrote:
> Hello-
> 
> This is a really basic question, sorry. Can anybody tell me why I get the
> following error when I run this script:
> 
> "Use of uninitialized value in numeric lt (<) at ./x2 line 8"

"Use of uninitialized value" means you're relying on an undef value to give
you something meaningful, and Perl thinks this is probably not what you
meant.

 
> #!/usr/bin/perl -w
> 
> 
> opendir DIRH, "/home/dwk/test" or die "can't open it: $!\n";
> @allfiles = readdir DIRH;
> closedir DIRH;
> foreach $temp (@allfiles) {
>   if (-M $temp < "0.5") {

This is line 8, of course, and your undefined value is obviously not "0.5",
so it must be the -M $temp.  -M will return an undefined value if the
underlying stat on the file failed.  This is can be caused by various
things, but the most likely reason is that the file $temp doesn't exist. 
Your problem probably lies in the fact that $temp is going to be a relative
filename (as all files returned by readdir are) that doesn't exist in your
current working directory.

What you need to do chdir, then opendir ".":

chdir("/home/dwk/test") || die("chdir failed: $!\n");
opendir DIRH, "." or die "can't open it: $!\n";
...

OR prepend the directory name to all of your files

opendir ...
@allfiles = map { "/home/dwk/test/$_" } readdir(DIR);
...


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



Re: This is odd to me

2001-06-13 Thread Wen Niu

I think "Learning Perl" by Randal Schwartz and Tom Christiansen covers more than 
"Learn Perl in 24 Hours".

If you "really" wanna know something about regex, try "Mastering Regular 
Expressions" by Jeffrey Friedl, and enjoy ;=)

Of course, you can always consult "Programming Perl" by Larry Wall, Tom 
Christianse and Jon Orwant.

By the way, all three books are from O'Reilly.

Wen 

>I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
>a couple web pages where you could submit a text file that would be posted
>onto the web (i.e. joke of the day sites).  I've written scripts that have
>taken
>files of lists of labels, compared them, then built a list of the ones that
>were
>in one an not the other file.  I thought that qualified me as a beginner.
>Then
>I join this group, and I get discussions of regexes and XML, etc.  I have
>no idea what a regex is!  What books have you guys (who I assume are
>beginners too, since that's the name of this board) been reading?  Turn
>me into a beginner too!
>
>Kirk

- End Forwarded Message -





Re: Installed Modules

2001-06-13 Thread Elaine -HFB- Ashton

Dave Watson [[EMAIL PROTECTED]] quoth:
*>
*>Using ExtUtils::Installed like;

Thank you for attributing the FAQ :)

I can't say enough good things about Alan Burlisons oft overlooked
ExtUtils modules that have been in the core since 5.005 as I recall. There
are lots of fun features to them and I wholly encourage reading the docs.

*>or pmtools
*>http://language.perl.com/misc/pmtools-1.00.tar.gz

That URL, last I knew, gave me a corrupted file. If it still does, try
http://history.perl.org/src/pmtools-1.00.tar.gz

e.



RE: uninitialized value in numeric error

2001-06-13 Thread David Kenneally

Hello-

I get the error both when it is quoted and when it is not. It still works,
and I guess this is just a notification, but I was hoping there might be a
more correct way.

Thanks!

David "Not quite a Saint" Kenneally



>David,

>Verily, on Wednesday June 13, 2001, the Sainted David Kenneally spake:
> #!/usr/bin/perl -w
> 
> 
> opendir DIRH, "/home/dwk/test" or die "can't open it: $!\n";
> @allfiles = readdir DIRH;
> closedir DIRH;
> foreach $temp (@allfiles) {
>   if (-M $temp < "0.5") {
>print "$temp\n";
>} else {
>print "$temp is older than 12 hours\n";
>  }
>   }

Looks to me as the though the problem is with your comparison.
Enclosing "0.5" in quotes forces Perl to treat the 0.5 as a
string rather than a number.  This is called "stringification"
and is an easy mistake to make.

I should stress that I'm not certain this is causing your
problem.  However, I *am* certain that doing this is not
the best practice, and I highly recommend that you quote
things only when absolutely necessary.

Short answer: remove the quotes from "0.5" and try it
again. :)

HTH,

John
-- 
   John Fox <[EMAIL PROTECTED]>
System Administrator, InfoStructure, Ashland OR USA
  -
"What is loved endures.  And Babylon 5 ... Babylon 5 endures."
  --Delenn, "Rising Stars", Babylon 5



Re: Installed Modules

2001-06-13 Thread Dave Watson

--scott lutz <[EMAIL PROTECTED]> [010613 16:17]:
> Is there a command to list all installed modules?
> _
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
> 

Yes.  There are a few ways.

perldoc perlocal

Using ExtUtils::Installed like;

#!/usr/bin/perl
use ExtUtils::Installed;
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module) || "???";
   print "$module -- $version\n";
}

or pmtools
http://language.perl.com/misc/pmtools-1.00.tar.gz
-- 
Dave Watson



Re: uninitialized value in numeric error

2001-06-13 Thread John Fox

David,

Verily, on Wednesday June 13, 2001, the Sainted David Kenneally spake:
> #!/usr/bin/perl -w
> 
> 
> opendir DIRH, "/home/dwk/test" or die "can't open it: $!\n";
> @allfiles = readdir DIRH;
> closedir DIRH;
> foreach $temp (@allfiles) {
>   if (-M $temp < "0.5") {
>print "$temp\n";
>} else {
>print "$temp is older than 12 hours\n";
>  }
>   }

Looks to me as the though the problem is with your comparison.
Enclosing "0.5" in quotes forces Perl to treat the 0.5 as a
string rather than a number.  This is called "stringification"
and is an easy mistake to make.

I should stress that I'm not certain this is causing your
problem.  However, I *am* certain that doing this is not
the best practice, and I highly recommend that you quote
things only when absolutely necessary.

Short answer: remove the quotes from "0.5" and try it
again. :)

HTH,

John
-- 
   John Fox <[EMAIL PROTECTED]>
System Administrator, InfoStructure, Ashland OR USA
  -
"What is loved endures.  And Babylon 5 ... Babylon 5 endures."
  --Delenn, "Rising Stars", Babylon 5



php -> perl

2001-06-13 Thread Michael Cartwright

Hi all,

The point of this script is to get arround setting application MIME types on
the server for when you don't have the right to do that on your server. It
will fetch any file as any MIME type. It adds the file extension and
defaults to "example.opx" if there is no filename given.

However, I need it in Perl. Could someone help me with what would this look
like in Perl?

Thanks,
Michael






Re: Installed Modules

2001-06-13 Thread Kevin Meltzer

There are a few ways. My favorite is to use:

perl -MCPAN -e autobundle

This will create a file (and display) all modules installed in the @INC paths,
as well as their versions. It also tells you the versions currently on the
CPAN. 

perldoc CPAN

for more information on the useful CPAN module.

You can also use a script to recurse through the directories in @INC:

#!/usr/bin/perl
use File::Find;
foreach $start (@INC) { find(\&modules, $start); }
# NOTES
#   1. Prune man, pod, etc. directories
#   2. Skip files with a suffix other than .pm
#   3. Format the filename so that it looks more like a module
#   4. Print it
sub modules {
if (-d && /^[a-z]/) { $File::Find::prune = 1; return; }# Note 1
return unless /\.pm$/; # Note 2
my $filename = "$File::Find::dir/$_";
$filename =~ s!^$start/!!; # Note 3
$filename =~ s!\.pm$!!;
$filename =~ s!/!::!g;
print "$filename\n";   # Note 4
}

Or, you can do (as seen on
http://www.cpan.org/misc/cpan-faq.html#How_installed_modules
):

perldoc perllocal

I generally use the 'autobundle', so I can quickly see how out of whack my
local modules are :)

Cheers,
Kevin


On Wed, Jun 13, 2001 at 11:17:10PM -, scott lutz ([EMAIL PROTECTED]) spew-ed 
forth:
> Is there a command to list all installed modules?
> _
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
> 

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
All people have the right to be stupid, some people just abuse it!
-- Frank Zappa



uninitialized value in numeric error

2001-06-13 Thread David Kenneally

Hello-

This is a really basic question, sorry. Can anybody tell me why I get the
following error when I run this script:

"Use of uninitialized value in numeric lt (<) at ./x2 line 8"


#!/usr/bin/perl -w


opendir DIRH, "/home/dwk/test" or die "can't open it: $!\n";
@allfiles = readdir DIRH;
closedir DIRH;
foreach $temp (@allfiles) {
  if (-M $temp < "0.5") {
   print "$temp\n";
   } else {
   print "$temp is older than 12 hours\n";
 }
  }


I just want it to be able to distinguish between files that are older than
12 hours, and those that are newer (then I will build on it to do better
things than just print).

Thanks

David






Re: Installed Modules

2001-06-13 Thread Peter Scott

At 11:17 PM 6/13/01 +, scott lutz wrote:
>Is there a command to list all installed modules?

http://www.cpan.org/misc/cpan-faq.html#How_installed_modules
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Installed Modules

2001-06-13 Thread scott lutz

Is there a command to list all installed modules?
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




RE: More DBI hassels

2001-06-13 Thread Steve Howard

Can you give us an example of the code that is not connecting, or not
working? It's pretty difficult to answer with no more than we have to go on.

Steve Howard

-Original Message-
From: justin todd [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 7:22 AM
To: Beginners (E-mail)
Subject: More DBI hassels


I am very confused.

About a week ago I completed a site that used perl and connected to a
MSSQL7 database. Everything worked hunky dory.

Now I have to start a new script but when I try do a select query it is
as if the site goes into a internal loop. If I run the query directly on
the DB it works fine but when I try run it in the cgi-bin it dont work.
I have set up my ODBC driver to connect to the correct table.

I have done everything the same as before but this time it dont work.

Any ideas?

Justin




RE: use of split command

2001-06-13 Thread Steve Howard

The reason I preferred to read a file into an array (when it is manageable)
then processing it is because of my understanding of what is occurring with
IO. It seems to bear out in the performance when I have tested the two side
by side. When you are using:

while ()

you are accessing the disk for one line, then processing that line, making
another IO operation if you are writing to another line, then you start over
with another disk IO operation for the next line. Reading the file into an
array in one large chunk then processing it give one IO operation for
reading the file, then almost negligible processing time, and one IO
operation for writing it to another file.

When dealing with files that are too large to handle that way, I try to use
the dbd::csv (since I'm a DBA who works primarily on conversions, I usually
get nicely delimited files). or I have used files reading in about 1000
lines at a time to try to minimize the IO operations without killing my
available RAM.

Your point is well taken about putting error trapping, and using strict and
declaring local variables - those are things normally practiced, but things
I suppose I wrongly assumed to be outside the scope of the question asked
when responding here.

Steve Howard


-Original Message-
From: Jos Boumans [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 6:55 AM
To: Steve Howard
Cc: Stephen Henderson; [EMAIL PROTECTED]
Subject: Re: use of split command


I'd like to make a few adjustments on this code, and give you some things
you might want
to concider using:

open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
open Accessions
file ", $!;
# this will produce also the error returned by the system call... usefull
for figuring out
*why* the file wasnt opened
# you might want to concider putting the location in a var name, like $loc
and have open
operate on $loc... makes it easy if you use that file more often in the
script.

# depending on size of the file, you will probably want to do one of the
following:

#this will read the entire file into a string and will save you somewhere
around 24 bytes
per line compared to an array
#quick math says that saves you ~2.4mb of ram on 100k lines
#putting it in a string is nice for doing s///, m// operations and passing
it around to
subroutines etc
*** Option 1 ***
my $in;
{local $/; $in =  }
while(split "\n", $in) {
my ($one, $two) = split "\t";#assuming a tabdelimited list again
# do something with those vars
}

#however, you might just want to lower memory load and use:
*** Option 2 ***
while () {
my ($one, $two) = split "\t";#assuming a tabdelimited list again
# do something with those vars
}

doing as mentioned below is not very smart, seeing it first copies all the
info to an
array, and then handles it one line at a time anyway in the for loop
this has the memory load of option 1, while it has the functionality of
option 2... the
worst of both worlds so to speak

last remark i want to make is that it's always good to run 'use strict' and
force yourself
to use lexicals (my'd vars).

hope this helps,

Jos Boumans

> open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accession.txt") or die "can't
> open Accessions file";
> @ets=;
>
> foreach (@ets) {
>
> ($first, $second) = split(/\t/, $_);#(Splits current
on a tab: \t)
>
> # do what you need with the two variables
>
> }
>
> you are right, that is a very fast way to deal with files.
>
> If you have regularly delimited files, and would prefer to work with them
> using SQL like syntax, you might look at DBD::CSV for another alternative.
>




RE: This is odd to me

2001-06-13 Thread Chad Blair

Regexes (regular expressions) are pretty important - I'm surprised the "24
hours" book didn't mention them.

I'd suggest reading O'Reilly's "Learning Perl" (aka "the llama book") for a
healthy introduction to regexes.

chad

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 2:32 PM
To: [EMAIL PROTECTED]
Subject: This is odd to me


I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
a couple web pages where you could submit a text file that would be posted
onto the web (i.e. joke of the day sites).  I've written scripts that have
taken
files of lists of labels, compared them, then built a list of the ones that
were
in one an not the other file.  I thought that qualified me as a beginner.
Then
I join this group, and I get discussions of regexes and XML, etc.  I have
no idea what a regex is!  What books have you guys (who I assume are
beginners too, since that's the name of this board) been reading?  Turn
me into a beginner too!

Kirk




Re: arrays problem

2001-06-13 Thread Michael Fowler

On Wed, Jun 13, 2001 at 06:00:34PM -0400, F.H wrote:
> 
> Michael,
> Thanks for taking the time to solve this problem. Of course those are not real ssn 
>numbers.
> I tried your suggestion:
> 
> 
> if ($key =~ /^Hobbies/i) {
> push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
> }
> }   
>  
> # print results
> print "\n TEST: $ssns{'123-43-4352'}{'hobbies'}[2][2]\n";

My mistake, this should be:

$ssns{'123-43-4352'}{'hobbies'}[0][2];

The 'H3' hobby is on the third -line-, but on the first -hobby- line.

See:
Name ,123-43-4352, JX, 1234
Sports,123-43-4352, SKI, BaseBall, swimming
Hobbies, 123-43-4352, H1,H2, H3
Hobbies, 123-43-4352, HH, HHH, 2
Hobbies,123-43-4352, H1,H43




> It came out with no results and down below in the foreach loop:
> It printed:
>   Hobbies are:
>  ARRAY(0xca6840) ARRAY(0xca6828) ARRAY(0xca67f8) ARRAY(0xca67a4)
> 
> Did I miss/skip something in the code?

No, you'll need to change your hobbies foreach statement:

print "  Hobbies are:\n";
foreach (sort @{$ssns{$_}{hobbies}}) {
print join(" ", @$_), " ";
}

Now $ssns{$_}{'hobbies'} is a list of lists, so you have to handle it as
such.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



Re: This is odd to me

2001-06-13 Thread Sean O'Leary

At 05:32 PM 6/13/2001, you wrote:
>I join this group, and I get discussions of regexes and XML, etc.  I have
>no idea what a regex is!  What books have you guys (who I assume are
>beginners too, since that's the name of this board) been reading?  Turn
>me into a beginner too!
>
>Kirk

Despair not.  You are a beginner.  : )

All a regex is a regular expression, which, I hope to high-heaven, were 
mentioned in Perl in 24 Hours.  I would think that doing your file parsing 
and such you would have had to have come across them.  If you need to know 
more about them, let us know.

As for all the XML stuff, I consider myself a passable Perl programmer, but 
I spend a *very* little time in XML-land, so I would qualify myself as 
sub-beginner as far as Perl with XML is concerned.  I've been keeping up 
with that thread because I know I'm going to need some of the tips 
mentioned when I finally get around to some real XML stuff.

As for books, you should really pick up Programming Perl, 3rd Edition, 
known throughout the community as the Camel Book, or just Camel.  If it 
pertains to Perl, it's in there.  And, frankly, I would not have 
recommended Perl in 24 Hours as anyone's first book.  (As an aside, it was 
the first book I picked up, but only because a good friend of mine had it, 
was willing to lend it to me for a bit, and we were both not-so-blissfully 
unaware of the great resources out there.)  If you feel like you are shaky 
on some of the basics you might want to check out the Llama Book, Learning 
Perl, to get up to speed.  But from your description of what you have 
accomplished, I don't know if you'll need it.  (BTW, when I returned 24 
Hours to my friend, I lent him my Llama Book too, and he was really amazed 
at how much clearer the explanations were, and how much more readable the 
code was.)

Both of the books mentioned above are published by O'Reilly and 
Associates.  Look around for the O'Reilly books with the light blue 
binding.  There be Perl.  And you'll figure out the animal nicknames when 
you see the covers.

Later,

Sean.




Re: Noobie question

2001-06-13 Thread Michael D . Risser

At least we were a little more friendly about it, as well as point to some 
resources that would be more help in the long run. And let's not forget 
TMTOWTDI.

--SNIP--
> Fucking typical.
--SNIP--
> I hope this answer is more useful than that suggested by the others.



Re: Noobie question

2001-06-13 Thread Chuck Ivy


On Wednesday, June 13, 2001, at 12:05 PM, Ward, Stefan wrote:

> Does anyone have an example of a way to write a perl script that will 
> go out
> hit a data base table, pull in a column for that table and use that 
> column
> in a dropdown list?  I know what to do once I get that variable 
> selected by
> RTFriendlyM, but couldn't find a clear example of this.
>

Gee, you get three responses with books to read, or URLs to visit, but 
nobody actually answering your question.

Fucking typical.

Excuse me.

Ok.

So you've read the manual, and you're doing your SELECT from the 
database. In many cases, I find myself getting both a value and a human 
readable text for my dropdown.

For sake of argument, let's say your dropdown was a list of web pages, 
and the VALUE for each  is the URL of the page.

So my statements might go something like...

my $sql = "SELECT URL, Name
FROM Links
ORDER BY Name";
my $sth = $dbh->prepare($sql) or die ("Cannot prepare query $sql");
my $sth->execute or die ("Cannot execute query $sql");
my @fields = '';
my $selectstatement = "";
while (@fields = $sth->fetchrow_array) {
$selectstatement .= "$fields[1]";
}
$selectstatement .= "";


I hope this answer is more useful than that suggested by the others.



regex on hash keys?

2001-06-13 Thread Hans Holtan

Hi everyone,

I'm a bit green, and I'm trying to split a large file into a hash. My 
problem is that the parts that I want to use as keys are a bit long 
(100-200 letters), and I will need to pull them out by the presence 
of certain substrings later. So my actual question is this, how do I 
retreive a slice from a hash based on substrings in their keys?

Thanks for your help.



Re: arrays problem

2001-06-13 Thread F.H

Hi,
Let me just clarify that in this loop where it doesn't work:
foreach $i ( 0 .. $#{ $ssns{$ssn}{hobbies} } ) {

print " $ssns{$ssn}{hobbies}[$i]";

}

I need to be able to access through maybe a multidemensional array each elemnt of the 
hobbies.

Thanks 

I.S
[EMAIL PROTECTED] (F.H) wrote:
>
> 
> Michael,
> Thanks for taking the time to solve this problem. Of course those are not real ssn 
>numbers.
> I tried your suggestion:
> 
> 
> if ($key =~ /^Hobbies/i) {
> push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
> }
> }           
>  
> # print results
> print "\n TEST: $ssns{'123-43-4352'}{'hobbies'}[2][2]\n";
> It came out with no results and down below in the foreach loop:
> It printed:
>   Hobbies are:
>  ARRAY(0xca6840) ARRAY(0xca6828) ARRAY(0xca67f8) ARRAY(0xca67a4)
> 
> Did I miss/skip something in the code?
> Regards
> 
> I.S
> 
> Michael Fowler <[EMAIL PROTECTED]> wrote:
> >
> > On Wed, Jun 13, 2001 at 04:09:29PM -0400, F.H wrote:
> > [snip]
> > >  $ssns{$ssn}{hobbies}[0][2] which should yield H3
> > >  $ssns{$ssn}{hobbies}[3][0]   to get HG.
> > [snip]
> > 
> > >     if ($key =~ /^Hobbies/i) {
> > >         push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line];
> > >     }
> > 
> > From this, your data structure is:
> > 
> >     %ssns = (
> >         '123-43-4352' => {
> >             'hobbies' => [qw(
> >                 JX 1234 SKI BaseBall swimming H1 H2 H3 HH HHH 2 H1 H43
> >             )],
> >             ...
> >         },
> > 
> >         ...
> >     );
> > 
> > But you're trying to access it as:
> > 
> >     $ssns{'123-43-4352'}{'hobbies'}[0][2];
> > 
> > You have one index too many.  To get 'H3' you'd use:
> > 
> >     $ssns{'123-43-4352'}{'hobbies'}[7];
> > 
> > 
> > If you want to preserve the line numbers you need to push an array
> > reference:
> > 
> >     if ($key =~ /^Hobbies/i) {
> >         push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
> >     }
> > 
> > Your data structure would then look like this:
> > 
> >     %ssns = (
> >         '123-43-4352' => {
> >             'hobbies' => [
> >                 [qw(JX 1234              )],
> >                 [qw(SKI BaseBall swimming)],
> >                 [qw(H1 H2 H3             )],
> >                 [qw(HH HHH 2         )],
> >                 [qw(H1 H43               )],
> >             )],
> >             ...
> >         },
> > 
> >         ...
> >     );
> > 
> > 
> > Then you'd be able to access 'H3' as:
> > 
> >     $ssns{'123-43-4352'}{'hobbies'}[2][2];
> > 
> > 
> > You have commented lines in your script for printing out the data structure
> > using Data::Dumper.  This is a good idea, and ideal for determining why your
> > accesses aren't getting the data you want.
> > 
> > 
> > 
> > > __DATA__
> > > Name ,123-43-4352, JX, 1234
> > > Sports,123-43-4352, SKI, BaseBall, swimming
> > > Hobbies, 123-43-4352, H1,H2, H3
> > > Hobbies, 123-43-4352, HH, HHH, 2
> > > Hobbies,123-43-4352, H1,H43
> > > 
> > > Name ,223-63-9352, JX, 1234
> > > Sports,223-63-9352, SKI, BaseBall, swimming
> > > Hobbies, 223-63-9352, H1,H2, H3
> > > Hobbies, 223-63-9352, HH, HHH, 2
> > > Hobbies,223-63-9352, H1,H43
> > > Hobbies,223-63-9352, HG, HG, HGFR
> > 
> > I sincerely hope these aren't real social security numbers.
> > 
> > 
> > Michael
> > --
> > Administrator                      www.shoebox.net
> > Programmer, System Administrator   www.gallanttech.com
> > --
> > 
> __
> Get your own FREE, personal Netscape Webmail account today at 
>http://webmail.netscape.com/
> 
__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Re: This is odd to me

2001-06-13 Thread register

Well a regex is a regular expression ... I am pretty sure you will come round
to it eventually if you go info hunting on perl.  A good book that I always
recommend (for beginners) is "Learning Perl" published by O'Reilly.

It is a bit difficult for a beginner sometimes as Perl can be used for so many
things that the spectrum of discussion even in a beginner's list is very
broad. I personally don't do anything with XML with Perl (and I have been at
Perl for two years now ...c ommercially ... not that I am saying aI am any
good).

Pick your spots with the mailing list topics.
On Wed, Jun 13, 2001 at 04:32:08PM -0500, [EMAIL PROTECTED] shaped the electrons to 
read:
> I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
> a couple web pages where you could submit a text file that would be posted
> onto the web (i.e. joke of the day sites).  I've written scripts that have
> taken
> files of lists of labels, compared them, then built a list of the ones that
> were
> in one an not the other file.  I thought that qualified me as a beginner.
> Then
> I join this group, and I get discussions of regexes and XML, etc.  I have
> no idea what a regex is!  What books have you guys (who I assume are
> beginners too, since that's the name of this board) been reading?  Turn
> me into a beginner too!
> 
> Kirk
> 



Re: This is odd to me

2001-06-13 Thread Brett W. McCoy

On Wed, 13 Jun 2001 [EMAIL PROTECTED] wrote:

> I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
> a couple web pages where you could submit a text file that would be posted
> onto the web (i.e. joke of the day sites).  I've written scripts that have
> taken
> files of lists of labels, compared them, then built a list of the ones that
> were
> in one an not the other file.  I thought that qualified me as a beginner.
> Then
> I join this group, and I get discussions of regexes and XML, etc.  I have
> no idea what a regex is!  What books have you guys (who I assume are
> beginners too, since that's the name of this board) been reading?  Turn
> me into a beginner too!

I question the value of any Perl book that does not teach you anything
about regular expressions (regex is short for regular expression).

-- Brett
   http://www.chapelperilous.net/btfwk/

A snake lurks in the grass.
-- Publius Vergilius Maro (Virgil)





Re: arrays problem

2001-06-13 Thread F.H


Michael,
Thanks for taking the time to solve this problem. Of course those are not real ssn 
numbers.
I tried your suggestion:


if ($key =~ /^Hobbies/i) {
push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
}
}   
 
# print results
print "\n TEST: $ssns{'123-43-4352'}{'hobbies'}[2][2]\n";
It came out with no results and down below in the foreach loop:
It printed:
  Hobbies are:
 ARRAY(0xca6840) ARRAY(0xca6828) ARRAY(0xca67f8) ARRAY(0xca67a4)

Did I miss/skip something in the code?
Regards

I.S

Michael Fowler <[EMAIL PROTECTED]> wrote:
>
> On Wed, Jun 13, 2001 at 04:09:29PM -0400, F.H wrote:
> [snip]
> >  $ssns{$ssn}{hobbies}[0][2] which should yield H3
> >  $ssns{$ssn}{hobbies}[3][0]   to get HG.
> [snip]
> 
> >     if ($key =~ /^Hobbies/i) {
> >         push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line];
> >     }
> 
> From this, your data structure is:
> 
>     %ssns = (
>         '123-43-4352' => {
>             'hobbies' => [qw(
>                 JX 1234 SKI BaseBall swimming H1 H2 H3 HH HHH 2 H1 H43
>             )],
>             ...
>         },
> 
>         ...
>     );
> 
> But you're trying to access it as:
> 
>     $ssns{'123-43-4352'}{'hobbies'}[0][2];
> 
> You have one index too many.  To get 'H3' you'd use:
> 
>     $ssns{'123-43-4352'}{'hobbies'}[7];
> 
> 
> If you want to preserve the line numbers you need to push an array
> reference:
> 
>     if ($key =~ /^Hobbies/i) {
>         push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
>     }
> 
> Your data structure would then look like this:
> 
>     %ssns = (
>         '123-43-4352' => {
>             'hobbies' => [
>                 [qw(JX 1234              )],
>                 [qw(SKI BaseBall swimming)],
>                 [qw(H1 H2 H3             )],
>                 [qw(HH HHH 2         )],
>                 [qw(H1 H43               )],
>             )],
>             ...
>         },
> 
>         ...
>     );
> 
> 
> Then you'd be able to access 'H3' as:
> 
>     $ssns{'123-43-4352'}{'hobbies'}[2][2];
> 
> 
> You have commented lines in your script for printing out the data structure
> using Data::Dumper.  This is a good idea, and ideal for determining why your
> accesses aren't getting the data you want.
> 
> 
> 
> > __DATA__
> > Name ,123-43-4352, JX, 1234
> > Sports,123-43-4352, SKI, BaseBall, swimming
> > Hobbies, 123-43-4352, H1,H2, H3
> > Hobbies, 123-43-4352, HH, HHH, 2
> > Hobbies,123-43-4352, H1,H43
> > 
> > Name ,223-63-9352, JX, 1234
> > Sports,223-63-9352, SKI, BaseBall, swimming
> > Hobbies, 223-63-9352, H1,H2, H3
> > Hobbies, 223-63-9352, HH, HHH, 2
> > Hobbies,223-63-9352, H1,H43
> > Hobbies,223-63-9352, HG, HG, HGFR
> 
> I sincerely hope these aren't real social security numbers.
> 
> 
> Michael
> --
> Administrator                      www.shoebox.net
> Programmer, System Administrator   www.gallanttech.com
> --
> 
__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Re: This is odd to me

2001-06-13 Thread Peter Scott

At 04:32 PM 6/13/01 -0500, [EMAIL PROTECTED] wrote:
>I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
>a couple web pages where you could submit a text file that would be posted
>onto the web (i.e. joke of the day sites).  I've written scripts that have
>taken
>files of lists of labels, compared them, then built a list of the ones that
>were
>in one an not the other file.  I thought that qualified me as a beginner.
>Then
>I join this group, and I get discussions of regexes and XML, etc.  I have
>no idea what a regex is!  What books have you guys (who I assume are
>beginners too, since that's the name of this board) been reading?  Turn
>me into a beginner too!

As a generalization, nothing worth learning can be learned in 24 hours.  So 
I wouldn't touch a book whose title was already false.

Try "Learning Perl" second edition, from O'Reilly.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: Question regarding the Substitution Operator

2001-06-13 Thread Evgeny Goldin (aka Genie)


> I've tried placing [ ] around each variable,

Stop, don't run and read "perlre" before you trying to use any special
regex characters.

When you put characters inside [] it means "any character" and it doesn't mean
"the whole word"
[abcd]  = "a or b or c or d" and not "abcd"

> using the || operator between

Did you mean the '|' operator ? ;)

C:\>perl -w
$line  = "Joe Doe 123 Main St. Sometown, USA";
$fname = "Joe";
$lname = "Doe";
$addr  = "123 Main St.";
$line  =~ s/$fname|$lname|$addr|\s//g;
print "[$line]\n";
^Z
[Sometown,USA]

C:\>

And, yeah, don't forget using \Q and \E around your variables.
( not around the whole regex - you'll disable the '|' by this )





Re: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread Steven Scott

ASCII 12 is a new page to printer.

Steven Scott
Team Lead
Email: mailto:[EMAIL PROTECTED]
Web: http://www.invatron.com

Invatron Systems Corp.
5710 Timberlea Blvd.,
Suite 201,
Mississauga, Ontario
L4W 4WI
Telephone: (905) 282-1290 x40
Fax: (905) 282-1266

- Original Message -
From: "Evgeny Goldin (aka Genie)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 13, 2001 6:37 PM
Subject: RE: A Term::ReadKey question -- keep cursor put!


>
> Hey, thank's for the answers !
> Although, I didn't ask the question but I was occasionally thinking
> about it. "\r" and "\b" - great !
> As once I was pointed to the ASCII character causing the printer to
> start a new page .. Btw, I've forgot it - does anybody know it ?
> 11 ?
>
> > I'm very new to perl (a week or so), so this may not be the best way to
do
> > this, but
> > for ($i=0; $i<10; $i++) {printf "%d\r",$i;}
>
> Don't overuse printf - you may be regular to it after C but it
> should only be used when it's formatting capabilities required.
> For simple print ( 95% of cases ? ) "print" is just fine.
>




This is odd to me

2001-06-13 Thread kotto

I read Learn Perl in 24 Hours.  I did the exercises in the book, and I wrote
a couple web pages where you could submit a text file that would be posted
onto the web (i.e. joke of the day sites).  I've written scripts that have
taken
files of lists of labels, compared them, then built a list of the ones that
were
in one an not the other file.  I thought that qualified me as a beginner.
Then
I join this group, and I get discussions of regexes and XML, etc.  I have
no idea what a regex is!  What books have you guys (who I assume are
beginners too, since that's the name of this board) been reading?  Turn
me into a beginner too!

Kirk



Re: Noobie question

2001-06-13 Thread Evgeny Goldin (aka Genie)


This should help :

http://dbi.symbolstone.org/
http://search.cpan.org/doc/TIMB/DBI-1.18/DBI.pm





Re: arrays problem

2001-06-13 Thread Michael Fowler

On Wed, Jun 13, 2001 at 04:09:29PM -0400, F.H wrote:
[snip]
>  $ssns{$ssn}{hobbies}[0][2] which should yield H3
>  $ssns{$ssn}{hobbies}[3][0]   to get HG.
[snip]

> if ($key =~ /^Hobbies/i) {
> push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line];
> }

>From this, your data structure is:

%ssns = (
'123-43-4352' => {
'hobbies' => [qw(
JX 1234 SKI BaseBall swimming H1 H2 H3 HH HHH 2 H1 H43
)],
...
},

...
);

But you're trying to access it as:

$ssns{'123-43-4352'}{'hobbies'}[0][2];

You have one index too many.  To get 'H3' you'd use:

$ssns{'123-43-4352'}{'hobbies'}[7];


If you want to preserve the line numbers you need to push an array
reference:

if ($key =~ /^Hobbies/i) {
push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]];
}

Your data structure would then look like this:

%ssns = (
'123-43-4352' => {
'hobbies' => [
[qw(JX 1234  )],
[qw(SKI BaseBall swimming)],
[qw(H1 H2 H3 )],
[qw(HH HHH 2 )],
[qw(H1 H43   )],
)],
...
},

...
);


Then you'd be able to access 'H3' as:

$ssns{'123-43-4352'}{'hobbies'}[2][2];


You have commented lines in your script for printing out the data structure
using Data::Dumper.  This is a good idea, and ideal for determining why your
accesses aren't getting the data you want.



> __DATA__
> Name ,123-43-4352, JX, 1234
> Sports,123-43-4352, SKI, BaseBall, swimming
> Hobbies, 123-43-4352, H1,H2, H3
> Hobbies, 123-43-4352, HH, HHH, 2
> Hobbies,123-43-4352, H1,H43
> 
> Name ,223-63-9352, JX, 1234
> Sports,223-63-9352, SKI, BaseBall, swimming
> Hobbies, 223-63-9352, H1,H2, H3
> Hobbies, 223-63-9352, HH, HHH, 2
> Hobbies,223-63-9352, H1,H43
> Hobbies,223-63-9352, HG, HG, HGFR

I sincerely hope these aren't real social security numbers.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread Evgeny Goldin (aka Genie)


Hey, thank's for the answers !
Although, I didn't ask the question but I was occasionally thinking
about it. "\r" and "\b" - great !
As once I was pointed to the ASCII character causing the printer to
start a new page .. Btw, I've forgot it - does anybody know it ?
11 ?

> I'm very new to perl (a week or so), so this may not be the best way to do
> this, but
> for ($i=0; $i<10; $i++) {printf "%d\r",$i;}

Don't overuse printf - you may be regular to it after C but it
should only be used when it's formatting capabilities required.
For simple print ( 95% of cases ? ) "print" is just fine.





Re: combine STDERR and STDOUT

2001-06-13 Thread Evgeny Goldin (aka Genie)


perlop, qx// operator :

> To read both a command's STDOUT and its STDERR separately, it's
> easiest and safest to redirect them separately to files, and
> then read from those files when the program is done:
> 
> system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");

So, if I was you I wasn't relying on the fact that B doesn't produce
anything to STDOUT and trying to redirect it's STDERR there - you're
locking yourself in the cage by this .. What if this will change ?
The good thing, IMHO, will be to write a little subroutine getting a
command to launch and returning it's STDERR and STDOUT separately in two
variables. Oh, I did it once, here we go :

# launches the script and returns it's STDOUT and STDERR separately
sub launch {
local ( $_, $/, *FIN );
my ( $script ) = @_;

# redirecting both STDOUT and STDERR to the corresponding files and reading 
them later

my $stdout_file = "$script.stdout";
my $stderr_file = "$script.stderr";

system "$script 1>$stdout_file 2>$stderr_file" # NOTE THE DOS SYNTAX !!!
and warn "Failed to launch [$script] ! \a\n";

# Even if we failed to launch the script - it's STDOUT and STDERR are still 
taken
open( FIN, "$stdout_file" ) or die "Unable to open [$stdout_file] for reading 
: $! \a\n";
my $stdout = ;
close( FIN ) or warn "Unable to close [$stdout_file] : $! \a\n";   
 
unlink $stdout_file;

open( FIN, "$stderr_file" ) or die "Unable to open [$stderr_file] for reading 
: $! \a\n";
my $stderr = ;
close( FIN ) or warn "Unable to close [$stderr_file] : $! \a\n";   
 
unlink $stderr_file;

( $stdout, $stderr );
}





RE: testing on email characters

2001-06-13 Thread Peter Cornelius

> Subject: testing on email characters 

I just wanted to expand on Jeff Yoaks comment that the regexes discussed in
this thread don't actually validate syntax on _all_ e-mail addresses.  I
think this is a common problem.  I remember looking this up in 'Mastering
Regular Expressions' (though I don't have it with me now) and the author
commented that a regex to do this would be over a thousand characters long.
You can take a look at RFC 822 to get an idea for the uncommon characters
allowed in e-mail addresses (like '& <>"').  

I've never used Email::Valid but it may be a good way to solve the problem,
I'd be impressed if it actually catches all valid addresses (and very
happy).  I've always just accepted that there would be some special cases
that wouldn't be caught and put other mechanisms in place to handle those.

'Just 2 bits'
Peter C.



Re: XML::Parser XML::SimpleObject -> First XML parsing pls help

2001-06-13 Thread Chas Owens

Always, always proofread your work, Sigh.  I meant to say:

Line 14 should be:
print $mail->child('smtp_server')->value;
not
print $mail->child('smtp_server')->{VALUE};

On 13 Jun 2001 16:46:06 -0400, Chas Owens wrote:
> line should be:
>   print $mail->child('smtp_server')->value;
> not
>   print $mail->child('smtp_server')->{VALUE};
> 
> On 13 Jun 2001 20:25:18 +, Stout, Joel R wrote:
> > I took the example from
> > http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html
> > I wanted something really simple for XML parsing that basically just reads
> > values.  But I'm stuck (again).
> > 
> > #Here's what I'm trying to run:
> > 
> > #!c:\perl\perl.exe 
> > 
> > use XML::Parser;
> > use XML::SimpleObject;
> > use strict;
> > 
> > my $file = 'c:\perl\work\job001_card.xml';
> > 
> > my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree");
> > my $xso = XML::SimpleObject->new( $parser->parsefile($file) );
> > 
> > foreach my $mail ($xso->child('job_card')->children('email')) {
> > print "SMTP server: ";
> > print $mail->child('smtp_server')->{VALUE};
> > print "\n";
> > }
> > 
> > #and I get 
> > 'SMTP server: '
> > 
> > #Here's an excerpt of the file I've been given:
> > 
> > xx
> > 
> > ftp.xxx.com
> > px
> > fx
> > .
> > 
> > 
> > 
> > c:\test
> > .xxx
> > 
> > c:\perl\log
> > 
> > mx.ex.com
> > ...
> > 
> > ...
> > 
> > 
> > #I think I'm close.  When I add -w I get:
> > 'use of uninitialized value in print at line 14 ...'
> > #but I know there's a value for that tag. ??? 
> --
> Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
> Kallisti!
> 
--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
You are what you see.





Re: testing on email characters

2001-06-13 Thread Jeff Yoak

At 06:45 PM 6/12/01 +0200, Jos Boumans wrote:
>Please, if you try and flame posts, get your facts straight.

That seems a little harsh.  I don't think it was intended as a flame or to 
be insulting in any way.  It was just suggesting what the author thought 
was a better way to do it.  :-)

>2nd:the regex is purposely written verbose, seeing this is a newbie 
>list and we
>want to teach them, not scare them away by hard to follow code

OK, but if your purpose is to point out important points for the new 
programmer, it seems to me that by far the most important thing to point 
out here is that these expressions have nothing to do with "testing on 
email characters."  They will pass things that aren't valid email addresses 
and they reject many things that are.  The Internet is full of people doing 
things like this:

if ($email =~ /[\w\.-]+\@[\w\.-]+(\.[\w\.-]+)+/){...}

which is just horrible.

Another poster to this list who hasn't said anything in this particular 
thread used to address this question sufficiently often that he had an 
auto-responder set up at fred&[EMAIL PROTECTED] that contained 
information about not using the sort of regular expression found above.  If 
you like, you can reply me about this message at "foo and bar"@yoak.com 
.  It'll come through with no trouble at all.

I understand that there is value in exploring how character classes and the 
like work in regular expressions, but someone should point out that the 
proposed problem isn't solved in any of these ways.

In another post, I mentioned Email::Valid and some other conversation 
about  ways to do it.

Cheers,
Jeff





Re: XML::Parser XML::SimpleObject -> First XML parsing pls help

2001-06-13 Thread Chas Owens

line should be:
print $mail->child('smtp_server')->value;
not
print $mail->child('smtp_server')->{VALUE};

On 13 Jun 2001 20:25:18 +, Stout, Joel R wrote:
> I took the example from
> http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html
> I wanted something really simple for XML parsing that basically just reads
> values.  But I'm stuck (again).
> 
> #Here's what I'm trying to run:
> 
> #!c:\perl\perl.exe 
> 
> use XML::Parser;
> use XML::SimpleObject;
> use strict;
> 
> my $file = 'c:\perl\work\job001_card.xml';
> 
> my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree");
> my $xso = XML::SimpleObject->new( $parser->parsefile($file) );
> 
> foreach my $mail ($xso->child('job_card')->children('email')) {
>   print "SMTP server: ";
>   print $mail->child('smtp_server')->{VALUE};
>   print "\n";
> }
> 
> #and I get 
> 'SMTP server: '
> 
> #Here's an excerpt of the file I've been given:
> 
>   xx
>   
>   ftp.xxx.com
>   px
>   fx
>   .
>   
>   
>   
>   c:\test
>   .xxx
>   
>   c:\perl\log
>   
>   mx.ex.com
>   ...
>   
>   ...
> 
> 
> #I think I'm close.  When I add -w I get:
> 'use of uninitialized value in print at line 14 ...'
> #but I know there's a value for that tag. ??? 
--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
Kallisti!





RE: :Parser XML::SimpleObject -> First XML parsing pls help

2001-06-13 Thread kotto

You're a beginner?  

-Original Message-
From: Stout, Joel R [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 3:25 PM
To: [EMAIL PROTECTED]
Subject: XML::Parser XML::SimpleObject -> First XML parsing pls help


I took the example from
http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html
I wanted something really simple for XML parsing that basically just reads
values.  But I'm stuck (again).

#Here's what I'm trying to run:

#!c:\perl\perl.exe 

use XML::Parser;
use XML::SimpleObject;
use strict;

my $file = 'c:\perl\work\job001_card.xml';

my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree");
my $xso = XML::SimpleObject->new( $parser->parsefile($file) );

foreach my $mail ($xso->child('job_card')->children('email')) {
print "SMTP server: ";
print $mail->child('smtp_server')->{VALUE};
print "\n";
}

#and I get 
'SMTP server: '

#Here's an excerpt of the file I've been given:

xx

ftp.xxx.com
px
fx
.



c:\test
.xxx

c:\perl\log

mx.ex.com
...

...


#I think I'm close.  When I add -w I get:
'use of uninitialized value in print at line 14 ...'
#but I know there's a value for that tag. ??? 



XML::Parser XML::SimpleObject -> First XML parsing pls help

2001-06-13 Thread Stout, Joel R

I took the example from
http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html
I wanted something really simple for XML parsing that basically just reads
values.  But I'm stuck (again).

#Here's what I'm trying to run:

#!c:\perl\perl.exe 

use XML::Parser;
use XML::SimpleObject;
use strict;

my $file = 'c:\perl\work\job001_card.xml';

my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree");
my $xso = XML::SimpleObject->new( $parser->parsefile($file) );

foreach my $mail ($xso->child('job_card')->children('email')) {
print "SMTP server: ";
print $mail->child('smtp_server')->{VALUE};
print "\n";
}

#and I get 
'SMTP server: '

#Here's an excerpt of the file I've been given:

xx

ftp.xxx.com
px
fx
.



c:\test
.xxx

c:\perl\log

mx.ex.com
...

...


#I think I'm close.  When I add -w I get:
'use of uninitialized value in print at line 14 ...'
#but I know there's a value for that tag. ??? 



RE: Huge hash ... running out of memory without warning???

2001-06-13 Thread Brett W. McCoy

On Wed, 13 Jun 2001, Bryan Gmyrek wrote:

> Hi, I tried to do this, but it didn't really work because first I
> declare an array like this:
> my @day;
>
> Then I did as you said...
>
> Then, I add information using things like:
>
> $day[$ext]{$line[2]}{$line[0]}{pages}=$line[1];

Oh, yeah, you're doing some pretty complex data structures there.  You
will want to use the MLDBM module instead.  You'll have to get it from
CPAN.  It is uses Data::Dumper to store complex data structures.  It works
like this:

use MLDBM 'DB_File';

tie (%myhash, 'MLDBM', [other args]) or die "...";

$myhash{$somekey} = ["some data", "more data"];

Be very careful, though, because you can't do:

$myhash{$somekey}->[0] = "even more data";

This is a limitation of the hash interface (you can't manipulate data via
references on the disk).  Instead, use temp variables:

$moredata = $myhash{$somekey};
$moredata->[0] = "even more data";
$myhash{$somekey} = $moredata;

-- Brett
   http://www.chapelperilous.net/btfwk/

Having a wonderful wine, wish you were beer.




Re: Problem printing a system value to a filehandle (windows)

2001-06-13 Thread Chas Owens

On 13 Jun 2001 13:39:49 -0400, Craig S Monroe wrote:
> Chris,
> I appreciate you responding to my message, but I don't understand some of
> the
> issues you were speaking about.
> 
> "you want to use backticks " I do not understand what you mean by this?
> Where should I be using them? In place of what?

> > There are two things wrong here.  First system returns the exit code of
> > the process you call (not the output), you want to use backticks (shift
> > ~ on most keyboards in the US).  Second =~ is the binding operator for
> > regexps not the assignment operator.  You should be saying:
> >
> > $time = `TIME /T`;
> > $date = `DATE /T`;
> >


There are three ways to execute an external program in Perl: exec,
system, 
and backticks.  Exec replaces the currently running process with the new
program.  System (which is actually a fork followed by an exec) runs the
the named program.  In both cases all output goes to the standard
output,
normally your screen.  NOTE: if you redirect stdout in your program (ie 
*stdout = *somefile;) it will have NO EFFECT on exec and system.  The
third
way to run a command is to put the command in backticks like this:

$return_value = `DATE /T`;

This runs the named program and returns what would have gone to stdout. 
NOTE: if the program writes to the stderr it will NOT be returned unless
you redirect stderr to stdout like this

$return_value = `somecommand 2>&1`; #NOTE: this only works in unix,
sorry.

Please let me know if this didn't help.
--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
Or is it?





arrays problem

2001-06-13 Thread F.H

Hi All,

Here is my problem with the script below:
 I can access each item from each line. But I got stuck trying to figure
 out how to access each hobbies/sports lines!!
 I need to be able to get data from for instance:

 $ssns{$ssn}{hobbies}[0][2] which should yield H3
 $ssns{$ssn}{hobbies}[3][0]   to get HG.

(data file is at bottom of message)

In a loop:   
for ssn = xyz:

 Hobbies are:
 line 0, row 0 : =
 line 0, row 1 : =
 line 1, row 0: =
 line 1, row 1: =
 and so on.



  script is below
use strict;
use Data::Dumper; $Data::Dumper::Indent=1; # print &Data::Dumper::Dumper($var);

my %ssns;

while () {

#   chomp;  # remove \n
next if /^\s*$/;# skip blanke lines

my @line = split /\s*,\s*/, $_;
my $key = $line[0];
my $ssn = $line[1];

# Name, SSN, , 

if ($key =~ /^Name/i) {
$ssns{$ssn}{name} = $line[2];
$ssns{$ssn}{number} = $line[3];
}

# Sports, SSN, , ...

if ($key =~ /^Sports/i) {
push @{$ssns{$ssn}{sports}}, @line[2 .. $#line];
}

# Hobbies, SSN, , ...

if ($key =~ /^Hobbies/i) {
push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line];
}
}
#print Data::Dumper->Dump([\%ssns], [qw(ssns)]);# dump hash

# print results

foreach (sort keys %ssns) {

print "For ssn $_:\n";

print "  Sports are:\n";
foreach (sort @{$ssns{$_}{sports}}) {
print "$_ ";
}
print "\n";

print "  Hobbies are:\n";
foreach (sort @{$ssns{$_}{hobbies}}) {
print "$_ ";
}
print "\n";
print "\n";
}

exit 0;

__DATA__
Name ,123-43-4352, JX, 1234
Sports,123-43-4352, SKI, BaseBall, swimming
Hobbies, 123-43-4352, H1,H2, H3
Hobbies, 123-43-4352, HH, HHH, 2
Hobbies,123-43-4352, H1,H43

Name ,223-63-9352, JX, 1234
Sports,223-63-9352, SKI, BaseBall, swimming
Hobbies, 223-63-9352, H1,H2, H3
Hobbies, 223-63-9352, HH, HHH, 2
Hobbies,223-63-9352, H1,H43
Hobbies,223-63-9352, HG, HG, HGFR

__END__
I.S
__
Get your own FREE, personal Netscape Webmail account today at 
http://webmail.netscape.com/



Re: Noobie question

2001-06-13 Thread Michael D . Risser

On Wednesday 13 June 2001 12:22 pm, Peter Scott wrote:
> At 12:05 PM 6/13/01 -0700, Ward, Stefan wrote:
> >Does anyone have an example of a way to write a perl script that will go
> > out hit a data base table, pull in a column for that table and use that
> > column in a dropdown list?  I know what to do once I get that variable
> > selected by RTFriendlyM, but couldn't find a clear example of this.
>
> A good book in this respect is "Writing CGI Application with Perl",
> http://www.amazon.com/exec/obidos/ASIN/0201710145.  Many examples.

You may also want to try "Programming the Perl DBI" by Alligator Descartes & 
Tim Bunce published by O'Reilly

> Peter Scott
> Pacific Systems Design Technologies
> http://www.perldebugged.com



Re: reading the next line from a file

2001-06-13 Thread Dave Cross

On Wed, Jun 13, 2001 at 02:45:40PM -0400, Brett W. McCoy ([EMAIL PROTECTED]) 
wrote:
> On Wed, 13 Jun 2001, Esrar Chowdhury wrote:
> 
> > my question is...how do I make the read pointer read every 10th line
> > from my input file? (After reading one line, does the read pointer stay
> > on the same line or automatically go the next line?)
> 
> Hmmm... a homework problem?
> 
> Keep a counter that keeps track of the line number you are reading and
> only do stuff to the data read from the line if the line number is
> divisible by 10.

No need to keep a count. Perl does that for you - it's called $.

Dave...

-- 

  Don't dream it... be it




Re: Noobie question

2001-06-13 Thread Peter Scott

At 12:05 PM 6/13/01 -0700, Ward, Stefan wrote:
>Does anyone have an example of a way to write a perl script that will go out
>hit a data base table, pull in a column for that table and use that column
>in a dropdown list?  I know what to do once I get that variable selected by
>RTFriendlyM, but couldn't find a clear example of this.

A good book in this respect is "Writing CGI Application with Perl", 
http://www.amazon.com/exec/obidos/ASIN/0201710145.  Many examples.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: RE: Huge hash ... running out of memory without warning???

2001-06-13 Thread Eduard Grinvald

Unfortunately, perl is quite liberal with memory, so from personal 
experience: have as many "my"ed variables as possible, undef things as 
often as possible, and remember, that perl doesn't release memory, just 
recycles it, so once it takes from the system, that's it until the end 
of execution, so be careful as to how much you let it grab.

Have fun :)

__END__
=sincerely, eduard grinvald
=email: [EMAIL PROTECTED]
=dev-email: [EMAIL PROTECTED]
=dev-site: r-x-linux.sourceforge.net
=icq:   114099136
=PGP
-BEGIN PGP PUBLIC KEY BLOCK-
Version: PGPfreeware 6.5.8 for non-commercial use 

mQGiBDr60ScRBADsdYfjVgLPiUU8kJvLx9rsONfx1K4wPAKLUCcFOyhmBvIT/EEY
pE2PVoOjosUdlkGGGFo9BLUi7UHoTrL7NyupJ4yHCU8wQiSPYK2GuZn5+ishIUI3
sDifAE4JKuLxtz2fdBcoimrFBfXQRwNrmIqFnA+ooP5GRrJxHpgAn6rvkwCg/0B8
uIXmUlVF+nwVHS6T2fAjYrUEAIe8LmwDVOorcWDRtoUzzSToAhhMY5ZM02OoG464
2SJzBtDo8ABcWCdddRjeEV3Mt5ohDoLXzH9N2LuOx0AEaWcC94a3y8pcGoF1Mbpq
UFQxUeh1TrKJlaTG0qSCb5euoIFPt5trob93CsHxVd69h6WKi3xOf1jXNbXsfWoj
b56jBACC8Mfhcpjtiw0KZRfqdrb5w11HNb0kP1Ma5mEKqsOBh8MlR9EyBrCji98B
pilGYsaW9PCxaFhJDPPbO6hcERup/O7787+LVc1ZYdlJFq/APcvNZZvbrHB7+uYW
eTI/Vmi7rB2ljE2mpEtms6RoiXqNF32xHDx2pSdSla/kqhPy2rQfRWR1YXJkIEdy
aW52YWxkIDxlZzM0NEBueXUuZWR1PokATgQQEQIADgUCOvrRJwQLAwIBAhkBAAoJ
EDDNAitGCH7xrjMAniAtflvrVvGegFgBYWv9f3eYFTQnAKDPJbKEjt2sOdRV1Ey5
Yah5ScFZEbkEDQQ6+tEnEBAA+RigfloGYXpDkJXcBWyHhuxh7M1FHw7Y4KN5xsnc
egus5D/jRpS2MEpT13wCFkiAtRXlKZmpnwd00//jocWWIE6YZbjYDe4QXau2FxxR
2FDKIldDKb6V6FYrOHhcC9v4TE3V46pGzPvOF+gqnRRh44SpT9GDhKh5tu+Pp0NG
CMbMHXdXJDhK4sTw6I4TZ5dOkhNh9tvrJQ4X/faY98h8ebByHTh1+/bBc8SDESYr
Q2DD4+jWCv2hKCYLrqmus2UPogBTAaB81qujEh76DyrOH3SET8rzF/OkQOnX0ne2
Qi0CNsEmy2henXyYCQqNfi3t5F159dSST5sYjvwqp0t8MvZCV7cIfwgXcqK61qlC
8wXo+VMROU+28W65Szgg2gGnVqMU6Y9AVfPQB8bLQ6mUrfdMZIZJ+AyDvWXpF9Sh
01D49Vlf3HZSTz09jdvOmeFXklnN/biudE/F/Ha8g8VHMGHOfMlm/xX5u/2RXscB
qtNbno2gpXI61Brwv0YAWCvl9Ij9WE5J280gtJ3kkQc2azNsOA1FHQ98iLMcfFst
jvbzySPAQ/ClWxiNjrtVjLhdONM0/XwXV0OjHRhs3jMhLLUq/zzhsSlAGBGNfISn
CnLWhsQDGcgHKXrKlQzZlp+r0ApQmwJG0wg9ZqRdQZ+cfL2JSyIZJrqrol7DVes9
1hcAAgIQAO6f9QVuw3eFMDxx4kVmw9pXlMcPlZT0xfBrzLkHwjoA0wdLp2W/ZWEC
FKQl7EV8yh3bqchlIIKRMLp05+5wgyS4GKsxRaRn1vUcKtPIe+mUojjvwkbdrLAM
TdZDVCwm1pxZqncCKrasJ8jtRT8kf93x3o1m0grVeldGukCvFl91gKXUv4vRT0/8
12MzhrxTkycx+pmS95Ytv7zps827dm6pXtlsTw9L7XNXYVTzHRd9MlvQzSxYIh2w
U0pwZfiNfYKKMOHjlQbHAjZtmuC7TpmOWaxDw0kqo7K6sYqo/bPs3dA5eA/0mfDl
7M2nwUjReCy1/O9B2Mf3QwjW712Rqyh2l+7Yp+GgIvHMHnIClZcNGjYh3jALUM3+
OenmcZfBzf6uuw9yFt/3bhoK/YkJJ6BIxx4q04TY93x28IqTt3l17omX+oOaDGS3
7gNTE52LTMUUwD+ienXrsu5mPL8CzrhXQAMTekJhc/HpOhNGPsqIe9TbFuacxr7j
OCJxPeeFGEO2NJ+ChCk0z3S1tWmDrM1gxdIxUbO1bp8hBm7LP9rKkMlEqpSJWdS8
yJmv/9WtDUTZdEJzzFeF+rp2lZpYkI/+sqVJP884fJ9NTS0aXiO1GxQWOKoVE58H
cyrO3hpYgMdC1oP4WZnEJwkLAN+4WnsF2DkKmkNvJRjAANSBTJF3iQBGBBgRAgAG
BQI6+tEnAAoJEDDNAitGCH7xa7AAn0dybVrFf+QHtfgkAsRK3oXY+7gwAJ4sWtYC
GuYw+8LgdC7Mp2ICim9MqA==
=iAF5
-END PGP PUBLIC KEY BLOCK-
=cut


- Original Message -
From: "Bryan Gmyrek" <[EMAIL PROTECTED]>
Date: Wednesday, June 13, 2001 2:59 pm
Subject: RE: Huge hash ... running out of memory without warning???

> Eduard,
> 
> Thanks for the help.  I think I will tie it into a DB file as you
> suggest.  Too bad this has to be such a pain ... it is so 
> 'elegant' to
> have a nice hash like that!
> 
> Cheers,
> Bryan
> 
> -Original Message-
> From: Eduard Grinvald [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 13, 2001 2:24 PM
> To: Bryan Gmyrek
> Cc: [EMAIL PROTECTED]
> Subject: Re: Huge hash ... running out of memory without warning???
> 
> 
> Hey, I had a similiar problem, but under different circumstances, 
> i 
> found only 2 reasonable solutions: tieing the hashes to a db file, 
> and 
> not storing data before printing it (print as soon as read). Tell 
> me if 
> you find another solution
> 
> __END__
> =sincerely, eduard grinvald
> =email: [EMAIL PROTECTED]
> =dev-email: [EMAIL PROTECTED]
> =dev-site: r-x-linux.sourceforge.net
> =icq:   114099136
> =PGP
> -BEGIN PGP PUBLIC KEY BLOCK-
> Version: PGPfreeware 6.5.8 for non-commercial use <" 
> target="l">http://www.pgp.com>
> mQGiBDr60ScRBADsdYfjVgLPiUU8kJvLx9rsONfx1K4wPAKLUCcFOyhmBvIT/EEY
> pE2PVoOjosUdlkGGGFo9BLUi7UHoTrL7NyupJ4yHCU8wQiSPYK2GuZn5+ishIUI3
> sDifAE4JKuLxtz2fdBcoimrFBfXQRwNrmIqFnA+ooP5GRrJxHpgAn6rvkwCg/0B8
> uIXmUlVF+nwVHS6T2fAjYrUEAIe8LmwDVOorcWDRtoUzzSToAhhMY5ZM02OoG464
> 2SJzBtDo8ABcWCdddRjeEV3Mt5ohDoLXzH9N2LuOx0AEaWcC94a3y8pcGoF1Mbpq
> UFQxUeh1TrKJlaTG0qSCb5euoIFPt5trob93CsHxVd69h6WKi3xOf1jXNbXsfWoj
> b56jBACC8Mfhcpjtiw0KZRfqdrb5w11HNb0kP1Ma5mEKqsOBh8MlR9EyBrCji98B
> 
pilGYsaW9PCxaFhJDPPbO6hcERup/O7787+LVc1ZYdlJFeTI/Vmi7rB2ljE2mpEtms6RoiXq
NF32xHDx2pSdSla/kqhPy2rQfRWR1YXJkIEdy
> aW52YWxkIDxlZzM0NEBueXUuZWR1PokATgQQEQIADgUCOvrRJwQLAwIBAhkBAAoJ
> EDDNAitGCH7xrjMAniAtflvrVvGegFgBYWv9f3eYFTQnAKDPJbKEjt2sOdRV1Ey5
> Yah5ScFZEbkEDQQ6+tEnEBAA+RigfloGYXpDkJXcBWyHhuxh7M1FHw7Y4KN5xsnc
> egus5D/jRpS2MEpT13wCFkiAtRXlKZmpnwd00//jocWWIE6YZbjYDe4QXau2FxxR
> 2FDKIldDKb6V6FYrOHhcC9v4TE3V46pGzPvOF+gqnRRh44SpT9GDhKh5tu+

RE: Huge hash ... running out of memory without warning???

2001-06-13 Thread Bryan Gmyrek

Brett,

Hi, I tried to do this, but it didn't really work because first I
declare an array like this:
my @day;

Then I did as you said...

Then, I add information using things like:

$day[$ext]{$line[2]}{$line[0]}{pages}=$line[1];

I checked out the database file and there was stuff like this in there:

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@
^@^@^AHASH(0x87166b8)^A20010612^AHASH(0x868a7e8)^A20010609^AHASH(0x85d52
c8)^A200
10605^AHASH(0x85179dc)^A20010601^AHASH(0x84e8da4)^A20010519^AHASH(0x842a
850)^A20
010515^AHASH(0x82e47e8)^A20010528^AHASH(0x8228b60)^A20010524^AHASH(0x816
a698)^A2
0010520^@^@^@^@^@^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^N^@Q^O^@^B÷^Oç^OÞ^OÎ^OÅ^
Oµ^O¬^O
<9C>^O<93>^O<83>^Oz^Oj^Oa^OQ^O^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@

I think that the problem is that the database file in this case just
holds information on where the hashes are in memory and not all of the
information in the hashes(???)  Do you have any idea of how could I
declare that I want the database file to keep track of the hashes?

Thanks,
Bryan

-Original Message-
From: Brett W. McCoy [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 2:40 PM
To: Bryan Gmyrek
Cc: [EMAIL PROTECTED]
Subject: Re: Huge hash ... running out of memory without warning???


On Wed, 13 Jun 2001, Bryan Gmyrek wrote:

> I have just written a program that makes an array of hashes of hashes
of
> hashes.  It reads all kind of information in from a bunch of files and
> then later I access the elements of this thing in a convienient way
> because it's kind of like a little database.  Anyways, I end up
printing
> everything out into a very big html table.  I noticed that *sometimes*
> nothing is printed  when I say 'print this part of that array...'
> Thought it was a bug in the code, but then I ran the program on a
> machine with more memory and *now* the elements that were missing
> previously are printed, but some 'further on down the line' are not.
It
> seems that the computer is running out of memory and at some point no
> data really gets added to this monster of a list of lists...  What the
> heck should I do so that I can perform these functions, but not run
into
> this problem of running out of memory?

You might want to look into using DB_File -- your hash will use your
disk
as a sort of 'virtual memory', plus your hash will be persistent between
calls of your script:

use DB_File;

tie %myhash, "DB_File", $filename or die "Can't open $filename$!\n";

#do stuff to gather data

$myhash{$somekey} = $somevalue;

#do more stuff with your data

untie %myhash;
   http://www.chapelperilous.net/btfwk/

Youth.  It's a wonder that anyone ever outgrows it.





Noobie question

2001-06-13 Thread Ward, Stefan

Does anyone have an example of a way to write a perl script that will go out
hit a data base table, pull in a column for that table and use that column
in a dropdown list?  I know what to do once I get that variable selected by
RTFriendlyM, but couldn't find a clear example of this.

Thanks,


Stefan Ward
Data Warehouse Eng
Sony Online Entertainment
www.station.sony.com  





RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread Wagner-David

This appeared either on this list or the Perl-Win32 list as the same
question.  You can use 
select(0,0,0,25) I believe which will pause for .25 of a second.  You may
need also to set autoflush to 1(ie, $|=1 ), so each IO will be displayed.

Wags ;)

-Original Message-
From: Dave Newton [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 13, 2001 11:33
To: [EMAIL PROTECTED]
Subject: RE: A Term::ReadKey question -- keep cursor put!


Bear in mind that without any sort of delay it's unlikely
you'll be able to see any of this occuring.

Ah, the good old days, where a 300-baud modem was fast
and little spinny cursors were still interesting. *sigh*

Dave

--
Dave Newton, [EMAIL PROTECTED]



RE: Remote command execution on NT and Solaris?

2001-06-13 Thread ggage


-Original Message-
From: Michael Dube [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 12, 2001 11:19 AM
To: Perl Beginners List
Subject: Remote command execution on NT and Solaris?


I have just begun a project that will involve automated state setting on
multiple machines across multiple platforms (NT & Solaris).  At this point
I
believe this will be done by writing scripts for each platform and having a
centralized system (NT or Solaris) execute a script which will instruct
each
of the other systems to run their initialization script.

Is there a PERL module available which will facilitate remote command
execution for NT and Solaris?

Any suggestions on the best way to do this?

Thanks,

Mike






Mike,

Here are a couple of alternatives to Steve Howard's suggestions on how to
access your NT boxes remotely.

1)  Remote Shell Service.  Which is part of the NT resource kit.  This
allows you to remsh (or rsh) from a unix host if trust is given in a
.rhosts file.
 - runs as a service and can be given the administrator account to run
under.
 - can execute scripts from here.  Handy if scripts reside on a Samba
or NT server, but could be local, too.
 - easy to install:
  - Make sure rshsetup.exe,  rshsvc.dll,  rshsvc.exe is
  in C:\winnt\system32 (Windows dir).
  - Run: rshsetup  c:\winnt\system32\rshsvc.exe  c:
\winnt\system32\rshsvc.dll
  - Put .rhosts in C:\winnt\system32\drivers\etc  with trusted
hostnames.
  - Start Remote Shell Service with "automatic" and administrator
acct.


2)  Program a client and a server script in perl that uses sockets for
communication.  See Camel Book  pp. 348 for samples.  This takes more
effort but can be used on multiple platforms (as both clients and servers)
using the perl script to detect what OS is running (  $my_os=$^O ) and
handle accordingly.










Re: reading the next line from a file

2001-06-13 Thread Brett W. McCoy

On Wed, 13 Jun 2001, Esrar Chowdhury wrote:

> my question is...how do I make the read pointer read every 10th line
> from my input file? (After reading one line, does the read pointer stay
> on the same line or automatically go the next line?)

Hmmm... a homework problem?

Keep a counter that keeps track of the line number you are reading and
only do stuff to the data read from the line if the line number is
divisible by 10.

-- Brett
   http://www.chapelperilous.net/btfwk/

I may not be totally perfect, but parts of me are excellent.
-- Ashleigh Brilliant





Re: Huge hash ... running out of memory without warning???

2001-06-13 Thread WebMaster AIM-US

 One thing you could do is to read only the things you need into memory at 
 the time you need them to.  If you change the values in the hash(es), you 
 could dump it to a temporary file and load them again as needed(note kind 
 of like a swap file does).
 
 Another thing would be to make the calculations, print them to the html 
 file, and move on, delete the hash etc.
 
 As always, there may well be a better solution than the two above
 Stephen


__ Reply Separator _
Subject: Huge hash ... running out of memory without warning???
Author:  <[EMAIL PROTECTED]> at Internet
Date:6/13/2001 2:04 PM


I have just written a program that makes an array of hashes of hashes of 
hashes.  It reads all kind of information in from a bunch of files and 
then later I access the elements of this thing in a convienient way 
because it's kind of like a little database.  Anyways, I end up printing 
everything out into a very big html table.  I noticed that *sometimes* 
nothing is printed  when I say 'print this part of that array...' Thought 
it was a bug in the code, but then I ran the program on a machine with 
more memory and *now* the elements that were missing previously are 
printed, but some 'further on down the line' are not.  It seems that the 
computer is running out of memory and at some point no data really gets 
added to this monster of a list of lists...  What the heck should I do so 
that I can perform these functions, but not run into this problem of 
running out of memory?
 
Cheers,
Bryan




Re: Huge hash ... running out of memory without warning???

2001-06-13 Thread Brett W. McCoy

On Wed, 13 Jun 2001, Bryan Gmyrek wrote:

> I have just written a program that makes an array of hashes of hashes of
> hashes.  It reads all kind of information in from a bunch of files and
> then later I access the elements of this thing in a convienient way
> because it's kind of like a little database.  Anyways, I end up printing
> everything out into a very big html table.  I noticed that *sometimes*
> nothing is printed  when I say 'print this part of that array...'
> Thought it was a bug in the code, but then I ran the program on a
> machine with more memory and *now* the elements that were missing
> previously are printed, but some 'further on down the line' are not.  It
> seems that the computer is running out of memory and at some point no
> data really gets added to this monster of a list of lists...  What the
> heck should I do so that I can perform these functions, but not run into
> this problem of running out of memory?

You might want to look into using DB_File -- your hash will use your disk
as a sort of 'virtual memory', plus your hash will be persistent between
calls of your script:

use DB_File;

tie %myhash, "DB_File", $filename or die "Can't open $filename$!\n";

#do stuff to gather data

$myhash{$somekey} = $somevalue;

#do more stuff with your data

untie %myhash;
   http://www.chapelperilous.net/btfwk/

Youth.  It's a wonder that anyone ever outgrows it.





RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread Dave Newton

Bear in mind that without any sort of delay it's unlikely
you'll be able to see any of this occuring.

Ah, the good old days, where a 300-baud modem was fast
and little spinny cursors were still interesting. *sigh*

Dave

--
Dave Newton, [EMAIL PROTECTED]




Re: reading the next line from a file

2001-06-13 Thread Dave Cross

On Wed, Jun 13, 2001 at 01:30:07PM -0700, Esrar Chowdhury ([EMAIL PROTECTED]) wrote:
> Hi!
> 
> I just started using perl and have a question. Let say I have an inputfile
> with 100 lines. Each of these lines contain a name...first name and
> last name.
> 
> I need to be able to read the 1st name..the 10th name...20th name..so on 
> i.e. every 10th name from the input file.
> 
> I do :
> 
> $name = ; #for the 1st line 
> 
> # have already opened my input file by
> 
> unless (open(INFILE, "test_input.txt")) {
> die ("Input file test_input.txt cannot be opened.\n");
> }
> 
> my question is...how do I make the read pointer read every 10th line
> from my input file? (After reading one line, does the read pointer stay
> on the same line or automatically go the next line?)

It's probably easiest to read every line, but only process every 10th one.

Something like this should do it:

while () {
  next unless $. % 10; # skip line unless it's a multiple of 10

  # Do whatever processing you want
  # The line is in $_
}

hth,

Dave...




reading the next line from a file

2001-06-13 Thread Esrar Chowdhury

Hi!

I just started using perl and have a question. Let say I have an inputfile
with 100 lines. Each of these lines contain a name...first name and
last name.

I need to be able to read the 1st name..the 10th name...20th name..so on 
i.e. every 10th name from the input file.

I do :

$name = ; #for the 1st line 

# have already opened my input file by

unless (open(INFILE, "test_input.txt")) {
die ("Input file test_input.txt cannot be opened.\n");
}

my question is...how do I make the read pointer read every 10th line
from my input file? (After reading one line, does the read pointer stay
on the same line or automatically go the next line?)


Thanks in advance.

--
Esrar


Esrar Chowdhury
CCS Internet
13740 Research Blvd Suite #O-4
Austin, TX 78750
Phone: 512-257-2274


Re: Huge hash ... running out of memory without warning???

2001-06-13 Thread Eduard Grinvald

Hey, I had a similiar problem, but under different circumstances, i 
found only 2 reasonable solutions: tieing the hashes to a db file, and 
not storing data before printing it (print as soon as read). Tell me if 
you find another solution

__END__
=sincerely, eduard grinvald
=email: [EMAIL PROTECTED]
=dev-email: [EMAIL PROTECTED]
=dev-site: r-x-linux.sourceforge.net
=icq:   114099136
=PGP
-BEGIN PGP PUBLIC KEY BLOCK-
Version: PGPfreeware 6.5.8 for non-commercial use 

mQGiBDr60ScRBADsdYfjVgLPiUU8kJvLx9rsONfx1K4wPAKLUCcFOyhmBvIT/EEY
pE2PVoOjosUdlkGGGFo9BLUi7UHoTrL7NyupJ4yHCU8wQiSPYK2GuZn5+ishIUI3
sDifAE4JKuLxtz2fdBcoimrFBfXQRwNrmIqFnA+ooP5GRrJxHpgAn6rvkwCg/0B8
uIXmUlVF+nwVHS6T2fAjYrUEAIe8LmwDVOorcWDRtoUzzSToAhhMY5ZM02OoG464
2SJzBtDo8ABcWCdddRjeEV3Mt5ohDoLXzH9N2LuOx0AEaWcC94a3y8pcGoF1Mbpq
UFQxUeh1TrKJlaTG0qSCb5euoIFPt5trob93CsHxVd69h6WKi3xOf1jXNbXsfWoj
b56jBACC8Mfhcpjtiw0KZRfqdrb5w11HNb0kP1Ma5mEKqsOBh8MlR9EyBrCji98B
pilGYsaW9PCxaFhJDPPbO6hcERup/O7787+LVc1ZYdlJFq/APcvNZZvbrHB7+uYW
eTI/Vmi7rB2ljE2mpEtms6RoiXqNF32xHDx2pSdSla/kqhPy2rQfRWR1YXJkIEdy
aW52YWxkIDxlZzM0NEBueXUuZWR1PokATgQQEQIADgUCOvrRJwQLAwIBAhkBAAoJ
EDDNAitGCH7xrjMAniAtflvrVvGegFgBYWv9f3eYFTQnAKDPJbKEjt2sOdRV1Ey5
Yah5ScFZEbkEDQQ6+tEnEBAA+RigfloGYXpDkJXcBWyHhuxh7M1FHw7Y4KN5xsnc
egus5D/jRpS2MEpT13wCFkiAtRXlKZmpnwd00//jocWWIE6YZbjYDe4QXau2FxxR
2FDKIldDKb6V6FYrOHhcC9v4TE3V46pGzPvOF+gqnRRh44SpT9GDhKh5tu+Pp0NG
CMbMHXdXJDhK4sTw6I4TZ5dOkhNh9tvrJQ4X/faY98h8ebByHTh1+/bBc8SDESYr
Q2DD4+jWCv2hKCYLrqmus2UPogBTAaB81qujEh76DyrOH3SET8rzF/OkQOnX0ne2
Qi0CNsEmy2henXyYCQqNfi3t5F159dSST5sYjvwqp0t8MvZCV7cIfwgXcqK61qlC
8wXo+VMROU+28W65Szgg2gGnVqMU6Y9AVfPQB8bLQ6mUrfdMZIZJ+AyDvWXpF9Sh
01D49Vlf3HZSTz09jdvOmeFXklnN/biudE/F/Ha8g8VHMGHOfMlm/xX5u/2RXscB
qtNbno2gpXI61Brwv0YAWCvl9Ij9WE5J280gtJ3kkQc2azNsOA1FHQ98iLMcfFst
jvbzySPAQ/ClWxiNjrtVjLhdONM0/XwXV0OjHRhs3jMhLLUq/zzhsSlAGBGNfISn
CnLWhsQDGcgHKXrKlQzZlp+r0ApQmwJG0wg9ZqRdQZ+cfL2JSyIZJrqrol7DVes9
1hcAAgIQAO6f9QVuw3eFMDxx4kVmw9pXlMcPlZT0xfBrzLkHwjoA0wdLp2W/ZWEC
FKQl7EV8yh3bqchlIIKRMLp05+5wgyS4GKsxRaRn1vUcKtPIe+mUojjvwkbdrLAM
TdZDVCwm1pxZqncCKrasJ8jtRT8kf93x3o1m0grVeldGukCvFl91gKXUv4vRT0/8
12MzhrxTkycx+pmS95Ytv7zps827dm6pXtlsTw9L7XNXYVTzHRd9MlvQzSxYIh2w
U0pwZfiNfYKKMOHjlQbHAjZtmuC7TpmOWaxDw0kqo7K6sYqo/bPs3dA5eA/0mfDl
7M2nwUjReCy1/O9B2Mf3QwjW712Rqyh2l+7Yp+GgIvHMHnIClZcNGjYh3jALUM3+
OenmcZfBzf6uuw9yFt/3bhoK/YkJJ6BIxx4q04TY93x28IqTt3l17omX+oOaDGS3
7gNTE52LTMUUwD+ienXrsu5mPL8CzrhXQAMTekJhc/HpOhNGPsqIe9TbFuacxr7j
OCJxPeeFGEO2NJ+ChCk0z3S1tWmDrM1gxdIxUbO1bp8hBm7LP9rKkMlEqpSJWdS8
yJmv/9WtDUTZdEJzzFeF+rp2lZpYkI/+sqVJP884fJ9NTS0aXiO1GxQWOKoVE58H
cyrO3hpYgMdC1oP4WZnEJwkLAN+4WnsF2DkKmkNvJRjAANSBTJF3iQBGBBgRAgAG
BQI6+tEnAAoJEDDNAitGCH7xa7AAn0dybVrFf+QHtfgkAsRK3oXY+7gwAJ4sWtYC
GuYw+8LgdC7Mp2ICim9MqA==
=iAF5
-END PGP PUBLIC KEY BLOCK-
=cut


- Original Message -
From: "Bryan Gmyrek" <[EMAIL PROTECTED]>
Date: Wednesday, June 13, 2001 2:04 pm
Subject: Huge hash ... running out of memory without warning???

> I have just written a program that makes an array of hashes of 
> hashes of
> hashes.  It reads all kind of information in from a bunch of files and
> then later I access the elements of this thing in a convienient way
> because it's kind of like a little database.  Anyways, I end up 
> printingeverything out into a very big html table.  I noticed that 
> *sometimes*nothing is printed  when I say 'print this part of that 
> array...'Thought it was a bug in the code, but then I ran the 
> program on a
> machine with more memory and *now* the elements that were missing
> previously are printed, but some 'further on down the line' are 
> not.  It
> seems that the computer is running out of memory and at some point no
> data really gets added to this monster of a list of lists...  What the
> heck should I do so that I can perform these functions, but not 
> run into
> this problem of running out of memory?
> 
> Cheers,
> Bryan
> 




Re[2]: Problem printing a system value to a filehandle (windows)

2001-06-13 Thread Peter Scott

At 12:46 PM 6/13/01 -0400, Tim Musson wrote:

>I was thinking along the same lines, but have another question.  Why
>would you.instead of,in the print line?
>
>why
> print DATAFILE "\n\n" . '='x77 . "\n\n" . localtime;
>over
> print DATAFILE "\n\n" , '='x77 , "\n\n" , localtime;

No difference in this case.  The . will put the things on each side in 
scalar context, the , will keep them in the list context imposed by 
print.  For other things on each side, this can make a difference.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Re: map question

2001-06-13 Thread Peter Scott

At 11:40 AM 6/13/01 -0500, [EMAIL PROTECTED] wrote:
>How do you evaluate a block in scalar context? Any light on this
>( or a pointer ) maybe?

$ perl -le 'do { print wantarray ? "LIST" : "SCALAR" }'
SCALAR

perlfunc should mention this under 'do', perhaps...
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Huge hash ... running out of memory without warning???

2001-06-13 Thread Bryan Gmyrek

I have just written a program that makes an array of hashes of hashes of
hashes.  It reads all kind of information in from a bunch of files and
then later I access the elements of this thing in a convienient way
because it's kind of like a little database.  Anyways, I end up printing
everything out into a very big html table.  I noticed that *sometimes*
nothing is printed  when I say 'print this part of that array...'
Thought it was a bug in the code, but then I ran the program on a
machine with more memory and *now* the elements that were missing
previously are printed, but some 'further on down the line' are not.  It
seems that the computer is running out of memory and at some point no
data really gets added to this monster of a list of lists...  What the
heck should I do so that I can perform these functions, but not run into
this problem of running out of memory?

Cheers,
Bryan



Re: Question regarding the Substitution Operator

2001-06-13 Thread Jeff 'japhy' Pinyan

On Jun 13, Carl Rogers said:

>Good afternoon;
>I have a dumb question: I'm working with the following:
>
>$line = "Joe Doe 123 Main St. Sometown, USA";
>
>I have parsed the line to assign the values to the following variables:
>
>$fname = "Joe";
>$lname = "Doe";
>$addr = "123 Main St.";
>
>I'm trying to use the substitution operator to do something like:
>
>   $line =~ s/$fname $lname $addr//;   ## doesn't like this syntax
>
>So the value of $line now becomes "Sometown, USA".

It does work, with the data you've given us.  It doesn't work with the
data you have.  Use the \Q...\E escape sequences so that regex-specific
characters are treated as literal characters:

  $line =~ s/\Q$fname $lname $addr\E//;

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **




Question regarding the Substitution Operator

2001-06-13 Thread Carl Rogers

Good afternoon;
I have a dumb question: I'm working with the following:

$line = "Joe Doe 123 Main St. Sometown, USA";

I have parsed the line to assign the values to the following variables:

$fname = "Joe";
$lname = "Doe";
$addr = "123 Main St.";

I'm trying to use the substitution operator to do something like:

$line =~ s/$fname $lname $addr//;   ## doesn't like this syntax

So the value of $line now becomes "Sometown, USA".

I know I can do this by using 3 successive $line =~ s/..//; statements, but 
can it be done with one statement like I tried above??
I've tried placing [ ] around each variable, using the || operator between 
each variable- nothing seems to work.

Any and all help would be greatly appreciated.
Sincerely,
Carl

PS: I know: There are no dumb questions. Only questions asked by dumb people! :)




Re: Problem printing a system value to a filehandle (windows)

2001-06-13 Thread Craig S Monroe

Thank you all for your suggestions.
I appreciate you all giving your time...

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

- Original Message -
From: "John Edwards" <[EMAIL PROTECTED]>
To: "Beginners@Perl (E-mail)" <[EMAIL PROTECTED]>
Sent: Wednesday, June 13, 2001 12:09 PM
Subject: RE: Problem printing a system value to a filehandle (windows)


> Hi, just joined the list and jumping into the middle of this thread, so
> excuse me if I'm talking out of turn.
>
> I have a couple of suggestions for you Craig.
>
> 1) Where you have
> print DATAFILE
>
"\n\n===
> ==\n\n";
>
> You could instead use
>
> print DATAFILE "\n\n" . '='x77 . "\n\n";
>
> This will print out two newlines, then 77 equals signs, then the last two
> newlines. It's a little easier to read and make changes to the number of
> equals signs. You could also use a variable number of equals signs if you
> wanted. (Maybe not useful for this task, but some other)
>
> e.g
>
> $repeat = 60;
> print DATAFILE "\n\n" . '='x$repeat . "\n\n";
>
> Next, why do a system call to get the date and time? Perl comes with built
> in functions to do this for you. A really quick and simple way is to use
the
> scalar value of the localtime function. (localtime normally returns a list
> value but called in scalar context it will return an easy to read date and
> time ideal for a timestamp)
>
> print DATAFILE scalar(localtime);
>
> This will store somthing like "Wed Jun 13 16:56:37 2001" into the
DATAFILE.
>
> so all in all you could re-write your code as:
>
> --
> print DATAFILE "\n\n" . '='x77 . "\n\n";
> print DATAFILE scalar(localtime);
> --
>
> You could even do it all on one line and lose the scalar bit as when you
> concancate you use the scalar, not list values of the function.
>
> print DATAFILE "\n\n" . '='x77 . "\n\n" . localtime;
>
> HTH
>
> John
>
> -Original Message-
> From: Chas Owens [mailto:[EMAIL PROTECTED]]
> Sent: 13 June 2001 16:41
> To: Craig S Monroe
> Cc: [EMAIL PROTECTED]
> Subject: Re: Problem printing a system value to a filehandle (windows)
>
>
> On 13 Jun 2001 10:49:44 -0400, Craig S Monroe wrote:
> > Hello all,
> >
> > I have a script that opens a socket to a device, issues some commands,
> > then writes the results to a datafile.
> > That all works fine. I decided that I wanted to time stamp each of the
> > entries
> >
> > So where I put my separator:
> >
> >  # print a section separator to the dateFile
> >  print DATAFILE
> > "\n\n===
> > ==\n\n";
> >
> > I wanted to put the date below it.
> >
> >  $time =~ system('TIME \/T');
> >  $date =~ system('DATE \/T');
>
> There are two things wrong here.  First system returns the exit code of
> the process you call (not the output), you want to use backticks (shift
> ~ on most keyboards in the US).  Second =~ is the binding operator for
> regexps not the assignment operator.  You should be saying:
>
> $time = `TIME /T`;
> $date = `DATE /T`;
>
> >  print DATAFILE "\n$time $date";
> >
> > It would not append the time and date.
> > So, I used the above to make it it's own perl script, and just removed
> > the filehandle so the output would print to the console.
> >
> > $time =~ system('TIME \/T');
> >  $date =~ system('DATE \/T');
> >  print "\n$time $date";
> >
> > This printed the date and the time to the console.
> > Does anyone have any suggestions as to why this is not working?
>
> It is working exactly as you told it to work .  It is running
> the TIME command (which outputs the time to stdout) and then running the
> DATE command (which outputs the date to stdout).
>
> >
> > Thank you,
> >
> > 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
> >
> --
> Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
> Grudnuk demand sustenance!
>
>
>
> --Confidentiality--.
> This E-mail is confidential.  It should not be read, copied, disclosed or
> used by any person other than the intended recipient.  Unauthorised use,
> disclosure or copying by whatever medium is strictly prohibited and may be
> unlawful.  If you have received this E-mail in error please contact the
> sender immediately and delete the E-mail from your system.
>
>




RE: RE: Unexplainable behavior

2001-06-13 Thread Peter Cornelius

So wouldn't you expect the more clingy '||' to work here?  It doesn't, I
checked.  If operator precedence was the problem then using the higher
precedence operator should work.  I think this is a logic flaw.  Charles
really meant 

if (exists ... and this and that) { ... }

not 

if (exists ... and (this or that)) { ... }  

The first is only true when all three are true, the second is true when the
first and either the second or third thing are true.  It looks like Robin
has a posting about De Morgan's law which is the formal explanation of all
this Boolean algebra goop.  

Discrete math bites again.

Peter C.

> >$hash{s} = "T";
> >
> >
> >if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
> > print "inside\n";
> >}
> >else{  print "outside\n"; }
> 
> 'or' is less "clingy" than 'and'.  Therefore, your code parses like:
> 
>   if (
> (exists $hash{s} and $hash{s} ne "T")
> or
> ($hash{s} ne "F")
>   ) { ... }
> 
> Change the parenthesization to suit your needs:
> 
>   if (exists ... and (this or that)) { ... }



Re: Problem printing a system value to a filehandle (windows)

2001-06-13 Thread Craig S Monroe

Chris,
I appreciate you responding to my message, but I don't understand some of
the
issues you were speaking about.

"you want to use backticks " I do not understand what you mean by this?
Where should I be using them? In place of what?

I understood the incorrect use of the binding operator.

As I included in the original message, when attempting to print to the
datafile,

 $time =~ system('TIME \/T');
 $date =~ system('DATE \/T');
 print DATAFILE "\n$time $date";

This did not work, so I removed the filehandle and put the 3 lines in it's
own program to test it to make
sure that it would print the date and time to the console.

 $time =~ system('TIME \/T');
 $date =~ system('DATE \/T');
 print "\n$time $date";

That worked. I am not sure that I understand your point.
Thanks for your patience,

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

- Original Message -
From: "Chas Owens" <[EMAIL PROTECTED]>
To: "Craig S Monroe" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, June 13, 2001 11:40 AM
Subject: Re: Problem printing a system value to a filehandle (windows)


> On 13 Jun 2001 10:49:44 -0400, Craig S Monroe wrote:
> > Hello all,
> >
> > I have a script that opens a socket to a device, issues some commands,
> > then writes the results to a datafile.
> > That all works fine. I decided that I wanted to time stamp each of the
> > entries
> >
> > So where I put my separator:
> >
> >  # print a section separator to the dateFile
> >  print DATAFILE
> > "\n\n===
> > ==\n\n";
> >
> > I wanted to put the date below it.
> >
> >  $time =~ system('TIME \/T');
> >  $date =~ system('DATE \/T');
>
> There are two things wrong here.  First system returns the exit code of
> the process you call (not the output), you want to use backticks (shift
> ~ on most keyboards in the US).  Second =~ is the binding operator for
> regexps not the assignment operator.  You should be saying:
>
> $time = `TIME /T`;
> $date = `DATE /T`;
>
> >  print DATAFILE "\n$time $date";
> >
> > It would not append the time and date.
> > So, I used the above to make it it's own perl script, and just removed
> > the filehandle so the output would print to the console.
> >
> > $time =~ system('TIME \/T');
> >  $date =~ system('DATE \/T');
> >  print "\n$time $date";
> >
> > This printed the date and the time to the console.
> > Does anyone have any suggestions as to why this is not working?
>
> It is working exactly as you told it to work .  It is running
> the TIME command (which outputs the time to stdout) and then running the
> DATE command (which outputs the date to stdout).
>
> >
> > Thank you,
> >
> > 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
> >
> --
> Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
> Grudnuk demand sustenance!
>
>




Re: map question

2001-06-13 Thread Atul_Khot

Dave>  Well it's quite simple actually. A BLOCK of Perl code is a BLOCK of 
Perl code.
Dave>  No matter where you put it. Typically anything inside a set of {}'s 
is a block
Dave>  of code. So the fact that a subroutine consists of a block of code
Dave>
Dave>  sub foo { BLOCK }
Dave>
Dave>  and map can use a block of code
Dave>
Dave>  map { BLOCK } @list
Dave>
Dave>  isn't too surprising.

This I think needs to be corrected slightly. 
"Programming Perl -- 3rd Ed." in section named "Bare Blocks" ( chapter 4 ) 
says, 
... Note that this is not true of the blocks in eval {}, sub {}, or much 
to everyone's surprise, do {}. These three are not loop blocks because 
they are not BLOCKs by themselves; ".
so in a certain sense, these differ. I sincerely feel there is something 
more to it. Also, What really bothers me is "Evaluates BLOCK in a list 
context". How do you evaluate a block in scalar context? Any light on this 
( or a pointer ) maybe?

 Regards,
Atul




Re: combine STDERR and STDOUT

2001-06-13 Thread rob chanter

On Wed, Jun 13, 2001 at 11:53:48AM -0400, Charles Lu wrote:
> How do I direct the messages destined for STDERR and redirect them to 
> STDOUT?
> 
> 
> 
> I have a perl script A that calls another program B.  If there is bad input, 
> Program B dumps out a lot of error messages through STDERR.  I want to be 
> able to stop my perl script when it detects messages coming from program B.  
> What is the best way to do that?  One way I thought of is by redirecting 
> error messages to STDOUT and capture it in my perl program and TERMINATE the 
> perl program if it detects anything.  (when program B runs normally, there 
> is no output)

Well, if you're on a Unix(-like) system, you can redirect STDOUT on the
command line:

$return = `program_B 2>&1`;
if ($return) {die "Program B blew up.\n"};

Not sure whether something like the following would work or not.

open PROGRAM_B, "program_B 2>&1 |";


I'm sure others will have more elegant solutions.

chrs
rob c



Re: Beginer...Any free resources for Learning Perl

2001-06-13 Thread Evgeny Goldin (aka Genie)


Check up my catalog at :
http://geniek.net/books/books/Programming/Perl/index-list.html

It's only a catalog but I upload titles from it upon request.





RE: Problem printing a system value to a filehandle (windows)

2001-06-13 Thread John Edwards

Hi, just joined the list and jumping into the middle of this thread, so
excuse me if I'm talking out of turn.

I have a couple of suggestions for you Craig.

1) Where you have 
print DATAFILE
"\n\n===
==\n\n";

You could instead use 

print DATAFILE "\n\n" . '='x77 . "\n\n";

This will print out two newlines, then 77 equals signs, then the last two
newlines. It's a little easier to read and make changes to the number of
equals signs. You could also use a variable number of equals signs if you
wanted. (Maybe not useful for this task, but some other)

e.g 

$repeat = 60;
print DATAFILE "\n\n" . '='x$repeat . "\n\n";

Next, why do a system call to get the date and time? Perl comes with built
in functions to do this for you. A really quick and simple way is to use the
scalar value of the localtime function. (localtime normally returns a list
value but called in scalar context it will return an easy to read date and
time ideal for a timestamp)

print DATAFILE scalar(localtime);

This will store somthing like "Wed Jun 13 16:56:37 2001" into the DATAFILE.

so all in all you could re-write your code as:

--
print DATAFILE "\n\n" . '='x77 . "\n\n";
print DATAFILE scalar(localtime);
--

You could even do it all on one line and lose the scalar bit as when you
concancate you use the scalar, not list values of the function.

print DATAFILE "\n\n" . '='x77 . "\n\n" . localtime;

HTH

John

-Original Message-
From: Chas Owens [mailto:[EMAIL PROTECTED]]
Sent: 13 June 2001 16:41
To: Craig S Monroe
Cc: [EMAIL PROTECTED]
Subject: Re: Problem printing a system value to a filehandle (windows)


On 13 Jun 2001 10:49:44 -0400, Craig S Monroe wrote:
> Hello all,
> 
> I have a script that opens a socket to a device, issues some commands,
> then writes the results to a datafile.
> That all works fine. I decided that I wanted to time stamp each of the
> entries
> 
> So where I put my separator:
> 
>  # print a section separator to the dateFile
>  print DATAFILE
> "\n\n===
> ==\n\n";
> 
> I wanted to put the date below it.
>  
>  $time =~ system('TIME \/T');
>  $date =~ system('DATE \/T');

There are two things wrong here.  First system returns the exit code of
the process you call (not the output), you want to use backticks (shift
~ on most keyboards in the US).  Second =~ is the binding operator for
regexps not the assignment operator.  You should be saying:

$time = `TIME /T`;
$date = `DATE /T`;

>  print DATAFILE "\n$time $date";
> 
> It would not append the time and date.
> So, I used the above to make it it's own perl script, and just removed
> the filehandle so the output would print to the console.
> 
> $time =~ system('TIME \/T');
>  $date =~ system('DATE \/T');
>  print "\n$time $date";
> 
> This printed the date and the time to the console.
> Does anyone have any suggestions as to why this is not working?

It is working exactly as you told it to work .  It is running
the TIME command (which outputs the time to stdout) and then running the
DATE command (which outputs the date to stdout).

> 
> Thank you,
> 
> 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
> 
--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
Grudnuk demand sustenance!



--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





RE: non-greedy *

2001-06-13 Thread Evgeny Goldin (aka Genie)


> I guess it's talking about *? - this will match the minimum number of times
> for a sucessful match, rather than the maximum. 

 Let me say the same with more formalism :
 
 perldoc perlre :

By default, a quantified subpattern is "greedy", that is, it will match
as many times as possible (given a particular starting location) while
still allowing the rest of the pattern to match. If you want it to match
the minimum number of times possible, follow the quantifier with a "?".
Note that the meanings don't change, just the "greediness":

*? Match 0 or more times
+? Match 1 or more times
?? Match 0 or 1 time
{n}?   Match exactly n times
{n,}?  Match at least n times
{n,m}? Match at least n but not more than m times





Re: converting standard input to an upper or lower case

2001-06-13 Thread Evgeny Goldin (aka Genie)


> Is the moral of this story "Don't use regexps unless nothing
> else will solve the problem?".

First, it even wasn't me who gave this idea - I met it twice in both
"Effective Perl Programming" and "Data Munging with Perl".

Second, the moral, I think, is "do whatever is good for your eyes but
think about efficiency too". And string operators should be more efficient
then regexes ( well, I didn't implement them but it can't be any other
way )
Sometimes, a combination of index + substr gives the same result as one
regex, but takes 3 lines of code - I take regexes in this case.
But "lc( $ans ) eq 'y'" is a tiny work - why applying such
a big thing as a regular expression mechanism for it ?

TMTOWTDI





Re: combine STDERR and STDOUT

2001-06-13 Thread Paul


--- Charles Lu <[EMAIL PROTECTED]> wrote:
> How do I direct the messages destined for STDERR and redirect them to
> STDOUT?

try:
  *STDERR = *STDOUT;

This aliases STDERR so that it's really STDOUT anyway.



=
print "Just another Perl Hacker\n"; # edited for readability =o)
=
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



combine STDERR and STDOUT

2001-06-13 Thread Charles Lu

How do I direct the messages destined for STDERR and redirect them to 
STDOUT?



I have a perl script A that calls another program B.  If there is bad input, 
Program B dumps out a lot of error messages through STDERR.  I want to be 
able to stop my perl script when it detects messages coming from program B.  
What is the best way to do that?  One way I thought of is by redirecting 
error messages to STDOUT and capture it in my perl program and TERMINATE the 
perl program if it detects anything.  (when program B runs normally, there 
is no output)
_
Get your FREE download of MSN Explorer at http://explorer.msn.com




Re: Problem printing a system value to a filehandle (windows)

2001-06-13 Thread Chas Owens

On 13 Jun 2001 10:49:44 -0400, Craig S Monroe wrote:
> Hello all,
> 
> I have a script that opens a socket to a device, issues some commands,
> then writes the results to a datafile.
> That all works fine. I decided that I wanted to time stamp each of the
> entries
> 
> So where I put my separator:
> 
>  # print a section separator to the dateFile
>  print DATAFILE
> "\n\n===
> ==\n\n";
> 
> I wanted to put the date below it.
>  
>  $time =~ system('TIME \/T');
>  $date =~ system('DATE \/T');

There are two things wrong here.  First system returns the exit code of
the process you call (not the output), you want to use backticks (shift
~ on most keyboards in the US).  Second =~ is the binding operator for
regexps not the assignment operator.  You should be saying:

$time = `TIME /T`;
$date = `DATE /T`;

>  print DATAFILE "\n$time $date";
> 
> It would not append the time and date.
> So, I used the above to make it it's own perl script, and just removed
> the filehandle so the output would print to the console.
> 
> $time =~ system('TIME \/T');
>  $date =~ system('DATE \/T');
>  print "\n$time $date";
> 
> This printed the date and the time to the console.
> Does anyone have any suggestions as to why this is not working?

It is working exactly as you told it to work .  It is running
the TIME command (which outputs the time to stdout) and then running the
DATE command (which outputs the date to stdout).

> 
> Thank you,
> 
> 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
> 
--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
Grudnuk demand sustenance!





Re: testing on email characters

2001-06-13 Thread Chas Owens

 

/^[\w.-]+$/ and !/[^\w.-]/ have one major difference (and I am kicking
myself for not seeing it until now).  The former requires that at least
one character must exist. !/[^\w.-]/ is equivalent to /[^[\w.-]*$/.
However, this can be overcome by saying !(/^$/ or /[^\w.-]/) and it
still has one advantage over /^[\w.-]+$/: the values of $`, $&, and $'
(everything before the match, the match, and everything after the match
respectivly).  This allows the creation of useful messages such as:

if (/^$/ or /[^\w.-]/) {
print "ilegal character ($&) in:$_\n";
}

or

if (/^$/ or /[^\w.-]/) {
print "cannot use character ($&) in:$`$&$'\n";
}


--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
Kallisti!





Re: Strict, require and hashes..

2001-06-13 Thread Paul


--- Dianne Van Dulken <[EMAIL PROTECTED]> wrote:
> Hi all, 
>  
> I was (yet again) hoping someone might help me with something.
>  
> I have a cfg file called extra_details.cfg containing a hash
> %my_hash.
>  
> I reference this in my perl script, using a require
> "extra_details.cfg"
>  
> The problem now is that every time I try to reference my_hash in my
> script,
> whilst I am using strict, I get a 
> Global symbol "%my_hash" requires explicit package name error.
>  
> If I add an "my %my_hash;" anywhere, it overwrites the hash, so it is
> just a
> blank one.
>  
> Does anyone know how I can get around this?
>  
> It will work perfectly if I remove the "use strict" line, but I have
> these
> terrible qualms of guilt and fear every time I do so.

Just reference it expicitly:

  %main::my_hash;

=
print "Just another Perl Hacker\n"; # edited for readability =o)
=
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: non-greedy *

2001-06-13 Thread Jeff 'japhy' Pinyan

On Jun 13, Josh said:

>Hi all,
>   I'm reading Mastering Regular Expressions and it discusses a
>non-greedy version of star. can someone explain how to write this
>non-greedy version of star. (i.e. how does it differ than just *)

Thanks to Peter for plugging my modules... you might also want to take a
look at "Regular Expressions in Perl", which can be found at

  http://www.pobox.com/~japhy/docs/book.html

I talk about greediness vs. non-greediness (or laziness) in chapter 6, I
believe.

The main difference is that * matches as much as it can, and then backs
off slowly until a match is complete, whereas *? matches as little as it
can, and inches forward slowly until a match is complete.

Think of it as searching through a book for something.  Sometimes you're
greedy and start at the end and flip backwards.  Sometimes you're lazy and
go forwards.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **




Re: checking the status of FileHandle

2001-06-13 Thread Paul


--- Charles Lu <[EMAIL PROTECTED]> wrote:
> 
>Lets say I want my program to print to STDOUT unless the user
> specifies that the output goes to a file.  Here is my code:
> 
> 
> 
> my $oldhandle=undef;
> if($user_input ne 'STDOUT') {   #user specify output to a
> file
> open (OUT,">$temp.txt") or die "Can't open the file\n";
> $oldhandle = select OUT;
> }
> 
> print "blah blah blah\n";
> 
> select ($oldhandle) if(defined($oldhandle));  #restore STDOUT as
> default
> 
> At this point I want to close my FileHandle (OUT) if it was open.  My
> 
> question is HOW do I check to see whether a filehandle(OUT) has been
> opened 
> so I can explicitly close it with
> 
> close(OUT);

use FileHandle to create the open file handle in a common scalar, and
don't put anything in it other wise. Then you can check it like a Bool.

 my ($fh,$oldhandle);
 if ($some_condition) {
   $fh = new FileHandle ">$file" or die "$file: $!";
   $oldhandle = select $fh;
 }
 # . . . .
 close $fh if $fh;




__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



RE: Unexplainable behavior

2001-06-13 Thread Robin Lavallee (LMC)


> -Original Message-
> From: Charles Lu [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, June 13, 2001 10:53 AM
> To:   [EMAIL PROTECTED]
> Subject:  Unexplainable behavior
> 
> The following snippet of code doesn't behave the way I want it to.  Yet i 
> cannot see why?
> 
> 
> $hash{s} = "T";
> 
> 
> if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
>   print "inside\n";
> }
> else{  print "outside\n"; }
> 
> 
This is a logic problem and can be explained by "De Morgan's Law".
Basically, if we analyze the if statement, it contains 3 parts.

exists($hash{s}) --> true
$hash{s} ne "T" --> false
$hash{s} ne "F" --> true

Hence, $hash{s} ne "T" or $hash{s} ne "F" --> true
And 'true' and 'true' --> true, so it goes 'inside'.

So you meant to only go inside if it does not equal
"T" or does not equal "F". This can be done by doing:

if(exists($hash{s}) and $hash{s} ne "T" and $hash{s} ne "F").

-Robin



Re: Unexplainable behavior

2001-06-13 Thread Jos Boumans

untested, but here's my theory:

you're having precedence problems, try parenthesizing!

ie,

if( exists($hash{s}) and ( ($hash{s} ne "T") or ($hash{s} ne "F") ) ) {


hth,

Jos Boumans


Charles Lu wrote:

> The following snippet of code doesn't behave the way I want it to.  Yet i
> cannot see why?
>
> $hash{s} = "T";
>
> if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
> print "inside\n";
> }
> else{  print "outside\n"; }
>
> the OUTPUT of this program prints   "inside".  But I want it to go INSIDE
> only if the key "s" exists in the hash, AND the value of $hash{s} DOES NOT
> equal "T" OR "F".Can anyone suggest what I might be doing wrong here?
> By the way, even if I comment out the line that contain
> $hash{s} = "T";,  the output still goes to "INSIDE".
>
> _
> Get your FREE download of MSN Explorer at http://explorer.msn.com




Re: Unexplainable behavior

2001-06-13 Thread Jeff 'japhy' Pinyan

On Jun 13, Charles Lu said:

>$hash{s} = "T";
>
>
>if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
>   print "inside\n";
>}
>else{  print "outside\n"; }

'or' is less "clingy" than 'and'.  Therefore, your code parses like:

  if (
(exists $hash{s} and $hash{s} ne "T")
or
($hash{s} ne "F")
  ) { ... }

Change the parenthesization to suit your needs:

  if (exists ... and (this or that)) { ... }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **




RE: Unexplainable behavior

2001-06-13 Thread mark crowe (JIC)

Try:
 if(exists($hash{s}) and $hash{s} ne "T" __and__ $hash{s} ne "F") {

(underscore for emphasis, not code). Using the 'or' means that if $hash{s}
is "T", ($hash{s} ne "F") is actually true, so it continues with that block.

Cheers

Mark C

-Original Message-
From: Charles Lu [mailto:[EMAIL PROTECTED]]
Sent: 13 June 2001 15:53
To: [EMAIL PROTECTED]
Subject: Unexplainable behavior


The following snippet of code doesn't behave the way I want it to.  Yet i 
cannot see why?


$hash{s} = "T";


if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
print "inside\n";
}
else{  print "outside\n"; }



the OUTPUT of this program prints   "inside".  But I want it to go INSIDE 
only if the key "s" exists in the hash, AND the value of $hash{s} DOES NOT 
equal "T" OR "F".Can anyone suggest what I might be doing wrong here?  
By the way, even if I comment out the line that contain
$hash{s} = "T";,  the output still goes to "INSIDE".


_
Get your FREE download of MSN Explorer at http://explorer.msn.com



Re: Unexplainable behavior

2001-06-13 Thread David M. Lloyd

On Wed, 13 Jun 2001, Charles Lu wrote:

> The following snippet of code doesn't behave the way I want it to.  Yet i 
> cannot see why?
> 
> 
> $hash{s} = "T";
> 
> 
> if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
>   print "inside\n";
> }
> else{  print "outside\n"; }

This expression is true if either:

1. $hash{s} exists and it's not "T";

or

2. $hash{s} is not "F".

Therefore it's always true, because if it is "T" then it's not "F" and
(2) is true, and if it's "F" then it's not "T" and (1) is true.

The solution is to use the 'and' operator:

if (exists($hash{s}) and $hash{s} ne "T" and $hash{s} ne "F") {

Then, the inside of the statement is executed only if ALL THREE
conditions are true.

- D

<[EMAIL PROTECTED]>




Unexplainable behavior

2001-06-13 Thread Charles Lu

The following snippet of code doesn't behave the way I want it to.  Yet i 
cannot see why?


$hash{s} = "T";


if(exists($hash{s}) and $hash{s} ne "T" or $hash{s} ne "F") {
print "inside\n";
}
else{  print "outside\n"; }



the OUTPUT of this program prints   "inside".  But I want it to go INSIDE 
only if the key "s" exists in the hash, AND the value of $hash{s} DOES NOT 
equal "T" OR "F".Can anyone suggest what I might be doing wrong here?  
By the way, even if I comment out the line that contain
$hash{s} = "T";,  the output still goes to "INSIDE".


_
Get your FREE download of MSN Explorer at http://explorer.msn.com




Problem printing a system value to a filehandle (windows)

2001-06-13 Thread Craig S Monroe

Hello all,

I have a script that opens a socket to a device, issues some commands, then writes the 
results to a datafile.
That all works fine. I decided that I wanted to time stamp each of the entries

So where I put my separator:

 # print a section separator to the dateFile
 print DATAFILE 
"\n\n=\n\n";

I wanted to put the date below it.
 
 $time =~ system('TIME \/T');
 $date =~ system('DATE \/T');
 print DATAFILE "\n$time $date";

It would not append the time and date.
So, I used the above to make it it's own perl script, and just removed the filehandle 
so the output would print to the console.

$time =~ system('TIME \/T');
 $date =~ system('DATE \/T');
 print "\n$time $date";

This printed the date and the time to the console.
Does anyone have any suggestions as to why this is not working?

Thank you,

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




Re: non-greedy *

2001-06-13 Thread Peter Cornelius

You might want to check out Japhy's modules YAPE::Regex and
YAPE::Regex::Explain.  You can pass in regular expressions and have it spit out
an explanation of what the parser is doing.

An example of (non) greedy matching would be something like:

$string = "here"; #you want to pull out the tags
and the content separately

$string =~ /(<.*>)([^<>]*)(<.*>)/; #won't work, the .* matches any character
including the '>' so you get the whole string in $1;
$string =~ /(<.*?>)([^<>]*?)(<.*?>)/; #I think this would work.
#Matches only as
many characters as is necessary for the entire match pattern to succeed.
#tags are in $1 and $3, content is in $2

I might have made a mistake with the above as I don't have an interpreter to run
it through at the moment, but I think the underlying info is sound.

Good luck!
Peter C.

Josh wrote:

> Hi all,
> I'm reading Mastering Regular Expressions and it discusses a
> non-greedy version of star. can someone explain how to write this
> non-greedy version of star. (i.e. how does it differ than just *)




RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread mark crowe (JIC)

Hi Matt

The \r option works fine, but an alternative is to use 'print "\b"' - this
will print a backspace character, and means you can have other stuff on the
line too. Try:
$|=1; for ($i=0; $i<10; $i++) {print "$i\b";sleep 1}
This method only works for single digit numbers though, since it only
backspaces a single character (although you could set up a routine to
backspace more depending on the length of the output number). 

$| = 1 turns on OUTPUT_AUTOFLUSH so it prints each time through the loop,
rather than one big rush at the end. The sleep is just there so you have
time to see the number before the next loop.

Cheers

Mark C

>Hi Matt,
>
>I'm very new to perl (a week or so), so this may not be the best way to do
>this, but
>
>for ($i=0; $i<10; $i++) {printf "%d\r",$i;}
>
>This will (should?) print the number followed by a Carriage Return (no
>linefeed), so the cursor returns to the start of the line.
>
>Hope this is what you wanted
>
>Mark
>
>
>>I'm trying something like:
>>
>>for ($i=0; $i<10; $i++){print $i;}
>>
>>and have the numbers iterate in ONE PLACE at the cursor (i.e. print, 
>>then backspace,print the new number, etc). I'm having problems figuring
>>this out. Any ideas? 
>>
>>Thanks
>>
>>Matt



RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread Brett W. McCoy

On Wed, 13 Jun 2001, Pate Mark-marpate1 wrote:

> I'm very new to perl (a week or so), so this may not be the best way to do
> this, but
>
> for ($i=0; $i<10; $i++) {printf "%d\r",$i;}

Just to point out a more Perlish way to do this, rather the C-ish way
(since we're doing Perl and not C):

print "$_\r" for (0..9);

-- Brett
   http://www.chapelperilous.net/btfwk/

If you have to think twice about it, you're wrong.




RE: A Term::ReadKey question -- keep cursor put!

2001-06-13 Thread Pate Mark-marpate1

Hi Matt,

I'm very new to perl (a week or so), so this may not be the best way to do
this, but

for ($i=0; $i<10; $i++) {printf "%d\r",$i;}

This will (should?) print the number followed by a Carriage Return (no
linefeed), so the cursor returns to the start of the line.

Hope this is what you wanted

Mark

-Original Message-
From: Matt Cauthorn [mailto:[EMAIL PROTECTED]]
Sent: 13 June 2001 13:21
To: [EMAIL PROTECTED]
Subject: A Term::ReadKey question -- keep cursor put!


I'm trying something like:

for ($i=0; $i<10; $i++){print $i;}

and have the numbers iterate in ONE PLACE at the cursor (i.e. print, then
backspace,
print the new number, etc). I'm having problems figuring this out. Any
ideas? 

Thanks

Matt

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



More DBI hassels

2001-06-13 Thread justin todd

I am very confused. 

About a week ago I completed a site that used perl and connected to a
MSSQL7 database. Everything worked hunky dory. 

Now I have to start a new script but when I try do a select query it is
as if the site goes into a internal loop. If I run the query directly on
the DB it works fine but when I try run it in the cgi-bin it dont work.
I have set up my ODBC driver to connect to the correct table.

I have done everything the same as before but this time it dont work.

Any ideas?

Justin



  1   2   >