question on appending file

2008-06-25 Thread bob
Hi
I wrote a program to append a number to an existing file.
but found a problem that i can't understand

***
code1:
my $cnt= 0
open FILE, ">>diff.txt";

while () {
if (match some condition) {
$cnt= $cnt+ 1;
}
}

print FILE "cnt is: $cnt\n";
close FILE;
***
the printed $cnt is 0.


but when write like this:
*
code2:
my $cnt= 0
open FILE, "diff.txt";

while () {
if (match some condition) {
$cnt= $cnt+ 1;
}
}
close FILE;

open FILE, ">>diff.txt"
print FILE "cnt is: $cnt\n";
close FILE;
*

the printed $cnt is the right num.

why the 1st code cannot work properly?
thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Splitting and printing on a single line

2012-01-05 Thread bob
Hello

I am very new to perl and I need some guidance on the following issue

My data set is like this

---
Record 38
Richard Nixon
http://en.wikipedia.org/wiki/Richard_Nixon
---
Record 39
Gerald Ford
http://en.wikipedia.org/wiki/Gerald_Ford
---
Record 40
Jimmy Carter
http://en.wikipedia.org/wiki/Jimmy_Carter

and I would like to print it out like

Record 38 \t Richard Nixon \t http://en.wikipedia.org/wiki/Richard_Nixon
Record 39 \t Gerald Ford \t http://en.wikipedia.org/wiki/Gerald_Ford
Record 40 \t Jimmy Carter \t http://en.wikipedia.org/wiki/Jimmy_Carter

Thank you


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Books

2002-05-14 Thread Bob

Hi everyone
I have been reading Learning Perl Second Edition and Programming Perl
2nd Edition. Has Perl evolved that much since these books were written
in 1997 and 98. Some of the things mentioned on this list I have never
seen in Learning Perl SE at least, haven't got into the other too much.
I ordered the newest Learning Perl just in case.
-- 
Bye
Bob     Bob Axmear  208 2nd St Ne  Waukon, Ia 52172
http://groups.yahoo.com/group/the_refuge
Websites http://gardensights.com
Hosta Library http://hostalibrary.org/

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




Re: [ Something Funnie to Read ;) ]

2002-05-16 Thread Bob

Timothy Johnson wrote:
> 
> This IS funny, but you shouldn't send URLs to people without some kind of
> description.  I don't know about the rest of you but I am pretty much
> paranoid about any HTML docs sent to me by email.

Hi Timothy
What could a url do, it isn't a document, just a link.
-- 
Bye
Bob Bob Axmear  208 2nd St Ne  Waukon, Ia 52172
http://groups.yahoo.com/group/the_refuge
Websites http://gardensights.com
Hosta Library http://hostalibrary.org/

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




RE: splitting strings with quoted white space

2001-06-06 Thread Accountant Bob

How about this: (the same but "unrolled")

my @elements;
push @elements, $1 while
   /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
   /\G\s*'([^\\']*(?:\\['\\][^\\']*)*)'/gc or
   /\G\s*([^\s'"]\S*)/gc;

is there actually an advantage to doing this?

-Original Message-
From: Randal L. Schwartz [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 06, 2001 10:43 AM
To: Ondrej Par
Cc: Peter Cornelius; [EMAIL PROTECTED]
Subject: Re: splitting strings with quoted white space


> "Ondrej" == Ondrej Par <[EMAIL PROTECTED]> writes:

Ondrej> On Wednesday 06 June 2001 18:19, Randal L. Schwartz wrote:
>> That's a good approach, but maybe this one is more straightforward:
>>
>> $_ = q{whatever "this" 'line is'};
>>
>> my @elements;
>> push @elements, $1 while
>> /\G\s*"(.*?)"/gc or
>> /\G\s*'(.*?)'/gc or
>> /\G\s*(\S+)/gc;
>>
>> print map "<<$_>>", @elements;
>>
>> The use of scalar /\G./gc to inchworm along a string is a powerful
>> technique.

Ondrej> Yes, this is better. With one exception - you're not handling \' and
\" (but
Ondrej> this can be copied from previous example).

my @elements;
push @elements, $1 while
  /\G\s*"((?:[^\\"]|\\"|)*)"/gc or
  /\G\s*'((?:[^\\']|\\'|)*)'/gc or
  /\G\s*([^\s'"]\S*)/gc;

Leaving undefined something like \X as malformed. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!




RE: system

2001-06-07 Thread Cheek, Bob

Since the problem is in your C program during the run of Perl, did you check
your C program for how it opens the file?  The C program probably is not
specifying the full path to the file it is trying to open.  


 -Original Message-
From:   prachi shroff [mailto:[EMAIL PROTECTED]] 
Sent:   Thursday, June 07, 2001 9:16 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject:Re: system

Its the exe which cannot open another fileand I have to use system 
and not exec, coz I need to get back to the script after executing the exe.
So, the problem is, the exe has no problems opening the other file if run on

the command prompt or by any other straight means, but if run within the 
perl script it shows errors. Also, I have run other exe from the same script

and they work fine.

Thanks,
Prachi


Original Message Follows
From: Jean-Matthieu Guerin <[EMAIL PROTECTED]>
To: prachi shroff <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: Re: system
Date: Thu, 07 Jun 2001 15:05:40 +0200

Hello,

Is your perl script that can't open exe file or your exe that can't open
another file ?

- if perl can't open exe file:
check that exe's path is defined on your PATH environment variable
or
if perl srcipt and exe are in same directory, check line
SYSTEM("./myexe.exe")
the ./ stands for current directory.
or
try another way than SYSTEM : exec, ` `, ...

prachi shroff wrote:
 >
 > Hi,
 >
 > I am trying to run an executable file from within my perl script using 
the
 > SYSTEM command. If I run the exe from either the command line or by 
double
 > clicking, it works fine, but when I embed it into the perl script it 
gives
 > errors compiling. It is an exe of a C code and shows errors specific to 
the
 > code like "error opening a file" that it needs to read.
 >
 > Could anyone please give in any suggestions.
 >
 > Thanks,
 > Prachi

--

  Jean-Matthieu Guerin
Brime Ingenierie
 [EMAIL PROTECTED]


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



RE: splitting strings with quoted white space

2001-06-07 Thread Accountant Bob

can any one explain to me why this doesn't seem to work:
  push @elements, $2 while
/\G\s*(["'])([^\\\1]*(?:\\.[^\\\1]*)*)\1/gc or
/\G(\s*)(\S+)/gc;   # k i know that's kinda kloogy, but I'm
experimenting.

-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 07, 2001 8:38 AM
To: Ondrej Par
Cc: Accountant Bob; "Randal L. Schwartz" <[EMAIL PROTECTED]> Peter
Cornelius; [EMAIL PROTECTED]
Subject: Re: splitting strings with quoted white space


On Jun 7, Ondrej Par said:

>On Wednesday 06 June 2001 22:59, Jeff 'japhy' Pinyan wrote:
>> On Jun 6, Accountant Bob said:
>> >How about this: (the same but "unrolled")
>> >
>> >my @elements;
>> >push @elements, $1 while
>> >   /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
>
>I think that
>   /\G\s*"((?:(?:\\.)|[^\\])*?)"/gc
>
>is shorter and also matches all \X sequences (the trick is that \\. is
longer
>than [^\\]

The formula for unrolling the loop is

  NORMAL* (SPECIAL NORMAL*)*

Here, NORMAL is /[^\\"]/, and SPECIAL is /\\./ -- at least, I'm using \\.,
since I want any backslash to pass through ok.

Thus, our regex is:

  push @elements, $1 while
/\G\s*"([^\\"]*(?:\\.[^\\"]*)*)"/gc or
/\G\s*'([^\\']*(?:\\.[^\\']*)*)'/gc or
/\G\s*(\S+)/gc;

Of course, that last regex can changed to your whims...

--
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  **




counting regex matches

2001-06-14 Thread Bob Mangold

Is there a simple way to know how many times a regex matches.
Say for example:

$string =~ /a/g; # match on all 'a' in $string

Now how do I know how many times it actually matched?

-Bob

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



readline

2001-06-15 Thread Bob Mangold

I'm having trouble reading STDIN.

This works:

$a = readline STDIN;
print $a; # prints out whatever was inputed

But the does not work:

use strict;
$a = readline ; # forced to use 
print $a; # prints nothing

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



variable losing it's value

2001-06-19 Thread Bob Mangold

I may have a bug somewhere in my code, but I can't find it. Before I look again
though please answer this for me.

If I execute:


my ($line) = "hello";
foreach $line (<>){
 . whatever
}
print $line;


Should it print the last line in <> or 'hello'? 

-Bob

__
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/



Re: variable losing it's value

2001-06-19 Thread Bob Mangold

Thanks, that's what I thought was happening, but now I have another question.
If I 'use strict' (and who doesn't), I am forced to declare $line before the
foreach loop, except I can't just type 'foreach my($line) (<>)'. I have to type
it on a preceeding line. If this is the case then why does perl localize it
anyway. If i'm declaring it before that loop shouldn't its scope carry through
the loop?

-Bob



--- Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote:
> On Jun 19, Bob Mangold said:
> 
> >I may have a bug somewhere in my code, but I can't find it. Before I
> >look again though please answer this for me.
> 
> >my ($line) = "hello";
> >foreach $line (<>){
> > . whatever
> >}
> >print $line;
> >
> >Should it print the last line in <> or 'hello'? 
> 
> I don't think the other responders tested their code.  If they had, they'd
> see that $line would retain its value.
> 
>   my $line = 1;
>   for $line (1 .. 10) { ; }
>   print $line;  # 1
> 
> This is because the looping variable is implicitly localized to the loop
> itself.  This is not a bug.
> 
> -- 
> 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  **
> 


__
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/



Fwd: Re: variable losing it's value

2001-06-19 Thread Bob Mangold

--- Bob Mangold <[EMAIL PROTECTED]> wrote:
> Date: Tue, 19 Jun 2001 19:40:51 -0700 (PDT)
> From: Bob Mangold <[EMAIL PROTECTED]>
> Reply-to: [EMAIL PROTECTED]
> Subject: Re: variable losing it's value
> To: Michael Fowler <[EMAIL PROTECTED]>
> 
> But this still leaves the question of why the scope of $foo on the first line
> doesn't carry through to the foreach loop. Assuming that $foo was declared
> global, it's value is essentially unaffected by the foreach loop, even though
> without it the foreach loop wouldn't work (using strict).
> 
> I guess I just don't see why this one example is an exception to the entire
> concept of scope. In any other case the scope of a localized variable
> includes
> it's own blcok and any sub-block within that, but not in this case.
> 
> -Bob
> 
> > However, regardless of whether or the iterator has always been localized,
> > the foreach syntax -has- made it easier to localize a variable.  Consider:
> > 
> > use strict;
> > 
> > my $foo;
> > foreach $foo (...) { ... }
> 
> 
> 
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
> 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



loop counting

2001-06-29 Thread Bob Mangold

Is there a perl variable that automatically counts loop iterations. Such that I
don't have to use '$count':

foreach (@array){
  $count++;
  ..whatever..
}

?????

Thanks,
Bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: loop counting

2001-06-29 Thread Bob Mangold

Paul,

Within the loop, some other programs are executed and occasionally it may take
a few minutes to complete everything and then continue. So I'm just throwing a
little counter to STDOUT so I can monitor the progress, to ensure it doesn't
get hung up somewhere.

I knew of all the different ways to do it, but since my programs tend to deal a
lot with arrays and looping through them I run into this issue (of how to count
through them) all the time. I was just curious if there was another way.

It seems to me that since Perl has the ability to know things like where a
search left off, or what the last matched item was, or what line of a file it's
reading, that it might be keeping track of this too.

-Bob

--- Paul <[EMAIL PROTECTED]> wrote:
> 
> --- Bob Mangold <[EMAIL PROTECTED]> wrote:
> > Is there a perl variable that automatically counts loop iterations.
> > Such that I don't have to use '$count':
> > 
> > foreach (@array){
> >   $count++;
> >   ..whatever..
> > }
> 
> Lot's of people with suggestions, but I have a question --
> what are you using $count for? Why do you need it?
> 
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



using the backspace \b character

2001-07-02 Thread Bob Mangold

Hello,

I know I can use the backspace character to overwrite previous characters and
the such, but can I use it to backup a few lines. Lets say I write:

print "hello\n";
print "world";

I know that:

print "\b";
print "a";

will replace the 'd' in 'world' with an 'a', but is there away to backspace
over both lines. I guess what I really need to do is backspace over an '\n'. Is
that possible?

-Bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



referncing hashes of array references

2001-07-05 Thread Bob Mangold

if I have a hash that contains array refs as its values and I create a
reference for it, what are the different ways that i can access the information
in the array?

for example.

my %hash;
my @array = ('red','white','blue');
$hash{'foo'} = \@array;
my $hashREF = \%hash;
print ${${$hashREF}{'foo'}}[1];

now I know that will print "white". but is there another syntax that will get
me the same result and is a little easier to read?

-bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



perl / php question

2001-07-09 Thread Bob Mangold

Hello,

I'm not sure if anyone here can help me with this, but at least some direction
in where to to look would be great.

I'm using a php script so call (via exec) a perl script. The STDOUT from perl
is automatically forwarded through the php script and displayed on the web
page. My problem however is that if the perl script errors and sends output to
STDERR there is no way for me to know that. Everything functions fine on the
php side regardless of what perl does.

So what i want to know is if there is a way to tell perl to send everything
that would normally go to STDERR to STDOUT? (I can't just change the filehandle
because the code is buried somewhere down in a module)

-Bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



STDIN and STDOUT

2001-07-10 Thread Bob Mangold

Hello,

I sent an email yesterday, but never heard anything. Maybe it was the word
'php' in the subject, but let me just simplify and ask another way.

Is there a way to automatically direct all STDERR output to STDOUT. A module I
have installed automatically creates STDERR output, but I want that output to
go to the filehandle STDOUT.

-Bob


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: STDIN and STDOUT

2001-07-10 Thread Bob Mangold

> Does anybody know why he shouldn't do the following?
> 
> *STDERR = *STDOUT;
> 

This is what I orignally tried, and is didn't really work. I think my problem
lies in the fact that I am hoping to make the change in a module that I am
'use'ing. So I tried all of the suggestions, but it seemed that no matter how I
did it, the output always went to STDERR. So I guess somewhere in the module
it's checking to make sure STDERR really is STDERR.

In any case I made a work around by just spitting the STDERR output to a file
and checking for it there. (which in itself is weird because i can push STDERR
to a file, but not to STDOUT.)

-Bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Help: Searching an array question++

2001-07-10 Thread Bob Bondi

Yep, another newbie at Perl. I have come to a wall. What I need to do is
open a file, find a value in the file and substitute a value.
I've gotten to the point of what to do with an open file. I have been trying
the @array =  statement.
I then wanted to verify the contents of the array and tried printing it,
print("$array\n");

But there is no output is unexpected! 0: is the output.

Also, the substitute thingie is, well, odd. Say, I define $sFind="this.gif",
and $sSwap="that.gif".
And say I have an array with each line of a file tucked away in it. What the
heck is the syntax for it

#\perl\bin 
open(TESTFILE, ">>/Inetpub/wwwroot/date.htm") || die "Can't open
/Inetpub/wwwroot/date.htm: $!";
@array = ;
print ("$array\n");
$sFindGIF = "this.gif"; 
$sSwapGIF = "that.gif";
for ($index = 0; $index<=$#index; $index++) {
  if ($array[$index] =~ /sFindGIF/) {
last;
  }
}
print ("$index: $_\n");
$s = $array[$index];
$s =~ s/this.gif/that.gif/; 
close (TESTFILE);

Please, any pointers, thanks.




Re: STDIN and STDOUT

2001-07-10 Thread Bob Mangold

> Are you sure it's STDERR? Some write directly to ther terminal
> screen...
>  

I checked through the module code and it definitely says 'print STDERR ...'.

> What is this module?

The module is 'bioperl' (used for genetic analysis).

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



(solution) Re: STDIN and STDOUT

2001-07-10 Thread Bob Mangold

As mentioned eariler...

--- Craig Moynes/Markham/IBM <[EMAIL PROTECTED]> wrote:
You mentioned in the earlier email that you were calling your perl script
via 'exec' (as I remember).
Could you not use something like
exec(' myperl.pl 2>&1 ' ) ?


ok, this works, but what the heck is it doing. i've never seen that syntax.

-bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



multiprocessors and perl

2001-07-10 Thread Bob Mangold

I'm about to upgrade to a dual processor sunblade 1000 at work (absolute
overkill), but before doing so I'm trying to figure out what I'm going to have
to do to exploit both processors.

- Do I need to install perl with any special options?
- Will I need to start writing my scripts differently to take advantage of both
processors?
- Is there anything at all I should know about perl's behaviour in this type of
environment that might be helpful?

Thanks,
Bob

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



FOLLOWUP Question: RE: Help: Searching an array question++

2001-07-11 Thread Bob Bondi

Thanks for the feedback, everyone.
My goal for this script is to make "this.gif" and "that.gif" change places
in the file. I.E.
-
this.gif
that.gif
this.gif
-

after running the script I would have
-
that.gif
this.gif
that.gif
-

using code like:
s/$sThis/$sThat/;
s/$sThat/$sThis/;

is there a method to do this?

I am running into a situation that I end up with just this.gif.
I guess what would be nice is:
s/(value1,value2)/(newValue1,newValue2)/
where value1 becomes NewValue1 OR value2 becomes newValue2






I need to "touch" a binary file

2001-07-11 Thread Bob Bondi

So, simple on Unix/Linux! Are there any solutions via Perl to "touch" a
binary file?



Can Perl 'see' HTML IfModifiedSince calls?

2001-07-12 Thread Bob Bondi

I need to know if my browsers are sending IMS calls to the web server to
fetch html, images, etc. Is Perl able to watch the data returned to the
browser and tell me if IMS calls occurred?



unsubcribe

2001-07-13 Thread Bob Tripp


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


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




Help: Starting a script with command line arguments

2001-07-19 Thread Bob Bondi

My question is: how can I pass arguments to a script from the command line?
The script at the tail of this message is what I thought would print the 2
arguments I passed into the script, yet the output for this snippet is:
Here ya go:
Here ya go:
Count is: 0
Not enough arguments to get started

#\perl\bin

use strict; # use strict! It will save you many headaches
use File::Basename;
use Carp;

my $count = @_;
print "Here ya go: $_[0]\n";
print "Here ya go: $_[1]\n";
print "Count is: $count\n";
carp "Not enough arguments to get started" unless $count > 0;



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


RE: Out of memory on sort !!!!

2001-07-19 Thread Bob Showalter

> @sorted = sort { $data[$a] [0] <=> $data[$b] [0] } @data;

In the sort block, $a and $b are *elements* of @data, not *subscripts*. Your
sort block should be more like

   { $a->[0] <=> $b->[0] }

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




RE: regex question with s///

2001-07-19 Thread Bob Showalter

Bradford Ritchie wrote:
> Is it possible to take a string ($pat) do a substitution on 
> it and print the result, without actually changing the 
> contents of the original variable?

No; you have to do the subsitution on a copy.

> 
> Basically, I'm trying to write a script that will take a 
> string and look for a pattern in that line (which is 
> guaranteed to be a number), increment it and print the new 
> line, then increment it again an print it, etc., up to a 
> specified number of times.
> 
> Here's the start of some code I have:
> (I realize there's no error checking but right now I'm just 
> focusing on the basic logic).
> 
> use strict;
> my $pat = $ARGV[0];
> my $num = $ARGV[1];
> 
> foreach(  ) {
>   print;  ## print the original line
>   foreach my $i ($pat .. ($pat+$num)) {
> s/$i/$i+1/e;
> print;
>   }
> }
> 
> A sample input line would look like this:
> 
> 
> And if called like this "%script.pl 18 5" I should expect to 
> seid="31.101.20.0">   id="31.101.22.0">  

The code you posted produces this result when I run it.

> 
> I'm running into several problems with this.  It doesn't work 
> because each substitution changes the original line.  If I 
> had specified 15 instead of 5 as the second parameter, the 
> s/// would start matching the first 31 in the input line when 
> $i eventually became 31.
> 
> Ultimately, I want to be able to specify a bit of sample text 
> like '.18.' which is more unique than simply '18'.  Then have 
> the script search for the more unique pattern but still be 
> able to increment the number within it. (ie.  '.19.' '.20.' 
> '.21' ...) Note, that these would be literal dots, not regex 
> wildcards.

Not sure exactly what you want to do. Do you just want to increment the
third number, whatever it is? Maybe you want something more like:

   for my $i (1..$num) {
  s/(\d+\.\d+\.)(\d+)/$1 . ($2+1)/e;
  print;
   }

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




RE: Re: Module question

2001-07-19 Thread Bob Showalter

[EMAIL PROTECTED] wrote:
> Like I said I was frustrated.  I'm using the Deitel and 
> Deitel book.  But it is probably not it's fault.  I'm just confused.

Don't know the book. I Suggest the O'Reilly books.

> I thought I understood I needed to define how I should use 
> the module so it would use it.  But from what you just said I 
> guess not.  Please provide assistance or a example.
> 
> Thanks..

Look at the documentation for Date::Calc. It has a section call "RECIPES",
and recipe #11 is very close to what you are wanting. Start with that code
and make sure it works. Then start changing it to match what you want.

perldoc Date::Calc

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




Snippet to list both directories and files to an array or...?

2001-07-20 Thread Bob Bondi

I've been trying to use opendir($tempdir,@ARGV[0]) or die "Couldn't open the
directory, $!";

Can't use string ("tempdir") as a symbol ref while "strict refs" in use at
run
test4.pl line 58.


So, is there a snippet, please, that will do this?



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


RE: parsing a session id out of LWP::

2001-07-23 Thread Bob Showalter

> -Original Message-
> From: Mark Maunder [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, July 23, 2001 2:09 PM
> To: Kevin Harwood; Beginners@Perl. Org
> Subject: RE: parsing a session id out of LWP::
> 
> 
> The URL is what you're requesting. Unless you receive a 
> redirect with LWP::UserAgent, you must know what you're 
> requesting. Either its the first page you hit on the site, or 
> you've grabbed the URL from an HREF in a requested document. 
> To avoid transparent redirects, subclass LWP::UserAgent and 
> override $ua->redirect_ok so that it returns false.

I think he needs to allow the redirect to occur and then grab the 'base'
value of the HTTP::Response returned by LWP:UserAgent. Wouldn't that allow
him to grab the session ID added by the server?

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




Can PERL do a DIRECT GET?

2001-07-23 Thread Bob Bondi

In fact what is a DIRECT GET compared to a GET? But, I need to do a DIRECT
GET, for testing IMS stuff in headers.



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


RE: Deleting the contents of file:Help

2001-07-24 Thread Bob Showalter

> -Original Message-
> From: Rahul Garg [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 4:44 AM
> To: [EMAIL PROTECTED]
> Subject: Deleting the contents of file:Help
> 
> I want to search for a specific mailid in a file and if found 
> then delete that mailid from that file.

Do you want to delete lines containing the mailid? Or just delete the text
of the mailid?

This will delete lines (like grep -v):

   perl -ne 'print unless /blahblah/' infile >outfile

This will strip all occurences of the text, but leave the line:

   perl -pe 's/blahblah//g' infile >outfile

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




RE: feasibility check allowed?

2001-07-24 Thread Bob Showalter



> -Original Message-
> From: Giridhar nandikotkur [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 12:04 PM
> To: Perl Gurus
> Subject: feasibility check allowed?
> 
> 
> Hi anyone
> 
> I had a question about feasibility. I am not sure if
> such questions are allowed but any answer will be
> greatly appreciated.
> 
> problem.
> Some archival data is to be retrieved from a
> partly-perl based (rest HT??) website passing through
> a set of 5-6 screens clicking 3-4  options on each
> screen.
> after the selection is done a tar file is stored at an
> ftp site whose name is mentioned in the final screen.

I assume you are talking about making a "robot" to harvest data from this
site via HTTP requests.

> 
> Question
> 1. Is this feasible?

Yes.

> 2. If so, what perl/CGI modules should I be looking
> at?

LWP::UserAgent and related modules for HTTP client stuff
Archive::Tar (?) for writing the tar file (I haven't used this module)

> 3. would things change if one of the screens is java
> based?

Yes, AFAIK, perl can't manipulate Java applets. You may have to write the
robot in Java; I really don't know. Even then, you may not be able to scrape
output written by an applet.

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




RE: passing a value to Perl

2001-07-24 Thread Bob Showalter

> -Original Message-
> From: Ackim Chisha [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 1:38 PM
> To: [EMAIL PROTECTED]
> Subject: passing a value to Perl
> 
> 
> Hi everybody,
> 
> is there a better way to pass a value from a shell script 
> rather than write to a file and have perl read the file.
> 
> In a shell script I can read the value as $1, how do I read 
> it in perl. In C++ i can read the value using  argv[1] , how 
> can I read this same value in perl, instead of having to have 
> shell script pass it to perl in form of a file.

Command-line arguments are in @ARGV. You can iterate over @ARGV or use shift
to grab one argument at a time (just like the shell).

   perldoc perlrun
   perldoc perlvar
   perldoc -f shift

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




RE: Cleanest way to split this

2001-07-24 Thread Bob Showalter

> -Original Message-
> From: Filip Sneppe (Yucom) [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 1:42 PM
> To: [EMAIL PROTECTED]
> Subject: Cleanest way to split this
> 
> 
> Hi,
> 
> I have input lines that look like this:
> 
>   username,[EMAIL PROTECTED],age,streetname number zip-code 
> city,www.website.com/user/default.html
> 
> and that need to be split into $username, $email, etc.
> 
> Easy to do, but some of the records look like this:
> 
>   username,[EMAIL PROTECTED],18,"streetname 54B, 1000 
> Brussels",www.site.com
>   "Doe, John",[EMAIL PROTECTED],40,"blah blah,,, ,stuff",www.site2.org
> 
> What would be the easiest way to take into account the quotes 
> when splitting ?

This is a FAQ. See:

   perldoc -q delimited

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




No "make", "nmake", or "dmake" in build 628 of ActivePerl for Win32?

2001-07-24 Thread Bob Abugov

Hi, I'm trying to build modules on a Win2K system using the Perl make command. What do 
I need to do? When I try to use it after building a Makefile, Perl can't seem to find 
here's what I get:

>perl Makefile.PL

Checking for URI ...

Checking if your kit is complete ...
Looks good

Writing Makefile ...

>dmake
dmake is not recognized as an internal or external ...

>perl -V:make
make='nmake';

>nmake

'nmake' is not recognized as an internal or external ...


>make
'make' is not recognized as an ...



__
Your favorite stores, helpful shopping tools and great gift ideas. Experience the 
convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


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




RE: Problem with scan fields using split

2001-07-24 Thread Bob Showalter



> -Original Message-
> From: Marvin Bonilla [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 1:54 PM
> To: [EMAIL PROTECTED]
> Subject: Problem with scan fields using split
> 
> 
> Hello
> 
> Certainly I have already new in program with perl , so I need 
> help with a log scan program, that extract a field 
> information from a log file and get some fileds in order to 
> use in another program. the log fields looks like this:
> 
> Jul 24 11:37:59.878 [13001] (v3.1.2) POP login by user 
> "conhosvp" at (m32.ibw.com.ni) 216.226.201.71 Jul 24 
> 11:37:59.932 [13002] (v3.1.2) POP login by user "icade" at 
> (mdig76.ibw.com.ni) 64.110.119.80
> 
> If you see the digits 24 are the second field using split(/ 
> /,$s) where the white space is the separator, the problems 
> begin when the digit is just one, thats mean from 1 to 9, the 
> field become third because the split take a white space as 
> the second field, that situation results in that i need to 
> change the program every time the date change from 1 to 2 
> digits to read correctly the fields.
> 
> Is there a solutions to avoid this situation with the split 
> function?? Thank you for your help.

Use split(' ', $s) or split(/\s+/, $s) instead of split(/ /, $s).

Using / / as your delimiter pattern means to treat each blank as a
delimiter. So "Jul  1" is treated as "Jul", "", "1". The /\s+/ pattern
treats any sequence of one or more whitespace chars as the delimiter (you
could also use / +/ to just use spaces and not other whitespace chars). Per
the documentation, a delimiter of a single space as a string (not a regex)
is the same as delimiting on sequences of whitespace.

   perldoc -f split

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




RE: reading a text file

2001-07-24 Thread Bob Showalter

> -Original Message-
> From: Debbie Christensen [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 3:03 PM
> To: [EMAIL PROTECTED]
> Subject: reading a text file
> 
> 
> I am brand new to perl; I am only on chapt 4 of the learning 
> perl book.  My boss has already given me a project to do that 
> I am really struggling with. I know you are all really busy, 
> but I would really appreciate any help you can give.
> 
> I have a text file that looks something like this
> 
> OH:  702
> PA: 702
> ND: 702
> NJ :703
> NY: 703
> Ca: 703
>
> ...
>
> I am able to open the file and read it with no problem.  
> Where I get lost is My boss wants the data to come out like 
> 702 OH, PA, ND
> 703 NJ, NY, CA

Hey, this is a really common type of thing and perl excels at this. The
trick is to use a hash to group the states together by the keys. A question
is whether a given state, number pair can occur more than once on the input
and whether you would want to show it only once on the output. Also, it
appears that you want the states to be listed on the output in the order
they appeared in the input (as opposed to being sorted alphabetically, for
example).

Here's a solution that will produce the output you showed:

   #/usr/bin/perl -w

   use strict;

   my %d;  # hash to accumulate data in

   while(<>)   # read line from file(s) specified on cmd line, or
STDIN
   {
  chomp;   # strip line terminator from $_
  my ($state, $key) = split /\s*:\s*/;   # extract state and number
  push @{$d{key}}, $state;   # add to list of state for this
num
   }

   # print the output data
   print "$_ ", join(', ', @{$d{$_}}), "\n" for sort { $a <=> $b } keys %d;

Some of those lines need explanation:

   my ($state, $key) = split /\s*:\s*/;

This is an assignment statement setting a list of variables from a list of
values on the right-hand side. The split function takes an input string
(here it is implied as the $_ variable) and splits it into a list of
multiple values based on a delimiter pattern (regular expression). I am
using a delimiter consisting of zero or more whitespace chars, followed by a
colon, followed by zero or more whitespace chars. So, if the line we just
read in was:

   OH:  702

Then $_ would contain "OH:  702\n" before the chomp; and "OH:  702" after
the chomp. The split function would see the ":  " sequence as matching the
delimiter and split the string into two values, "OH" and "702". The first
value would be assinged to $state and the second to $key.

   push @{$d{$key}}, $state;

This is a call to the push() function, which takes two arguments: an array,
and a single (scalar) value. The value is added to the end of the array.
What is the array? The array is an anonymous (unnamed) array which is
referenced by the value of $d{$key}, which is a hash entry of the hash %d.
So this statement means: "Add the value of $state to the end of the array
pointed to by the hash entry $d{$key}"

Note that if the hash entry $d{$key} doesn't exist, it is automatically
created and initialized to point to an empty array when this statement is
executed, which makes our life simpler. So after executing this statement
with the above values, the hash %d would contain one entry with a key value
of "702". This entry would point to an anonymous array containing one entry,
the value "OH".

   print "$_ ", join(', ', @{$d{$_}}), "\n" for sort { $a <=> $b } keys %d;

This one statement prints the entire output table. What you have is a
statement of the form:

   print  for .

The "for" is a statement modifier that basically causes the "print"
statement to execute multiple times. Following the "for" keyword is a list
of values. The print statement will be executed once for each value in the
list, and during each execution, the $_ variable will be set to the
particular value in the list being processed.

What is the list of values after the "for"? It is the list produced by the
expression

   sort { $a <=> $b } keys %d;

This is taking the result of the expression "keys %d", which is the list of
key values from the %d hash (e.g. the numbers 703, 702, etc.) and feeding
them to the sort function. The sort function is using the expression $a <=>
$b to compare the keys. This will have the effect of sorting the keys as
numbers, instead of the default strings. (This will make "1001" come after
"702" instead of before).

So the "for" modifier will execute the print statement, setting $_ to the
numbers in your list successively. For the input data you gave, the print
statement will execute twice, first for 702, then for 703.

So the print statement prints each line. What does it print?

   print "$_ ", join(', ', @{$d{$_}}), "\n"

There are three values printed: $_, which is the number (e.g. 702). Next
comes a join() function call, then comes a "\n" (newline) to mark the end of
the line. The join() function is the opposite of split(): it takes a list of
values (in this case th

RE: basename ?

2001-07-24 Thread Bob Showalter

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 24, 2001 5:33 PM
> To: [EMAIL PROTECTED]
> Subject: RE: basename ?
> 
> 
> Why add another module when one regexp can do it? ;)

The module does allow you to deal with non-Unix systems where the filename
separator is other than "/", if portability is a concern.

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




RE: Running Perl scripts...

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 1:46 AM
> To: [EMAIL PROTECTED]
> Subject: Running Perl scripts...
> 
> 
> List,
> 
> I want to be able to check for errors on my Linux box before 
> I run them in a browser.  The problem is is tha when I do 
> this all my HTML is dispalyed.  I don't want to see this I 
> want to be able to just check for any errors and display the 
> errors only.

If the errors go to STDERR, just throw away STDOUT:

   $ perl myscript.pl >/dev/null

Or am I missing something?

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




RE: stat() keeps returningthe incorrect date

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: Shepard, Gregory R [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 10:56 AM
> To: '[EMAIL PROTECTED]'
> Subject: stat() keeps returningthe incorrect date
> 
> 
> I am trying to create a script which gathers the stat info of 
> every file in a given directory. Then return the date it was 
> last modified for the purpose of picking the file that was 
> created/modiefied last. The script is reading the files ok, 
> however, when placing them in the stat() to exctact the info, 
> it only reads the . and .. files correctly, while returning 
> the same date for all of the text files. The incorrect date I 
> get for them is: Last modified at:Wed Dec 31 18:00:00 1968

No, . and .. aren't really working correctly. See below.

> 
>   @ARGV=$dir;
>   $directory=shift || '.';
>   opendir DIR, $directory || die "Can't open directory 
> $directory: $!\n";
>   
>   while ($file=readdir DIR) 
>   {
>   #print "$file\n";
>   @filespecs=stat("$file");

The problem is here. You need to check the return of stat(). $file is the
filename relative to the directory in $directory. But you are trying to
stat() it relative to the current working directory, whatever that is.
stat() is returning an empty list, since the file doesn't exist.

>   $last_modification_time = localtime($filespecs[9]);

$filespecs[9] is undef, which is treated as a time value of 0, which is
giving you the 1969 date.

>   print "Last modified at:$last_modification_time\n";
>   #print "$mytime\n";
>   }
> 
> How do I get it to read the date it was last created/modified?

Solution is to append the file name to the directory to get a full path
before calling stat().

Using -w in your script would have given you a warning that you were using
an undefined value on the localtime call.

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




Getting values from a file

2001-07-25 Thread Bob Bondi

I'm planning on starting my perl script with a commandline argument, a
filename. I open the file and parse through it line by line, OK, but I'm
getting a blank on how to grab the value out of the file for a variable in
the script. The file will read like:
-TestClass = 3
-TestCase = all
-Proxy_IP = 255.255.255.255
-Proxy_Port = 8080
-Url = 101.101.101.10:80/test.html

I'll have variable for each item above and I just want to fill-in the
values.

Is there a way to pull out those values and assign them properly?



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


RE: First Script Question

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: David Freeman [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 2:29 PM
> To: [EMAIL PROTECTED]
> Subject: First Script Question
> 
> 
> 
> Hi all, i've been receiving the list mail for a few days and 
> read through 
> what people seem to need to look at to help others with 
> script problems. I 
> included what little bit of code i have for my project below. 
> Basically i've been going through the Perl by Example book 
> and pulling 
> relevant bits out to piece this together.  I want to 
> eventually turn this 
> into a web script, but not yet.
> 
> I want this script to be able to open the /etc/mail/access file, read 
> through it and sort the hopefully 2 columns into seperate arrays. the 
> e-mail/domain names to be blocking in the first array and the REJECT, 
> RELAY, 500 Message in the second array.  It asks for user 
> input of "which 
> doamin to look for" in the list already and runs through to 
> see if it has a 
> match.  At the moment when i put in a name i know is in there 
> it comes back 
> with the REJECT, which is out of array 2.  The list is 
> seperated by tabs, 
> and (honestly) i don't know what to put in the delimeter 
> field to make it 
> look for a tab to seperate.
> 
> The harder question i have is the second half of the script.  Once it 
> determines that no match was found, i want to have it 
> appended to the end 
> of array 1, ask for another user input for "How should we 
> treat this email 
> / domain name?" in which user fills in REJECT, RELAY, etc. 
> and then close 
> the access file with changes made.
> 
> and that's sort of where i'm reading as much as i can and code stops.
> 
> Thanks for any advise!
> 
> 
> #!/usr/bin/perl -w
> #Script to add spam to /etc/mail/access file
> #And create and hash of it then restart sendmail
> 
> open(NAMES,"/etc/mail/access") || die "Can't open access: 
> $!\n"; while (){
>  ( $email, $action )= split('', $_);

If the fields are separated by a single tab char, use /\t/ as the first
argument to split. Using a null string will split into individual
characters. Also, naming $_ in your split() call is unnecessary, as $_ is
the default. This is documented in:

   perldoc -f split

>  $newarray{$email} = $action;

Your description above keeps saying "array", but you realize that newarray
here is a hash, not an array, right?

> }
> close NAMES;
> 
> while(1){
>  print "Look for what domain in spam filter? ";
>  chomp($email=);
>  last unless $email;
>  print $newarray{$email},"\n";

If you want to test whether an entry for $email exists in %newarray, use the
exists() function:

   perldoc -f exists

> }
> 
> if  <> $email
> open(APPEND, ">>/etc/mail/access1") || die "can't open 
> access1 $!\n"; APPEND= print APPEND "  \n";

I have no idea what this code is supposed to be doing.

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




RE: clearing memory

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 3:07 PM
> To: Beginners (E-mail)
> Subject: clearing memory
> 
> 
> Folks,
> 
> I am drawing a blank here.. I am onsite at a customers 
> location with not perl books and perldoc is not installed :(
> 
> what is the quickest, cleanest , efficient way to clear out 
> memory used by an array and other variables in a script?
> 
> We have a script that is continuously run and sleeps every 30 
> seconds b4 grabbing data and populating arrays. Is it 
> possible to make a clean() that will wipe the slate clean at 
> the end or beginning of the next run?

Well, you can just clear out variables individually with undef and let perl
do its garbage collection:

   undef @myarray;
   undef %myhasn;
   undef $myscalar;

For a truly fresh start, maybe have the script exec() itself?


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




RE: Cooperating with WINSOCK using Socket::

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: Dan Grossman [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 3:51 PM
> To: [EMAIL PROTECTED]
> Subject: Cooperating with WINSOCK using Socket::
> 
> 
> Hello,
> 
> I'm hoping someone can help me with an INET Socket question.  
> I have the following socket setup and subroutine to receive 
> data from a
> Server:
> 
> # connection protocol
> if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
> die "No port" unless $port;
> $iaddr = inet_aton($remote)   or die "no host: $remote";
> my $paddr = sockaddr_in($port, $iaddr);
> 
> $proto = getprotobyname('tcp');
> socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
> connect(SOCK, $paddr)  or die "connect: $!";
> 

I suggest you use IO::Socket instead of all this jazz. It handles all this
setup stuff for you in one call.

> # Client subroutine
> sub receiveServerResponse() {
> my $line = "";
> while ($line = ) {
> if ($line) {
> print "\tReceived: $line";
> return $line;
> }
> }
> }
> 
> The protocol I am following insists on having a LF at the end 
> of all messages, but some (Windows-based) servers with whom I 
> am attempting to cooperate are incorrectly sending messages 
> ending with CR.  How can I get 
> 
>   while ($line = )
> 
> to recognize a "line" ending with CR?

Well, the $/ variable determines what a "line" is (see perldoc perlvar). But
you can't use a regex.

So you may have to use read() instead and process 1 char at a time.

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




RE: Whole Script, global symbol?

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: David Freeman [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 25, 2001 4:36 PM
> To: [EMAIL PROTECTED]
> Subject: Whole Script, global symbol?
> 
> 
> 
> 
> I modified the script to reflect what was suggested to me
> earlier, and now 
> when i run it, i receive errors telling me i'm missing 
> something at line 11 
> regarding global symbols for my variables?
> 
> this is the whole script, nothing left out, if it's missing something
> declared i'm not familiar enough with perl to know what that 
> might be yet.
> 
> suggestions appreciated.
> 
> 
> 
> 
> #!/usr/bin/perl -w
> #Script to add e-mail address or domain name to
> /etc/mail/access file #if it was not already listed.
> 
> use strict;
> #use warnings;
> 
> 
> open(NAMES,"/etc/mail/access") || die "Can't open access:
> $!\n"; while (){
>  ( $email, $action )= split(/\t/);
>  $newarray{$email} = $action;
> }
> close NAMES;
> 
> if( exists $newarray{$email} ){
>  print $newarray{$email}, "\n";
> }else{
>  print "How you wanna handle this one? ";
>  my $action;
>  chomp( $action =  );
>  $newarray{$email} = $action;
> }
> ~
> 
> Global symbol "$email" requires explicit package name at
> spamadd02.pl line 11. Global symbol "$action" requires 
> explicit package name at spamadd02.pl line 11. Global symbol 
> "%newarray" requires explicit package name at spamadd02.pl 
> line 12.
> Execution of spamadd02.pl aborted due to compilation errors.

These errors are cause by "use strict;". "use strict" is a very good thing,
so don't take it out. What you need to do is declare your variables in some
way. See:

   perldoc strict
   perldoc vars
   perldoc my
   perldoc our (perl 5.6 only)

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




RE: perldoc

2001-07-25 Thread Bob Showalter

> -Original Message-
> From: David Freeman [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 5:03 PM
> To: [EMAIL PROTECTED]
> Subject: perldoc
> 
> 
> 
> ok so to have global symbols i need to declare them. i can understand 
> that.  in perldoc there in no my on this system it would 
> appear.  but i 
> read about it elsewhere.  But i could not find in either 
> place an example 
> of the types of declarations i would need to make for these variables.
> 
> use strict;
> 
> $email = $str?
> 
> would this be correct to do?

perldoc is installed into the same directory as your perl binary. It may not
be in your path, so you may need to add it or link to it. You won't get very
far if you don't use it, so find it and use it. Save yourself much head
banging.

You need to declare your variables, typically with "my".

   use strict;

   my $email;   # $email is a lexcially-scoped variable
# existing from here through the end of this file

   $email = "blah blah";

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




RE: Convert date mmddyy to day of the week

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 4:33 PM
> To: [EMAIL PROTECTED]
> Subject: Convert date mmddyy to day of the week
> 
> 
> I want to convert a date in the format mm/dd/yy to the day of 
> the week.  For example 07/25/01 should become Wednesday.

Look at the Date::Manip or Date::Calc modules.

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




RE: USPS has me stumped!

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: Luke Bakken [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 5:13 PM
> To: [EMAIL PROTECTED]
> Subject: USPS has me stumped!
> 
> 
> Hi all,
> 
> I'm tinkering with some of the libwww modules and trying to 
> get some information from the USPS web site.  Here's a simple 
> script to get a zip+4
> address:
> 
> use HTTP::Request::Common qw(POST);
> use LWP::UserAgent;
> 
> $ua = LWP::UserAgent->new;
> 
> my $req = POST 'http://www.usps.gov/cgi-bin/zip4/zip4inq2',
>  [ 'Submit' => 'Process',
>'Delivery Address' => '46 W 34TH AVE',
>'Zip Code' => 99203 ];
> 
> print $ua->request($req)->as_string;
> 
> Every time I run this I get a 500 error, yet when I do the 
> same thing with lynx from my machine, it works fine.
> 
> Is the web site able to discern who is sending requests to 
> keep people from mass-querying their database?  I have tried 
> adding a $ua->agent('Mozilla/5.0'); line to no avail.
> 
> I have also used the cg-eye live service at www.htmlhelp.org 
> to diagnose the problem, but I still get the same 500 error 
> there (but no error otherwise).
> 
> Any ideas?
> Thanks,
> Luke

I got it to work by: 1) adding all the form fields, and 2) putting them in
the same order as they appear on the form. Not really sure why either of
these was necessary. Didn't change agent identifier at all.

   my $req = POST 'http://www.usps.gov/cgi-bin/zip4/zip4inq2',
   [
  'Firm' => '',
  'Urbanization' => '',
  'Delivery Address' => '46 W 34TH AVE',
  'Zip Code' => '99203', 
  'City' => '',
  'State' => '',
  'Submit' => 'Process',
   ];

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




RE: clearing memory

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: Michael Fowler [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 5:26 PM
> To: Yacketta, Ronald
> Cc: Beginners (E-mail)
> Subject: Re: clearing memory
>
> ...
> The ideal solution would be to use 
> lexical variables that go out of scope before it starts 
> another iteration.

Yes, Michael that is the ideal solution. I was hung up on the OP's concern
over globals. But you can even do the same thing with globals by using the
"local" declaration:

   while (1)
   {
   do_stuff();
   sleep 30;
   }

   sub do_stuff
   {
   local ($var1, $var2);

   # load huge stuff into $var1, $var2, etc.
   # these are globals that can be seen in any sub called
   # from here (unlike "my")

   # when do_stuff ends, "local" copies of $var1 and $var2
   # are freed
   }

This is a technique I use every day in my Apache::Registry scripts.

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




RE: Reading binary files

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: Sambamoorthy Jayaraman [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 2:32 AM
> To: [EMAIL PROTECTED]
> Subject: Reading binary files
> 
> 
> Hi,
> 
> How do I read a binary file?? From this file, I need to read 
> 16 bit values. 
> I have attached a sample binary file alongwith. When you are 
> reading this 
> file, enable `hex edit mode'.

You need to use the unpack() function.

   perldoc -f unpack

Things to watch out for:

Some evil systems (Windows) have a "text" and "binary" file concept. On
Unix, this is not relevant. See

   perldoc -f binmode

To read fixed length records, see

   perldoc -f read
   perldoc -f sysopen
   perldoc -f sysread

If the file is created on a different architecture, byte ordering may be
different. So a two-byte integer written by an HP PA-RISC (big endian)
system would be interpred wrong when ready by an Intel-based (little endian)
system.

   perldoc perlport (search for "endian")

There are also some FAQ's related:

   perldoc -q binary

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




RE: array contents to a file

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: John Edwards [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 4:43 AM
> To: 'Ron Smith'; [EMAIL PROTECTED]
> Subject: RE: array contents to a file
> 
> ...
> foreach $element(@array) {
>   print FILE "$element\n";
> }

FWIW, this can be simplifed to:

   print FILE "$_\n" for @array;

Folks often forget about the statement modifiers (especially if coming from
a C background). But they are extremely common and contribute to concise,
readable code.

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




RE: isWindows95() and isWIndowsNT()

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: Barry Carroll [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 8:18 AM
> To: '[EMAIL PROTECTED]'
> Subject: isWindows95() and isWIndowsNT()
> 
> 
> Hi all,
> 
> This is my first post :)
> 
> I once saw functions such as the ones above for perl.
> 
> I am writing a script and I want to be able to determine
> the machine's Operating System type.
> 
> Does anyone know where i can get these functions or
> similar ones to determine the OS type.
> 
> I know how to get the OSType for a UNIX system, it's
> just windows that i'm having trouble with.

The functions are:

   Win32::IsWinNT()
   Win32::IsWin95()

They come with ActiveState perl.

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




RE: Tear me to shreds please...

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: Michael Carmody [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 2:30 AM
> To: [EMAIL PROTECTED]
> Subject: Tear me to shreds please...
> ...

Regarding this section of the code:

>  $c = ($data[4][$i] =~ s/\//\//g);
>  if ($c eq "")
>  {
>  print LDIF "sn: $data[4][$i]\n";
>  }
>  else
>  {
>  @array = split(/\//,$data[4][$i]);
>  $j = scalar(@array);
>  $j--;
>  for $d (0 .. $j)
>  {print LDIF ("sn:",$array[$d],"\n");}
>  }

It appears that what you are trying to do is print the parts of $data[4][$i]
as delimited by forward slashes on individual lines, with each line prefixed
by "sn: ". Is that correct? If so, this entire block of code can be replaced
with one line:

   print LDIF "sn: $_\n" for split /\//, $data[4][$i];

Try to get away from thinking in C terms. Perl absolutely excels at dealing
with managing lists of things and iterating over those lists in various
ways.

Some comments:

1. You are first trying to decide whether the string contains any slashes.
If not, you print the whole string. Otherwise, you split the string into
multiple parts. This is not necessary. The split function will handle a
string with no delimiters by simply returning a list consisting of one
element: the entire string. Also, you are using the operation 

   s/\//\//g 

to test whether the string has any slashes. This is incredibly inefficient,
as you are asking perl to replace a slash with a slash and the /g modifiers
forces perl to do so for every instance in the string. But you don't care
how many slashes are in the string, just whether there is one. The simpler
test would be 

   /\//(or m!/! which is possibly more readable)

But again, the whole test is unneeded.

2. You use 

   if ($c eq "") 

to test the return from the s/// operation. This makes me uncomfortable. You
really want to test whether $c does not have a value. I would use

   unless ($c)

3. You use the following code to iterate over @array:

   @array = split(/\//,$data[4][$i]);
   $j = scalar(@array);
   $j--;
   for $d (0 .. $j) { 
  print LDIF ("sn:",$array[$d],"\n"); 
   }

First, $j is unnecessary. If you want the last index in the array, use
$#array:

   for $d (0 .. $#array)

Second, don't use subscripting if you just want to iterate over the array.
Use perl's iteration capabilties:

   for (@array) {
  print LDIF ("sn: $_\n"); 
   }

Third, if the array body is a simple one-liner, use the for statement
modifier instead:

   print LDIF "sn: $_\n" for @array;

Finally, the intermediate array is unnecessary. Use the output of split
directly:

   print LDIF "sn: $_\n" for split /\//, $data[4][$i];

This eliminates several lines of code, is more readable, and uses no
additional variables.

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




RE: Login error w/FTP

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: Sparkle Williams [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 10:13 AM
> To: [EMAIL PROTECTED]
> Subject: Login error w/FTP
> 
> 
> Well, I have this script that I'm trying to write using the 
> FTP module, 
> however it keeps responding with an error message concerning 
> the login line 
> of the script whenever I try to run it. I have run out of 
> ideas and have 
> absolutely no clue as to what the problem is. It is driving 
> me crazy. Below 
> is an excerpt of the script. Help!
> use Net::FTP;
> 
> print "Username?";
> 
> $username = ;
> 
> print "Password?";
> 
> $password =  ;
> 
> print "ftp_home?";
> 
> $ftp_home = ;
> 
> print "The filename you are searching for is...";
> 
> $filename = ;
> 
> $ftp = Net::FTP->new($url, Debug=>0);
> 
> $ftp->login( $username , $password );
> 
> print $ftp->cwd($ftp_home), "\n";
> 
> $ftp->get($filename);
> 
> $ftp->quit;

Looks like you need to chomp() the $username and $password variables. You
didn't give us the error message or tell where it was coming from, so this
is just a guess. Does it work if you hard code the username and password?

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




RE: code doesn't work

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: COLLINEAU Franck FTRD/DMI/TAM 
> [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 11:12 AM
> To: Perl (E-mail)
> Subject: code doesn't work
> 
> 
> Hi,
> 
> Can anybody tell me why this code doesn't work ?

Define "doesn't work"

> 
> #!/usr/bin/perl -w
> 
> open(FICHIER,"rdn1.html");
> open (TEMP,">>temp.html");
> while()
> {
>   print TEMP $_ until ($_ =~m/ancre/);

This doesn't look good. The loop condition is not modified in the loop body.
So the print will either happen once (if $_ contains "ancre") or an infinite
number of times (if $_ does not contain "ancre").

If you want the outer loop to stop after printing the line containing
"ancre", you need:

   print TEMP $_;
   last if /ancre/;

Or maybe it's something else entirely.

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




RE: "last until eof unless" question

2001-07-26 Thread Bob Showalter

> -Original Message-
> From: David Freeman [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 2:47 PM
> To: [EMAIL PROTECTED]
> Subject: Re: "last until eof unless" question
> 
> 
> 
> 
> well, i'm strictly speaking from a grammatical point of view, 
> but it would 
> seem to me that a
> 
> last until eof unless $email;
> 
> would be a valid syntax to go through to the end of the file 
> unless $email 
> was found.

No, sorry, but it isn't. It's basically nonsense. The syntax:

   "expression" until "condition"

Means: 
   1) evaluate "condition"
   2) if condition is false, evaluate "expression" and go back to step 1

The only way this can ever stop is for "expression" to somehow affect the
value of "condition". In your example:

   last until eof

"eof" is the condition. If eof is false, then last is executed. But last is
a loop control construct, which will terminate the loop. So, if eof is
false, the loop immediately exits. If eof is true, the loop immediately
exits. Hence,

   last until eof

makes no sense, Q.E.D.

Next, you cannot use multiple statement modifiers, so:

   foo until bar unless baz

needs to be written as:

   unless (baz) {
  foo until bar;
   }

> i'm not sure that this is what i want to do, but i thought i 
> would see what 
> would happen if i put it in, other than not working. =)
> 
> basically i'm trying to incorporate a way out of the loop i've made.

Well, last is the way out of a loop.

> 
> so after the script has gone through for the first user input 
> and either 
> found it or not, then added it if not found, i want to have something 
> either End the script, or prompt me to look for another user input.
> 
> hope this clarifies what i'm trying to do.

Well, what is the condition that ends the loop? User presses Enter? User
sends Ctrl-D as eof on stdin? Once you figure that out, the statement:

   last if "condition";

will do the trick.

> 
> Thanks!
> 
> 
> --- code  
> #!/usr/bin/perl -w #Script to add e-mail or domain name to 
> /etc/mail/access file #if not already present.
> 
> use strict;
> #use warnings;
> 
> my $email;
> my $action;
> my $newarray;
> 
> open(NAMES,"/etc/mail/access") || die "Can't open access: 
> $!\n"; while (){
>  ( $email, $action )= split(/\t/);
>  $newarray{$email} = $action;
> }
> close NAMES;
> 
> while(1){
>  print "Look for what domain in spam filter? ";
>  chomp($email=);
>  last until eof unless $email;
>  if( exists $newarray{$email} ){
>  print $newarray{$email}, "\n";
>  }else{
>  print "How you wanna handle this one? ";
>  my $action;
>  chomp( $action =  );
>  $newarray{$email} = $action;
> 
>  }
> open(APPEND,">>testfile") || die print "Can't open testfile: 
> $!\n"; #line above to eventually open /etc/mail/access and 
> append $email & $action #to file. print APPEND 
> "$email\t$action\n"; #to show that file has been added close APPEND; }
> 
> eof;
> 
>  eof ---
> 
> 
> At 09:39 PM 7/26/01 +0300, you wrote:
> >[EMAIL PROTECTED]
> 
> David M.R. Freeman
> webmaster sysadmin for MMP, Inc.
> web:www.woodfreeman.com
> e-mail: [EMAIL PROTECTED]
> phone:  (253) 564-5902
> fax:(253) 565-1811
> 

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




Why does this conditional fail? Perl bug?

2001-07-26 Thread Bob Bondi

Probably not a Perl bug, but this is so confusing I' probably enter it as a
bug
Given the script below and the fact that you run it like: 
>   perl foo.pl -p 10.0.0.1 -s 8080 -t SOS

what would you expect the output to be?


use strict;
use Getopt::Std;
 
my %opts = ();
getopt('pst', \%opts);
my $proxy = $opts{p};
my $serviceport = $opts{s};
my $this_string = $opts{t};

if  ($this_string == "all") {
print "WHY AM I HERE\n";
  }
else {
print "YES! I AM HERE\n";
  }

I'd expect: YES! I AM HERE, yet what I get is: WHY AM I HERE.

Please, any help on this one will be happily accepted.



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


use Getopt::Std question

2001-07-26 Thread Bob Bondi

I really like this set of functions, very handy indeed. I've done this:

my %opts = ();
getopt('psuctfh', \%opts);#proxy serviceport url testclass testcase filename
my $proxy = $opts{p};
my $serviceport = $opts{s};
my $thisurl = $opts{u};
my $testclass = $opts{c};
my $testcase = $opts{t};
my $thistest = $opts{f};


Question: Is there a way to capture the case of bad flags? I've figured out
the no flag case, but, can't seem to get this simple case solved. In the
above -p -s -u -c -t -f are good flags. What can I do to capture the -z -x
... bad flags?

Also, Isn't this really a lot of fun!!!



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


RE: setting and importing ENV from within PERL

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: perl newbie [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, July 26, 2001 6:22 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: setting and importing ENV from within PERL
> 
> 
> I am trying to figure out if there is a way to :
> 
> a) set an ENV variable from within a perl script and
> then print out it's value from within the same shell.
> 
> Here is the code that I am trying to use:
> 
> #!/usr/bin/perl -w
> use strict;
> 
> #  set some environment variables.
>  system(`setenv MY_VAR "test"`);

Problems here: 

1) the backticks are asking perl to run the setenv command, and then
substitue the stdout of that command (probably nothing) and send it to
system(). You need to lose the backticks.

2) setenv is a csh built-in, and backticks use /bin/sh (see perldoc perlop).
Hence, the error message you're getting.

3) system() runs commands in a subshell. Any changes to the environment made
in the subshell will not affect the environment of your perl script.

The solution is just to assign %ENV:

   $ENV{MY_VAR} = "test";

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




RE: UNIQUE ID problems...

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, July 27, 2001 2:50 AM
> To: Beginners (E-mail); Beginners-Cgi (E-mail)
> Subject: UNIQUE ID problems...
> 
> 
> List,
> 
> Interesting problem that I think proves just how much I 
> really don't know about Perl.
> 
> I have copyied most of this variable from the internet... 

Ouch. Some of the worst crap imaginable can be copied from the internet.

> 
> my $unique_id  = time && 0xF && $$;
> 
>  ALL I know is that this uses Unix time and some sort of 
> process ID and also adds some other magic stuff to it.  

Whoever wrote this is a moron. The result of this expression will always be
the process id. The && is a logical "and" operation. The three values,
time(), 0xF, and $$ will always be "true". The result of stringing a
bunch of true values together with && will be the rightmost value, namely
$$.

I would avoid this idiot's code like the plague...

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




RE: deleting lines

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: Me [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, July 27, 2001 5:30 AM
> To: COLLINEAU Franck FTRD/DMI/TAM; Perl (E-mail)
> Subject: Re: deleting lines
> 
> 
> > I would like too delete the 2nd, 3rd, 4, and 5 lines of a file. how 
> > can i do ?
> 
> Try this at a shell prompt:
> 
> perl -ni.bak -e '$. =~ /[2-5]/ or print' FILENAME

Ouch! That will delete lines 12, 13, 14, 15, plus all lines between 20 and
59, 62, 63, 64, 65, 72, 73, 74, 75, ...

At least you had him create a .bak file!

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




RE: Passaing arrays or array references as parameters

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: Rahul Garg [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, July 27, 2001 8:55 AM
> To: [EMAIL PROTECTED]; Perl Beginners
> Subject: Passaing arrays or array references as parameters 
> 
> 
> Hello Everybody,
> 
> what i want is to pass an array(reference) as a parameter to 
> an hyperlink(in CGI script)  to another CGI script and access 
> the elements of array there.how can i do it... if 
> this is not possible then how can i call the subroutine 
> within the same CGI script thru an hyperlink  with 
> array(reference) as a parameter

First of all, use the CGI module.

To encode an array in a url, you can just give multiple parameters with the
same name:

   http://mysite.com/cgi-bin/myscript.pl?color=red&color=white&color=blue

In myscript.pl, you would retrieve this array as:

   use CGI;

   my $q = new CGI;

   my @color = $q->param('color');

@color would contain ('red', 'white', 'blue')

HTH,
-- Bob

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




RE: lost in hashes

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, July 27, 2001 10:21 AM
> To: begginners
> Subject: RE: lost in hashes
> 
> ...Also, when you reference some field from $T{d4}, you need to 
> be sure to deREFERENCE it like this:
> 
> $T{d4}->{names}
> 
> So you'll have to change that in the popup_menu.

Actually, according to perllol the -> is not required when placed between
brackets (square or curly).

So $T{d4}->{names} and $T{d4}{names} are equivalent.

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




RE: in over my head in hashes again

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: Jerry Preston [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, July 27, 2001 1:09 PM
> To: begginners
> Subject: in over my head in hashes again
> 
> 
> Hi!
> 
> I am lost again:
> 
> 
> 
>   %T_QUESTION = {

(snip remainder)

The construct

   %foo = { blah ... };

is wrong. a list inside curly braces { } evaluates to a *reference* to an
anoynmous hash. You need to enclose your list in parens ( ) to initialize a
hash. You either need to use:

   $foo = { bar => 'baz' };
   print $foo->{bar};   # note deref; prints "baz"

or

   %foo = ( bar => 'baz' );
   print $foo{bar}; # prints "baz"

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




RE: CGI to rewrite a URL

2001-07-27 Thread Bob Showalter

> -Original Message-
> From: Rich Fernandez [mailto:[EMAIL PROTECTED]] 
> Sent: Friday, July 27, 2001 3:09 PM
> To: [EMAIL PROTECTED]
> Subject: CGI to rewrite a URL
> 
> 
> Hi,
> 
> I've been asked to write a CGI script that takes a URL of the form:
>   https://webserver/cgi-bin/myscript.cgi/myreport
> 
> and redirects the browser to:
>   
> https://webserver/cgi-bin/myscript.cgi/full/path/to/report/myr
eport
>
> In other words, we want to hide the true URL of the report from the
browser.
>
> Can anyone give me an idea about how to start this? Specifically, if I
have a
> script called myscript.cgi, how do I get it to recognize "myreport" as a 
> parameter? It's probably easy to do, but my experience with CGI is next to

> nothing.

1. Use the CGI module:

   use CGI;

   my $q = new CGI;

2. the extra stuff beyond your script name will be in $q->path_info();

3. to send the browser somewhere else, use the redirect method:

   print $q->redirect('http://wherever.you/want/them/to/go');

All nicely documented in 

   perldoc CGI

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




loose matching with regex

2001-07-28 Thread Bob Mangold

Hello,

I'm working on a program where I am searching for a short string within a
longer string. The catch is that the long string is about 4.5 million chars
long and the short string is about 500. Using a regex to do an exact match is
simple, but what if I want just a close match, like 80% or whatever. I've used
the module Similarity in the past, but in order to use that I have to send it
two string to compare, which means I'd have to slide down the longer string
character by character. Is there a faster way. Is there a module that returns
true for a regex match within a certain percentage?

-Bob

__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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




Re: (MORE INFO) loose matching with regex

2001-07-28 Thread Bob Mangold

Aziz,

I guess I hadn't thought about it that way, so here is more info.

What I'm basically doing is randomly pulling a string of 500 from one string
and looking for it in another string. So I'm looking for a substring of the
larger string that matches my query string. In terms of how it matches the
answer and to your questions, all of the above. I don't care if there are
insertions, deletions of just character changes, as long as the query sting is
80% similar to the subject string.

Like I said I know I can use the module Similarity. But in order to do this I
would need bot the query and the subject string. And to get the subject string
I would need to 'slide' down the larger string and pull out all combinations 1
by 1. This is very slow with a 4.5 million character string. I'm just looking
for a way to speed things up.

BTW, if it helps at all, I'm doing genetic analysis of whole genomes, hence the
4.5 million long string.

-Bob

--- Abdulaziz Ghuloum <[EMAIL PROTECTED]> wrote:
> Hello,
> 
> I don't have a direct answer for your question since your question is a
> little bit ambigious; let me explain:
> 
> Do you want to search for a substring in a long string, or you want true
> regexp match?
> 
> If you want a true regexp match, then the question is even more
> ambigious.  For example, the regexp /(ab){20}a{10}/ does not match the
> string "ababababababa", but what percentage does it match?  How
> do you determine the percentage let alone matching for a given error
> percentage.
> 
> If you just want a substring match (not a regexp), then your problem is
> simpler, but you need to define your criteria more clearly.
> 
> Do you want to allow up to 20% more characters to be inserted to the
> substring and still consider it a match?
> 
> Do you want to match down to 80% of the substring and still consider it a
> match?
> 
> Do you want to allow up to 20% of the characters to be altered (not
> removed or inserted) and still consider it a match?
> 
> Or a combination of the above?
> 
> Without this information, no reply is even remotely correct.  Please
> provide more information about the problem to get closer to the solution
> to your problem.
> 
> Hope this helps,,,
> 
> Aziz,,, 
> 
> In article <[EMAIL PROTECTED]>, "Bob
> Mangold" <[EMAIL PROTECTED]> wrote:
> 
> > Hello,
> > 
> > I'm working on a program where I am searching for a short string within
> > a longer string. The catch is that the long string is about 4.5 million
> > chars long and the short string is about 500. Using a regex to do an
> > exact match is simple, but what if I want just a close match, like 80%
> > or whatever. I've used the module Similarity in the past, but in order
> > to use that I have to send it two string to compare, which means I'd
> > have to slide down the longer string character by character. Is there a
> > faster way. Is there a module that returns true for a regex match within
> > a certain percentage?
> > 
> > -Bob
> > 
> > __ Do You Yahoo!?
> > Make international calls for as low as $.04/minute with Yahoo! Messenger
> > http://phonecard.yahoo.com/
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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




RE: [Fwd: Re: how can an element in a array be deleted from a subroutine ?]

2001-07-30 Thread Bob Showalter

> -Original Message-
> From: Narendran Kumaraguru Nathan [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, July 30, 2001 6:08 AM
> To: [EMAIL PROTECTED]
> Subject: [Fwd: Re: how can an element in a array be deleted 
> from a subroutine ?]
> 
> 
> 
> Hai all,
>I have found it myself, using splice, it is working.
> Naren.
> 
> Narendran Kumaraguru Nathan wrote:
> 
> > Hai all,
> >I have a local array and I wish to delete the last 
> element of the 
> > array from the subroutine. I pass the array as reference 
> and tried as 
> > pop(@array_neme); this didn't work. Is there a way I can do it?
> > Thanks & Regards,
> > Naren.

Note that pop() is just a special case of splice(), so using pop() should
work to remove the last element in an array.

You mention passing a reference to a sub, but your pop() call doesn't
dereference. A sub to remove the last element from an array would look like:

   sub remove_last
   {
  my $aref = shift;

  pop @$aref;  # note dereference
   }

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




RE: eval and Data::Dumper

2001-07-30 Thread Bob Showalter

> -Original Message-
> From: mark crowe (JIC) [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, July 30, 2001 11:25 AM
> To: beginners
> Subject: eval and Data::Dumper
> 
> 
> Please can someone give me some advice about Data::Dumper. I 
> have a program which will generate a large multidimensional 
> array which I then want to import into another program. From 
> what I remember from some posts a while ago (and can't find 
> again now) I should be able to do this using Data::Dumper, 
> and the Camel book and perldoc seem to agree. It's just I 
> can't work out how to read the data back in. I've tried eval 
> and do, and neither of them are working as I hoped. Here's 
> some test code I've tried:
> 
>   use Data::Dumper;
>   @array = qw(one two three);
>   $string  = Dumper(@array);
>   @newarray = eval $string;
>   print "@newarray";
> 
> This outputs:
>   $VAR1 = 'one';
>   $VAR2 = 'two';
>   $VAR3 = 'three';
>   three
> 
> I can print the Dumper output to a file and read it back in 
> with do or eval and get the same problem, just getting the 
> last value put into the array. Can someone point me in the 
> right direction please?

Suggestions:

1. Pass reference to your array to Dumper(): 

   $string = Dumper(\@array);

2. Read Data::Dumper docs and look at "Purity" and "Deepcopy" options. 

3. Look at Storable module.

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




RE: most efficient way to count lines in a file

2001-07-30 Thread Bob Showalter

> -Original Message-
> From: ERIC Lawson - x52010 [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, July 30, 2001 11:35 AM
> To: [EMAIL PROTECTED]
> Subject: most efficient way to count lines in a file
> 
> 
> What's the most efficient way to find the total number of 
> lines in a file using perl?
> 
> Now, I'm using 
> 
> while () { ++$lincnt; }

That's OK. This also works:

   perl -ne 'END { print "$.\n" }' foo

$. is line number (see perldoc perlvar)

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




RE: Destroying Database Handle

2001-07-30 Thread Bob Showalter

> -Original Message-
> From: Frank Newland [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, July 30, 2001 11:35 AM
> To: [EMAIL PROTECTED]
> Subject: Destroying Database Handle
> 
> 
> Question about DBI
> 
> I'm having success in preparing , executing and getting SQL 
> output when I use DBI. What I want to do is ensure that I 
> close properly. 
> Q: What statement(s) do I need to prevent destroying database handle?
> 
> Thanks,
> 
> Frank
> ***
> #!/usr/bin/perl -w 
> use strict ;
> use DBI;
> my $dbh ; my $sth ; my $sql_stmt ; $data_row; 
> 
> $dbh = DBI->connect("dbi:Oracle:oracle:qa_1",user, 
> password,{PrintError =>0, AutoCommit =>0 )) || die "failed to 
> login to Oracle \n"; $sql_stmt = << "EOF+" ; select comments 
> from table_a where comments is not null
> EOF+ 
> 
> $sth=$dbh->prepare($sql_stmt) || die "Failure to prepare SQL 
> Statement \n" ; $sth->execute || die "Failure to execute SQL 
> \n"; $data_row=$sth->fetchrow_hashref; $comments = 
> $data_row->{COMMENTS};
> 
> print $comments ;
> **
> Output:
> 185221202202110  ## desired output. .
> Database handle destroyed without explicit disconnect.

You need to use

   $sth->finish;
   $dbh->disconnect;

After you are done reading fetching the data. That should do the trick.

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




Getopts and ARGV

2001-07-30 Thread Bob Bondi

I've been trying to figure out how to give help with a -h opt flag and use
the Getopt::Std within the same script.
I've tried several ways to make this happen, and stumbled on an answer. 
I've discovered that use Getopt::Std will not allow me to use @ARGV beyond
the point I have typed Getopt::Std in the Perl script. I simply wanted to
get the count of args from @argv and if it was a single arg AND it was '-h'
then give help. 

Anyway, the order of items in Perl is really important!!!

use strict -w; 
use File::Basename;
use Carp;
use FileHandle;
my $count = @ARGV;
carp "<<>> unless $count > 0;
if ($count = 1 && @ARGV[0] eq "-h") {<.HELP STUFF>}
use Getopt::Std;
use constant DIRECTGET   => 1;
my %opts = ();
getopt('p:s:u:c:t:f:', \%opts);

I had wanted to keep all the declarations in a section and the subs in a
section and the main script at the bottom, but, I find I must add code in
the declaration section!

Is this normal



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


RE: search for string in a file

2001-07-30 Thread Bob Showalter

> -Original Message-
> From: alex stan [mailto:[EMAIL PROTECTED]] 
> Sent: Monday, July 30, 2001 1:57 PM
> To: [EMAIL PROTECTED]
> Subject: search for string in a file
> 
> 
> I need to search for a string in httpd.conf file , ( the 
> string is : CustomLog /var/log/httpd/site.com/access_log ) 
> and then replace inside them  site.com with site_com. I 
> mentioned that the site.com can take diferent values, such as 
> shop.com , 
>  radioq.com
>  etc.

Something along the lines of

   perl -pe 's!/([^/]+)\.com!/$1_com! if /^CustomLog/' httpd.conf

should do the trick.

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




RE: DBI question ...

2001-07-31 Thread Bob Showalter

> -Original Message-
> From: Elie De Brauwer [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 31, 2001 9:16 AM
> To: [EMAIL PROTECTED]
> Subject: DBI question ...
> 
> 
> Hello,
> I have a little problem relating a program that I'm writing. 
> This program 
> involves getting data from mysql databases.
> 
> According to some docs the code should be like
> 
> use DBI;
> $dbh = 
> BDI->connect('DBI:mysql:databasename:database:host','username'
> ,'pass') 
> or die $DBI::errst;
> 
> Now my problem is the following, in order to connect you have 
> to know the 
> databasename but I want it to be that the users get a list of 
> possible 
> databases, picks one of them and then uses that database.  So 
> simply putting 
> a sql show database; to the screen and letting the user pick one out.
> 
> BUT before connecting  you already have to know the 
> databasename ... how do i 
> solve this ? Or can i stupidly give no databasename ?

Look at the DBI method data_sources(). Look also at the caveats for this
method in the DBI documentation. I use Oracle, at it works for that, but I
don't know if it works for MySQL. Try the following:

   perl -MDBI -e 'print "$_\n" for DBI->data_sources("mysql")'

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




RE: substitution

2001-07-31 Thread Bob Showalter

> -Original Message-
> From: COLLINEAU Franck FTRD/DMI/TAM 
> [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 31, 2001 8:15 AM
> To: Perl (E-mail)
> Subject: substitution
> 
> 
> Hi!
> 
> I have a file where there is a line whitch begans by the 
> string "". I would like to remove the string 
> "" by nothing. How can i do ?

   perl -pe 's/^//' myfile

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




RE: check array element (HELP)

2001-07-31 Thread Bob Showalter

> -Original Message-
> From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 31, 2001 9:44 AM
> To: [EMAIL PROTECTED]
> Subject: RE: check array element (HELP)
> 
> 
> I would probably do this, although i'm sure some smarty-pants 
> could come up with a one-liner  ;)
> 
> sub repeated_elements
> {
>   my %found_one;
>   for (@_)
>   {
>   return 1 if $found_one{$_}++;
>   }
>   return 0;
> }

One-liner:

   print "Duplicates!" if keys %{{ map { ($_ => 1) } @arr }} != @arr;

Note: Do NOT use this! Along with being quite unreadable, it's also
inefficient. Use the iterative approach above.

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




RE: Security Question (follow-up question)

2001-07-31 Thread Bob Mangold

This is somewhat alarming to me because I hadn't realized this potential
before, but is there an easy way to check what is being opened. Would using a
-f() or -d() to verify that you were actually opening a file or directory do
the trick?

-Bob

--- Mooney Christophe-CMOONEY1 <[EMAIL PROTECTED]> wrote:
> Actually, open is only a security hole if you allow the user to tell you
> what to open at the command line.
> 
> i don't have the exact message in front of me, but my guess is that someone
> said something like:
> 
> $_=;
> open(IN,"$_|");
> 
> In which case if the user entered 'rm -rf /', it would try to delete
> everything.  This would be especially disastrous if the script were run as a
> superuser, in which case everything on the system would irretrievably vanish
> in the blink of an eye.
> 
> So don't be afraid to use 'open' if you know exactly what you're opening ...
> ;)
> 
> -Original Message-
> From: Mooney Christophe-CMOONEY1
> [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 31, 2001 9:41 AM
> To: Perl Beginners
> Subject: RE: Security Question
> 
> 
> 'rm -rf .' is a unix command that removes everything in the current
> direcotry PERMANENTLY and UNCONDITIONALLY
> 
> -Original Message-
> From: Customer Service [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 31, 2001 9:44 AM
> To: Perl Beginners
> Subject: Security Question
> 
> 
> Dear Sirs,
> I first of all wanted to apologize about sending so many redundant questions
> to the list.  I wasn't aware that my wife was downloading my mail also and I
> didn't see all of your replies to previous questions.  Won't happen again
> ;-))
> 
> I was reading a reply to a question this morning that stated that the open()
> call is a big security hole because someone could put in ";rm -rf ."  as the
> value for $email.
> What does ";rm -rf ." do?  Why is it so dangerous?
> 
> Nathan Garlington
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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




RE: Exec cgi

2001-07-31 Thread Bob Showalter

> -Original Message-
> From: Tiago Almeida Spritzer [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 31, 2001 10:44 AM
> To: [EMAIL PROTECTED]
> Subject: Exec cgi
> 
> 
> Hi,
> 
>  Anybody help me with this question?
>  I have two folders at the server, one with perl files 
> and other with html files. I need that the page index.html 
> execute perl file, and I know that this TAG do that .  But I 
> try and don't obtain any result.

Are you sure the server is configured for server side includes? Does
something simple the following work?

   

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




RE: Exec cgi

2001-07-31 Thread Bob Showalter

> -Original Message-
> From: Tiago Almeida Spritzer [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 31, 2001 10:44 AM
> To: [EMAIL PROTECTED]
> Subject: Exec cgi
> 
> 
> Hi,
> 
>  Anybody help me with this question?
>  I have two folders at the server, one with perl files 
> and other with html files. I need that the page index.html 
> execute perl file, and I know that this TAG do that .  But I 
> try and don't obtain any result.

Forgot to add: the argument to #exec cgi is a URL, not a filespec.

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




RE: binary files

2001-07-31 Thread Bob Showalter

> -Original Message-
> From: Tyler Cruickshank [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, July 31, 2001 1:32 PM
> To: [EMAIL PROTECTED]
> Subject: binary files
> 
> 
> Hello. 
> 
> Looking for some binary file help.  I want to read, 
> manipulate, and print (in ascii) a binary file on a solaris 7 
> machine.  I have looked into and tried the binmode() function 
> but this seems to be for older machines that differentiate 
> between ascii and binary files.  I have tried the following 
> and just get the binary form printed back out at me (the 
> expected result):
> 
> open(FILE, "mybinaryfile") || or die "error\n";
> while(){
> print "$_\n";
> }
> 
> When perl reads a binary file as above, does it understand 
> what it is reading?  How can I print the file back out in ascii?

A file is a file. Perl isn't going to do anything special with your files.
It just calls your system read(2), or fread(3) calls to read a file.

A loop like you have above is suitable for reading "text" files broken into
"lines" separated by \n chars (although perl lets you define any kind of
"line" separator you want).

For data that's not divided into "lines", you can use the perl read()
function. If the data is packed into various binary formats, you can use
perl's unpack() function to decode it into individual values.

binmode is for those systems like Win32 that munge around with line endings
on "text" files. For Unix, you don't need to worry about it (although
calling binmode is harmless on Unix).

See:

   perldoc read
   perldoc seek
   perldoc tell
   perldoc sysread
   perldoc unpack

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




RE: Printing a data structure

2001-08-01 Thread Bob Showalter

> -Original Message-
> From: Chris Garringer [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 10:19 AM
> To: [EMAIL PROTECTED]
> Subject: Printing a data structure
> 
> 
> I have a data structure $logs[]{}{}[] that has the data 
> parsed from a log file.  I need to print the structure in a 
> form that managment can understand.  My problem is, I can 
> fill the structure correctly but cannot seem to get a handle 
> on printing it to allow printing the parts in a decent form.  I tried
> foreach $day (@logs)
> {

OK, @logs is an array of hashrefs. So $day is a hashref. So far so good.

> some code1.
> foreach $username (%$day)
> {

Problem here. %$day is a hash (dereferced via the $day hashref). When you
put a hash in the for (...) loop, it is "unrolled" into a flat list of
key/value pairs. So $username is assigned alternately a username (hash key)
and then a hashref (hash entry).

If you don't need the user name or don't care about the order in which
users are processed, you can use the values() function to get just the
hash entries as a list:

   for my $userref (values %$day)

If you do need the user name, and/or you want to process users in sorted
order (for example), you need to use the keys() function to get just the
hash keys as a list:

   for my $username (sort keys %$day)
   {
  my $userref = $day->{$username};   # get the hashref for this user

> .some code2.
>   foreach $authmethod (%$username)
>{

Same problem here as above.

>   .somecode    the program never got here
>   }
> }
> }
> 
> I am still confused on Perl's reference/dereference 
> symbology, so what am I doing wrong?

Make sense?

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




RE: Sending mail using PERL with file as body of message

2001-08-01 Thread Bob Showalter

> -Original Message-
> From: Rice, Elizabeth A. [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 11:58 AM
> To: '[EMAIL PROTECTED]'
> Subject: Sending mail using PERL with file as body of message
> 
> 
> ...
> Here's the basic sendmail code:
> 
> open(TMPMAIL, "<$tmpmail");
> 
> use Mail::Sendmail;
> 
> %mail = ( To  => "@slist",
>   From=> '[EMAIL PROTECTED]',
>   Subject => "$HOSTNAME $QMGR MQARCH03I Just 
> a short message
> ",
>   Body=> 

This looks like a problem.  is being evaulated in a list context,
so it evaluates to a list containing one element for each line in the file.
But this list of lines is being used as a hash intializer (for %mail). So
the first line of the file becomes the value associated with the key 'Body'.
The second line of the file becomes another key in %mail, with the third
line of the file becoming the value associated with that key.

You need to have the entire body as one scalar. The use of  in the
hash initializer is too tricky for my blood. I would do something like this:

   open(TMPMAIL, "<$tmpmail") or die "Couldn't open: $!";
   my $body;
   {
  local $/ = undef;  # file "slurp" mode temporarily
  ($body) = ;
   }

Then use in the hash initializer:

   Body => $body

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




RE: check array element (HELP)

2001-08-01 Thread Bob Showalter

> -Original Message-
> From: Wagner Jeff Civ Logicon/TTMS
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 2:14 PM
> To: Bob Showalter
> Cc: '[EMAIL PROTECTED]'
> Subject: RE: check array element (HELP)
> 
> 
> Let me see if I understand your one-liner...
> 
> *  the "map" function creates a hash, using the array 
> elements as key names,
> automatically eliminating duplicates
> *  the output from the "keys" function (an array) is compared to the
> original array, both in scalar context, so the number of 
> elements will be
> different if there were duplicates

Yep, you've got it. Actually map() is creating a *list*, which is being used
to initalize an anonymous hash. Working from the inside out:

   map { ($_ => 1) } @arr

returns a list equivalent to ($arr[0], 1, $arr[1], 1, $arr[2], 1, ...). 
Wrapping any list in curly braces:

   { list }

returns a reference to an anonymous hash initialized from the list. The hash
keys
end up being the (unique) original array values, and each hash entry is
simply
a 1 (which is really being ignored). The notation:

   keys %{ hashref }

returns a list of the keys in the hash pointed to by the hash reference.
Since this expression appears as part of a != test, it is evaluated in
scalar context. Any list evaluated in scalar context returns the number of
elements in the list. So this is equal to the number of unique values from
our original array. We then compare this to @arr, again in scalar context.

So the test is:

   No. of unique elments != No. of total elements

If they are not equal, there must be at least one duplicate.

> 
> Pretty neat.  So the difference between this an the iterative 
> approach is
> that the one liner processes all the array elements every time and the
> iterative approach drops out as soon as it finds a duplicate.

Yes, and my one-liner is almost certainly more memory-intensive than the
iterative approach.

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




RE: check array element (HELP)

2001-08-01 Thread Bob Showalter

> -Original Message-
> From: Paul [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 3:41 PM
> To: Bob Showalter; '[EMAIL PROTECTED]'
> Subject: RE: check array element (HELP)
> 
> 
> 
> --- Bob Showalter <[EMAIL PROTECTED]> wrote:
> > . . . 
> > Yep, you've got it. Actually map() is creating a *list*, which is
> > being used to initalize an anonymous hash. Working from the inside
> > out:
> > 
> >map { ($_ => 1) } @arr
> > 
> > returns a list equivalent to ($arr[0], 1, $arr[1], 1, $arr[2], 1,
> > ...). 
> > Wrapping any list in curly braces:
> > 
> >{ list }
> > 
> > returns a reference to an anonymous hash initialized from the list.
> 
> Just a caution -- I misread this the first time through. =o)
> While generally true, consider the context. For example,
> 
> map { ($_ => 1) } @arr
> 
> is wrapping a list in curly braces, but in this case, it's a block.
> The curlies represent not a hash reference, but code block which map
> uses. The code is just a list expression.
> 
> Curlies do return hash refs, though, in the right context. =o)

Yes, you are correct. The curlies in the map() are a block. Context
is everything.

> What was the code? something like
> 
>   %{ { map { ($_ => 1) } @arr } }
> 
> The %{} says "the enclosed expression evaluates to a hash reference".
> The inner curlies make the reference out of the list.

Actually the { } around map creates the hash ref, while the outer %{ }
dereferences this hash ref back to a hash, so I can feed it to keys(). 
Just one pair of {} doesn't do it.

Whew!

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




RE: save file in an array

2001-08-01 Thread Bob Showalter



> -Original Message-
> From: Jennifer Pan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 4:45 PM
> To: [EMAIL PROTECTED]
> Subject: save file in an array
> 
> 
> I want to download a page, and want to save it in an array to parse it
> later on,
> I did
> 
> #usr/local/bin/perl
> my @list;
> 
> $URL1= "http://blablabla";;
> $command="/opt/sfw/bin/wget -nv -O @list $URL1";

Perl will interpolate @list here and replace it with "", since @list is
empty.
(Which is just as well, since the shell has no idea what a perl array is.)

> system "$command";
> print @list;
> 
> it didn;t work. But if I say 
> $command="/opt/sfw/bin/wget -nv -O list $URL1";
> 
> it works, but it saved the downloaded file into a file named "list" in
> the current directory.
> 
> How do I save a file to an local variable?

Get your system command to write its output to stdout and capture the output
with backticks:

   $output = `$command`

Or, open the file created by your command and read it.

Also, consider using the LWP::Simple or LWP::UserAgent modules, which let
you make HTTP and other requests directly from Perl.

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




RE: Valid DB Handle Assertion Test

2001-08-02 Thread Bob Showalter

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 9:44 AM
> To: [EMAIL PROTECTED]
> Subject: Valid DB Handle Assertion Test
> 
> 
> 
> Can I test for the existence of a method without actually calling it?

I don't know. Maybe, but some methods are implemented via AUTOLOAD, so may
not "exist" in the sense you mean.

> 
> Basically what I'm trying to do is to verify that $dbh is 
> still a valid
> handle.
> I want to use this as an assertion test at the start of a function.
> 
> # verify that the $dbh is valid
> if ( !defined($dbh->disconnect() ) )
>  {
>  print "dbh is invalid\n" ;
>  exit 1
>  }

Well, this won't work, becuase it's testing the result returned from calling
$dbh->disconnect.

You have 3 possiblities with $dbh:

1. $dbh is a reference to a connected database handle.

2. $dbh is a reference to an unconnected database handle.

3. $dbh is not a reference to a database handle at all.

You can use perl's ref() function to distinguish the first two cases from
the last. see

   perldoc -f ref

Once you know you have a database handle, you can use $dbh->{Active} to
tell whether it is connected (per DBI docs, although this may vary from
driver to driver). Actually, calling disconnect on an unconnected handle
seems to be harmless and treated as a no-op.

Another approach is to wrap the disconnect in eval, which lets you capture
the error rather than having it stop your program:

   eval { $dbh->disconnect(); };

If $dbh is not a database handle, the relevant error message will be in $@.

   perldoc -f eval

> 
> # $dbh is valid so we can safely disconnect
> $dbh->disconnect()

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




RE: File Handling question - easy

2001-08-02 Thread Bob Showalter

> -Original Message-
> From: Jon [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 2:03 PM
> To: [EMAIL PROTECTED]
> Subject: File Handling question - easy
> 
> 
> I don't know if I sent my first email correctly.  Sorry for 
> the repeat if I 
> did, I'm new :)
> 
> Hello,
> The code below takes all files in my current directory that 
> have filenames 
> ending with ".txt". Using this stuff I can loop through those 
> files and do 
> what I need to do.
> 
> My problem is, I want to do this for a bunch of different 
> patterns (ex. 
> ".txt", ".this", ".that"). How can I make what is inside the 
> angle brackets 
> a variable? I've tried to use eval to build my while 
> statement and I can't 
> make it work. Help Please?
> 
> while(<*.txt>)
> {
> ### do stuff, given a filename
> }

Use glob():

   my $patterns = '*.txt *.this *.that';
   for (glob($patterns)) { ... }

P.S. I'm surprised this works with while(). I didn't realize fileglobs
were magical inside while(), but it appears they are... Is this documented?

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




RE: Help with Net::Telnet module

2001-08-02 Thread Bob Showalter

> -Original Message-
> From: S. Johnson [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 5:05 PM
> To: [EMAIL PROTECTED]
> Subject: Help with Net::Telnet module
> 
> 
> I am looking for some help debugging a problem with the 
> Net::Telnet module
> written by Jay Rogers.
> 
> Here's the subroutine I am having problems with:
> 
> sub login
>   {
>$errmode = 'return';
>$hostaddress = 'xxx.xxx.xxx.xxx'; 
>$prompt = '/Sheldon_NS16>/';
>$username = '';
>$password = '';
>$obj = new Net::Telnet ( Host => $hostaddress,
> Errmode => $errmode,
> Prompt =>  $prompt,
> Timeout => 15,
> Port => 23 );
>   $obj->login($username, $password);  # line 212
>   $errmsg = $obj->errmsg;
>   print STDOUT "Error - $errmsg\n" unless ($errmsg eq "");
>   }
> 
> This subroutine is part of a larger script (sheldon.pl) that 
> calls this
> subroutine once per minute
>  to login to a modem pool to get user information and log it 
> for tracking
> users usage.  
> The program will run for 1-2 days before dying.  The error I get is as
> follows:
> 
> Can't call method "login" on undefined value at ./sheldon line 212.
> 
> As I said above, the script will run for a day or two collecting data
> without any problems, then
> die with the error above.  Any Perls of wisdom out there?

I don't know anything about Net::Telnet, but I'd say the call to
Net::Telnet::new is failing for some reason. You're not checking the return
value from new(). Perhaps there is a way to do that?


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




RE: input output append

2001-08-02 Thread Bob Showalter

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 5:10 PM
> To: [EMAIL PROTECTED]
> Subject: input output append
> 
> 
> HI,
> anyone knows the right syntax for  reading and writing 
> (appending) to a file.

I assume you mean "open a file for both reading and writing", since
the code you posted doesn't do any reading or writing.

> I tried this and it didn't seem to work
> open (FH,"+< file.txt" )

Define "didn't seem to work". The file must exist for this open to succeed.

open(FH, '+>>file.txt') will open file for append, creating if necessary,
and allowing read access. But all writes go to end of file.

perldoc perlopentut gives all the gory details of how to open things.

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




RE: Where is DB_File::Lock module?

2001-08-02 Thread Bob Showalter

> -Original Message-
> From: Carlos C.Gonzalez [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 01, 2001 7:35 PM
> To: [EMAIL PROTECTED]
> Subject: Where is DB_File::Lock module?
> 
> 
> Hi everyone,
> 
> I am going absolutely nuts trying to find where to get the 
> DB_File::Lock 
> module.  I have looked all over CPAN, have done searches on 
> Google.com 
> and while there is some info on it I can't find out where to 
> download it. 
> 
> Does anyone have any suggestions?

Use the CPAN module to get and install modules.

   perldoc CPAN

   perl -MCPAN -e shell
   cpan> install DB_File::Lock


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




RE: File Handling question - easy

2001-08-03 Thread Bob Showalter

> -Original Message-
> From: Michael Fowler [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 2:48 PM
> To: Bob Showalter
> Cc: [EMAIL PROTECTED]
> Subject: Re: File Handling question - easy
> 
> 
> On Thu, Aug 02, 2001 at 02:31:28PM -0400, Bob Showalter wrote:
> > P.S. I'm surprised this works with while(). I didn't 
> realize fileglobs
> > were magical inside while(), but it appears they are... Is 
> this documented?
> 
> Yes, perldoc perlop, in the I/O Operators section (5.6.1 version):
> 
>   A (file)glob evaluates its (embedded) argument only when it is
>   starting a new list.  All values must be read before it 
> will start
>   over.  In list context, this isn't important because 
> you automatically
>   get them all anyway.  However, in scalar context the 
> operator returns
>   the next value each time it's called, or "undef" when 
> the list has run
>   out.  As with filehandle reads, an automatic "defined" 
> is generated
>   when the glob occurs in the test part of a "while", 
> because legal glob
>   returns (e.g. a file called 0) would otherwise 
> terminate the loop.
>   Again, "undef" is returned only once.

Thanks for the cite.

I played around with this a bit and found that:

   perl -e 'print scalar(glob("*")) for (1..2)'

prints two different files, while

   perl -e 'print scalar(glob("*")), scalar(glob("*"))'

prints the same file twice. I tried this on 5.005_03 and 5.6.1.

Wonder why? Seems like its related to the loop context and not merely
to scalar context.

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




RE: Any good perldoc viewer?

2001-08-03 Thread Bob Showalter

> -Original Message-
> From: Will Muir [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 03, 2001 10:10 AM
> To: [EMAIL PROTECTED]
> Subject: Any good perldoc viewer?
> 
> 
> 
> Is there such a thing as a good perldoc viewer, I guess what 
> I mean is there something other then the dos prompt.  I don't 
> mind using an xterm window under Linux but I am stuck with 
> using windoze for the time being and I hate the way that 
> perldoc works under windows.  Something with a nice GUI that 
> works under windows would be nice.

If you have ActiveState, it has all the standard docs in HTML format, so you
can just use your browser.

Also, perldoc will pipe its outupt to any program defined in the PAGER env
variable. I use gnu less and using perldoc in a DOS window is satisfactory
that way.

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




RE: Perl equivalent of "case" or "switch" statements ?

2001-08-06 Thread Bob Showalter

> -Original Message-
> From: jp [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 06, 2001 11:21 AM
> To: [EMAIL PROTECTED]
> Subject: Perl equivalent of "case" or "switch" statements ?
> 
> 
> 
> I've been searching through books and web resources
> but can't seem to find any reference to equivalent 
> of "case" or "switch" statements in Perl.
> 
> Is there such a thing in Perl?
> 
> (Every reference to the word "switch" leads me towards
>  things like -w etc...)

This is a FAQ. Try:

   perldoc -q switch

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




RE: == vs eq What's the difference?

2001-08-06 Thread Bob Showalter

> -Original Message-
> From: Michael Kelly [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 06, 2001 1:38 PM
> To: [EMAIL PROTECTED]
> Subject: Re: == vs eq What's the difference?
>  
> ...
> To elaborate, all strings have a numerical value of 0.

Ouch! need to clarify that a bit.

When comparing with the numeric operators, Perl converts strings to numbers
using something like the atof(3) function (maybe it actually uses atof(),
I'm not sure). So the numeric value of a string is determined by skipping
any leading whitespace and examining characters until the first unrecognized
character is found. If no characters that look like a number are found, 0 is
returned.

The following numeric comparisons are all TRUE:

   "123" == 123
   "   123" == 123
   "123.0" == 123
   "1.23E2" == 123
   "123 Main Street" == 123


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




RE: Did I violate?

2001-08-06 Thread Bob Showalter

> -Original Message-
> From: Tom Malone [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 06, 2001 2:59 PM
> To: [EMAIL PROTECTED]
> Subject: Did I violate?
> 
> 
> Hey everyone!
> 
> I hope that I did not violate some rule of list etiquette 
> with my messages 
> about writing Perl scripts for GAIM ("GAIM", "GAIM && Perl", 
> and "Perl 
> Scripts for GAIM"). I posted three messages, and all of them 
> went unanswered. 

I don't think you angered anyone. I personally have no idea what GAIM is.

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




RE: Did I violate?

2001-08-06 Thread Bob Showalter

> -Original Message-
> From: Tom Malone [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 06, 2001 3:26 PM
> To: Bob Showalter
> Subject: Re: Did I violate?
> 
> 
> Is that what my problem was (why nobody responded)?  Because 
> a lot of people 
> didn't know what GAIM was?  I hadn't expected that windows 
> users would be 
> familiar with it, but I thought most Linux people would know about it.

I do not use Linux. My environment is HP-UX/Oracle/Apache/mod_perl/Mason.

Are you going to tell us what it is? :)

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




  1   2   3   4   5   6   7   8   9   10   >