RE: Trouble with m///g

2004-09-30 Thread Hanson, Rob
I think this might work.

/\b\d{4}\b/

Rob

-Original Message-
From: Chap Harrison [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 30, 2004 10:38 AM
To: [EMAIL PROTECTED]
Subject: Trouble with m///g


Hi,

I'm trying to extract all four-digit numbers from a string in one fell 
swoop, but I can't seem to come up with the proper regexp.  This is my 
first time using /g in a match so maybe there's a trick I'm missing.

For example, the string

 aa 444   -

should yield

, , , , , .

Here's one attempt that I thought had a reasonable chance.

- - - - -
#!/usr/bin/perl -w
my $foo =  aa 444   -;
my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g);
print $foo\n;
print(join(:,@a).\n);
- - - - -

 aa 444   -
::

Thanks for your consideration,
Chap


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


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




RE: HTML::Template is choking

2004-09-28 Thread Hanson, Rob
 The nested quotes in my attempt to put TMPL_VARs
 into the value field make me suspicious that I 
 am misusing HTML::Template

It may look odd, but the nested quotes are fine.

If I had to guess I would say it is because there is a newline within the
tag (as it seems to be in your example).  I tried it on my installation and
*did not* get an error.  I am running version 2.7.

Looking at the change log this was something that was added in version 2.3.
So if you are running anything older than 2.3 it may be time for an upgrade.

[From: http://search.cpan.org/src/SAMTREGAR/HTML-Template-2.7/Changes]
2.3 Thu June 28 12:00:00 2001
   - New Feature: template tags can now span lines.  (Roland Giersig)

Rob

-Original Message-
From: Rick Triplett [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 28, 2004 2:39 PM
To: [EMAIL PROTECTED]
Subject: HTML::Template is choking


HTML::Template is choking with the complaint ...

HTML::Template-new() : Syntax error in TMPL_* tag at /XXX[here I'm 
ommiting the path]/data/templates/student_info.tmpl : 13. at 
/usr/local/lib/perl5/site_perl/5.005/HTML/Template.pm line 2243.

This is a typical line from my template ...

input type=text name=name_full value=TMPL_VAR 
NAME=name_full size=40 maxlength=40/div

This isn't much code to look at, but I'm hoping my blunder will be 
obvious to someone with more experience. The nested quotes in my 
attempt to put TMPL_VARs into the value field make me suspicious that I 
am misusing HTML::Template. Anyone have some words of wisdom for me?
Rick T.


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


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




RE: image manipulation (scaling)

2004-09-17 Thread Hanson, Rob
The best module that I know of for scaling is Image::Magick.  I didn't find
the docs very easy to navigate, but it does a very good job.

[Very light documentation]
http://search.cpan.org/~jcristy/PerlMagick-6.02/Magick.pm

[Additional docs]
http://www.imagemagick.org/www/perl.html

The code you want would be something like this:

use Image::Magick;

my $image = Image::Magick-new;
$image-Read('logo.jpg');
$image-Crop(geometry='100x100+100+100');
$image-Write('x.jpg');


Rob

-Original Message-
From: Ingo Weiss [mailto:[EMAIL PROTECTED]
Sent: Friday, September 17, 2004 12:19 PM
To: [EMAIL PROTECTED]
Subject: image manipulation (scaling)


Hi all,

I need have my CGI scale images on the server, and I was wondering
whether there is a standard perl module that can do that (and possibly
other image manipulation tasks). I am looking for one that:

- is easy to understand and use
- is likely to be already installed on the server or so well known that
my hosting provider is likely to agree to install it for me.


Thanks for any hint!

Ingo

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


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




RE: Perl modules path related

2004-09-09 Thread Hanson, Rob

Put this at the top of your script:

use lib '/tmp/perlNew/lib';

Or you can set the environment variable PERL5LIB to that path.

Rob

-Original Message-
From: Ajey Kulkarni [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 09, 2004 5:56 PM
To: [EMAIL PROTECTED]
Subject: Perl modules path related


hi,

I've a perl script which uses a perl module located in
/tools/tools/perl/lib. If i want to change this path to say
/tmp/perlNew/lib and make the script to fetch the new /tmp/perlNew/lib
path.

How can i do this??

TIA
-Ajey


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


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




RE: PHPerl

2004-09-08 Thread Hanson, Rob

There is embperl like was mentioned.  Also Mason is very popular and well
documented.

Rob

-Original Message-
From: Octavian Rasnita [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 08, 2004 11:57 AM
To: [EMAIL PROTECTED]
Subject: PHPerl


Hi all,

Is there a way to embed Perl programs in html like PHP can do?
I heard that Perl can be used in ASP files, but I am wondering if there is
an Apache module for that task.

It would be cool to exist such a thing...

Thanks.

Teddy


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


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




RE: Month-Year Links....

2004-09-07 Thread Hanson, Rob
The trick is to use Time::Local to find the first day of the month, then
subtract 1 day.

This prints:
09-2004
08-2004
07-2004

###
use Time::Local;
use constant DAY = 86_400;

$current = time;
$previous = first_day($current) - DAY;
$current_2 = first_day($previous) - DAY;

print get_date($current), \n;
print get_date($previous), \n;
print get_date($current_2), \n;

sub first_day
{
  my $time = shift;
  my @time = localtime($time);
  $time[3] = 1;
  return timelocal(@time);
}

sub get_date
{
  my $time = shift;
  my @time = localtime($time);
  return sprintf('%02d-%04d', $time[4]+1, $time[5]+1900);
}



-Original Message-
From: Greg Schiedler [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 07, 2004 5:01 PM
To: [EMAIL PROTECTED]
Subject: Month-Year Links


Perl v5.6.1

Trying to easily create some variable based on the current month and links
to the two
previous months.  The filename(s) are based on two digit months
MM--Filename.  I have the
filename part working but I need some guidancd on creating the MM-.  I
have seen many
perl modules that I could install to implement a solution but I think that
is an overkill
just to make create a current month, previous month and two months ago
variables.

RedHat ish OS Cobalt RaQ4i to be specific

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

Ie.
$current = 09-2004-Filename
$previous = 08-2004-Filename
$current_2 = 07-2004-Filename

Does anyone have a simple solution?

Greg





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


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




RE: Month-Year Links....

2004-09-07 Thread Hanson, Rob
One note... if you have a daylight savings time that takes effect between
11pm and 1am this won't work.  In the US DST is 2am, so it is safe.

Also, this might be a prettier solution...

use Time::Local;
use constant DAY = 86_400;

$current = time;
$previous = subtract_month(time, 1);
$current_2 = subtract_month(time, 2);

print get_date($current), \n;
print get_date($previous), \n;
print get_date($current_2), \n;

sub subtract_month
{
  my $time = shift;
  my $months = shift;

  if ($months) {
$time = subtract_month(first_day($time) - DAY, --$months)
  }

  return $time;
}

sub first_day
{
  my $time = shift;
  my @time = localtime($time);
  $time[3] = 1;
  return timelocal(@time);
}

sub get_date
{
  my $time = shift;
  my @time = localtime($time);
  return sprintf('%02d-%04d', $time[4]+1, $time[5]+1900);
}




-Original Message-
From: Hanson, Rob 
Sent: Tuesday, September 07, 2004 6:33 PM
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: Month-Year Links


The trick is to use Time::Local to find the first day of the month, then
subtract 1 day.

This prints:
09-2004
08-2004
07-2004

###
use Time::Local;
use constant DAY = 86_400;

$current = time;
$previous = first_day($current) - DAY;
$current_2 = first_day($previous) - DAY;

print get_date($current), \n;
print get_date($previous), \n;
print get_date($current_2), \n;

sub first_day
{
  my $time = shift;
  my @time = localtime($time);
  $time[3] = 1;
  return timelocal(@time);
}

sub get_date
{
  my $time = shift;
  my @time = localtime($time);
  return sprintf('%02d-%04d', $time[4]+1, $time[5]+1900);
}



-Original Message-
From: Greg Schiedler [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 07, 2004 5:01 PM
To: [EMAIL PROTECTED]
Subject: Month-Year Links


Perl v5.6.1

Trying to easily create some variable based on the current month and links
to the two
previous months.  The filename(s) are based on two digit months
MM--Filename.  I have the
filename part working but I need some guidancd on creating the MM-.  I
have seen many
perl modules that I could install to implement a solution but I think that
is an overkill
just to make create a current month, previous month and two months ago
variables.

RedHat ish OS Cobalt RaQ4i to be specific

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

Ie.
$current = 09-2004-Filename
$previous = 08-2004-Filename
$current_2 = 07-2004-Filename

Does anyone have a simple solution?

Greg





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


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


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




RE: Image::Magic / Perl::Magick

2004-08-25 Thread Hanson, Rob
Maybe this will help... maybe it won't.

I just tried installing Image::Magick (on Win2K/AS perl 5.6.1 build 635),
and had no issues.  The install showed that it installed Magick.dll, and
where it was installed to.  Note that I used Image-Magick, which is how AS
has it stored in the repository.

[session follows]
H:\ppm install Image-Magick
Installing package 'Image-Magick'...
Downloading
http://ppm.ActiveState.com/PPMPackages/5.6plus/MSWin32-x86-multi-thr
ead/Image-Magick.tar.gz ...
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.bs
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.dll
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.exp
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.lib
Installing C:\perl2\html\site\lib\Image\Magick.html
Installing C:\perl2\site\lib\Image\Magick.pm
Installing C:\perl2\site\lib\auto\Image\Magick\autosplit.ix

The I queried it using the query command...

H:\ppm query Image-Magick
Image-Magick [0]

Also tried using the module (which should load the DLL you mentioned) with
no problems.

H:\perl -e use Image::Magick

Rob



-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 25, 2004 12:48 PM
To: Beginners (E-mail)
Subject: Image::Magic / Perl::Magick 


I've asked this question on the ImageMagick bugs mailing list...w/ no reply.
If anyone has any suggestion, I would greatly appreciate it.  
I have both ImageMagick and PerlMagick installed. I can view pictures fine
w/ ImageMagick,  I just can't use the Image::Magick module...  Do I have the
modules installed correctly?  I let the ImageMagick software install them.
I checked ppm but I didn't see them installed.  Was I doing something
wrong?  ppm search Image::Magick ...ppm returned no match.  Same w/
PerlMagick.  
Is there another way to check the ppm?

- 
C:\Program Files\ImageMagick-6.0.5-Q16\PerlMagick\demoperl shapes.pl 
Can't load 'C:/Perl/site/lib/auto/Image/Magick/Magick.dll' for module
Image::Mag 
ick: load_file:One of the library files needed to run this application
cannot be 
found at C:/Perl/lib/DynaLoader.pm line 229. 
at shapes.pl line 4 
Compilation failed in require at shapes.pl line 4. 
BEGIN failed--compilation aborted at shapes.pl line 4. 

- 

Thanks in advance! 

Brian 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]



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


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




RE: Image::Magic / Perl::Magick

2004-08-25 Thread Hanson, Rob
 Error installing package 'PerlMagick': Read a PPD
 for 'PerlMagick', but it is not intended for this
 build of Perl (MSWin32-x86-multi-thread)

The error just means that ActiveState has this module in their repository,
but they don't have a version compiled for Windows.

So you are out of luck, unless you happen to have Microsoft's C++ compiler.
I believe not only do you need the MS C++ compiler, but it may also need to
be the same version the ActiveState uses to compile the perl executable
(someone, please correct me if I am wrong).

I took a look at the package on CPAN
(http://search.cpan.org/src/JCRISTY/PerlMagick-6.02/), and the README.txt
says that it does include a Makefile just for Windows... so it should
compile if you have the compiler.

Other than that all you can do is ask if someone already has it compiled,
and can send you the files.

Maybe you could even send a mail to ActiveState, I'm not sure but maybe if
they are in a good mood they might get it added to the repository (there may
even be some AS employees on this list, I see one poster's name that looks
familiar, but I'm not sure if he still works there).

Rob


-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 25, 2004 5:42 PM
To: Hanson, Rob; Beginners (E-mail)
Subject: RE: Image::Magic / Perl::Magick 


Rob,

Did you have any problems installing PerlMagick?  Below is the error I
received.  Any suggestions?

Thanks again for your help.  ImageMagick is now working.

Brian


PPM install PerlMagick
Install package 'PerlMagick?' (y/N): y
Installing package 'PerlMagick'...
Error installing package 'PerlMagick': Read a PPD for 'PerlMagick', but it
is no
t intended for this build of Perl (MSWin32-x86-multi-thread)

-Original Message-
From: Hanson, Rob [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 25, 2004 12:39 PM
To: 'Brian Volk'; Beginners (E-mail)
Subject: RE: Image::Magic / Perl::Magick 


Maybe this will help... maybe it won't.

I just tried installing Image::Magick (on Win2K/AS perl 5.6.1 build 635),
and had no issues.  The install showed that it installed Magick.dll, and
where it was installed to.  Note that I used Image-Magick, which is how AS
has it stored in the repository.

[session follows]
H:\ppm install Image-Magick
Installing package 'Image-Magick'...
Downloading
http://ppm.ActiveState.com/PPMPackages/5.6plus/MSWin32-x86-multi-thr
ead/Image-Magick.tar.gz ...
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.bs
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.dll
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.exp
Installing C:\perl2\site\lib\auto\Image\Magick\Magick.lib
Installing C:\perl2\html\site\lib\Image\Magick.html
Installing C:\perl2\site\lib\Image\Magick.pm
Installing C:\perl2\site\lib\auto\Image\Magick\autosplit.ix

The I queried it using the query command...

H:\ppm query Image-Magick
Image-Magick [0]

Also tried using the module (which should load the DLL you mentioned) with
no problems.

H:\perl -e use Image::Magick

Rob



-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 25, 2004 12:48 PM
To: Beginners (E-mail)
Subject: Image::Magic / Perl::Magick 


I've asked this question on the ImageMagick bugs mailing list...w/ no reply.
If anyone has any suggestion, I would greatly appreciate it.  
I have both ImageMagick and PerlMagick installed. I can view pictures fine
w/ ImageMagick,  I just can't use the Image::Magick module...  Do I have the
modules installed correctly?  I let the ImageMagick software install them.
I checked ppm but I didn't see them installed.  Was I doing something
wrong?  ppm search Image::Magick ...ppm returned no match.  Same w/
PerlMagick.  
Is there another way to check the ppm?

- 
C:\Program Files\ImageMagick-6.0.5-Q16\PerlMagick\demoperl shapes.pl 
Can't load 'C:/Perl/site/lib/auto/Image/Magick/Magick.dll' for module
Image::Mag 
ick: load_file:One of the library files needed to run this application
cannot be 
found at C:/Perl/lib/DynaLoader.pm line 229. 
at shapes.pl line 4 
Compilation failed in require at shapes.pl line 4. 
BEGIN failed--compilation aborted at shapes.pl line 4. 

- 

Thanks in advance! 

Brian 
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]



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

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




RE: Web Application with PERL or ASP.NET

2004-08-13 Thread Hanson, Rob
 I need to prove that perl is better that ASP.NET for the project.

This is like comparing apples and granola bars.  Perl is a language and
ASP.Net is a framework.  What you should really be doing is comparing Perl
vs. C# (or VB.Net).

ASP.Net (and /Net in general) is a powerful tool, and although I was only
breifly introduced to it I can see where it could enhance a project.  Things
like seamless multi-language support and the ability to code a web app like
a desktop app (a distributed app coded like a local app) are pretty powerful
things.

If I had the opporunity to code for ASP.Net I think I would be a big fan.

So perhaps you shouldn't be trying to convince them that Perl is better than
ASP.Net... perhaps you should instead try to convince them that Perl is
better than C# (or VB.Net) due to the language features and most importantly
the vast library of pre-written code that is available.

So what I am trying to say is, look at Visual Perl
(http://www.activestate.com/Products/ActivePerlProStudio/?_x=1).  It let's
you write .Net apps in Perl.  Sort of the best of both worlds.

Just to give you some background on where I am coming from, I used to be an
ASP developer.  At my jast job I was pulled into the Internet Resources
Department due to the fact that I knew Perl, and although it was an ASP
shop, they had a need to write a CGI app for an external server.
Unfortunately the CGI project fell through, but I did convince them that
Perl was more powerful than VBScript, and they installed ActivePerl which
allowed Perl coding in the ASP pages.  In general we found that things that
the VBScript programmers strugged with I was able to do easily just because
of the language features (regular expressions in particular) and the
available libraries.

Hope that helps some.

Rob




-Original Message-
From: Joe Echavarria [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 10, 2004 3:37 PM
To: [EMAIL PROTECTED]
Subject: Web Application with PERL or ASP.NET


Hi there,

  The company i work is considering two tools for the
web version of a loan system.  I need to prove that
perl is better that ASP.NET for the project. Can
anyone help me ?, is posible with perl have controls
?, data grids ?, date controls ?, the way that asp.net
works ?, why perl is better ?, give examples of robust
web applications writtern in perl , links, examples,
etc. anything that could help me prove that perl is
better for the project. 

  Thanks.



__
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

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


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




RE: splitting large xml file

2004-07-22 Thread Hanson, Rob
 Ideally, I would use SAX to parse things

Optionally you could look at XML::RAX.

Article on the RAX concept:
http://www.xml.com/pub/a/2000/04/26/rax/index.html

RAX allows you to specify a record seperator (a tag in the XML file), and
splits into into chunks of that tag.  It is stream based so it only reads in
as much of the file it needs to construct the next record.  It only applies
to XML files that fit that type of format though (like RSS).  At the very
least you might find the code helpful.

 but I can't figure out how to echo the data
 back out exactly as I got it.

I'm not sure I completely understand.  Anyway I am out of here today, hope
you find an answer.

Rob


-Original Message-
From: Sean Davis [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 22, 2004 5:42 PM
To: [EMAIL PROTECTED]
Subject: splitting large xml file


I have a very large (200Mb) XML file that consists of multiple records.  I
would like to split these records up and store the XML for each in a
database for quick retrieval.  I simply need to echo all of the XML between
the enclosing record tags into the database.  Ideally, I would use SAX to
parse things, but I can't figure out how to echo the data back out exactly
as I got it.  Any clues?

Thanks,
Sean




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


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




RE: Install modules locally

2004-07-22 Thread Hanson, Rob

I don't recall that thread, but basically you can do a few things.

When you install, specify some local directory to install into:

perl Makefile.PL PREFIX=/some/local/path LIB=/some/local/path

/some/local/path is the root of your local library.

For some modules that don't require pre-processing (compiling C code, etc)
you can just copy the module to the correct location.  For example
My::Module would live at /some/local/path/My/Module.pm.

To use it from there you can...

1. use lib

use lib '/some/local/path';
use My::Module;

2. set the PERL5LIB environment variable

In your shell config file (.bashrc, etc):
export PERL5LIB=/some/local/path

...Then use the module normally in command line scripts.

If you need this for a CGI, set this variable in the .htaccess or main
Apache config:
setenv PERL5LIB /some/local/path

...Then use the module normally in CGI scripts.

3. add it to the @INC (I perfer option #1 to this though, also I am unsure
if this syntax is correct):

BEGIN {
  unshift @INC, '/some/local/path';
}

Rob


-Original Message-
From: Mike Blezien [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 22, 2004 5:52 PM
To: Perl List
Subject: Install modules locally


Hello,

I seemed to recall an earlier posting regarding instruction on how to
install 
Perl modules locally when one doesn't have root access, but was able to find
the 
thread. Can someone possible post that info again.

Much appreciated :)

-- 
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://thunder-rain.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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


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




RE: Perl and XML::Simple

2004-07-19 Thread Hanson, Rob
 results id=Quiz1 file=Quiz1.pdf n=3

This isn't well-formed XML.  The n=3 must be n=3.  All attributes in XML
must be quoted, either single-quotes or double-quotes.

Rob

-Original Message-
From: David Arnold [mailto:[EMAIL PROTECTED]
Sent: Monday, July 19, 2004 2:04 AM
To: [EMAIL PROTECTED]
Subject: Perl and XML::Simple


All

I tried to run this:

#! /usr/local/bin/perl -w
# File: Responses.pl

use strict;
use warnings;

# Import the SML::Simple module
use XML::Simple;
use Data::Dumper;

# Turn the file into a has reference, using XML::Simples' XMLin
# subroutine. We'll also turn on the 'forcearray' option, so that all
# elements contain arrayrefs.
my $resp_xml=XMLin('./Responses.xml',forcearray=1);

print Dumper $resp_xml;

On this file:

[EMAIL PROTECTED] perlxml]# cat -A Responses.xml
 results id=Quiz1 file=Quiz1.pdf n=3question n=1 type=mc
ptype=2.1 points=1 credit=0
correct=0valuea/value/questionquestion n=2 type=mc ptype=5.4
points=1 credit=0 correct=0valuea/value/questionquestion n=3
type=mc ptype=3.6 points=1 credit=0
correct=1valuea/value/question/results$
[EMAIL PROTECTED] perlxml]#

And I got this error message:

[EMAIL PROTECTED] perlxml]# ./Responses.pl
Not a quote character [Ln: 1, Col: 38]

Can anyone help?

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


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




RE: Another Perl datatype headache ( scalars $, hashes %, and arr ays @ )

2004-07-19 Thread Hanson, Rob
 I still don't know how to declare arrays using only '$' instead of '@'

You can't.  But you can store a *reference* to an array in a scalar.

This will work:

# the backslash (\) returns a reference to the
# variable, so this doesn't actually pass the array,
# it passes a reference (pointer sort of) to the array.
goodsub([EMAIL PROTECTED], $scalar);

sub goodsub()

{
  my ($array_ref,$scalar) = @_; 

  # turns the ref back to an actual array.
  my @array = @{$array_ref};

  # or use the array directly through the ref.
  # note that changes made through a ref will change
  # the original array.
  print $array_ref-[0];
}

 Is it possible to write scripts using only '$'
 instead of other prefix symbols?

No, not the way you intend.  You could use only references, but that
wouldn't make sense.

Rob

-Original Message-
From: gohaku [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 18, 2004 8:59 PM
To: Perl Beginners
Subject: Another Perl datatype headache ( scalars $, hashes %, and
arrays @ )


Hi everyone,
after writing perl scripts for about 3 years now, I still have trouble 
with the
basic datatypes.
I know that variables that start with '$' are scalars.
This covers Hashes ($HASH{$key}), Arrays ( $_[0] ), and
regular scalar values ( $foobar );

The code I write as well other's code is still unreadable to me
even though I have followed examples from the
Camel book, many other Perl books from O'Reilly and online references.
I have also used perldoc on many occasions.

There are still some things that haven't sunk in, such as:

If I want to add Hash keys to another Hash, I do the following:

%HASH = ( 1 = 'one' ); #NO BRACES OR ELSE
%HASH2 = ( 2 = 'two' ); AGAIN, NO BRACES OR ELSE...
@HASH2{ keys %HASH } = ;
#confusing, considering it's the symbol used for arrays

To get the length of an array, it's $#array, not [EMAIL PROTECTED] or #$array.
Usually, I use scalar @array;

Problems with subroutines where the array is the first argument
sub badsub()

{

my (@array,$scalar) = @_;   
#Pass Array last!
#my ($scalar,@array) = @_:
...
}

I still don't know how to declare arrays using only '$' instead of '@'

anyway, Is it possible to write scripts using only '$' instead of other 
prefix symbols?
In other words, a php-style script written in perl

Thanks in advance.
-gohaku


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


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




RE: Use of uninitialized value in string eq

2004-07-08 Thread Hanson, Rob
 Use of uninitialized value

This just means that you haven't given a value to $atmnb yet (which will
happen unless /^XXX/ matches in your loop).

To get rid of the warning you should initialize the variable when you create
it.

Instead of:
my $atmnb;

Use this:
my $atmnb = '';

Rob


-Original Message-
From: FyD [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 3:50 PM
To: [EMAIL PROTECTED]
Subject: Use of uninitialized value in string eq


Hi,

Here is a short perl script:

   open (FILE, $START);
   $nbc=0;
   foreach(FILE){
if (/^XXX/ig)   { $atmnb[$nbc]++;}
if (/^YYY/ig)   { $atmnb1=$atmnb[0];}
if (/^ZZZ/ig)   { $nbc++;}
   }
   if ($atmnb1 eq )   { $atmnb1=$atmnb[0];}
   close(FILE);
   $nbc++;

When I try to execute it using the '-w' option, I get the following warning:
Use of uninitialized value in string eq at RED-II.pl line 8

I do not understand as for me ($atmnb1 eq ) is needed for uninitialized
values.

How can avoid such warnings ?

Thanks, Francois

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


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




RE: where to put modules?

2004-07-08 Thread Hanson, Rob

To see what directories are in your Perl's path, you can run this at the
command line.  It should work on Win or *nix.

perl -e print join(qq[\n], @INC)

You might instead want to create your own private library by setting the
PERL5LIB environment variable.  It will add a directory to the beginning of
your @INC path.

So, for example, on Unix you might create a directory called ~/my_modules/.
You would place the module in ~/my_modules/CJB/String.pm.  ...And in your
environment you would set PERL5LIB to ~/my_modules/.  On *nix (with bash)
add to your .bashrc export PERL5LIB=~/my_modules/.

Rob

-Original Message-
From: Christopher J. Bottaro [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 2:40 PM
To: [EMAIL PROTECTED]
Subject: where to put modules?


lets say i made a module called cjb::string.  where would i put
cjb/string.pm?  i'm using fedora core 1 and the default perl installation. 
i've read in my book about modules and a little bit about them on
perldoc.com, but i couldn't find the answer to this.

thanks.


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


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




RE: Query Oracle, show results (need help!!)

2004-06-08 Thread Hanson, Rob

I think you should turn on errors... by debault DBI will supress them.

After the DB connection, put this...
$db-{RaiseError} = 1;

Once you do this you will see that your prepare failed, your SQL syntax is
not valid.

 select * from ban where row num  100

It should be rownum, not row num.

Rob

-Original Message-
From: jason corbett [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 08, 2004 3:53 PM
To: [EMAIL PROTECTED]
Subject: Query Oracle, show results (need help!!)


Hello all. I am trying to log into an Oracle database, send this query {
select * from ban where row num  100} and I am getting erros like:
 
can't call method 'execute' on an undefined value at (filename) line_number.
Got any suggestions?
 
 
using the following perl script:
 
#!/usr/bin/perl -w
use strict; 
use DBI; 
#  $ENV{ORACLE_HOME}=/orav101/oracle/8.0.6; 

#Gather data for connecting to database:
 
 
print Enter the database name that you want to connect to: ;
chomp (my $database_name1=STDIN);
print Enter the username: ;
chomp (my $username=STDIN);
print Enter the password: ;
chomp (my $passwd=STDIN);

#Must define the database here:
my $database=dbi:Oracle:$database_name1;

#Connecting to the database:database=database_name1','$username','$passwd'

#Note the variables for username and password must be username and passwd
ONLY!!
my $dbh = DBI-connect($database, $username, $passwd) 
  or die Can't connect to Oracle database: \n $DBI::errstr\n; 

#Set up your sql statement that you want to run in Oracle
my $sql=qq(select * from ban where row num  100);
 
Prepare the SQL statement for running and it'll be stored in Oracle buffer
my $sth=$dbh-prepare($sql);
 
#Execute the SQL statememt
$sth-execute || die Couldn't execute statement;

while (my @record= $sth-fetchrow_array)
{
 for  (@record){
  print (@record);
}
print \n\n;
}

$dbh-disconnect;
 
 
 


-
Do you Yahoo!?
Friends.  Fun. Try the all-new Yahoo! Messenger

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




RE: how to execute make command

2004-06-03 Thread Hanson, Rob
Thre ways...

exec('make');
system('make');
`make`;

The three differ slightly, you might want to check the docs.

Breifly...

exec - executes the command, but your Perl program ends where it is.
system - executes the command, waits for it to finish, returns the return
code.
`` (backticks) - executes the command, waits for it to finish, returns the
output (STDOUT, not STDERR).

Rob

-Original Message-
From: Sidharth [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 03, 2004 11:27 AM
To: [EMAIL PROTECTED]
Subject: how to execute make command 


hi all,

i want to know  how to execute makefile  from  the perl script ,its a sort
of urgent .

thank u all in advance...

-
There is nothing in a caterpillar that tells you it's going to be a
butterfly.   - Anonymous

*
Sidharth M Patil
Engineer
Kyocera-Wireless (India) Pvt Ltd
5th Floor, Phase I, Divyashree Towers,
Guruppanapalya, Bannerghatta Road,
Bangalore-560072
Tel : 51106988  extn  5171
*

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




RE: Loading Scalar Vars with Text - Readability

2004-06-01 Thread Hanson, Rob
You could do create the string then strip the space.  I think there was
something in the Perl Cookbook that was similar to this.

my $longlist = no_space(END_OF_LIST);
Clause1|
Clause2|
Clause3|
Clause4
END_OF_LIST

print $longlist;


sub no_space
{
  my $txt = shift;
  $txt =~ s/^\s+//;
  $txt =~ s/\s*\n\s*//sg;
  $txt =~ s/\s+$//;
  return $txt;
}

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 01, 2004 3:16 PM
To: [EMAIL PROTECTED]
Subject: Loading Scalar Vars with Text - Readability


Hi, 
   Adding Perl to the list of languages... and came across a question of
loading vars with very long strings...

   Actually I am modifiying a prior employee's code and want to make it
more readable.

currently the code is such:
my $longlist = Clause1|Clause2|Clause3|Clause4|...|ClauseN;

I would like to know why I can't make this more readable?  Is it because
newline characters would be added to the mix?  I would like to do
something like this:

my $longlist = Clause1|
Clause2|
Clause3|
Clause4|
...|
ClauseN;

Please copy me directly on your response.  T

Thanks,
Art Bahrs
[EMAIL PROTECTED]



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


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




RE: regex alternation question

2004-05-20 Thread Hanson, Rob
 Would this be correct:  /foo|bar/

Yes.

 Should they be grouped thusly: /(foo|bar)/

This works too, but has the side effect of setting $1 to the matched value,
either foo or bar.

 What about /(?:foo|bar)/   ?

This is ok too, but the parens aren't necessary.  If you wanted to search
for foobar or ff you would need the parens.

/foo(?:bar|oof)/

In this case you need the parens to group the alternation part of the
expression.

Rob


-Original Message-
From: Rich Fernandez [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 20, 2004 4:23 PM
To: '[EMAIL PROTECTED]'
Subject: regex alternation question


I'm unclear about how alternation works in a regex.
 
Say I want to find either foo or bar within a string. I don't care which
one I match, only that I make a match.
Would this be correct:  /foo|bar/
 
Should they be grouped thusly: /(foo|bar)/
 
What about /(?:foo|bar)/   ?
 
Specifically, I know that the second one remembers which one is found and
the third one doesn't. But is the first example wrong? 
 
TIA
 
richf

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


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




RE: Making a linker/preassembler

2004-04-15 Thread Hanson, Rob
I don't know much about asm, but maybe this will help a little. A s///
should work, and as the replacement value it can call a function to do the
work.

# untested
$code = handle_includes($code);

sub handle_includes {
  my $code = shift;
  $code = s/^\s*include\s+([\w\.]+)/include_file($1)/eg;
  return $code;
}

sub include_file {
  my $file = shift;
  my $result;

  local $/ = undef; # slurp mode

  open IN, $file or die Cannot include file $file: $!\n;
  $result = IN;
  close IN;

  $result = handle_includes($result); # recursively handle includes

  return $file_content;  
}

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 3:38 PM
To: [EMAIL PROTECTED]
Subject: Making a linker/preassembler


Hi,

I'm planning to make a kind of linker/preassembler for making ROM source 
files from multiple header and ASM files.

What sort of regular expression and algoriths could I use to search for 
things like include Name.dat, etc?

Thanks,

Lewis

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




RE: Simple regex

2004-04-15 Thread Hanson, Rob
Try this...

# untested
$text =~ s/\[[^\]]+?\]/$1/g;

[^\]] - means anything but a closing bracket
+? - means 1 or more times (as few as possible)

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 7:11 PM
To: [EMAIL PROTECTED]
Subject: Simple regex


How can I write a regular expression to keep the part of a string that's
between a pair of square braces?  Here's a sample line:

Updating Wellbore Set Keys: [wlbr_id = 1234567890, data_provider_code =
MTBL, welltype = OIL]

Thanks in advance for your help!

Scott

Scott E. Robinson
SWAT Team
Data Mgt Practices  Operations (DMPO)
RR-690 -- 281-654-5169
EMB-2813N -- 713-656-3629


Safe today - here tomorrow


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


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




RE: Regex to match domain for cookie

2004-04-15 Thread Hanson, Rob

It might be easier to do it with a split.

# untested
foreach (@domains) {
  my @parts = split(/\./, $_);
  my $name;
  
  if (@parts  1) {
shift @parts;
$name = '.' . join('.', @parts);
  }

  print $name;
}

As a regex, this I think will work...

foreach (@domains) {
  my $name = $_;
  $name =~ s/^[^\.]+//;
  print $name;
}


-Original Message-
From: B. Fongo [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 7:29 PM
To: [EMAIL PROTECTED]
Subject: Regex to match domain for cookie


How do I match a domain name starting from the dot? 
 
# Match something like these
.domain4you.co.uk
.domain-house.de
 
 
This is what I have:
 
 
@domains = (http://www.domain.com , http://www.domain4you.co.uk  
http://www.domain-house.de; https//rrp.cash-day.com
  );
 
 
foreach (@domains){
 
$_ =~ /^\D ([\.A-Za-z0-9]+[\.\D])$/; # What is wrong here?
# Need .domain.com, but I get ww.domain.com
$x = $1;
print $x;
 
 
}
 
 
 
Babs
 
 
 

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




RE: Nothing executes after system.

2004-03-05 Thread Hanson, Rob
 Any idea why print never gets executed?

The su is probably waiting for you to enter in a password.

...And this probably doesn't do what you think anyway.  Even though you su,
it doesn't change who the current script is running under.  Your program (as
written) will spawn a new process, execute su, then close that process.

Hope that helps.

Rob

-Original Message-
From: Silky Manwani [mailto:[EMAIL PROTECTED]
Sent: Friday, March 05, 2004 1:16 PM
To: [EMAIL PROTECTED]
Subject: Nothing executes after system.


Hello,

@args = (/usr/bin/su,sam);
system(@args);
print hello;

Any idea why print never gets executed? So, the switch user takes place 
but nothing gets executed after that..

Thanks.


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


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




RE: Nothing executes after system.

2004-03-05 Thread Hanson, Rob
 Is there another way os saying su using perl?

You might be able to do it with the POSIX module, and the setuid() call.
But I can't say that I have tried it, so I am only guessing.

See:
 man setuid
 http://search.cpan.org/~lbrocard/perl5.005_04/ext/POSIX/POSIX.pod

Rob

-Original Message-
From: Silky Manwani [mailto:[EMAIL PROTECTED]
Sent: Friday, March 05, 2004 1:30 PM
Cc: [EMAIL PROTECTED]
Subject: Re: Nothing executes after system.


It doesn't wait for the password. I can see that it switches the user 
coz the prompt changes. But as you said , yes, since another process 
gets spawned and su gets executed.

Is there another way os saying su using perl?

Thanks.

On Mar 5, 2004, at 10:26 AM, Hanson, Rob wrote:

 Any idea why print never gets executed?

 The su is probably waiting for you to enter in a password.

 ...And this probably doesn't do what you think anyway.  Even though 
 you su,
 it doesn't change who the current script is running under.  Your 
 program (as
 written) will spawn a new process, execute su, then close that process.

 Hope that helps.

 Rob

 -Original Message-
 From: Silky Manwani [mailto:[EMAIL PROTECTED]
 Sent: Friday, March 05, 2004 1:16 PM
 To: [EMAIL PROTECTED]
 Subject: Nothing executes after system.


 Hello,

 @args = (/usr/bin/su,sam);
 system(@args);
 print hello;

 Any idea why print never gets executed? So, the switch user takes place
 but nothing gets executed after that..

 Thanks.


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


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




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


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




RE: How to capture pid

2004-03-02 Thread Hanson, Rob
I'm not sure, probably by forking and execing.  It won't return the result
code from the other program though.


$some_process = 'tcpdump -v -ieth0 file';

my $pid = fork();
unless ($pid) {
  exec($some_process);
  die Can't start $some_process: $!;
}

print Pid is $pid\n;


-Original Message-
From: Harry Putnam [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 02, 2004 3:34 PM
To: [EMAIL PROTECTED]
Subject: How to capture pid



What is the handy way to record the pid of $some_process in this
fake code?

$some_process = 'tcpdump -v -ieth0 file')
system($some_process) or die Can't start $some_process: $!;

print Pid is $pid\n;

The process is started by a more elaborate perl script at bootup.
and restarted every four hours from syslog. Code above is way simplified.

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


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




RE: Count the number of lines in a file without actually iteratin g through the file

2004-02-25 Thread Hanson, Rob
 Is there a way to determine the number of lines
 in a file without actually iterating through the
 file and incrementing a file?

No.

 I found the following on perlmonks.org, it works
 great but this is command line syntax

When you deparse that command (see below), you can see that all it does is
read each line of the file and set $_ to the line number (*.).  After
reading in each line it then prints the result.  So there is no silver
bullet.

$ perl -MO=Deparse -lpe '}{*_=*.}{' file

LINE: while (defined($_ = ARGV)) {
chomp $_;
}
{
*_ = *.;
}
{
();
}
continue {
die -p destination: $!\n unless print $_;
}



-Original Message-
From: Jason Normandin [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 25, 2004 6:56 PM
To: Perl Beginners
Subject: Count the number of lines in a file without actually iterating
through the file


Hi List.

 

Is there a way to determine the number of lines in a file without actually
iterating through the file and incrementing a file?

 

I found the following on perlmonks.org, it works great but this is command
line syntax

:

perl -lpe '}{*_=*.}{' file

 

How could I integrate this into a script without invoking another instance
of Perl?

 

Thanks !

~Jason



 

 If, after the first twenty minutes, you don't know who the sucker at the
table is, it's you. 

 



 


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




RE: substitution

2004-02-23 Thread Hanson, Rob
 Is it possible to do this

No, at least not the way you are doing it.

Something like this will work (untested)

my %replacements = (ARE = 756, TYP = 978, SPE = 840);
$marque =~ s/(ARE|TYR|SPE)/$replacements{$1}/;

Rob

-Original Message-
From: Olivier Wirz [mailto:[EMAIL PROTECTED]
Sent: Monday, February 23, 2004 1:39 PM
To: [EMAIL PROTECTED]
Subject: substitution


Hello,

Is it possible to do this kind of substitute to change ARE in 756, TYP in
978 (not with an if) ...:

$marque =~ s/(ARE|TYR|SPE)/(756|978|840)/;# don't bring the result I
want.

Thank you.

Olivier



-- 
GMX ProMail (250 MB Mailbox, 50 FreeSMS, Virenschutz, 2,99 EUR/Monat...)
jetzt 3 Monate GRATIS + 3x DER SPIEGEL +++ http://www.gmx.net/derspiegel +++


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


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




RE: lc

2004-02-20 Thread Hanson, Rob
 then I tried this:
 lc($input);
 and I got the same error.

This shouldn't give an error.  ...It didn't give me one.

 so I tried this:
 lc(chomp($input = STDIN)));
 and I got an error message that said I couldn't use lc
 in that way - or something like that.

The exact error would be helpful.

This won't work though because chomp() returns the number of newline
characters removed from the string... so in essence you are trying to
lowercase the number 0 or 1 (the return value of chomp).  ...Not to
mention that you lc() does not modify the scalar passed as an argument (like
chomp does), so you need to store the result of lc().

This is what you want:

chomp($input = STDIN);
$input = lc($input);
print $input;

Rob

-Original Message-
From: Stuart White [mailto:[EMAIL PROTECTED]
Sent: Friday, February 20, 2004 5:21 PM
To: Perl Beginners Mailing List
Subject: lc


I want to take input from STDIN and then convert it
to lowercase.  so I tried this:

lc(chomp($input = STDIN)));

and I got an error message that said I couldn't use lc
in that way - or something like that.  I can't
remember the message now.

then I tried this:

lc($input);

and I got the same error.

Then I checked my copy of Learning Perl and the index
pointed me to an example of lower case, but it was a
regex example, not a function.  So I thought that
perhaps I had confused two different languages and
that Perl didn't have a lowercase function.

Just now I checked the man pages to see if I really
was not remembering the function for lowercase.  When
I went there, sure enough, lc was there.  

http://www.perldoc.com/perl5.8.0/pod/func/lc.html

The way it is described makes me think that I am using
it correctly, but Perl is telling me different.
So, am I using it incorrectly?  Thanks

__
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

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


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




RE: quote marks in DBM

2004-02-08 Thread Hanson, Rob
 Must I abandon trying to get double-quote marks
 into my hash element?

No, it would be silly if the language didn't support that.  And I want to
apologize for my long winded answer that is to follow... I guess I just felt
like typing.

...

As for an answer I think some explanation is needed, otherwise it won't help
much the next time you have a problem.

The hash value is just a scalar value, and a scalar can hold ANY type of
data... even binary.

There are several ways to quote a scalar value...

Single-quotes: 'Hello World'

The value in the quotes is NOT interpolated (meaning it won't look for
variables in the value), and the single-quote (') must be escaped with a
backslash if you want to have one in the string (e.g. 'The\'re here').

Double quotes: Hello World

The value in the quotes IS interpolated (meaning variables in the value are
converted to their string value), and double-quotes() must be escaped with
a backslash if you want to have one in the string (e.g. Robert \The
Hacker\ Hanson).

The q() operator: q(Hello World)

The value is treated like a single-quoted string, EXCEPT that the delimiter
is not a single-quote('), it is the character following the q.  The end
delimiter is either the closing brace/bracket/paren OR the same character as
the opening delimiter.  Some examples: q|Hello World|, q{Hello World},
q*Hello World*.

The qq() operator: qq(Hello World)

Same as the q() operator, but acts like the double-quotes because it does
interpolate.

Anyway, there are several solutions to your problem, which can be handled
however you like best (1 uses the escape (\), the others use a different
delimiter)...

%database = (
...
q_1 = \Excretion is getting rid of __ material.,
q_2 = 'Excretion is getting rid of __ material.',
q_3 = q{Excretion is getting rid of __ material.},
q_4 = qq|Excretion is getting rid of __ material.|,
...
);

BTW - I unquoted the hash keys.  They only need to be quoted if there are
spaces or special characters in them.  In this case they will automatically
be treated as single quoted strings without having to actually use quotes
around them.  It's really a matter of preference on if you want to
explicitly quote them, I tend to prefer not to (less quotes = less clutter).

Rob

-Original Message-
From: Rick Triplett [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 08, 2004 5:26 PM
To: [EMAIL PROTECTED]
Subject: quote marks in DBM

The following snippet of code is from Programming the Perl DBI and 
shows the storing of a hash element that contains both a comma and a 
sort-of double quote. (In the book, double quotes are shown; in the 
book-file, it looks like back tics and single quotes.)

...
### Insert some data rows
$database{'Callanish I'} =
 This site, commonly known as the ``Stonehenge of the North'' is in 
the
form of a buckled Celtic cross.;
...

The next snippet is from code I wrote which didn't compile (choked on 
the repeated double quote marks as I attempted to put the word 
Excretion in quotes.

%database = (
...
a4_2 = releasing energy from food,
q_3  = Excretion is getting rid of __ material.,
a1_3 = excess,
...
);

Must I abandon trying to get double-quote marks into my hash element 
for later printing to the screen? I can live with single-quotes if I 
must.


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


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




RE: :Writer beginner problems

2004-02-03 Thread Hanson, Rob
 ?xml version=1.0 encoding=ISO-8859-1?
 docnumPIP 189165/docnum
 greeting class=simpleHello, world!/greeting
 ...
 Attempt to insert start tag after close of document
 element at ./test.pl line 11

A rule of XML is that there MAY ONLY BE ONE ROOT ELEMENT.  You have two.

You need to put docnum and greeting inside a single element.  The
following would be well-formed XML.

?xml version=1.0 encoding=ISO-8859-1?
rootTag
  docnumPIP 189165/docnum
  greeting class=simpleHello, world!/greeting
/rootTag

Rob

-Original Message-
From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 03, 2004 12:41 PM
To: [EMAIL PROTECTED]
Subject: XML::Writer beginner problems


Hope it's okay to write to this group regarding beginner problems with
XML::Writer. I'm a beginner both to XML  in general, and XML::Writer in
particular.

I'm trying to run this program:

#! /usr/bin/perl

use XML::Writer;

my $writer = new XML::Writer(DATA_MODE = 1,
 DATA_INDENT = 3,
 UNSAFE =1);

$writer-xmlDecl(ISO-8859-1);

$writer-dataElement(docnum, PIP 189165);
$writer-startTag(greeting,
  class = simple);
$writer-characters(Hello, world!);
$writer-endTag(greeting);

$writer-end();

When I do, I get the output I think I want:
[EMAIL PROTECTED]:~/POPLINE_XML$ ./test.pl

?xml version=1.0 encoding=ISO-8859-1?

docnumPIP 189165/docnum
greeting class=simpleHello, world!/greeting
[EMAIL PROTECTED]:~/POPLINE_XML$ 

This output looks like valid XML to me. I don't see any problems with it.

However, when I remove the UNSAFE and change the third line to:
my $writer = new XML::Writer(DATA_MODE = 1,
 DATA_INDENT = 3);

I get this output:
[EMAIL PROTECTED]:~/POPLINE_XML$ ./test.pl  
?xml version=1.0 encoding=ISO-8859-1?

Attempt to insert start tag after close of document element at ./test.pl
line 11
docnumPIP 189165/docnum[EMAIL PROTECTED]:~/POPLINE_XML$ 

I don't understand what I'm doing wrong to cause XML::Writer to complain. Do
I not understand XML correctly?

Thanks for your thoughts and suggestions.

-Kevin Zembower

-
E. Kevin Zembower
Unix Administrator
Johns Hopkins University/Center for Communications Programs
111 Market Place, Suite 310
Baltimore, MD  21202
410-659-6139


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


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




RE: Writing to file

2004-02-01 Thread Hanson, Rob
 but I can not retrieve the data into $newline with join. Is this bit wrong

Yes, it is a little off.

 $member_array[$count]

This *isn't* an array, it is an *array reference*

 [EMAIL PROTECTED]

Same with this.

Join takes a list of scalars, not a list of references.  So you need to
dereference them.  I think this is what you are after.

join(\:,@{$member_array[$count]});

Rob


-Original Message-
From: Support [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 01, 2004 2:31 PM
To: [EMAIL PROTECTED]
Subject: Writing to file

Hi all 
I have a little bit of code you may be able to help with. I load a file into
an array with

foreach $lines(@database_array) {
[EMAIL PROTECTED] = split(/\:/,$lines);
push(@member_array,[EMAIL PROTECTED]);
$x++;
}   #loop

and then play around with the array a bit, then I would like to load it back
into the file with

while($count$x){   
$newline = join(\:,$member_array[$count],[EMAIL PROTECTED]);
chomp($newline);
print DAT $newline\n;
$count++;
}

but I can not retrieve the data into $newline with join. Is this bit wrong 

$member_array[$count],[EMAIL PROTECTED]) 

or am I missing the point completely or is there another way of doing it. 
I am currently loading direct from the file working on that line and them
loading back to file, but I can only change one line at a time. Doing it
with as above I can alter the entire array and then load back to file.
Any help is appreciated and please excuse if I'm in the wrong forum.
Cheers
Colin

---

www.rentmyplace.co.nz
The ultimate in that holiday spot away from the maddening crowd
Join as a member today its FREE
List your holiday accommodation for FREE



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




RE: What is eval?

2004-01-29 Thread Hanson, Rob
It evaluates the code that you give it.  It can be used when you need to
create code on the fly, like this...

my $cmd = 'print';
my $arg = 'Hello World';
eval($cmd '$arg');

This is useful for allowing a user to pass code to the program (for whatever
reason).

The other use it to trap errors.

my $this = 1;
my $that = 2;
eval {
  if ($this != $that) {
die They don't match!;
  }
};
print $@;

In this case the die doesn't terminate the program, it only terminates the
eval.  And $@ stores the error message that was thrown in the eval.  So
this prints the error message without abnormally terminating the program.
This is akin to the try/catch blocks in other languages (the Errors gives
you try/catch functionality by using eval).

Hope that helps.

Rob

-Original Message-
From: Mallik [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 29, 2004 7:26 AM
To: Perl Beginners
Subject: What is eval?


Can anybody explain the functionality of eval in brief?

Thanks in advance,
Mallik.

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


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




RE: sort

2004-01-29 Thread Hanson, Rob
I have to run, otherwise I would elaborate a bit.

The code is below.  Check out the perldoc perlreftut for what the
[EMAIL PROTECTED], @{$row}, and $a-[2] means.  Check out perldoc -f sort for
what the sort {...} @rows means.  And of course ask questions if you get
stuck (but take a look at the docs first).

 THE CODE 

my @rows;

while (my $line = DATA) {
  chomp($line);
  my @cols = split(/\s+/, $line);
  push @rows, [EMAIL PROTECTED];
}

print Sorted on 5th column:\n;
@rows = sort {$a-[4] = $b-[4]} @rows;

foreach my $row (@rows) {
  print @{$row}\n;
}

print Sorted on 3rd column:\n;
@rows = sort {$a-[2] = $b-[2]} @rows;

foreach my $row (@rows) {
  print @{$row}\n;
}

__DATA__
Abc 12.8 8 left 1 15.7
Def  13.8 9 top 0 19.7
gef  14.8 9 left 0 19.7
Dgf  12.3 9 right 4 99.6
cef  16.8 4 right 0 89.7
baf  32.8 7 bottom 5 79.8
efg  16.8 5 right 0 56.7
etg  12.8 2 left 7 34.7

 THE OUTPUT 

$ perl sort.pl 
Sorted on 5th column:
efg 16.8 5 right 0 56.7
Def 13.8 9 top 0 19.7
gef 14.8 9 left 0 19.7
cef 16.8 4 right 0 89.7
Abc 12.8 8 left 1 15.7
Dgf 12.3 9 right 4 99.6
baf 32.8 7 bottom 5 79.8
etg 12.8 2 left 7 34.7
Sorted on 3rd column:
etg 12.8 2 left 7 34.7
cef 16.8 4 right 0 89.7
efg 16.8 5 right 0 56.7
baf 32.8 7 bottom 5 79.8
Abc 12.8 8 left 1 15.7
Dgf 12.3 9 right 4 99.6
Def 13.8 9 top 0 19.7
gef 14.8 9 left 0 19.7


-Original Message-
From: Boon Chong Ang [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 29, 2004 7:38 PM
To: [EMAIL PROTECTED]
Subject: sort


Hi,

I want to write a perl script to do something like this

 

Abc 12.8 8 left 1 15.7

Def  13.8 9 top 0 19.7

gef  14.8 9 left 0 19.7

Dgf  12.3 9 right 4 99.6

cef  16.8 4 right 0 89.7

baf  32.8 7 bottom 5 79.8

efg  16.8 5 right 0 56.7

etg  12.8 2 left 7 34.7

 

 

Just say I want to sort the row based on the value on fifth or third column,
any advice how to do so?

 

 

Thank you  best regards,

ABC

 


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




RE: Placing handmade modules

2004-01-26 Thread Hanson, Rob
 my ($update_path, $gallery_title) = Test::Template::choose();

Can I assume that your module has the line package Test::Template; at the
top of the file?  If not, that is why.

 use Test::Template;

This says load {lib directory}/Test/Template.pm.

 Test::Template::choose();

This says execute choose() in the Test::Template package.

Rob


-Original Message-
From: Jan Eden [mailto:[EMAIL PROTECTED]
Sent: Monday, January 26, 2004 11:39 AM
To: Perl Lists
Subject: Placing handmade modules


Hi all,

I use the following code to use a module I made:

use lib $ENV{HOME}/Library/Scripts/Modules;

use Test::Template;

my ($update_path, $gallery_title) = Test::Template::choose();

The module sits in /Users/jan/Library/Scripts/Modules/Test. Now Perl tells
me it cannot locate the subroutine choose. If I place Template.pm directly
into the path set in the use lib line and remove the Test:: at both
places, everything works fine.

I read in the camel that double colon separators in a module name would be
translated to a directory structure when Perl searches for them.

Why doesn't Perl do it for me?

Thanks,

Jan
-- 
How many Microsoft engineers does it take to screw in a lightbulb? None.
They just redefine dark as the new standard.

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


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




RE: name of calling function

2004-01-19 Thread Hanson, Rob

 my $caller=

You are so close.

my $caller = caller;

Look at perldoc -f caller for more info on the different ways to use it.

Please note that sometime the info you get from caller isn't the real
caller.  If you call your debug() function right before a return statement
it is possible that optimizations by the Perl compiler can optimize the
calling info away.  You should be able to defeat the optimization by making
sure that some operation happens after the call to your debug() method.
Anyway, I just wanted to mention it because when I did something similar I
was going nuts trying to figure out why caller wasn't returning what it
should.

Rob


-Original Message-
From: Gary Stainburn [mailto:[EMAIL PROTECTED]
Sent: Monday, January 19, 2004 8:09 AM
To: [EMAIL PROTECTED]
Subject: name of calling function


Hi folks,

In the back of my mind I seem to think that you can find out where a
function 
was called from.  What I'm after is:

my %_DEBUG={'new'=1,'load_file'=0};

sub debug {
  my $caller=
  return (defined $_DEBUG{$caller} ? $_DEBUG{$caller} : 0;
}


sub new { # create new track object
  print calling Trainset::Track::new\n if debug;

}

Is this possible?
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


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


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




RE: Search and replace pattern in a file

2004-01-19 Thread Hanson, Rob
I think you will like this, it does exactly whay you described...

perl -pi.bak 's|ReplaceThis|WithThis|' *

This does everything you want, AND makes a backup of each file.  You can
only perform a substitution on a single line though (AFAIK).

See perldoc perlrun for all of the details.

WARNING: Make an extra backup of the files before doing this! It is easy to
make a mistake and delete everything by accident.

Rob

-Original Message-
From: Perl [mailto:[EMAIL PROTECTED]
Sent: Monday, January 19, 2004 6:48 PM
To: [EMAIL PROTECTED]
Subject: Search and replace pattern in a file


Hi,
  here is the situation i have :

i have a long list of files in a directory. i have to
search and replace a particular pattern in each file.
since a file cannot be read and written to at the same
time, what's the best way of doing the search and
replace ?
i take this approach of doing the search and replace
and then writing the contents into a new temporary
file. then i close both the files. thereafter i write
the contents of  the temporary file into the original
file.

i am sure, there is a better efficient way of doing
it.
can anybody let me know.


__
Do you Yahoo!?
Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

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


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




RE: Search and replace pattern in a file

2004-01-19 Thread Hanson, Rob
Sorry, my bad.  Forgot the -e switch...

perl -pi.bak -e 's|ReplaceThis|WithThis|' *

Rob

-Original Message-
From: Hanson, Rob 
Sent: Monday, January 19, 2004 8:04 PM
To: 'Perl'; [EMAIL PROTECTED]
Subject: RE: Search and replace pattern in a file


I think you will like this, it does exactly whay you described...

perl -pi.bak 's|ReplaceThis|WithThis|' *

This does everything you want, AND makes a backup of each file.  You can
only perform a substitution on a single line though (AFAIK).

See perldoc perlrun for all of the details.

WARNING: Make an extra backup of the files before doing this! It is easy to
make a mistake and delete everything by accident.

Rob

-Original Message-
From: Perl [mailto:[EMAIL PROTECTED]
Sent: Monday, January 19, 2004 6:48 PM
To: [EMAIL PROTECTED]
Subject: Search and replace pattern in a file


Hi,
  here is the situation i have :

i have a long list of files in a directory. i have to
search and replace a particular pattern in each file.
since a file cannot be read and written to at the same
time, what's the best way of doing the search and
replace ?
i take this approach of doing the search and replace
and then writing the contents into a new temporary
file. then i close both the files. thereafter i write
the contents of  the temporary file into the original
file.

i am sure, there is a better efficient way of doing
it.
can anybody let me know.


__
Do you Yahoo!?
Yahoo! Hotjobs: Enter the Signing Bonus Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

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


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


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




RE: passing arguments to functions

2004-01-19 Thread Hanson, Rob
 I want to send 2 arguments to a subroutine
 in the form of arrays

I think what you want to use are references. Check out perldoc perlreftut.

# WARNING: untested code ahead
my @a = `/bin/cat /some/file`;
my @b = `/bin/cat /another/file`;

my @result = addArray([EMAIL PROTECTED], [EMAIL PROTECTED]);

sub addArray {
  my $array1 = shift;
  my $array2 = shift;
  my (@res, $counter);

  # access the whole array by dereferencing (e.g. @{$array1}).
  # access individual elements through the reference (e.g. $array1-[0]).
  for (my $i = 0; $i  @{$array1}; $i++) {
$res[$counter++] = $array1-[0] + $array2-[0];
  }

  return @res;
}

I don't know if this is enough to solve your problem though.  You might be
better off taking a quick look at the reference tutorial I mentioned.

Rob


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, January 19, 2004 8:15 PM
To: [EMAIL PROTECTED]
Subject: passing arguments to functions


Hi all 

Problem:

I want to send 2 arguments to a subroutine in the form of arrays and want to
use their result which is also in the form of an array. 
  
Explanation:

suppose i have 2 arrays 

@a=`/bin/cat /some/file` ; # A file that has a list of users  
@b=`/bin/cat /another/file` ; # Another file with a list of users  

sub try
   {
 *%^^[EMAIL PROTECTED]()(*
 the code will do some sort of comparison of the elements of both arrays
and return the results in the form of an array 
  
here i want to return my result in the form of an array 
say @answer
   }

how I can use the resulted array @answer in my main program ? 

Solution:

 

Regards 

--Bobby 



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


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




RE: for loop not ending

2004-01-19 Thread Hanson, Rob
 for ($day=$keeplogs+1;$day$keeplogs;$day++) {

Hmmm... lets assume $keeplogs = 60 (right?).  The problem is that $day is
always going to e greater than $keeplogs, because you initialized day that
way.  So yes, you need to set an upper bounds.

Maybe this.

my $max_days_old = 120;

# loops from 61 to 120.
# assumes there are no files older than 120 days old.
for ($day = $keeplogs+1; $day = $max_days_old; $day++) {
 ...
}

...Or set $max_days_old to 240, or 365, or whatever you consider to be the
logical limit for how old a file could possibly be (e.g. if the script runs
weekly you can use $max_days_old=67).

Rob

-Original Message-
From: Damian Scott [mailto:[EMAIL PROTECTED]
Sent: Monday, January 19, 2004 8:48 PM
To: [EMAIL PROTECTED]
Subject: for loop not ending


Ok.  Here's my situation.  I am modifying a Perl script that was created 
some time ago and am learning Perl on kind of a trial by fire basis 
(with a couple of good books).

The problem was first brought to my attention that we still had old log 
files greater than 60 old.  The gziplog Perl script you see below is 
supposed to do 3 things

1.  Keep today's and yesterday's log file in uncompressed format
2.  Anything older than 2 days up to 60 days, compress
3.  Anything older than 60 days, delete

Originally, the problem was the last item.  The script would delete some 
but not all files older than 60 days.  Here's the difference:

Before (sub RemoveOldLogs)

  for ($day=$keeplogs+1;$day=$keeplogs+60;$day++) {

After my change

  for ($day=$keeplogs+1;$day$keeplogs;$day++) {


After making this change, old files from Mar/Apr 2003 were deleted 
successfully, but the script wouldn't end without a CTRL +C.  I'm thinking 
because of the increment $day++ it just keeps looking.  Do I need to put 
in a last statement somewhere or using a While statement instead?

What are you thoughts, expert Perl mongers?


#!/usr/bin/perl -w
#
#
#These logs remain for x days (as set by keeplogs) and then are 
deleted.
#This script needs to be run at least once a week.
#This script is best run at midnight each day.
#
#Changes made 02Apr2003 by x to fix deletion of old logs
#5/22/03 - Changed ziplogs to 2 so that logs get zipped more 
frequently
#
#
$release = 1.0;

$logs = /var/spool/logs;  # location of logs
$ziplogs = 02;  # days before zipping logs
$keeplogs = $ENV{KEEPMAILLOGS}; # days to keep daily logs, but = 60
$keeplogs = 60; # unless ($keeplogs = 60);

$host=`hostname`;chop($host);   # get local host name
chdir(/);
$clock = time();# get start time
$oneday = 24*60*60; # seconds in one day
@monthname = 
(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);

GetLogName(1);  # get log name and date format for 
yesterday
ZipOldLogs($ziplogs);   # zip up old logs to save space
RemoveOldLogs($keeplogs);   # remove logs too old to be usefull
exit(0);

#

# zip any logs which are older $ziplogs
#
sub ZipOldLogs {
  for ($day=$ziplogs;$day=$keeplogs;$day++) {
GetLogName($day);
if (-r $logname) {
  unless (-r $logname.gz) {
print Zipping log for $logdate ($logday)\n;
system(/bin/gzip $logname);
  }
}
  }
}

#
# remove any logs which are older than we want to keep
#
sub RemoveOldLogs {
#   ** RK 04Apr2003 was 7 before
  for ($day=$keeplogs+1;$day$keeplogs;$day++) {
GetLogName($day);
#   * RK 04Apr2003 the $ was missing
@dated = ($logname,$logname.gz);
foreach $datedfile (@dated) {
  if (-r $datedfile) {
# * RK 04Apr2003 there was an extraneous g so it 
didn't print the file name
print Purging $datedfile\n;
if (length($datedfile)10) {die Invalid log name $datedfile\n;}
unlink ($datedfile);
  }
}
  }
}
#
sub nn {
  local($xn) = $_[0];
  $xn = $xn+0;
  if ($xn10) { return 0$xn; }
  return $xn;
};
#
#format date as 2000-12-31
#
sub fmtdate {
  local($fsec,$fmin,$fhour,$fday,$fmon,$fyear) = localtime($_[0]);
  $fyear+=1900;
  $fmon++;
  return $fyear...nn($fmon)...nn($fday);
};
#
sub fmtday {
  local($fsec,$fmin,$fhour,$fday,$fmon,$fyear) = localtime($_[0]);
  $fmon = $monthname[$fmon];
  if ($fday10) { return $fmon $fday;}
  return $fmon $fday;
};

#
# get log date and log name for a relative date
#
sub GetLogName {
  local($day) = $_[0]+0;
  if ($day  1) {die Invalid number of log days... $day \n;}
  $logtime = $clock-$day*$oneday;   # backup a number of days
  $logdate = fmtdate($logtime); # get date for log file
  $logday = fmtday($logtime);   # get day for log file 
extract
  $logname = $logs/log.$logdate;  # get daily log name
};

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




RE: Hidden field on a form in perl

2003-11-21 Thread Hanson, Rob
I'll see if I can explain it gently as you seem to be a gov't worker ;)

There is no perl translation... you just aren't thinking about it in a
web-app type of way.  The sequence would look like this...

1. display page A to user
2. user submits page A with hidden form field
3. perl script process input from page A
4. perl script prints new form page, creating a new hidden input field that
has the value that the script recieved from step 3.

If that makes sense, then the rest is easy... but I am sure something there
won't make sense.  So you might need to ask a more detailed question.

BTW - for step #3 you would probably use the CGI module to extract the form
data from the input to the script.  The code for steps #3 and #4 might look
like this...

use CGI qw(:cgi);

my $hidden_val = param('name_of_hidden_field');

print Content-type: text/html\n\n;
print EOF;
html
body
form action=foo.cgi
 input type=hidden name=name_of_hidden_field value=$hidden_val
 input type=text name=bar
 input type=submit
/form
/body
/html
EOF



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Friday, November 21, 2003 2:21 PM
To: [EMAIL PROTECTED]
Subject: Hidden field on a form in perl


I was wondering if anyone knows how to hide a field in a form so that it 
can be passed on to other forms, mainly for version number and some other 
information that i wish the user not to see and/or change. I know in HTML 
i could simply input type=hidden name=version value=1.0 yet I've 
looked through the manpages and a few books and can't seem to find the 
translation for this in perl. I will say I've only been using perl for 
maybe 3 weeks, so if your response is RTFM... i ask that you refer me to 
what section of the FM i should look to.

Thank you for any and all assistance.

Derrick 

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



RE: How does perl compile functions

2003-11-20 Thread Hanson, Rob
 When the actual C code (or ASM equivalent or
 bytecode or whatever Perl uses) for a
 function is run, is there overhead to the
 function?

I'm no internals expert, but I would say yes, there is some overhead.  The
overhead has to deal with pushing aliases of the passed params onto the @_
array and I assume a push onto the call stack.

 Are functions inlined?

No, not that I am aware of.

 Does perl lazy compile functions?

Yes, like Bob mentioned, but it isn't the usual behavior.  Two ways (that I
can think of) to do this are using the Autoload module which will load and
compile functions that are in external files (Some large modules like CGI do
this).  The other way is eval'ing a block of code, using eval(), do(), or
require().

Rob

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 20, 2003 1:12 PM
To: Perl Beginners
Subject: How does perl compile functions


I'm curious how perl compiles functions internally.  When the actual C
code (or ASM equivalent or bytecode or whatever Perl uses) for a
function is run, is there overhead to the function?  Are functions
inlined?  Does perl lazy compile functions?  (i.e. functions never used
are never compiled and that is why errors suddenly pop up when using a
function for the same time).

Thanks in advance from a curious mind,
Dan


-- 
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: When is Perl 6 coming out?

2003-11-12 Thread Hanson, Rob
 When is it coming out

The usual answer is when it is done.

It is far from completion, but a lot of progress has been made.  My guess is
beta in a year... but nobody really knows, and there is no schedule for it.
The goal is to do it right, even if it means a very long development cycle.

 and will it support code from 5.0+?

Yes.

Rob

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 12, 2003 10:54 AM
To: Perl Beginners
Subject: When is Perl 6 coming out?


I saw a book on Perl 6 but I didn't think it was out yet.  When is it
coming out, and will it support code from 5.0+? 

Thanks,

Dan


-- 
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: RFC on first perl script

2003-11-06 Thread Hanson, Rob
 please have a look at the code below and give comments

Here are some quick comments.

#1. Always use strict
#2. See #1.

When you use strict it foeces you to do things the right way and will
help catch errors because of the extra checks it makes.

So something like this:
 @dataFile=; # read in file from command line

Needs to be changed to this by explicitly declaring that variable:
my @dataFile=; # read in file from command line

 @standardRules=`cat standard.for.arf.txt` ;

This isn't portable (if you care for it to be), and does not check for
errors.  This might be better:

open IN, 'standard.for.arf.txt' or die $!;
my @standardRules = IN;
close IN;

 (@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);

The ( and ) force list context.  The array @sitePVCs will already force
list context without the parens.  This can be rewriten like this, which may
or may not be more readable to you:

my @sitePVCs = split(/;/,$siteAllPVCs,$siteNoOfPVCs);

 open(ARFfile, $siteARFfile) or die(can not open

Typically filehandles are in all caps.  They don't need to be, but it is the
usual way of doing things because it makes them easier to spot (especially
to people other than the author).  Also the parens are not needed because
or has very low precedence.  I also tend to put my error condition on the
next line, but that is just my preference.

open ARFFILE, $siteARFfile
  or die can not open '$siteARFfile': $!;

Again, parens not needed here, but they don't hurt either:

 print ARFfile (@standardRules\n); #print standard bits
print ARFFILE @standardRules\n; #print standard bits

This is pretty icky:
print ARFfile (name matches  \.*RH-Serial.*\:
 {\n \tsetName(\$SiteName-RH-WAN\$2\) ;\n \tsetGroup
 (\$siteGroup\) ..snip..); # print RH-Serial rule

Try a here-document instead:

# print RH-Serial rule
print ARFFILE EOF;
name matches  .*RH-Serial.*: {
setName($SiteName-RH-WAN\$2);
setGroup($siteGroup);
setAlias($siteCCTReff);
setSpeedIn($siteACRate);
setSpeedOut($siteACRate);
setDeviceSpeedIn($siteACRate);
setDeviceSpeedOut($siteACRate);
}
EOF

It makes it a lot easier to read, not to mention I could remove the \n and
the \ escapes.  BTW - If you have quotes in your string you can do this
qq[a blah b] instead of a \blah\ b.  The char following the qq can
be any char, so you could use qq{}, qq||, qq**, etc.

In general there isn't anything *wrong* with the script... but use strict
is STRONGLY encouraged.  The rest are just suggestions for readability.

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 06, 2003 11:34 AM
To: [EMAIL PROTECTED]
Subject: RFC on first perl script




Hi all
 well im trying at lerning this perl stuff.. reading from the learning
perl oreilly book and a few other places,
but also using perl a long time before i should ie making the below script,
so that i dont get in to any very bad habbits at such an early stage.
could some one please have a look at the code below and give comments, the
code does do what i want it to ( well at leest from this stage).


#!/usr/bin/perl -w

# this function creates a arf rule file from an input file
# Version 0.1 6/11/03

@dataFile=; # read in file from command line
@standardRules=`cat standard.for.arf.txt` ;

foreach $site (@dataFile) {  # loop  for each line/site in dataFile
chomp $site;

($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3); #split
up main / pvc info
 
($siteIP,$siteString,$SiteName,$siteGroup,$siteCCTReff,$siteACRate)=split(/,
/,$siteLink,6);
#split up main info
(@sitePVCs)=split(/;/,$siteAllPVCs,$siteNoOfPVCs);

my $siteARFfile = $siteIP.arf;
open(ARFfile, $siteARFfile) or die(can not open
'$siteARFfile': $!);

print ARFfile
(##
\n# \n# Discover Rule for:
$siteIP \n#
\n##
\n\n); # print header

print ARFfile (@standardRules\n); #print standard bits

print ARFfile (name matches  \.*-Cpu-.*\: {\n \tsetName
(\$SiteName-RH-Cpu\) ;\n \tsetGroup (\$siteGroup\)
;\n \tsetAlias (\RH-Cpu\) ;\n} \n\n ); # print -Cpu- rule

print ARFfile (name matches  \.*-RH\: { \n \tsetName
(\$SiteName-RH\) ;\n \tsetGroup (\$siteGroup\) ; \n \t
setAlias (\RH\) ;\n} \n\n ); # print -RH rule

print ARFfile (name matches  \.*RH-Serial.*\: {\n \tsetName
(\$SiteName-RH-WAN\$2\) ;\n \tsetGroup (\$siteGr
oup\) ;\n \tsetAlias (\$siteCCTReff\) ;\n \tsetSpeedIn
(\$siteACRate\) ;\n \tsetSpeedOut (\$siteACRate\) ;\n \tsetD
eviceSpeedIn (\$siteACRate\) ;\n \tsetDeviceSpeedOut (\$siteACRate\)
;\n} \n\n); # print RH-Serial rule


print ARFfile (name matches  \.*-Serial.*\: {\n \tsetName
(\$SiteName-WAN\$2\) ;\n \tsetGroup (\$siteGroup\
) ;\n \tsetAlias 

RE: Where is Apache::Session

2003-10-20 Thread Hanson, Rob
On CPAN.

http://search.cpan.org/~jbaker/Apache-Session-1.54/

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, October 20, 2003 6:15 PM
To: [EMAIL PROTECTED]
Subject: Where is Apache::Session


I'm looking for the download of Apache::Session.
There is a lot of docs on it but where is the download?

thanks


-
eMail solutions by 
http://www.swanmail.com

-- 
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: quotes problem

2003-10-20 Thread Hanson, Rob
I'm not sure if John or Greg from the previous answers understand the
question... or maybe it is me that is misunderstanding it.

You are receiving a string from the query string that includes quotes, but
it isn't printing the whole value.  Correct?

If that is the case, I am not sure I know where the problem is, even though
you say you do.

For example, this works fine:

my $x = 'This is the string which contains the quotes';
print $x, \n;
print qq|
$x
|;

Once the quote is inside the variable you don't need to do anything special
to print it.

If you could give us an example of the query string, maybe that would help.
My guess would be that the query string is malformed.

Rob


-Original Message-
From: Sara [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 19, 2003 6:56 PM
To: beginners-cgi
Subject: quotes problem


##
use CGI;

$q = new CGI;

my $field = $q-param('field');

print qq|
$field
|;
#

# Lets Suppose the form Input contains the quotes in the string e.g.

$field = This is the string which contains the quotes;

The script stops printing everything after first quote (), I KNOW where the
problem is but at a loss to prevent it as I have tried all the options

Any help!!!.

thanks,

Sara.

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



RE: How do you find out the size of a file

2003-10-20 Thread Hanson, Rob
Try stat().  It is a built-in function.

From perldoc -f stat:

stat FILEHANDLE
stat EXPR
statReturns a 13-element list giving the status info
for a file, either the file opened via FILEHANDLE,
or named by EXPR.  If EXPR is omitted, it stats
$_.  Returns a null list if the stat fails.
Typically used as follows:

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
   $atime,$mtime,$ctime,$blksize,$blocks)
   = stat($filename);

Rob

-Original Message-
From: Chinku Simon [mailto:[EMAIL PROTECTED]
Sent: Monday, October 20, 2003 5:24 PM
To: [EMAIL PROTECTED]
Subject: How do you find out the size of a file


Hi,

I have a requirement to find out the size of a file existing in an NTFS file
system.

Are there any suitable modules that can be used?

Thanks in advance
Chinku

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
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: malformed header

2003-10-13 Thread Hanson, Rob
The short answer...

Make sure this is the first print statement:

print Content-type: text/html\n\n;


The long answer...

CGI scripts work by passing the web server a header part and a body part.
The header part must contain AT LEAST the content type of the document (e.g.
text/plain, text/html, etc).  The header is then followed by a single
blank line, then comes the main body content for the page.

The web server takes your header info and adds some of it's own (or even
modifies yours).  It them sends this page to the client (browser) in two
parts... header, followed by a blank line, then the body content (see HTTP
specs).

The print statement I game above includes the minimal header info, the
Content-type, as well as a single blank line.  Anything after that statement
is taken by the web server as belonging to the body.

The error you recieved was because you never printed the header, only the
body, and the web server choked on it because it didn't make any sense (was
malformed).

Hope the helps.

Rob

-Original Message-
From: Nino V [mailto:[EMAIL PROTECTED]
Sent: Monday, October 13, 2003 1:49 PM
To: [EMAIL PROTECTED]
Subject: malformed header


Hi,

I'm trying my first perl script on a Unix server, but without any success!

The script (codice.pl) is something like this:

#!/usr/bin/perl
$home=/home/dominio/public_html;
print Home $home;

when I run it, I get this error:

malformed header from script. Bad header=Home /home/dominio/public_:
/home/dominio/public_html/cgi-bin/codice.pl

Can someone help me to understand where I'm wrong?

Thanks very much,
Nino

=
http://www.vessella.it (italiano, esperanto, kiswahili, english)
http://www.changamano.org (Iniziative di solidarietà per la Tanzania)
Corso di lingua swahili: http://corsoswahili.vessella.net
Corso di lingua esperanto: http://esperanto.vessella.net
Jifunze lugha ya Kiesperanto: http://kiesperanto.vessella.net
Kamusi/Vortaro: http://kamusi.vessella.net
Vocabolario esperanto-italiano: http://vortaro.vessella.net
Articoli di quotidiani della Tanzania: http://habari.lernado.it


-- 
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: Regular Expression question

2003-10-09 Thread Hanson, Rob
Like Jeff said, you can just use \w if you are allowing numbers as well.

 s/([A-Za-z]_*)/\n$1/g;

This will take a little bit of explaining, so bear with me.

[ ... ] - Brackets represent a character class.  A char class will match a
SINGLE char that is inside of it.  So if I wanted to match a, b, or c
I would use [abc].  As a shortcut you can use a range to specify a list of
chars.  A range line a-k is the same as abcdefghijk.  Ranges are just a
shortcut, and you can use ranges along with single chars in the char class.
So I could match a single char that is in the range a-k or is a z by
using [a-kz].

Your mistake was that you placed the underscore (_) outside of the range,
not inside it.

This is what you meant to do:

s/([A-Za-z_]*)/\n$1/g;

Hope that helps.

Rob

-Original Message-
From: Trina Espinoza [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 09, 2003 4:11 PM
To: [EMAIL PROTECTED]
Subject: Regular Expression question


How do you create a regular expression that allows you to have files like 
ths:
Stuff_Dev
Greg_Files
myThings_
_default

I wrote this


s/([A-Za-z]*)/\n$1/g;


It only gets the letters, but I am not sure how to write in the underscore. 
Any attemps I have made
on adding the _ get the wrong results e.g --s/([A-Za-z]_*)/\n$1/g; 
---Didn't work.Created a newline
right before the underscore.

Assistance would be much appreciated :)

-T

_
Get McAfee virus scanning and cleaning of incoming attachments.  Get Hotmail

Extra Storage!   http://join.msn.com/?PAGE=features/es


-- 
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: Chopping off firstlast character in a string

2003-10-07 Thread Hanson, Rob
You could just use a regex...

$string =~ s/.//;

Or even substr()...

substr($string, 0, 1, '');

Both look equally efficient.

Rob


-Original Message-
From: Li, William [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 07, 2003 12:57 PM
To: [EMAIL PROTECTED]
Subject: Chopping off firstlast character in a string


Hi,

Silly question, is there an equal but opposite function to chop in Perl?
I'd like to remove the first and last character of a string and am looking
for a simple way to do it.  So far I have:

# 1234567 - 23456
chop($string); # 123456
$string = reverse($string); # 654321
chop($string); # 65432
$string = reverse($string); # 23456



--
This message is intended only for the personal and confidential use of the
designated recipient(s) named above.  If you are not the intended recipient
of
this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited.  This
communication is for information purposes only and should not be regarded as
an offer to sell or as a solicitation of an offer to buy any financial
product, an official confirmation of any transaction, or as an official
statement of Lehman Brothers.  Email transmission cannot be guaranteed to be
secure or error-free.  Therefore, we do not represent that this information
is
complete or accurate and it should not be relied upon as such.  All
information is subject to change without notice.


-- 
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: Chopping off firstlast character in a string

2003-10-07 Thread Hanson, Rob
 $string =~ s/^.(.*).$/$1/;

It's prettier, but it's very inefficient.  It's probably 20+ times slower
then doing it in two steps.

It has to do with how Perl internally handled string data.  When you s/// or
substr() all it does is move a pointer.  With your version it would need to
rewrite the whole string value, which is pretty expensive in comparison.

Rob

-Original Message-
From: James Edward Gray II [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 07, 2003 6:07 PM
To: Li, William
Cc: [EMAIL PROTECTED]
Subject: Re: Chopping off firstlast character in a string


On Tuesday, October 7, 2003, at 11:56  AM, Li, William wrote:

 Hi,

Howdy.

 Silly question, is there an equal but opposite function to chop in 
 Perl?
 I'd like to remove the first and last character of a string and am 
 looking
 for a simple way to do it.  So far I have:

 # 1234567 - 23456
 chop($string); # 123456
 $string = reverse($string); # 654321
 chop($string); # 65432
 $string = reverse($string); # 23456

How about an all-in-one try:

$string =~ s/^.(.*).$/$1/;

James


-- 
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: initialising a list of variables

2003-10-03 Thread Hanson, Rob
 It's open to user error quite easily

You can also use this...

my $x = my $y = '';

...Or...

my ($x, $y);
$x = $y = '';

...Or...

init(my ($x,$y));

sub init {
  $_ = '' for (@_);
}

This last one uses the fact that $_ is an alias to the array item in @_, and
@_ contains aliases to the variables that were passed.  So modifying $_
modified $x and $y directly without having to return a value.

Rob

-Original Message-
From: Gary Stainburn [mailto:[EMAIL PROTECTED]
Sent: Friday, October 03, 2003 11:27 AM
To: James Edward Gray II
Cc: [EMAIL PROTECTED]
Subject: Re: initialising a list of variables


On Friday 03 Oct 2003 4:05 pm, James Edward Gray II wrote:
 On Friday, October 3, 2003, at 09:55  AM, Gary Stainburn wrote:
  Hi folks

 Howdy.

  I've got a query about variable initialisation. I want to initialise a
  list of
  variables to an empty string, but I'm having troubles.
 
  What's the best wat to do this?

 How about:

 my($fred, $ginger) = ('') x 2;

Hmmm,  thanks you three for this.

However, while I can see why - one array initialised by another array of the

same size - I'd have expected a simpler method from Perl.

It's open to user error quite easily by not specifying enough on the right 
side, and Perl's usually better at making life easy for the programmer.

Or is it just that I'm getting too spoilt by Perl?


 James

[snip]
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
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: explain regex statement?

2003-10-02 Thread Hanson, Rob
Close, not quite.  The quantifier (i.e. ?,+,*) appear AFTER the atom
(i.e. char or special symbol).

The syntax is also off a bit.  It should be =~ and /../ (not single ticks).

$result =~ /^ *-?[0-9]+[.]?[0-9]* *\$/; 

^ = beginning of line (also called an anchor)

 * = zero or more spaces (not whitespace).  I suggest using \s* instead,
which is zero or more whitespace (includes spaces, tabs, returns, and
newlines in some situations)

-? = Matches an optional - char (0 or 1 times).

[0-9]+ =  1 or more numbers (use \d+ instead)

[.]? = optional char (any char).  Brackets not needed, use .? instead.

[0-9]* = 0 or more digits, again use \d* instead.

 * = 0 or more spaces, again use \s* instead.

\$ = matches an actual $ char.

So the new regex looks like this...

$result =~ /^\s*-?\d+.?\d*\s*\$/;

Or using the x modifier (a good thing to do) to space it out, and add
comments... 

$result =~ /
  ^# start of string
  \s*  # 0+ whitespace
  -?   # 0-1 -
  \d+  # 1+ digits
  .?   # 0-1 any char
  \d*  # 0+ digits
  \s*  # 0+ whitespace
  \$   # $ char
/x;


The regex is starting to look like it is supposed to match numbers like
21.25$ and -50.00.  ...In which case the .? is supposed to be a real
period, not an any char.  If it should be a real period (or decimal
point), use \.? instead.

Rob


-Original Message-
From: Johnson, Shaunn [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 5:20 PM
To: [EMAIL PROTECTED]
Subject: explain regex statement?


Howdy:

I have a statement and I'm trying to see if
I understand what it is really is doing (not my code).

The code does this:

[snip]

result ~ '^ *-?[0-9]+[.]?[0-9]* *\$' 

[/snip]

I break out the meaning as this:


[snip example]
^ = beginning of line plus a white space
*- = everything up to, and including,  to the ' - '
?[0-9] =  1 or 0 times of a number
+[.] = 1 or more times any character
?[0-9]* *\$ = 1 or more times any number plus any other character and
a white space and then any MORE characters to the 
end of the line

[/snip example]

How far off am I?

Thanks!

-X

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



RE: explicit vs implicit syntax

2003-10-02 Thread Hanson, Rob
My preference...

 showargs();

Ick.  I use this one when it is required (references and overriding
prototypes), otherwise it isn't what I mean.  If I mean to just execute the
method, then I don't use it.

 showargs;

Yuk.  It saves a few keystrokes, but I tend to avoid it.

 showargs();

I like this one.  It's the usual way to program.  In most languages the
parens are required, so it's just easier to stick with one habit.

Rob


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 5:43 PM
To: Thomas Bätzler
Cc: '[EMAIL PROTECTED]'; Tim Johnson; [EMAIL PROTECTED]
Subject: RE: explicit vs implicit syntax


Thanks I understand what you're saying.

If I could ask, which one of these would you use?

 showargs;  #NOT this is the tricky

 showargs();
 showargs;
 showargs();

thanks,
-rkl

 [EMAIL PROTECTED] asked:
 Here's an excerpt about the  from orielly and what the heck
 does it means:

 ...If a subroutine is called using the  form, the argument list is
 optional. if ommitted, no @_ array is setup for the routine;
 the @_ array at the time of the call is visible to subroutine instead.

 If in doubt, run a test ;-)

 #!/usr/bin/perl -w

 use strict;

 sub showargs {
   print arguments are:  . join(', ', @_) . \n;
 }

 sub test {
   print Arguments for test() are:  . join(', ', @_) . \n;
   print Calling showargs - ;
   showargs;
   print Calling showargs() - ;
   showargs();
   print Calling showargs - ;
   showargs;
   print Calling showargs() - ;
   showargs();
 }

 test qw(foo baz bar);
 __END__

 So, is there a better or worse? both ways works for me. I just started
 going back and putting the  onto the sub ;) I don't like it
 the  but I thought that you need it.

 See for yourself - there's only one use for the ampersand,
 and it's obscure. My advice would be to avoid using it even
 in the one situation where it would make sense - when passing
 @_ as an argument to your function. Sure, it is idiomatic Perl
 at its best, but it also makes a program harder to read and
 understand.

 In other words - save it for Perl Golf ;-)

 HTH,
 Thomas

 PS: Perl Golf - writing code with as little (key-)strokes as
 possible.



-- 
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: explicit vs implicit syntax

2003-10-02 Thread Hanson, Rob
 But Orielly says showargs() is slower than showargs

That's a good point, and something I didn't know.

...I'm not sure if it will make me change my ways though.

Do you know where you read that?  I'm not sure why it would be slower, I
would think that this would be optimized when the code is compiled to be the
same speed.

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 6:15 PM
To: Hanson, Rob
Cc: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: explicit vs implicit syntax


I agree it looks like the best standardized candidate for use.
But Orielly says showargs() is slower than showargs when not passing
arguments. It's just a minor point but its something I read.

In any case, I'm used to the showarg() style.

thanks,
-rkl

 showargs();

 I like this one.  It's the usual way to program.  In most languages the
 parens are required, so it's just easier to stick with one habit.


 My preference...

 showargs();

 Ick.  I use this one when it is required (references and overriding
 prototypes), otherwise it isn't what I mean.  If I mean to just execute
 the
 method, then I don't use it.

 showargs;

 Yuk.  It saves a few keystrokes, but I tend to avoid it.

 showargs();

 I like this one.  It's the usual way to program.  In most languages the
 parens are required, so it's just easier to stick with one habit.

 Rob


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Thursday, October 02, 2003 5:43 PM
 To: Thomas Bätzler
 Cc: '[EMAIL PROTECTED]'; Tim Johnson; [EMAIL PROTECTED]
 Subject: RE: explicit vs implicit syntax


 Thanks I understand what you're saying.

 If I could ask, which one of these would you use?

 showargs;  #NOT this is the tricky

 showargs();
 showargs;
 showargs();

 thanks,
 -rkl

 [EMAIL PROTECTED] asked:
 Here's an excerpt about the  from orielly and what the heck
 does it means:

 ...If a subroutine is called using the  form, the argument list is
 optional. if ommitted, no @_ array is setup for the routine;
 the @_ array at the time of the call is visible to subroutine instead.

 If in doubt, run a test ;-)

 #!/usr/bin/perl -w

 use strict;

 sub showargs {
   print arguments are:  . join(', ', @_) . \n;
 }

 sub test {
   print Arguments for test() are:  . join(', ', @_) . \n;
   print Calling showargs - ;
   showargs;
   print Calling showargs() - ;
   showargs();
   print Calling showargs - ;
   showargs;
   print Calling showargs() - ;
   showargs();
 }

 test qw(foo baz bar);
 __END__

 So, is there a better or worse? both ways works for me. I just started
 going back and putting the  onto the sub ;) I don't like it
 the  but I thought that you need it.

 See for yourself - there's only one use for the ampersand,
 and it's obscure. My advice would be to avoid using it even
 in the one situation where it would make sense - when passing
 @_ as an argument to your function. Sure, it is idiomatic Perl
 at its best, but it also makes a program harder to read and
 understand.

 In other words - save it for Perl Golf ;-)

 HTH,
 Thomas

 PS: Perl Golf - writing code with as little (key-)strokes as
 possible.



 --
 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: Is there a function to see if something is an element of an a rray?

2003-09-30 Thread Hanson, Rob
 I don't want the IP addresses to be
 printed if they are not unique.

Unless you need to keep the ordering of the values you should use a hash
like this.

my %data;

for (@list_of_ip) {
  $data{$_} = 1;
}

my @unique = keys %data;


Rob



-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 12:58 PM
To: [EMAIL PROTECTED]
Subject: Is there a function to see if something is an element of an
array?


I have a long list of IP addresses I am going to be reading in (using
regexps) and then seperating out into a list of IP addresses.  I don't
want the IP addresses to be printed if they are not unique.

Is there a way to check if a string already has an element in a stack?

i.e. push @stack, $_ if is_unique($_, @stack); ?

Or would I have to code that myself?

-Dan


-- 
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: Pattern matching username

2003-09-30 Thread Hanson, Rob
That isn't quite right, you may get better milage with this...

# untested
if ($z =~ /^[a-zA-Z_\-\.][\w\-\.]{2,}$/) {
  # is ok
}
else {
  # failed
}

Yours should also work, except that...

1. \s isn't needed in the first regex since a space would fail in the second
regex anyway.

2. You need to specify the dash (-), it isn't included in \w.

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 1:30 PM
To: [EMAIL PROTECTED]
Subject: Pattern matching username


Is this doing what it is suppose to and how efficient?

rule
 - valid chars A-z0-9 _ - .
 - cannot start with a digit
 - cannot start with a space
 - must be greater than 3 in length

sub isValidChars
{ my ($z) = @_;
 return length($z)  3  $z !~ /^[\d\s]/  $z =~ /^[\w.]+$/
}

thanks,
-rkl

-- 
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: building module/package

2003-09-30 Thread Hanson, Rob
Besides the advice given below, there are a few other things you can do...

To add the location of the Perl script to the lib path you can use this.
The FindBin module finds your script, then sets $Bin to that location.

use FindBin qw($Bin);
use lib $Bin;

Another way to do it is to set the environment variable PERL5LIB to the
location of your home-grown modules.  You can set this in the Apache config
(or .htaccess file) with the setenv command (see Apache docs for more info,
but I think it is setenv PERL5LIB /path/to/lib).

You could also install it into the site_perl directory in your @INC path,
but you should never put it in the vendor_perl directories.

Of the above options I would recommend using the PERL5LIB env variable.
...And I would also recommend that the libraries not be put in any directory
accessable to the web server (unless you have no choice).

Rob


-Original Message-
From: Daniel Staal [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 2:39 PM
To: [EMAIL PROTECTED]; Perl Newbies
Subject: Re: building module/package




--On Monday, September 29, 2003 23:53 -0700 [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:

 -I've sent this to the mod_perl list but there seems to be no
 response.

 I got the module working in the current directory executing on the
 command line. But I have a problem calling a module in my mod_perl
 dir using apache on redhat 9. I have a mystuff.pm in the same
 directory as the calling perl program. I got it working running on
 the command line but in apache mod_perl, it can't find the module.

Ok, I know nothing about mod_perl, but let's see what I can do. 
First guess: mod_perl considers that 'the current directory' is 
either itself or insecure.  (Probably the latter: it is in this 
context.)

 Questions:
  - Where should the mystuff.pm be located in?
  - The only place i know about mod_perl configuration file is:
 /etc/httpd/conf.d/perl.conf. This contains the Alias and Directory
 directive.

 Error message:
 Can't locate mystuff.pm in @INC (@INC contains:
 /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl
 /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl
 /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .)

Hmm.  So it does seem to contain the current directory...  (That 
would be the '.' at the end.)  Doesn't help much: We still don't know 
*which* directory is the current directory.

There are two or three things you could do here.  First off, you 
could put 'mystuff.pm' in one of the above directories.  Don't really 
recommend that, it confuses the user on what is written on your end 
and what isn't, but it is possible.

Secondly, you could see if there is a way to add to the @INC array in 
mod_perl's config.  I would assume so, but I have no clue...

Third, you could add to @INC in your program file.  The best way to 
do this is to use the 'use lib' pragma.  Syntax: 'use lib $lib;' 
where $lib is any perl expression that can be expanded into the 
directory.  (That means you can use variables, but only ones that 
will have a value without running any of your program code...)  Put 
that in your program before you 'use' your module.

To simplify: put 'use lib /path/to/module;' before 'use module;' in 
your main program and it should work. ;-)

 Any help would be great.
 By the way, I just getting started with perl.
 -rkl

Hey, I haven't even completed my first perl program yet.  It just 
happens that my first program is best written with three modules...

Daniel T. Staal

---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---

-- 
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: building module/package

2003-09-30 Thread Hanson, Rob
 The only configuration I know is
 in /etc/httpd/conf.d/perl

Yup, that looks like the one.

 put this here?

I think it would go right above (or below) the Alias line.

Rob


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 3:12 PM
To: Hanson, Rob
Cc: 'Perl Newbies'; [EMAIL PROTECTED]
Subject: RE: building module/package


my redhat 9 is configured canned w/apache and mod_perl. The only
configuration I know is in /etc/httpd/conf.d/perl:

Alias /mp /var/www/mp
Directory /var/www/mp
SetHandler perl-script
PerlHandler ModPerl::Registry::handler
PerlOptions +ParseHeaders
Options +ExecCGI

put this here?
setenv PERL5LIB /path/to/lib

/Directory

 Besides the advice given below, there are a few other things you can do...

 To add the location of the Perl script to the lib path you can use this.
 The FindBin module finds your script, then sets $Bin to that location.

 use FindBin qw($Bin);
 use lib $Bin;

 Another way to do it is to set the environment variable PERL5LIB to the
 location of your home-grown modules.  You can set this in the Apache
 config
 (or .htaccess file) with the setenv command (see Apache docs for more
 info,
 but I think it is setenv PERL5LIB /path/to/lib).

 You could also install it into the site_perl directory in your @INC
 path,
 but you should never put it in the vendor_perl directories.

 Of the above options I would recommend using the PERL5LIB env variable.
 ...And I would also recommend that the libraries not be put in any
 directory
 accessable to the web server (unless you have no choice).

 Rob


 -Original Message-
 From: Daniel Staal [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, September 30, 2003 2:39 PM
 To: [EMAIL PROTECTED]; Perl Newbies
 Subject: Re: building module/package




 --On Monday, September 29, 2003 23:53 -0700 [EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:

 -I've sent this to the mod_perl list but there seems to be no
 response.

 I got the module working in the current directory executing on the
 command line. But I have a problem calling a module in my mod_perl
 dir using apache on redhat 9. I have a mystuff.pm in the same
 directory as the calling perl program. I got it working running on
 the command line but in apache mod_perl, it can't find the module.

 Ok, I know nothing about mod_perl, but let's see what I can do.
 First guess: mod_perl considers that 'the current directory' is
 either itself or insecure.  (Probably the latter: it is in this
 context.)

 Questions:
  - Where should the mystuff.pm be located in?
  - The only place i know about mod_perl configuration file is:
 /etc/httpd/conf.d/perl.conf. This contains the Alias and Directory
 directive.

 Error message:
 Can't locate mystuff.pm in @INC (@INC contains:
 /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl
 /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl
 /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .)

 Hmm.  So it does seem to contain the current directory...  (That
 would be the '.' at the end.)  Doesn't help much: We still don't know
 *which* directory is the current directory.

 There are two or three things you could do here.  First off, you
 could put 'mystuff.pm' in one of the above directories.  Don't really
 recommend that, it confuses the user on what is written on your end
 and what isn't, but it is possible.

 Secondly, you could see if there is a way to add to the @INC array in
 mod_perl's config.  I would assume so, but I have no clue...

 Third, you could add to @INC in your program file.  The best way to
 do this is to use the 'use lib' pragma.  Syntax: 'use lib $lib;'
 where $lib is any perl expression that can be expanded into the
 directory.  (That means you can use variables, but only ones that
 will have a value without running any of your program code...)  Put
 that in your program before you 'use' your module.

 To simplify: put 'use lib /path/to/module;' before 'use module;' in
 your main program and it should work. ;-)

 Any help would be great.
 By the way, I just getting started with perl.
 -rkl

 Hey, I haven't even completed my first perl program yet.  It just
 happens that my first program is best written with three modules...

 Daniel T. Staal

 ---
 This email copyright the author.  Unless otherwise noted, you
 are expressly allowed to retransmit, quote, or otherwise use
 the contents for non-commercial purposes.  This copyright will
 expire 5 years after the author's death, or in 30 years,
 whichever is longer, unless such a period is in excess of
 local copyright law.
 ---

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED

RE: Look At This Package

2003-09-30 Thread Hanson, Rob
 #this does NOT work
 #how do i reference these vars
 USER::fname=bob;
 USER::lname=Bingham;

You need the $, like this...
$USER::fname=bob;
$USER::lname=Bingham;

But this may be what you really want. It will allow you to create multiple
USER objects, each with different values stored in them.

use USER;

my $user = new USER();

$user-{fname} = bob;
$user-{lname} = Bingham;

print $user-prt() . \n;

USER.pm
---
package USER;

sub new {
  my $class = shift;
  bless {}, $class;
}

sub prtAll {
  my $self = shift; # $self is the object
  ...
}


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 7:01 PM
To: [EMAIL PROTECTED]
Subject: Look At This Package


Can someone make this work like I want? I'm trying to create a package
USER and reference/change it. The only thing I'm able to do is to call the
sub prtAll. I just want a structure that I can pass around in perl.

test.pl
---
use USER;

#this does NOT work
#how do i reference these vars
USER::fname=bob;
USER::lname=Bingham;

print USER::prt . \n;

USER.pm
---
package USER;

$fname;
$lname;

sub prtAll { ... }



-- 
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: Look At This Package

2003-09-30 Thread Hanson, Rob
James pretty much covered everything, but here are my two coppers.

First thing is that this line is wrong...

 my $self = { fname, lname };

It should be this...

my $self = {fname = '', lname = ''};

If you had use strict or warnings on it would have yelled about that one.
The way you had it, it was setting fname to lname instead of creating
two different fields.

 use UserInfo;

 Okay, UserInfo is better, but doesn't tell
 us much.  I was thinking something more like
 ComputerUser, DatabaseUser, GymUser, etc.

I actually like UserInfo, it means you can make ComputerUser and
GymUser subclasses :)  ...but I would hold off on that until everything
else sinks in.

Rob


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 7:53 PM
To: James Edward Gray II
Cc: [EMAIL PROTECTED]
Subject: Re: Look At This Package


James and Rob,

OK version x.2
- I want to create a user object with value initialized.
- Initialize/Change it anytime

test.pl
---
use UserInfo;

my $ui = new UserInfo();
$ui-(fname) = bob;
$ui-(lname) = Bingham;

#change name
$ui-(fname) = robert;

print ui: [ . $ui-full_name() . ]\n;

exit

UserInfo.pm
---
#!/usr/bin/perl
package UserInfo;

sub new
{ my $class = shift;
  my $self = { fname, lname };
  return bless $self, $class;
}

sub full_name
{ my $self = shift;
  return $self-{fname} . ' ' . $self-{lname};
}

1;


 On Tuesday, September 30, 2003, at 06:01  PM, [EMAIL PROTECTED] wrote:

 Can someone make this work like I want? I'm trying to create a package
 USER and reference/change it. The only thing I'm able to do is to call
 the
 sub prtAll. I just want a structure that I can pass around in perl.

 test.pl
 ---

 Good code starts with the following, I promise.

 use strict;
 use warnings;

 use USER;

 Let's drop the all caps here.  Perl tradition is class names in
 titlecase.  The name could also be more descriptive.  What kind of user?

 use User;

 #this does NOT work
 #how do i reference these vars
 USER::fname=bob;
 USER::lname=Bingham;

 It doesn't work because you forgot the special variable symbols.

 $User::fname = 'bob';
 $User::lname = 'Bingham';

 However, objects would probably be better here, so let's try:

 my $user = User-new(f_name = 'bob', l_name = 'Bingham');

 print USER::prt . \n;

 print $user-full_name(), \n;

 USER.pm

 User.pm

 ---
 package USER;

 package User;

 use strict;
 use warnings;

 $fname;
 $lname;

 These would need to use our(), under strict:

 our($fname, $lname);

 But we don't need them.

 sub new {
   my $class = shift;
   my $self = { f_name = 'John', l_name = 'Doe', @_ };
   return bless $self, $class;
 }

 sub full_name {
   my $self = shift;
   return $self-{f_name} . ' ' . $self-{l_name};
 }

 That's very basic object oriented programming, tell me if you need
 parts of it explained.

 James

 sub prtAll { ... }



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

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



RE: remove blanks

2003-09-29 Thread Hanson, Rob
I ran some benchmarks.

The two-liner outperformed the one-liners by a 10 to 1 ratio.  Code and
results below.


Benchmark: timing 10 iterations of OneLine, OneLine2, TwoLines...
  OneLine: 41 wallclock secs (39.30 usr +  0.00 sys = 39.30 CPU) @ 2544.79/s
  OneLine2: 34 wallclock secs (32.58 usr +  0.00 sys = 32.58 CPU) @
3069.56/s
  TwoLines:  3 wallclock secs ( 2.58 usr +  0.00 sys =  2.58 CPU) @
38789.76/s


use strict;
use Benchmark;

my $val =  . (foo x 200) . ;

timethese(100_000, {
'OneLine' = sub{trimOne($val)},
'OneLine2' = sub{trimOne2($val)},
'TwoLines' = sub{trimTwo($val)},
});

sub trimOne {
  my $s = shift;
  $s =~ s/^\s+|\s+$//g;
  die $s unless ($s eq (foox200));
}

sub trimOne2 {
  my $s = shift;
  $s =~ s/^\s*(.*?)\s*$/$1/g;
  die unless ($s eq foox200);
}

sub trimTwo {
  my $s = shift;
  $s =~ s/^\s+//;
  $s =~ s/\s+$//;
  die unless ($s eq foox200);
}


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, September 29, 2003 8:04 PM
To: [EMAIL PROTECTED]
Subject: remove blanks


Is there a func or a onliner for removing blanks from both ends?

I'm using these:

$username =~ s/^\s+//;
$username =~ s/\s+$//;

There got to be one out there!

thanks,
-rkl

-- 
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: Should loops return a value?

2003-09-26 Thread Hanson, Rob
 cleverness and hacks often makes code hard
 to debug or read particularly when programs grow.

I was really just showing that it could be done.  The next step would be to
package the subroutine up as a library so that is can be reused.  This has
been done before in module like Error that gives you constructs that look
like typical try/catch/finally.  And once it is packaged, and deemed stable,
you never have to worry about it again.  Just think how often you use a
module, and never question that it is working correctly.

 i'm not searching a way to solve a single
 problem but trying to make programming easier.

This is what packaging up the functionality will do.  A quick search on CPAN
shows several specialized loop constructs that are designed to make
programming easier:

IfLoop - mixes if and for syntax
Proc::ParallelLoop - loop in parallel
Loop - for loops with added value

Why not add another loop construct module?  ...In fact, I challenge you to
do so. :)

 If loops returned values it would make the
 whole coding much clearlier and better
 structured - at least i believe so.

It sounds like what you are after is to modify the current loop constructs.
The issue there is that returning a value for all loops requires extra
overhead.  Since most users won't want anything returned from a loop you end
up just wasting some CPU time.  Sure, you might argue that a few CPU cycles
won't hurt anyone... but what about the next thing someone wants added, and
the next, and the next.  I would expect the users that would use such a
construct would be few, especially since it isn't a common paradigm, so I
think it is better suited as an extension as opposed to a built-in.

Rob

-Original Message-
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 10:18 PM
To: Hanson, Rob; [EMAIL PROTECTED]
Subject: RE: Should loops return a value?


From: Hanson, Rob [EMAIL PROTECTED]
If you really want a loop to return something, you can roll your own, even
in Perl 5... but the syntax won't be as you gave.

Ye - i'm not searching a way to solve a single problem but trying to make 
programming easier. If loops returned values it would make the whole coding 
much clearlier and better structured - at least i believe so. It'd b easy to

just watch a code and say what it's doing in many cases. Look at what You 
write below; it is of course clever code but cleverness and hacks often 
makes code hard to debug or read particularly when programs grow.

Yours,
---
Ville Jungman

How is this?  The only difference is that you need to put the array to loop
over after the code.  it's close though.

sub loop (@);

my @x = (1,3,5,7);
my @y = loop {
   return $_[0].a if $_[0]  4;
} @x;

print @y;


sub loop (@) {
   my $sub = shift;
   my @ret;

   foreach (@_) {
 my $val = $sub($_);
 push @ret, $val if $val;
   }

   return @ret;
}

Rob


-Original Message-
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 9:36 PM
To: Hanson, Rob; [EMAIL PROTECTED]
Subject: RE: Should loops return a value?


Rob, did You read my message at all :-) ?

i just was wandering if there _could_ be more readable way to do this.
Andnot only for to be readable. If loops (and maybe some other builtin
commands, too - we are not talking only about whiles and for's) returned
values, programming might be a way different because you could combine 
loops

with for example those greps and maps. Consider really what would be
possible to do with this (maybe look at those examples again, too, to get
the idea). Also You can not do everything with grep and map and on the 
other

hand they are not very fast to read or debug when comparizing with this.

i've _always_ wanted to have a program language where loop-commands could
return whatever is needed. It might be that someday i have to write such
language or make a fast poor implementation. If this ability would be
implemented wisely to perl (or to some other language), it wouldn't even
affect to performance (ok, maybe little bit). But it'd bring much power
because You could have more control, readibility and straightforwardity in
Your code - and maybe more speed in some circumstances, too.

Kindly, Ville Jungman

 From: Hanson, Rob [EMAIL PROTECTED]
 @values = (1,3,5,7);
 @bigger_than_4 = map {$_.'a'} grep {$_4} @values;
 print @bigger_than_4;
   You need to escape a loop with a value.
 
 Not sure I understand what you are trying to accomplish, but this is the
 equivalent of your Perl version and is as short as your proposed syntax.
 
 while (FH) {
next unless /stop/;
#somthing
last;
 }
 
 Rob
 
 
 -Original Message-
 From: Ville Jungman [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 25, 2003 8:25 PM
 To: [EMAIL PROTECTED]
 Subject: Should loops return a value?
 
 
 Shortly, I think it might be good if loops (etc.) could return values.
 
 
 
 Example 1: Retnext (like 'return next' borrowed from pl/sql)
 You want to extract

RE: How to pass parameters to a module

2003-09-26 Thread Hanson, Rob
 Can someone explain how does one pass
 a parameter to a Perl Module?

There are a few ways.

#1 - On the use line

use My::Module qw(foo bar);

When you use a module it first loads the module and evaluates it.  Second
it runs the import() subroutine in the module (if there is one), passing the
params you specified on the use line.  BTW - this is how Exporter works, it
supplies an import() subroutine that exports variables/methods for you.  If
you need to use Exporter, and want your own import() sub, then you need to
do it a little differently.  Take a look at the perl docs for more info.

#2 - On object creation

my $obj = new My::Module('foo', 'bar');

#3 - Set via properties or methods

$obj-{key} = 'foo';
...or...
$obj-set_key('foo');

It really depends on what exactly you are trying to accomplish.

Rob



-Original Message-
From: Rajesh Dorairajan [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 1:00 AM
To: '[EMAIL PROTECTED]'
Subject: How to pass parameters to a module


Can someone explain how does one pass a parameter to a Perl Module? To
illustrate suppose I've My::Module

package My::Module;

BEGIN
{
  $scalar = $input;
}

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = ($scalar);

In the above script is there anyway to pass the $input variable to the
package My::Module from the calling script? Please excuse me if the code is
horrible, just trying to simplify what I want ;)

TIA

Rajesh

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



RE: Basic question...

2003-09-25 Thread Hanson, Rob
 I see two ways of writing this code.

Hmmm, how about a third way.  The following code dynamically loads a module
based on the extension of the file.  If it successfully loads the module it
instantiates a new object and calls the handle_file() method of the object.

This accomplishes a few things:

1. Allows each file type to be handled by a seperate module.  This allows
you to plug-in new file types as needed without modifying other working
code.  This should make debugging easier.

2. The modularity of this approad simplifies maintenance since each module
is smaller than if you lumped all the code into one place.

3. Each object instantiated to do something with a file can store state if
you ever need it.

# tested code

use strict;
use lib './testlib';
use Error qw(:try);

my @files = ('foobar.log');

foreach my $file (@files) {
  if ($file =~ /.+\.(\w+)$/) {
my $ext = $1;

try {
  require MyWorkers/$ext.pm;

  my $obj = MyWorkers::$ext-new();
  $obj-handle_file($file);

}
catch Error::Simple with {
  warn Unhandled extension: $ext\n;
}
  }
}

...Elsewhere in ./testlib/MyWorkers/log.pm

package MyWorkers::log;

sub new
{
  my $class = shift;
  bless {}, $class;
}


sub handle_file
{
  my $self = shift;
  my $file = shift;
  print Handling $file\n;
  print Write file handling code here\n;
}

1;


-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 10:27 AM
To: [EMAIL PROTECTED]
Subject: Basic question...


I posted the other day a question about writing a daemon to monitor
a directory and then process the files as they arrive in said directory.  I
will begin working on this shortly, but I have a related question and this I
think is mainly a question of good coding practice.  Eventually, there will
be several different types of files that will be hitting this directory for
processing.  The processing that occurs on each file will be based on the
filename.  I see two ways of writing this code.  First, I could write each
section of code as a separate Perl script that is called by the daemon.  The
other way I see doing this is to write each section of code as a subroutine
within the daemon program and have that called.  Any suggestions on which of
these would be better?  More correct?  Etc.?
Thanks in advance for the help yet again.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-- 
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: How do ISTDIN to a stack until a pattern is matched, How do I

2003-09-25 Thread Hanson, Rob
 How can I do this?

You can do it like this...

# tested
my @stack;

while (STDIN) {
  last if /QUIT/;
  push @stack, $_;
}

print @stack;


Rob

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:23 PM
To: Perl Newbies
Subject: How do ISTDIN to a stack until a pattern is matched, How do I


Is there an easy way to read STDIN into a stack until some pattern is
matched and then break.  I tried all sorts of (error producing) code,
but nothing seemed to work.  I ended up with:

#! /usr/bin/perl

#can I make this more concise?
$infinite_loop = 1;
while ($infinite_loop)
{
  $temp = STDIN;
  if ($temp =~ /QUIT/)
{ 
$infinite_loop = 0; 
continue;
}
  push @thestack, $temp;
}

I've got a funny feeling that perl will let me make the above 15 lines
of code /much/ more concise.  How can I do this?  

Is there any way to do something like?

while (1)
{
  push @thestack, STDIN unless STDIN =~ /QUIT/;
  last if STDIN =~ continue;
}

Or perhaps something even more concise (and much more perlish)?

Thanks,

Dan



-- 
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: Should loops return a value?

2003-09-25 Thread Hanson, Rob
 You want to extract numbers from an array
 if they are  4 and put an 'a'-letter after them.

Try this...

# tested
@values = (1,3,5,7);
@bigger_than_4 = map {$_.'a'} grep {$_4} @values;
print @bigger_than_4;

 You need to escape a loop with a value.

Not sure I understand what you are trying to accomplish, but this is the
equivalent of your Perl version and is as short as your proposed syntax.

while (FH) {
  next unless /stop/;
  #somthing
  last;
}

Rob


-Original Message-
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:25 PM
To: [EMAIL PROTECTED]
Subject: Should loops return a value?


Shortly, I think it might be good if loops (etc.) could return values.



Example 1: Retnext (like 'return next' borrowed from pl/sql)
You want to extract numbers from an array if they are  4 and put an 
'a'-letter after them.

   @values=(1,3,5,7);
   @bigger_than_4=   # get an array from loop
  foreach $value(@values) {
 retnext $value.a if $value  4;   # return value from loop if  4
  }
   ;



Example 2: Retlast (== perl 'last'-command with a value)

You need to escape a loop with a value. Familiar way:

   while(FH){
  if(/stop/){
 $array_terminated='true';
 last;
  }
   }
   if($array_terminated){
  # something
   }

This could be written as:

   if(
  while(FH){
 retlast if /stop/;  # returns $_ by default
  }
   ){
  # something
   }



So, not very conserverite but think what all you could do with this.
And please, let me know what you think about this. Crap?

---

ville jungman, 2 laureston crescent, tower, blarney, cork, ireland
tel. + 353 - 21 - 451 6847, http://www.kolumbus.fi/vilmak
usko Herraan Jeesukseen, niin sinä pelastut. (apt. 16:31)

_
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail


-- 
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: How do ISTDIN to a stack until a pattern is matched, How do I

2003-09-25 Thread Hanson, Rob
 I assume that $_ is the last thing gotten by STDIN

Yes, but there is a little more to it than that.

Normally while() does NOT set $_.  So this would not work normally:

while ($foo) { print $_ } # $_ is NOT set

At some point it was decided that most people will use a while loop to loop
over the lines of a file, so some magic dust was sprinkled on the while()
loop to set $_, but ONLY if there is only a file handle as the condition.

So while(HANDLE) is a special case.

 while (!(STDIN =~ /QUIT/))

This won't set $_ because there is more than just the filehandle in the
condition.

You can though set $_ yourself in the condition, like this:

while ($_ = STDIN and !/QUIT/) {
  push @stack, $_;
}
print @stack;

Or even this:

push @stack, $_ while ($_ = STDIN and !/QUIT/);
print @stack;

 will regexes always default to using $_

Yes.


Rob

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:40 PM
To: Hanson, Rob
Cc: Perl Newbies
Subject: RE: How do ISTDIN to a stack until a pattern is matched, How
do I


First, thank you for your help.  Second, please bear with me as I'm
a
perl noob.

I assume that $_ is the last thing gotten by STDIN.  will regexes
always default to using $_?  I think that's right, but when I try:

while (!(STDIN =~ /QUIT/))
{ push @stack, $_; }
print @stack;

it doesn't print anything (although it compiles).

So I typed use warnings; at the top and I get a lot of errors about
using an uninitialized variable (@stack).  Now I assume that @stack
comes into scope as local to that while loop, but typing:

my @stack;
our @stack;
local @stack;

Before the loop do nothing.  Am I missing something? 

Thanks again for your help,

-Dan




On Thu, 2003-09-25 at 20:29, Hanson, Rob wrote:
  How can I do this?
 
 You can do it like this...
 
 # tested
 my @stack;
 
 while (STDIN) {
   last if /QUIT/;
   push @stack, $_;
 }
 
 print @stack;
 
 
 Rob
 
 -Original Message-
 From: Dan Anderson [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 25, 2003 8:23 PM
 To: Perl Newbies
 Subject: How do ISTDIN to a stack until a pattern is matched, How do I
 
 
 Is there an easy way to read STDIN into a stack until some pattern is
 matched and then break.  I tried all sorts of (error producing) code,
 but nothing seemed to work.  I ended up with:
 
 #! /usr/bin/perl
 
 #can I make this more concise?
 $infinite_loop = 1;
 while ($infinite_loop)
 {
   $temp = STDIN;
   if ($temp =~ /QUIT/)
 { 
   $infinite_loop = 0; 
   continue;
 }
   push @thestack, $temp;
 }
 
 I've got a funny feeling that perl will let me make the above 15 lines
 of code /much/ more concise.  How can I do this?  
 
 Is there any way to do something like?
 
 while (1)
 {
   push @thestack, STDIN unless STDIN =~ /QUIT/;
   last if STDIN =~ continue;
 }
 
 Or perhaps something even more concise (and much more perlish)?
 
 Thanks,
 
 Dan
 
 

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



RE: Should loops return a value?

2003-09-25 Thread Hanson, Rob
 Shortly, I think it might be good if
 loops (etc.) could return values.

BTW - One of the goals for Perl 6 is that you will be able to build any Perl
construct in Perl itself.

So also although Perl5, and probably Perl6, won't let you return values from
a loop, you should at least be able to build your own loop construct in Perl
6 that will.

Something to look forward to.

Rob

-Original Message-
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:25 PM
To: [EMAIL PROTECTED]
Subject: Should loops return a value?


Shortly, I think it might be good if loops (etc.) could return values.



Example 1: Retnext (like 'return next' borrowed from pl/sql)
You want to extract numbers from an array if they are  4 and put an 
'a'-letter after them.

   @values=(1,3,5,7);
   @bigger_than_4=   # get an array from loop
  foreach $value(@values) {
 retnext $value.a if $value  4;   # return value from loop if  4
  }
   ;



Example 2: Retlast (== perl 'last'-command with a value)

You need to escape a loop with a value. Familiar way:

   while(FH){
  if(/stop/){
 $array_terminated='true';
 last;
  }
   }
   if($array_terminated){
  # something
   }

This could be written as:

   if(
  while(FH){
 retlast if /stop/;  # returns $_ by default
  }
   ){
  # something
   }



So, not very conserverite but think what all you could do with this.
And please, let me know what you think about this. Crap?

---

ville jungman, 2 laureston crescent, tower, blarney, cork, ireland
tel. + 353 - 21 - 451 6847, http://www.kolumbus.fi/vilmak
usko Herraan Jeesukseen, niin sinä pelastut. (apt. 16:31)

_
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail


-- 
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: Do BEGIN blocks and END blocks have priority?

2003-09-25 Thread Hanson, Rob
 Will the inner BEGIN block take precedence over the outer one

I dunno, but I guess I could check...

print Done\n;
BEGIN {
  print Top begin\n;
}
BEGIN {
  print Outer\n;

  BEGIN {
print Inner\n;
  }
}
BEGIN {
  print Bottom begin\n;
}

This prints:
Top begin
Inner
Outer
Bottom begin
Done

So apparently it does.  Interesting.

Rob

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 9:13 PM
To: Perl Newbies
Subject: Do BEGIN blocks and END blocks have priority?


If I create code with:

BEGIN
{
   # something
   BEGIN
   {
 # something else
   }
}

Will the inner BEGIN block take precedence over the outer one, and thus
load any subroutines or whatever is in the inner begin block?  Or will
the second begin block be ignored and the compiler see:

BEGIN
{
  #something
  #something else
}

Thanks in advance,

Dan


-- 
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: Should loops return a value?

2003-09-25 Thread Hanson, Rob
 Rob, did You read my message at all :-) ?

I'm not telling. :P

If you really want a loop to return something, you can roll your own, even
in Perl 5... but the syntax won't be as you gave.

How is this?  The only difference is that you need to put the array to loop
over after the code.  it's close though.

sub loop (@);

my @x = (1,3,5,7);
my @y = loop {
  return $_[0].a if $_[0]  4;
} @x;

print @y;


sub loop (@) {
  my $sub = shift;
  my @ret;

  foreach (@_) {
my $val = $sub($_);
push @ret, $val if $val;
  }

  return @ret;
}

Rob


-Original Message-
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 9:36 PM
To: Hanson, Rob; [EMAIL PROTECTED]
Subject: RE: Should loops return a value?


Rob, did You read my message at all :-) ?

i just was wandering if there _could_ be more readable way to do this. 
Andnot only for to be readable. If loops (and maybe some other builtin 
commands, too - we are not talking only about whiles and for's) returned 
values, programming might be a way different because you could combine loops

with for example those greps and maps. Consider really what would be 
possible to do with this (maybe look at those examples again, too, to get 
the idea). Also You can not do everything with grep and map and on the other

hand they are not very fast to read or debug when comparizing with this.

i've _always_ wanted to have a program language where loop-commands could 
return whatever is needed. It might be that someday i have to write such 
language or make a fast poor implementation. If this ability would be 
implemented wisely to perl (or to some other language), it wouldn't even 
affect to performance (ok, maybe little bit). But it'd bring much power 
because You could have more control, readibility and straightforwardity in 
Your code - and maybe more speed in some circumstances, too.

Kindly, Ville Jungman

From: Hanson, Rob [EMAIL PROTECTED]
@values = (1,3,5,7);
@bigger_than_4 = map {$_.'a'} grep {$_4} @values;
print @bigger_than_4;
  You need to escape a loop with a value.

Not sure I understand what you are trying to accomplish, but this is the
equivalent of your Perl version and is as short as your proposed syntax.

while (FH) {
   next unless /stop/;
   #somthing
   last;
}

Rob


-Original Message-
From: Ville Jungman [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:25 PM
To: [EMAIL PROTECTED]
Subject: Should loops return a value?


Shortly, I think it might be good if loops (etc.) could return values.



Example 1: Retnext (like 'return next' borrowed from pl/sql)
You want to extract numbers from an array if they are  4 and put an
'a'-letter after them.

@values=(1,3,5,7);
@bigger_than_4=   # get an array from loop
   foreach $value(@values) {
  retnext $value.a if $value  4;   # return value from loop if 

4
   }
;



Example 2: Retlast (== perl 'last'-command with a value)

You need to escape a loop with a value. Familiar way:

while(FH){
   if(/stop/){
  $array_terminated='true';
  last;
   }
}
if($array_terminated){
   # something
}

This could be written as:

if(
   while(FH){
  retlast if /stop/;  # returns $_ by default
   }
){
   # something
}



So, not very conserverite but think what all you could do with this.
And please, let me know what you think about this. Crap?

---

ville jungman, 2 laureston crescent, tower, blarney, cork, ireland
tel. + 353 - 21 - 451 6847, http://www.kolumbus.fi/vilmak
usko Herraan Jeesukseen, niin sinä pelastut. (apt. 16:31)

_
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail


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


_
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus

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



RE: Query string to LWP requests

2003-09-23 Thread Hanson, Rob
 I wonder why GET wouldn't work? Any ideas of the reason?

GET tells the receiving app to look at the query string (the part of the URL
after the ?), POST tells it to look at the body content.  You passed the
data in the body content, NOT the query string... to the CGI module was
looking in the wrong place for the data.

If you wanted to sent a GET, you could do it like this...

my $req = new HTTP::Request(GET = 'http://joemama.com/howdy.cgi?hi=dummy');
my $res = $agt-request($req);

Rob

-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 23, 2003 2:53 PM
To: [EMAIL PROTECTED]
Subject: RE: Query string to LWP requests


 my $agt = new LWP::UserAgent; 
   # works
 my $req = new HTTP::Request(GET = 
 'http://joemama.com/howdy.cgi'); # works
 
 #What am I doing 
 wrong here? The script I'm getting just has 
 #print param('hi'); so I don't thignk it's a get/post issue.

I was totally wrong! I change GET = to POST = above and it worked el
prefecto!

I wonder why GET wouldn't work? Any ideas of the reason?

 
 $req-content_type('application/x-www-form-urlencoded'); 
 $req-content('hi=dummy');  

-- 
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: GetOpts: boolean and argument value combos

2003-09-23 Thread Hanson, Rob
 Since I want to treat -book like a boolean

The problem is that you are telling Getopt::Long that book expects a
string value:

 book=s =\$book,

This is untested, but this should work.

 book =\$book,

It sets the value of $book to 1 if the option is present.

See the Getopt::Long docs, the section on Simple Options.
http://search.cpan.org/author/JV/Getopt-Long-2.34/lib/Getopt/Long.pm#Simple_
options

Rob


-Original Message-
From: Trina Espinoza [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 23, 2003 9:11 PM
To: [EMAIL PROTECTED]
Subject: GetOpts: boolean and argument value combos


Hey Perl Peps,

I am stuck in the mudd and hoping someone can give me a few clues that will
help get me back on track.

I want to submit some arguments like so:
./script1.pl -book  -title HP3 -chapter 04 

 NOTE: -book does not have an argument
Now I have been using GetOpt::Long and everything works except the first
value -book. Since I want to treat -book like a boolean, I do
not give it value, which causes problems because I guess it needs to receive
some sort of value in it's current format. This is causing problems
where the value of the second argument -title does not show. Is there a
syntactical form I can follow to treat -book like a boolean and feed the
other arguments
values? Can I continue to use Getopt::Long?

Any suggestions would be much appreciated.

CODE
---
use Getopt::Long;
use File::Path;
#use strict;


GetOptions  (
book=s =\$book,
magazine=s =\$magazine,
video=s =\$video,
c=s = \$chapter,
t=s = \$title,
 );

##Routes to appropriate subroutine
print SHOW TEST: $sPath\n;
if ($book) {
itemCreator($chapter, $title);
}
###SUBROUTINES
sub showCreator {
my($chapter, $title) = @_;
print \n; 
print CHAPTER: $chapter\n;  ###Not appearing because -book did not
receive an arguement :(
print TITLE: $title: $template\n;
   
}


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



RE: instance variables?

2003-09-18 Thread Hanson, Rob
 But I'm wondering if there is another way
 (like the Java private variable) to say
 all class variables declared here are unique
 to each instance? 

It sounds like you are trying to link how OO-Perl works with OO-Java... and
that is only going to make your head spin.  What you really need to do is
understand what bless really does, and that OO-Perl isn't really OO in the
usual sense (but it works like it is).

In Perl an object is really just a scalar variable that has been blessed.
Blessing adds an attribute to the scalar variable which is supposed to
represent the type of scalar.  The only requirement is that the bless
scalar must be a reference.

my $x = foo;
my $y = bless \$x, bar;
print $y;
# PRINTS: bar=SCALAR(0xa01ed1c)

Here $y is a reference to a scalar (hence the SCALAR(0xa01ed1c)), and it
has been tagged as type bar.

That is all bless does.

Now the next part is the magic that Perl does...

$x-do_stuff;

Here $x does what looks like a method call.  Perl will look at the type of
$x, which is foo, then try to execute do_stuff() in the foo package.
The first argument of this call will always be $x, like this:

foo:do_stuff($x);

This call does exactly the same thing as above.

Now when you talk about instance variables, realize that there is no true
object instance in Perl.  It is just a reference tagged with a type... the
rest is all smoke and mirrors.

So to emmulate instance variables you can use a hash reference instead of a
scalar reference, like this:

my %x = (field1 = 'val1', field2 = 'val2');
my $y = bless \%x, bar;

Now $y is just a hash reference, so this stuff still works:

print $y-{field1};
print $y-{field2};

...And $y is also blessed, meaning you can emulate calling methods like I
did earlier.

Now you can still emulate private variables, but again, it's more smoke and
mirrors.  Without getting into the details (look at 'tie' for more info) you
can just use the Tie::SecureHash module.  It emulated public, protected, and
private variables.

http://search.cpan.org/author/DCONWAY/Tie-SecureHash-1.03/SecureHash.pm

I hope that helps a little.

Rob



-Original Message-
From: Kevin Pfeiffer [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 18, 2003 1:32 PM
To: [EMAIL PROTECTED]
Subject: instance variables?


Hi all,

I stumbled across something called BlueJ which provides a user-friendly
graphical environment in which to learn OO-programming, Java-style. I think
this is a great parallel universe to go along with the Perl Objects book.

I started re-writing one of the first exercises as a Perl package:
[question follows below]

package TicketMachine;
# etc.

=head1 DESCRIPTION
TicketMachine models a naive ticket machine that issues
flat-fare tickets.

The price of a ticket is specified via the constructor.

[Based on an exercise from Objects First With Java:
A Practical Introduction Using BlueJ.]
=cut

# my $price;# Price of a ticket from this machine.
# my $balance;  # Amount of money entered by customer
# my $total;# Total amount of money collected by machine


# Create a machine that issues tickets of the given price.
# Price must be greater than zero (but no checks done).
sub new {
my $class = shift;

# In the BlueJ environment instances are automatically
# named behind the scenes (so far)...
my $instance = tm . int(rand(25));

my $self = { Name = $instance, Price = shift };
bless $self, $class;
}

sub getPrice {
my $self = shift;
return $self-{Price};
}

# more methods to come...

1;

__END__

In the Java version, the three variables are declared in the class first:
private int price;
private int balance;
private int total;

So in Perl I tried declaring these in the package using my, but they seemed
to remain class variables, so if I would do something like:

for (@ticket_machines) {
  print A ticket costs , $_-getPrice(),  cents.\n;
} 

I would then get (for two machines):

A ticket costs 100 cents.
A ticket costs 100 cents.


Then I tried this with Perl...

In the new constructor:

   my $class = shift;
   my $price = shift;
   my $self = $instance;
   bless \$self, $class, $price;

...I was told too many arguments to bless. The Perl Objects book says the
easiest way to use more data with an instance is with a blessed hash
reference, and that did work fine (and maybe that's the best way).

But I'm wondering if there is another way (like the Java private variable)
to say all class variables declared here are unique to each instance? 

It occurs to me that perhaps the difference is that in Perl you can call
methods on a class (i.e. the an unnamed horse from the Perl Objects book)
but not in Java (other than the contructor method)?

(If anyone is interested in BlueJ - www.bluej.org)

-K

-- 
Kevin Pfeiffer
International University Bremen



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

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

RE: Conceptual -- Spam stopper script

2003-09-16 Thread Hanson, Rob
You will probably run into a few issues.  First you need to fetch the MX
record for the domain before you can even connect.  After that you could use
the SMTP verify user command to see if the user exists, but I think you
might find that many SMTP servers will not give you a reliable answer.  I
think AOL, for example, will always tell you that the user exists (I may be
wrong though).

I think you might be better off with Spam Assassin, or using an ISP that
uses it.

On the other hand, it can't hurt to try doing it yourself.

Rob 

-Original Message-
From: Jerry Rocteur [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 16, 2003 5:33 PM
To: [EMAIL PROTECTED]
Subject: OT: Conceptual -- Spam stopper script


Hi,

I've been analyzing my SPAM by replying to it lately and find that MOST  
email addresses where the SPAM originates do not exist.. Nothing new  
here..

What I'd like to do is to write a script that accesses my pop mail,  
gets the From: address, verifies it and if it is a valid address,  
accepts the mail, otherwise, removes  it..

Is this feasible or plain wishful thinking ???

I've written perl scripts to  handle sending mail and to access pop  
mail but I'm not sure of being able to do the above ???

I realize this is a bit OFF topic but SPAM is getting to me ;-((

Thanks for your thoughts,

Jerry Rocteur.

Italy did it first...
http://www.rocteur.cc/geeklog/public_html/ 
article.php?story=20030914164349518


-- 
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: load apache perl on a CD to run HTML documents?

2003-09-15 Thread Hanson, Rob
You will still need a webserver.

Check out microweb, it does exactly what you need.  I never tried it though,
so I can't say if it is any good.

http://www.indigostar.com/microweb.htm

Rob

-Original Message-
From: Gregg O'Donnell [mailto:[EMAIL PROTECTED]
Sent: Monday, September 15, 2003 11:45 AM
To: [EMAIL PROTECTED]
Subject: load apache  perl on a CD to run HTML documents?


I have a web-based manual that includes calculators and other .cgi scripts.
I need to make this manual available to some users who have no Internet
access; that is, turn a web app into desktop app. Would appreciate any help
or guidance to resources to do this. Thanks, Gregg


-
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

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



RE: :Mechanize -links() problem

2003-09-11 Thread Hanson, Rob
Each link returned is a WWW::Mechanize::Link object.  You need to use the
methods supplied to get the info.

See:
http://search.cpan.org/~petdance/WWW-Mechanize-0.59/lib/WWW/Mechanize/Link.p
m

Use it like this...

@LINKS = $agent-links();
foreach (@LINKS) {
  print $_-url(), \n;
  print $_-text(), \n;
  print $_-name(), \n;
  print $_-tag(), \n;
}


Rob


-Original Message-
From: Dave Odell [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 11, 2003 2:16 PM
To: [EMAIL PROTECTED]
Subject: WWW::Mechanize -links() problem


Question:
I'm trying to use the links(); function which in the man page says
returns a list of the links found in the last fetched page. 
However when I try

@LINKS =  $agent-links();
foreach(@LINKS){
print $_\n;
}
it returns

WWW::Mechanize::Link=ARRAY(0x84a731c)

Does this mean it's an reference or does it return and array and I'm
just using it incorrectly? 
 If it is a reference is there a good tutorial around for using them.

Thanks

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



RE: Module install

2003-09-10 Thread Hanson, Rob
Sure.

Use this when running Makefile.PL.

perl Makefile.PL LIB=~/myhomelib PREFIX=~/myhomelib

This will install the modules to ~/myhomelib.  To use the modules in a
script you can either use lib '/myhomepath/myhomelib' (note the full path,
no ~).  Or you can set the environment var PERL5LIB to that directory, which
will be prepended to your @INC array.

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 10, 2003 12:49 PM
To: [EMAIL PROTECTED]
Subject: Module install


Anyone know if your able to install modules in the users local home 
directory? I'm running on a system that I'm not able to install modules 
system wide.

Thanks

Denis


-- 
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: Modules Question

2003-09-10 Thread Hanson, Rob
I googles Julian and came up with two email addresses from this page:
http://www.monkey.org/openbsd/archive/misc/9904/msg00077.html

If that fails I'm not sure.

The FAQ on CPAN doesn't help much with this specific case since the mails
are bouncing:
http://www.cpan.org/misc/cpan-faq.html#How_maintain_module

Perhaps Randal will pop his head in and have some advice.

Rob

-Original Message-
From: James Edward Gray II [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 10, 2003 6:11 PM
To: [EMAIL PROTECTED]
Subject: Modules Question


I use Text::Bastardize off of the CPAN from time to time.  I find it 
mildly amusing, if not terribly practical.

However, today when I was working with it, I basically fed it some text 
that overwhelmed it.  What I fed it really wasn't too crazy, so I took 
a look under the hood.

While I was in there, I basically saw a lot of general improvements I 
would like to make, so I fired off a message to the author.  Of course, 
it bounced.  Looking at the CPAN, it looks like it's been around three 
years since the author contributed anything.

So, if memory serves, there is a proper protocol for taking control of 
an abandoned module, which is what I would like to do.  However, I'm 
having trouble finding it.  Could someone point me in the right 
direction?

Thanks.

James


-- 
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: accessing a hash map...

2003-09-09 Thread Hanson, Rob
You have it slightly wrong...

print $hashref{'disks'}-{'io'};

...And the quotes are optional (usually)...

print $hashref{disks}-{io};

 Is there a more generic mailing list
 for the different perl modules?

Thare are other lists/newsgroups, but most are geared to specific port
(ActiveState), or modules (Tk).  This is a good list for any beginner(ish)
question, no matter the subject... just as long as it is a Perl question.

Rob

-Original Message-
From: Li, Kit-Wing [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 09, 2003 2:40 PM
To: cgi cgi-list
Subject: accessing a hash map...


This may not be the right thread but I'd like to see if someone could point
me to the right direction.  I'm writing a CGI script to show current
performance of the Apache server and I'm using Linux::stat to get the disk
IO for example.  I can seem to access the value of the hash reference(see
below).  Does anybody have any thoughts?  Is there a more generic mailing
list for the different perl modules?  I know there's the mod_perl thread but
its more for Apache.  Any help will be greatly appreciated.  Thanks!

use Data::VarPrint;
use Linux::stat;

my $stat = Linux::stat-new( [ stat = path to /proc/stat ] );
my $hashref = $stat-stat();

print $hashref{'disks'}={'io'};




--
This message is intended only for the personal and confidential use of the
designated recipient(s) named above.  If you are not the intended recipient
of
this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited.  This
communication is for information purposes only and should not be regarded as
an offer to sell or as a solicitation of an offer to buy any financial
product, an official confirmation of any transaction, or as an official
statement of Lehman Brothers.  Email transmission cannot be guaranteed to be
secure or error-free.  Therefore, we do not represent that this information
is
complete or accurate and it should not be relied upon as such.  All
information is subject to change without notice.


-- 
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: perl error

2003-09-09 Thread Hanson, Rob
I have no hard answers, but here are some suggestions from my admin...

I'd look to see which DBD connector he's trying to use.  He's also using a
multi-threaded perl which I believe is buggy under Solaris -- especially
perl 5.6.  I'd try re-compiling perl 5.8 and check that the DBD modules are
installed correctly.

Rob

-Original Message-
From: Sachin Mathur [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 09, 2003 1:10 AM
To: [EMAIL PROTECTED]
Subject: perl error


Hi , 
Please let me know if anyone  has a clue about this one.
 
 
 
error on running a perl script
 


  ld.so.1: perl: fatal: relocation error: file
/opt/perl/lib/site_perl/5.6.1/sun4-solaris-thread-multi//auto/DBI/DBI.so
: symbol Perl_Gthr_key_ptr: referenced symbol not found
Killed
 


 

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



RE: authenticate module

2003-09-08 Thread Hanson, Rob
No extra module is needed.  WWW::Mechanize is a subclass of LWP::UserAgent,
which supports it.

my $ua = new WWW::Mechanize();

$ua-credentials('www.myhostname.com:80', 'RealmName', 'user', 'pass');
$ua-get('http://www.myhostname.com');
print $ua-content;

The params are host/port, realm, username, password.

The realm should be visible in the login box (in IE6 it is).

See LWP::UserAgent for more info... although it doesn't say much about that
function.

Rob


-Original Message-
From: Raghupathy [mailto:[EMAIL PROTECTED]
Sent: Monday, September 08, 2003 5:44 PM
To: [EMAIL PROTECTED]
Subject: authenticate module


Hi,
   
  I like to use WWW::Mechanize to scrape a website.
However the website has a authentication page. Is
there a perl module I can use to perform the 
authentication ?

Thanks,
Raghu

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
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: REPOST - print c:\program files\*.*;

2003-09-05 Thread Hanson, Rob
Windows is a little weird here because of the way long filenames are
supported.  You need to use the short name of the directory, which is the
first 6 letters - a tilda - and a number (always 1, unless there multiple
files with the same first 6 chars).

This works for me:
print c:/progra~1/*.*;

Rob

-Original Message-
From: Robert Citek [mailto:[EMAIL PROTECTED]
Sent: Friday, September 05, 2003 8:24 PM
To: [EMAIL PROTECTED]
Subject: Re: REPOST - print c:\program files\*.*;



Hello Edward,

At 05:07 PM 9/5/2003 +0800, Edward Yang wrote:
The problem is I do not get correct result from the following code:
print c:\program files\*.*;
or
print c:\\program files\\*.*;

I don't use perl in Windows, but I can simulate a similar result on Linux
or Mac OS X:
  mkdir foo bar
  cd foo bar
  touch a b c
  cd ..
  perl -le 'print join(\n, foo bar/*);

I can get things to work by adding in two back slashes befor the space in
the name:
  perl -le 'print join(\n, foo\\ bar/*);

Perhaps this will work with Windows as well.

Regards,
- Robert


-- 
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: REPOST - print c:\program files\*.*;

2003-09-05 Thread Hanson, Rob
This also works and is more portable...

my $dir = 'C:/Program Files';
opendir DIR, $dir;
print map {$dir/$_} grep {/.+\..+/} readdir(DIR);
closedir DIR;

Rob


-Original Message-
From: Hanson, Rob 
Sent: Friday, September 05, 2003 8:38 PM
To: [EMAIL PROTECTED]
Subject: RE: REPOST - print c:\program files\*.*;


Windows is a little weird here because of the way long filenames are
supported.  You need to use the short name of the directory, which is the
first 6 letters - a tilda - and a number (always 1, unless there multiple
files with the same first 6 chars).

This works for me:
print c:/progra~1/*.*;

Rob

-Original Message-
From: Robert Citek [mailto:[EMAIL PROTECTED]
Sent: Friday, September 05, 2003 8:24 PM
To: [EMAIL PROTECTED]
Subject: Re: REPOST - print c:\program files\*.*;



Hello Edward,

At 05:07 PM 9/5/2003 +0800, Edward Yang wrote:
The problem is I do not get correct result from the following code:
print c:\program files\*.*;
or
print c:\\program files\\*.*;

I don't use perl in Windows, but I can simulate a similar result on Linux
or Mac OS X:
  mkdir foo bar
  cd foo bar
  touch a b c
  cd ..
  perl -le 'print join(\n, foo bar/*);

I can get things to work by adding in two back slashes befor the space in
the name:
  perl -le 'print join(\n, foo\\ bar/*);

Perhaps this will work with Windows as well.

Regards,
- Robert


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

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



RE: Stripping HTML from a text file.

2003-09-04 Thread Hanson, Rob
A simple regex will do the trick...

# untested
$text = ...;
$text =~ s|head.*?/head||s;

Or something more generic...

# untested
$tag = head;
$text =~ s|$tag[^]*?.*?/$tag||s;

This second one also allows for possible attributes in the start tag.  You
may need more than this if the HTML isn't well formed, or if there are extra
spaces in your tags.

If you want something for the command line you could do this...

(Note: for *nix, needs modification for Win [untested])
perl -e '$x=join(,);$x=~s|head.*?/head||s' myfile.html 
newfile.html

Rob


-Original Message-
From: Sara [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 03, 2003 6:32 AM
To: beginperl
Subject: Stripping HTML from a text file.


I have a couple of text files with html code in them.. e.g.

-- Text File --
html
head
titleThis is Test File/title
/head
body
font size=2 face=arialThis is the test file contentsbr
p
blah blah blah.
/body
/html

-

What I want to do is to remove/delete HTML code from the text file from a
certain tag upto certain tag.

For example; I want to delete the code completely that comes in between
head and /head (including any style tags and embedded javascripts etc)

Any ideas?

Thanks in advance.

Sara.

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



RE: Stripping HTML from a text file.

2003-09-04 Thread Hanson, Rob
 Or maybe I misunderstood the question

Or maybe I did :)

 HTML::TokeParser::Simple

I agree... but only if you are looking for a strong permanant solution.  The
regex way is good for quick and dirty HTML work.

Sara, if you need to keep the head tags, then you could use this modified
version...

# untested
$text = ...;
$text =~ s|(head).*?(/head)|$1$2|s;

...Or if you wanted to keep the title tag...

# untested
$text = ...;
$text =~ s|(head).*?title.*?/title.*?(/head)|$1$2$3|s;

Rob

-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 04, 2003 8:48 PM
To: 'Sara'
Cc: beginperl
Subject: Re: Stripping HTML from a text file.


Won't this remove *everything* between the given tags? Or maybe I 
misunderstood the question, I thought she wanted to remove the code 
from all of the contents between two tags?

Because of the complexity and variety of HTML code, the number of 
different tags, etc. I would suggest using an HTML parsing module for 
this task. HTML::TokeParser::Simple has worked very well for me in the 
past.  There are a number of examples available. If this is what you 
want and you get stuck on the module then come back with questions. 
There are also the base modules such as HTML::Parser, etc. that the one 
previously mentioned builds on, among others check CPAN.

http://danconia.org

Hanson, Rob wrote:
 A simple regex will do the trick...
 
 # untested
 $text = ...;
 $text =~ s|head.*?/head||s;
 
 Or something more generic...
 
 # untested
 $tag = head;
 $text =~ s|$tag[^]*?.*?/$tag||s;
 
 This second one also allows for possible attributes in the start tag.  You
 may need more than this if the HTML isn't well formed, or if there are
extra
 spaces in your tags.
 
 If you want something for the command line you could do this...
 
 (Note: for *nix, needs modification for Win [untested])
 perl -e '$x=join(,);$x=~s|head.*?/head||s' myfile.html 
 newfile.html
 
 Rob
 
 
 -Original Message-
 From: Sara [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, September 03, 2003 6:32 AM
 To: beginperl
 Subject: Stripping HTML from a text file.
 
 
 I have a couple of text files with html code in them.. e.g.
 
 -- Text File --
 html
 head
 titleThis is Test File/title
 /head
 body
 font size=2 face=arialThis is the test file contentsbr
 p
 blah blah blah.
 /body
 /html
 
 -
 
 What I want to do is to remove/delete HTML code from the text file from a
 certain tag upto certain tag.
 
 For example; I want to delete the code completely that comes in between
 head and /head (including any style tags and embedded javascripts etc)
 
 Any ideas?
 
 Thanks in advance.
 
 Sara.
 


-- 
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: WWW::Mechanize and Cookies

2003-09-04 Thread Hanson, Rob
mod_perl isn't a language, it is an application server.

If the question is Is it mod_perl safe?, then that is a different
question.  I would think they are, both are OOP, and there is no state that
I am aware of that is outside of the object properties.

Rob

-Original Message-
From: rkl [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 04, 2003 3:40 AM
To: perl
Subject: Re: WWW::Mechanize and Cookies


Hi all: 

Are these libs: WWW:: Mechanize and HTTP::Cookies in perl or mod_perl? 

 -rkl 

Pablo Fischer writes: 

 Hi! 
 
 Im creating an script that checks for broken links. Im using this modules:

 
 use WWW::Mechanize;
 use HTTP::Cookies; 
 
 What Im trying to do?, I need to login in a website (cause to check broken

 links I need to be loged).  
 
 I also checked the cookies once I've loged and they're created, however,
when 
 I try to entrer another website I cant cause the website shows me a pretty

 message: Not Authorized. 
 
 My Code:
 
 #El archivo en el que se guardan las cookies
 $cookies = /home/unmada/cookies.txt; 
 
 #El objeto que va a estar escuchando las cookies
 $cookie = HTTP::Cookies-new(
file = $cookies,
ignore_discard = 1,
autosave = 1);
 #$agent-cookie_jar($cookie); 
 
 #El objeto que va a hacerla de navegador
 my $agent = WWW::Mechanize-new(agent = 'Mozilla/5.0',
   debug = 1);
 #La direccin que se va a visitar (la primera)
 my $url = http://cursos.itesm.mx/webapps/login;; 
 
 #$agent-redirect_ok();
 #Decirle al navegador que las cookies van a ser guardadas en el objeto
cookie
 $agent-cookie_jar($cookie); 
 
 #Cargamos la pgina
 $agent-get($url);
 #Mostramos el titulo de la pgina
 print $agent-title(),\n;
 #Buscamos el formulario que tiene el nombre de 'login'
 $agent-form(login);
 #Llenamos el campo de user_id
 $agent-field(user_id, username);
 #Llenamos el campo de password
 $agent-field(password, password);
 #Le damos ENTER
 $agent-submit(); 
 
 Then to enter another website (in the same domain), I jsut: 
 
 $agent-get(otherurl_of_the_same_domain);
  
 
 Thanks!
 Pablo
 -- 
 Pablo Fischer Sandoval ([EMAIL PROTECTED])
 http://www.pablo.com.mx
 http://www.debianmexico.org
 GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
 Firma URL: http://www.pablo.com.mx/firmagpg.txt 
 
 -- 
 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]

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



RE: problems with installing CPAN modules

2003-09-02 Thread Hanson, Rob
If you are on Windows with AS-Perl, you should use there version of ReadKey.
I might be wrong, but I think that module includes some C code.  So unless
you have C++ and compiled Perl yourself, you want to use the AS version of
the module, which will be pre-compiled for you.

The AS module list for 5.6 is here:
http://ppm.activestate.com/PPMPackages/zips/6xx-builds-only/

You can use ppm to automate the installation (ppm install TermReadKey)
without downloading it... or download and read the README for a local
install.

 it says that there is not target file

Don't use make on Windows with AS-Perl, use nmake instead (the reason
for the error).  You can search Google for it, or maybe someone here has it
bookmarked.  It is available from MS's site, and also comes with their C++
(I think).

Rob


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 02, 2003 7:59 AM
To: Perl Beginners
Subject: problems with installing CPAN modules


I am on win2k, active perl 5.6.1 system.

I downloaded the ReadKey module, (all the packet of Term-Readkey-2-21)

I gave perl MakeFile.pl and i recieved writing MakeFile

then i set make, and it says that there is not target file





-- 
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: base domain parsing www.mydomain.com

2003-09-02 Thread Hanson, Rob
Something like this should work...

my $domain = 'www.station.fire.org';

if ($domain =~ /([^\.]+\.[^\.]+)$/) {
print $1\n;
}
else {
print Failed to find domain\n;
}

This is very lenient in the matching, so it should match all valid domain
names as well as a lot of invalid ones.  If there is the possibility of
invalid domain names (ie. this is not a domain.name) you will need
something stronger.

Rob

-Original Message-
From: perl [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 02, 2003 12:54 PM
To: [EMAIL PROTECTED]
Subject: base domain parsing www.mydomain.com


Please help me parse this www.mydomain.com to just mydomain.com 

Below are some scenarios in which all I want is the last two values, 
mydomain.com : 

mydomain.com = mydomain.com
www.yourdomain.com = yourdomain.com
www.station.fire.org = fire.org 

results in just the base domain. 

thanks 


-- 
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: exact string match?

2003-09-02 Thread Hanson, Rob
Use eq (as well as lt, gt, ne, ge, le, cmp) for string matching.  The
operators == (as well as , , !=, =, =, =) for numeric matching.
Perl will convert the values based on the operator used.

So with ==, like you are using, Perl converts both arguments to numbers
before comparing.

So this is what you want...

$mystr eq exactstr

Rob

-Original Message-
From: rkl [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 02, 2003 2:12 PM
To: perl
Subject: exact string match?


How to test for exact string match? 

this doesn't work: 

$mystr == exactstr 

thanks
 -rkl

-- 
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: :Mechanize and Cookies

2003-09-02 Thread Hanson, Rob
I run into this a lot.  There is JavaScript in the page, and you need to
emulate that in your script.

Look at the source HTML for the page.  It takes the password and look like
it Base 64 encodes the password, then sets a hidden form field named
encoded_pw to the value.  It then clears the password field before sending
the data.

You need to emulate this process in your script.  After that I would think
it would work.

Rob

-Original Message-
From: Pablo Fischer [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 02, 2003 5:17 PM
To: [EMAIL PROTECTED]
Subject: WWW::Mechanize and Cookies


Hi!

Im creating an script that checks for broken links. Im using this modules:

use WWW::Mechanize;
use HTTP::Cookies;

What Im trying to do?, I need to login in a website (cause to check broken 
links I need to be loged). 

I also checked the cookies once I've loged and they're created, however,
when 
I try to entrer another website I cant cause the website shows me a pretty 
message: Not Authorized.

My Code:

#El archivo en el que se guardan las cookies
$cookies = /home/unmada/cookies.txt;

#El objeto que va a estar escuchando las cookies
$cookie = HTTP::Cookies-new(
 file = $cookies,
 ignore_discard = 1,
 autosave = 1);
#$agent-cookie_jar($cookie);

#El objeto que va a hacerla de navegador
my $agent = WWW::Mechanize-new(agent = 'Mozilla/5.0',
debug = 1);
#La dirección que se va a visitar (la primera)
my $url = http://cursos.itesm.mx/webapps/login;;

#$agent-redirect_ok();
#Decirle al navegador que las cookies van a ser guardadas en el objeto
cookie
$agent-cookie_jar($cookie);

#Cargamos la página
$agent-get($url);
#Mostramos el titulo de la página
print $agent-title(),\n;
#Buscamos el formulario que tiene el nombre de 'login'
$agent-form(login);
#Llenamos el campo de user_id
$agent-field(user_id, username);
#Llenamos el campo de password
$agent-field(password, password);
#Le damos ENTER
$agent-submit();

Then to enter another website (in the same domain), I jsut:

$agent-get(otherurl_of_the_same_domain);


Thanks!
Pablo
-- 
Pablo Fischer Sandoval ([EMAIL PROTECTED])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

-- 
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: system call

2003-08-29 Thread Hanson, Rob
Use backticks.

$result = `some command`;

system() on the other hand returns the exit status code.

$exit_code = system('some command');

...Or...

if (system('some command') != 0) {
  print Failed!;
}

Rob 


-Original Message-
From: Imtiaz Ahmad [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 28, 2003 4:48 PM
To: [EMAIL PROTECTED]
Subject: system call


Hi-

Can someone please tell me how do I modify following line so that the result
gets stored in the var.


$count = system($command $archive_dir | $grep_command -c $string1) ;


thanks.

-- 
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: how to return all rows selected in subroutine?

2003-08-29 Thread Hanson, Rob
I'll skip over most of your mail, and go right to the heart of the matter...

 I am trying to return an array of 
 all records in the subroutine below.

#
# ...WARNING: UNTESTED CODE AHEAD...
#

sub getcols {
  # I prefer this over the ($table) syntax...
  # but it has the same end result
  my $table = shift;

  # this is the array or rows returned.
  my @return_rows;

  # never use Perl variables in your queries, it
  # opens you up to SQL Injection attacks.
  # Do a query on Google for more info about
  # what this is.
  my $sql = 'select column_name, nullable,
column_id, data_type
 from all_tab_columns
 where lower(table_name) = ?
   and column_id  0';

  # prepare with the placeholder, and pass
  # $table in the execute() statement.
  my $sth = $dbh-prepare($sql);
  $sth-execute($table);

  # this loops over each record returned,
  # and pushes a REFERENCE to the array on
  # to the result array.  This is essentially
  # a multi-dimentional array if you do not
  # understand referenced.
  while (my @row = $sth-fetchrow_array()) {
push @return_rows, [EMAIL PROTECTED];
  }

  return @return_rows;
);


# call the method like so...
my @records = getcold('my_table_name);

# print first record, first field
# (the column_name column).  the array
# is zero-based, so [0] is the first item.
print $records[0][0];

# print second record, fourth field
print $records[1][3];

...etc...

See Also:
  perldoc perllol
  perldoc perlreftut


Rob



-Original Message-
From: Johnson, Shaunn [mailto:[EMAIL PROTECTED]
Sent: Friday, August 29, 2003 4:14 PM
To: [EMAIL PROTECTED]
Subject: how to return all rows selected in subroutine?


Howdy:

I am trying to return an array of 
all records in the subroutine below.

I want to hold all of that info
in one location so that I can use
it (each row and each column of said
row) later in a program.

In the $sql part, I had the 'selectrow_array';
as was noted to me in another email, it returns
ONE row in the array.  But I want to select
ALL of the rows in the query.  So, I got rid
of that and just set up the sql/prepare/execute
part.

According to the DBI book, fetchall_arrayref
can be used to fetch all the data to be returned.
So I thought I could just:

*do my query
*prep and check the query
*execute
*create an empty array
*push each row returned from fetchall_array in 
 to the array
*call the sub routine and do something silly
 like get the 2nd records and 3rd column and
 use it

[snippet of my broken code]

sub getcols {
my ($table)[EMAIL PROTECTED];
my $sql=q(
select
column_name,
nullable,
column_id,
data_type
from
all_tab_columns
where
lower(table_name)='$table'
and
column_id  0
);

my $sth=$dbh-prepare($sql);
sth-execute();

my @rows;

while (my ($col_name, $nullable, $col_id,
$data_type)=$sql-fetchrow_array()) {
push (@rows, $sql);
}

[/snippet of my broken code]


On the other hand, there is a program that I am
trying to imitate that DOES this very thing:

[snip of working code]

sub getcols {
my($table)[EMAIL PROTECTED];
return doquery('find rows',
SELECT   a1.attname, a1.attnotnull, a1.attnum, t.typname, 
a1.attlen, a1.atttypmod, c1.relkind
FROM pg_class c1,
 pg_attribute a1,
 pg_type t
WHEREc1.relname='$table'
 and a1.attnum  0
 and a1.attrelid = c1.oid
 and a1.atttypid = t.oid
ORDER BY upper(attname);
);

}
#--- GET THE TARGET TABLE'S VARIABLES
$target=getcols($opt_t);
if ( $target-ntuples==0 ) {
print STDERR Target table $opt_t not found\n;
exit 1;
}

print resultstatus=.$result_error{$target-resultStatus}.\n.
n= .$target-ntuples.\n if $debug;

#--- DOES THE SOURCE HAVE THE NECESSARY VARS?
while ( @trow=$target-fetchrow ) {
print -- $trow[0]\n if $debug;
$view=1 if $srow[6] eq 'v';
if ($trow[0] eq 'user') {
$cols[$trow[2]-1]=q!'ADMIN'!;
}
elsif ($trow[0] eq 'updated') {
$cols[$trow[2]-1]=q!'now'::datetime!;
 $cols[$trow[2]-1]=q!'now'::datetime!;
}
else {
print whatever\n;
}
[/snip of working code]

I know this is getting tired, but I would appreciate it
if someone could tell me why the 'broken code' will only
pull back one row and not hold anything into an array to
be used later.

TIA!

-X

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



RE: Managing Pictures with Perl

2003-08-29 Thread Hanson, Rob
 What is the best library to handle pictures?

Image::Magick is a great tool for creating thumbnails, it is both easy and
the shrunk images still look good.

http://search.cpan.org/author/JCRISTY/PerlMagick-5.57/Magick.pm

If you are running the ActiveState version of Perl, be sure to get it from
there instead of CPAN.  You can install this with ActiveState Perl by
running ppm install Image-Magick at the command line.

For HTML creation you might find it easier to use templates, and have your
Perl program just fill in the blanks.  The are some complex kits out there,
so you might want to try HTML::Template first, it is very easy to use.

http://search.cpan.org/author/SAMTREGAR/HTML-Template-2.6/Template.pm

 What resources from Perl do you suggest I to use?

It depends.  If you are comfortable with manpages, then check out the
documentation that comes with Perl.  If not, pick up a copy of Learning Perl
published by O'Reilly  Assoc.

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

...Or Learning Perl on Win32 if you are running it on Windows.

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

Once you start getting into Perl and need to explore more complex topics,
check out their other specialized Perl books... they have lots.

http://perl.oreilly.com/

Rob



-Original Message-
From: Geraldo Milagre [mailto:[EMAIL PROTECTED]
Sent: Friday, August 29, 2003 5:19 PM
To: [EMAIL PROTECTED]
Subject: Managing Pictures with Perl


Hi,

I would like to write a program to manage my pictures colection and 
generate statics html pages for view the pics. I would like to use Perl 
to do this, as a way to learning more about the language. What resources 
from Perl do you suggest I to use? What is the best library to handle 
pictures?

Thanks a lot.

-- 
Geraldo Milagre
[EMAIL PROTECTED]
(19)9121-0704
(19)3236-1305



-- 
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: grep with ftp

2003-08-28 Thread Hanson, Rob
 Is this possible?

I'm no expert of FTP software, so I can't say if that is generally possible,
but it will depend on what the FTP server software allows you to do.  So I
would start there, find out what software they are running, then find some
documentation on it.

Rob

-Original Message-
From: Johnson, Shaunn [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 28, 2003 10:34 AM
To: [EMAIL PROTECTED]
Subject: grep with ftp


Howdy:

I'm looking for information that will let me 
open an ftp connection and grep / search 
for files and then FTP them back to me.

I saw something about FTP and macros, but
the other articles about Net::FTP got me to
believe you can do this with Perl.  If so,
is Net::FTP the route the go?

Is this possible?

Thanks!

-X

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



RE: How to cate DBI error and pass the control to subroutine?

2003-08-27 Thread Hanson, Rob
Take a look at the Error module (although you can use eval as well).

use DBI;
use Error qw(:try);

my $dbh = DBI-connect(...);
$dbh-{RaiseError} = 1;

try {
  $dbh-do(insert ...);
}
catch Error with {
  print STDERR Insert failed!;
}

$dbh-do(update ...);


...Or if you only want to update when the insert fails, then put the insert
in the catch block.

Rob


-Original Message-
From: Titu Kim [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 27, 2003 2:37 PM
To: [EMAIL PROTECTED]
Subject: How to cate DBI error and pass the control to subroutine?


Hi, 
   I am using DBI and DBD to insert into database. If
the insert fails because of the key constraints, I
want to continue to update that record. How can I it
do this after I issue $sth-execute() statement?


Thanks.

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
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: Simulating VB Enum

2003-08-27 Thread Hanson, Rob
Remember these 3 words... search.cpan.org ;)

http://search.cpan.org/search?query=enummode=all

CPAN is always the best place to start looking for code.

On the results page is looks like enum will do what you need.

Rob


-Original Message-
From: Harter, Douglas [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 27, 2003 3:36 PM
To: Beginners Mailing List Perl (E-mail)
Subject: Simulating VB Enum


Visual Basic has a construct called Enum which looks like so:

Enum namea
dhbold
dhcaption
dhend
dhform
.
end enum

What it essentially does is assign an incrementing numeric value to each
variable in the enum, so that 
dhbold = 1
dhcaption = 2
dhend = 3
dh form = 4
etc.

Is there a way to do the same thing easily in Perl?


.

-- 
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: Length() is bits/bytes or neither

2003-08-26 Thread Hanson, Rob
length() returns the length in characters, which for ASCII is also the
number of bytes.  To get the bits, just multiply by 8.

If you are using a Unicode character set instead, I'm not too sure what will
be returned, or how you can convert it to bits.

Rob

-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 26, 2003 11:30 AM
To: [EMAIL PROTECTED]
Subject: Length() is bits/bytes or neither


I know that the number returned by the length function is the number of
characters.
With ascii text is that the bits or bytes also?

If not is there a function similar to length() that tells you the bits or
bytes of a string or a way to figure that with the return value of length?

TIA

Dan

-- 
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: Perl Codes Written in Windows Env

2003-08-25 Thread Hanson, Rob
 If you ftp them in binary mode instead of
 ascii mode yes that will screw it up.

I wanted to elaborate on this since this is a common issue for the
unknowing.

When you tell FTP to use binary mode it doesn't modify the file, it just
copies it byte by byte.  If you tell it to use ascii mode, then it will
adjust the line endings depending on the source and destination systems.

When you FTP a text file (including code) between different environments be
sure to use ascii mode as it will convert the line endings as appropriate.

In general I don't think Perl cares about line endings too much, I think it
can handle most of them (I may be wrong).  ...The root of the problem  is
the sh'bang line.  Unix uses the sh'bang to determine where the Perl binary
is, and Unix (not Perl) can't understand the carriage-return character.

In general I don't think this is an issue if you go from Unix to Windows.
Since Windows generally uses the file extension to determine what kind of
app it is, and doesn't actually need to peek at the file like Unix does.

Rob


-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED]
Sent: Monday, August 25, 2003 4:46 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Perl Codes Written in Windows Env


 I have a perl script that I developped in a windows machine 
 and it had to be 
 transfered by ftp to a UNIX server. The codes worked fine 
 when I tested them on 
 my windows machine. Is it true that the data could get 
 corrupted while being 
 ftp'ed from Windows to Unix. I was told by the Unix people 

If you ftp them in binary mode instead of ascii mode yes that will screw it
up.

 that they couldn't 
 get the code to work at first because the codes were 
 developped in windows 

What do you mean by didn't work. They failed completely, output not as
expected, ...
What modules did you use? Are those installed on the unix host?
What errors are you getting? To the screen or a log of some kind?

 environment. Codes are working now though. Just being curious.

-- 
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: FILEHANDLE to print to nothing

2003-08-25 Thread Hanson, Rob
Sure, just use this without an open or close statement...

print VOID 'test';

I'm not exactly sure how Perl handles this, but since there is no filehandle
called VOID is just goes away.

I wouldn't leave this in there when it goes into production, but it
shouldn't cause any problems during testing.

Rob

-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED]
Sent: Monday, August 25, 2003 5:24 PM
To: [EMAIL PROTECTED]
Subject: FILEHANDLE to print to nothing


Howdy,

I am benchmarking some stuff that does multiple print staements.

What I'd like to do is print to a file handel so ethat the stuff I'm
printing doesn't go to the screen.

Ie instead of print stuff;
print BITBUCKET stuff;

That way the output of the benchmark test won't be screwy on the terminal or
cause 500 errors if someone runs this test before an html header gets
printed.

Any ideas of how to create a filehandle to the void?

open(VOID,'');
print VOID 'test';
close VOID;

TIA

Dan

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



  1   2   >