Re: Any ideas [on how to redirect STDOUT to an array]?

2002-11-02 Thread Daniel Gardner
Dr. Poo wrote:
> What i am trying to do is set up a very rudimentary logging system. I want
> to log everything that is directed to STDOUT. And the way i'd like to try
> to do this is have an array declared that will "read" STDOUT and store the
> contents to the array rather than print them to the screen. (or they can
> go to the screen too... but i'd rather them not.)

There's loads of logging modules on CPAN, I've been using Log::Dispatch 
lately, and that seems to work well.

As for sending STDOUT to a scalar, you can use tie...

,[ sample ]
| package Catch;
| our @buffer;
| 
| sub TIEHANDLE {
| return bless {}, shift;
| }
| 
| sub PRINT {
| my $self = shift;
| push @buffer, @_;
| }
| 
| package main;
| 
| tie *STDOUT, 'Catch';
| 
| print "hello";
| print "foo";
| 
| my @contents = @Catch::buffer;
| 
| print STDERR @contents;
`

That might do what you want...

> PS. To the ones who do most of the answering and helping on this list...
> How many years (roughly) have you all been "perling"? Cause i'd really

I don't do most of the answering, just drop in every now and again, but 
commercially roughly 5 or 6 years.


--
Daniel Gardner


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




Re: How fatalsToBrowser works ?

2002-08-16 Thread Daniel Gardner

> I am on a Win32 system, and  I use the fatalsToBrowser to prompt errors
> with some scripts. However, the error mesg will also prompt where exactly
> the file(script) is located. In case, I don't want the full path is
> exposed. Can I modify sth , perhaps regex s///, to mask the root path ?
> 
> like :
> File not found : html/log/connie.txt at C:\WWWroot\CGI-ALL\index.pl line
> 12.
> 
> is better be masked as :
> File not found : html/log/connie.txt at /index.pl line 12.
> 
> Is that possible ?

Interesting... Looking at the CGI::Carp source, there seems to be some 
undocumented functionality. It looks like you can define a variable 
$CGI::Carp::CUSTOM_MSG, which can either be a message or a coderef.

I haven't tested this, but by the looks of things something like this might 
work for you:

,[ code ]
| use CGI::Carp qw(fatalsToBrowser);
| BEGIN {
|$CGI::Carp::CUSTOM_MSG = sub {
|   my $msg = shift;
|   $msg =~ s/C:\WWWroot\CGI-ALL//;
|   
|   print STDOUT $msg;
|};
| }
`

As I said, untested, and undocumented as far as I can see. So who knows if 
it'll actually work.

Thanks,
Daniel

-- 
Just wanna dance the night away
With senoritas who can sway

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




Re: possible RFC?

2002-08-15 Thread Daniel Gardner

Nikola Janceski wrote:

> WTF doesn't perl -c check for valid subroutines/function calls?
> 
> I can write a perlscript calling a function that doesn't exist but perl -c
> will say syntax ok.
> ie:
> % perl -ce "nothing_here('some junk')"
> -e syntax OK
> 
> % perl -e "nothing_here('some junk')"
> Undefined subroutine &main::nothing_here called at -e line 1.
> 
> That doesn't make sense!
> It should check function calls at compile time, correct?
> So why not for -c?

I'd hazard a guess it's to do with it sometimes being hard to tell if a 
function does exist or not at compile time. Think AUTOLOAD and string eval.

Thanks,
Daniel



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




Re: word count (limit) in a scalar...

2002-07-16 Thread Daniel Gardner

Anthony E. wrote:

> i have a bunch of text in a scalar $text
> How would I keep the word count to a maximum, and just
> dump the rest.. ie - I only want the paragraph to
> contain 500 words, and trash the rest.

I know this isn't exaclty what you asked...

I'm taking a wild guess and thinking that what you want to do is show some 
sort of summary of various documents, and 500 words is a good size for a 
summary.

If that's the case, then I would avoid the overhead of splitting and 
joining by simply taking the first n characters of the string, where n is 
about 500 words worth of characters.

Assuming the average word has 6 characters in it:

,[ code ]
| my $summary_size = 6 * 500;
| my $summary = $start_text;
| $summary = substr $start_text, 0, $summary_size
|   if (length($start_text) > $summary_size);
`

Of course it all depends what you want to use the data for.

--
Best Regards,
Daniel


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




Re: Perl constants with modules

2002-07-16 Thread Daniel Gardner

Kevin Old wrote:
 
> I am writing a script for a client and they have requested an easy way
> to configure their script.without having to enter the script code
> itself.


> Second, which sytax (in your opinion) should I use?
> 
> $CDMA::USER = "myusername";
> 
> or
> 
> use constant USER => "myusername";
> (called like CDMA::USER.correct?)
> 

Personally, I quite like use constant. I've got quite a few scripts 
configured at the top with constants - data directories, that sort of thing.

The advantage over variables is that these things are obviously constants, 
and you can't go changing them in your code. It makes it easier for 
mainanance programmers to see what's going on.

If it's just a one-off script, and these variables aren't going to be 
needed by any other script you write, then throw a few constants at the top 
of the script. If you've got more complicated configuration to do, then 
check out some of the config modules off cpan - there's loads of them.

And don't underestimate the power of using perl data structures for 
configuration. Data::Dumper and eval might help you out.

--
Best Regards,
Daniel

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




Re: Trapping "Ctrl C"

2002-07-15 Thread Daniel Gardner

Max Clark wrote:

> I'm looking for a way to run an operation (like a while (<>) loop for
> example) until the user presses "ctrl-c". Except instead of ending the
> perl script I want to trap the "ctrl-c" and present the user a menu of
> options.
 
This is very minimal:

,
|   $SIG{INT} = sub { warn "ctl-c pressed!\n" };
|  
|   while (1) {
| print "hi\n";
| sleep 1;
|   }
`

If you run that it'll print "hi" forever, and a message when you press 
ctl-c. You'll have to kill it to stop it (something to think about)

Try "perldoc -q trap signals" also, as well as the docs Paul pointed you at.

--
Best Regards,
Daniel

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




Re: System commands..

2002-07-15 Thread Daniel Gardner

Vishal Kapoor wrote:

> thanx for the previous help 
> can we use system commands in a perl program , commands such as ls or grep
> 
> im sure we can , can someone point out how ???

You don't often see it mentioned, but there is a core module called 
Shell.pm - try perldoc Shell to see what it does.

Haven't used it myself, but by the looks of things it does just what you 
want. 

--
Best Regards,
Daniel

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




Re: capture out put from piped process

2002-07-15 Thread Daniel Gardner

Jon Howe wrote:

> How do I capture the output from sendmail running under the -v switch back
> to my programme.
> 
> The line I am using is -
> 
> open (MAIL, "|/usr/lib/sendmail -oi -t -v") or die "cant fork proc to
> mail\n";

perldoc IPC::Open2

IPC::Run on cpan can do some clever stuff too
 
--
Best Regards,
Daniel

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




Re: Serial Comms with Perl

2002-07-15 Thread Daniel Gardner

Gary Stainburn wrote:

> I've got a perl script that takes text input from our switchboard and
> feeds a call logging database.
> 
> Currently, I have a BASH script that calls kermit to control the serial
> port
> and pipe the output to my perl script (shown below).  However, this causes
> admin problems - especially the kermit process - when having to restart
> etc.
> 
> What's the best way to do the whole process in my perl script?
> I will need to lock the port (create lock file LCK..ttyS0) - no problem.
> I will then need to configure the port settings and then open the port for
> input so that I can read from it.


Does Device::SerialPort help?

http://search.cpan.org/search?dist=Device-SerialPort
 
--
Best Regards,
Daniel

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




Re: How to use one sub in a perl package?

2002-07-14 Thread Daniel Gardner

Drieux wrote:
> 
>> I should have mentioned that the package does an import in main.
> 
> what exactly do you mean by 'import in main'?
> 
> this sounds way strange...
> 
> could you provide us with illustrative code here.

I presume what the OP meant was that the module has an import() subroutine 
which perhaps messes about with namespaces and fails if it's dependencies 
are not met.

I may be wrong, but you might be interested to read up on the differences 
between "require" and "use" - what use actually does and when. It's quite 
enlightening.
 
--
Best Regards,
Daniel


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




Re[2]: How to use one sub in a perl package?

2002-07-14 Thread Daniel Gardner

Sunday, July 14, 2002, 5:18:14 PM, chris wrote:

> I should have mentioned that the package does an import in main. This
> will make it harder if not impossible to work around. 

> Using the sample provided

>>   use DTK::WebAccess;

> This will cause the import to occur leading to compile errors. Am I
> reading this correctly?

Does doing a require work, so that the import isn't called?

If it's just the import that causes the failure you should
be able to require and then use whatever subroutines are in
there by fully qualifying the package name.

HTH,
Daniel




> Thank you for your time.

> On Sun, 14 Jul 2002 08:03:27 -0700, [EMAIL PROTECTED] (Drieux) wrote:

>>yes and no
>>
>>first the 'no side' - since you may need to 'get the code up
>>and running now' = you can Work Around the problem by fully
>>qualifying the path to the function - as it were
>>
>>I have used the trick of
>>
>>   use DTK::WebAccess;
>>   ...
>>   DTK::WebAccess::dtk_openSocket_to_webPage( $host, $port, $fd);
>>
>>and
>>
>>   use DTK::WebAccess qw/dtk_openSocket_to_webPage/;
>>   ...
>>   dtk_openSocket_to_webPage( $host, $port, $fd);
>>
>>in places - depending upon whether I am more or less angst
>>ridden about remembering WHERE a 'function' came from
> 




-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: About Perl OO Orthodoxy

2002-06-30 Thread Daniel Gardner

Sunday, June 30, 2002, 5:57:23 PM, drieux wrote:

I don't know if it's just me, but I didn't really understand
what you're actually trying to achieve...

> Ok, so let's start with the simples stuff, I'm not God's
> brightest child - so I tend to try stuff, and argue with
> myself about whether or not a thing makes sense. Here is
> the basic problem.

> I need to have a base class

> FOO::BAR

> from which I will have a secondary class

> FOO::BAR::BAZ

> but for 'political Reasons' I want to have
> a new class that is 'derived' from FOO::BAR::BAZ
> but it needs to be 'hung' ass

> FOO::BAR::BOB

This sounds straightforward:

  package FOO::BAR::BOB;
  use base 'FOO::BAR::BAZ';

> So while muddling this affair I opted to do the following
> trick in the FOO::BAR class package:

> # our private defaults - things starting in a Capital
> # are 'public' elements, things in 'lower case', should
> # NOT be messed about by anyone but this module...
> # caveat emptor

But then you start mentioning public and private variables,
and other things.

> our %def =(
> Exposed_A => undef,
> Exposed_B => 666,
> Exposed_C => 'frodo',
> private_fd => undef,
> );

> #
> # So that we have a way to redefine our Values.
> sub redefine {

What is this "redefine" supposed to do?


> my $me = shift;

> if ( @_ % 2 ) {
> $me->{'Exposed_A'} = shift;
> # only suppose to hand me the Single Arg...
> die "Odd Number of args passed to redefine: @_ \n" if @_;
> } else {
> # this seems to be required to allow sub_classing
> # hence we can not get away with some of the dope we have 
>done
> my %hash = (@_);
> while( my ($k,$v) = each %hash ) {
> if ( $k eq 'fd' ) {
> me->CloseOut() if defined($me->{private_fd});
> $v = undef unless ( ref($v) eq "PRIVATE::TYPE");
> }

And what's a PRIVATE::TYPE?

Perhaps some more explanation about what you're trying to
do here would be useful.


--
Best Regards,
Daniel   [EMAIL PROTECTED]


> $me->{$k} = $v ;
> }
> }
> $me->{private_fd} = new PRIVATE::TYPE
> unless defined $me->{private_fd};

> } # end of redefine

> #
> # so that the NEW remains almost as virgin as possible

> sub _init {
> my $me = shift;

> # load our defaults
> while( my ($k,$v) = each %def) {
> $me->{$k} = $v ;
> }

> $me->redefine(@_) if @_;

> # so that we always have a New One of these
> $me->{private_fd} = new PRIVATE::TYPE
> unless defined $me->{private_fd};
> } # end of _init

> #
> # So that we have our _init do our initializing

> sub new {
> my $type = shift;

> my $self = {};

> my $class = ref($type) || $type ;

> bless $self, $class ;

> #
> # this may bother some with the subsequent sub_classing
> #
> $self->_init(@_);

> $self;

> } # end New

> The new is basically stock out of the manual - save for my choice
> to allow an '_init()' - that is from the old naming convention,
> one "_" is an application specific thingie - in this case one of
> our 'private' methods - but since I may need to pass thru re-definitions,
> why not have a 'redefine' - where I can stuff all of MY personal
> requirements for how this class should be doing it.

> I think I should 'expose' the redefine() method - so that other sub_classes
> can use it... in this sense, point to it in the POD - since I really can
> not think of a way to expressly prevent them from using it. I found that
> having this redefine() allows me 'back door' updates in my
> own methods where I use tricks like

> sub do_me_now {
> my $self = shift;
> $self->redefine(@_) if @_;
> .
> }

> So far - I think I am well within Kosher, since in the
> FOO::BAR::BAZ I do the old

> package FOO::BAR::BAZ;
> 
> our @ISA = qw(FOO::BAR);

> steal the very same 'new' method - cut and paste, and out
> and away we go BadaBoom, badaBing - the new in this class
> updates the stuff I want to have initialized in the base class
> as well So Far - no major wo

Re: getting the fields pulled from a database

2002-06-18 Thread Daniel Gardner

Tuesday, June 18, 2002, 8:12:30 PM, A Taylor wrote:
> I have a script that allows me to connect to my SQL Server7 database, and 
> run a SQL command:

>use Win32::OLE;
>$conn = new Win32::OLE('Adodb.Connection');
[snip]
>$conn->Execute(<  SELECT * FROM Customers
>EOF

> But how do I get the fields returned from the SQL command 'SELECT * FROM 
> Customers'

You could try the ADO docs:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthcnnexecute.asp

They might help.

A more Perlish way to do it would be to use DBI, which
provides an abstraction layer for database access. That and
DBD::ADO or similar would probably be easier to work with.


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: Function for converting a specific date to number of seconds since 01/01/1970?

2002-06-18 Thread Daniel Gardner

Tuesday, June 18, 2002, 9:30:40 PM, Todd Wade wrote:

> # this sub was written by Larry Rosler
> # modified by me to get rid of the 'argument isnt numeric' warnings by -w
> # i found it on deja

it's probably better to use timelocal() from the core
Time::Local module, if only for the reason that it's got a
whole lot more documentation than this subroutine.


> # it takes 6 arguments
> # and returns the time in epoch seconds
> # or undef if the date is not valid
> sub UTC_to_Epoch {
> my($year, $mon, $day, $hour, $min, $sec) = @_;
> (($year =~ m/^\d{4}$/) && ($mon =~ m/^\d{1,2}$/) && ($day =~ 
> m/^\d{1,2}$/)) or return;
> ($year <= 2037) or return;
> my @m_day = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
> $m_day[2] = 29 unless $year % 4; # OK from 1901 through 2099.

> 1970 <= $year && $year <= 2099
> && 1 <= $mon  && $mon  <= 12
> && 1 <= $day  && $day  <= $m_day[$mon]
> && 0 <= ($hour ||= 0) && $hour <= 23
> && 0 <= ($min  ||= 0) && $min  <= 59
> && 0 <= ($sec  ||= 0) && $sec  <= 59
> or return;

> # Adapted from Astronomical Computing, Sky & Telescope, May, 1984.
> 24 * 60 * 60 * (367 * $year - 678972 - 40587 + int(275 * $mon / 9) + $day 
> - int((int(int($year + ($mon < 9 ? -1 : 1) * int(abs($mon - 9) / 7)) / 100) 
> + 1) * 3 / 4) - int(7 * (int(($mon + 9) / 12) + $year) / 4)) + 60 * 60 * 
> $hour + 60 * $min + $sec
> }

> Todd W


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: cutting of last char of a variable

2002-06-16 Thread Daniel Gardner

Check perldoc -f chop

http://www.perldoc.com/perl5.6.1/pod/func/chop.html


Sunday, June 16, 2002, 9:29:00 AM, Chris Knipe wrote:

> Hi,

> How can I cut off the last char. of a string?

> $string = "160700Z";

> I want to remove the Z ?

> This is to import METAR weather data if anyone's interested, and if someone
> has a script which process and imports the Metar data already, I'd
> appreciate it allot :P

> --


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




Re[2]: "lazy" variable declaration

2002-06-15 Thread Daniel Gardner

Could be that someone would be interested in this thread
from fwp:

http:[EMAIL PROTECTED]/msg02488.html


Friday, June 14, 2002, 9:23:43 PM, Chas Owens wrote:

> On Fri, 2002-06-14 at 15:50, todd r wade wrote:
>> 
>> 
>> Chas Owens wrote:
>> 
>> 
>> >
>> >> Alternately, you could say:
>> >> 
>> >> $track ||= '';
>> >> 
>> >> right before the next time you use foo after the split. I dont know 
>> why this
>> >> works offhand, I just remember reading in the docs somewhere that 
>> its exempt
>> >> from warnings. But for me, that is crossing over into the land of 
>> ugly =0).
>> >
>> >
>> >$track ||= '';
>> >
>> >is equivalent to 
>> >
>> >$track = $track || '';
>> >
>> >which is equivalent to 
>> >
>> >if ($track) {
>> > $track = $track;
>> >} else {
>> > $track = '';
>> >}
>> >
>> 
>> When I said, "I dont know why this works...", I meant I dont remember 
>> why ||= is exempt from warnings. I know what it does.
>> 
>> Your examples are neither equivalent nor dangerous in the context of 
>> this thread. We are trying to avoid "undefined value..." warnings by 
>> the use of a variable after a split.
>> 
>> Im sure your second example is not exempt from the warning ,where 
>> $track ||= ''; is exempt.
>> 
>> also, The original OPs conditional following the split uses the eq 
>> operator with $track as one of its arguments, so the zero issue does 
>> not apply.
>> 
>> This was my second example, and my first suggestion to use:
>> 
>> if ( defined($track) and ( $track eq "foo") ) { 
>> 
>> would be the most prudent IMHO.
>> 
>> Todd W

> The reason it works is because of the third case.  The value undef is
> equivalent to false in logical situations.  The proof is below.  I agree
> that

> if ( defined($track) and ( $track eq "foo") ) {
> .
> .
> .
> }

> is the safest method since it correctly handles the case where $track ==
> 0 (which would be the first track in some numbering systems).  As I
> said, Perl 6 will solve this problem with a new operator.

> 
> Testing for warnings

> shortest way
> Use of uninitialized value in print at ./t.pl line 12.
> test

> short way
> Use of uninitialized value in print at ./t.pl line 22.
> test

> Longest way
> Use of uninitialized value in print at ./t.pl line 32.
> test

> Testing for overwrite of 0

> shortest way
> test

> short way
> test

> Longest way
> test
> 

> 
> #!/usr/bin/perl

> use warnings;
> use strict;

> print "Testing for warnings\n\n";

> print "shortest way\n";

> my $var1;

> print $var1;

> $var1 ||= "test\n\n";

> print $var1;

> print "short way\n";

> my $var2;

> print $var2;

> $var2 = $var2 || "test\n\n";

> print $var2;

> print "Longest way\n";

> my $var3;

> print $var3;

> if ($var3) {
> $var3 = $var3;
> } else {
> $var3 = "test\n\n";
> }

> print $var3;

> print "Testing for overwrite of 0\n\n";

> print "shortest way\n";

> my $var4 = 0;

> $var4 ||= "test\n\n";

> print $var4;

> print "short way\n";

> my $var5 = 0;

> $var5 = $var5 || "test\n\n";

> print $var5;

> print "Longest way\n";

> my $var6 = 0;

> if ($var6) {
> $var6 = $var6;
> } else {
> $var6 = "test\n\n";
> }

> print $var6;
> 
 
> -- 
> Today is Setting Orange the 19th day of Confusion in the YOLD 3168
> Frink!

> Missile Address: 33:48:3.521N  84:23:34.786W





-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: file tokenizers

2002-06-15 Thread Daniel Gardner

Friday, June 14, 2002, 8:36:01 PM, Torres, Jose wrote:

> I have a script that opens a file and needs to grab certain values from it.
> Can anyone recommend a good file tokenizing module? Thanks.

Is Parse::RecDescent what you want? or Parse::Lex perhaps...


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: Controlling Novell products with Perl

2002-06-14 Thread Daniel Gardner

This sounds fairly interesting...

http://developer.novell.com/ndk/perl5.htm

There's some docs at the bottom of that page about doing
stuff with Novell things using perl.

Can't say I've ever used it myself, and haven't touched a
netware box for years, but it looks like good stuff.

hth,
Daniel



Thursday, June 13, 2002, 9:52:13 PM, Bill Akins wrote:

> I would also be interested in seeing what others have come up with.



> Bill Akins, CNE
> Sr. OSA
> Emory Healthcare
> (404) 712-2879 - Office
> 12674 - PIC
> [EMAIL PROTECTED]



 "Nigel Peck" <[EMAIL PROTECTED]> 06/13/02 04:03AM >>>
> Does anyone have experience of using Perl to control any Novell
> products
> such as Netware, eDirectory (NDS) etc.

> I don't have a specific requirement at present but we do a lot of
> Novell stuff and I am interested to know what can be/has been done.

> Apologies if this question is a bit general but I am hoping someone
> will come up with something cool :-)

> TIA
> Nigel


> ITM Business Solutions
> Unit 4
> Nine Trees Trading Estate
> Morthen Road
> Rotherham
> S66 9JG

> Reception
> Tel: 01709 703288
> Fax: 01709 701549

> Help Desk
> Tel:01709 530424
> Fax: 01709 702159

> CONFIDENTIALITY NOTICE: This message is intended only for the use of
> the individual or entity to which it is addressed, and may contain
> information that is privileged, confidential and exempt from
> disclosure
> under applicable law.


> 
> CONFIDENTIALITY NOTICE:

> This message may contain legally confidential and privileged information
> and is intended only for the named recipient(s).  No one else is 
> authorized to read, disseminate, distribute, copy, or otherwise disclose
> the contents of this message.  If you have received this message in 
> error, please notify the sender immediately by e-mail or telephone and 
> delete the message in its entirety. Thank you.
> 
> <<<>>>




-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: scp inside perl

2002-04-01 Thread Daniel Gardner

take a look at the Net::SCP, Expect and Net::SCP::Expect
modules on CPAN.




-- 
Best Regards,
Daniel   [EMAIL PROTECTED]




Monday, April 01, 2002, 6:05:49 PM, Jeff Liu wrote:


> Hi Greg,

> Thanks for your help.

> But I have difficulty to fill in the password. What I like to do is, 

> open (SCP, "| scp source destination");
> print SCP scppassword;
> close SCP;

> Above code does not work for me. Any idea to make it work?

> Best regards,

> Jeff Liu


> -Original Message-
> From: Lirot, Gregory [mailto:[EMAIL PROTECTED]]
> Sent: April 1, 2002 12:02 PM
> To: Jeff Liu; Beginners
> Subject: RE: scp inside perl



> Jeff:
> Yes. Merely use something like:

> system("scp Source Destination");

> This would be the easiest way, or, also:

> `scp Source Dest`;

> More elaborate stuff can be done, but this is good for starters.

> Best Regards,

> Greg 
> -Original Message-
> From: Jeff Liu [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 01, 2002 11:44 AM
> To: Beginners
> Subject: scp inside perl



> Hi all,

> Is there a way to do scp inside perl script?

> Thanks,
> Jeff Liu


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




Re[2]: Random Sampling in Perl

2002-03-18 Thread Daniel Gardner

Monday, March 18, 2002, 10:28:14 PM, "Jonathan E. Paton" wrote:


> Even if it doesn't it solves the problem of having
> duplicates.  Then you can shuffle elements to get
> your data set.  There must be a decent shuffle
> algorithm someplace, since I haven't thought of
> one yet.  splicing to pop elements midway
> off an array just doesn't appeal.


Check out Algorithm::Numerical::Shuffle on CPAN


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: strange error message on exiting script

2002-03-18 Thread Daniel Gardner

Monday, March 18, 2002, 7:21:51 PM, John W. Krahn wrote:

> perldoc perldiag
> [snip]
> Attempt to free unreferenced scalar
> (W internal) Perl went to decrement the reference
> count of a scalar to see if it would go to 0, and dis­
> covered that it had already gone to 0 earlier, and
> should have been freed, and in fact, probably was
> freed.  This could indicate that SvREFCNT_dec() was
> called too many times, or that SvREFCNT_inc() was
> called too few times, or that the SV was mortalized
> when it shouldn't have been, or that memory has been
> corrupted.

Just for anyone who'd like to see informative stuff like
that for all their warnings, adding "use diagnostics;" to
the top of your script will give you the right section from
perldiag at the same time your warning is generated. It also
does a couple of other nifty bits like giving you a stack
trace on die.

Can be very helpful when trying to work out what's wrong
with some code.



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: xmit Perl code for carriage return during telnet session

2002-03-17 Thread Daniel Gardner

Hello John,

Monday, March 18, 2002, 5:15:18 AM, John wrote:


> I do not understand the results of the following experiment, and would
> appreciate input.

> Using telnet on a Win PC, I executed this code:

> perl -e ‘print "Hello world.\n\r"' > /dev/tty1

> On my Linux system monitor (/dev/tty1), I see "Hello world." printed along
> with the newline and carriage return.

> What I don't understand is why I don't see a return of my Linux screen
> prompt until I hit the Enter key on that system.

> Should I be flushing some sort of buffer, closing a file, or transmitting
> some other code sequence to indicate an end to my output?

try without the \r

\n is a "newline", \r a "carriage return", in windows files
you usually need both, on unix you usually only need the
newline.

the \r in this case will move the cursor back to the start
of the line, overwriting the prompt which is there.


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Attacking this wrong? Syslog sort & extract question

2002-03-17 Thread Daniel Gardner

Sunday, March 17, 2002, 9:44:49 PM, swansong wrote:

> I'm fairly certain I'm attacking this incorrectly, so any advice is
> greatly appreciated...

> Task:

> I want to sort through my Solaris syslog (/var/adm/messages) looking for
> any system
> reboots which always start with the string SunOS and, if found, return
> that line and
> the next 20 lines, at least for starters.

> I was going to try and catch the line # of the line that has the SunOS
> in it and then
> increment that by 1, print that line from the array and then increment
> by 1 for 20
> iterations.

> I scratching out something such as.(I'm a complete newbie and I'm
> banging my head
> against the wall because either I'm completely attacking this with the
> wrong logic and/or
> I'm misinterpreting the usage of $. ..me thinks...help
> please...)


> #!/usr/local/bin/perl -w

> $file="/var/adm/messages";

> printf "test of the emergency broadcast system\n";

> open (FILE, "< $file") or die "can't open $file: $!";
> @lines = ;

> foreach (@lines) {
> if ($_ =~ /SunOS/)
> printf "$_\n";  {
> for ($i = $.; $i ($. + 20);$.++)
> printf $lines[$i];
>}
> }


It looks like your basic idea is sound, but there's a couple
of little problems. Where you've got printf you should have
print - they're different. see perldoc -f printf for the
difference. Also in your for loop there's something dodgy
with "$i ($. + 20)".

Also you want to be careful with "@lines = " because
the whole file will be read into memory; if the file is huge
then it might cause problems.

Try this:

   #!/usr/bin/perl -w

   use strict;

   my $file = "/var/adm/messages";

   open (FILE, $file) or die $!;
   while () {
 if (/^SunOS/) {
   print;
   my $stop = $.+20;
   while () {
 last if $.>$stop;
 print;
   }
 }
   }

$. is automagically incremented for each line read from a
file, so we say, "read lines from a file, until we find one
starting 'SunOS', then carry on reading lines. Stop after 20
of them"

There is a case where there could be less than 20 lines
before the end of the file, which this solution handles.
However it doesn't handle the case where the string SunOS
appears within the 20 rows we output.



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: limiting a regular expression

2002-03-17 Thread Daniel Gardner

Sunday, March 17, 2002, 1:10:16 PM, Zysman, Roiy wrote:

> I'm sorry if i wasn't clear
> after tmp_ can come any character for example tmp_6676frf877 or
> tmp_hbhbbd3y78783xcbh
> how can i limit my regex to catch any character but not "/"
> Thx Roiy

how about

  m|/(tmp_[^/]+)|;

which says, "match a /, the letters 'tmp_', then some stuff
which isn't a '/'."



> -Original Message-
> From: Mark Maunder [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, March 17, 2002 12:13 PM
> To: Zysman, Roiy
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: limiting a regular expression


> What are you trying to match? If it's just the dir name then:
> /\/(tmp_\w)/ will do it and set $1 to equal your directory name.

> ~mark.
> http://www.workzoo.com/


> "Zysman, Roiy" wrote:

>> Hi All,
>> As we all know Regular Expressions are very greedy and tries to big as big
>> as possible.
>> How do i limit a regular expression for example ion the follwing case
>>
>> i try to find a specific directory called tmp_* in some paths which are
> like
>> this
>>
>> /dir1/dir2/dir3/tmp_test1/dir4/dir5.../.../...
>> /dir6/dir7/dir8/tmp_test2/dir9/dir10../...//...
>>
>> if i use (\S+) it will also catch the following dirs, even if i use
> (\S+)\/
>> Any suggestions ?
>> Thx Roiy
>>




-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Width of an Image

2002-03-17 Thread Daniel Gardner

Sunday, March 17, 2002, 12:43:07 AM, [EMAIL PROTECTED] wrote:
> I'm writing a CGI program that requires that I discover the dimensions of an
> image that a person uploads.   Can perl or javascript do that?

The Image::Size module on CPAN does exactly that:

http://search.cpan.org/search?dist=Image-Size


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: foreach loop :(

2002-03-17 Thread Daniel Gardner

Sunday, March 17, 2002, 10:41:01 AM, Mark Maunder wrote:

> You have two dollar signs before the 'name' variable in
> the loop. That probably works provided the value of the
> variable is not a number, but it may be causing the
> strangeness you're experiencing. Always 'use strict' in
> your scripts. You should be storing your params in a hash
> and doing something like this instead:

> my %stuff;
> foreach my $name (param())
> {
> $stuff{$name} = param($name);
> }

> Try that instead, perhaps it will solve your problem.

Seconded. Emphatically.

Creating variables in your main namespace is Just A Bad Idea.

Here's a couple of really obvious reasons not to do it:
http:[EMAIL PROTECTED]/msg22156.html

and you almost always want to 'use strict'. There's no
excuse for not using it except laziness (okay, except for
the perl golf crowd, but none of them would ever write
production code without it). And it's false laziness at
that, because it's going to cause you more trouble in the
long run.

Here's a nice post by ovid on perlmonks about strict:
http://www.perlmonks.org/index.pl?node=%27use%20strict%27%20is%20not%20Perl

Honestly, using a hash is the best thing.

If you really really really want to import your parameters,
then look at the 'import_names' method in CGI.pm.

Also you should be using taint mode as well. Look at
perldoc perlsec, or
http://www.perldoc.com/perl5.6.1/pod/perlsec.html


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: Cleaning poorly formated csv files

2002-03-17 Thread Daniel Gardner

Sunday, March 17, 2002, 12:18:01 AM, Dave Chappell wrote:

> Thanks. I got lots to learn about perl, thinking for the 2 hours I was
> trying to solve my issue with chomp and split. I have began disecting your
> reponse to learn from it. One question, the last print statement:

> print $_ . "\n";

> what is the significance of the .  ?  when I remove it nothing is displayed

It's the concatenation operator:

  my $greeting = "Hello";
  print $greeting . " world!\n";

Often you can use variable interpolation (ie

  print "$greeting world\n";

but there's many times you don't want to.

I'd recommend a copy of "Learning Perl" by Schwartz and
Phoenix, as the publishers say:

   Learning Perl is the quintessential tutorial for the Perl
   programming language. The third edition has not only been
   updated to Perl Version 5.6, but has also been rewritten
   from the ground up to reflect the needs of programmers
   learning Perl today. Other books may teach you to program
   in Perl, but this book will turn you into a Perl
   programmer

   http://www.oreilly.com/catalog/lperl3/
  

-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: param function

2002-03-16 Thread Daniel Gardner

Saturday, March 16, 2002, 9:58:15 AM, Gary Hawkins wrote:

> Web form element names automatically become script variable names and are
> assigned their values...

> use CGI 'param';

> for $name (param()) {
> $$name = param($name);
> }

> The double $$ is not a typo.  Your question resulting in this solution has
> reduced the script I'm working on, by about 2000 bytes, or about 3%.  Thank
> you.


That's quite scary...

You've just allowed input from a web form to stomp all over
all your variables. You're very trusting.

Here's a really simple example of something that could break
your code:

  #!/usr/bin/perl -w

  use CGI 'param';

  for $name (param()) {
$$name = param($name);
  }

  print CGI::header();
  print "hello\n";
  print "foo\n";
  print "bar\n";

what could possibly go wrong with that?

try running it under a webserver and requesting the url:

http://server.com/cgi-bin/script.pl?\=The%20CEO%20sucks

imagine if you were reading from files, perhaps we could
redefine $/ for you, perhaps $/ = "a"... so if you used code
like:

  foreach my $line () {
my $result = &do_something($line);
  }

suddenly a "line" is whatever is between two 'a' characters,
rather than between \n's... lovely...

and that's just a couple of really simple things... how
about code like this in a credit card refund script:

  use LWP::Simple;
  my $credit_card_server = "secure.mybank.com";
  my $username = "my_secret_username";
  my $password = "my_password";
  for $name (param()) {
$$name = param($name);
  }

  my $result = get("https://$credit_card_server/refund.pl?";.
   "username=$username&password=$password&".
   ...some more details about what to refund...
  );

a sneaky user could easily redefine "$credit_card_server",
and you'd happily post your username and password to
whichever server they wanted. The user's now free to refund
any purchase they ever make from your store. peachy.


>From the CGI docs:

  $query->import_names('R');

  This creates a series of variables in the 'R' namespace.
  For example, $R::foo, @R:foo. For keyword lists, a
  variable @R::keywords will appear. If no namespace is
  given, this method will assume 'Q'. WARNING: don't import
  anything into 'main'; this is a major security risk



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: param function

2002-03-16 Thread Daniel Gardner

Saturday, March 16, 2002, 12:42:40 AM, Tiller, Jason wrote:
> my %params;

> $params{$_} = param($_) foreach param();

> If I understand your code correctly, param() returns a list of all the
> possible keys, right?  If so, then the above code should work.  You refer to
> the parameters as $param{name} instead of just $name.

Just FYI, CGI.pm has a method to do that for you:

  my $q = new CGI;
  %params = $q->Vars;

>From the CGI.pm docs:

  Many people want to fetch the entire parameter list as a
  hash in which the keys are the names of the CGI
  parameters, and the values are the parameters' values. The
  Vars() method does this. Called in a scalar context, it
  returns the parameter list as a tied hash reference.
  Changing a key changes the value of the parameter in the
  underlying CGI parameter list. Called in a list context,
  it returns the parameter list as an ordinary hash. This
  allows you to read the contents of the parameter list, but
  not to change it.

  When using this, the thing you must watch out for are
  multivalued CGI parameters. Because a hash cannot
  distinguish between scalar and list context, multivalued
  parameters will be returned as a packed string, separated
  by the "\0" (null) character. You must split this packed
  string in order to get at the individual values. This is
  the convention introduced long ago by Steve Brenner in his
  cgi-lib.pl module for Perl version 4.


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: the scope of 'use strict'

2002-03-16 Thread Daniel Gardner

Saturday, March 16, 2002, 3:29:29 AM, Yuan Cheng wrote:

> I am wondering what else 'use strict' does besides it
> is stated in the perldoc that it stricts on use of
> 'vars', 'refs' and 'subs'.  Thanks.

They basically stop you from doing things that are
dangerous, or stupid, or could break things in subtle ways.

Timothy Johnson said stuff about vars...

Strictures on 'refs' means that you can't use symbolic
references. Say you defined a variable:

  $foo = "hello, world\n";

then without strict 'refs', you would be able to do:

  $var_name = "foo";
  print $$var_name;

very occasionally you may want to do this, but it's not
common that anyone would want to. It's guaranteed to make
your head hurt working out what are variables and what
aren't, and usually it's better to use a hash.

strict 'subs' generates "a compile-time error if you try to
use a bareword identifier that's not a subroutine, unless it
appears in curly braces or on the left hand side of the "=>"
symbol" [1]

compare:

  #!/usr/bin/perl
  my $greet = hello;
  print "$greet world\n";

which outputs "hello world", to:

  #!/usr/bin/perl
  use strict;
  my $greet = hello;
  print "$greet world\n";

which die's saying:

  Bareword "hello" not allowed while "strict subs" in use at ./strict.pl line 3.

you shouldn't want to use barewords anyway



[1] http://www.perldoc.com/perl5.6.1/lib/strict.html


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: eval and BEGIN

2002-03-16 Thread Daniel Gardner

Saturday, March 16, 2002, 1:24:11 AM, Jenda Krynicky wrote:
> Imagine you need to compute something and the formula is pretty
> complex. Then for some input values it is not computeable, 
> because you divide by zero at one point or other. To find all the 
> "forbidden" input values and test them might be tedious.
> But your script can't just explode. It should report to the user that 
> these input values are wrong and continue.

> So you wrap up the computation in an eval{} block, report the errors 
> if any and everything is cool.

> Basicaly the eval {} block is great if you have to do something 
> potentialy dangerous, but cannot let the errors kill the whole script.

Here's a very simplified example of what Jenda means:

   #!/usr/bin/perl -w

   use strict;

   my $result;
   eval {
  $result = div_by(0);
   };
   if ($@) {
  if ($@ =~ /division by zero/) {
 $result = "undefined due to division by zero";
  } else {
 die $@;
  }
   }

   print "result is: $result\n";

   sub div_by {
  my $value = shift;
  return 10 / $value
   }

We have a function "div_by", which returns 10 divided by
it's input. Obviously if we passed the value zero to this
function, it will die.

We can wrap the call to the dangerous function in an eval
block, which means we can test to see if the code did in
fact die(), and what the error message was. The error will
be held in a special variable $@ (mnemonic "Where the error
was at").

In this case it would probably be easier to check the input
values for zero, but the eval/die method is perfectly valid.


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: Sockets and NNTP

2002-03-04 Thread Daniel Gardner

Monday, March 04, 2002, 12:28:44 AM, Hernan Freschi wrote:

> I already did, but I dont understand it,... it uses objects and I don't know
> them.

i just took a look, and it seems to send a \015\012

i was assuming when you said \r\f below it was a typo and
you meant \r\n, if that's not the case then try \015\012

just out of interest, why can you not use NNTPClient.pm?
it's only one file...




> "Daniel Gardner" <[EMAIL PROTECTED]> escribió en el mensaje
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>>
>> Sunday, March 03, 2002, 1:11:39 AM, Hernan Freschi wrote:
>> > I wrote a little script to get the newsgroup list from a newsserver. It
>> > opens a socket, connects to it, writes "LIST\n" and does while
> ()
>> > 'till /^\./.
>> > The problem is that, it works only with some servers. On others, it just
>> > keeps waiting for input (looks like). For example, it works on
>> > nntp.perl.org, but not on news.microsoft.com.
>> > I tried \r\f instead of \n but it doesn't work either.
>> > News:NNTPClient is NOT an option (or any other module for the matter).
>>
>> > Can anyone help me? Thank you.
>>
>>
>> how about getting the module and looking at how they do it?
>>



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Sockets and NNTP

2002-03-03 Thread Daniel Gardner


Sunday, March 03, 2002, 1:11:39 AM, Hernan Freschi wrote:
> I wrote a little script to get the newsgroup list from a newsserver. It
> opens a socket, connects to it, writes "LIST\n" and does while ()
> 'till /^\./.
> The problem is that, it works only with some servers. On others, it just
> keeps waiting for input (looks like). For example, it works on
> nntp.perl.org, but not on news.microsoft.com.
> I tried \r\f instead of \n but it doesn't work either.
> News:NNTPClient is NOT an option (or any other module for the matter).

> Can anyone help me? Thank you.


how about getting the module and looking at how they do it?



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: perldoc manual

2002-02-20 Thread Daniel Gardner

Thursday, February 21, 2002, 12:31:45 AM, Scott Lutz wrote:

> Where can one find a good reference to the perldocs?
> I want to find out about "push", so I tried :

perldoc list ->> No documentation found for "push".
perldoc array ->> No documentation found for "array".
perldoc list ->> No documentation found for "list".

perldoc -f push



-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re[2]: can't print input argument

2002-02-12 Thread Daniel Gardner


Wednesday, February 13, 2002, 1:06:18 AM, Timothy Johnson wrote:
> Looking at the command-line thing more closely, something like this should
> work...

C:\>> perl -e "while(<>){s/good/bad/;print}" test.txt

or

perl -pi -e 's/good/bad/' test.txt


take a look in perldoc perlrun, there's all sorts of
command-line switches that can be used.

ta,
daniel




> but again, I don't use the command-line all that much.

> -Original Message-
> From: Booher Timothy B 1stLt AFRL/MNAC
> [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 12, 2002 4:37 PM
> To: [EMAIL PROTECTED]
> Subject: can't print input argument


> Hello - more trouble, I just can't seem to write a program that prints an
> argument it's passed:
 
> My script contains:
 
> #not working
> print "$ARGV\n";
 
> when I run this I get:
 
> c:\work.pl "this"
 
> c:\
 
> confused by this but also confused that I can't run anything from the
> command line in windows. Like
 
> c:\perl -e "s/Bad/Good/" test.txt
> or
> c:\perl -e 's/Bad/Good/" test.txt
 
> I have activePerl installed and my file attributes are fine  . . .
 
> tim


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Redirect error to file using system()

2002-01-29 Thread Daniel Gardner

Tuesday, January 29, 2002, 3:38:20 PM, Kipp, James wrote:

> I am working on an NT script which uses system(). I can not get it to write
> errors to stderr instead of stdout. it works fine from the command line. see
> code snip below. any ideas?
> thanks
> Jim

> --
> foreach $user (@users)
> {
> system("NET SEND $user testing 2>err.out"); 
> }
> ---


Does IPC::Open3 help? That sends the program's STDERR to
whatever filehandle you want...

http://www.perldoc.com/perl5.6.1/lib/IPC/Open3.html



-- 
Best Regards,
Daniel  [EMAIL PROTECTED]


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




Re: delete first line of the text file

2002-01-27 Thread Daniel Gardner

Sunday, January 27, 2002, 10:00:44 PM, Malunas wrote:

> I have a log file in text format. I need to delete the first line so I could
> put the rest in MySQL database. How do I delete only the first line of this
> text file?

perldoc -q "delete a line in a file"




-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: perl for php, in order to break free from asp

2002-01-27 Thread Daniel Gardner

Sunday, January 27, 2002, 3:03:03 PM, Matt C. wrote:

> There's a module called DBD::CSV, which will probably solve your problem. CPAN is
> good at that :).  You can tell it what the field separator is and then you'll be
> able to manipulate it however you want with the DBI. I believe you'll need to
> install the bundle, found here: 


I hate to say it, but this guy can't even manage to read
from a file, telling him to go and use *anything* from CPAN
is probably much like telling him that he should sacrifice a
chicken and dance naked under a full moon - both suggestions
are about as likely to be as effective.


Taking strictly from what the guy wants to do (which bears
little relation as to what the guy should do) this should do
the trick:

  #!/usr/bin/perl -w

  use strict;

  open INFILE, "text.csv" or die "Can't open text.csv: $!";
  while () {
 print "insert into TABLENAME id,first,last VALUES ($_);\n";
  }

of course this assumes that all of the data in text.csv is
properly quoted. If it's not then that'll fail dismally.

and just as an aside to the OP, why not use php to do this?
if you know that, then why try and get another language that
you don't know involved?


> --- bc <[EMAIL PROTECTED]> wrote:
>> i have a mdb db, i use with asp
>> 
>> i want to switch to php
>> 
>> i want to use perl to convert the csv produced from this mdb to make a many many
>> lined sql statement for my php db, in order to get the 
>> data to it
>> 
>> so in perl, how do i turn each line of csv data into sql statements by adding
>> "insert into"... etc etc...
>> 
>> i want to take 44, jon, doe, 3479, alabama
>> 
>> and add "insert into TABLENAME id, first, last, number, state VALUES ("
>> $the_csv_string_one_per_row ")";
>> 
>> so in my linux websever's cgi-bin directory, what will the pl script look like:
>> 
>> ex:
>> 
>> #!/user/bin/perl
>> open (infile, "text.csv");
>> @indata = infile;
>> foreach???
>> 
>> something like this?
>> 
>> thanks a ton, i've gotten a lot of error's trying to do this for days...?
>> 
>> bc
>> 
>> 



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re[2]: A few Great Modules

2002-01-20 Thread Daniel Gardner

Sunday, January 20, 2002, 4:27:10 PM, Chris Ball wrote:
> I really enjoyed this post.  Does anyone else want to share some CPAN
> modules or techniques they've found useful recently?

> My plaything of recent times is Leon Brocard's GraphViz.pm module, which
> allows you to graph from perl.  There's also a GraphViz::DBI, which
> simply takes a DBI connection and snarfs table/relationship details from
> the database before outputting a graph showing tables and the links
> between them.

I was really impressed with GraphViz, it can make really
interesting stuff. Seeing as Matt mentioned both
Data::Dumper and XML::Simple, here's a link to a very quick
script i made a while ago with all three modules and the
output...

http://www.pl14759.demon.co.uk/graphviz.html


I've been having a bit of a play with Parse::RecDescent
recently too. good introductory article here:

http://www.stonehenge.com/merlyn/UnixReview/col40.html




-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Perl code - Coverage

2002-01-17 Thread Daniel Gardner

Hello Rajanikanth,

Thursday, January 17, 2002, 9:49:03 AM, Rajanikanth Dandamudi wrote:

> Hello,

>  Can someone help me in getting the coverage of a perl
>  program. I had used the Coverage  module  of the perl
>  distribution by issuing a command:

>  perl -d:Coverage script_name [ args ]

>  Running the  above  command  created  a  file by name:
>  script_name.cvp

>  This file script_name.cvp is an ascii  text file, but I
>  am not able to get much information from this file. Can
>  someone help me on what needs to be done with the file,
>  script_name.cvp

   perldoc Devel::Coverage
   
   This software is still very early-alpha quality. Use the
   tool coverperl to analyze the files that result from
   running your scripts with coverage enabled

   

-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Security advice: SHA vs crypt for authenticator

2002-01-17 Thread Daniel Gardner

Wednesday, January 16, 2002, 6:45:40 PM, [EMAIL PROTECTED] wrote:

> I'm using a nice little GDBM file for authentication. It just stores users
> and passwords as SHA1 hashes. When I need to authenticate someone (fewer
> than 15 lines in the dbm file) I just tie it and compare the SHA'd user
> input against the hex value in the dbm file. (The file is not publicly
> readable.)

> It has been suggested, however, that this is not adequately secure and that
> the passwords would be better stored crypted or some such. I don't really
> see the difference between a SHA password and a crypted password in this
> context. Wouldn't they be equally difficult to crack?

crypt and SHA do basically the same thing - take some bits
(a password in this case) and turn it into some other
sequence of bits, unpredictably.

that is, assuming you're talking about the "crypt" function
that's often used when dealing with unix passwd files.

SHA1 is probably more "secure" than crypt, but saying that
the only way someone would try cracking your passwords would
be a dictionary attack, where they try hashing lots of
potential passwords (dictionary words) and comparing them to
the values stored in your dbm file.

SHA and crypt() would be equally vulnerable to a dictionary
attack.


I'd stick with SHA. Hashing functions don't get better than
that.

-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Thumbnail images on-the-fly

2002-01-16 Thread Daniel Gardner

Wednesday, January 16, 2002, 10:24:27 AM, Scott R. Godin wrote:

> I've got an idea kicking around in my head .. 

> having a web-directory that can have image files added to it, taken 
> away, or prefaced with "." to have them be ignored temporarily without 
> removing them.

[snip]

> any pointers? I'm happy to toddle off and download and read my face off 
> -- that's not a problem.. I'd just like to have some indication on which 
> direction to start walking. :-)


If you're feeling a bit sadistic and want to walk for many,
many miles you could try to make something as clever as
Apache::Gallery.

It uses mod_perl, Inline::C and a C libary called imlib2 to
do it's thing. The guy who wrote it has a demo site at
http://pictures.legart.dk/

Very comprehensive, very good, and a long way to walk - but
very educational and a fun trip if you make it over the
mountains



-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re: Encryption/Decryption

2002-01-15 Thread Daniel Gardner

Tuesday, January 15, 2002, 4:31:46 PM, Gary Luther wrote:
> I need some help from someone that may have traveled this road.

> We will be receiving encrypted data from a remote location that we need to decrypt 
>and process.

> What I know about the encryption is that it is symmetric, with DES and CBC.

> My question is can I use a Perl routine to Decrypt the information?

> If so what modules do I need?  

> Crypt::DES?  are there others?  

> The specs indicate that is it is also Base-64 encoded so that I will  need to decode 
>then decrypt, I think

> Is there a CBC module? that I need or does the DES module understand all of that.  

> Any help is appreciated.  This sucker is overwhelming me a tad bit.


you could try using Crypt::CBCeasy and MIME::Base64.

something like this might work:

  #!/usr/bin/perl -w
  use strict;
  use MIME::Base64;
  use Crypt::CBCeasy;

  my $my_key = "a very secret key";
  
  ... read contents of file into $source...

  my $crypted = base64_decode($source);
  my $plaintext = DES::decipher($my_key, $crypted);

and then you have some plaintext.

it's untested, and i've never used Crypt::CBCeasy, but it
looks like it might be good for you.

http://search.cpan.org/doc/MBLAZ/Crypt-CBCeasy-0.24/CBCeasy.pm



-- 
Best Regards,
Daniel  [EMAIL PROTECTED]


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




Re: How to detect the correct OS:

2002-01-15 Thread Daniel Gardner

Tuesday, January 15, 2002, 6:16:49 AM, Chris Anderson wrote:
> I need to find out which OS I am on -
> It would be nice to know:
> Ref Hiat
> Mandrake
> Slackware
> W2K
> W98
> WME
> WXP
> Solaris
> AIX, etc

> but

> Unix
> Linux
> W32


> is fine also

> How can I do this???

$^O should have the right stuff in there. try

  print $^O;

or perhaps getting it from Config would work:

  use Config;
  print $Config{osname};
  print $Config{osvers};



-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Help with encryption/decryption

2002-01-13 Thread Daniel Gardner

Friday, January 11, 2002, 9:27:46 PM, Gary Luther wrote:
> Here is what I know about the data I need to decrypt:

> Algorithm - The block cipher DES is the standard cipher for all 
>encryption/decryption operations.
> Padding - PKCS #5 padding is used.
> Chaining - Cipher Block Chaining (CBC) is used for both key and data cipher 
>operations.
> Encoding - All encrypted data is stored Base-64 encoded.

> Keys are password based encrypted using DES-MD5 with CBC.  All keys are Base-64 
>encoded.
> Keys used within the DES algorithm are 64-bit with and effective key length of 
>56-bits.
> All data is symmetrically encrypted.

Crypt::DES
Crypt::CBC
MIME::Base64
Digest::MD5

56-bit DES isn't very good... i'm assuming that you you're
interfacing with an existing system rather than implementing
something new.

looks like you might have a bit more trouble with something
to do PKCS#5 padding. from the Crypt::CBC docs:
http://search.cpan.org/doc/LDS/Crypt-CBC-2.01/CBC.pm

   Future versions of the module may include PKCS5 / PKCS7
   padding support, but right now my Bruce Schneier Applied
   Cryptography book is missing. information into an e-mail
   message, Web page or URL.

so it sounds like you might be able to work something out

> I am not sure at this point what Perl Modules will do this for me. I think I need 
>Crypt::DES as a starter.  I am running on an AIX box. I have Perl 5.6.1 from the Bull 
>distribution installed. I
> have tried several times to download the Crypt::DES module which CPAN says is 
>Crypt-DES-2.03.tar.gz.
> When I download it (I have done this several times) and try to run gunzip I am told 
>the file is not in gzip format. I have been gunzip'ing other files with no problem. 

> SoI am looking for help and direction.

> 1) What CPAN modules do I need in addition to Crypt::DES
> to meet the requirements of the above?

> 2) Where can I get a good copy of the modules (by the way
> I am downloading to a Windows box and FTPing to the
> RS/6000...the way I have always done it.)

the stuff on CPAN should be good. i'd double-check that
you're ftp-ing in binary mode... if that's not the problem
you could try asking the author of the package if there's a
known problem (something like Crypt::DES i imagine is used a
*lot*)

> Thanks to anyone who can get me back on track. I have
> spent 2 days trying to unravel this and all that is
> unravelled is my brain ;~{

i don't know if it'll be any use to you, but there's an
interesting article here: http://www.perl.com/pub/a/2001/09/26/crypto1.htm


-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Sorry for off topic, please reply as interested, and off list....

2002-01-12 Thread Daniel Gardner

Friday, January 11, 2002, 8:32:56 AM, Connie Chan wrote:

> now, I am writing a script which to let user modify the password of
> their email account automatically, but our email server will encrypy 
> the password in some ways. so it makes me unable to cmp or write.

> such as, if I give "A" as a new pass, it encrypted as QQ== in the user's profile.
> if I give "AA", it encrypted as QUE=
> if I give "AAA", it enctypted as QUFB
> if I give "B", it change to Qg==
> if I give "BB", it change to QkI=
> if I give "BBB", it change to QkJC

> any expert can help me to accomplish this un-encryption,  or give
> me some ideas on how to make this up ? I've tried to think from 
> ascii code, change ascii from bin, hex, oct, dec. and analysis what
> is varying... but I got nothing related... Thank you very much for any help

you're in luck - there isn't any encryption performed at
all.

  #!/usr/bin/perl -w

  use strict;

  use MIME::Base64;

  my $enc = encode_base64("AAA");

  print "$enc\n";


it does Base64 encoding of the password, doesn't add in any
sort of hashing or anything. those are basically plain-text
passwords.

to get back the other way go

  my $pass = decode_base64("QUE=");

and that's it.



-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re: Lists or hash

2002-01-12 Thread Daniel Gardner

Friday, January 11, 2002, 3:12:19 PM, Scott wrote:

> I am reading a file into a list and then formatting it to prepare it for a
> mainframe.  Currently I read the contents into a list as such:

> my @fields = split(/\t/, $record)
> and then I call them by $fields[0], etc.

> Would it be more beneficial to use a hash instead?  Or is that overkill?  
> I would need to set the key and then import the values from the file 
> import.

if what you're after is to improve the readability of your
script there's a few different options you have.

  * keep the array but make it more readable

it's disingenuous to write things like $fields[0], but what
if you could write $fields[ORDER_ID] - much more obvious.
you could use code like the following:

  use constant ORDER_ID => 0;
  use constant PRODUCT => 1;

  my @fields = split(/\t/, $record);

  print $fields[ORDER_ID];

conventionally the "use constant" lines would be at the top
of your script.

this is quite nice if you're concerned about the speed
impact of using hashes over arrays, as the optimizer will
replace any of these "constant values" with the respective
value at compile time, so as far as perl is concerned you've
written $fields[0]

you can read about the constant pragma with "perldoc constant".

as perl people like to chant TIMTOWTDI... so here's another
way.


  * use a hash instead of an array

this will make code which looks pretty much identical to the
last idea. ie we can say $field{order_id}. the first way you
might think of doing this might be something like:

  my @fields_array = split(/\t/, $record);
  my %fields_hash;
  $fields_hash{order_id} = $fields_array[0];
  $fields_hash{product} = $fields_array[1];

but this seems remarkably longwinded to me. i'd use "map" in
this case. map is one of the scary keywords that most people
new to perl don't understand and skip over... if there were
lots of fields and they were going to change regularly then
i might do something like:

  my $index = 0;
  my @field_names = qw( order_id product );
  my %fields_hash = map { $field_names[$index++] => $_ }
 split(/\t/, $record);

which will put exactly the same data in %fields_hash as the
last example.


here's another way, which you might like...

  * use a different variable for each field

this does away with the hash and the array altogether...

  my ($order_id, $product) = split(/\t/, $record);

  print $order_id;

which hopefully should be self-explanatory.


there's other things that could be done, but they start to
get a bit silly. hopefully that will give you a few things
to think about.



-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re[2]: C vs. Perl

2002-01-02 Thread Daniel Gardner

Wednesday, January 02, 2002, 7:06:34 PM, Maciejewski, Thomas wrote:

> how ?

> through CGI? 

> can you post an example?

i can't say i've ever tried to build a perl with threading
enabled, but there's always lots of discussion on the mod_perl
mailing list about sharing data between processes. take a
look at the Cache::* modules, Apache::Session, MLDBM::Sync,
or probably a host of others for ways to share data around.
none of those modules need mod_perl (even the non-intuitively
named Apache::Session)

http://search.cpan.org/search?dist=Cache-Cache
http://search.cpan.org/search?dist=Apache-Session
http://search.cpan.org/search?dist=MLDBM-Sync

hth,
daniel



> -Original Message-
> From: Hanson, Robert [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 02, 2002 2:09 PM
> To: Maciejewski, Thomas; Agustin Rivera; [EMAIL PROTECTED]
> Subject: RE: C vs. Perl


> "One benifit to running java though ... is that you can easily share
> information between your threads"

> Same with Perl.

> Rob


> -Original Message-
> From: Maciejewski, Thomas [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 02, 2002 2:02 PM
> To: 'Brett W. McCoy'
> Cc: Agustin Rivera; [EMAIL PROTECTED]
> Subject: RE: C vs. Perl


> agreed that OO isnt always better but the point that I was trying to make
> was that I would rather build more structured code that is easier to
> maintain / debug than to worry about the internal speed of a program ...
> also wanted to point out that there are other aspects to the percieved speed
> of a program like running servlets or in tomcat or whatever  

> One benifit to running java though ... and maybe tomcat does this is that
> you can easily share information between your threads ...  not sure how
> tomcat deals with that ... 


> -Original Message-
> From: Brett W. McCoy [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 02, 2002 2:01 PM
> To: Maciejewski, Thomas
> Cc: Agustin Rivera; [EMAIL PROTECTED]
> Subject: RE: C vs. Perl


> On Wed, 2 Jan 2002, Maciejewski, Thomas wrote:

>> how about all of the issues involved with spawning off processes ...
>>
>> in java servlets I know this is handled because the servlet is always
>> running ...

> You mean the servlet container is always running, like Tomcat.

>> you may end up with a more efficient system and easier to debug code and
> all
>> of the other benifits from OO ... pretty much all around better by
>> re-writing in java ... rather than c

> Bah, OO isn't always the best way.  I won't get into a Java vs. C vs. Perl
> thing here, but you code in a style which is most suitable for the project
> at hand and for the people doing the coding.

> -- Brett

>   http://www.chapelperilous.net/
> 
> If you suspect a man, don't employ him.






-- 
Best Regards,
Daniel  [EMAIL PROTECTED]


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




Re: Advice Wanted: authenticating users with perl

2001-12-20 Thread Daniel Gardner

Thursday, December 20, 2001, 11:04:44 PM, [EMAIL PROTECTED] wrote:

> Okay, let me just start by saying that I'm only looking for advice and
> triage. (In other words, I'm not asking you to do the work for me. Please
> don't send nasty emails along the lines of "Use Google you moron." Done
> that; there's a lot out there.)

> So my big project for Jan is the following:
> Write a client/server where-
> -client runs on Windows w/activestate
> -daemon runs on Solaris
> -client taps server, server responds with query for password
> -client takes password from user (preferably without echoing) and encrypts
> or hashes it
> -sends to server, which authenticates agains the Unix password file
> -server oks
> -client sends file across socket
> -server checks file, severs connection; does something with file

> This is probably trivial for some of you, but it's a big project for me.
> I'd love advice on the password authentication component in particular
> (e.g. module suggestions). But if anyone can recommend a site with sample
> code I can play with, or any number of books on the subject that would be
> great. I just want models and examples and references.

> I've ordered a book by the oft-acclaimed Lincoln Stein, "Network
> Programming with Perl." Do you think this will go a long way toward helping
> me? (As I hope.)

sounds like a particularly good book for what you're trying
to do (not that i've read it, but the TOC[1] looks good).

about the password sending part, there was an article on
perl.com[2] that you might find interesting.


1) http://www.aw.com/catalog/academic/product/1,4096,0201615711,00.html
2) http://www.perl.com/pub/a/2001/09/26/crypto1.html

-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: CPAN and Perl

2001-12-20 Thread Daniel Gardner

Thursday, December 20, 2001, 11:20:35 PM, Daniel Falkenberg wrote:

> I was just wondering if any one here has any experience with download
> Perl CPAN modules from a Perl script.  I have looked at CPAN.pm but am a
> little confused by this.

> I have tried the following...

> #!/usr/bin/perl -w

> use strict;

> #Check if a module exists... if it doesn't then ask the user with
>  Y or N if they want to download and install it.

> Can any one give me a helping hand with this?

nope, don't have any experience with it...

this little snippet should give you some thoughts about the
checking if a module exists part:

   #!/usr/bin/perl -w
   use strict;
 
   print "no CGI\n" unless there('CGI');
   print "no Foo\n" unless there('Foo');
 
   sub there {
my ($module) = @_;
 
eval "use $module";
 
return $@ ? 0 : 1;
   }

you might get some mileage out of schwern's new Module::Info[1]
module, but i haven't used it (yet)

and the Y/N thing might be solved by doing:

  my $input_froom_user = ;

or alternatively check out the Term::Readline[2] module for
more power.

1) http://theoryx5.uwinnipeg.ca/CPAN/data/Module-Info/Module/Info.html
2) http://theoryx5.uwinnipeg.ca/CPAN/data/perl-5.6.1-TRIAL/Term/ReadLine.html

-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: How to grab a file from web?

2001-12-20 Thread Daniel Gardner

Thursday, December 20, 2001, 9:34:29 PM, Jeff Self wrote:
> I'm trying to automate a process of grabbing a file from a website. I
> could do a system call and use wget but I would like it to be as
> portable as possible. Here's my function I've written so far:

> sub get_games_file() {
> »···use LWP::Simple;
> »···
> »···my $URL = 'http://www.mcn.net/~kenpom/cbbgames.txt';
> »···my $gamefile = get($URL) or die "Failed to get " .. $URL .": $!";
> }

> This doesn't give me any errors but it doesn't save the file to my
> computer. Am I on the right track or is there another function that
> works better?

do you try and save it somewhere afterwards? if there's no
more code than what you posted then it'll download the file
and then just ignore it. if you want to save it to a file
you could use:

   getstore($url, $file)
  Gets a document identified by a URL and stores it in
  the file. The return value is the HTTP response code.

$! won't be set if get() fails. if you want to get
interesting error codes while using get() then your needs
are no longer "Simple", and you'll have to start looking at
LWP::UserAgent et al.



-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re: extract uptime for linux box w/perl

2001-12-20 Thread Daniel Gardner

Thursday, December 20, 2001, 4:02:00 AM, KeN ClarK wrote:

> right now i do 

> w | head -1

> and get what's below my signature. I want to clean that up, cutting it 
> after the # of users, so that everything after AND including the third 
> comma is removed from that line. Then take that and add it to my signature 
> script. i can either send it to a new file and cat that into the signature 
> script, or figure out a way to write my script over in perl. right now 
> it's just a simple bash thing of 4 lines. my question is how can i read 
> the output of w | head -1 into a file, and then remove all after the 3rd 
> comma, to include the comma, and have that saved in a file?

> if there's a better way to do this, please advise. (after ghosting on this 
> list for awhile, I see how there's alot of ways to do anything...) also, 
> i'd like more or less pointers so i can kludge through this one myself.

i see you got lots of answers, but in the spirit of
TMTOWTDI, seeing as you say you're on a linux box you might
want to look at the file /proc/loadavg, which has the load
information in there.

also if you've got a copy of the cookbook around have a look
at recipe 16.22 which has some interesting stuff about using
named pipes for .sig files. named pipes are good for .sig
files...


-- 
Best Regards,
Daniel  [EMAIL PROTECTED]


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




Re: Optimizations.

2001-12-19 Thread Daniel Gardner

Wednesday, December 19, 2001, 4:38:03 PM, Ryan Guy wrote:
> I want to get a consensus here.  Do you think one liners are faster than
> more extensive programs.  Discuss.

they're both perl
they're both using the same interpreter
they're both doing the same job

if they're executing the same code, bar a little bit of
white space, then they're going to take the same amount of
time to run...


having said that, it's almost always faster to *write*
something verbose than it is to craft a finely-tuned
perl golf style one-liner.

-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re: system function question

2001-12-14 Thread Daniel Gardner

Thursday, December 13, 2001, 8:28:53 PM, Mike Gargiullo wrote:
> ok... I'm writing a perl program that will use scp to copy a file from
> one machine to another securely.

> The problem is that scp asks for the users password...  how can I have
> perl answer scp's request for a password...

> by hand it looks like so;

> $$scp -C test [EMAIL PROTECTED]:test 
> [EMAIL PROTECTED]'s password:
> test 100%
> |*|
> 0   --:-- ETA
> $$

> I would like to run the command like:

> system("scp -C test [EMAIL PROTECTED]:test");

> But how do I then feed it the password for user bob ?

there's a module called Net::SCP, which does scp in perl.

it says:

   Q: How do you supply a password to connect with ssh within a perl
   script using the Net::SSH module?

   A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage

http://theoryx5.uwinnipeg.ca/CPAN/data/Net-SCP/SCP.html

although if you're determined to do it the other way, you could look
at the Expect module: http://search.cpan.org/search?dist=Expect


-- 
Best Regards,
Daniel [EMAIL PROTECTED]


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




Re: Not creating home dir....

2001-12-14 Thread Daniel Gardner

Friday, December 14, 2001, 1:37:00 AM, Daniel Falkenberg wrote:
> Could some one help me with the following code?  Basically the code
> works OK except for the fact that the user $new_user (s) home dir is not
> created?

> #!/usr/bin/perl -w

> use Unix::PasswdFile;

> my $new_user = "test7";
> my $new_fname = "Test";
> my $new_lname = "Account";
> my $new_pass  = "password";

> my $pw = new Unix::PasswdFile "/etc/passwd";
$pw->>user("$new_user", $pw->encpass("$new_pass"), $pw->maxuid + 1, 45,
> "$new_fname $new_lname", "/home/$new_user", "/bin/false");
$pw->>passwd("$new_user", $pw->encpass("$new_pass"));
$pw->>commit();
> undef $pw;
> system("pwconv $new_user");

> Am I missing something here?

i haven't used the module, but looking at the documentation it doesn't
say anything about creating the user's home directory.

it looks like you can use Unix::PasswdFile to set the right entries in
/etc/passwd, but you'll have to make sure the directories are there
through other methods.


-- 
Best Regards,
Daniel  [EMAIL PROTECTED]


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




Re: Pre-populating standard input

2001-12-13 Thread Daniel Gardner

Thursday, December 13, 2001, 2:48:16 PM, Warren, Barry wrote:
> For example, I want to issue a command line prompt for the user to key in a
> directory name.
> I would like the current directory to be displayed on the command line and
> be editable.

> Key in directory name: /home/currentdir

how about the Term::Readline module. it's part of the standard perl
distribution, so you should already have it.

http://www.perldoc.com/perl5.6.1/lib/Term/ReadLine.html


-- 
Best Regards,
Daniel[EMAIL PROTECTED]


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




Re: How would I E-Mail something in perl.

2001-12-12 Thread Daniel Gardner

Wednesday, December 12, 2001, 11:57:53 PM, Michael Eggleton wrote:
>   I'm looking for some advice on how to e-mail a log file that my Perl
> script creates.  So here it is, I have a script that runs as an AT job 
> on a Micro$oft Windoz 2000 server.  What I would like to do is e-mail a 
> list of users when it kicks off, and then e-mail them again with the 
> log file the script created at the end.  I'm just looking for someone 
> to point me in the right direction as to commands I should look at or 
> ref web pages to read.  Most of what I have read so far deals with 
> sendmail, but I'm using a MS Server so I don't have something nice like 
> sendmail.

how about Mail::Bulkmail [1]. it sounds like it should do what you
want quite easily.


[1] http://theoryx5.uwinnipeg.ca/CPAN/data/Mail-Bulkmail/Bulkmail.html

-- 
Best Regards,
Daniel   [EMAIL PROTECTED]


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




Re: Cpan.pm

2001-12-12 Thread Daniel Gardner

Hello Daniel,

Wednesday, December 12, 2001, 11:31:13 PM, Daniel Falkenberg wrote:
> # install my favorite programs if necessary:
> for $mod (qw(Net::FTP MD5 Data::Dumper)){
>   my $obj = CPAN::Shell->expand('Module',$mod);
>   $obj->install;
> }

> I recieve the following error...

> Can't locate object method "expand" via package "CPAN::Shell" (perhaps
> you forgot to load "CPAN::Shell"?) at ./test

> Does this mean I need to install expand.PM???

i haven't used any of the CPAN modules in a script, but the error
message could be a pointer. did you forget to load "CPAN::Shell"?

ie, use CPAN::Shell


-- 
Best Regards,
Daniel [EMAIL PROTECTED]


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




Re: making a perl DLL

2001-12-11 Thread Daniel Gardner

Tuesday, December 11, 2001, 2:12:05 PM, Ben Crane wrote:
> I'm having to send some data out of MapBasic and into
> a Perl program and then return it to MapBasic. I was
> thinking a small perl DLL program would work. I know
> how to send info to a DLL file, but HOW do you make a
> perl DLL from scratch??? Any assistance/code snippets
> would be a dream. I am just passing text/number data
> that is jumbled up in Mapbasic to perl to sort it out
> and then return it.

Activestate have a product called "perl dev kit"[1] which
apparently has:

  PerlCtrl - Create ActiveX controls written in Perl
  PerlCOM - Embed Perl interpreters into client applications

is that the sort of thing?

(disclaimer: i don't do windows)

[1] http://www.activestate.com/Products/Perl_Dev_Kit/

-- 
Best regards,
Daniel   [EMAIL PROTECTED]


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




Re: Deleting a hash value

2001-12-11 Thread Daniel Gardner

Tuesday, December 11, 2001, 6:38:47 AM, Daniel Falkenberg wrote:
> Does any one know how I would go about deleing all hash keys with a star
> in them from the following hash?

> Would I go something like the following

> #!/usr/bin/perl -w

> %allusers = (
>   'users' => {
> 'user' => 'Test Account',
> '*Crudles' => 'Hello World',
> 'Crud' => 'Another Test',
> '*test' => 'Crud User'
>  }
> );

> #Delete all hashs values with a * at the beginning of their value...

> delete $allusers{$users}{$all_values} if ($all_values != /^\*/);

yes, something like that should do... perhaps

  foreach my $key (keys %{$allusers{users}}) {
  next unless (substr($key, 0, 1) eq '*');

  delete $allusers{users}{$key};
  }



-- 
Best regards,
Daniel   [EMAIL PROTECTED]


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




Re: Data::Dumper and eval question

2001-12-11 Thread Daniel Gardner

Tuesday, December 11, 2001, 1:09:06 AM, Robert Thompson wrote:

> I am using Data:Dumper in a script and am running into a problem with "use 
>strict" and eval. Basically the conundrum is that the data I will be loading from the 
>Data::Dumper file is going
> to be based off input to the final script, so it may not be the same for each run of 
>the script. There will be many dumper files that have different variables. I cannot 
>predeclare them for "use
> strict" since I won't know what they are until the eval.

> The only work around is to turn off use strict, but I would like to continue 
>using it. Is there a way, either with Data:Dumper, or something else to get this to 
>work?

> Here is the snippet of code and some source files, so if one is confused 
>hopefully this will explain:

> eval shift(@wholetemplatefile); # define $datadumperfile.
> eval shift(@wholetemplatefile); # define $outfile.
> shift(@wholetemplatefile);  # Get rid of the divider.

> # Get the Data::Dumper information.
> open (READ_DD, $datadumperfile);
> while() {
>   eval $_;
> }
> close(READ_DD);


it doesn't look like you got any replies. perhaps you could indulge
us, try explaining your problem again assuming we don't know what
Data::Dumper is. it might help...


-- 
Best regards,
Daniel  [EMAIL PROTECTED]


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




Re[2]: $searchstring help

2001-12-07 Thread Daniel Gardner

>>
>> Why slow it down with the 'i'?
>>   $searchstring=~/[a-zA-Z0-9]/;

> Why slow it down with a regular expression?  :-)

> if ( $searchstring =~ tr/a-zA-Z0-9/ ) {


i was bored, and thought i'd try a little benchmark. note, this
is for the specific problem expressed here, not the general case.

i benchmarked the following:

  RegexWithI: $string =~ /[A-Z0-9]/i;
  RegexNoI:   $string =~ /A-Za-z0-9/;
  tr: $string =~ tr/[A-Za-z0-9//;

i tested each with $string eq "A" and $string eq "z"

i ran it three times on my perl 5.6.1, linux 2.4.7, celeron 400
laptop. the results (formatting slightly adjusted)

Benchmark: timing 100 iterations
  RegexNoI(A): 18 wallclock secs (14.05 usr +  0.38 sys = 14.43 CPU) @ 69300.07/s 
(n=100)
  RegexNoI(z): 17 wallclock secs (14.05 usr +  0.40 sys = 14.45 CPU) @ 69204.15/s 
(n=100)
RegexWithI(A): 16 wallclock secs (13.86 usr +  0.40 sys = 14.26 CPU) @ 70126.23/s 
(n=100)
RegexWithI(z): 18 wallclock secs (13.54 usr +  0.25 sys = 13.79 CPU) @ 72516.32/s 
(n=100)
tr(A): 12 wallclock secs (11.30 usr +  0.16 sys = 11.46 CPU) @ 87260.03/s 
(n=100)
tr(z): 16 wallclock secs (11.32 usr +  0.50 sys = 11.82 CPU) @ 84602.37/s 
(n=100)

Benchmark: timing 100 iterations
  RegexNoI(A): 16 wallclock secs (13.84 usr +  0.29 sys = 14.13 CPU) @ 70771.41/s 
(n=100)
  RegexNoI(z): 17 wallclock secs (14.05 usr +  0.33 sys = 14.38 CPU) @ 69541.03/s 
(n=100)
RegexWithI(A): 16 wallclock secs (13.57 usr +  0.27 sys = 13.84 CPU) @ 72254.34/s 
(n=100)
RegexWithI(z): 20 wallclock secs (14.06 usr +  0.53 sys = 14.59 CPU) @ 68540.10/s 
(n=100)
tr(A): 15 wallclock secs (11.19 usr +  0.25 sys = 11.44 CPU) @ 87412.59/s 
(n=100)
tr(z): 13 wallclock secs (11.17 usr +  0.14 sys = 11.31 CPU) @ 88417.33/s 
(n=100)

Benchmark: timing 100 iterations
  RegexNoI(A): 17 wallclock secs (13.76 usr +  0.16 sys = 13.92 CPU) @ 71839.08/s 
(n=100)
  RegexNoI(z): 18 wallclock secs (13.95 usr +  0.41 sys = 14.36 CPU) @ 69637.88/s 
(n=100)
RegexWithI(A): 15 wallclock secs (13.69 usr +  0.27 sys = 13.96 CPU) @ 71633.24/s 
(n=100)
RegexWithI(z): 14 wallclock secs (13.49 usr +  0.06 sys = 13.55 CPU) @ 73800.74/s 
(n=100)
tr(A): 13 wallclock secs (11.17 usr +  0.16 sys = 11.33 CPU) @ 88261.25/s 
(n=100)
tr(z): 13 wallclock secs (10.78 usr +  0.25 sys = 11.03 CPU) @ 90661.83/s 
(n=100)


make if that what you will...

i've pasted the code i used below, it isn't very interesting.

-- 
Best regards, Daniel

"The only thing worse than being talked about - is not being talked about!" -
Oscar Wilde.




#!/usr/bin/perl -w


use Benchmark;

$string1 = "A";
$string2 = "z";

timethese( 100, { 'RegexWithI(A)' => '&with_i($string1)' ,
'RegexWithI(z)' => '&with_i($string2)',
'RegexNoI(A)' => '&without_i($string1)',
'RegexNoI(z)' => '&without_i($string2)',
'tr(A)' => '&tr_without($string1)',
'tr(z)' => '&tr_without($string2)'

  });

sub with_i {
my ($string) = @_;

$string =~ /[A-Z0-9]/i;
}

sub without_i {
my ($string) = @_;

$string =~ /[A-Za-z0-9]/;
}

sub tr_without {
my ($string) = @_;

$string =~ tr/[A-Za-z0-9]//;
}


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




Re[2]: Disable ModPerl

2001-12-07 Thread Daniel Gardner

Friday, December 07, 2001, 11:40:06 PM, Agustin Rivera wrote:

> I am under the idea that modperl recycles as many variables as possible to
> speed up script processing.  I don't want it to recycle variables in some
> scripts (in particular, ones I haven't written and have no desire to debug).

take a look at the Apache::PerlRun module. that's for running nasty
old scripts.

and if you're going to be using mod_perl very much at all get a copy
of the eagle book ("writing apache modules with perl and c"), and
digest quite a lot of the stuff in the guide -
http://perl.apache.org/guide/

perhaps this would be a nice place to start:
http://perl.apache.org/guide/intro.html#What_is_mod_perl

-- 
Best regards, Daniel

Never call a man a fool. Instead, borrow things from him.


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




Re: Disable ModPerl

2001-12-07 Thread Daniel Gardner

Friday, December 07, 2001, 11:29:15 PM, Agustin Rivera wrote:
> Is there a quick, simple command I can use to disable Modperl on all
> variables in script, without having to qw' then all?


what do you mean when you say "disable modperl"?



-- 
Best regards, Daniel

Democracy: Two wolves and a sheep voting to decide what's for dinner.


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




Re: Using die but not break out of the script

2001-12-07 Thread Daniel Gardner

Friday, December 07, 2001, 7:38:11 PM, [EMAIL PROTECTED] wrote:

> Is there a way to use die but not break the entire script?

> system ("dir $servervolume > dirinfo") || die "cant get dir info";

> I want it that if does die to assign a value of zero to a variable?  Is
> that posssible?

how about:

  $var = system ("dir ...");

it'll be 0 on success, which isn't quite what you want, but probably
just as useful.

check perldoc -f system


-- 
Best regards, Daniel

-- If you do what you always do, you'll get what you always get --


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




Re: PERL MySQL DBI

2001-12-07 Thread Daniel Gardner

Friday, December 07, 2001, 5:18:38 AM, Aaron Shurts wrote:
AS> Okay, I was the one that asked the crazy question about the weird join,
AS> but I got that figured out.  Now I have a problem.

AS> while( ($login, $existingemail, $areacode, $prefix, $rest) =
$sth->>fetchrow_array ())
AS> {
AS> print "$login,$existingemail,$areacode-$prefix-$rest\n";
AS> }

AS> That code is inside my foreach statement, but existingemail is an
AS> optional field.  If there is no email address given, I would like to
AS> print out "NO EMAIL PROVIDED".  How do I do this within my while loop.
AS> When this report is run, it is piped to a csv file so that it can easily
AS> be imported into Excel.  Thanks in advance for the help.

you could do

  while(( $a, $b, $c) = ...) {
$b ||= "NO EMAIL";
...
  }

which says "if $b is false, then assign it 'NO EMAIL'". this is a nice
generic little way for setting up default values.

the only issue with it is if $b already contains a false value that
you want to keep (eg 0) it will be overwritten, although with email
addresses that's not a problem. perl 6 is going to have //= which does
the same thing as ||= but only assigns if $b is undef.


-- 
Best regards, Daniel

Bershere's Formula for Failure: There are only two kinds of people who fail:
those who listen to nobody... and those who listen to everybody.


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




Re: Perl + Procmail

2001-12-06 Thread Daniel Gardner

Thursday, December 06, 2001, 8:23:27 PM, Agustin Rivera wrote:
AR> Anyone use Procmail to pipe information to a Perl script for processing?  If
AR> so, any basic example of the procmail recipe and a Perl script would be
AR> greatly appreciated.

something like

  :0
  *^TOwhoever
  | /my/script/here.pl

then the script gets the whole mail piped to it.

The SpamAssassin[1] module might have some examples around it, but
look at stuff like Mail::Internet et al for nice ways of making emails
perlified.

the while(<>) construct might be useful for you too...

  while (<>) {
# do something
  }

will read each line of STDIN and put it's contents into $_
  

[1] http://search.cpan.org/search?dist=Mail-SpamAssassin

-- 
Best regards, Daniel

You cannot apply a technological solution to a sociological problem.
(Edwards' Law)


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




Re: HowTo prevent CPAN upgrading perl.

2001-12-05 Thread Daniel Gardner

GS> In the past, if I've let CPAN install a bundle for just about anything, it's
GS> also gone and tried to upgrade perl first which to put it bluntly shafts my 
GS> box.  I would like to avoid this while still making use of CPAN.

i believe that newer versions of the CPAN module don't have this
"feature" - upgrade that and you should be sorted.



-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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




Re: SafePerl

2001-12-04 Thread Daniel Gardner


Monday, December 03, 2001, 12:30:25 PM, Jules wrote:
J> Our web server enables us to use 'SafePerl' for CGI scripts. I can find
J> little information relating to this, and what subset of Perl commands are
J> enabled (or correctly, which commands are disabled).
J> Can anyone point me in the right direction?

out of google's top 20 hits for 'SafePerl' most of them are from ox.ac.uk

http://www.oucs.ox.ac.uk/web/cgi/index.xml.ID=body.1_div.2

perhaps you should try asking this Sebastian Rahtz chap if he knows
what's turned off (he is the alleged author of that page after all),
he appears to have a homepage here http://users.ox.ac.uk/~rahtz/.

the conclusion being, that google is your friend.

perhaps bringing this slightly on topic for those who want to learn
perl, the Safe module is very interesting for those who want to run
code they don't trust.

http://www.perldoc.com/perl5.6.1/lib/Safe.html



-- 
Best regards,
 Daniel


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




Re: Net:SFTP license and security

2001-12-04 Thread Daniel Gardner

Tuesday, December 04, 2001, 9:32:37 PM, Ahmed Moustafa wrote:
AM> I need documents describing the license of using Net:SFTP

at the bottom of the pod for Net::SFTP it says:

   AUTHOR & COPYRIGHTS
   Benjamin Trott, [EMAIL PROTECTED]

   Except where otherwise noted, Net::SFTP is Copyright 2001 Benjamin
   Trott. All rights reserved. Net::SFTP is free software; you may
   redistribute it and/or modify it under the same terms as Perl
   itself.

AM> http://search.cpan.org/search?dist=Net-SFTP also the security issues of it
AM> i.e is the connection between the client and the server is *really*
AM> encrypted?

well... it says at the top of the pod for Net::SFTP

   Net::SFTP uses Net::SSH::Perl to build a secure, encrypted tunnel
   through which files can be transferred and managed

i suspect that most of your other questions can be answered by looking
in the pod for Net::SFTP.

-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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




Re: system `ls` or File::Find?

2001-12-03 Thread Daniel Gardner


Monday, December 03, 2001, 8:14:48 PM, Wright, Thomas wrote:

WT> When I do this in Perl thusly:

WT> $oldfile = `system "ls -1r $oldfile.\*.orig | head -1"`;

you want to use system *or* backticks, not both.

  $oldfile = `ls|head`;

should do the trick

here's something that will do it just in perl. very naive though -
it's going to call stat() about a million times (which is bad)

  $oldfile = (sort { (stat $b)[9] <=> (stat $a)[9] } <*> )[0];

i'd say that if you're happy with the shell way then stick with it -
it's going to make far more sense to you, and whoever has to maintain
the script later.

  
-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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




Re[2]: @_

2001-11-25 Thread Daniel Gardner

Hello Leon,

Monday, November 26, 2001, 12:15:59 AM, Leon wrote:

L> - Original Message -
L> From: "Jenda Krynicky" <[EMAIL PROTECTED]>
L> To: <[EMAIL PROTECTED]>
L> Sent: Monday, November 26, 2001 4:44 AM
L> Subject: Re: @_

>> When you cann a function all the parameters you gave it end up in
>> @_. You can (and usualy do) copy them then into some lexical
>> variables to give them meaningfull names. You don't have to
>> though.

>> If for example <  you wanted to write a function that sums two

L> I like your style, in fact I think everybody should follow Jenda's style of
L> giving an example after an explanation ; an example paints a thousand words.

>> numbers you can write it either as
>> sub add {
>> my ($a, $b) = @_;
>> return $a + $b;
>> }

L> On the above, so what is @_?
L> @_ = ?


if i have code like:

  $result = add( 2, 3 );

then in the code

  sub add {
   my ($a, $b) = @_;
   return $a + $b;
  }

@_ is set to the list (2, 3) just after the "sub add {" line

there's nothing really special about @_, it's the same as any other
array, eg:

  @foo = (1, 2, 3);

isn't special, @_ is just an array who's name is "_", think of the _
like the letter "a" and it might look more comprehensible.

the only special part comes when we're calling a subroutine, where @_
is used to pass the variables into our subroutine.

we could say:

  my @foo = (1,2,3);
  my ($value1, $value2, $value3) = @foo;

and now $value1 == 1, $value2 == 2 and $value3 == 3. so it's the same
when we use @_ at the start of a function.

  my ($a, $b) = @_;

does that make it any clearer?


-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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




Re: checking if a file exists

2001-11-22 Thread Daniel Gardner

Thursday, November 22, 2001, 2:19:16 PM, [EMAIL PROTECTED] wrote:

GFFC> How would I check if a certain file exists in a certain directory?

GFFC> I'm already using File::Find to process a bunch of mp3's, and before I 
GFFC> move/copy them to a different folder, I want to check if the file already 
GFFC> exists.

you can use the -e operator...

  $file = '/etc/passwd';
  if (-e $file) {
 # the passwd file exists
  }

perldoc -f -X

http://www.perldoc.com/perl5.6.1/pod/func/X.html


-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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




Re[2]: Getting past "Use of uninitialized value..."

2001-11-21 Thread Daniel Gardner

Wednesday, November 21, 2001, 6:35:46 PM, Tomasi, Chuck wrote:

TC> I hate those.  I usually end up creating a log file (or stderr in the case
TC> of web apps) and just print them out to use them again.  Nice debugging, but
TC> needless in some cases.

TC> If you figure a good way use the variable more than once without affecting
TC> the value, I'd like to hear it.

i'm interested - why do you need the variables if you're only using
them once... and what does it matter if you change the value if you're
never going to look at it again?



-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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




Re[2]: How to delete hash element

2001-11-20 Thread Daniel Gardner

Tuesday, November 20, 2001, 8:54:26 PM, Ahmed Moustafa Ibrahim Ahmed wrote:

AMIA> The value of each key is an array. And, I want to delete an
AMIA> element of this array. I don't want to delete the whole key. Is
AMIA> it possible?

delete $hash{ key }->[0];

like brett said, perldoc -f delete


AMIA>   - Original Message - 
AMIA>   From: Daniel Gardner 
AMIA>   To: Ahmed Moustafa Ibrahim Ahmed 
AMIA>   Cc: [EMAIL PROTECTED] 
AMIA>   Sent: Tuesday, November 20, 2001 12:50 PM
AMIA>   Subject: Re: How to delete hash element


AMIA>   Tuesday, November 20, 2001, 8:41:03 PM, Ahmed Moustafa Ibrahim Ahmed wrote:

AMIA>   AMIA> If I know the key and offset of the element, how can I delete that hash
AMIA>   AMIA> element, please?

AMIA>   you can delete a hash element like:

AMIA> delete $hash{ the_key };

AMIA>   but i'm not sure what you mean by "the offset of the element"



-- 
Best regards,
 Daniel


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




Re: How to delete hash element

2001-11-20 Thread Daniel Gardner

Tuesday, November 20, 2001, 8:41:03 PM, Ahmed Moustafa Ibrahim Ahmed wrote:

AMIA> If I know the key and offset of the element, how can I delete that hash
AMIA> element, please?

you can delete a hash element like:

  delete $hash{ the_key };

but i'm not sure what you mean by "the offset of the element"


-- 
Best regards,
 Danielmailto:[EMAIL PROTECTED]


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





Re[2]: Sorting a list of links by the linked text

2001-11-20 Thread Daniel Gardner

Tuesday, November 20, 2001, 7:11:34 PM, Wagner-David wrote:

WD> Here is a start:
WD> Script starts on next line:
WD> #!perl -w

WD> printf "%-20s - %-s\n", "SortField", "Url";
WD> foreach my $MyData (sort {$a->[2] cmp $b->[2]} map{ 
[$_,/="([^"]+).+\>([^<]+)\<\/a/i ] }  ) {
WD>printf "%-20s - %-s\n", $MyData->[2], $MyData->[1];
WD>  }

for those who won't have any clues whatsoever about that hunk of line
noise, i've expanded it out a bit and added some commentary.

  1: my @links;
  2: foreach my $line () {
  3:   my ($link, $desc) = $line =~ /="([^"]+).+\>([^<]+)\<\/a/i;
  4:   push @links, [ $link, $desc ];
  5: }
  6:
  7: my @sorted_links = sort { $a->[2] cmp $b->[2] } @links;
  8:
  9: foreach my $line (@sorted_links) {
 10:printf "%-20s - %-s\n", $line->[2], $line->[1];
 11: }
 
the overall aim is to read each line from the data file (what's under
__DATA__ [1]), find the interesting parts of each line, sort them, and
then print them.

using angle brackets around a file descriptor ("DATA" in this case)
will read a line in scalar context and the whole file in array
context. so our foreach line will read a line from the file, store it
in the "$line" variable and then execute the code within the loop.

that scary looking line 3 is, in fact, scary. it will pattern match on
$line, returning the right bits.

  /
   ="  # match an = then a " (like in href="
   ([^"]+) # then go find everything that's not a
   # quote and remember it
   .+  # find something, one or more time
   \>  # then a literal >
   ([^<]+) # everything that's not a < and remember it
   \<\/a   # then the string "[1] cmp $b->[1] } @links;

we need to sort the data, so we use the "sort" function [3]. this
function allows us to specify how we'd like the sorting to happen, and
in this case we want to sort on the anchor text. if you remember from
line 4 it's stored in the second element of our anonymous array.
because the first element is indexed at 0, the second is at position
1.

that'll give us all of the links sorted properly, so now we need to
print them out:

  9: foreach my $line (@sorted_links) {
 10:printf "%-20s - %-s\n", $line->[1], $line->[0];

printf is like doing a print and an sprintf [4]. that funny string
with the %'s in it is a template which says that we'd like the data
formatted please and how we'd like it formatted. in this case, we'd
like the first field left-justified within 20 spaces and the second
field just left-justified. [4] has good info about it.


hope that helps someone!


-- 
Best regards,
 Daniel


[1] http://www.perldoc.com/perl5.6.1/lib/SelfLoader.html#The-__DATA__-token
[2] http://www.perldoc.com/perl5.6.1/pod/perlreftut.html
[3] http://www.perldoc.com/perl5.6.1/pod/func/sort.html
[4] http://www.perldoc.com/perl5.6.1/pod/func/sprintf.html
[5] http://www.perldoc.com/perl5.6.1/pod/perlretut.html


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




Re[2]: Little pb with sort ...

2001-11-20 Thread Daniel Gardner

Tuesday, November 20, 2001, 6:27:44 PM, Brett W. McCoy wrote:

BWM> On Tue, 20 Nov 2001, Franck FASANO wrote:

>> Here is a little code :
>>
>> --
>> my @trav= ( 1, 12, 5, 3);
>> @trav=sort { $b cmp $a } @trav;
>>
>> foreach (@trav) {
>>  print " $_ ";
>> }
>> --
>>
>> After exec, we have :
>>  5  3  12  1

BWM> You're using the wrong operator.  You want { $b <=> $a} for your
BWM> comparison.

because <=> will do a numeric comparison, whereas cmp will do a string
comparison...

as strings "12" is less that "5", but as numbers 5 is obviously less
than 12.


-- 
Best regards,
 Daniel


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




Re: Use of packages

2001-11-19 Thread Daniel Gardner

Monday, November 19, 2001, 4:41:21 PM, Bruce Ferrell wrote:

BF> #begin example 2
BF> use packagename();
BF> sub1();
BF> sub2();
BF> #end example 2

BF> No can someone explain to me what, if anything is incorrect about the
BF> second example?  What I'm looking for is how sub-routines are used from
BF> a used module without the module name prefix.

you want to look at the Exporter module. there's full details here [1],
but what it basically comes down to is:

  package packagename;
  require Exporter;
  @ISA = qw(Exporter);

  @EXPORT_OK = qw(sub1 sub2);

  sub sub1 {
 perl code here
  }

  sub sub2 {
 perl code here
  }

  1;
  
and then in your script:

  use packagename qw(sub1 sub2);

  sub1();
  sub2();


[1] http://www.perldoc.com/perl5.6.1/lib/Exporter.html

-- 
Best regards,
 Daniel


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




Re: [OT] Who's online, which is the best method?

2001-11-19 Thread Daniel Gardner

EM> What is the best method for a Who's online type of thing?

EM> Users can either log in or be automatically logged in with a cookie on
EM> the site.

EM> How can I "see" when the user is "there" or "gone"

EM> Am I better of reading a text file or a database table?
EM> With a cron to update every x minutes the number/handles of the users?

the way i'd probably do it would be to update a database table every
time a user logged in. the table could have (username, last_access)

there is no real way with HTTP to see id a user is "there" or "gone",
the only way you can tell is if a user has not accessed any pages for
x minutes... say if they haven't accessed for 10 minutes they are
"gone".

so, on all of your pages have a function to update the "last access"
table, and when you want to see who is "there", do a select from the
table where last_access > 10 minutes ago

if you have only a few users then this will be okay, but if you have
lots of users then a cron job to delete records where the user
hasn't accessed for more than 10 minutes running once a day or
something would be good.

hope that gives you some idea of a way to start...


-- 
Best regards,
 Daniel


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




Re: include a file

2001-11-19 Thread Daniel Gardner

sre> sorry for this question, but i'm not a perl programmer. =\

sre> is there any similar function to php's "include()"?

sre> i want to include an html file into the output the user will get when
sre> opening the .pl


you could use a function something like:

sub echo_file {
  my ($filename) = @_;

  open my $fh, $filename;
  if (!$fh) {
print "Could not include $filename: $!";
return;
  }

  # slurp the whole file - don't try this with huge
  # files
  local $/ = undef;
  print <$fh>;
}


this doesn't work like the php include because it won't evaluate any
code that's in the other file, but if all you want to do is cat a file
containing html then this should be okay for you.


-- 
Best regards,
 Daniel


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




Re: pattern matching

2001-11-18 Thread Daniel Gardner

PT> Hi,
PT> Iam a beginner in perl.I have one question,
PT> Iam trying to write one prog,in which i have to search for one word in a
PT> file,
PT> If I found that word,print next 4 lines.
PT> PLs help me,how to write code.
PT> cheers,
PT> prasa.


something like this should do the trick:

open FILE, ") {
   # if the line we just read contains your word
   # then read the next four lines and print them
   if (/your_word/) {
   # loop four times (four lines)
   for (1..4) {
   # specify scalar here to ensure correct context
   print scalar ;
   } # end for
   } # end if
} # end while
close FILE;


if you want to stop after you've found the word the first time, then
add "last;" below "} # end for"

we need to say "scalar" because otherwise perl will think that we want
to print the whole of the file. "print" works in array context, and
the angle brackets <> will return all the lines in array context. if
we force it to scalar context it will only return the next line.

hth,
daniel


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




Re: Off-Topic (200%) - Where are you from?

2001-11-10 Thread Daniel Gardner

Manchester, UK


Friday, November 09, 2001, 4:07:57 PM, you wrote:

JE> Leeds, UK

JE> -Original Message-
JE> From: Mike Gargiullo [mailto:[EMAIL PROTECTED]]
JE> Sent: 09 November 2001 16:13
JE> To: [EMAIL PROTECTED]
JE> Subject: RE: Off-Topic (200%) - Where are you from?


JE> Princeton Jct., New Jersey

JE> -Original Message-
JE> From: dan radom [mailto:[EMAIL PROTECTED]]
JE> Sent: Friday, November 09, 2001 11:08 AM
JE> To: [EMAIL PROTECTED]
JE> Subject: Re: Off-Topic (200%) - Where are you from?


JE> boulder, colorado

JE> * Etienne Marcotte ([EMAIL PROTECTED]) wrote:
>> By reading the messages everyday I can guess most of us are from
JE> United
>> States right? And since there are not a lot of messages in (my)
JE> morning
>> time, probably means most are from the west coast (different
JE> timezone).
>> 
>> Am I right?
>> 
>> I'm from Quebec, Canada.. and you?
>> 
>> Sorry if it's way off topic, I hope the ones that hate OT subject
>> filtered *off*topic* in their  emails!
>> 
>> Etienne
>> 
>> -- 
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]


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




Re: array of hashes

2001-10-31 Thread Daniel Gardner

S> I have a systems hash that contains the type of system
S> as keys and the name of the machines as values:

S> %systems = (
S>sgi   => ["sgi1", "sgi2"],
S>linux => ["linux1", "linux2"],
S>dec   => ["dec1", "dec2"]
S> };

S> Now, each type of system has default values like an
S> email help address, shell used, users home directory,
S> etc.  Something like this:

S> %default = (
S> sgi   => ["sgi-help","/bin/csh","/home"],
S> linux =>
S> ["someaddress-help","/bin/bash","/usr/home"],
S> dec   => ["help-desk","bin/kcsh","/usr1/home"]
S> );

S> Is there a way to combine this last hash into the
S> first one or should I keep them separate?

there's loads of ways you could hold the data. the first one that
comes to mind looks like:

 %systems = (
sgi   =>  { defaults => ["sgi-help","/bin/csh","/home"],
machines => ["sgi1", "sgi2"],
  },
linux =>  { defaults => ["someaddress-help","/bin/bash","/usr/home"],
machines => ["linux1", "linux2"],
  },
dec   =>  { defaults => ["help-desk","bin/kcsh","/usr1/home"],
machines => ["dec1", "dec2"],
  },
 );

but it really depends on what it is you're doing with the data. you
want to design your data structure around the processing, rather than
designing a data structure that looks nice, but makes the code hard.

perhaps if you let us know what you want to do with it we might be
able to give some suggestions.

hth,
daniel


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




Re: Regex syntax

2001-10-31 Thread Daniel Gardner

FN> Hey,

FN> On an Oct 25 thread, someone asked how to remove trailing spaces.
FN> The response was $Value =~ s/\s+$//.

FN> Question.

FN> 1. The string upon which this operation was made is on $_ correct?

no - $Value.

  $Value = 'foo';
  $Value =~ s/\s+$//;
  $Value eq 'foo';


FN> 2. If I've made the assignment $tempstring = substr($_ ,0,20) how do I
FN> remove trailing spaces from $tempstring?

so do $tempstring =~ s/\s+//;


hth,
daniel


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




Re: create hash slice from hash

2001-10-31 Thread Daniel Gardner

LN> I am attempting to create a hash slice from a hash.  The hash is:

LN> %hash =("test1" => "test10",
LN>"test2" => "test12" ,
LN>   "test3" => "test13")

LN> I want the slice to include only the keys test1 and test3.  How can I
LN> accomplish this?

you could use map:

  my %new_hash = map { $_ => $hash{$_} } qw(test1 test2);

map is a really useful function...

hth,
daniel


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




Re: date/time

2001-10-01 Thread Daniel Gardner

YR> Looking for a little help for taking current time (from time) and finding
YR> the time until 1 minute after midnight.

YR> I have a daemon process (perl script) that needs to die ever new day,
YR> the process should only run from 12:01 AM Today -  l 12:01 AM Tomorrow


as ever there's more than one way to do it...

there's a variable called $^T (or $BASETIME) if you use Engligh, which
is the number of seconds since the epoch when your script started, the
time() function tells you what the number of seconds past the epoch is
now.

probably the easiest thing for you to do is a simple test like:

if (time > ($^T + (60*60*24))) {
# we want to finish
}

but you could do something clever with POSIX::strftime as well...

it depends on how exact you need to be...

hth,
daniel


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