Re: Dates

2005-01-07 Thread Scott R. Godin
Jeff Eggen wrote:
Tim Wolak <[EMAIL PROTECTED]> 06/01/2005 3:59:26 pm >>>
Hello all,

I am in need of a quick way to get the current date in the MMDD 
format.  This is something I would like to understand better on how to

get the date with perl.  Any suggestions would be most welcome.
As per the perlcheat page: "just use POSIX::strftime!"
# Begin
use POSIX qw(strftime);
my $date = strftime("%Y%m%d", localtime());
# End
There's possibly something in Date::Calc as well.  But this is the
quickest way I know, especially if you're familiar with the date command
in *nix.
Indeed, this is what I would use myself if I needed to format a unixtime 
string into a particular date format although I prefer %F myself ..

 $ perl -MPOSIX=strftime -le 'print strftime("%F", localtime())'
2005-01-07

%F is the equivalent of %Y-%m-%d which, according to the strftime 
manpage, is the ISO 8601 date format.


I've used this on occasion after returning values from Date::Parse, in 
order to insert the tested valid value in a database, later, but 
reformatted as the db expects to see it.

sub valid_birthday { #object-oriented method
$_[0]->get_birthday() and
return( str2time( $_[0]->{_birthday} ) );
return undef;
}
and once I have a true value returned from the valid_birthday method, I 
can format it with POSIX strftime into what the database expects to see, 
as opposed to whatever the user typed into the form.

It's simple, elegant things like this that make me happy. :)
--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Warning: Use of hash a reference is deprecated

2005-01-07 Thread Scott R. Godin
Alfred Vahau wrote:
10   my ($me, %hash )= @_;
11   my $type = %hash->{base_type};

In 10, is the structure of the hash preserved? What happens if you pass 
the hash by reference?
In 11, you are using the hash as a reference. What you want is something 
like:
In which case you would also want to use
  my ($me, $hashref) = @_;
my $type = $hashref->{base_type};
alfred,
Siegfried Heintze wrote:
I'm getting a warning on line 10 or 11. The program works. I'd like to 
get
rid of the warnings however. When I change "%hash" to "$hash" on lines 
10-11
then the program does not work at all then.

Thanks,
Siegfried

[snip]
  9 sub mfr {
 10   my ($me, %hash )= @_;
 11   my $type = %hash->{base_type};
 12   if ($type == &case_constants::btRankSuspects ){  13 return 
RA->new($type, @_); }
 14   elsif ($type == &case_constants::btCompareAssertions){  15 
return CA->new($type, @_); }
 16   elsif ($type == &case_constants::btCriminal){  17 return 
CR->new($type, @_); }
 18   elsif ($type == &case_constants::btEvidenceEvaluation){  19 
return EV->new($type, @_); }
 20   elsif ($type == &case_constants::btCivil){  21 return 
CI->new($type, @_); }
 22   else{  23 return Case->new($type, @_);  24   }
 25 }
 26 sub new {
 27   my $invocant = shift;
 28   my $class = ref($invocant) || $invocant;
 29   my $self = { @_ };
 30   bless($self, $class);
 31   return $self;
 32 }

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: GD isn't outputting image data

2005-01-08 Thread Scott R. Godin
JupiterHost.Net wrote:
hello list :)
Anyone have any idea why the last line doesn't print anything?
I get no errors and have eval'ed it with no errors. I've also tried with 
->png and ->jpeg also with the same results...

I think I'm doing it right according to 
http://search.cpan.org/~lds/GD-2.19/GD.pm

All it outputs is the header:
 $ ./gdtest.pl
 Content-type: image/gif
 $
Here's the code:
#!/usr/bin/perl
use strict;
use warnings;
use GD;
my $image = GD::Image->new(100,50);
my $white = $image->colorAllocate(255,255,255);
$image->transparent($white);
my $fontcolor = $image->colorAllocate(0,0,0);
my $font = GD::Font->Small();
print "Content-type: image/gif\n\n";
$image->string($font,2,10,'hello world',$fontcolor);
#$image->rotate90;
print $image->gif;
TIA!
make sure that GD and libgd were built with gif support.
you may also wish to use
binmode STDOUT;
before you print
--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: GD isn't outputting image data

2005-01-08 Thread Scott R. Godin
Owen wrote:
--insert---
	open (OUT,">GD.png");

my $img = $image->png;
	print OUT "$img";
--end insert---

It worked for me, try modifying the script a la above and see if it produces a GD.png file
indeed.
#!/usr/bin/perl
use warnings;
use strict;
use GD;
my $image = GD::Image->new(100,50);
my $white = $image->colorAllocate(128,128,255);
#$image->transparent($white);
my $fontcolor = $image->colorAllocate(0,0,0);
my $font = GD::Font->Small();
print "Content-type: image/png\n\n";
$image->string($font,2, 8,">hello world...",$fontcolor);
$image->string($font,2,20," Would you like",$fontcolor);
$image->string($font,2,32," to play a game?",$fontcolor);
my $img = $image->png or die "$!";
binmode STDOUT;
print $img;
apparently it's necessary to extract it to a scalar first; plus this way 
you can test for whether the method is supported in the compiled libgd 
and error if not,

$ perl gif.pl > gif.gif
libgd was not built with gif support
...propagated at gif.pl line 19.
or,
"The image 'http://localhost/cgi-bin/hello.cgi' cannot be displayed, 
because it contains errors."  ;) (yes that works, try it with the above 
code, which should work fine and display an image. :)

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: GD isn't outputting image data

2005-01-09 Thread Scott R. Godin
JupiterHost.Net wrote:

Scott R. Godin wrote:
Owen wrote:
--insert---
open (OUT,">GD.png");
my $img = $image->png;
print OUT "$img";
--end insert---


It worked for me, try modifying the script a la above and see if it 
produces a GD.png file

indeed.
#!/usr/bin/perl
use warnings;
use strict;
use GD;
my $image = GD::Image->new(100,50);
my $white = $image->colorAllocate(128,128,255);
#$image->transparent($white);
my $fontcolor = $image->colorAllocate(0,0,0);
my $font = GD::Font->Small();
print "Content-type: image/png\n\n";
$image->string($font,2, 8,">hello world...",$fontcolor);
$image->string($font,2,20," Would you like",$fontcolor);
$image->string($font,2,32," to play a game?",$fontcolor);
my $img = $image->png or die "$!";
binmode STDOUT;
print $img;
apparently it's necessary to extract it to a scalar first; plus this 
way you can test for whether the method is supported in the compiled 
libgd and error if not,

$ perl gif.pl > gif.gif
libgd was not built with gif support
...propagated at gif.pl line 19.

#!/usr/bin/perl
use strict;
use warnings;
use GD;
my $image = GD::Image->new(100,50);
my $white = $image->colorAllocate(255,255,255);
$image->transparent($white);
my $fontcolor = $image->colorAllocate(0,0,0);
my $font = GD::Font->Small();
$image->string($font,2,10,'hello world',$fontcolor);
my $png = $image->png or die $!;
err, you mean
or die "$!"
not
or die $!;
binmode STDOUT;
print $png;
$ ./gdtest.pl
No such file or directory at ./gdtest.pl line 15.
$
That is the $! on line 15 so it looks like we're getting closer ;p
I should've died before :)
So I'm assuming its a temp file of some kind, have to search teh guts 
more to find out what that means. Any ideas?
no, you made a typo
or,
"The image 'http://localhost/cgi-bin/hello.cgi' cannot be displayed, 
because it contains errors."  ;) (yes that works, try it with the 
above code, which should work fine and display an image. :)

Add a content type header and it will work in your browser :)
no, that error message is from when I tried gif, since I have libgd 
compiled without gif support

the script, as png, works PRECISELY as I pasted it, WITHOUT a 
content-type header, simply called directly as a url in the browser

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: GD isn't outputting image data

2005-01-09 Thread Scott R. Godin
JupiterHost.Net wrote:

$image->string($font,2,10,'hello world',$fontcolor);
my $png = $image->png or die $!;

err, you mean
or die "$!"
not
or die $!;

Why? Its redundant and ugly to double quote a string that is a single 
variable.
the quotes are there to prompt you to include a sensible error message 
there, in addition to the error, if you like. :P

As for the content type header, it may display in your browser but you 
should put a content type header so others browsers wonn't have to guess 
and there fore it will work for everyone :)
I wasn't embedding it in a webpage like so:
http://localhost/blah/cgi-bin/hello.cgi";>
I was literally calling it from the browser's URL line as a file, 
directly, in which case the content-type header was interfering with the 
browser's ability to display the image (which would have been obvious 
had you tried it, as I suggested.)

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: GD isn't outputting image data

2005-01-09 Thread Scott R. Godin
JupiterHost.Net wrote:
Very weird, still nothing :)
GD just isn't returning anything in any format, scalar or array 
context...


Well all a bit of a mystery.
su to root and do all that stuff again, maybe there is a permission 
problem on the files or on the directory.

Great idea! Still busted:
 root# ./gdtest.pl
 No such file or directory at ./gdtest.pl line 15.
 root#
I'll need to investigate the source and maybe redo gdlib and then GD.pm 
again.
is this the same gd_example.cgi that comes with GD.pm, in the demos dir 
of the package, or are you running the script we've pasted here for you?

Because I tried running gd_example.cgi as given, and got a similar error 
"no such file or directory" which makes no sense since we aren't opening 
any files or working with any files.

[Sun Jan 09 13:53:12 2005] [error] [client 127.0.0.1] (2)No such file or 
directory: exec of '/home/webadmin/madhouse/html/cgi-bin/gd_example.cgi' 
failed, referer: http://localhost/madhouse/bleh.htm
[Sun Jan 09 13:53:12 2005] [error] [client 127.0.0.1] Premature end of 
script headers: gd_example.cgi, referer: http://localhost/madhouse/bleh.htm

however it also occurs to me that gd_example.cgi points to
#!/usr/local/bin/perl
and not
#!/usr/bin/perl
which is where it's installed on my system, and fixing THAT to point to 
a perl that DOES exist, the script runs perfectly.

nothing whatsoever to do with temp files, or any such nonsense. the 
error makes complete and utter sense if you just think really hard about 
what makes sense and what doesn't about the error message.

the script doesn't open any files, so how could it give a 'no such file' 
error ? it's not printing a 'file' either, no, so toss that idea too.

and if GD were using tempfiles they'd be completely encapsulated by the 
GD object, and handled internally. If you got a 'no such file' error 
from GD itself, the script's die message would reflect that case and it 
would again be _obvious_ that it were GD's fault and not (pointedly) 
your own, or my own, or the gd-using-script-authors own, in pointing to 
a perl binary that 'does not exist' on this system.

use your head, man!
--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: CPAN

2005-01-10 Thread Scott R. Godin
Daniel wrote:
I made a mistake when setting up CPAN, I chose Central America as my
Continent, then the only option was to chose Costa Rica as my Country.
 Not that I have anything against Costa Rica, very lovely place will
visit soon, but would like a ftp server closer to my real home.  I
looked thru the h option and the perldocs, but cannot figure out how
to reload my info.  Please help!!
Daniel
fire up the cpan shell and enter
  o conf init
at the cpan> prompt (yes that's the letter o, not a bullet point)
--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Any call-response subscription packages available ?

2005-01-13 Thread Scott R. Godin
WebDragon wrote:
I'm curious to know if there are any generic call-response subscribe 
packages out there written in Perl (preferably object oriented in design)

i.e. what I am looking for is,
{
o  user subscribes via form on website, gives e-mail address and 
creates a password

o  user is sent a 'call' e-mail saying "you've just been subscribed. 
did you want this? if so, click this URL"

o  clicking the URL 'response' finishes the subscription process, 
and users data is then sent onward. user recieves a confirmation message 
as a result of their webclick both in the webpage itself and via e-mail, 
thanking them for joining.

o  eventually something is done to clean up the data for which there 
was no further 'response'.
}

I would like to have such a feature as part of a package I'm writing for 
this client, rather than just blindly accept the data and their choice 
of e-mail. That and I really hate to have to re-invent the wheel if 
something suitable is already available for use that has worked around 
some of the obvious problems involved with this issue.

There are several open source packages out there that implement such 
things but it is rarely something semi-separate from the package itself 
that can be easily extracted, genericised, and put to use elsewhere. I 
would prefer something that is 'the thing itself' and easily integrated 
further into whatever needs it. (rather than spending a few weeks 
stripping it out of whatever package I find that does it well enough to 
suit my needs, and refactoring it. ack! :)

If anyone has any information leading to such a thing, I would be most 
grateful. Surely someone has done this by now?
never saw a response to this, so I'm reposting once in the hopes that 
perhaps someone else will see it that has any recommendations.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: how to

2005-01-18 Thread Scott R. Godin
Juan Gomez wrote:
 
Good day 

 I am new to perl but I need a jump start to CGI so I have active perl 5.8.1
install in my pc 
Now a friend gave me a script that has a form and sends an email with the
data 
Now in his pc its working fine but when I try it in my pc did not work 


Is there some documentation about how to make it work from my computer???
Thanks
Hopefully this script is not one from Matt's Script Archive, but is in 
fact a drop-in replacement for those (which would be more secure and not 
prone to the bugs and hacking that matt's scripts are.)

see http://nms-cgi.sourceforge.net/
if you're simply sending e-mails from a form's submitted data, I'd use 
one of the scripts from the above source.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: More elegant solution for a date conversion

2005-01-21 Thread Scott R. Godin
Todd W wrote:
"Jason Balicki" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,
I've got a phone record that keeps the date and time
in the following format:
 YYMMDDHHMM
example:  0501201500
So, I've written the following to convert it to the
format:
 MM/DD/,HH:MM
example:  01/20/2005,15:00


This works, but strikes me as ugly.  Is there a more
elegant way of doing what I've done here?  It seems
like I should be able to loop through the $ardate[n]
entries and select them somehow instead of hard coding
the indexes, but nothing is coming to mind.

You want to use the C strptime finction. Theres several ways to use it
inside perl. I like Time::Piece:
[EMAIL PROTECTED] trwww]$ perl
use warnings;
use strict;
use Time::Piece;
my $time = Time::Piece->strptime('0501201500','%y%m%d%H%M');
print $time->datetime, "\n";
Ctrl-D
2005-01-20T15:00:00
Install and read the docs for Time::Piece.
Nice, Todd, I'd forgotten about that one.
I would like to add one thing however; that it might be preferable to 
-MM-DD,HH:MM the time unless you for whatever reasons will only be 
using the converted date for display purposes and not sorting purposes 
once it's been reformatted to your liking. Additionally, this format is 
not ambiguous to those from other countries who sometimes write DD/MM/YY 
or MM/DD/YY and may mis-read the dates there. YYYY-MM-DD is a well known 
format that disambiguates this confusion.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



TERM::ReadLine and program flow question

2005-02-08 Thread Scott R. Godin
This is my first time attempting to use Term::ReadLine to get input from 
the commandline while a script is running. I grok the basics of it, but 
am stumbling over the implementation of it. Let me illustrate:

READLINE:
{
# closure, so I don't have to either
#   -  call Term::ReadLine->new() every time thru the sub, or
#   -  pass the object to the sub every time thru
# this way it gets called _once_, period, and I don't have to think
# about it later
my $term = Term::ReadLine->new();
sub get_input ($;$) {
my($descr, $default) = @_;
croak "No description specified for input"
unless $descr;
$default ||= '';
my $result = $term->readline("$descr [$default]: ") || $default;
return $result;
}
}
my(%input, $default);
$default = sub {
foreach ("$ENV{HOME}/public_html", "$ENV{HOME}/html", 
"$ENV{HOME}/www") {
return $_ if -e && -d _;
}
};

while ( get_input "What is the full path to the directory containing\
your website .html files", $default->() ) {
print && next unless $_; #DEBUG
print "nonexistent: $_" && next unless -d ;
print "not readable: $_", next unless -r;
die  "directory not writable by this process. check permissions on: 
$_" unless -w;
$input{htdocs} = $_;
}

now, eventually what I'm aiming at is a way to sort of batch-process 
thru a bunch of queries, but I'll worry about that part later. Just 
trying to get this small bit working how I'd expect it to.

What's wrong with the way outlined above is that $_ isn't being set, so 
the DEBUG print gets an undefined value.

if I use
	while (local $_ = get_input ... ) {
(or some variant of
	while (my $var = get_input...) {
)
then the conditionals don't get checked if the user presses return on an 
empty default.

My brain seems frozen today. How do I ensure that the input loop will 
continue if the value is not defined, and test the values if they are ? 
I'm guessing a continue block but I can't seem to wrap my brain around 
the problem today. I should KNOW this, dammit! It's killing me that I 
can't figure it out, and I'm sure it'll be obvious in retrospect.

should I even be using 'while' here?
--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: TERM::ReadLine and program flow question

2005-02-08 Thread Scott R. Godin
Philipp Traeder wrote:
On Tuesday 08 February 2005 18:57, Scott R. Godin wrote:
This is my first time attempting to use Term::ReadLine to get input from
the commandline while a script is running. I grok the basics of it, but
am stumbling over the implementation of it. Let me illustrate:
READLINE:
{
# closure, so I don't have to either
#   -  call Term::ReadLine->new() every time thru the sub, or
#   -  pass the object to the sub every time thru
# this way it gets called _once_, period, and I don't have to think
# about it later
my $term = Term::ReadLine->new();
sub get_input ($;$) {
[..]
}
}
[..]
while ( get_input "What is the full path to the directory containing\
your website .html files", $default->() ) {
print && next unless $_; #DEBUG
print "nonexistent: $_" && next unless -d ;
print "not readable: $_", next unless -r;
die  "directory not writable by this process. check permissions on:
$_" unless -w;
$input{htdocs} = $_;
}
[..]
My brain seems frozen today. How do I ensure that the input loop will
continue if the value is not defined, and test the values if they are ?
I'm guessing a continue block but I can't seem to wrap my brain around
the problem today. I should KNOW this, dammit! It's killing me that I
can't figure it out, and I'm sure it'll be obvious in retrospect.
should I even be using 'while' here?

I would say 'no' to this one ;-)
Why do you need a loop here? The way you've written your get_input() method, 
you'll always get a return value - either the one from the user, or a default 
value. Even if you implement a query without return value, your directory 
checks will catch it because "-d undef" returns 0, so the user would get the 
message "nonexistent: " if he enters no value for a question without default 
value, which is more or less correc.t

Maybe I didn't get the point, but I would probably write it like this:
[...]
$term = Term::ReadLine->new();
$_ = get_input "What is the full path to the directory containing your \ 
website .html files", $default->();
die "nonexistent: $_" unless -d;
die "not readable: $_" unless -r;
die "directory not writable by this process. check permissions on: $_" unless 
-w;
print "ok - got $_\n";
$input{htdocs} = $_;
and that's sorta fine except I'll have other different circumstances as 
well..

there will be instances where I cannot provide a default (Guess I should 
have made this clearer earlier... *smacks forehead*), such as username, 
password, etc.

and, on the off chance that my 'default' sub turns up returning undef 
(I'm unable to guess what their correct dir location might be), there 
won't be a default, in which case if they mistakenly press return, I get 
an undef value, which the sub converts to '' ..

that's all fine and dandy but I don't want to make the user re-run the 
script several times whenever he supplies bad input. I would prefer that 
it ask the question again until it gets a value it can use. (perhaps 
providing a 'sorry I didn't understand that.." message if they provide a 
null value, or the default doesn't exist for some reason.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Processing a string containing an HTML response.

2005-02-08 Thread Scott R. Godin
Philip Tham wrote:
Hi
I am using LWP to send an HTTP Get and I receive the http response in
 a variable which I named resp.
I would like to process the string resp->content token by token and 
modify the output.

I see that HTML::TokeParser allows for this kind of processing but I
have to read the input from a file. However in my case I have the 
entire hmtl response in a string.

What library should I use for this purpose.
Philip
I wrote (for practice with OO) a WWW::Mechanize object for parsing 
TinyURL's website for the results of a form input, MOSTLY by using 
Data::Dumper on the WWW::Mechanize object to see what it contained after 
each step I worked thru. This led me to HTTP::Response, and 
HTML::TokeParser readily enough, and fiddling with those got me what I 
wanted.

It's VERY simple, and I'd posted it at
	http://www.webdragon.net/miscel/tinyurl.htm
to share with a friend at the time I finished it. Feel free to cadge, if 
you find it useful as an example reference.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Get list of available modules?

2003-03-03 Thread Scott R. Godin
Dave K wrote:

> 
>> Greetings!
> Hello
>>
>> I'm trying to do some Perl for a non-profit organization.  The computer
>> administrator doesn't know very much about Perl or about the server.
>> If I were to ask him what Perl modules were available, he'd probably
>> just have to call somebody else and get back to me.  Is there any way
>> to use Perl to generate a list of such modules for me?
> I was hoping to get some feedback on the following. Let me know what you
> think.
> 
> #!/usr/bin/perl -w
> use ExtUtils::Installed;
> my $instmod = ExtUtils::Installed->new();
> foreach my $module ($instmod->modules()) {
>  my $version = $instmod->version($module) || "???";
>  print "$module -- $version\n";
> }

I've scripted up a fancier way of doing this, for when you're interested in 
seeing the groupings, and updating lots of modules in one go, as well as 
seeing which packages they belong to.

It's somewhat similar to entering 'r' in the CPAN shell, but gives you the 
full list of installed modules, versions (installed/CPAN) and the package 
name, rather than just the list of outdated modules. 

Full information, sample output, and a copy of the script is available here: 

http://www.webdragon.net/mr/

Currently it's designed to be run on Linux/Unix workstations, but is not 
currently portable to other OS's. I'd originally done it on the Macintosh 
using MacPerl, but have since evolved it a tad. I've been wondering about 
when I'd get some tuits to complete the cross-platform compatibility stuff. 
:o) 


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



Re: unsubscribing.... [OT]

2003-03-03 Thread Scott R. Godin
Todd W wrote:

> 
> "Paul" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> This is too fun, and so occupies far to much of what should otherwise
>> be a productive workday.
>>
>> Alas, I must unsubscribe again.
>>
>> *sigh*
>>
>> Later, all. :)
>>
> 
> You can point your news reader to nntp.perl.org and keep your mailbox
> uncluttered, but then theres even MORE messages to read/reply to =0)


Yes, definitely the preferred method.. you can 'expire' messages after a few 
days of not being read, so that there's not *quite* so much to catch up on 
if you're away for a week or two doing RL(tm) things :) 

Of course, the uncluttered mailbox is the best method. 

Plus this helps to reduce the amount of "false threads" where new users tend 
to "reply" to the mailing list and then create a completely new message 
that has a message-id header [References: ] referring to the previous post 
(which messes with threaded newsreaders something fierce) 

In other words, if I see a topic I have no interest in, I tend to mark the 
whole thread as READ. If you "replied" to one of these posts, instead of 
starting a NEW thread for your NEW topic by creating a NEW message and 
addressing it to the list accordingly, then your message would never be 
seen by me. I see this way too much here, and strongly advocate the 
newsreader approach for this reason. =]


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



Re: Blacklist an array

2003-03-03 Thread Scott R. Godin
Philipp Gruemmer wrote:

> A small correction (thanks to Carlos Diaz)
> 
>> Isn't shis code supposed to read the first line of the @input array then
>> read the first line of the @blacklist array, see if the $line contains a
>> $cond and then ptrint "true". After that it should carry on with the
>> second line from both arrays
> 
> I want every line of the @input array to be checked with all the lines
> from the @blacklist array.
> 
> Get first line from @input
> Cycle through @blacklist -> If sth. matches, do something
> Get second line from @input
> Cycle through @blacklist -> If sth. matches, do something
> [...etc...]
> 
> 
> Greeting, philipp

You could try playing with Quantum::Superpositions

I've got a small test case I love showing people who know C/C++, to show how 
two arrays can be compared for missing items without using a nested loop. 

observe: 

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

my @Array1 = qw(cat dog mouse rat); 
my @Array2 = qw(mouse bird rat snake);

print "\nArray 1 contains: @Array1\n",
"Array 2 contains: @Array2\n\n";

print<<"END";
hmm. how to find out which elements from one array are missing from the 
other without doing nested loops? aha! Quantum Mechanics! 

END

use Quantum::Superpositions;

my @notinarray1 = 
map { $_ }  
eigenstates( any(@Array2) ne all(@Array1) );

my @notinarray2 =
map { $_ }  
eigenstates( any(@Array1) ne all(@Array2) );

print "@notinarray1:  not found in Array 1\n",
  "@notinarray2:  not found in Array 2\n";

__END__

Quantum::Superpositions requires Class::Multimethods.

I haven't played much with this regarding regular expression matching rather 
than string matching. Feel free to contact the current maintainer if you 
run into problems. 

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



Re: How do I recursively look in every directory

2003-03-03 Thread Scott R. Godin
Randal L. Schwartz wrote:

[snip]

> John> Use the File::Find module.
> 
> John> perldoc File::Find
> 
> I have many examples of this module (including a two-parter that
> recently appeared in Linux Magazine) on my site.  Google
> for
> 
>   site:stonehenge.com "File::Find"
> 
> for the examples.  43 hits at the moment.
> 

Heya Randal! :)

Enjoyed the article -- found a few interesting ways to fiddle with 
File::Find that I wasn't previously aware of. 

Just FYI, you are the SOLE reason I still read Linux Magazine. I've recently 
discovered Linux Format (http://www.linuxformat.co.uk/) and have found the 
breadth and depth of articles there to be MUCH more in line with where I'm 
headed in educating myself about Linux. The contents of Linux Magazine 
generally seem to be very very very sparse in comparison. 

As a potential topic for articles, have you fiddled with 
Quantum::Superpositions at all? I'd love to see some more interesting ways 
of twisting things using this module than what I've been previously playing 
with. :-)

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



Re: Newby first little script. (Lots of errors and wrong ways of doing things)

2003-03-03 Thread Scott R. Godin
Johann Snyman wrote:

> Hello there,
> 
> I am a newby trying to learn pearl. I wrote my first little script,
> and I would love to se where I could have done things better (in a
> more proffesional way).
> 
> Feedback would be appreciated!

Well you are off to a good start with lines two and three ;) 

> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> our @scores = `cat /home/johann/smail/Spam/* | grep ^Subject:` ;
> # string looks like this: Subject: 10.20 Re: Hallo

Good, commenting your code is a good thing :) 

However backticks aren't the only way or always the best way ... In this 
case it's not a bad usage, but always be aware of when it COULD be. Reading 
perldoc perlsec is a good place to observe some security issues. (Running 
this under -T isn't a bad idea either.)

observe: 

my @scores;
my @files = glob "/home/johann/smail/Spam/*";
foreach my $file (@files) {
open(IN, "<", $file) or die "Cannot open file $file: $!";
while () {
next unless /^Subject:/;
push @scores, $_;
last; # found what we need, no need to go further with this file
}
close IN or die "Cannot close filehandle for $file: $!";
}

> our @vals;
> our $counter = 0;

no need to make these globals.. this will do: 

my($counter, @vals);

> for (@scores) {
>   $_ =~ /([0-9][0-9]\.[0-9][0-9])/;
>   $vals[$counter] = $1;
>   $counter++;
>   }

# and in fact, you don't need $counter at all...
foreach my $score (@scores) {
# this avoids problems in the case of the regex NOT matching
unless ($score =~ /\s([\d]+\.[\d]+)\s/) {# assumes score is space-delimited
warn "$score did not match!";
next;
}
push @vals, $1; 
}
  
> my $saved = `cat /home/johann/.spamscore` || die $!;
> chomp($saved);
> push @vals, $saved;

open IN, "<", "/home/johann/.spamscore" 
or die "Cannot open .spamscore file: $!";
while () {
chomp;
push @vals, $_ if $_;
}
close IN or die "Could not close .spamscore file: $!";


> @scores = sort(@vals);
> #for (@scores) {
>#  print $_,"\n";
> #   }

re-using the same array to describe something different isn't always a good 
idea. rather,

my @newscores = sort @vals;

#this is also an easier way of writing the above debugging check ;) 
#print "$_\n" foreach @newscores;

> my $highest = @scores;
> $highest -= 1;

why not just do: 

#my $highest = $#newscores;
#although you don't need to... see below :)

> open (FH, ">/home/johann/.spamscore") || die $!;
> 
> print FH $scores[$highest];
> 
> close(FH);

this is ok, but again, 

open FH, ">", "/home/johann/.spamscore" 
or die "Cannot open .spamscore for writing!: $!";
print FH $newscores[$#newscores];
close FH or die "Cannot close output file .spamscore: $!";


> __END__
> 
> 
> Thanks!
> 

useful [descriptive] die error messages can help debug things much more 
easily. 

This help any? 

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



Re: Blacklist an array

2003-03-04 Thread Scott R. Godin
John W. Krahn wrote:

> "Scott R. Godin" wrote:
>> 
>> use Quantum::Superpositions;
>> 
>> my @notinarray1 =
>> map { $_ }
>   ^^
> 
>> eigenstates( any(@Array2) ne all(@Array1) );
>> 
>> my @notinarray2 =
>> map { $_ }
>   ^^
> 
>> eigenstates( any(@Array1) ne all(@Array2) );
> 
> The map operator in this instance is not doing anything except slow down
> the code.


True, but illustrates how to easily further affect the results enroute to 
@notinarray.. could be valuable to a newcomer :)



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



Re: Newby first little script. (Lots of errors and wrong ways of doing things)

2003-03-04 Thread Scott R. Godin
George P. wrote:

> I noticed that you've said
> "open () or die()"
> and
> "close() or die()"
> 
> If open fails, the program will kill itself, so the close function
> will never be called.
> Therefore there is no need to say "close() or die()"

not true.

> You've done it thrice in this email, so I'm presuming
> that it's a habitual thing.
> 
> Putting it won't hurt, but it's not useful either.
> 
> Just thought I should point it out :)


The simple answer is: Good programming practice. 

What if something happens to the file before I'm able to close the 
filehandle? 

This has implications beyond the simple example shown here, and consequently 
I've made it a force of habit to always check success of certain operations 
as a matter of course. 

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



Re: Newby first little script. (Lots of errors and wrong ways of doing things)

2003-03-04 Thread Scott R. Godin
George P. wrote:

[snip]
>> > I noticed that you've said
>> > "open () or die()"
>> > and
>> > "close() or die()"
>> >
>> > If open fails, the program will kill itself, so 
>> > the close function will never be called.
>> > Therefore there is no need to say "close() or die()"
>>
>> I don't follow this logic.
>>
[snip]
>> If you are saying that because the file was successfully opened the close
>> cannot fail, then this is not correct.  Now, it might not fail very
>> often, and even when it does you might not care, but then again you
>> might, and I normally do.  If something goes wrong, I like to know 
>> about it.

I do too. ;-)

> I can't think of any instance when open() will return a true value
> and still fail to open an handle to the file.

This is neither the point you originally made, nor is it the statement made 
by the above gentleman. You've managed to confuse _yourself_ at this point. 

if open returns a true value it won't fail to open the file (since it's 
already opened the file). no one disputed that.

HOWEVER, once the file is open, any number of things could occur that could 
potentially cause a close() to fail. so, we test for that, too. If 
something goes wrong on that end, I like my programs to die also, and print 
me a useful error message advising me of the problem so I can go look and 
see what happened. 

I will say that there is a small error in my version of the script that I 
chose to make, in that it doesn't test for multiple instances of 
/^Subject:/ but instead skips the remainder of the file upon finding the 
first one. This is to save time, but it IS based on an (possibly false) 
assumption. The likelihood is very small though. :-)

When you've read enough posts here on nntp.perl.org:perl.beginners and on 
usenet:comp.lang.perl.misc and seen how many professional perl programmers 
recommend doing certain things, you quite sensibly get in the habit of 
doing them. 

I didn't have to do an explicit close in this case thanks to the loop the 
open() call was in, however I ALSO chose to do so, because when training a 
new person (the original poster is a self-admitted newbie :), one hopes to 
train them to do things RIGHT, even if the code winds up a tad long-winded. 
Let them learn the shortcuts as they go on. i.e. "as you get used to this, 
you can effectively leave this part out, but it's good for you to know that 
it needs to be done, and tested sometimes." 

It's good programming practice to test these things. period. :)

Just because a file opened successfully doesn't mean that it will always 
close successfully as well. hard drive implosion. network outage. you name 
it. Q.E.D.

'nuff said.

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



RE: Simple script requires simple soulution

2003-03-05 Thread Scott R. Godin
Aimal Pashtoonmal wrote:

> Hello,
> 
> I have the script below giving the folowing error meesages.
> 
> =>Useless use of string in void context at
>   extract_data_from_IPR_HMM_libs.pl
>  line 12.
> =>Useless use of a constant in void context at
>  extract_data_from_IPR_HMM_libs.pl line 13.
> 
> Even though the script works and I get the desired output, what is
> causing these messages?
> 
> Also, does anyone know how I introduce a blank line. The script starts
> printing out beginning with NAME on the first line. I am trying to get a
> blank before every NAME line except the very for first.
> 
> cheers.
> 
> _SCRIPT_
> #!/usr/bin/perl -w
> 
> use strict;
> 
> 
> my $infile = $ARGV[0];
> my $dataread;
> my $line;
> my $dbsize;
> 
> 
> open(INFILE, $infile) || "unable to open file $infile: $! \n";
> open(OFILE, ">$infile.HMMdata") || "couldnt open output file";

right here: 


open(INFILE, "<", $infile) 
or die "unable to open file $infile: $!";
open(OFILE, ">", "$infile.HMMdata") 
or die "couldnt open output file $infile.HMMdata: $!";

> while ($line = ) {
>  $dbsize++ if ( $line =~ /^HMMER/ );
>  $dataread = 1 if ( $line =~ /NAME\s/ );
>  $dataread = 0 if ( $line =~ /^HMM\s/ );
> 
>  print  "$line" if $dataread;
> }
> 
> print "Database size for $infile = $dbsize\n";
> 
> close INFILE;
> close OFILE;

it's also good programming practice to test close events as well, ala: 

close INFILE or die "Unable to close filehandle for $infile: $!";
etc...

> exit;

the script falls off the end here.  no reason to explicitly call exit at 
this point. it's redundant. 

> _END_



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



Re: Commands inside a reg-ex substitution problems

2003-03-06 Thread Scott R. Godin
John W. Krahn wrote:

>> ($_pattern, $_start) = (shift, shift);
>> print "Starting search at: $_start\n";
>> 
>> chdir "$_start";
> 
> Useless use of quotes.  You should verify that chdir worked.
> 
> unless ( chdir $_start ) {
> print STDERR "Cannot chdir to $_start: $!";
> exit 1;
> }
> 
> 
>> opendir (DIR, "$_start");
> 
> Useless use of quotes.  You should verify that opendir worked.
> 
> unless ( opendir( DIR, $_start ) ) {
> print STDERR "Cannot open $_start: $!";
> exit 1;
> }
> 
> 

die "Cannot chdir to $_start: $!"
unless chdir($_start);

die "Cannot open directory $_start: $!"
unless opendir(DIR, $_start);

:-)


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



Re: Simple Regex Problem.

2003-03-07 Thread Scott R. Godin
David wrote:

> Gregg R . Allen wrote:
> 
>> It was close but what I got is : "JohnDoe.com"  Instead of
>> "[EMAIL PROTECTED]".
>> 
>> I think it has something to do with escaping the "@" sign.  I've been
>> experimenting, but without much luck.
>> 
> 
> that's because Perl thinks @Someplace is an array. if you have warning
> enable, Perl will probably tell you that @Someplace is undef. either put
> the string in single quote like:
> 
> '[EMAIL PROTECTED]'
> 
> or escape the @ character like:
> 
> "[EMAIL PROTECTED]'
> 
> and apply your reg. exp again.


and add 

use warnings;
use strict;

to every program you write. period.

This will help you catch a LOT of oddball errors that aren't obvious from 
just looking at the code.

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



Re: Simple Regex Problem.

2003-03-07 Thread Scott R. Godin
Rob Dixon wrote:

> Paul Johnson wrote:
>> Rob Dixon said:
>>
>> > $data =~ m/ <([^>]*)> /x;
>> > my $newdata = $1;
>>
>> And if the match fails?
> 
> Well I think it's likely that you'd want to do:
> 
> $data =~ m/ <([^>]*)> /x or die "Malformed data";
> 
> or at least:
> 
> $data =~ m/ <([^>]*)> /x or next;
> 
> as a mismatch inmplies that something's happening that
> you don't expect. But you're quite right, I should have
> pointed out that $1 etc. are 'sticky' and will keep their
> values from the last successful match. I'll go for:
> 
> {
> my $newdata;
> $newdata = $1 if $data =~ m/ <([^>]*)> /x;
> :
> }
> 
> Rob

you want to know what's failing, right? 

unless ($data =~ m/ <([^>]*)> /x) {
warn "## Error matching regex in '$data'";
next;
}
$newdata = $1;



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



Re: Module listing

2003-03-07 Thread Scott R. Godin
Rob wrote:

> Is there a perl command to list installed modules?

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

foreach my $mod ( sort CPAN::Shell->expand("Module","/./") )
{
next unless $mod->inst_file;
print $mod->id;
print ": ", $mod->inst_version 
if $mod->inst_version;
print "\n";
}

perhaps a little different from ExtUtils::Installed, but this is what Perl 
is all about.. TMTOWTDI :)

I've also written a little module reporting script that expands on this 
idea; checking CPAN and producing a nice report of installed modules and 
versions. 

http://www.webdragon.net/mr/

currently it requires a unix/linux OS, though. I haven't gotten around to 
making it fully cross-platform. 

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



RE: cpan problems

2003-03-07 Thread Scott R. Godin
Dan Muey wrote:

> I've also had trouble using CPAN and so I did the reload index
> mentioned in this thread and that seemed to go thought but I s
> til can't get it to go.
> 
> It's the same error everytime ( diff module names of course ) :: could not
> open y... There is a direct
> perl -MCAPN =e shell;
> CPAN> install Bundel::CPAN
> 
> ...
> cannot open y/sources/authors/id/A/AN/ANDK/CPAN-1.70.tar.gz: no such file
> Could not open >y/build/ANDK000/Makefile.PL at
> /usr/libdata/perl/5.00503/CPAN.pm line 3642
> 
> I'm root when I do this.
> Do I need to be in a special directory when I do it? ( I also tried it in
> root's home directory, same thing )
> 
> Permissions ::
> ([EMAIL PROTECTED](~/perl_cpan_mod ):120)# ls -al y/
> total 8
> drwxr-xr-x  4 root  wheel  512 Mar  5 11:11 .
> drwxr-xr-x  3 root  wheel  512 Mar  5 11:10 ..
> drwxr-xr-x  2 root  wheel  512 Mar  5 11:11 build
> drwxr-xr-x  4 root  wheel  512 Mar  5 11:10 sources
> ([EMAIL PROTECTED](~/perl_cpan_mod ):121)#
> 
> Or whatelse could I be fumbling up ??
> 
> Thanks
> 
> Dan
> 
> -- DETAILS --
> 
> ([EMAIL PROTECTED](/home/dmuey):101)# perl -MCPAN -e shell;
> 
> cpan shell -- CPAN exploration and modules installation (v1.48)
> ReadLine support available (try ``install Bundle::CPAN'')
> 
> cpan> relaod index
> Unknown command 'relaod'. Type ? for help.
> 
> cpan> reload index
> CPAN: LWP::UserAgent loaded ok
> Fetching with LWP:
>   ftp://mirrors.phenominet.com/pub/CPAN/authors/01mailrc.txt.gz
> Going to read y/sources/authors/01mailrc.txt.gz
> CPAN: Compress::Zlib loaded ok
> Fetching with LWP:
>   ftp://mirrors.phenominet.com/pub/CPAN/modules/02packages.details.txt.gz
> Going to read y/sources/modules/02packages.details.txt.gz
> Scanning cache y/build for sizes
> 
>   There's a new CPAN.pm version (v1.70) available!
>   You might want to try
> install Bundle::CPAN
> reload cpan
>   without quitting the current session. It should be a seamless upgrade
>   while we are running...
> 
> Fetching with LWP:
>   ftp://mirrors.phenominet.com/pub/CPAN/modules/03modlist.data.gz
> Going to read y/sources/modules/03modlist.data.gz
> 
> cpan> install Bundle::CPAN
> Fetching with LWP:
>   
ftp://mirrors.phenominet.com/pub/CPAN/authors/id/A/AN/ANDK/CPAN-1.70.tar.gz
> 
>   CPAN: MD5 security checks disabled because MD5 not installed.
>   Please consider installing the MD5 module.
> 
> cannot open y/sources/authors/id/A/AN/ANDK/CPAN-1.70.tar.gz: no such file
> Could not open >y/build/ANDK000/Makefile.PL at
> /usr/libdata/perl/5.00503/CPAN.pm line 3642
> 
> cpan> exit
> Lockfile removed.
> ([EMAIL PROTECTED](/home/dmuey):102)#
> 
> --- end details ---


you could try doing 

install CPAN

instead of 

install Bundle::CPAN

and see if that works. I normally skip the Bundle myself and just install 
only the modules that require updating. 

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



RE: cpan problems

2003-03-07 Thread Scott R. Godin
Dan Muey wrote:


>> ([EMAIL PROTECTED](/home/dmuey):101)# perl -MCPAN -e shell;
>> 
>> cpan shell -- CPAN exploration and modules installation
>> (v1.48) ReadLine support available (try ``install Bundle::CPAN'')
>> 
>> cpan> relaod index
>> Unknown command 'relaod'. Type ? for help.
>> 
>> cpan> reload index
>> CPAN: LWP::UserAgent loaded ok
>> Fetching with LWP:
>>   ftp://mirrors.phenominet.com/pub/CPAN/authors/01mailrc.txt.gz
>> Going to read y/sources/authors/01mailrc.txt.gz
>> CPAN: Compress::Zlib loaded ok
>> Fetching with LWP:
>>   
>> ftp://mirrors.phenominet.com/pub/CPAN/modules/02packages.detai
> ls.txt.gz
> Going to read y/sources/modules/02packages.details.txt.gz
> Scanning cache y/build for sizes
> 
>   There's a new CPAN.pm version (v1.70) available!
>   You might want to try
> install Bundle::CPAN
> reload cpan
>   without quitting the current session. It should be a seamless upgrade
>   while we are running...
> 
> Fetching with LWP:
>   ftp://mirrors.phenominet.com/pub/CPAN/modules/03modlist.data.gz
> Going to read y/sources/modules/03modlist.data.gz
> 
> cpan> install Bundle::CPAN
> Fetching with LWP:
>   
ftp://mirrors.phenominet.com/pub/CPAN/authors/id/A/AN/ANDK/CPAN-1.70.tar.gz
> 
>   CPAN: MD5 security checks disabled because MD5 not installed.
>   Please consider installing the MD5 module.
> 
> cannot open y/sources/authors/id/A/AN/ANDK/CPAN-1.70.tar.gz: no such file
> Could not open >y/build/ANDK000/Makefile.PL at
> /usr/libdata/perl/5.00503/CPAN.pm line 3642
> 
> cpan> exit
> Lockfile removed.
> ([EMAIL PROTECTED](/home/dmuey):102)#
> 
> --- end details ---
> 

You know, as I look at this again, it *appears* as though you answered "y" 
to a question that would normally invite some sort of OTHER typing.

try doing a 

 o conf

in the CPAN shell to see what entry has a weird value like "y" in it..

if there is one, try re-running

o conf init

over agan, and be more careful in what you type :)



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



Re: special caracters in variables in patternmatching

2003-03-07 Thread Scott R. Godin
Francesco Del Vecchio wrote:

> suppose this:
> ==
> $string 'I saw Roger and I said :roger? what the @*$!';
> 
> $var1 = "roger? what the @*$!";
> $var2 = "Hi roger...nice to meet you";
> 
> $string=~ s/$var1/$var2/;
> ===
> 
> I'm having problemsdue (i suppose) to the special chars in the $var1
> string the s/// don't match anything.
> What can I do to?
> 
> thanx
> Francesco


Two things:

First, it's better if you post to the list by NOT replying to someone else's 
post. When you do this, it references the previous post via the message-id, 
and appears threaded below a post with a completely different Subject line. 
If you are starting a completely new thread, don't reply .. just create a 
new e-mail to the list address. 

(the problem with the above is that if I "mark the thread as 'read'", your 
post gets ignored, and I never see it since it's buried below the other 
thread's subject.)

On to your question. 

s{\Q$var1\E}{$var2} is usually what you want, except that may very well 
'quote' out the $ in $var. 

I suspect what you really want is 

$var1 = qr{roger? what the @*$!};

( perldoc -f qr ) (perldoc perlre) and (perldoc perlop) for more details. 

I'd also recommend you add 

use warnings; 
use strict; 

to the top of every script you write. This will catch a LOT of potential 
mess-ups that would be hard to find otherwise. 

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



Re: Simple Regex Problem.

2003-03-08 Thread Scott R. Godin
Rob Dixon wrote:

>> you want to know what's failing, right?
> 
> Wrong. John was just pointing out that $1 would remain
> defined from a previous regex match in my previous post.
> This would mean that there was no way of telling in
> retrospect if the match had suceeded. The context of
> the problem was vague anyway, and I was supposing that
> the match in question would be within a 'while' block.

ok. and yeah, it depends on what you're looping around :)

> My solution above leaves $newdata undefined if the
> match fails, and is a better generalisation as the
> surrounding code has all the information it could
> need (including the original $data value).

right same as the below, however in the case of my suggestion, I regularly 
do this sort of thing during testing phases to determine if the data-set 
contains any unexpected data I need to know about. :-) 

>> unless ($data =~ m/ <([^>]*)> /x) {
>> warn "## Error matching regex in '$data'";
>> next;
>> }
>> $newdata = $1;
> 
> This is the same as one of my musings above:
> 
> $data =~ m/ <([^>]*)> /x or next;
> 
> apart from the warning call.

right. except if you want that to work I'd recommend getting in the habit of 
doing the following, which can be particularly important if you are 
extracting multiple matches to different variables

($data) = ~ m/\s<([^>]*)>\s/x or next;

It's also not a bad idea to get in the habit of being explicit about 
whitespace (via \s) as Perl 6 regular expressions will ignore whitespace by 
default. Get in the habit now, and you won't have to re-learn and re-train 
yourself later. :)

(cue the ominous foreshadowing music) 

...

Cheers,


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



Re: tnx to Scott Godin

2003-03-08 Thread Scott R. Godin
Francesco Del Vecchio wrote:

> First, I'm really sorry...I didn't want to send you a personal email...I
> pushed Reply instead of Reply All

Well, you didn't send me a personal mail.. it did go to the list. I read 
this group via a newsreader application so the mail doesn't fill up my 
mailbox. It's much easier this way for me to keep up. 

What you DID do, however, was *reply* to the list, but *starting a new 
topic* !

This threads your NEW post below a previous post with a TOTALLY different 
topic. Anyone ignoring the previous topic and "marking it read" with a 
newsreader or threaded e-mail app, would never see your NEW topic since 
it's buried below the other one, outline-fashion. 

if you're creating a New post, don't REPLY to the list. COMPOSE a NEW 
message, and type in the list's address, and then create your new Subject: 
line. ;-)

does this make any sense or should I e-mail you a screenshot of what I mean 
so you can *see* it ? :)

> Second, Scott...you are great!...I solved my problem with your suggestion.
> Thank a lot...this is a great mailing list!!!

Wheee, glad I was able to help :) 

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



Re: special caracters in variables in patternmatching

2003-03-08 Thread Scott R. Godin
Rob Dixon wrote:

>> > I'm having problemsdue (i suppose) to the special chars in the
>> > $var1 string the s/// don't match anything.
>> > What can I do to?
>>
>> s{\Q$var1\E}{$var2} is usually what you want, except that may very
>> well 'quote' out the $ in $var.
> 
> I guess you mean $var2? The replacement expression will
> only be interpolated once. Any variable names embedded in the
> contents of $var2 will be copied verbatim.

no, I meant $var1 there 

>> I suspect what you really want is
>>
>> $var1 = qr{roger? what the @*$!};
> 
> This won't work, I'm afraid. The $! will be interpolated
> unless the delimiters are single-quotes:

oh duh. That's what I get for not *(testing testing testing)* before I 
posted. :-P bleah. thanks for pointing that out. :)
 
> print (my $var1 = qr{roger? what the @*$!});
> 
> output
> 
> (?-xism:roger? what the @*)
> 
>> ( perldoc -f qr ) (perldoc perlre) and (perldoc perlop) for more
>> details.
> 
> Maybe what is wanted is:
> 
> $var1 = quotemeta q{roger? what the @*$!};
> 
> which is the equivalent of the \Q...\E construct, but
> applicable to an existing string.
> 
> HTH,
> 
> Rob


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



Re: Help! What am I doing wrong?

2003-03-08 Thread Scott R. Godin

>> foreach $AddrToCheck (@AddrArray) {
> 
> Beware that at this point you may well still have newlines
> at the end of each record. Make sure you have 'chomp'ed
> each record, otherwise it won't validate as an email
> address.
> 
> Also, the easiest way to put all the lines from a file
> into an array is this:
> 
> open EMAILS, "emails.txt" or die $!;
> my @AddrArray = ;
> close EMAILS;
> chomp @AddrArray;
> 
> HTH,
> 
> Rob

chomp(my @addr = );

:-) 


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



Re: Test for empty list

2003-03-08 Thread Scott R. Godin

> #!/usr/bin/perl -w
> 
> use strict;
> 
> my @array = ('', 0, "", 1);
> 
> my $hasTruth;
> foreach (@array) {
>   if ($_ ){
> $hasTruth = "yezzindeedydo!";
> last;
>   }
> }
> if ($hasTruth) {print "$hasTruth has truth\n";}
> else {print "Does not have truth";}
> 
> 
> Joseph

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

my @array = ('', 0, "", 1);

foreach (@array) {
print $_ ? "$_ has truth\n" : "$_ has no truth\n;
}


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



Re: print output from HTML::Parser

2003-03-08 Thread Scott R. Godin
Steven Massey wrote:

> Hi all
> 
> perl script below works, and does what I hoped it would, but I don't seem
> to understand how to get it to print out the result to a new file as
> opposed to stdout.
> 
> Thanks for any help
> 
> #!/usr/bin/perl -w
> use strict;
> use HTML::Parser;
> 
> open(OUT, ">/share/file1") || die "Cannot open /share/file1: $!\n";
> 
> my $html = HTML::Parser->new(
> api_version => 3,
> text_h  => [sub{ print shift;}, 'dtext'],
> start_h => [sub{ print shift;}, 'text'],
> end_h   => [sub{ print shift;}, 'text']);

tried sub {print OUT shift;) ? :)
 
> $html->ignore_tags(qw(!? table body span img p br hr td tr font i b h1
> a)); $html->parse_file("/share/input.txt");
> $html->eof;
> 
> close(OUT);


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



Re: CG I Script [guestbook.cgi]

2003-03-10 Thread Scott R. Godin
Mr. Horace Franklin Jr. wrote:

> It looks like this error came about in the course of re-formatting.  I
> looked at earlier versions of the same script, and the ending tag was
> flush
> left.  So also was the rest of the html.  It probably was a good idea to
> indent the html, not so good with the heredoc.  That points up the reason
> I limit my use of this feature--because I prefer to preserve the logical
> indentation of my code, and interposing the intended indentation of some
> remote document is seldom compatible with this.

Well, you can always do this:

print <<"HERE"
this is a test
HERE

Cheers,

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



Re: Odd number of elements in hash assignment

2003-03-10 Thread Scott R. Godin
Deb wrote:

> You know, I'm just not "getting it" I guess.  When I read through
> simple of examples in perldsc and perlfunc, it seems straightforward
> enough, but when I try to put into practice everything, it doesn't go
> as I might expect.
> 
> Recall this code I posted a day or two ago:
> 
>  8-< -- snip 
> 
> while () {
> chomp;
> ($listname, $field) = split(/:\s+/, $_);
> print "\nListname is $listname,\nField is: $field\n";
> %hrLists = split(/\s+/, $field);
> $Lists{$listname} = \%hrLists;
> }
> 
> __DATA__
> list-1: -x abc -r tenb
> list-2: -x def -r ghi -h tenr
> list-3: -x fel -h asci
> list-4: -x foo -h nonasci -r bfab
> 
>  8-< -- snip 
> 
> Note the print in the while loop - essentially, when the hash is built, 
> my goal is to be able to use $listname as a key to call up the value of a
> key in the 2nd level hash.
> 
> I understand this:
> 
> foreach $listname (sort keys %Lists) {
> print "$listname\n";
> }
> 
> But, I don't quite get how to get to the key values below that.  I know
> I'm so close, but just not quite there...
> 
> Could some kind soul give me a blow by blow "what's happening here" going
> from
> 
> $Lists{$listname} = \%hrLists;
> 
> to printing out the key, values by $listname?

There's nothing stopping you from doing something like the following. There 
really is no need to store a reference to a hash in the manner that you are 
doing so. 

#!/usr/bin/perl
use warnings;
use strict;
my %Lists;

while () 
{
chomp;
my( $listname, $field ) = split /:\s+/;
print "\nListname is $listname,\nField is: $field\n";
$Lists{$listname} = {
(split /\s+./, $field)
};
}

foreach ( sort keys %Lists )
{
print "Key: $_\tReference: $Lists{$_}\n";
print "Dereference:\n";
foreach my $key ( sort keys %{$Lists{$_}} )
{
print "Inner Key: $key\tValue: $Lists{$_}->{$key}\n";
}
print "\n";
}

__DATA__
list-1: -x abc -r tenb
list-2: -x def -r ghi -h tenr
list-3: -x fel -h asci
list-4: -x foo -h nonasci -r bfab


Is this more understandable? 


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



Re: CGI:Session

2003-03-12 Thread Scott R. Godin
Xiongfei Wang wrote:

> Thanks for reponse.
> I am very new to perl.
> A silly question is where i can find CGI:Session and how to install it?
> 
> i have  perl, v5.6.1 built for i386-linux.
> 
first 
perldoc CPAN
then
perl -MCPAN -e shell

run through the configuration

then when CPAN is configured properly, you (when within the CPAN shell) can 
do this: 

cpan> m CGI::Session
{results}
cpan> install CGI::Session
{longer results}
cpan> q



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



Re: image sorting....

2003-03-12 Thread Scott R. Godin
Shawn Wilson wrote:

> 1. why is my if statement not working to detect when i have a directory:
> last if ($file eq $dir);
> 

next if (-d $file);

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



Re: ls: *.jpg: No such file or directory

2003-03-12 Thread Scott R. Godin
Mel Awaisi wrote:

> Hi
> 
> My error is as the subject says, i have a script that i am trying in it to
> locate where a directory with images are.
> 
> the part in the script that the error i think is arising from is
> 
> my $dir = '/home/me/images/';
> my @jpegs = `ls *.jpg`;
> foreach (@jpegs) {
> print"$_";# dont forget that a newline is still at the end of each
> element in the array...
> }
> 
> 
> ls: *.jpg: No such file or directory
> ---
> 

chdir '/home/me/images/' or die "Unable to chdir to /home/me/images: $!";
my @jpegs = glob "*.jpg";

print "$_\n" for @jpegs;


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



Re: AW: ls: *.jpg: No such file or directory

2003-03-12 Thread Scott R. Godin
On Wed, 12 Mar 2003, Liedtke Stephan ICM MP IT BLM GA KLF wrote:

Obviously people have gotten so used to top-posting and reading things 
BACKWARDS (and NOT reading the stuff that comes afterwards, like 
the REST OF KNOWN HUMANITY) that... 

> 
> Try my @jpegs = `ls /*.jpg`;
> 
>   SIEMENS AG
>   Information and Communication mobile
>   ICM MP IT BLM GA KLf
>   *:+49 (0) 2842-95-4979
>   Südstr. 9 *:   +49 (0) 2842-95-5991
>   D-47475 Kamp-Lintfort   *: [EMAIL PROTECTED]
> 
> 
> 
> -----Ursprüngliche Nachricht-
> Von: Scott R. Godin [mailto:[EMAIL PROTECTED] 
> Gesendet: Mittwoch, 12. März 2003 11:25
> An: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Betreff: Re: ls: *.jpg: No such file or directory 
> 
> 
> Mel Awaisi wrote:
> 
> > Hi
> > 
> > My error is as the subject says, i have a script that i am trying in 
> > it to locate where a directory with images are.
> > 
> > the part in the script that the error i think is arising from is
> > 
> > my $dir = '/home/me/images/';
> > my @jpegs = `ls *.jpg`;
> > foreach (@jpegs) {
> > print"$_";# dont forget that a newline is still at the end of each
> > element in the array...
> > }
> > 
> > 
> > ls: *.jpg: No such file or directory
> > ---
> > 

...they COMPLETELY miss the fact that I RESPONDED to THE ABOVE, with THE 
BELOW: 

> 
> chdir '/home/me/images/' or die "Unable to chdir to /home/me/images: $!"; my
> @jpegs = glob "*.jpg";
> 
> print "$_\n" for @jpegs;
> 

Q.E.D.


This is why top-posting is bad, people.

Deal with it. Just say no to top-posting.



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



RE: Regular Expressions http error code

2003-03-13 Thread Scott R. Godin
Derek Romeyn wrote:

> K, I tried this and it didn't work as expected:
> 
> $code =~ / HTTP\/\d\.\d\" (\d+)/;
> if (!$code) {
> print "NEXT\n";
> next;
> }
> print "$code\n";
> 
> 
> The loop just printed NEXT 300 or so times.  I was thinking that $code
> would
> equal whatever was in the parentheses.  Am I still not getting this?

top posting is bad. don't do that. respond below, or interleaved with the 
post you are replying to. 

while ()
{
next unless (my $file, $code) = 
m|GET\s+([/.\w\d]+)\s+HTTP/[\d.]+"\s+(\d+)\s+|
print "$file: $code\n";
}

try this one on for size as a start. Does a little bit more than you asked 
for but you might find that useful too. ;) 

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



Re: Where to use 'use'

2003-03-13 Thread Scott R. Godin
Jeff Westman wrote:

> Hello All,
> 
> I have a trivial question.  I have a perl script, with several
> sub-routines.
> In one of those routines, I currently have listed 'use Date::Calc'.  So
> that package is therefore only available (and needed) in that one
> sub-routine.
> 
> My question is, should all 'use' statements be placed at the top of the
> script, or only in routines that need them?
> 
> 
> -Jeff


If there's a chance that the script in question will NOT have to call on 
this module, you can use the 

use autouse 'Date::Calc';

pragma.

I sometimes do this with Carp, for instances where I don't expect carp to 
get called very often, in those instances it won't load unless it's needed. 

use autouse 'Carp' => qw(carp croak);

Otherwise I generally place all module usage at the top so they are easy to 
find for future maintainers. 

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



Re: Linux Perl Editor

2003-03-14 Thread Scott R. Godin
Francesco Del Vecchio wrote:

> Is there a perl Editor for linux? (except EMACS)
> 
> Francesco

Personally I use vim (and gvim under Xfree86)

Nice syntax colorization, and the :set cindent smartindent feature does all 
the fancy indenting for me, which is very nice. 

you can run vimtutor at the command line to get a brief tutorial on the 
basics, and MetaCosm from irc.freenode.net has put up a very nice irc-style 
tutorial that explains a great deal more about what vim can do. 

You'll find that here: 



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



Re: apache error

2003-03-15 Thread Scott R. Godin
Pete Emerson wrote:

> The CGI module is fantastic for doing things like printing headers,
> parsing forms, etc. I don't think I've written a CGI script without it.
> Your missing the header. See 'perldoc CGI'.
> 
> #!/usr/bin/perl -w
> 
> use strict; # Highly recommended!
> use CGI qw(:standard);
> 
> print header;
> print start_html;
> print "Hello world!\n";
> print end_html;


#!/usr/bin/perl
use warnings;
use strict;
use CGI qw(:standard :html3 -no_xhtml);
# use CGI::Pretty qw(:html3); # use this for multiline html output
  # leave out for faster downloads of pages
print header(), 
start_html(),
h2({-align=>'center'}, 'A Simple Test'), hr(), br(),
p({-align=>'center'}, "Hello World!"),
end_html();

# in this manner (the function-oriented interface of CGI.pm) you can
# code up perl as if it were HTML, and it even LOOKS like it. 
# AND properly opens/closes html tags in the right places for you. 

# :-)

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



Re: Problems with while loop and array

2003-03-17 Thread Scott R. Godin
Erwin Zavala wrote:

> I know I could use the filehandle but I am trying to understand why I
> cannot use the array and print each element at the time.
> 
> #!/usr/bin/perl

use warnings; #why was this left out?

> use strict;
> use Fcntl;
> 
> $/ = "\n\n";
# I assume you know what you're doing here
> sysopen(readFile, "cnnArticle.txt", O_RDONLY) || die $!;
> sysopen(writeFile, "fortuneCookie.txt", O_WRONLY|O_CREAT) || die $1;

#nuh uh.
sysopen(writeFile, "fortuneCookie.txt", O_WRONLY|O_CREAT) || die $!;

> 
> my @articleArray = ;
> 
> while(<@articleArray>)

#bah. why slurp the whole file into memory at once, when you're only 
# printing a line at a time? what if the file was a web-log gigabytes
# long?  
while ()

> {
> print $_;

#you have to specify the output filehandle
print writeFile; #$_ is superfluous here as it is the default.

> }

# always close (and test the closing of) file handles
close readFile or die "Unable to close input file: $!";
close writeFile or die "Unable to close output file: $!";
#always use descriptive error messages.


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



Re: Fun with Regexes

2003-03-17 Thread Scott R. Godin
Pete Emerson wrote:

> Mar 16, 2003 at 5:08pm from Rob Dixon:
> 
> RD> (print 'abc') + ($success = 0) + (last);
> 
> Rob, thanks, this example helps drive the point home. Would you also argue
> that
> 
> open INFILE, $file || die "Can't open $file: $!";
> 
> should really be written as
> 
> die "Can't open $file: $!" if (!open INFILE, $file);
> 
> or is this a different kettle of fish?
> 
> By the way, I really appreciate that this list caters to multiple levels
> of "beginners"! I've not only been helped a lot on here, but I hope I've
> helped a few myself. :)
> 

there's instances where 

die "errmsg: $!"
unless open(INFILE, "<", $file);

syntax is preferable. The Camel mentions this in a few places. 

IIRC you might try looking in perldoc perlstyle, although I could be wrong 
on that. Usually it's a factor of readability and intent. 


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



RE: Help with script , error 500

2003-03-18 Thread Scott R. Godin
Rgíón «hávkú wrote:

> I wanna say Thank you to all of you.
> Rob: I wouldn't have found that unescaped double quote.
> Thanx for all your comments.
> I've found the very answer on line 6
> 
> I had
>  $bd = imagenes.dat;
> 
> ans it must be
>$bd = "imdat";agenes.
> Everything OK now. After a good sleep night ..
> 
> c u
> -rm-
> 
> 
> 
> 
> - Original Message -
> From: R. Joseph Newton <[EMAIL PROTECTED]>
> To: Ramón Chávez <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Monday, March 17, 2003 5:41 PM
> Subject: Re: Help with script , error 500
> 
> 
>> Ramón Chávez wrote:
>>
>> > Hello everyone.
>>
>> Hi Ramon,
>>  I think I see your problem right here:
>>
>> >print "content-type: text/html \n\n";
>>
>> Should be:
>> print "Content-type: text/html\n\n";
>> I can't say that that is the only problem, but that probably would be
> enough  to hang the process.  Try changing that, then see what results you
> get.

would have found it faster if you did 

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

at the top of all your programs. 

>$ perl -Mwarnings -Mstrict -e '$bd = imagenes.dat;'
Global symbol "$bd" requires explicit package name at -e line 1.
Bareword "imagenes" not allowed while "strict subs" in use at -e line 1.
Bareword "dat" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.



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



Re: pb of listing and renaming files

2003-03-18 Thread Scott R. Godin
John W. Krahn wrote:

> chomp;
> if ( /(.*)\.BMP/ ) {
> print "processing image $_ ..\n";
> system( 'mv', $_, "$1.bmp" ) == 0 or die "system 'mv $_' failed:
> $?";
> }

next unless /(.*)\.BMP$/;#anchor it to the end of the string!
print "processing image file: $_\n";

#rename will clobber existing files, so check first!
warn "File exists!: $1.bmp. skipping...\n" && next
if -f "$1.bmp";

# use perl rather than spawning external processes!
rename( $_, "$1.bmp" ) or die "unable to rename file $_: $!"; 



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



Re: PERL OSX --- reading a local text file

2003-03-18 Thread Scott R. Godin
David Gilden wrote:

> OK, one problem is solved, which was the path to the data file.
> 
> I know there is a simple way to read in a file like the following:
> 
> apple,2
> banana,4
> kiwi,1
> 
> 
> and produce a HASH. The code below works I get the feeling there is a more
> compact way to accomplish this.
> 
> ---
> 
> #!/usr/bin/perl -w
> 
> use strict;
> my %prices;
> 
> my $data = "/Users/dowda/Desktop/tmp test/test.txt";
> 
> open (FH,$data)  || die  "could not open $data $!";
> 
> local $/;
> 
> my $tmp = ;
> my @tmp =  split (/\n/,$tmp);
> 
> close FH;
> 
> for (@tmp) {
> my ($k,$v)  = split /,/;
> $prices{$k} =$v;
> }
> 
> for my $key (keys %prices){
> 
> print "$key = $prices{$key}\n";
> 
> }

how about this: 

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

open (FH, "<", '/Users/dowda/Desktop/tmp test/test.txt') 
or die "Unable to open input file: $!";

my %prices;
while ()
{
chomp;
my ($key, $value) = split /,/;
warn "Duplicate key: $key\noldval: $prices{$key}\tnewval:$value\n"
if defined $prices{$key};#always idiot proof the input ;)
$prices{$key} = $value;
}

print "$_ = $prices{$key}\n" for sort keys %prices;

this work any better? 

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



Re: PERL OSX --- reading a local text file

2003-03-19 Thread Scott R. Godin
John W. Krahn wrote:

> David Gilden wrote:
>> 
>> OK, one problem is solved, which was the path to the data file.
>> I know there is a simple way to read in a file like the following:
>> 
>> apple,2
>> banana,4
>> kiwi,1
>> 
>> and produce a HASH. The code below works I get the feeling there is a
>> more compact way to accomplish this.
> 
> Yes, there is.  :-)
> 
> my %hash = do { local $/;  =~ /[^\n,]+/g };

Holy Handgrenades, Batman!

but where's the implicit split of key and value there? forgive me for 
asking, but I just don't see it. is there some magic going on here? 

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



Re: pb of listing and renaming files

2003-03-19 Thread Scott R. Godin
Rob Dixon wrote:

> Hi Scott.
> 
> Scott R. Godin wrote:
>> John W. Krahn wrote:
>>
>> > chomp;
>> > if ( /(.*)\.BMP/ ) {
>> > print "processing image $_ ..\n";
>> > system( 'mv', $_, "$1.bmp" ) == 0 or die "system 'mv $_'
>> > failed: $?";
>> > }
>>
>> next unless /(.*)\.BMP$/;#anchor it to the end of the string!
>> print "processing image file: $_\n";
>>
>> #rename will clobber existing files, so check first!
>> warn "File exists!: $1.bmp. skipping...\n" && next
>> if -f "$1.bmp";
>>
>> # use perl rather than spawning external processes!
>> rename( $_, "$1.bmp" ) or die "unable to rename file $_: $!";
> 
> There's a big [SNIP] here from the end of John's post:
> 
> John W. Krahn wrote:
>> However, you could write the whole thing in perl and avoid the pipes
>> and system().
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> use File::Find;
>> use File::Copy;
>>
>> find( sub {
>> return unless -f and /^(.+)\.BMP$/s;
>> move( $_, "$1.bmp" ) or warn "Cannot move $_: $!";
>> }, '.' );
>>
>> __END__
> 
> Rob

Yes,. I saw his post after I posted mine. 

However, this still doesn't address the issue of clobbering existing files 
(File::Copy documentation makes no mention of this issue). MY whole issue 
was not using external 'mv' when perl already has 'rename', and the 
possible issue of overwriting files that already exist. 

It IS, however, yet another way of doing things (which Perl is well known 
for)

to select the files, I'd have done a chdir to the directory in question, and 
then a (my @files = glob "*.BMP";) myself.

File::Find is another perfectly good way of accomplishing this in a 
different way. It all depends on your approach. EITHER way is perfectly 
viable, but you STILL have to address the potential issue of overwriting 
existing files on a case-sensitive filesystem. 

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



Re: PERL OSX --- reading a local text file

2003-03-19 Thread Scott R. Godin
Rob Dixon wrote:

> John W. Krahn wrote:
>> David Gilden wrote:
>> >
>> > OK, one problem is solved, which was the path to the data file.
>> > I know there is a simple way to read in a file like the following:
>> >
>> > apple,2
>> > banana,4
>> > kiwi,1
>> >
>> > and produce a HASH. The code below works I get the feeling there is
>> > a more compact way to accomplish this.
>>
>> Yes, there is.  :-)
>>
>> my %hash = do { local $/;  =~ /[^\n,]+/g };
> 
> my %hash = map {/\w+/g} 
> 
> :-)

grin away. This shortcut deserves to be in the perldocs somewhere. I wish 
I'd seen this before. 

...and I thought I was impressed by the earlier post. *shaking head* 
sheesh. I should know better by now. :D

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



Re: PERL OSX --- reading a local text file

2003-03-22 Thread Scott R. Godin
Rob Dixon wrote:

> Scott R. Godin wrote:
>> John W. Krahn wrote:
>> >
>> > Yes, there is.  :-)
>> >
>> > my %hash = do { local $/;  =~ /[^\n,]+/g };
>>
>> Holy Handgrenades, Batman!
>>
>> but where's the implicit split of key and value there? forgive me for
>> asking, but I just don't see it. is there some magic going on here?
> 
> Hi Scott.
> 
> May the apprentice answer for the master?
> 
> The %hash = puts /[^\n,]+/g into list context, which therefore
> returns a list of all the matches. The regex matches all contiguous
> strings of characters excluding comma and newline, so will
> effectively split at both and return two fields per file record.
> local $/, of course, enable slurp mode and reads the entire
> file into a single string.
> 
> Did I pass?
> 
> Rob

Indeed. this construct is one I've rarely seen, which accounts for much of 
my surprise. I was already aware of 'slurp mode', but had not seen the 
localized use of do in this manner, where the filehandle was bound to a 
regex  =~ /matchthis/; 

list context explains much here, but the usage was still surprising to me. 
I'll definitely have to remember this for future reference. 



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



Re: How can I check the size of a file

2003-03-22 Thread Scott R. Godin
Rob Dixon wrote:

> Giarrocco, Camillo wrote:
>> Hi,
>>
>> Can anybody tell me how can I check the size of a file?
>>
>> I know the "if  (-s "file") function but never used and don't know the
>> right syntax of it.
> 
> Well it's just that really. But you can do more than just test it for
> being non-zero with 'if'.
> 
> my $size = -s 'file';
> 
> and use it as you will.
> 
> Rob

there's also 
perldoc -f stat

my $filesize = (stat( $filename ))[7];



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



Re: PERL OSX --- reading a local text file

2003-03-22 Thread Scott R. Godin
Randal L. Schwartz wrote:

>>>>>> "Scott" == Scott R Godin <[EMAIL PROTECTED]> writes:
> 
>>> my %hash = map {/\w+/g} 
>>> 
>>> :-)
> 
> Scott> grin away. This shortcut deserves to be in the perldocs
> Scott> somewhere. I wish I'd seen this before.
> 
> The problem is that it is very intolerant of mis-formatted data.  If I
> had a line that had one or three items, or an item that was a hostname
> that had a hyphen in the name for example, then that line and all
> subsequent lines would be misinterpreted.
> 
> Probably better is:
> 
> my %hash = map /^(\w+),(\w+)\n/, ;
> 
> which ensures that faulty data merely messes up that particular entry,
> not all entries.  And it serves to document the result better, I
> think.
> 

very very true. brevity isn't always the master of wit. :) 

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



Re: Linux Environment Variable

2003-03-22 Thread Scott R. Godin
Ankit Gupta wrote:

> Hi,
> 
> I want to print some linux environment variables that have already been
> set. Could some one let me know which command I can use to get value of
> environment variables.
> 
> Regards,
> Ankit

perl -le 'print "$_ -> $ENV{$_}" for sort keys %ENV'



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



Re: networking with perl

2003-03-23 Thread Scott R. Godin
Soumyadeep Nandi wrote:

> Hi Wiggins,
> 
> I wrote a simple script that is sending a request to
> localhost and receiving the response with LWP.
> As I am trying to run the script it is ending up with
> the error " 403 Forbidden ". I am sending the script
> along with this mail bellow.
> 
> I've checked the file permission of file3.cgi and put
> it to "-rwxrwxrwx".

should be chmod 755 not 777 

> Could you please suggest me what and where I am making
> the mistake, and what should I do to overcome the
> error.

Sounds like you might be having a problem with the directory permissions on 
the path leading TO the .cgi. 

chmod 711 /home/$USER
chmod 755 /home/$USER/public_html
chmod 755 /home/$USER/public_html/cgi-bin/ 

 


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



Re: Printing epoch time

2003-03-24 Thread Scott R. Godin
Francesco Del Vecchio wrote:

> how can I print the today date (DD MM YY HH MM SS) in epoch format?
> 
> Frank

perldoc -f time
   localtime
   gmtime

perldoc Time::Local (<-- I think this is what you're after. if not, please 
clarify for us)
POSIX  (and search for the strftime function)

There's also Time::HiRes if you're interested in that sort of thing. 

That should be enough info for you. 

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



Re: networking with perl

2003-03-25 Thread Scott R. Godin
On Mon, 24 Mar 2003, Soumyadeep nandi wrote:

> Thanks Scott,
> 
> The mistake was in directory permission.
> 
> I have a little more problem in running system command
> from cgi file. Even I wrote a perl file so that I can
> run the system command from the perl file. But the
> perl file is also not executing the system command. I
> could run the short commands from the cgi 
> file.
> 
> I am sending the scripte for your kind considerations,
> 
> Looking forward for your reply.
> With regards,
> Soumyadeep
> 
> 
> 
> I am sending the request from the perl file
> 
> send.pl--
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> use LWP::UserAgent;
> 
> use LWP;
> my $ua = new LWP::UserAgent;
> my $req = new HTTP::Request POST =>
> 'http://localhost/cgi-bin/bic_genscan/file3.cgi';
> $req->content_type('application/x-www-form-urlencoded');
> $req->content('st=atgtcgatcagctacgatc');
> my $res = $ua->request($req);
> 
> 
> if($res->is_success){
> print $res->content;
> }else{
> print "Error: ".$res->status_line."\n";
> }
> 
> exit;
> 
> 
> Receiving the request by cgi file

not sure about the above, but this: 

> 
> file3.cgi---
> #!/usr/bin/perl -w
> 
>   use CGI;
> 
>   print "Content-type:text/plain\n\n";
> 
>   $query = new CGI;
> 
>   print "blast\n";
> 
>   $str = $query->param('st');
> 
>   print "here the string is : $str\n";
> 
>   system("./perl1.pl");

is just wrong. 

#!/usr/bin/perl -w
use strict;
use CGI qw/:standard :html3 -no_xhtml/;

print header(), start_html(), p("blast");

my $str = param('st') || 'no results';

print p("The 'st' param result is: $str"), end_html();

__END__

now, WHY is the above cgi calling an external process instead of just 
executing the perl code within itself, and if you ARE determined to 
execute a separate process WHY are you not passing it any parameters when 
the recieving script plainly expects SOMETHING as a parameter? 

> ---
> 
> And processing the request by another perl file
> 
> perl1.pl-
> 
> #!/usr/bin/perl
> 
> $str = shift;
> print "received the sequence\n";
> system("/home/soumya/Application/BLAST/blastall -p
> blastn -d /home/soumya/Application/BLAST/data/ecoli.nt
> -i /var/www/cgi-bin/bic_genscan/testseq");
> print "done...\n";

and lastly WHY are you not TESTING any of these for success? 

WHY are you not using 

  use strict; 

??

for answers to these and other questions, please post your resonse to the 
perl list rather than to just me.. just because I had time to answer an 
earlier question doesn't mean I have time to answer ALL your questions, 
NOR does it mean that all my answers will be RIGHT. :) 

better to get the concensus of the GROUP instead. post to the 
newsgroup/mailing list where this originated, please. 

thanks :) 


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



Re: First program not working

2003-03-25 Thread Scott R. Godin
R. Joseph Newton wrote:

> Barb Konings wrote:
> 
>> I have checked my books, checked permissions, and am
>> still having trouble.
>>
>> Here is my code in a file named hello.pl. I have a
>> link to this file off my web page to test it.
>> (Maybe this part is now right?...)
>> - - - - - - - - - - - - - - - - - - - - - -
>> #!/usr/bin/perl
>>
>> # hello.pl
> 
> What kind of system are you working on?  If you are working in Windows,
> one possibility is that you have FTP'd the script in binary mode, keeping
> the DOS carriage-returns in your newlines.

If you'd read through her entire message you would have seen: 

>>Apache Server - Red Hat 8

> Another possibility is that the server does not have a Perl installation
> at the locaation specified.  Usually, an Internal Server Error indicateds
> an error has occured before the content header is printed.

also answered by the above

> In your html directory, it looks like your browser or server is assuming
> GET as the method.  This is the default for URLs typed into the address
> bar.  It seems that your server assumes this also.  If your server
> configuaration includes a cgi-bin directory, you should use this, and just
> focus on fixing errors received doing this.
> 
> One thing you might try is simplifying your script header:
> 
> #!perl -w

This won't work on a unix system which requires the full shebang line to 
have the proper path to the executable. 

> If the perl executable is in your systems executable path, this should be
> enough.  It is definitely better than giving the server an incorrect path.
> 
> Joseph


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



Re: First program not working

2003-03-25 Thread Scott R. Godin
Barb Konings wrote:

> I have checked my books, checked permissions, and am
> still having trouble.
> 
> Here is my code in a file named hello.pl. I have a
> link to this file off my web page to test it.
> (Maybe this part is now right?...)
> - - - - - - - - - - - - - - - - - - - - - -
> #!/usr/bin/perl
> 
> # hello.pl
> 
> print "Content-type: text/html\n\n";
> print < 
> 
>Hello
> 
> 
>Hello, world!
> 
> 
> 
> END_OF_FILE
> 
> - - - - - - - - - - - - - - - - - - - - - - - -
> When I have this file in the CGI-BIN directory,
> I get an internal server error. So I put it in
> with my HTML files, and this is now what I get
> in the browser.
> - - - - - - - - - - - - - - - - - - - - - - - -
> #!/usr/bin/perl # hello.pl print "Content-type:
> text/html\n\n"; print <
> Hello, world!
> 
> END_OF_FILE
> 
> - - - - - - - - - - - - - - - - - - - - - - - -
> I started with the permissions of both the CGI-Bin
> directory and the file at 755, then changed to 777.
> No luck.
> 
> I have tried with both a .pl and .cgi extension.
> 
> There is another .pl file in the CGI-BIN directory
> that works fine.  It is executed on clicking a submit
> button.
> 
> The first line of this file matches the first line of
> the file that works.
> 
> Apache Server - Red Hat 8


Barb, it sounds to me that possibly the Apache server is not configured 
correctly. The other .pl script is being sent form data from an existing 
form, but isn't being run DIRECTLY as a .cgi script viewed from the browser

Is the httpd.conf set to allow .cgi execution in userdirs ? This DOES need 
to be manually set on a Red Hat 8 default httpd.conf, in order to allow 
/home/$USER/public_html/cgi-bin/file.cgi to execute as a CGI script

You could try this. It's a bit more complex, but should yield some results. 
(oh, by the way, have you checked /var/log/httpd/access_log and 
/var/log/httpd/error_log during testing of the script to see what KIND of 
errors are showing up ?)

#!/usr/bin/perl 
use warnings;
use strict;
use CGI qw/:standard :html3 -no_xhtml/;

# report fatal errors to browser - check website error log for warnings!
use CGI::Carp qw(fatalsToBrowser set_message);
BEGIN {
   sub handle_errors {
  my $msg = join( br(), @_);
  print header(), 
start_html( "CGI/Perl Script Error" ),
h2( "Eek!"),
p( "I must be beta-testing some changes, so E-mail me, ", 
   a({-href=>'mailto:[EMAIL PROTECTED]'}, "YOURNAMEHERE"), 
   ", about this if it persists for very long.",
 ), 
hr(),
p( "Got an error: $msg" ), 
end_html();
  }
  set_message(\&handle_errors);
};   

print header(), 
  start_html({-title=>"Hello"},),
p("Hello, world!"),
  end_html();

# ps. it's MUCH easier to code html using CGI.pm's function oriented 
# interface. As you can see. :-) 
 

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



Re: INFO PLEASE

2003-03-28 Thread Scott R. Godin
Eric Walker wrote:

> how can I see where modules are installed no matter if they are personal
> or come with perl also how can I tell what functions are available for
> them. Thanks

There's my ModuleReport script -- http://www.webdragon.net/mr/

There's still a few things I'd like to do with it, but it's fully functional 
as-is, and will let you know which modules have updated counterparts on 
CPAN (http://www.cpan.org/)


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



Re: running a script thru a webpage

2003-03-30 Thread Scott R. Godin
Christopher M Burger wrote:

> Hello everyone.
>  
> I have written a perl program that will take a tar file and untar it then
> move file from the untarred direcories to it's directory on the webserver.
> However, when I run the program thru a webpage it does not untar the file.
> If I run the program localy it works fine.  I have even run the program
> localy as www the user the webserver uses and it works fine, but when turn
> around and run the program thru my web browser it does not work.
>  
> If anyone has any reasons why this would happen I would appreciate it.
>  
> I'm running in strict mode, and am using the following system command to
> untar.
>  
>   eval { system("/usr/local/bin/gtar -C /$temp_directory -xzf
> /$temp_directory/$short_name") == 0 or die "sorry! Could not extract file
> $temp_directory/$short_name" };
>  
> where $temp_directory is the full path to the tar file, and $short_name is
> the name of the tar file.
>  
> Thanks
>  
> Christopher Burger

Howcome you're not using Archive::Tar ? :) 

check CPAN for details.



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



Re: :Ping Cannot redirect output !

2003-03-30 Thread Scott R. Godin
R. Joseph Newton wrote:

> "Bakken, Luke" wrote:
> 
>> > $!=1;
>>
>> $! contains error text, if I remember correctly off the top of my head.
>>
>> Use $| = 1 instead for autoflush. This shouldn't cause redirect
>> problems, tho.
>>
>> > use Net::Ping;
>> > @host_array = ;
>> > $p = Net::Ping->new("icmp");
>> > $p->bind("192.168.2.211"); # Specify source interface of pings
>> > foreach $host (@host_array)  {
>> >chomp($host);
>> >print "$host is ";
>> >print "NOT " unless $p->ping($host, 2);
>> >print "reachable.\n";
>> > }
>> > $p->close();
>>
>> Are you running this on Windows? I've noticed redirect weirdness with
>> Windows at times.
>>
>> Otherwise everything looks OK.
>>
>> Luke
> 
> Hi Luke,
> 
> FWIW, Rob's speculation hit the mark.  Neither setting the error message
> to '1', nor output redirection problems seem to hang it, at least on
> Win2K.  I think it probably would be better to quote the entire parameter
> list for perl, but it did run fine once the call to the non-existent
> bind() function was commented out.

non-existent? since when? 

perldoc Net::Ping

   $p->bind($local_addr);
   Sets the source address from which pings will be sent.  This must
   be the address of one of the interfaces on the local host.
   $local_addr may be specified as a hostname or as a text IP 
   address such as "192.168.1.1".

   If the protocol is set to "tcp", this method may be called any 
   number of times, and each call to the ping() method (below) will 
   use the most recent $local_addr.  If the protocol is "icmp" or 
   "udp", then bind() must be called at most once per object, and 
   (if it is called at all) must be called before the first call to 
   ping() for that object.


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



Re: :Ping Cannot redirect output !

2003-03-31 Thread Scott R. Godin
On Sun, 30 Mar 2003, R. Joseph Newton wrote:

> "Scott R. Godin" wrote:
> 
> >   I think it probably would be better to quote the entire parameter
> > > list for perl, but it did run fine once the call to the non-existent
> > > bind() function was commented out.
> >
> > non-existent? since when?
> >
> > perldoc Net::Ping
> >
> >$p->bind($local_addr);
> >Sets the source address from which pings will be sent.  This must

[snip]

> >ping() for that object.
> 
> You are right.  It is there.  OTOH, that does not mean that it is a good
> idea to use it.  In the way that ramprasad was using it, the code
> assumed the interface IP to be static.  Now, I don't know the innards of
> his LAN, but the IP used sure looks like one dished up by DHCP.  Most of
> the hosts list also look like DHCP.  Those would not hang the process,
> though; they would only return 0 from the ping() call.
> 
> So, whether the function exists or not, it should probably not be used
> unless there is a very specific reaswon why it needs to be.  If you scan
> through the synopsis for the module, you may notice that it is not even
> mentioned.
> 

Without debating the possible usefulness of it when set improperly by 
inexperienced coders, In Net::Ping 2.28 which I have installed here, and 
which appears to be the most recent version available from CPAN, the bind() 
call certainly SEEMS to be mentioned in the Synopsis in the 6th line (of 
code) into it.

Observe: 

SYNOPSIS
   use Net::Ping;

   $p = Net::Ping->new();
   print "$host is alive.\n" if $p->ping($host);
   $p->close();

   $p = Net::Ping->new("icmp");
   ->  $p->bind($my_addr); # Specify source interface of pings
   foreach $host (@host_array)
   {
   print "$host is ";
etc, etc, etc, 

/me wanders off whistling to the sound of one pin, dropping.



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



Re: Help required

2003-03-31 Thread Scott R. Godin
Brijesh Kanderia wrote:

> Hi All,
> 
> I dont have very much idea about perl programing. I have writen a small
> script which reads the content of one file which keeps on changing daily.
> and sends the out put to the concerned person thru mail.
> 
> Now what I want is that I dont want the contents. I want this script to
> send this txt file as an attachment to [EMAIL PROTECTED] now pls tell me how to
> do this.

Take a look at Mail::Mailer from CPAN

You might want to have MIME::Base64 installed as well.





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



Re: question about || operator

2003-04-01 Thread Scott R. Godin
Ravi Malghan wrote:

> Hello: I seem to have forgotten
> 
> Can this statement be shortened
> if(($node =~ /net/) || ($node =~ /gaat/))
> 
> The following does not give me the expected results
> if($node =~ (/net/ || /gaat/) )
> 

if ($node =~ /net|gaat/) {


perldoc perlre
perlretut
perlrequick



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



Re: Problem with script.

2003-04-01 Thread Scott R. Godin
R. Joseph Newton wrote:

> I'm fatalistic.  People rarely actually take my advice.  I'm going to give
> you some anyway.  Suspend this project, and work on the process of
> organizing your task into named subroutines.  You have better things to do
> with your mental powers than trying to keep track of how one line of code
> is going to interact with hundreds or thousands of others.  This might
> delay your project somewhat, but in the long run, it will speed your work
> dramatically.
> 
> Break your problem down into manageable chunks.

I'm not fatalistic, and second this advice wholeheartedly. Breaking the 
problem down into smaller parts and when you are sure each separate part 
works properly, THEN working on interlacing and glueing them together, will 
make the overall issue MUCH clearer to you. It's also easier to figure out 
what each part is doing this way, if you need to make subtle changes at a 
later date...

trust me on this. :o) 

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



RE: Simple split question

2003-04-01 Thread Scott R. Godin
Jdavis wrote:

>> 
>> ($left,$right) = split(/word/, $sentence);
>> 
> 
> I am trying this but its not working. Im lost :)
> could someone take a look...
> 
> This is the beggining of a scrip to make reports
> based on droped iptable packets

I've done something like this with my tailfilter project. 

http://www.webdragon.net/tf/

>From the synopsis: 

-=-

Tailfilter is something that started off as a perl one-liner, took on a life 
of its own, and swiftly grew out of control because I couldn't stop 
thinking of ways to enhance the original idea.

Essentially, it's a logfile filter that reformats the output from the log 
and 'pretty-prints' a more legible arrangement that lends itself better to 
rapid and/or cursory analysis, as well as offering immediate audible 
notification of new events as they occur (optional). It additionally caches 
the results of DNS lookups, as well as the TCP-based services in 
/etc/services to speed up the info lookups considerably.

To use it, simply do one of the following (or similar, depending on where 
you store the tailfilter script):

 tail -f /var/log/messages |tailfilter

 sudo tail -n 50 -f /var/log/messages |./tailfilter -l 40 -c --iptables

-=-

It works with both ipchains and iptables currently, as well as running under 
anything above 5.6.0 (I haven't tried it with 5.005_03 but I don't believe 
it will work, there. Anyone willing to play with it?) 

I'm still pondering ways to suppress flood symptoms in the script, such as 
when a nmap comes in masked by several hundred other (bogus) IP's, but this 
is a rare enough occurrance, that as long as you have the audible 
notification on, you can stop/pause the script until the flood passes. A 
flood from a single IP address is already cached by the existing script, 
but when masked behind hundreds of other bogus non-valid IP's, a flood of 
hostname lookups inevitably occurs. 

I'm also planning on replacing the external `host` lookup with perl's own, 
now that I've found out how to do it properly. The only misgiving I have 
about that is the notification error messages that one gets from `host` 
have different qualities depending on the error, whereas I don't *think* 
the internal perl way of doing it, does. Still experimenting in my (I wish) 
copious spare time. 

suggestions are welcome. (as are patches :-)


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



Re: AW: *.jpg: No such file or directory

2003-04-01 Thread Scott R. Godin
James Hughes wrote:

> 
> Just a thought, but try to change to your directory first
> 
> my $dir = '/home/me/images/';
> my @jpegs = `ls *.jpg`;
> chdir ($dir) || die "Cannot chdir to $dir: $!";;
> foreach (@jpegs) {
> print"$_";# dont forget that a newline is still at the end of
> each element in the array...
> }

err, make that

my $dir = '/home/me/images';
chdir $dir or die "Cannot chdir to $dir: $!";
my @jpegs = glob "*.jpg"; #use perl rather than shell wherever possible

print join("\n", @jpegs) if scalar(@jpegs);

Always chdir to the dir you need FIRST, before actually trying to get a list 
of files IN it. ;) 


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



Re: dumb array/hash question

2003-04-01 Thread Scott R. Godin
Jdavis wrote:

> 
> I have a hash that i needed to put into a 2d array.
> I wound up doing this...
> 
> foreach $key (keys(%temp)){
> push(@graph_key,$key);
> push(@graph_value,$temp{$key});
> }
> 
> $data[0] = [EMAIL PROTECTED];
> $data[1] = [EMAIL PROTECTED];
> 
> Though Im not quite sure why i need to escape the @?
> 
> but it works :)

Well, you aren't 'escaping' the @ in the array name. 

You're taking a reference to the original array itself 

if you print $data[0] you'll see that it's an array reference, and needs to 
be accessed via @{ $data[0] }.

I'm not sure this is the best way of doing this, in this case... THe only 
reason I can think of to use arrays in this manner is because you need the 
data in a particular order. 

What's wrong with using the hash itself to store the data? Maybe I need to 
back up and look at the original post again. *headscratching*


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



Re: Problem with script.

2003-04-01 Thread Scott R. Godin
Jenda Krynicky wrote:

> From: Aim <[EMAIL PROTECTED]>
[snip]
>> be a simple bug. Going back to the drawing board may be inefficient
>> in this case as the script is almost there, I can feel it. The mistake
>> I made was pausing from the work for a few days and then to come back
>> to it scratching my head.
> 
> If you have such problems after only a few days, how will you feel if
> you'll need to make som changes to the script half a year later?
> This is as clear sign that you should refactor the script as you
> could get.

Seconded. A little more time spent now will save you a great deal of time 
later. 

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



Re: use of "?" operator instead of "if"

2003-04-03 Thread Scott R. Godin
Jeff Westman wrote:

> It's called the ternary operator, and works like this:
> 
> $VAL ? $VAL = "$VAL:$expr" : $VAL = "$expr";
> 

couldn't this be written as 

$VAL = $VAL ? "$VAL:$expr" : $expr; 



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



RE: Problems with TEXT::CSV_XS

2003-04-03 Thread Scott R. Godin
Bk Good wrote:

> Can Text::CSV handle other types of delimited files besides comma?

You could also look into AnyData.pm (and DBD::AnyData if you're more 
familiar with DBI) which has some interesting ways of parsing various files 
and treating them like databases ;o)



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



Re: Command line argurments to perl program

2003-04-03 Thread Scott R. Godin
Madhu Reddy wrote:

> Hi,
>   I want to pass command line arguements to perl
> program ?
> How to do this ?


There's Getopt::Std and Getopt::Long. IMHO the Getopt::Long interface and 
how it accesses the command line options is superior to Getopt::Std and 
supports both short (-t) and long (--type) switches.



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



Re: Php perl?

2003-04-05 Thread Scott R. Godin
Gary Stainburn wrote:

> Just to put things into perspective here
> 
> 1) I made the comment about the start-up speed.
> 2) Although I use PHP frequently my feet are FIRMLY in the Perl camp
> 3) Unix Fork/Load/Exec cycle *IS* slow because of the amount of work
> involved. The MS equiv will be just as slow
> 4) The F/L/E cycle has to be done *every* time the CGI is requested.
> 
> The PHP interpreter is already loaded and therefore *WILL* have a quicker
> startup. I don't have figures to back it up, but I would imagine Perl
> scripts exec much quicker that PHP asuming both scripts perform the same
> function.
> 
> (From memory) Using mod_perl will only require scripts to be loaded and
> compiled once per lifetime of the apache daemon so will be much quicker
> overall and provide less load on the server than either traditional CGI's.

The question I have is with the current Apache (2.x) and mod_perl (1.27?) 
involved, when a perl program is incorporated into the httpd process in 
this manner, how much more *memory* overhead does each httpd process 
require over related circumstances in php? 

for example if I use CGI.pm to create a form (using its functional interface 
to produce the actual HTML seen) and also respond to said form, how much 
more RAM will each httpd process require if this is run under mod_perl ? 

One argument I've been handed by the php camp is that in a mod_perl 
situation, this will cause apache processes to become much larger, thereby 
taking up more of the precious memory resources. 

(consider a large gaming website like planetunreal (which IIRC uses .asp), 
or quakeworld, which garner huge volumes of hits on a daily basis)

This issue needs to be addressed firmly to the php camp, because the FUD 
being spread was enough to cost me one of the most fun hobby projects I was 
involved with, and the one that got me started on the perl path to begin 
with while they were still on .asp and had not yet migrated the site to a 
linux server and mod_php...  

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



RE: How to measure Array or Hash's byte size ?

2003-04-05 Thread Scott R. Godin
Vincent Bufferne wrote:

> What's about:
> 
> my @foo = ( '1', '2' ,'3' );
> my $size = $#foo + 1;
> print "table size $size\n";
> 
> Ouput:
> table size 3

print "Table size: ", scalar(@foo), "\n";


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



Re: Php perl?

2003-04-06 Thread Scott R. Godin
George Schlossnagle wrote:

> 
> On Friday, April 4, 2003, at 01:56  PM, Scott R. Godin wrote:
>> The question I have is with the current Apache (2.x)
> 
> First off, Apache 2.x is highly beta software.  Almost no-one is
> running it in production.  The questionable thread-safety of many third
> party libraries makes anything but the pre-fork MPM largely unusable
> for most people (php and perl).

Right. The place that I mention below was using 1.3.x .. Whether or not 
Apache 2.x is still not widely regarded as stable, this does not invalidate 
the question. 

>> and mod_perl (1.27?)
>> involved, when a perl program is incorporated into the httpd process in
>> this manner, how much more *memory* overhead does each httpd process
>> require over related circumstances in php?
> 
> Probably more relevant to that is to look at so-called realistic
> performance benchmarks.  When the Yahoo! folks were deciding to swicth
> from their hown-grown scripting language to something more mainstream,
> they did an internal performance bakeoff between a mod_perl solution
> and a mod_php solution.  Properly tuned they delivered almost identical
> performance numbers.  Look up Michael Radwin's 'Making The Case for PHP
> at Yahoo!' talk from PHPCON 2002 for the details.  (It was an
> interesting talk no matter outside of this as well.  An interesting
> take on the differences between language solutions.)

performance speed wise and performance in terms of how much extra memory 
each httpd child requires are different animals. I'll look up the article 
though. should be interesting reading. 

>> for example if I use CGI.pm to create a form (using its functional
>> interface to produce the actual HTML seen) and also respond to said 
>> form, how much more RAM will each httpd process require if this is 
>> run under mod_perl?
> 
> Comparing mod_php to CGI.pm is really apples and oranges.  CGI.pm pages
> result in a high level of intermingling between Perl code and html
> code.The resultant soup looks neither like HTML or Perl.  PHP on

I don't know how you code personally, or what sort of code you encounter, 
but when I code CGI.pm applications the processing sections look like perl 
and the output sections look like html (very much so thanks to CGI.pm's 
function-oriented interface. This also has the VERY nice side-effect that 
all the html closures are provided for and wrapped properly... i.e. it's 
easier to produce well-formed html via this method.) To *me*, the 
intermingling of html and php looks more like soup. 

> the other hand is designed for embedding of code fragments within HTML,
> producing code that still largely looks like HTML.  This allows (but
> doesn't force you) to have as much separation of display logic from
> application logic as you would like.  This isn't PHP FUD, there are
> solutions in almost every language that emulate this behavior:
> 
> Perl: Apache::ASP, embperl (both mod_perl)
> Python: mod_python, mod_snake, mod_psp
> VB: ASP
> PHP: PHP
> ?: ?

true true.

> They've chosen this model because for a huge number of people it's the
> Right Way (tm) to solve the web problem.
> 
>>
>> One argument I've been handed by the php camp is that in a mod_perl
>> situation, this will cause apache processes to become much larger,
>> thereby taking up more of the precious memory resources.
> 
> In my experience that statement is pretty vacuous.  The PHP and
> mod_perl footprints both largely depend on the size of the source code
> base you are running and the number of extensions/packages you use.
> It's hard to get a side-by-side comparison.  And why bother.
> Performance numbers and code maintainability/extensibility are what
> really matter.

Also true. Considering an un-mod_perl cgi accessing a database via DBI will 
run considerably slower than one that is run under mod_perl, and also 
considerably slower than its php counterpart. 

This is one of the things I ran into where the people involved outright 
refused to even consider testing with mod_perl and instead waved specious 
benchmarks around comparing the perl vs the php in completely unrelated 
contexts. It was quite frustrating to nice well-formed scripts thrown out 
because of the lack of support hooks in the httpd process that the 
'opposing' scripts were given. 

>> (consider a large gaming website like planetunreal (which IIRC uses
>> .asp),
>> or quakeworld, which garner huge volumes of hits on a daily basis)
> 
> I've run PHP on a website doing 130 million page requests/day.  I've
> also run Apache::ASP on a site doing 10 million hits per day.  They
> both run fine.  Performance wise, the language-intrinsic differences
&g

Re: Does anyone gets duplicated copies of a message all the time?!

2003-09-08 Thread Scott R. Godin
Ramprasad A Padmanabhan wrote:

> Nelson Wong wrote:
>> Hi all,
>> 
>> I always get three identical copies of a message all the time,
>> therefore, I just wonder if anyone has the same situation as mine!
>> 
>> Thanks!
>> 
>> BTW, it is a great ML!!! Happy knowledge sharing!
>> 
> No, But reading the full headers of both the mails can help.
> 
> I think using nntp.perl.org is a great option. Use nntp instead of
> mails. No sending mails back and forth. Mails typically are relayed
> across many servers before the finally reach the destination thus in
> general cause more wasteful traffic on the net.
> 
>BTW I am saying this because I am a mail server administrator ( And I
> hate to see all newsgroup mails clogging my mail server )
> Typicaly I believe only 10-20% of mails are read by these recipients and
> a waste of bandwidth relaying all mails
> 
> These are purely my opinions , I dont intend to dissuade anyone using
> mail to the list
> 

Personally I think that using a newsreader pointed to nntp.perl.org is a far
more efficient way to read these lists. 

#1 it doesn't clog your inbox and you don't have to sort the mailing list
mails out of your normal mail to more easily keep track of them in a busy
group
#2 the digests and messages also use up more server bandwidth than is
necessary with the groups
#3 it's MUCH easier to both catch up, and follow the various postings if
you're away for a time.
#4 messages use proper threading so it's easier to follow a thread. Mailers
generally destroy the threads and you wind up with posts all over the list
that ARE related but ARE NOT threaded. 
#5 you'll have fewer people replying to a message (which occasionally if
their mailer supports threads) when they INTEND to create a new thread,
which causes their NEW message to appear BELOW a thread that's completely
unrelated to it. If people are ignoring that thread because it doesn't
interest them, they will never see the new message. 

C'mon, how often do you get cheaper, faster AND better, at one swell foop?
:-)


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



Re: Deleting a line that contains certain text

2003-09-08 Thread Scott R. Godin
David Wall wrote:

> 
> 
> --On Saturday, September 06, 2003 7:45 PM -0400 perlwannabe
> <[EMAIL PROTECTED]> wrote:
> 
>> OK, I have a new problem.  I need to delete an entire line that contains
>> certain text.  I have done an extensive search and had no luck finding an
>> adequate answer.  Yes, I also saw the FAQ that just refers me to
>> Tie::file.  The most promising solution was:
>>
>> perl -ni.bak -e 'print unless /FOO/;' input.txt
>>
>> but when I run that line from the c:\ I get the following error:
>>
>> Can't find string terminator "'" anywhere before EOF at -e line 1.
> 
> Windows is weird that way.  Use double-quotes instead of single-quotes.
> 
> 
>> Also, I would like to run this from within a script instead of from the
>> command line.
>>
>> BTW...using PERL 5.8.0 on Windows2000 Pro
> 
> Take a look at 'perldoc perlrun' -- it explains how all the command-line
> options work and give equivalent code.

Perlfaq5 also has a nice tidbit on how to do this while within a script. 

I used this trick recently to do some updates to an existing website where I
needed to move a bunch of images from the main html/ directory to a
subfolder html/images/ *provided* that the images were actually used in the
existing html files; otherwise they should be skipped and left in the dir
so I can move them elsewhere manually.

here's the code I wound up using. Hopefully you'll find this a useful
example. I've commented the code to make things more obvious.


#!/usr/bin/perl
use warnings;
use strict;
$|++;

use File::Glob;
# make these operations fatal if they fail
use Fatal qw( chdir open close rename );
# go here, and scan for jpg images that don't belong here.
chdir "/home/webdragon/webclient/bigbronze/html";
my @jpegfiles = glob( q{*.jpg} );

foreach my $jpegfile (sort @jpegfiles)
{
# find every file that contains the image as a src="filename.jpg"
chomp(my @htmlfiles = qx{grep -l 'src="$jpegfile"' *});
# skip it if we couldn't find any html files referencing this image.
unless (@htmlfiles)
{
print "$jpegfile was not found in any other file\n\n";
next;
}
# tell us about it
print "$jpegfile was found in: @htmlfiles\n";
# quote the expression for the document replacement so we don't 
# have to do this multiple times
my $regex = qr{\Qsrc="$jpegfile"};
# wrap the local magic in a block to keep the scoping sensible
{   
# set a local -i.bak and file list 
# just as if we passed this on a command line to a 
# (perl -pi -e '#code here' filename filename2 filename3) one-liner
# this deep magic lets us edit the files in-place from within this script.
local ($^I, @ARGV) = ('', @htmlfiles);
# more magic with @ARGV
while (<>)
{
# fix the newline for foreign files as long as we're here
s#\015\012|\015|\012#\n#;
# fix our image location to the subdirectory where we really want them
s#$regex#src="images/$jpegfile"#;

print;
# resets $. using yet more ARGV filehandle magic. nifty trick, this.
close ARGV if eof;
}
print " -- edited @htmlfiles\n";
}
# move the image too! 
rename "$jpegfile", "images/$jpegfile";
print " -- moved $jpegfile to images/\n\n";
}

__END__

now, you'll note that here I used -i rather than -i.bak since with 900 of
these images referencing 250 html files, you wind up with
blah.htm.bak.bak.bak.bak or blah.htm.~.~.~.~.~.~ and swiftly hit a filename
size limitation in your OS after a very short bit. so I used a few 'last'
statements to test it on ONE file, and then removed the backup stuff and
had it run in-place with $^I set to '' instead. 

HTH!

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



Re: stupid question

2001-11-17 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Chris And Madonna Stalnaker) wrote:

>   $password eq ;

eq is a comparison operator not an assignment operator.

you meant

$password = ;

always start your scripts with either 

#!/path/to/perl -w
use strict;
# ...

or under Perl 5.6.1

#!/path/to/perl 
require 5.006;# not mandatory here, but the line below does require 5.006
use warnings;
use strict;
# ...

and you'll avoid silly mistakes like this. :-)

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: CGI.pm questions

2001-11-18 Thread Scott R. Godin

In article <3827643.100599@[10.0.0.140]>,
 [EMAIL PROTECTED] (Birgit Kellner) wrote:

> I want to use CGI.pm to parse form input and store all name/value-pairs in 
> a hash.
> 
> At present, the code I have reads like this:
> 
> my $in = new CGI;
> my %in = &parse_form;
> 
> sub parse_form {
> 
> my @names = $in->param;
> foreach my $name ( @names ) {
>   if (param($name)) {
>   $in{$name} = $in->param($name);}
>   }
> foreach my $key (keys %in) {
>   if ($in{$key} eq "---") { # if this is a select field with no value 
> selected, it will have the value "---"
>   delete ($in{$key});
>   }
>   }
> return (%in)}
> 
> There are two cases where I run into problems with this code:
> 
> - multiple select fields. I guess storing all names in @names gets rid of 
> duplicate instances of names; at any rate, there are only unique array 
> elements in @names when the foreach loop loops over them. The problem is 
> that I won't know the names of the multiple select fields in advance, so I 
> can't do something specific with them. I thought of adding a hidden input 
> field to the form, with the name "multiple" and the value of the multiple 
> select field. Then I could first parse this field and, if it has a value, 
> treat the multiple select field differently from the other fields. (Implies 
> that I can only have one multiple select field per form, but that's fine.)
> 
> - there are forms where I have a text input field named "fieldname" and a 
> select field with the same name. Users are to select an item from the list 
> or alternatively, if the item does not occur in the list, enter a new 
> value. What the parse_form *should* do is ignore names without values from 
> the start, and not read them into @names and *then* check whether they have 
> values.
> 
> Thanks a lot for any advice,
> 
> Birgit Kellner
> 

look in cgi_docs.html (comes with CGI.pm when you install it.. check in 
the .cpan directory or wherever you installed it)

under Creating a New CGI Query Object, there's the sub-header "Fetching 
the Parameter List as a Hash" which has the details you need.

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: PERL Debugging

2001-11-18 Thread Scott R. Godin

In article <005301c16fae$563b3d00$[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Sherri) wrote:

> Can anyone please tell me what this error means:
> 
> syntax error `(' unexpected
> 
> Is it that I am not supposed to be using "(" ever in my programs, because 
> almost everytime I have a program that needs something to be enclosed in "( 
> )" it has a syntax error with the "(".
> 
> Any assistance would be gladly appreciated.

start with more detailed error messages

use diagnostics -verbose; #disable this for production code.. it's hefty

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: CGI.pm problems continued

2001-11-20 Thread Scott R. Godin

In article <56313003.1006216242@[10.0.0.140]>,
 [EMAIL PROTECTED] (Birgit Kellner) wrote:

> I have tried the following code to read a query-string from a CGI request 
> into a hash, taking into account (a) multiple select fields without knowing 
> the field name, (b) getting rid of names without values, and thereby, 
> hopefully, (c) allowing for user input alternately through a text field or 
> a select list, (d) getting rid of select fields where no selection was 
> made, in which case the value will be "---".
> 
> This is the code I used:
> 
> #!/usr/bin/perl
> use CGI qw(:standard);
> use CGI qw(:cgi-lib);
> my $q = new CGI;
> my %in = &parse_form;

#!/usr/bin/perl -w
use strict;
use CGI 2.78 qw(:standard :cgi-lib -no_xhtml);
# if this errors, remove the 2.78
# what version of CGI.pm does your server have? 
print $CGI::VERSION, " CGI.pm installed\n";
my $q = new CGI;
my $in = $q->Vars;# reference to hash

print "Param 'foo' is ", $in->{'foo'}, "\n";
print "Multivalued param 'bar' contains ";
my @bar = split("\0", $in->{'bar'});
print join "\n\t", @bar;
print "\n";
print "Param 'baz' ", defined(param('baz')) 
   ? " is ", $in->{'baz'}, "\n" 
   : " is undefined\n";

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Command Line arguments.

2001-11-21 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Nicolae Popovici) wrote:

> Hi guys,
> 
>  Can anyone tell me how can I take the command line arguments in a perl
> script . I forgot how to do it .
> Thanks for your support .

Couple ways. 

process a loop around @ARGV...

work with the Modules like Getopt::Std, or Getopt::Long...

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: extracting *just* matched text

2001-11-22 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Waspcatcher) wrote:

> hi,
> how does one extract *just* the matched text in a regular expression,
> e.g.
> 
> my $text = "Hello 1234, come in";
> if ($text =~ /\d{4,4}/)
> {
> #grab just the 4 digit number
> }
> 
> thanks
> 
> 

if ( $text =~ /(\d{4,4})/ )
{
print "captured $1\n";
}

parens around what you want to capture, and each paren group is from 
left to right, stuffed in $1, $2, $3, etc.

see
perldoc perlre 
for examples

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Name of current sub?

2001-11-22 Thread Scott R. Godin

In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Chuck Tomasi) wrote:

> I find myself writing this sort of thing a lot:
> 
> print STDERR "program.pl: subname(): debug statement\n";
> 
> I know $0 can be used for programname.pl (except it returns the full path to
> the program), is there some cool variable to get my hands on the name of the
> current sub?
> 
> --Chuck

perldoc -f caller

the croak and confess portions of the Carp module are also useful. 

perldoc Carp

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: CGI.pm problems continued

2001-11-21 Thread Scott R. Godin

In article <3852920.1006256205@[10.0.0.140]>,
 [EMAIL PROTECTED] (Birgit Kellner) wrote:

> Sorry for being stubborn, but I' like to decode multivalued parameters 
> *without* identifying them by name.
> That's precisely why reading multiple values into an array is not 
> applicable.

that depends on how you wish to detect said multivalued parameters, does 
it not? :-) 

> Is it possible that, when I do "my %in = $q->Vars" (should be "%in", not 
> "$in", shouldn't it?), %in contains not the actual names and values, but 

well if you do it as $in, it passes a reference. if you do it as %in, it 
passes the hash. I tend to find the referenced value more 
straightforward to work with when using the object-oriented CGI.pm 
interface, it being similar. 

> only references, and that that's why any subsequent attempts at deleting 
> key/value-paris are unsuccessful?

wouldn't it be simpler and easier to merely ignore the parameters you 
don't want? :) 

foreach my $key (keys %{$in}) 
{
next if $key =~ /submit/i;
next if $in->{$key} =~ /^---$/;
#... 

if you're unused to working with references, by all means use %in, but 
you'll find the similarities between the objects to be *very* similar to 
how CGI works with objects, and also a few peeks at perlref, perllol, 
perldsc to be of enlightening proportions.

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Getting past "Use of uninitialized value..."

2001-11-22 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Etienne Marcotte) wrote:

> I have:
> 
> my $q = new CGI;
> $q->import_names('IN');
> 
> my $ID = lib::auth_user($IN::UsrName,$IN::UsrPass);
> 
> sub auth_user returns a session ID kind of data.
> 
> $IN::UsrName and $IN::UsrPass are used only once and gives warnings.
> 
> Etienne
> 

I noticed that and used something like this to get around that.

# set up major input/output variables in such a way that it supresses 
# "used only once" warnings for the variables brought in via the 
# import_names() sub, but also keep some main-only vars separate from 
# the dupes to cut down on memory usage. 
BEGIN {
@main::globals = 
  qw($mapname $author $author_first $author_nick $author_last 
 $version $release_date $filename 
 $last_update $email $website_url $website_name $credits 
 $other_levels_by_author $gametype $bot_able $single_player 
 $teamplay $difficulty_settings $new_sounds $new_textures 
 $mutators $mods $construction_base $build_time $editors_used 
 $ext_description $known_bugs $mod_type $mod_description 
 $authors_notes $game $weapons $power_ups $new_music 
 $num_playerstarts
);
}
# this takes advantage of the fact that use vars is looking for 
# list context
use vars @main::globals, 
 qw($internal_comment1 $style $namefill $output_path $htmlout 
$textout @htmldata @textdata $current_date);

# the namespace used will be ' import_names("UT"); ' later in the script
package UT; # slip into the package

   # and slide in our 'globals' that get imported to that namespace
   use vars @main::globals; 

package main; # then slide back out to main again. 

a semi-slick workaround for a semi-ugly problem. supresses all those 
'used only once' warnings quite nicely though.

-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Split

2001-11-27 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Daniel Falkenberg) wrote:

> Hey all,
> 
> I have a problem here that I don't really know how to go about.
> 
> Basically I want to be able to find a user in the  /etc/passwd with only
> a GID of 45 and a username of what I type the user name to be.
> 
> test5:x:503:503::/home/tunnel:/bin/bash
> test:x:504:45:Test Account:/home/test:/bin/false
> test4:x:506:505:test Account:/home/test4:/bin/false
> test2:x:507:45:Test Account:/home/test2:/bin/false
> daniel:x:508:45:Daniel Merritt:/home/daniel:/bin/false
> 
> As we all know the Unix /etc/passwd file looks like the above...
> 
> Now with the following I want to be able to only find the user name that
> has a GID of 45 and make sure the username exists in /etc/passd in the
> first place.
> 
> #!/usr/bin/perl -w
> 
> $user = "daneilson";
> $file   = '/etc/passwd';
> 
> open PASSSWD, "$file"  or die "Cannot open $file for reading :$!";
> #Store /etc/passwd as a file
> while ( $lines = ) {
>   #split the /etc/passwd file at every colon and store it as an
> array.
>   @lines = split (/:/, $lines);
> }
> 
> #Now for the fun part...
> #Here I need to be able to search through @lines for the username I
> enter $lines[0]
> #if $user is not found then I need to report an error
> #else if $user is found then I need it to check that it has a GID of 45
> and if it doesn't
> #then I need to report another error.

try this for starters (tested)

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

my $usrname = $ARGV[0] || 'daneilson';

open(PASSWD, '<', '/etc/passwd') 
or die "Unable to open /etc/passwd: $!";

#dunno how big it is so let's line-by-line it
my $found = 0;
while ()
{
chomp;
my @line = split /:/;
if ( (lc($line[0]) eq lc($usrname)) && ($line[3] == 45) )
{
++$found;
print "Found [$found]:\n\t", join("\n\t", @line), "\n";
}
}

if ($found)
{
print "Total records found = [$found]\n";
}
else
{
print "No records were found that matched\n";
}
__END__
=pod
delete the use warnings; line and use the simple -w switch as in

#!/usr/bin/perl -w 

if you don't have 5.6.0 or later on your system, and also change the 
open line to the 2-argument version like so:

open(PASSWD, '< /etc/passwd') 
    or die "Unable to open /etc/passwd: $!";

you do realise, of course, that you could get similar results with 

cat /etc/passwd |grep "username" |grep ":45:"

right? 
=cut

The problem with sharks is that they are too large to get to the shallow end of the 
gene pool :P
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Trouble installing modules with CPAN, or changing @INC

2001-11-27 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Kevin Zembower) wrote:

> I have a program that requires Mail::Mailer.pm. When I try to run it, I
> get:
> www:/usr/local/httpd/cgi-bin # ./mail2friend.pl 
> Can't locate Mail/Mailer.pm in @INC (@INC contains:
> /usr/lib/perl5/5.6.0/i586-linux /usr/lib/perl5/5.6.0
> /usr/lib/perl5/site_perl/5.6.0/i586-linux /usr/lib/perl5/site_perl/5.6.0
> /usr/lib/perl5/site_perl .) at ./mail2friend.pl line 45.
> BEGIN failed--compilation aborted at ./mail2friend.pl line 45.
> 
> However:
> www:/usr/local/httpd/cgi-bin # find / -name Mailer.pm
> /root/.cpan/build/MailTools-1.41/Mail/Mailer.pm
> /root/.cpan/build/MailTools-1.41/blib/lib/Mail/Mailer.pm
> /usr/local/lib/perl5/site_perl/5.6.1/Mail/Mailer.pm
> 
> So, it seems to me that what's happening is that CPAN installed
> Mail::Maker in a directory that's not being searched in the @INC array.
> 
> When I try to install it using CPAN, I get:
> www:/usr/local/httpd/cgi-bin # perl -MCPAN -e "install Mail::Mailer"
> ...
> Mail::Mailer is up to date.
> 
> This also happens if I force install. Previously, I had entered "o conf
> make_install_arg UNINST=1" so I believe that this should uninstall the
> module, then reinstall it. [Tangent: How do I check to make sure this
> variable is still correctly set?]
> 
> 
> My questions:
>   How do I control which directory CPAN installs a module in? Is it a
> good idea to force this?
> Or:
>How do I change the directories in @INC? Is it a good idea to force
> this?
> 
> Thanks in advance for your help.
> 
> -Kevin Zembower

it installed it in your /usr/local directory.

/usr/local/lib/perl5/site_perl/5.6.1/Mail/Mailer.pm

simply add the line 

use lib '/usr/local/lib/perl5/site_perl/'; # usually

but in this case you may have to add the 

use lib '/usr/local/lib/perl5/site_perl/5.6.1/';

typically one tells the cpan shell to use ~/perl/ for the individual 
users stuff, but you can reconfigure CPAN to install it where you want. 

check the options under 

perl -MCPAN -e shell
and enter a '?' at the cpan> prompt for help, and 'o conf' to see the 
config options for CPAN's shell.

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Perl Versin

2001-11-27 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Purshottam Chandak) wrote:

> Is there a major difference between the Perl at Perl.com and Active Perl?
> 
> Pc

ActiveState's Perl has been set up with Windows in mind. If you need to 
run Perl on a Win32 platform, then ActiveState's your place to be.

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




'vacation'

2001-11-27 Thread Scott R. Godin

has anyone implemented a 'better version' of the vacation program for 
themselves? 

I'm particularly interested in 'screening' the bulk-mail type messages 
that list me in their "bcc:" header so that my address does not show up 
in the "from:" or "cc:" address listings, thus preventing 
/usr/bin/vacation from triggering and sending the response. =:P (fat lot 
of good that does me)

I've noticed that near 99% of the spam I receive uses this method to 
mask it from reciept, so typically I filter this with my mailer into a 
dumping ground, but the sheer amount of spam lately (235 items since Nov 
5th) has caused me to form a desire to tackle this more forthrightly and 
aggressively. 

Ideally, it should return the offending mail to postmaster@* (where * is 
the supposed 'from' address) to report the abuse, and include a full 
copy of the original message including headers (along with a nice terse 
little message regarding the laws involved). Additionally it would be 
nice if it could forward the spam to my OWN postmaster for additional 
reportage and filtering at their end.  

I'm quite unsure how to go about this. I'm loathe to start messing with 
it without some direction, against the possibility of perhaps breaking 
things or doing it VERY wrongly and seriously pissing off my own 
postmaster hehe ;) without some starting point references to work from, 
and I don't have a testbed here to play with, until my friend finishes 
the work on the redhat box he's been tossing together for me in his free 
time. :-) 

Can you kind folks offer some pointers to me as to how I can go about 
such a task, and what would be some of the traps and pitfalls to avoid 
(of which I'm quite sure there are many) in the process? 

I'm very anxious to get back at these spamming bastards somehow, as this 
intrusion into my personal e-mail is MOST unwelcome, and I've got a 
growing passion to stamp out this *expletive deleted* practice as often 
as I can. 

Hitting them where it hurts with *minimal* manual intervention, seems 
the best way. >;D

I've considered also, the possibility of stuffing them in a database, 
and then periodically checking it interactively with the program, and 
triggering 'bounce' type messages to said postmasters on a specific 
basis -- as this way I don't auto-trigger "I'm-annoyed-by-your-spam" 
responses for *legitimate* 'bcc' messages.

 something sort of like an 
$ ~/bin/vacation.pl -X (where X will be whatever flag I decide on to 
enter the database processing stage)

You have (n) messages in your holding cell. Proceed? (y/n) _

Enter a Selected line number, or 'a' for all. [#/a] _

Preview, Accept, Bounce, Delete [p/a/b/d]? _
(if Preview is selected)

Accept, Bounce, Delete, 
Mark-this-Entire-Domain-as-SPAM-source-for-all-time-and-bounce-and-report
-all-instances :D [a/b/d/m]? _m

Domain 'btamail.net.cn' Captured. OK?
: _

(where (A)ccept could possibly add the From address to a list of 
acceptable e-mails that get passed through automatically from then on. 
:-) as well as passing the mail on to my proper inbox, just like a 
\$user in my .forward file would.

this is just a stray shell account, that I retain around on my prior ISP 
for testing purposes, perl-wise, and in case some people still haven't 
upgraded their addressbooks, so delaying the mail a bit won't kill me. 
(particularly considering the volume of spam it's recieving lately) I 
don't even get 1/20th the amount of spam to other accounts I have. :/

With enough pointers, I think I can complete the beastie -- I mean I DO 
have a pretty complete 'vision' of what I want. :-) I just need some 
pointers on how to get there. I'll happily contribute this pup to the 
CPAN scripts archive if I can get it working exactly the way I want it 
to. I'm SURE some of you could find a use for it. ;) 

Your thoughts and contemplations are anticipated with great desire and 
gleeful hand-rubbings and evil-grinning eyebrow-wagglings to "Make it 
so."

If stuff like this isn't one of the things that makes Perl so "fun" I 
dunno what is. :D 

(note that while I'm sort of broad-casting my initial hopes on this to 
four groups on perl.org (perl.scripts, perl.beginners, 
perl.macperl.anyperl, perl.fwp), I'm confining responses (via reply-to 
and followup-to) to 

[EMAIL PROTECTED] 
aka nntp://nntp.perl.org/perl.scripts/ 

to consolidate things and reduce the required effort of following this 
thread to a single track. I hope this is the proper way to go about it 
-- despite years of experience with cross-posting on usenet, this is the 
first time I've thought about doing such a thing on a group that was 
also mirrored out as a mailing list. :\ Apologies and if th

Re: Split

2001-11-28 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (John W. Krahn) 
wrote:

> > my @line = split /:/;
> > if ( (lc($line[0]) eq lc($usrname)) && ($line[3] == 45) )
> ^^  ^^
> This won't work if a user name has upper case letters, for example I
> just created these two accounts:
> 
> # cat /etc/passwd
> [snip]
> roger:x:5001:100:Roger 1 Test:/home/roger:/bin/bash
> Roger:x:5002:100:Roger 2 Test:/home/Roger:/bin/bash

mmm true.. I'd forgotten about that. 

You catch that, Daniel?

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Sorting a Hash

2001-11-29 Thread Scott R. Godin

In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Dale Pellerin) wrote:

> I am very new to hashes (as well as Perl) and am having some difficulty with
> a cgi script.  This script allows individuals to post "announcements" via a
> form.  The form data is stored in a text file, sorted in descending order by
> date, and printed to the html page.  However, the script is currently
> sorting by the month and not by the year, thus creating a problem when news
> items are posted from 2002. (01/01/02 news items are being printed below
> 12/01/01 news items)
> 
> Here is a sample of the text file that the data is stored in:
> 
> http://is-blah.com/corprate/pages/news/cafeteria_closed.htm ~ 10/24/01 ~
> Cafeteria closed
> 
> Here is  a snippet of code from the cgi script that sorts the file:
> 
> # Hash to sort date
> $from = "tmc.dat";
> my %h;
> 
> open(FILE, "$from") || die "Can't open $from!\n";
> while () {
>chomp;
>($announcement,$date,$description) = split(/~/,$_);
>
># if the date has already been seen, tack this entry on to the hash value
> if( $h{$date} ){ 
> $h{$date} .= "|$announcement~$description";
> }
> 
> # date hasn't been seen, so create a new hash entry
> else
> {
> $h{$date} = "$announcement~$description";
> }
> }
> 
> #sort the dates in desc. order
> foreach $key (sort {$b cmp $a} keys %h)
> {
>#do for each item for that date
> @items = split '\|', $h{$key};
> foreach $item (@items)
> {
> #split back out the values and print the table
> my($announcement,$description) = split /~/,$item;
> print "";
> print " src='http://is-web/corprate/gifs/blueball.gif'>";
> print " href=\"$announcement\">$description( color=black> $key)";
> print "";
> 
> I would appreciate any assistance in figuring out how to sort by year, then
> by month.  

Child's play. Under the "Efficiency" secion in the Camel[1], there is a 
section that reads:

"Sorting on a manufactured key array may be faster than using a 
fancy sort subroutine. A given array value  will usually be compared 
multiple times, so if the sort subroutine as to do much 
recalculation, it's better to factor out that calculation to a 
separate pass before the actual sort."

... and at this point tiny little bells should be going off in your 
head. :-)

right around here: 

use POSIX qw/strftime/;

> while () {
>chomp;
>($announcement,$date,$description) = split(/~/,$_);
>

my ($mon, $day, $yr) = split /\//, $date;# non european date
$date = strftime("%Y/%m/%d", 0, 0, 0, $day, $mon - 1, $yr + 100 );
#or
#$date = strftime("%y/%m/%d", 0, 0, 0, $day, $mon - 1, $yr );

then the date will sort by, say, 2001/10/24 or 01/10/24 although I argue 
for the former and not the latter.

I've had to do similar things when converting an old database to MySQL's 
DATETIME format. -MM-DD 00:00:00

I'd suggest reformatting those dates if it all possible, and not too 
inconvenient. A true database would in the long run be better, if such 
can be arranged (IMHO).


[1]Programming Perl, both 2nd and 3rd editions mention this

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Getting rid of hash values I don't want..

2001-11-29 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Daniel Falkenberg) wrote:

> Hey all,
> 
> Currently I am working on the Linux /etc/passwd file.  Now I want to be
> able to split the /etc/passwd file for example...
> 
> tunnel:x:503:503::/home/tunnel:/bin/bash
> test:x:504:50:Test Account:/home/test:/bin/false
> test2:x:507:502:Test Account:/home/test2:/bin/false
> daniel:x:508:45:Thats Me:/home/daniel:/bin/false
> *test6:x:509:45:Test Account:/home/test6:/bin/false
> 
> Now I have no trouble actually splitting the file but what I really want
> to do is have all the values of $lines
> 
> $file = '/etc/passwd';
> 
> open PASSWD, "$file" or die "$file: $!\n";
>  while ($lines = ) {
> @lines = split (/:/, $lines);
> if ($lines[3] == 45 ) {
> #Store all users and their gids in a hash!
> $users{$lines[4]} = $lines[0];
> }
>   }
> close PASSWD;
> 
> foreach $fullnames (keys %users) {
> print $fullnames, "\n";
> }
> 
> foreach $usernames (values %users) {
> print $usernames, "\n";
> }
> 
> Why is it the hash doesn't insert all the keys and values.  I get a
> result that is complety wrong. Such as the following...
> 
> %users = (
>'Test Account' => 'test6'
>  );
> 
> This is about all I get.  When we all know very well that the file
> ($file) contains alot more users with a GID of 45.  Can some one point
> me into the right direction as to what I am doing wrong here?

that's possibly because you're not using my

try 
while (my $lines = ) {
my @lines = split (/:/, $lines);
 foreach my $fullnames (keys %users) {
 print $fullnames, "\n";
 }
 
 foreach my $usernames (values %users) {
 print $usernames, "\n";
 }

Make sure you have 

use strict; 

at the top of your program and it will help catch things like this. 

also I'd suggest using the username as the key and reversing the meaning 
of the above two foreach statements

$users{$lines[0]} = $lines[4];

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: Using CGI locally

2001-11-30 Thread Scott R. Godin

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Clive Lansink) wrote:

> I know that when I call up a local HTML file from within Internet Explorer it 
> works and renders the HTML correctly.  Now is there a way to directly call 
> Perl from within IE to create active HTML which is then rendered by IE or can 
> this only be done with a web server of some sort.  There must be a way to 
> specify a URL which can cause Perl to generate HTML on the fly for IE to 
> render.  I simply want to do this locally so is there a way to do this?  I 
> feel sure this should be possible.

You need to have some sort of web-server running that's capable of 
processing CGI scripts. 

MacPerl 5.20r4 offers the built-in capability of creating a small cgi 
application that runs on the Mac even under Apple's built-in websharing 
control-panel environment, provided the script and necessary processing 
are small.. (larger needs overrun the basic limits, and would be better 
served with a more robust solution anyway. :)

then you simply point localhost at it with 
http://127.0.0.1/cgi-scripts/your.cgi

I sometimes use this for testing basic stuff with until I start hitting 
the memory limitations due to my needs. I haven't bothered setting up a 
full webserver package since I have a shell readily available for 
testing these with. (and will soon have a redhat unix box of my own set 
up for this specific purpose...banging on my scripts until I'm sure they 
stand on their own and don't beat up the server.  :)

You could install a webserver on your windows box. You could dual-boot 
unix and run your own server that way. Lots of options. Lots of initial 
configuration overhead too, but once you get that out of the way, you're 
off and running.

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




Re: open FILE, "+ (was :

2001-11-30 Thread Scott R. Godin

In article <002201c1796e$55b9fbe0$5947a9cb@nothing>,
 [EMAIL PROTECTED] (Leon) wrote:

> - Original Message - 
> From: "Johnson, Shaunn" <[EMAIL PROTECTED]>
> > open (FILE, "+ 
> I was just wondering, what is that + sign for.

perldoc -f open

third paragraph.

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin| e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

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




  1   2   >