Re: Copyright

2001-06-15 Thread Andrew

Brian,

Even though this may be off-topic, I have to take you to task on this
comment:

>Unfortunately, foreign nationals do not have respect for the rights of
>American created property.

>It is a problem running rampant. We have had foreign nationals pirate our
>code and ideas along with the books whose copyrights are ignored.

This is a typical US-centric view of the problem.

These people have no respect for *anyone's* copyright, not just those
from the US.
They will just as happily violate copyright from their own country,
Britain, Australia
or anywhere else.

It is not an issue of stealing *American* property at all.  It's just
stealing of property, full stop.

And secondly, there's no piracy of American (or other nations !)code,
software, books, music or any other copyrighted material done by US
nationals ?

Gimme a break.

I'm not belittling the concerns you have by any means, but to take the
view that it's a problem restricted to 
"foreign nationals" not respecting "American created property"
denigrates those of us who live outside the US.

It also ignores the fact that it's just as likely that some US national
will pirate an idea, code or whatever which is copyright in say,
England.  Or is it OK for the US to steal property of other nations ?

The US is not the sole repository of good and worthwhile ideas.

Now, I'll get off my soapbox and go back to lurking on this very
informative list !

Andrew
(An Australian)



Cookie and redirecting.

2001-09-26 Thread Andrew

Dear Folks,

I am currently working on cookies for tesing out.
Although a lot of people had disabled the function on
their browsers, I would just like to try it.

I got few knotty problems :

1) I could set the cookie's parameters and
retrieve it. But how I can make use of the returned
parameters to realise the concept of cookie.

2) Upon detecting that the cookie is not valid
using if statement, I would like to use the command in
the CGI script to immediate load another URL page. I
had tried the redirect command for cookie but could
not help.

E.g. if ($cookieID eq '12345') {
 
 #load new web page.

 }

Thanks,
Andrew



Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

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




Re: Cookie and redirecting.

2001-09-27 Thread Andrew

Thanks pal, you are great. I will try out. 
Cheers, Andrew 

-- Sawsan Sarandah <[EMAIL PROTECTED]> wrote: > Hi
Andrew,
> I've been working on a similar question recently.
> Try to set the cookie and
> then redirect back into the same script. When
> setting the cookie, also place
> a temporary value in the CGI environment. When the
> script is activated the
> second time around, the presence of the temporary
> CGI value indicates our
> attempt to set a cookie. If there is no cookie and
> the temporary value
> exists, it basically means that the remote browser
> is not accepting our
> cookie. BTW, I gained a lot of insight regarding
> this issue by reading a
> Randal Schwartz tutorial at the following URL:
> 
>
>
http://www.stonehenge.com/merlyn/WebTechniques/col61.html
> 
> and I know that the author frequently hovers around
> this newsgroup so I just
> want to say thank you Randal for your excellent
> articles.
> 
> Ibrahim Dawud
> 
> 
> 
> 
> Here is a sample of my code which is based on that
> tutorial:
> 
> my $visitor_cookie =
> $cgi->cookie(-name=>'site-visitor');
> my $visitor_param  = $cgi->param ("site-visitor");
> 
> if (!defined $visitor_cookie){
> if (!defined $visitor_param){
> # Try to start a new session by setting a
> "site-visitor"
> # cookie. If that fails, place the session
> in the CGI environment.
> $visitor_cookie = $cgi->cookie
>  -name=>"site-visitor",-value=>"value");
> if (!defined $cgi->param("cookietemp")) {
> # Try to create a "site-visitor" cookie
> for the first time.
> # Exit the script using redirect and
> come back to check if it is
> there.
> # Set a temporary value in the CGI
> environment.
> $cgi->param("cookietemp",1);
> print $cgi->redirect(-cookie=>
> $visitor_cookie, -uri=>
> $cgi->self_url());
> }
> else {
> # We know if we are here that we failed
> to create a
> "site-visitor"
> # cookie the first time we ran this
> script. Place the session
> data
> # in the CGI environment instead.
> $cgi->param("site-visitor","value");
> print $cgi->redirect(-uri=>
> $cgi->self_url());
> }
> }
> else {
> # Basically, the previous session was passed
> via CGI. It is
> # reasonable to continue using CGI to pass
> along session data. This
> # means making sure that all links and
> hidden fields have a
> # unique identifier embedded in them to pass
> on.
> if (!defined $cgi->param("cookietemp")) {
> # subsequent times using CGI
> }
> else {
> # first time using CGI
> $cgi->delete("cookietemp");
> print $cgi->redirect(-uri=>
> $cgi->self_url());
> }
> }
> else {
> # previous session was passed via a cookie.
> Question: Is it necessary
> # to also check CGI parameters at this point?
> Probably not since
> # we have assumed cookies as the primary method
> for passing session
> # data.
> if (!defined $cgi->param("cookietemp")) {
> # subsequent times using cookies
> }
> else {
> # first time using cookies
> $cgi->delete("cookietemp");
> print $cgi->redirect(-uri=>
> $cgi->self_url());
> }
> }
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> - Original Message -
> From: "Andrew" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, September 27, 2001 4:27 AM
> Subject: Cookie and redirecting.
> 
> 
> > Dear Folks,
> >
> > I am currently working on cookies for tesing
> out.
> > Although a lot of people had disabled the function
> on
> > their browsers, I would just like to try it.
> >
> > I got few knotty problems :
> >
> > 1) I could set the cookie's parameters and
> > retrieve it. But how I can make use of the
> returned
> > parameters to realise the concept of cookie.
> >
> > 2) Upon detecting that the cookie is not valid
> > using if statement, I would like to use the
> command in
> > the CGI script to immediate load another URL page.
> I
> > had tried the redirect command for cookie but
> could
> > not help.
&g

Login Screen

2001-09-27 Thread Andrew

Dear all,

   1) Any body knows to go about creating login screen
program for perl. 

   2) The good websites about this.


Thanks,
Andrew 




Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

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




Re: CGI script to change user's password, and login.

2001-10-02 Thread Andrew

Dear Wee Keong,

I had written something for Perl on windows for
login, password.

login.cgi will call check.cgi and check.cgi will
call password.cgi. a bit messy. but you can try to
use. The scripts will create html. it is not from
apache.
 
To prompt users in from apache, you have to set
the private_groups and private users, also set the
httpd.conf files. this is some thing I know. there
should be more ref.


Thanks and cheers,
Andrew 

 --- Tan Wee Keong <[EMAIL PROTECTED]> wrote: > Hi,
> 
> Recently I've received a task to write a script
> (CGI) to allow changing 
> of user password on a web page. Basically I'm very
> new to CGIs and is 
> facing a tremendous problem starting this task.
> 
> Basically, the script is supposed to run on Apache
> (ran as "nobody") and 
> allow users to change their system password via web
> interface. I'm not 
> too sure whether it can be done this way or is it
> right to be done this 
> way. Therefore I seek help from here to reach a
> conclusion.
> 
> Can any gurus advise me?
> 
> WK
> 
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>  


Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie
 login.cgi
 password.cgi
 check.cgi

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


Revolution of Perl

2001-11-09 Thread Andrew

Hey Gentlemen,

   Can anybody tell me if wrting Perl can be as
easy as writing a simple story.

  It would be good If we can discard away all the
syntaxes, expecially. It can even be OO based to
compete with Java, C++.


Cheers,
Andrew

  

__
Do You Yahoo!?
Everything you'll ever need on one web page from News and Sport to Email and Music 
Charts
http://uk.my.yahoo.com

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




How to evolve Perl to ignore syntax and can just write a story to finish the program.

2001-11-15 Thread Andrew

 Thanks,
Andrew

__
Do You Yahoo!?
Everything you'll ever need on one web page from News and Sport to Email and Music 
Charts
http://uk.my.yahoo.com

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




test

2001-11-15 Thread Andrew

 
 

__
Do You Yahoo!?
Everything you'll ever need on one web page from News and Sport to Email and Music 
Charts
http://uk.my.yahoo.com

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




Greedy v non greedy regexps in lookahead.

2008-11-23 Thread Andrew

I am tying to expand some camel case with spaces - but I want multiple 
captitals to remain as one word. So
I want  "PerlNotesOnXML" -> "Perl Notes On XML"

My attempt is to use [A-Z]+ in a lookahead.

  my $text = "PerlNotesOnXML" ;
  $text =~ s/(?=[A-Z]+)/ /gx ;
  print $text ;

I think I can see what is happening - [A-Z]+ matches XML then ML then L.
Is there a way of preventing it looking XML more than once.


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




Re: Greedy v non greedy regexps in lookahead.

2008-11-23 Thread Andrew
Thanks 

"Mr. Shawn H. Corey" <[EMAIL PROTECTED]> wrote in 
news:[EMAIL PROTECTED]:

> How would it parse "XMLSchema" ?  You need to write down the rules
> before you try creating than regex for them.  Try:
> 
Ok - I am a typical customer - my stated requirement isn't quite my real 
requirement :-)  In my defence I was solving a one off problem and this 
case didn't come up.

I agree that looking at the definition of a _word_ is better than looking 
at what divides words.

"Dr.Ruud" <[EMAIL PROTECTED]> wrote in 
news:[EMAIL PROTECTED]:

>   s/(?<=[a-z])(?=[A-Z])/ /g

This one most closely meets my stated requirements.
I was trying to avoid repeating "$1 $2" in the replacesment hence why I 
prefered a lookahead/ behind

Thanks John and Rob for other suggestions.



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




Non interactive interaction

2013-02-28 Thread Andrew

I'm a brand newbie to cpan and relatively inexperienced with perl.  I was given 
some cpan commands to follow for a third
party application I'm trying to install/build, but I want to script (bash) 
these commands as chances are I'll be
reinstalling a bunch of times after I screw it up.

The module installs are easy (cpan modulename).  However, I need to do "o conf 
commit" and
possibly other somewhat similar commands.  I can't find anything that 
explicitly explains how.

My investigations reveal that it may be the case that I can use YAML, 
autocommit, expect and/or mkmyconfig to accomplish
this task, but I'm in way over my head.  I didn't want this to be a major 
project, I just wanted to automate
the installation of a few modules and whatnot so I can move on with my life.  
This is for a personal Linux (Ubuntu)machine
so yes I'm root & I want to do this on a system wide basis.

Any help?

Thank you in advance


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




Re: cannot install modules

2016-12-22 Thread Andrew

Not sure but check out  or install libssl-dev ( root privs required )

22.12.2016 16:56, Luca Ferrari пишет:

Hi all,
running perl 5.25.8 on kubuntu 16.10 via perlbrew I try to install
Net::SCP but got this strange stuff:

% cpanm Net::SCP
...
Successfully installed Net-SSH-0.09
...
Successfully installed String-ShellQuote-1.04
! Installing the dependencies failed: Module 'String::ShellQuote' is
not installed, Module 'Net::SSH' is not installed
! Bailing out the installation for Net-SCP-0.08.
2 distributions installed

so it seems that Net::SSH and String::ShellQuote are installed but not
installed, uh?
Even trying to install the dependencies manually provides an OK on
installation but then Net::SCP fails with the same message.
What am I missing here?

Luca




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




Re: cannot install modules

2016-12-22 Thread Andrew

https://srcc.stanford.edu/farmshare2/software-perlbrew

22.12.2016 17:24, Andrew пишет:

Check also this article ( nearing the issue I guess )

22.12.2016 17:13, Andrew пишет:

Not sure but check out  or install libssl-dev ( root privs required )

22.12.2016 16:56, Luca Ferrari пишет:

Hi all,
running perl 5.25.8 on kubuntu 16.10 via perlbrew I try to install
Net::SCP but got this strange stuff:

% cpanm Net::SCP
...
Successfully installed Net-SSH-0.09
...
Successfully installed String-ShellQuote-1.04
! Installing the dependencies failed: Module 'String::ShellQuote' is
not installed, Module 'Net::SSH' is not installed
! Bailing out the installation for Net-SCP-0.08.
2 distributions installed

so it seems that Net::SSH and String::ShellQuote are installed but not
installed, uh?
Even trying to install the dependencies manually provides an OK on
installation but then Net::SCP fails with the same message.
What am I missing here?

Luca








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




Re: cannot install modules

2016-12-22 Thread Andrew

Check also this article ( nearing the issue I guess )

22.12.2016 17:13, Andrew пишет:

Not sure but check out  or install libssl-dev ( root privs required )

22.12.2016 16:56, Luca Ferrari пишет:

Hi all,
running perl 5.25.8 on kubuntu 16.10 via perlbrew I try to install
Net::SCP but got this strange stuff:

% cpanm Net::SCP
...
Successfully installed Net-SSH-0.09
...
Successfully installed String-ShellQuote-1.04
! Installing the dependencies failed: Module 'String::ShellQuote' is
not installed, Module 'Net::SSH' is not installed
! Bailing out the installation for Net-SCP-0.08.
2 distributions installed

so it seems that Net::SSH and String::ShellQuote are installed but not
installed, uh?
Even trying to install the dependencies manually provides an OK on
installation but then Net::SCP fails with the same message.
What am I missing here?

Luca






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




RE: the ENV command? parameter?

2001-06-07 Thread Andrew Nelson

Ok, assuming you're working on some type of unix or unix clone, and this is
not CGI(as I've not done this elsewhere, and haven't written CGI)

$ENV refers to the environment of the current shell - for instance, if you
use bash, the results of typing "set" on the command line. For tcsh, it's
setenv, etc etc.

>From the shell, try "echo $QUERY_STRING" and see if anything pops up. If it
does, then that's what the variable is set to. If nothing does, then it's
not set. And in that case, I've no idea what it could be, as that will
depend on the context it's used in.

Environment variables in the shell are a way fo keeping things persistent
across multiple tasks. it's not particularly portable, however, so unless
there's a reason you need to do things that way, it's generally not the best
idea.

(note: CGI might do something completely different with it. As I said, it's
dependent entirely on context.

Your mileage may vary.

hope that helps,
Andrew Nelson

-Original Message-
From: Bradshaw, Brian [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 07, 2001 10:53 AM
To: [EMAIL PROTECTED]
Subject: the ENV command? parameter?


Hi list. 

I am trying to learn PERL and decipher some code somone else wrote. I have
the code snip -- $ENV{'QUERY_STRING'} --
I have not found this in the archives, so I am hoping someone will answer
this:

I cannot figure out exaclty what the ENV is.The book says it contains the
current environment. OK, but what is in this environment. I can't find info
what the environment consists of. What does the 'Query_String' mean?

Please help me out? Thanks in advance.

Brian Bradshaw
Systems Engineer
McGraw-Hill Education
McGraw-Hill Companies
860-409-2603
[EMAIL PROTECTED]




RE: directory listing to array

2001-06-07 Thread Andrew Nelson


# begin cheap non portable hack

$list = `/bin/ls -1 *.jpg`;
@array = split(/\n/, $list);

# end cheap non portable hack

# try this a little cleaner

opendir(DIR, ".");
@dir_entries = readdir(DIR);
closedir(DIR);

foreach (@dir_entries)
{
   next if(!/\.jpg/);
   push(@arr, $_);
}

#end attempt at decent code

Probably not the best way. I'm still a newbie hack somedays myself. But this
should work :)

-=- 
G. Andrew Nelson
Release Engineer
Storigen Systems, Inc.
650 Suffolk Street
Lowell MA 01854
+1 978 323 4454 x271


-Original Message-
From: Evan McNabb [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 07, 2001 12:17 PM
To: [EMAIL PROTECTED]
Subject: directory listing to array



I've been working on a little script for a while but I can't seem to get
this part working. What I want to do is list all of the *.jpg files in a
directory (ls *.jpg) and then have an array with each filename as elements
of that array. Its probably easy but I just can't get it right  yet... :-) 
Thanks for the help.

-Evan


  Evan McNabb [EMAIL PROTECTED]
http://www.mcnabbs.org/evan




RE: Problem with getting a file to open

2001-06-07 Thread Andrew Nelson

You can open a file via open() for reading or writing, but not both. Try

open (FILE, $file);
print FILE;
close(FILE);

And see if that doesnt help.

-Original Message-
From: Sara Campbell Meeks [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 07, 2001 12:39 PM
To: '[EMAIL PROTECTED]'
Subject: Problem with getting a file to open


I have this bit of code:

#!/usr/bin/perl -w

$edgar = "/home/Campbell/perl/edgar"

opendir (EDGAR, $edgar) or die "Can't find $edgar!\n";

while ($file = readdir EDGAR) {
open (FILE, ">$file");
print FILE;
}


When I run the program I get this error message:

Use of uninitialized value in print at /home/Campbell/perl/Get.Info line 9

If I change the open line to say

open (FILE, "<$file");

I get this error message:

Filehandle main::FILE opened only for input at /home/Campbell/perl/Get.Info
line 9

I don't understand why it recognizes the file handle in one case and not in
the other, and I don't have the first clue how to fix it.  Help?  I'm using
perl 5.6.0 on a RedHat 7.1 machine if it means anything.

Thanks,
Campbell



RE: Special Variable for name of the running script

2001-06-14 Thread Andrew Nelson

Sure. Try $0. :)

-Original Message-
From: Charles Lu [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 15, 2001 2:31 AM
To: [EMAIL PROTECTED]
Subject: Special Variable for name of the running script


When you run a perl script from command line, you can often retrieve the 
arguments through the special variable @ARGV.

If you type the following:

perl myscript.pl input.txt output.txt

on a commandline, the value of $ARGV[0] will be input.txt,
$ARGV[1] will be output.txt.


My question is is there perl special variable that stores the name of the 
actualy script that is running?  In other words, which variable, if any 
holds the value "myscript.pl"?

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



Net::FTP

2001-07-23 Thread Hinkle, Andrew

I am using the Net::FTP module in Perl to automate transferring datafiles
between one of my Unix servers and a mainframe.  I have the connection going
and in general, can transfer files without problems.  

However, I've been told that as part of the file transfer, I have to issue a
mainframe specific command (there is no method in Net::FTP that corresponds
with this command).  The command I need to issue is "quote site lrecl=827
recfm=fb blksize=27291 cylinder primary=1 secondary=1".  

I have tried to use the "quot" method.  It goes something like this
$ftp->quot("quote site lrecl=827 recfm=fb blksize=27291 cylinder primary=1
secondary=1");

The script runs the whole way through but apparently does not evaluate this
line.  I don't get any kind of error but when our mainframe programmer looks
at the mainframe, she says that that command did not work.  If I step
through the ftp process on that command line, that command works like it is
supposed to.

Any ideas?

Andrew Hinkle
Unix Systems Administrator
CA Secretary of State's Office
916.653.2320
[EMAIL PROTECTED]

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




DBI tutorial

2001-04-29 Thread Andrew Teo

Hi all,
I am interested in self-learning the DBI module for database
manipulation. Are there any good online tutorials available?

Thanks,
Andrew



Re: Got a project for Perl but need some help

2001-04-30 Thread Andrew Teo

Just curious, how would you send an attachment?


Johnathan Kupferer wrote:
> 
> Aww... you should have let him hire a consultant.  ;o)
> 
> Seriously though, this is dead simple.  Gary's code is great and robust
> if a bit intimidating for a newbie.  You said you have background in
> VisualBasic and that would lead me to think you might be using windoze
> NT or 2000.  (Unfortunately, so am I).  If this is the case, you
> probably don't have access to sendmail, in which case I suggest you take
> a look at the Mail::Sendmail module.  The only info you need to
> configure it is an SMTP server.  (If you are using win32 and
> ActiveState, this can be found using ppm).  Lots of people also use a
> program called Blat, but I don't like it because it forces you to write
> a file to disk first...
> 
> To get the form info:
> 
> use CGI;
> my $cgi = new CGI;
> 
> #
> # $cgi->param returns a list of the fields in the form when not
> # given any arguments.  Passed a field name, it returns the value.
> # I'm not sure how you mean tab delimited, so I'll leave that to
> # you...
> #
> for my $field ($cgi->param){
>$message .= "$field = ".$cgi->param($field)."\n";
> }
> 
> #
> # Now just send it!
> #
> use Mail::Sendmail;
> sendmail (
>To => $email_to,
>From   => '[EMAIL PROTECTED]',
>Subject=> "Email Subject"
>Message=> $message
> );
> 
> With that said, I hope you see that this is really quite simple.  Gary's
> code takes into account alot of details like what to do if we don't know
> what mail program to use and giving a response back to whoever submitted
> the form which is generally a good idea so you should definitely follow
> his lead even if you're not on Unix.
> 
> As for publicly available base code...  I don't know.  This is actually
> a bit too simple to expect to find base code, but you never know.  But
> hey!  We're the public and here's a bunch of code!
> 
> Good Luck,
> 
> - Johnathan



Re: regexp trouble

2001-05-07 Thread Andrew Teo

try this : 
$tmp =~ tr/a/ /;


Johan Groth wrote:
> 
> Hi,
> I want to strip a variable of all characters including a token, i.e.
> aaa_bbb_ccc_ddd would become bbb_ccc_ddd.  As you can see I want to get rid of
> aaa_. Does anyone know how to acomplish this in Perl?
> 
> I've tried:
> $tmp = "aaa_bbb_ccc_ddd"
> $tmp =~ /^\w+_/
> $tmp = $';
> 
> but that results in $tmp eq "ddd" instead of "bbb_ccc_ddd".
> 
> /Johan
> 
> --
> Johan Groth (xghjn) ! Tel. mobil: 0703 - 24 25 27
> Cell Network!   Kontoret:  054 - 14 25 27
> [EMAIL PROTECTED] ! Bofors: 0586 - 820 14
> [EMAIL PROTECTED]



RE: create a new file

2001-06-01 Thread Andrew Prueser

open(FILEHANDLE, ">filename")

the '>' indicates open for append, or create if doesn't exist.

checkout 'perldoc -f open' for all the fun things you can do with open.

Andrew 

-Original Message-
From: Nichole Bialczyk [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 01, 2001 12:10 PM
To: [EMAIL PROTECTED]
Subject: create a new file


ok, so i know how to write to an existing file, how do i create the file, 
if it doesn't exist? i want to do something like, 

pseudocode -- ewww!
if the file exists{
 write to it
}

if the file does not exist{
 create it
 write to it
}

close the file
 




gettin awk output from obj.conf files.

2001-06-06 Thread Andrew Roberts

Below is a script that I can't get to work as a Korn shell script. I
would like to get something like it to run in perl. 

What I am attempting to do is search thru all of the websites on my
server and make a file that tells me what websites reside in what
directory. 

I can get the first part of the script to work but I can't get the file
cleanup to look nice. 

I bet this is really simple. 

Thanks Everyone,

Andy



Sample of current output
---
pwh4
/$PATH?www/ns-admin-new/https-brands-misc/config
05Jun-04:41PM






What I used to get current output
-
# Setup environment variables
#
BOXNAME=`hostname`
CURDATE=`date +%d%h-%I:%M%p`
WORKINGDIR=`pwd`
NSWEB=`ls -d $PATH/www/ns-admin*/https*/config/`
FILENAME=found_hosts_`date +%d%h-%I:%M%p`
#
# Main processing
#
# Read all webserver obj.conf files and get a list of hosts
#
for WEB_SERVER in $NSWEB

do

  cd $WEB_SERVER

CURDIR=`pwd`

# Output hostname

echo $BOXNAME >> /tmp/$FILENAME

# Output Directory Name

echo $CURDIR >> /tmp/$FILENAME

# Output Date

echo $CURDATE >> /tmp/$FILENAME

# Output host information

grep urlhost obj.conf >> /tmp/$FILENAME


I tried to clean it up doing below and it hasn't worked so far. 

#
# Clean up of output file
#
# Remove all but URL Name only from lines that have urls in them.

cat $FILENAME | awk -F\" '{print $2}'
cat $FILENAME | awk '{print $1}'

done

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



Deleting an element from an array.

2001-10-03 Thread Mason, Andrew

Say I have an array @array = ( 1, 2, 3, 4, 5)

I know I want to remove the second value, $array[2].  How should I do
this?

Is it possible to issue a command that just does this for me or do I
have to loop through setting $array[n]=$array[n+1] for n>which ever
value I wish to remove?  (I hope that makes sense).

The second solution whilst effectively removing the unwanted element
would mean that the end of my array was filled with duplicates or
rubbish, so isn't really a solution unless I can then tidy it up
somehow. 

TIA 

Andrew

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




Where are the archives?

2001-10-04 Thread Mason, Andrew

Where are the archives?

Sorry to ask such a dumb question but I don't know and it might save me
posting others.


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




RE: Periodic Auto Start

2001-10-05 Thread Mason, Andrew

I think the 'Scheduled tasks' referred to is what I would call the
Scheduler service.  

AT jobs can be created from the command line (probably fine if you are a
Unix/Perl type person) or from the GUI using WINAT (if you are a dumb NT
person like me).

To use AT jobs the Scheduler service needs to be running.  This itself
isn't normally a problem.  However as with all things NT it is prone to
stopping/crashing.  Therefore the log file concept stated below is a
very good idea.  Alternatively some other form of notification.

The same applies for Win2k.

If you have money to burn there is a product out there called ControlM
with quite powerful scheduling capabilities (i.e. cross platform and
task dependant sequencing) however I think that would be overkill for
what you require.

&rw
(Glad to have found something on the list he can actually contribute to)

-Original Message-
From: Stout, Joel R [mailto:[EMAIL PROTECTED]]
Sent: 04 October 2001 19:11
To: 'Gibbs Tanton - tgibbs'; 'Eric Wang '; '[EMAIL PROTECTED] '
Subject: RE: Periodic Auto Start


On windowsNT you can use 'Scheduled Tasks'.  For example I have:

C:\Perl\work\ftp\edicheck.pl /m

running every night at 11:59.  It will pop up a dos window and run.  In
the
morning you can check the 'Last Result' column to make sure it ran okay,
but
I usually build a log file entry into my script.
 
Joel

-Original Message-
From: Gibbs Tanton - tgibbs [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 04, 2001 11:04 AM
To: 'Eric Wang '; '[EMAIL PROTECTED] '
Subject: RE: Periodic Auto Start


If you are on a unix system you can use cron
man cron
I don't know about windows. 

-Original Message-
From: Eric Wang
To: [EMAIL PROTECTED]
Sent: 10/4/2001 1:03 PM
Subject: Periodic Auto Start

Hi People,

How do I call a perl script periodically. Say everyday at 2:00am, I copy
one directory to the backup machine?

Thanx

Eric


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


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




Capturing Output from a program

2001-11-29 Thread Andrew Tait

Hi All,

At the moment I am using the system() fuctions to run external commands as
follows:

print "Run \"userdel -r $arg\" [y/N] ";
chop ($answer=);
if ($answer =~ /^y/i) {
print "Deleting account";
system("userdel -r $arg");
print "Done\n";
}

However, if  "system("userdel -r $arg");" prints any errors, nothing appears
on screen! For example, I am runng this script as a normal user (not root),
which should print the following error.

andrewt@sat:~$ userdel -r $arg
bash: userdel: command not found


But when run from the script nothing happens.

How can I capture the output? Or at least have the output print to screen.

Andrew Tait
System Administrator
Country NetLink Pty, Ltd
E-Mail: [EMAIL PROTECTED]
WWW: http://www.cnl.com.au
30 Bank St Cobram, VIC 3644, Australia
Ph: +61 (03) 58 711 000
Fax: +61 (03) 58 711 874

"It's the smell! If there is such a thing." Agent Smith - The Matrix


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




Does Perl have an equivalent of C's #include

2001-12-05 Thread Andrew Clark

The subject says it all.

R,

AJFC

Please CC replys, I'm not on the list.



Left side variable interpolation during associative arrayassignment?

2001-12-31 Thread Andrew Koebrick

I am trying to build up associative arrays using a looping draw from a database.  I 
would like to end up with one or more arrays(depending on number of elements in the 
@Dataset) named %sub0, %sub1, %sub2... and so on.  I need to keep these arrays around 
for latter manipulation.

What I have now is:

$c=0;
foreach (@Datasets){
 my $SQL = "select year,value from data where trend like '%$Datasets[$c]%' order 
by year";
 my $arrayname = "\$sub$c";
 my $cursor = $dbh->prepare($SQL);
$cursor->execute;
while(@columns = $cursor->fetchrow){
$arrayname{$columns[0]} = $columns[1]; #FAILED LEFT SIDE 
INTERPOLATION
} # end while assignment
 $c++;
}

However, what obviously is happening is that $arrayname{columns[0]} = $columns[1] is 
sticking the values into an array called "$arrayname" rather than interpolating back 
to "$sub0" (or "sub1"... depending on what loop we are in).  I've tried various 
conbinations of quotation marks and eval statements to try to make this work with no 
luck.  Can this be done?  If not, is there a standard workaround?

Many thanks for any assistance.

Andrew Koebrick
Web Coordinator/Librarian
MN-Planning (Office of Strategic and Long Range Planning)
658 Cedar St., Suite 300
St. Paul, MN 55155

651-296-4156 phone
651-296-3698 fax

www.mnplan.state.mn.us



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




use hashref here?

2002-01-19 Thread Andrew Koper

I am working on an org chart app.  It is easy to loop through an
employee list and get an array of everyone who reports to a given user
ID (say, a vice president), but my logic breaks when I try and loop
through the list again and get arrays of everyone who reports to the
managers in the initial array.  Any help?

$name = 'bsmith';

open (FH);
while () {
  (@junk, $sup) = split(/\,/,$_);
  if ($sup eq '$name') {
 push (@underlings, $_);
  }
}
close (FH);

foreach $under (@underling) {
  open (FH);
  while () {
 (@junk, $sup) = split(/\,/,$_);
 if ($sup eq '$under') {
#this is where it breaks, I need a separate array of underlings for each

#CDS ID in underlings, but it doesn't know which CDS IDs will be in
#underlings before it begins. This throws all into one array.
#Useless for my purpose.
push (@under_underlings, $_);
 }
  }
  close (FH);
}


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




Using system variables (M$ OS's)

2002-01-21 Thread Mason, Andrew

I would like to print a line containing the value of a system variable
(I'm running on M$ NT4).

My system variable is %IPADDRESS%.

At the moment my code looks like

chomp ($IpAddress=`echo %IPADDRESS%`);
print "blah blah $IpAddress blah";

Is there a better/preferable way of doing this?

Cheers,
Andrew

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




RE: Using system variables (M$ OS's)

2002-01-21 Thread Mason, Andrew

Fantastic!

Thankyou.

From: Briac Pilpré [mailto:[EMAIL PROTECTED]]
Sent: 21 January 2002 16:05
To: [EMAIL PROTECTED]
Subject: Re: Using system variables (M$ OS's)


Andrew Mason wrote:
> I would like to print a line containing the value of a system variable
> (I'm running on M$ NT4).
#!/usr/bin/perl -w
use strict;


print "Blah blah $ENV{IPADDRESS} blah!\n";

__END__

-- 
briac
 << dynamic .sig on strike, we apologize for the inconvenience >>


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




news articles database

2002-01-22 Thread Hughes, Andrew

I want to create an website where my brother can load his news articles for
searching, sorting, displaying and printing online.  I can figure out the
basics with perl (CGI.pm and DBI) and mySQL.  However, I was wondering what
would be the best way to go about storing each article's content considering
that I will want to format the output and keep paragraph breaks online etc.
Do I store them as .txt files, .doc files or cut an paste the content?  Any
input from people who have gone down this path or can point out some
possible pitfalls is greatly appreciated.

Thanks,
Andrew

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




formatting database text

2002-02-05 Thread Hughes, Andrew

I have created a news article database where non-technical people can cut
and paste articles to be stored in a mySQL database table.  Everything
works.  However when I display these in a browser, I want to have  tags around each paragraph, so that the non-technical
people do not have to worry about adding these tags.  I was thinking the
logic would go something like this:

When displaying the body field of the database, before anything else print


Then, for each blank line print 

Finally, after the last paragraph print 

Should I do this when the articles go into or are pulled out of the
database?
How do I go about doing this?

All suggestions are welcome.

Thanks,
Andrew


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




Issuing multiple concurrent commands (to system)

2002-02-07 Thread Mason, Andrew

Is it possible to issue multiple concurrent commands to system (for
instance) from within a perl script?

If it is (and I strongly suspect that it must be) would someone please
be so kind as to suggest some terms or perl commands to look up.  (I
suspect the term threading might appear but I don't want to start
barking up the wrong tree if I don't have to)

I'm happy to research this but just don't know where to start.

The reason I would like to do this is to speed up some reporting
scripts.  Ie if I'm using a perl script to search multiple locations for
a file, or issue a command on multiple machines it would be nice to
issue them all at once rather than wait for each to return.

Also is it possible to make perl issue a command to system (again for
instance) and not wait for a returned value?

Rgds,

&rw

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




enumerating subarrays

2009-04-04 Thread Andrew Fithian
What's a slick way to enumerate all subarrays of length n from a master 
array of length m? For example I've been enumerating all possible two 
card hands from a deck of 52 cards (n=2, m<=52) using nested for loops:
for ( $i = 0 ; $i < $#deck ; $i++ ) {
for ( $j = $i+1 ; $j <= $#deck ; $j++ ) {
someMethod( $deck[$i] , $deck[$j] )
}
}
How do I clean this up and generalize it to larger hands (longer 
subarrays).

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




escaping regex to do math on backreferences

2009-04-12 Thread Andrew Fithian
Hello everyone,
I have a program that needs to find straights in a hand of cards. The hand
is a string with no whitespace sorted by the cards' ranks, eg "9d10cJhQsKd".
How can I identify if that hand contains a straight with a single regex? Is
that even possible?
Is there a way to escape the regex and do addition on a backreference to get
something like /(\d+)[cdhs]\1+1[cdhs]\1+2/?
Thanks,
-Andrew


RE: Simple regex question

2009-05-19 Thread Andrew Curry
A crude one

($part,$unit,$x,$y,$xlen,$ylen) = ($1,$2,$3,length($4),length($5))
if ($string =~ /(^\S{5})\.(\d{2})([+-])(\d+)\.(\d+)$/);



-Original Message-
From: Dan Fish [mailto:d...@ninemoons.com] 
Sent: 19 May 2009 14:18
To: beginners@perl.org
Subject: Simple regex question

Simple question for the regEXperts out there...

I have a string that is always in the format:  a.nn+x.y 

a is always 5 chars 
n can be 1 or 2 digits
x can be +/- (with sign), 1-4 digits
y is always positive (no sign), 1-4 digits


Some examples:
A123C.11+002.001
FC32G.2-1.0
12B15.01+2145.15

I need all 4 pieces and the length of x & y. The following works:

my $id= "A123C.11+002.001";

my @tmp = split(/[\.+-]/,$id);
my $part = $tmp[0];
my $unit = $tmp[1];
my $x = $tmp[2];
my $y = $tmp[3];
my $xlen = length $tmp[2];
my $ylen = length $tmp[3];

but in my quest for understanding regex, I'm always looking for more
elegant
(obfuscated :-) code... 
Anybody have a good one-liner for this?

my ($part,$unit,$x,$y,$xlen,$ylen) = /* Some obfuscated code here.. */


Thanks!
-Dan

---
d...@mapson.ninemoons.com
(To reply via email, remove 'reverse(nospam)' in address.  Spambots are
getting wy too smart nowadays...:-) 


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



This email is from the Press Association.  For more information, see 
www.pressassociation.com.
This email may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this email is personal to the sender and may not 
reflect the opinion of the Press Association.
Any email reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: recurive chown with perl chown

2009-06-19 Thread Andrew Curry
http://www.perlmonks.org/?node_id=202898

may be of use.

-Original Message-
From: news [mailto:n...@ger.gmane.org] On Behalf Of Harry Putnam
Sent: 19 June 2009 14:36
To: beginners@perl.org
Subject: recurive chown with perl chown

How to manage a recursive chown using perl function chown?

Do I have to employ something like File::Find to recursively chown a
directory heirarchy.  Or maybe opendir and readdir...

Or is there some simpler way?


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



This email is from the Press Association.  For more information, see 
www.pressassociation.com.
This email may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this email is personal to the sender and may not 
reflect the opinion of the Press Association.
Any email reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




Totally lost on how to get the argv of Perl

2009-07-31 Thread Andrew Steinborn
I need to know how to get the arguments passed to Perl. I'm using the 
ActiveState built version of Perl on Windows Vista.


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




Re: How to pass info to a CGI program without using a form?

2009-08-24 Thread Andrew Steinborn

boll wrote:
There is a perl program running on my server  that delivers random 
images to a web page.

The image on the html page is specified by this html code:

http://localhost/cgi/random_image.cgi"/>

I would like to use this program in several places to display images 
from other directories,
so that one URL might display a random image from the 'vegetables' 
directory,
and a different URL would call the same program but display an image 
from the 'fruits' directory.


Here's where I'm requesting help-
I don't understand how to pass the name of the image directory in the URL,
or how to modify the program to read the directory name.

Here is the program, written to call images from the 'specials' directory:

#! /usr/bin/perl -wT
#
# $Id: rand_image.pl,v 1.11 2002/10/21 19:37:36 nickjc Exp $
#Modified from http://nms-cgi.sourceforge.net

use strict;
use CGI qw(redirect header);
use Fcntl qw(:DEFAULT :flock);
use vars qw($DEBUGGING $done_headers);

# Configuration

#  DEBUGGING: ===
BEGIN
{
$DEBUGGING = 1;
}

my $use_redirect = 1; #Use redirect and baseurl on server & localhost 
version.

my $baseurl = 'http://localhost/specials/';
my $basedir = '/my-domain.com/specials/';

# === image files here: 

open LIST, "specials_img_list.txt" #must exist in cgi directory
or die "Image List filehandle not open: $!\n";
my @files = ; #images (thumbs).

# === LOGGING: ==
my $uselog = 1; # 1 = YES; 0 = NO
my $logfile = 'randimages.log';

#  End configuration.

my %content_types = (
jpg => 'image/jpeg',
gif => 'image/gif',
png => 'image/png'
);


# === ERRORS: ==

BEGIN
{
sub fatalsToBrowser
{
my ( $message ) = @_;

if ( $DEBUGGING )
{
$message =~ s//>/g;
}
else
{
$message = '';
}

my ( $pack, $file, $line, $sub ) = caller(0);
my ($id ) = $file =~ m%([^/]+)$%;

return undef if $file =~ /^\(eval/;

print "Content-Type: text/html\n\n" unless $done_headers;

print 
http://www.w3.org/1999/xhtml";>

Error


Application Error

An error has occurred in the program


$message



EOERR
die @_;
};

$SIG{__DIE__} = \&fatalsToBrowser;
}


# === IMAGE FILE NAME: ===

my $pic = '';
while ($pic !~ m/\w+/){
$pic = $files[rand @files];
chomp $pic;
}


# Log Image
if ($uselog) {
sysopen (LOG, $logfile, O_RDWR|O_APPEND|O_CREAT)
or die "Can NOT open logfile: $!\n";
flock(LOG, LOCK_EX)
or die "Can't lock logfile: $!\n";
#print LOG "LOG FILE OPENED \n";
#print LOG "$baseurl$pic\n";
}

if ( $use_redirect )
{
if ( $baseurl !~ m%/$% )
{
$baseurl .= '/';
}
print LOG qq[specials: redirect("$baseurl$pic")\n];
print redirect("$baseurl$pic");
$done_headers++;
}
else
{
if ( $basedir !~ m%/$% )
{
$basedir .= '/';
}

my ( $extension ) = $pic =~ /\.(\S+)$/;

my $ctype = $content_types{$extension} || 'image/png';

open INFILE, "<$basedir$pic" or die "Can't open $basedir$pic - $!";
binmode INFILE;
local $/;

my $image = ;
close INFILE;

print header(-type => $ctype),
$image;
print LOG "$baseurl$pic\n";
}
close (LOG)
or die "Can't close logfile: $!\n";



You can use a custom random image file list - eg. "vegs.txt" for say, 
carrots.jpg, tomato.png and squash.gif and "nature.txt" for hills.jpg 
and tree.png.


I am not an expert when it comes to Perl in CGI, you may have to Google 
the rest.


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




Re: Totally lost on how to get the argv of Perl

2009-08-24 Thread Andrew Steinborn

Shawn H. Corey wrote:

Andrew Steinborn wrote:
I need to know how to get the arguments passed to Perl. I'm using the 
ActiveState built version of Perl on Windows Vista.




Perl loads the command-line arguments into the special variable @ARGV

See `perldoc perlvar`.



Thanks. I figured it out reading the HTML docs.

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




RE: find an entry in hash array

2008-03-20 Thread Andrew Curry
  %hash = map { $_ => 1 } @array;

 is just a funny way to write

 %hash = ();
 foreach $_ (@array) {
 $hash{$_} = 1;
 } 

-Original Message-
From: Sharan Basappa [mailto:[EMAIL PROTECTED] 
Sent: 20 March 2008 15:47
To: Chas. Owens
Cc: Robert Leibl; Perl Beginners
Subject: Re: find an entry in hash array

Can you throw some light on this statement:
my %hashset = map { $_ => 1 } @array;

On Thu, Mar 20, 2008 at 9:14 PM, Chas. Owens <[EMAIL PROTECTED]>
wrote:
> On Thu, Mar 20, 2008 at 11:35 AM, Sharan Basappa
>
> <[EMAIL PROTECTED]> wrote:
>
> > Well here is what I am trying to do.
>  >  I have an array (generated from somewhere) I would like to convert

> >  this into an associative array and then based on some other input  
> >  I would like to see if an entry exists in the asso array. As you 
> can see  >  the value does not really matter. What matters is whether 
> the entry  >  exists or not.
>  >  For example (very trivial one)
>  >  I have a list of names that are allowed access to a machine. I 
> create a asso  >  array of them. Later when I want to check if the 
> user is allowed to login, I  >  check if that user exists or not. 
> Currently I am doing this by making value for  >  key as 1. But I
never really use the value at all.
>  >  Regards
>  snip
>
>  This data structure is called a hash set.  Hash sets are easy to make
in Perl:
>
>  #!/usr/bin/perl
>
>  use warnings;
>  use strict;
>
>  my @array   = qw;
>  my %hashset = map { $_ => 1 } @array;  for my $letter ("a" .. "i") {
> if (exists $hashset{$letter}) {
> print "$letter is in the hash set\n";
> } else {
> print "$letter is not in the hash set\n";
> }
>  }
>
>  a is in the hash set
>  b is not in the hash set
>  c is not in the hash set
>  d is in the hash set
>  e is not in the hash set
>  f is in the hash set
>  g is not in the hash set
>  h is in the hash set
>  i is not in the hash set
>
>
>  --
>
>
> Chas. Owens
>  wonkden.net
>  The most important skill a programmer can have is the ability to
read.
>

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



This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: Joining/Merging AoA

2008-04-24 Thread Andrew Curry
As this is a beginners list are you going to explain...

push my @c, [EMAIL PROTECTED] @a}];
push @{$c[0]}, (@{shift @b})[1];

$c[$_->[0]] = [ @{$_} ] while $_ = shift @a;
push @{$c[$_->[0]]}, $_->[1] while $_ = shift @b;
 


-Original Message-
From: Jay Savage [mailto:[EMAIL PROTECTED] 
Sent: 24 April 2008 14:53
To: Vishal G; Perl List
Subject: Re: Joining/Merging AoA

On Tue, Apr 22, 2008 at 2:28 AM, Vishal G <[EMAIL PROTECTED]> wrote:
> Hi Guys,
>
>  I have a little complicated problem...
>
>  I have two arrays
>
>  @a = ( ['id', 'name', 'age'],
>['1', 'Fred', '24'],
>['2', 'Frank', '42'],
>  );
>
>  @b = ( ['id', 'sex'],
>['1', 'm' ],
>['2', 'm'],
>  );
>
>  I want to join these two AoA, based on id, so the resulting array 
> will  look like this
>
>  @c = ( ['id', 'name', 'age', 'sex'],
>['1', 'Fred', '24', 'm' ],
>['2', 'Frank', '42', 'm'],
>  );
>
>  Any Ideas?
>

It really depends on the data. Are you certain that both lists will be in
the same order? Are you certain that all data will exist for each person? If
so you can just loop though both lists. That's not very robust, though,
because as soon as you get a value that is one list and not the other,
everything gets out of sync.

I'd probably do something like the following, which stores the is in the
array index, as well as the first element:


push my @c, [EMAIL PROTECTED] @a}];
push @{$c[0]}, (@{shift @b})[1];

$c[$_->[0]] = [ @{$_} ] while $_ = shift @a;
push @{$c[$_->[0]]}, $_->[1] while $_ = shift @b;


HTH,

-- jay
--
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and
confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org

values of β will give rise to dom!


This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





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




RE: hash return from a sub

2008-04-28 Thread Andrew Curry
Ill make a guess it's a scope issue, but cant be sure without the main
code.

Try something like 

use strict;

my %test=mysub();

print %test;

sub mysub {
my(%myhash,$var1,$var2);
 $var1 = '1';
 $var2 = '2';
 $myhash{$var1} = $var2;
print %myhash;
return ( %myhash );
}

This works fine from testing.
 

-Original Message-
From: Flyzone [mailto:[EMAIL PROTECTED] 
Sent: 28 April 2008 18:06
To: beginners@perl.org
Subject: hash return from a sub

How can i return a copy of the hash? (The hash is build correct, but
return alsways null) Here a sample of my code:

sub mysub {
while (.) {
 var1 = ;
 var2 = ;
 $myhash{$var1} = $var2;
}
print %myhash; # all ok until here
return ( %myhash );
}

%test=mysub();
print %test; # wrong, don't print nothing, neither error;

I would like to return a copy of the hash to a new variable, not a
reference.
Thanks in advance.


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



This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: sql and perl

2008-04-28 Thread Andrew Curry
 

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: 28 April 2008 17:53
To: beginners@perl.org
Cc: Francisco Valladolid
Subject: Re: sql and perl

Francisco Valladolid wrote:
>>
>> I want to start learning about sql and how it interacts w/ perl.
>>
>> My rough idea is to install mysql server and read some books to start

>> playing w/ it along w/ perl.
>> Any advice?
>>
>> For now, I just plan to go through the book 'mysql and perl for the 
>> web'
>>
>> If someone can post some excellent site relates to mysql and perl.. 
>> would be appreciated.
>> I will post related questions along the way(also, please let me know 
>> if this is not the right mailing list for this and if something 
>> exists that I am not aware of at this point)
> 
> I  Recommended using PostgreSQL over MySQL, if you need begin, 
> postgresql is the best choice.

>(Please bottom-post responses to this group, so that extended thread
remain comprehensible. Thank you.)

>That is a divisive comment, and a matter of opinion. What it really
boils down to is that PostgreSQL is better-featured but MySQL is more
common in the field. For a beginner >who is unlikely to need the more
esoteric features that PostgreSQL has  to offer, MySQL is absolutely
fine and is likely to be better supported.

>Rob

As a dba using both flavours as well as comercial database solutions,
they both have advantages and disadvantages. They came from the same
basic source code, postgress went for features, mysql speed. As it
stands there is not a lot between them come enterprise version 5 but in
terms of actual features from a Admin point of view and resilience
postgres has an edge. Mysql however from a developer speed point of view
is probably better. SQL wise they are pretty much identical following
the major standards so either is a good basis for testing the choice
comes when you actually want to do something in a live environment. 


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



This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: question on foreach loop

2008-05-01 Thread Andrew Curry

>-Original Message-
>rom: J. Peng [mailto:[EMAIL PROTECTED] 
Sent: 01 May 2008 15:31
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Subject: Re: question on foreach loop

To add a statement of "print $_" follow the foreach, you will see what
was happening.

foreach (@data){
   print "$_\n";
   splice @data,0,1;
   print "printing [EMAIL PROTECTED] = @data\n";
}

On Thu, May 1, 2008 at 10:15 PM,  <[EMAIL PROTECTED]> wrote:
> Hi Members,
>  Can someone explain why the foreach loop did not iterate 10 times.
>
>  Thanks
>
>  #
>  use strict;
>  use warnings;
>
>  my @data = (1..10);
>
>  foreach (@data){
> splice @data,0,1;
> print "printing [EMAIL PROTECTED] = @data\n";  }
>
>  # results ###
>  printing @data = 2 3 4 5 6 7 8 9 10
>  printing @data = 3 4 5 6 7 8 9 10
>  printing @data = 4 5 6 7 8 9 10
>  printing @data = 5 6 7 8 9 10
>  printing @data = 6 7 8 9 10

Is not what is exactly expected

Removes the elements designated by OFFSET and LENGTH
 from an array, and replaces them with the elements
 of LIST, if any.  
So above...

ON @data 1,2,3,4,5,6,7,8,9,10#
Remove 0,1 (1) so 
printing @data = 2 3 4 5 6 7 8 9 10

ON @data 2,3,4,5,6,7,8,9,10
Remove 2
printing @data = 3 4 5 6 7 8 9 10


ON @data 3,4,5,6,7,8,9,10
Remove 3
printing @data = 4 5 6 7 8 9 10

ON @data 4,5,6,7,8,9,10
Remove 4
printing @data = 5 6 7 8 9 10

ON @data 5,6,7,8,9,10
Remove 5
printing @data = 6 7 8 9 10

As the iterator of foreach has been modified once by the foreach and
once by the splice it thinks it has nothing more to process?



--
J. Peng - QQMail Operation Team
eMail: [EMAIL PROTECTED] AIM: JeffHua

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



This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: what is ^M at the end of a line?

2008-05-21 Thread Andrew Curry
If your trying to do this on a unix based system 

^M is equivalent to \r\n so you can get rid of \r I believe. 

-Original Message-
From: Remy Guo [mailto:[EMAIL PROTECTED] 
Sent: 21 May 2008 15:20
To: Rob Coops
Cc: Perl Beginners
Subject: Re: what is ^M at the end of a line?

it's really interesting... then how can i match that ^M using regex?
i've tried "chomp" when reading each line but it doesn't work...

2008/5/21 Rob Coops <[EMAIL PROTECTED]>:

> That ^M is a line feed, or well the windows version of a line feed.
>
> There are several different ways in which to write a line feed and of 
> course to make our lives better *nix, Dos/Windows and Mac all have 
> their own way of writting them.
>
> So Jeff's suggestion relies on a little application that simply finds 
> ad relapces all the dos/windows ways of doing things like line feeds 
> and replaces them with the unix version of the same.
>
> If you feel like doing this in perl a simple regex will do the trick, 
> at least for the line feeds, but there is more windows fun to be had, 
> like the way MS Word replaces ceretain characters like " ' - and even 
> ... with a special charatcer because they are estetacly more pleasing 
> to the reader of the document. I am sure there are more examples and 
> dos2unix covers them all.
>
> So if it is a single file and only a one of then dos2unix is the 
> easiest way, if you want to do it in perl then you will most likely 
> have to use a regex because not all moachines will have the dos2unix 
> applicaiton available.
>
> Regards,
>
> Rob Coops
>
>   On Wed, May 21, 2008 at 10:45 AM, Remy Guo <[EMAIL PROTECTED]>
> wrote:
>
>> hi all,
>> i have a text processing script that can work with a file but cannot 
>> work with another file that has the same content.
>> as i compared the 2 files, i found the file that cannot work has a 
>> "^M" at the end of each line. what is this? is this what made it not
work?
>> by the way, i'm under unix.
>> thanks
>>
>> -Remy
>>
>
>


This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





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




RE: What is wrong with this script ??

2008-08-20 Thread Andrew Curry
Depending on your server the error could be that the group doesn't exist i.e. 
on unix you would need to add the groups to /etc/group first. 

-Original Message-
From: Jyotishmaan Ray [mailto:[EMAIL PROTECTED] 
Sent: 20 August 2008 13:17
To: beginners@perl.org
Subject: What is wrong with this script ??

Dear All,

I have a input file containing all the rolnos of 400 studenst. I have written a 
small perl script to create their home directories in the cluster server. 

everything worked fine except for the reason that, it shows up error message 
indicating that the following messages for example: 

when my input file rr.txt contains the following roll nos.:-


s08-1-5-095
s08-1-5-096
s08-1-5-097

the error messages displayed are :-

[EMAIL PROTECTED] perl]# perl h20.pl
chgrp: invalid group `s08-1-5-095'
chgrp: invalid group `s08-1-5-096'
chgrp: invalid group `s08-1-5-097'

The ls -l listing shows up the following :-


drwx-- 2 s08-1-5-095 root   4096 2008-08-20 17:28 s08-1-5-095
drwx-- 2 s08-1-5-096 root   4096 2008-08-20 17:28 s08-1-5-096
drwx-- 2 s08-1-5-097 root   4096 2008-08-20 17:28 s08-1-5-097


As shown above the group is shown as root, but i want each student to be the 
group itself, for example it should be :

drwx--2 s08-1-5-095 s08-1-5-095 4096 2008-08 17:28
s08-1-5-095

The perl script is shown below:

Can anyone tell me what changes should I make in the script so as to make the 
group same as owner i.e., the roll no. itself.



#!/usr/local/bin/perl
$file = '/root/perl/rr.txt';
open(PWD, $file);
while()
{
($a)=split(/\s+/,$_);
#system("mkdir /root/perl/$a");
system("chmod 700 /root/perl/$a");
#system("chown   /root/perl/$a  $a");
system("chgrp  $a  /root/perl/$a" );
}
close(PWD);
~   














Thanks,
Jyotishmaan Ray Moderator Of Paradise Groups 
http://yahoogroups.com/group/Spirituality-Paradise Are You Spiritually Aware  
!!! Are You Enjoying Yourself  !!!  See What All You Had Been Missing 
Please Join Immediately By Sending A Blank Mail @ [EMAIL PROTECTED] 
   


  

This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: doubt

2008-08-20 Thread Andrew Curry
Im going with empty string or null. 

-Original Message-
From: Irfan J Sayed (isayed) [mailto:[EMAIL PROTECTED] 
Sent: 20 August 2008 14:34
To: beginners@perl.org
Subject: doubt

Hi All,

Can you please tell me what is the value of $file. When i execute this
script . it says "Can't open : No such file or directory"

Please suggect.

Regards

Irf.

#!/usr/bin/perl

# file: count_lines.pl

# Figure 1.4: Count the lines of a file

use strict;

use IO::File;

my $file = shift;

my $counter = 0;

my $fh = IO::File->new($file) or die "Can't open $file: $!\n";

while ( defined (my $line = $fh->getline) ) {

$counter++;

}

STDOUT->print("Counted $counter lines\n");


This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: Perl equivalent of "sed -f" or "awk -f"

2008-09-02 Thread Andrew Curry
Perl -p -i -e "s/search/replace/;"  

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: 02 September 2008 15:06
To: beginners@perl.org
Subject: Perl equivalent of "sed -f" or "awk -f"

I'd like to apply a series of inline edits to a file in Perl.

With sed, I could use "sed -f commandfile inputfile" or in awk, "awk - f
commandfile inputfile", however, I could not find an equivalent in Perl.
I'd prefer not to use sed or awk as they do not support inline editing
directly.

In Perl, what would be the way to apply a series of multiple inline
edits in this form to an inputfile?

commandfile:
s/searchterm/replaceterm/
s/searchterm2/replaceterm2/
s/searchterm3/replaceterm3/

etc...

Thanks in advance.


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



This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




Introduction to Perl talk available at osbootcamp.org

2008-09-06 Thread Andrew Ross
Hi All,
 
Open Source Bootcamp (osbootcamp) teaches skills with open source. We
recently had a Perl talk which we've recorded and made freely available from
the osbootcamp.org videos section. Enjoy!
 
Andrew
http://osbootcamp.org
 


Re: How can I execute linux commands on terminal and catch the results?

2008-09-29 Thread Andrew Smith

Hi Daniel
I think the qx command will do what you want. It's described in perldoc 
perlop

An example of it in use is
perl -e '$res=qx/date/;print $res;'
--
Andrew
Daniel Nascimento wrote:

Hello everyone!
I'm learning perl and I need some help.

I want to write a script that execute commands into a linux terminal
and catch the results but I don't know how to do this.

Example: I want a script try to create a new user, but it has to
verify if the user is created before do it. If the user was already
created the script has to print a message for user informing something
like this "user already created"

Somebody has a tip for me?

PS: Sorry by my English. I'm not a good speaker... I'm learning yet.

A big hug and thanks for all.

Daniel


  



--
Andrew

******
Andrew Smith BSc(Hons), MBA
Founder & Director
Valley Technology Research  Limited
VTRL
14 Inverleith Place
Edinburgh
SCOTLAND
EH3 5PZ
T:  0131-5527543 or 0131-5529983(home)
M: 07807321039
F:  0131-5512702
E: [EMAIL PROTECTED])

**


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




Re: Beginners' books for Perl newbies using Windows?

2008-09-30 Thread Andrew Smith
Hi
>From my experience learning Perl, the supplied on-line documentation
accessed through the perldoc command provides everything you need.
--

air wrote:
> On 9月19日, 下午12时19分, [EMAIL PROTECTED] (Jeff Pang) wrote:
>   
>> 2008/9/19 Phillip Pi <[EMAIL PROTECTED]>:
>>
>>
>>
>> 
>>> Thank you, but I don't see anything about hardcopy books.
>>> --
>>>   
>> Well, I think you should buy the book "learning Perl" which is
>> suitable for both unix users and windows users, since Perl is a
>> Cross-Platform language.
>> 
>
> Yes, the book "Learning Perl" had 5th in 2008.
> and you can download it from the here:
> www.freebookspot.net
> also it had many frees books to download.
> good luck.
>
> Air
>
>
>   


-- 
--
Andrew

**
Andrew Smith BSc(Hons), MBA
14 Inverleith Place, Edinburgh. EH3 5PZ
Tel: 0131-552 9983
Fax: 0131-551 2702
**


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




RE: Reg : Browser Back Button

2008-11-03 Thread Andrew Curry
Actually using javascript it is possible although probably not
recommended and again can not be guaranteed to work on all browsers.

-Original Message-
From: Rob Coops [mailto:[EMAIL PROTECTED] 
Sent: 03 November 2008 10:42
To: beginners@perl.org
Subject: Re: Reg : Browser Back Button

On Mon, Nov 3, 2008 at 11:10 AM, Anusha Krishna chand <
[EMAIL PROTECTED]> wrote:

> Hi All,
>Is it possible to perform some action when we click on back
button
> of the browser. I need to call a script when i click on back button of
the
> browser using perl script...
>


Is there any browser that sends a signal to your server when a user
clicks
the back button? Or is there any client side script that can detect this
for
you?

The answer to the first question is: No.
The answer to the second question is as far as I am aware: No.

So that means that the answer to your question is unfortunately: No.

What you might be able to so is keep track of where the user was last in
the
session, and then on the page that they navigate to take an action based
on
the location they came from, btu that can quite quickly become messy as
a
user might type a URL directly which might mean the new page is not the
previous page but four pages back or a completely different unrelated
page.

You could also consider that if you need to take an action based on the
back
button then you need to alter your design since this should not be
needed,
looking at al kinds of web tool kits using ajax and other "cool" words.
You
can see many examples of frameworks that manage to handle the back
button
gracefully, even though most web developers will tell you that the back
button is the one thing that all browsers have and that is just as hard
to
code for in every single one of them.

This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




RE: [Fwd: Re: Determining if a file is more than so many days old]

2008-11-20 Thread Andrew Curry
If your on unix you can just use find with -mtime and an exec rm. If all
you want to do is perge files. 

-Original Message-
From: Raymond Wan [mailto:[EMAIL PROTECTED] 
Sent: 20 November 2008 15:39
To: beginners@perl.org
Subject: [Fwd: Re: Determining if a file is more than so many days old]


Sorry, forgot to send it to the list...

Ray

-
Hi Andrew,

AndrewMcHorney wrote:
 > I am working on a perl script that will go through a directory and
 > it's subdirectories and purge all the files that are more than a
 > specified number of days old. I am using a Unix system so I do a find
 > command to gather up the files I want. I then am going to do a stat
 > command to find the date the file was created (it is never modified)
 > and then determine if it is to be deleted. What is the easiest way to
 > determine if a date is more than x number of days old.

In Perl? I wrote such a script -- yet, I do not know if this is the
"easiest" way to do it.

I used -M to do it (http://perldoc.perl.org/functions/-X.html):

my $days = sprintf ("%.2f", -M $fn);
if ((defined $days) && ($days > $daylimit)) {
rmtree ($dir);
}
}

where $daylimit is a value provided earlier. Seems to work fine...

Ray


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



This e-mail is from the PA Group.  For more information, see www.thepagroup.com.
This e-mail may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this e-mail is personal to the sender and may not 
reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


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




Re: subroutine definitions

2004-03-01 Thread Andrew Gaffney
zsdc wrote:
Confusion? You should read 6th Apocalypse by Larry Wall and the 
appropriate Exegesis by Damian Conway:

http://dev.perl.org/perl6/apocalypse/A06.html
http://dev.perl.org/perl6/exegesis/E06.html
Now, _that_ is confusing. :)
I think that's an understatement. Blood is coming out of my ears after reading a few pages 
of the first one...

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



interacting with table layouts using DBI

2004-03-02 Thread Andrew Gaffney
Is there an easy way with DBI (or anything other modules) to retrieve and modify the 
layout of database tables in a MySQL DB? I need to write a program to add 2 fields to ~40 
tables with an identical layout. The tables are named "m"mmyy where "m" is an actual 'm', 
mm is a 2 digit month, and  is a 4 digit year. If the table doesn't exist, I want to 
create it with the same layout as all the rest. I can write a program that does this the 
hard way, but before I started, I wanted to know if there was an easier way.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: interacting with table layouts using DBI

2004-03-02 Thread Andrew Gaffney
Andrew Gaffney wrote:
Is there an easy way with DBI (or anything other modules) to retrieve 
and modify the layout of database tables in a MySQL DB? I need to write 
a program to add 2 fields to ~40 tables with an identical layout. The 
tables are named "m"mmyy where "m" is an actual 'm', mm is a 2 digit 
month, and  is a 4 digit year. If the table doesn't exist, I want to 
create it with the same layout as all the rest. I can write a program 
that does this the hard way, but before I started, I wanted to know if 
there was an easier way.
To add/modify my query: Is there a module in existance that can act as a wrapper for table 
structures in a MySQL (or any other) DB? I'm thinking about writing a module that uses a 
tied hash (which will be a hash of hash references corresponding to different properties 
of each field). If one doesn't exist, I'd like to atleast try my hand at creating 
something like this for easily adding and modifying tables via DBI.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



iterating through hash of hash references

2004-03-03 Thread Andrew Gaffney
I have a script which creates a hash where all the values are hash references. I'm trying 
to iterate through the original hash and down into the anonymous hashes to make sure my 
code is doing what I think it's doing. My problem comes in at those nested foreach loops 
before the DB disconnect. I get the error:

Using a hash as a reference is deprecated at ./modtables.pl line 24.
Type of arg 1 to keys must be hash (not hash element) at ./modtables.pl line 24, near 
"})"

#!/usr/bin/perl
use Skyline; # Custom module
use strict;
use warnings;
my @tables;
my $dbh = init_db(); # Custom function to connect to MySQL DB
my ($sth, $ref, $tabledesc);
get_table_list();
foreach (@tables) {
  $tabledesc = {};
  $sth = $dbh->prepare("DESCRIBE $_");
  $sth->execute;
  while($ref = $sth->fetchrow_hashref) {
$tabledesc->{$ref->{Field}} = {type=> $ref->{Type},
   null=> $ref->{Null},
   key => $ref->{Key},
   default => $ref->{Default},
   extra   => $ref->{Extra} };
  }
  foreach (keys %$tabledesc) {
foreach (keys %$tabledesc->{$_}) {
  print "$_ = $tabledesc->{$_}, ";
}
print "\n";
  }
}
$dbh->disconnect();
sub get_table_list {
  $sth = $dbh->prepare("SHOW TABLES");
  $sth->execute;
  while($ref = $sth->fetchrow_hashref) {
push @tables, $ref->{'Tables_in_skyline'} if($ref->{'Tables_in_skyline'} =~ 
/^m\d{6}$/);
  }
}

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: interacting with table layouts using DBI

2004-03-03 Thread Andrew Gaffney
Ed Pigg wrote:
On Mar 2, 2004, at 5:53 PM, Andrew Gaffney wrote:

Is there an easy way with DBI (or anything other modules) to retrieve 
and modify the layout of database tables in a MySQL DB?


You might want to look at Class::DBI on CPAN.
That is the general idea. I was thinking about something that let you have a little more 
control over the creation of tables and fields, such as data types and field lengths.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: iterating through hash of hash references

2004-03-03 Thread Andrew Gaffney
Charles K. Clarkson wrote:
Andrew Gaffney <[EMAIL PROTECTED]> wrtoe:

:foreach (keys %$tabledesc) {
:  foreach (keys %$tabledesc->{$_}) {
Shouldn't that be:

foreach ( keys %{ $tabledesc->{$_} } ) {

:print "$_ = $tabledesc->{$_}, ";
:  }
:  print "\n";
:}
BTW, it's confusing to use nested loops
which both use the default value ($_). You would
probably be better off with named values or just
not using two loops.
use Data::Dumper 'Dumper';

print Dumper $tabledesc;
I changed it to:

  foreach my $field (keys %$tabledesc) {
print "${field} - ";
foreach (keys %{ $tabledesc->{$field} }) {
  print "$_ = $tabledesc->{$field}->{$_}, ";
}
print "\n";
  }
which makes it a tad less confusing (and also makes it work). Now I've got another issue. 
How can I dynamically assign new keys to a hash without getting warnings when using 'use 
warnings'? I get the warning about an undefined value on the line with the '->'.

  $tabledesc = {};
  $sth = $dbh->prepare("DESCRIBE $_");
  $sth->execute;
  while($ref = $sth->fetchrow_hashref) {
->  $tabledesc->{$ref->{Field}} = {type=> "$ref->{Type}",
   null=> "$ref->{Null}",
   key => "$ref->{Key}",
   default => "$ref->{Default}",
   extra   => "$ref->{Extra}" };
  }
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: iterating through hash of hash references

2004-03-03 Thread Andrew Gaffney
Charles K. Clarkson wrote:
Andrew Gaffney <[EMAIL PROTECTED]> wrote:

: Now I've got another issue. 
: How can I dynamically assign new keys to a hash without
: getting warnings when using 'use warnings'? I get the warning
: about an undefined value on the line with the '->'.

You can either temporarily turn those warnings off (not a
good idea) or you can make certain undefined values are not
used. The big question would be: Why is '$sth->fetchrow_hashref'
returning at least one undefined value?
It looks like not all of the fields have something in them. Perl is taking blanks for 
undefined for some reason.

:$tabledesc = {};
:$sth = $dbh->prepare("DESCRIBE $_");
:$sth->execute;
:while($ref = $sth->fetchrow_hashref) {
Are you sure your DB returns Field, Type, Null, Key, Default,
and Extra on every field? Perhaps a more general approach would
work:
my $field = delete $ref->{Field};

$tabledesc->{ $field } = $ref;

: ->  $tabledesc->{$ref->{Field}} = {type=> "$ref->{Type}",
: null=> "$ref->{Null}",
: key => "$ref->{Key}",
: default => "$ref->{Default}",
: extra   => "$ref->{Extra}" };
 What are the double quotes for? You're forcing
stringification (perlfaq4). That's usually a bad idea.
I was trying to get rid of another warning:

Use of uninitialized value in concatenation (.) or string at ./modtables.pl line 26.

Which is the line where it prints out the values in the hash. It gives me that when the 
field is blank, the same as it give me the other warning with the quotes.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: HERE DOCUMENTS

2004-03-06 Thread Andrew Gaffney
WC -Sx- Jones wrote:
This is Part One of a Multipart posting - just to see if we can't keep 
things in the list archieves (Give the listbots something to do :)

(These are not really posted questions so much as they are things that 
beginners need to consider.)

"HERE" DOCUMENTS

* Here documents are used to embed lines of text in a Perl
  script, for printing or variable assignment.
  $foo = <
print <<_Html_;
various basic html can go here
sprinkled with Perl variables...
_Html_
NOTE that the ending portion of a heredoc must be in column zero -- I 
have noticed that having indented can cause issues at times...

* Variable interpolation is "on" by default.  You turn it off
  by making it single quoted.
  print <<'EOP0'
  interpolation is off:
  $foo $bar are not converted to data
  EOP0
Whether you use Double quotes, the variables are
interpolated into their corrisponding data:
  print <
# The following is somewhat dangerous; use with
# appropriate caution -
* Commands will be executed if the ending-string uses backticks.
  $sommand_results = <<`END_OF_COMMANDS`
  ls -al
  ps -aux
  END_OF_COMMANDS
Also, I previously posted how to cram single lines of text into an 
array; it is left upto the reader as an exercise to find that posting 
out there in Usenet land.

That's a small start to what I hope will become a long term thing :)

So, if you have a statement or neat easy to understand fact about HERE 
Documents, post it; keep this Perl Chain Posting going...
If you want to indent your ending line (EOF, EOT, END_OF_COMMANDS, etc.) for readability, 
you can do so like this:

  print <<"  EOF"; # Single quotes turn off variable interpolation (found out hard way)
This is some text.
More text.
foo = $foo
  EOF
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: OT: Re: subroutine definitions

2004-03-08 Thread Andrew Gaffney
Wiggins d'Anconia wrote:
Andrew Gaffney wrote:

[snip]

Really, I'm the only user of my code. I don't expect to get replaced 
anytime soon as my boss also doubles as my father ;) Besides, I 
certaintly don't want to make things easier for my replacement (if 
there ever is one).
Sorry for the old post, but this last sentence of yours is scary. More 
often than not your replacement will be you in a few weeks, months, etc. 
 But a bigger problem is the attitude taken in it, and maybe you are set 
for life with dear ol' dad running the company, but it is a sign of 
something bigger that will be apparent in your coding, and maybe your 
life.  If you spend your time trying to keep your job, rather than doing 
your job, you are likely to lose your job.  Two of my unfortunate 
colleagues found that out the hard way recently...
I should have put that smiley after the last sentence instead of where I did. It was a 
joke. I'm currently going through and cleaning up all my code and moving all common code 
to my module.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: OT: Re: subroutine definitions

2004-03-08 Thread Andrew Gaffney
Charles K. Clarkson wrote:
Andrew Gaffney <[EMAIL PROTECTED]> wrote:
: 
: I'm currently going through and cleaning up all my code 
: and moving all common code to my module.

Get used to doing it. In about a year you'll wonder
why you did it that way and how you did anything with
such terrible programming.
A year? Try right now. When I originally started this project over 2 years ago (I was 17 
and had done nothing like this before) I wrote all the CGI scripts in C++ using the 
mysql++ interface library. That was a mess. It was also slow as hell. I rewrote one of the 
larger scripts in Perl (when I originally started learning it about a year ago) and it was 
about 5 times faster, which didn't make much sense.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: True IP behind a router?

2004-03-10 Thread Andrew Gaffney
Bee wrote:
> Hi, 
> 
> Is there any modules can check my true IP( NOT 192.168.x.x ) I am on while I am 
> behind
>  a router? 

You can use a Perl module (or external system call) to go to http://privacy.net/ which
will show the router's IP at the top of the page. You can then use regex to grab the 
IP.

-- 
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


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




using Expect to change password

2004-03-15 Thread Andrew Gaffney
I've read through the Expect.pm documentation and looked at what few examples I could 
find, but I still can't figure out how to use Expect to interact with the 'passwd' 
program. Can anyone point me to an example that does this? Thanks.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: using Expect to change password

2004-03-15 Thread Andrew Gaffney
Andrew Gaffney wrote:
I've read through the Expect.pm documentation and looked at what few 
examples I could find, but I still can't figure out how to use Expect to 
interact with the 'passwd' program. Can anyone point me to an example 
that does this? Thanks.
I figured it out, mostly. I can get it to work on the command line, but not in CGI.

command line version:


#!/usr/bin/perl
use Expect;

my $user = shift;
my $password = shift;
print "Running 'sudo passwd ${user}'\n";
my $exp = Expect->spawn("sudo passwd ${user}") or die "Can't run 'sudo passwd 
${user}'\n";
$exp->expect(1000,
 [qr'New UNIX password: $',
  sub {
my $fh = shift;
$fh->send("${password}\n");
print "sent '${password}'\n";
exp_continue;
  }
 ],
 [qr'Retype new UNIX password: $',
  sub {
my $fh = shift;
$fh->send("${password}\n");
print "sent '${password}'\n";
#exp_continue;
  }
 ]);

and the output is:

Running 'sudo passwd agaffney'
New UNIX password: sent '*'
BAD PASSWORD: it is too short
Retype new UNIX password: sent '*'
and the CGI version:


#!/usr/bin/perl
use Expect;
use CGI;
my $cgi = new CGI;
my $p = $cgi->Vars;
print $cgi->header;
my $exp = Expect->spawn("sudo passwd $p->{user}") or die "Can't run 'sudo passwd 
$p->{user}'\n";
print "Running 'sudo passwd $p->{user}' with password '$p->{password}'";
$exp->expect(1000,
 [qr'New UNIX password: $',
  sub {
my $fh = shift;
$fh->send("$p->{password}\n");
print "Sent '$p->{password}'";
exp_continue;
  }
 ],
 [qr'Retype new UNIX password: $',
  sub {
my $fh = shift;
$fh->send("$p->{password}\n");
print "Sent '$p->{password}'";
#exp_continue;
  }
 ]);


and the output is:

Running 'sudo passwd agaffney' with password '*'
New UNIX password: New UNIX password: New UNIX password: passwd: Conversation error
Why doesn't the CGI version work? Any help is greatly appreciated.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



weird Perl errors

2004-03-18 Thread Andrew Gaffney
I keep getting the following errors in my Apache error log every time a certain script is run:

Prototype mismatch: sub Apache::ROOT::cgi_2dbin::showday_2epl::time2str vs ($;$$) at 
/usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4
Prototype mismatch: sub Apache::ROOT::cgi_2dbin::showday_2epl::strftime vs ($\@;$) at 
/usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4
Prototype mismatch: sub Apache::ROOT::cgi_2dbin::showday_2epl::ctime vs ($;$) at 
/usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4
Prototype mismatch: sub Apache::ROOT::cgi_2dbin::showday_2epl::asctime vs (\@;$) at 
/usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4

Relevant lines of showday.pl are:

#!/usr/bin/perl

use CGI;
use Date::Format; # line 4
use Time::Local;
Can anyone tell me how to get these errors/warnings to stop popping up everytime this 
script is run? This script is run a lot and it's filling up my error log.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: weird Perl errors

2004-03-19 Thread Andrew Gaffney
Randy W. Sims wrote:
On 03/19/04 00:58, Andrew Gaffney wrote:

I keep getting the following errors in my Apache error log every time 
a certain script is run:

Prototype mismatch: sub 
Apache::ROOT::cgi_2dbin::showday_2epl::time2str vs ($;$$) at 
/usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4
Prototype mismatch: sub 
Apache::ROOT::cgi_2dbin::showday_2epl::strftime vs ($\@;$) at 
/usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4
Prototype mismatch: sub Apache::ROOT::cgi_2dbin::showday_2epl::ctime 
vs ($;$) at /usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4
Prototype mismatch: sub Apache::ROOT::cgi_2dbin::showday_2epl::asctime 
vs (\@;$) at /usr/lib/perl5/5.8.0/Exporter.pm line 59.
 at /home/httpd/cgi-bin/showday.pl line 4

Relevant lines of showday.pl are:

#!/usr/bin/perl

use CGI;
use Date::Format; # line 4
use Time::Local;
Can anyone tell me how to get these errors/warnings to stop popping up 
everytime this script is run? This script is run a lot and it's 
filling up my error log.


Looks like you are using two modules that define the same subs. You 
should block the exported subs in one of the modules and just use the 
fully qualified names:

use Date::Format (); # Don't import subs.
...
Date::Format::asctime(); # use fully qualified names
Alternatively you can just import the subs that you want from each of 
the modules you use, making sure not to import two functions of the same 
name. This is generally a good practice anyway.
That worked perfectly. Thanks. I'm just wondering where the other versions of those 
functions were defined.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



using DBI to form query with variables that have quotes

2004-03-19 Thread Andrew Gaffney
Damn, that's a mouthful. Hopefully someone understands it ;) I'm writing a script to take 
an existing data source (tab delimeted text file exported from Word doc w/ table) and 
insert the data into a MySQL DB using DBI. My problem is that some of the fields are 
either quoted ("") or have apostrophes ('), so I can't quote the data in the query without 
something fouling up (MySQL chokes on the query because of the weird quoting). Can someone 
help?

$dbh->do("INSERT INTO people VALUES(NULL, '$parts[1]', '$parts[2]', '$parts[3]', ");

Example:

INSERT INTO people VALUES(NULL, "Firstname", "Lastname", ""123 Anywhere Address"", 
...");
INSERT INTO people VALUES(NULL, "Firstname", "Lastname", '123 O'Walley Street', ...");
See the problem? I can't use either quoting consistently due to the nature of the data I'm 
working with.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: using DBI to form query with variables that have quotes

2004-03-20 Thread Andrew Gaffney
WC -Sx- Jones wrote:
Andrew Gaffney wrote:

INSERT INTO people VALUES(NULL, "Firstname", "Lastname", ""123 
Anywhere Address"", ...");
INSERT INTO people VALUES(NULL, "Firstname", "Lastname", '123 O'Walley 
Street', ...");

See the problem? I can't use either quoting consistently due to the 
nature of the data I'm working with.


Clean the data before saving it?

s,^["'],,; # Kill Starting Quotes
s,["']$,,; # Kill Ending Quotes
Or convert them to a storable
character: | for " and ~ for '
I ended up stripping double quotes (s/\"//g) and escaping single quotes (s/\'/\\'/g). This 
seems to work for me.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: using DBI to form query with variables that have quotes

2004-03-20 Thread Andrew Gaffney
Wiggins d'Anconia wrote:
Andrew Gaffney wrote:

WC -Sx- Jones wrote:

Andrew Gaffney wrote:

INSERT INTO people VALUES(NULL, "Firstname", "Lastname", ""123 
Anywhere Address"", ...");
INSERT INTO people VALUES(NULL, "Firstname", "Lastname", '123 
O'Walley Street', ...");

See the problem? I can't use either quoting consistently due to the 
nature of the data I'm working with.




Clean the data before saving it?

s,^["'],,; # Kill Starting Quotes
s,["']$,,; # Kill Ending Quotes
Or convert them to a storable
character: | for " and ~ for '


I ended up stripping double quotes (s/\"//g) and escaping single 
quotes (s/\'/\\'/g). This seems to work for me.

This is a lazy hack and a bad habit to get into, IMO.  DBI provides 
various useful ways to allow your data to not be corrupted (aka changed) 
while allowing your code to be cross platform and cross DB compatible.

Do what you will, but this is one of the first things I would clean up 
when arriving on a project that uses this "fix".
This is a one time "fix". I writing a web-based client directory for a lawyer. He 
currently keeps all his client contact information in a 137 page Word document with a 
table. I'm using Word and Excel to get the data in a tab delimeted form to pull apart with 
Perl and insert into the DB. The data is in horrible shape and I'm just doing whatever I 
can to get it into the DB.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



extracting data from table embedded in Word document

2004-03-20 Thread Andrew Gaffney
I'm writing a web-based client information system for a lawyer. His current client list is 
in a 137 page Word document with an embedded table. I can get it into a somewhat usable 
format by copying the entire table, pasting into Excel, and saving as tab delimeted text, 
but this has its problems.

Some of the cells in the table have newlines in them. Because of this, when it's exported 
from Excel, the 2nd line will appear in the correct field, but on a line by itself:

Row 1   Firstname   LastnameAddress CityState   Zip Phone   
AnotherPhone
Row 2   First2  LastaddyCityState   Zip 555-
So it looks like 3 records instead of 2. Does anyone have any ideas on how to pick apart 
the data to get it into the DB?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: extracting data from table embedded in Word document

2004-03-20 Thread Andrew Gaffney
R. Joseph Newton wrote:
Andrew Gaffney wrote:


I'm writing a web-based client information system for a lawyer.


[OT}
Eek!!  Be very, very careful about security, please.  I trust your employer has taken 
"duty of
care" isuues into account.
[/OT]

His current client list is
in a 137 page Word document with an embedded table. I can get it into a somewhat usable
format by copying the entire table, pasting into Excel, and saving as tab delimeted 
text,
but this has its problems.
Some of the cells in the table have newlines in them. Because of this, when it's 
exported
from Excel, the 2nd line will appear in the correct field, but on a line by itself:
Row 1,   Firstname,   Lastname,Address, City,State,   Zip, Phone,
Don't export as space,-delimited.  Use CSV, which is much more portable.
That was what I wanted to do in the first place, but Word doesn't support exporting a 
document with a table as CSV.

Row 2,   First middle,  Last,   addy,City,State,   Zip, 555-

So it looks like 3 records instead of 2. Does anyone have any ideas on how to pick 
apart
the data to get it into the DB?
The problem here is more one of datqa design, specifically data normalization, than
formatting.  Neither documents nor spreadsheets are really good storage methods for 
large
scale data.  For long-term robustness, this data should probably be in a normalized 
database.
Multi-valued fields generally indicate data that should be broken out into a table of 
its own:
Believe me, I cringed when I saw this Word doc. I'm writing this script to import the data 
in the Word doc into a MySQL DB in order to do away with the doc. I will personally be 
overwriting the Word docs with /dev/zero multiple times once I'm done ;)

Now as far as the particular mehtod to use for picking the data apart, that depends. 
Is the
phone number the only  multivalued field?  If so it should be fairly straightforward.  
  It
would help if we could actually see some of the data you have to work with.  Might be 
a bit of
work, since you will have to sustitute aliases--but realistic please, for any 
identifying
information.
The phone number isn't the only field like that. Just scanning through the doc, I see this 
problem in most of the fields at some point in the doc.

Greetings! C:\Documents and Settings\rjnewton>perl -w
my @rows;
push @rows, $_ while ;
chomp @rows;
my %phones;
my $current_row_tag;
my %data_rows;
foreach $row (@rows) {
   last unless $row =~ /\S/;
   if ($row =~ /^\w/) {
  my ($row_tag, $given_name, $last_name, $streetaddress, $city, $state,
  $zip, $phone) = split /,\s*/, $row;
 $phones{$row_tag} = [];
 push @{$phones{$row_tag}}, $phone;
 my $customer_data = {};
 $customer_data->{'given name'} = $given_name;
 $customer_data->{'last name'} = $last_name;
 $customer_data->{'street address'} = $streetaddress;
 $customer_data->{'City'} = $city;
 $customer_data->{'State'} = $state;
 $customer_data->{'Zip'} = $zip;
 $data_rows{$row_tag} = $customer_data;
 $current_row_tag = $row_tag;
   } else {
  $row =~ s/^\s*//;
  $row =~ s/\s*$//;
  push @{$phones{$current_row_tag}}, $row;
   }
}
foreach $client_id (sort keys %data_rows) {
   my $client = $data_rows{$client_id};
   print "$client->{'given name'} $client->{'last name'}\n";
   print "$_\n" foreach @{$phones{$client_id}};
}
The above code won't work because it splits on a comma. A lot of the fields contain a 
comma somewhere within the actual data. If it was easy as that, I would have had this done 
long ago ;)

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: extracting data from table embedded in Word document

2004-03-20 Thread Andrew Gaffney
Andrew Gaffney wrote:
I'm writing a web-based client information system for a lawyer. His 
current client list is in a 137 page Word document with an embedded 
table. I can get it into a somewhat usable format by copying the entire 
table, pasting into Excel, and saving as tab delimeted text, but this 
has its problems.

Some of the cells in the table have newlines in them. Because of this, 
when it's exported from Excel, the 2nd line will appear in the correct 
field, but on a line by itself:

Row 1FirstnameLastnameAddressCityStateZip
Phone   
AnotherPhone
Row 2First2LastaddyCityStateZip555-

So it looks like 3 records instead of 2. Does anyone have any ideas on 
how to pick apart the data to get it into the DB?
I managed to get Word to export it into a format where the fields are separated by '\r'. 
Yeah, kinda weird. I wrote the following:

open FILE, $file;
my $counter = 0;
while () {
  while (/\r?([^\r]*)/sgc) {
$counter++;
if($counter == 10) {
  print "\n\n";
  $counter = 1;
}
my $temp = $1;
$temp =~ s/\n/~~~/sg;
$temp =~ s/\"//g;
$temp =~ s/\'/\\'/g;
print " $temp ";
  }
}
This should print the contents of each field as it reads it, which it does seem to be 
doing. The only problem is that it seems to be printing "\n\n" after only 7 fields. Also, 
will that regex get everything I want it to? I need to capture everything between each set 
of '\r' including the first field which only has a trailing '\r'.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



displaying ASCII value of character

2004-03-20 Thread Andrew Gaffney
I have a non-printable character that I'm trying to match in a regex, but I can't figure 
out what it is. If I know it comes after '~~~' in a string, how can I show its value? I tried:

s/~~~(.?)/sprintf "|%d|", $1/se;

but that just displays '|0|' which I don't think is right because it shows as a CRLF on 
the terminal. I have an input file which has data between '\r' characters. Some of these 
fields contain '\n' and the mystery character. I have a regex which changes any '\n' to '~~~':

s/\n+/~~~/sg;

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: displaying ASCII value of character

2004-03-20 Thread Andrew Gaffney
Andrew Gaffney wrote:
I have a non-printable character that I'm trying to match in a regex, 
but I can't figure out what it is. If I know it comes after '~~~' in a 
string, how can I show its value? I tried:

s/~~~(.?)/sprintf "|%d|", $1/se;

but that just displays '|0|' which I don't think is right because it 
shows as a CRLF on the terminal. I have an input file which has data 
between '\r' characters. Some of these fields contain '\n' and the 
mystery character. I have a regex which changes any '\n' to '~~~':

s/\n+/~~~/sg;
Why can't I figure out what's there?

Name^M~~
^MAddres
That is some sample input after the following regex's have been run on it:

s/\r\n/~~/sg;
s/~~./~~!/sg;
The '~~' in the input was put there in place of a '\r\n'. The '^M' is a '\r'. What is 
causing the carriage return after '~~'? There's obviously something there if it's causing 
a carriage return in the output. Shouldn't the second regex catch whatever is there?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: displaying ASCII value of character

2004-03-21 Thread Andrew Gaffney
Andrew Gaffney wrote:
Andrew Gaffney wrote:

I have a non-printable character that I'm trying to match in a regex, 
but I can't figure out what it is. If I know it comes after '~~~' in a 
string, how can I show its value? I tried:

s/~~~(.?)/sprintf "|%d|", $1/se;

but that just displays '|0|' which I don't think is right because it 
shows as a CRLF on the terminal. I have an input file which has data 
between '\r' characters. Some of these fields contain '\n' and the 
mystery character. I have a regex which changes any '\n' to '~~~':

s/\n+/~~~/sg;


Why can't I figure out what's there?

Name^M~~
^MAddres
That is some sample input after the following regex's have been run on it:

s/\r\n/~~/sg;
s/~~./~~!/sg;
The '~~' in the input was put there in place of a '\r\n'. The '^M' is a 
'\r'. What is causing the carriage return after '~~'? There's obviously 
something there if it's causing a carriage return in the output. 
Shouldn't the second regex catch whatever is there?
It turns out that there was nothing there. I was reading the file one line at a time. I 
could strip out the '\r\n' but the line break was already there.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: extracting data from table embedded in Word document

2004-03-21 Thread Andrew Gaffney
Charles K. Clarkson wrote:
Andrew Gaffney <[EMAIL PROTECTED]> wrtoe:
: 
: I managed to get Word to export it into a format where
: the fields are separated by '\r'. Yeah, kinda weird. I
: wrote the following:
: 
: open FILE, $file;
: my $counter = 0;
: 
: while () {
:while (/\r?([^\r]*)/sgc) {
:  $counter++;
:  if($counter == 10) {
:print "\n\n";
:$counter = 1;
:  }
:  my $temp = $1;
:  $temp =~ s/\n/~~~/sg;
:  $temp =~ s/\"//g;
:  $temp =~ s/\'/\\'/g;
:  print " $temp ";
:}
: }
: 
: This should print the contents of each field as it
: reads it, which it does seem to be doing. The only
: problem is that it seems to be printing "\n\n"
: after only 7 fields. Also, will that regex get
: everything I want it to? I need to capture
: everything between each set of '\r' including the
: first field which only has a trailing '\r'.

   Can you provicde some test data?
No, I can't. The data I'm working with is a lawyer's client list. I figured it out anyway. 
There were embedded '\r\n' in some of the field. My program was interpreting this as 2 
more fields, one with a '\n'. I just wrote a regex to filter any occurences of '\r\n' and 
the problem went away.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: extracting data from table embedded in Word document

2004-03-21 Thread Andrew Gaffney
R. Joseph Newton wrote:
Andrew Gaffney wrote:



The above code won't work because it splits on a comma. A lot of the fields contain a
comma somewhere within the actual data. If it was easy as that, I would have had this 
done
long ago ;)
--
Andrew Gaffney


Hi Andrew,

Don't count on it not being that easy.  Are you using the native capacities of the 
application to
their best.  I'm presuming here that a lawyer will have a full M$ Office suite, if 
they are u8sing
the tools at all.  You can paste tables from Word docs into Excel, and exoprt as CSV 
from there.
Excel should have a much broader range of data export filters.
It sound, though, like you will have a major job of normalization ahead.  I would 
foresee a bit of
hand work in the data design.  One interim step you might take, for multivalued 
fields, is to
concatenate them with some nuetral delimiter, such as a semi-colon.  This way, as you 
normalize to
break out any given field, you can use the Text::CSV module to get your fields, then 
split the
fields of interest on the semicolons.
If this material is already in an Office format, though, I would definitely recommend 
that you do as
much as possible within Office.  There is so much solid built-in functionality there 
that it
wouldn't make sense to low-level something you can do with a macro.
I tried copying from Word and pasting to Excel first. Excel would only let me export as 
tab delimeted text, which was fine. The problem was the fields with embedded '\r\n' which 
completely fscked up the output.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Using Perl Expect.pm

2004-03-25 Thread Andrew Gaffney
TapasranjanMohapatra wrote:
Hi,
Can someone tell me how to handle the vt100 sequences using expect module of perl.
 I have used the same sequences while using TCL Expect. It works fine. But I don't understand what is the problem while I try doing the same thing using Perl Expect.
 If my TCL Expect Code goes like:-
 
 send "\x09" # hexadecimal equivalent of a tab
 expect "\x1b?2;2H"

What should be the equivalent Perl code?
I am able to send "\x09" in perl but I think it doesn't expect the correct thing. 
Perhaps the semicolon has to be escaped but even after escaping the semicolon didn't solve the 
problem.
Can someone give some help or reference link where I can learn what these values
like "\x1b?2;2H"  mean.
Most likely, the problem is that Perl is interpreting what is in the quotes first. Try 
putting it in single quotes when you pass it to expect.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



date math

2004-03-27 Thread Andrew Gaffney
I'm looking for a way to do some date math. I'm working on a payroll tracking system. I 
want to provide a list of 2 week periods for the user to select. These periods start from 
a hard-coded known start of pay period date. I want it to display the 6 most recent 2 week 
periods. For example, my known start of pay period date is '2004-03-21.'. I want to count 
off 2 week periods from that. So, my program should be able to give me '2004-03-21 - 
2004-04-03', '2004-04-04 - 2004-04-17', '2004-04-18 - 2004-05-01', etc. Once I have my 
list, I can then find out which ones are the most recent and display them to the user. I 
also need to be able to determine if a certain date is between 2 dates. I really only need 
help with the date math part. Everything else I can do. Is there a module that can help me?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: date math

2004-03-27 Thread Andrew Gaffney
Chris Charley wrote:
Hello Andrew

I've enclosed a text file that demonstrates Date::Simple.

HTH
Chris
- Original Message - 
From: "Andrew Gaffney" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: "beginners" <[EMAIL PROTECTED]>
Sent: Saturday, March 27, 2004 7:52 PM
Subject: date math



I'm looking for a way to do some date math. I'm working on a payroll
tracking system. I

want to provide a list of 2 week periods for the user to select. These
periods start from

a hard-coded known start of pay period date. I want it to display the 6
most recent 2 week

periods. For example, my known start of pay period date is '2004-03-21.'.
I want to count

off 2 week periods from that. So, my program should be able to give me
'2004-03-21 -

2004-04-03', '2004-04-04 - 2004-04-17', '2004-04-18 - 2004-05-01', etc.
Once I have my

list, I can then find out which ones are the most recent and display them
to the user. I

also need to be able to determine if a certain date is between 2 dates. I
really only need

help with the date math part. Everything else I can do. Is there a module
that can help me?



#!/usr/bin/perl
use strict;
use warnings;
use Date::Simple;
my $start = "2004-03-21";
my $start_date = Date::Simple->new($start);
my @output;

for (1..6) {
push @output, [$start_date, $start_date + 13];
$start_date += 14;
}
print map {join(" :: ", $_->[0], $_->[1]), "\n"} @output;

# Find if date between 2 dates
my $first  = Date::Simple->new("2004-06-01");
my $second = Date::Simple->new("2004-08-01");
my $fourth_of_july = Date::Simple->new("2004-07-04");
if ($first < $fourth_of_july && $fourth_of_july < $second) {
print "$fourth_of_july falls between $first and $second\n";
}
Thanks. That helps a lot.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: date math

2004-03-28 Thread Andrew Gaffney
Chris Charley wrote:
Hello Andrew

I've enclosed a text file that demonstrates Date::Simple.

HTH
Chris
- Original Message - 
From: "Andrew Gaffney" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: "beginners" <[EMAIL PROTECTED]>
Sent: Saturday, March 27, 2004 7:52 PM
Subject: date math



I'm looking for a way to do some date math. I'm working on a payroll
tracking system. I

want to provide a list of 2 week periods for the user to select. These
periods start from

a hard-coded known start of pay period date. I want it to display the 6
most recent 2 week

periods. For example, my known start of pay period date is '2004-03-21.'.
I want to count

off 2 week periods from that. So, my program should be able to give me
'2004-03-21 -

2004-04-03', '2004-04-04 - 2004-04-17', '2004-04-18 - 2004-05-01', etc.
Once I have my

list, I can then find out which ones are the most recent and display them
to the user. I

also need to be able to determine if a certain date is between 2 dates. I
really only need

help with the date math part. Everything else I can do. Is there a module
that can help me?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548




#!/usr/bin/perl
use strict;
use warnings;
use Date::Simple;
my $start = "2004-03-21";
my $start_date = Date::Simple->new($start);
my @output;

for (1..6) {
push @output, [$start_date, $start_date + 13];
$start_date += 14;
}
print map {join(" :: ", $_->[0], $_->[1]), "\n"} @output;

# Find if date between 2 dates
my $first  = Date::Simple->new("2004-06-01");
my $second = Date::Simple->new("2004-08-01");
my $fourth_of_july = Date::Simple->new("2004-07-04");
if ($first < $fourth_of_july && $fourth_of_july < $second) {
print "$fourth_of_july falls between $first and $second\n";
}
My code ended up looking like:

my @payperiods;
my @finalpayperiods;
my $lastperiodend = Date::Simple->new('2004-01-10');
while() {
  my $newstart = $lastperiodend + 1;
  my $newend = $newstart + 13;
  my @lt = localtime;
  last if(Date::Simple->new($lt[5]+1900, $lt[4]+1, $lt[3]) < $newstart);
  push @payperiods, "$newstart to $newend";
  $lastperiodend = $newend;
}
my $periodcounter = 0;
foreach(reverse @payperiods) {
  $periodcounter++;
  last if($periodcounter > 6);
  push @finalpayperiods, $_;
}
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: date math

2004-03-28 Thread Andrew Gaffney
R. Joseph Newton wrote:
Andrew Gaffney wrote:

My code ended up looking like:
use strict;
use warnings;
This code is running under mod_perl, so I think both of those are already being used.

use constant PAY_PERIOD_DAYS => 14;
Good idea. I never use constants. My code makes sense to me, but few others for this reason ;)

my @payperiods;
Underscores are both permissible and advisable in variable names:
my @pay_periods;
Another good idea. Readability is good.

my @finalpayperiods;
my $lastperiodend = Date::Simple->new('2004-01-10');
while() {
  my $newstart = $lastperiodend + 1;
Good enough.  $new_start should take the value following  $last_period_end.


  my $newend = $newstart + 13;
This works, but could be more clear.  The number 13 here is sort of a "magic
number", which requires reading contextual code to understand.  Better to use
the size of the pay period
my $new_end = $last_period_end + 14;
or
my $new_end = $last_period_end + PAY_PERIOD_DAYS;
  my @lt = localtime;
  last if(Date::Simple->new($lt[5]+1900, $lt[4]+1, $lt[3]) < $newstart);
This probably does what you want, but what does it mean?  It may seem strange to
say this about a single line, but I think this should be in a function of its
own, if only so that it has a logiacl identifier.  Hmmm, actually, this probably
should not be inside the loop at all.  Unless you expect some significant change
in the local time values between iterations of the loop, you should perform the
creation of the new Date::Simple object only once, then compare the object as
you go through the loop.
That line creates a date object for today. It ended up there because I was originally 
looking at the documentation for v2.03 of Date::Simple when I only have v1.03 installed. 
There is a today() call in 2.03. So, it was 'last if(Date::Simple::today() < $newstart);'.

Better yet, you should have this in the loop control, since controlling the
execution of the loop is its purpose.
while($last_period_end < $current_date - 1) {

  push @payperiods, "$newstart to $newend";
  $lastperiodend = $newend;
}
my $periodcounter = 0;
=item remove complicated stuff

foreach(reverse @payperiods) {
  $periodcounter++;
  last if($periodcounter > 6);
  push @finalpayperiods, $_;
}
=cut

for (1..6) {
push @final_pay_periods, pop @pay_periods;
}
I didn't do it this way because there is a "first" pay period. If there are only 2 pay 
periods from the starting date, you can't build a list of 6. My way takes that into 
account. Below is the modified code based on (most of) your suggestions.

use constant PAY_PERIOD_DAYS => 14;
my @pay_periods;
my @final_pay_periods;
my $last_period_end = Date::Simple->new('2004-03-20');
my @lt = localtime;
my $today = Date::Simple->new($lt[5]+1900, $lt[4]+1, $lt[3]);
while($today > $last_period_end + 1) {
  my $new_start = $last_period_end + 1;
  my $new_end = $last_period_end + PAY_PERIOD_DAYS;
  push @pay_periods, "$new_start to $new_end";
  $last_period_end = $new_end;
}
my $period_counter = 0;
foreach(reverse @pay_periods) {
  $period_counter++;
  last if($period_counter > 6);
  push @final_pay_periods, $_;
}
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Find User Apache is running as

2004-03-28 Thread Andrew Gaffney
JupiterHost.Net wrote:
Hello List!

I was trying to figure out how to see the user the script/webserver is 
running as. (Like Apache is 'nobody' or the owner 'foomonkey' perhaps 
with SuExec enabled)

I looked in %ENV and didn't see it in there.

Any ideas?
If you're running Linux (might work on other UNIXs too), you can run 'ps aux | grep 
apache' (Apache 2.x) or 'ps aux | grep httpd' (Apache 1.x). The first column is the user 
it's running as.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: date math

2004-03-29 Thread Andrew Gaffney
Chris Charley wrote:
"Andrew Gaffney" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
R. Joseph Newton wrote:

Andrew Gaffney wrote:


[snip]


I didn't do it this way because there is a "first" pay period. If there
are only 2 pay

periods from the starting date, you can't build a list of 6. My way takes
that into

account. Below is the modified code based on (most of) your suggestions.

use constant PAY_PERIOD_DAYS => 14;
my @pay_periods;
my @final_pay_periods;
my $last_period_end = Date::Simple->new('2004-03-20');



my @lt = localtime;
my $today = Date::Simple->new($lt[5]+1900, $lt[4]+1, $lt[3]);


Here you could just say:

my $today = Date::Simple->new;



while($today > $last_period_end + 1) {
  my $new_start = $last_period_end + 1;
  my $new_end = $last_period_end + PAY_PERIOD_DAYS;
  push @pay_periods, "$new_start to $new_end";


You can make the list ordered from most recent period to least recent
by saying:
unshift @pay_periods, "$new_start to $new_end";



  $last_period_end = $new_end;
}


> my $period_counter = 0;
> foreach(reverse @pay_periods) {
>$period_counter++;
>last if($period_counter > 6);
>push @final_pay_periods, $_;
> }
Not necessary to do the above, but need this statement to
limit @pay_periods to most recent 6 periods (if there are 6)
splice @pay_periods, 6 if @pay_periods > 6;
All good suggestions. Thanks. My code is now:

use constant PAY_PERIOD_DAYS => 7; # Boss wanted it changed to 1 week from 2
my @pay_periods;
my $last_period_end = Date::Simple->new('2004-01-10');
my $today = Date::Simple->new;
while($today > $last_period_end + 1) {
  my $new_start = $last_period_end + 1;
  my $new_end = $last_period_end + PAY_PERIOD_DAYS;
  unshift @pay_periods, "$new_start to $new_end";
  $last_period_end = $new_end;
}
splice @pay_periods, 6 if @pay_periods > 6;
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
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 happening here

2004-03-29 Thread Andrew Gaffney
WC -Sx- Jones wrote:
What is happening here -

#! /usr/bin/perl
use strict;
use warnings;
my $count;

while(1) {
  (++$count) ? $count += $count-- : $count += $count++;
  print "$count\n"; exit if $count > 60_000;
  sleep 1;
}
__END__
-Sx-
That is a damn good question. I'm not sure what results I was expecting when I ran it, but 
it sure wasn't this:

3
15
63
255
1023
4095
16383
65535
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



determing number of records returned with DBI

2004-03-30 Thread Andrew Gaffney
Is there a way to find out how many records were returned with a DBI query? There's the 
obvious counting each record as you fetch it, but I need the count before I start going 
through them.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: determing number of records returned with DBI

2004-03-30 Thread Andrew Gaffney
Guay Jean-Sébastien wrote:
Hello Andrew,


Is there a way to find out how many records were returned 
with a DBI query? There's the 
obvious counting each record as you fetch it, but I need the 
count before I start going 
through them.


I was looking through the DBI documentation (perldoc DBI) not long ago and
this caught my eye... It's in the "Statement Handle Methods" section. Just
proof that sometimes the info is there, but it's hard to find or buried in a
very big man page (which certainly is the case for the DBI man page...).
< snip >
rows
  $rv = $sth->rows;

Returns the number of rows affected by the last row affecting command,
or -1 if the number of rows is not known or not available.
Generally, you can only rely on a row count after a non-SELECT execute
(for some specific operations like UPDATE and DELETE), or after fetching all
the rows of a SELECT statement.
With the mysql driver, it does return the number of fetched rows before you start 
iterating through them. It does what I need it to do. Thanks.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



need help modifying code

2004-04-06 Thread Andrew Gaffney
I have written the following code to generate HTML reports from Perl scripts. It works 
pretty well. I need to modify it to accept parameters for each column (e.g. column width, 
whether to total that column, etc.), but I can't figure out the best way to go about it.

sub generate_report_html {
  my ($title, $columns, $data) = @_;
  print <<"  EOF";



${title} Report



  EOF
  foreach (@$columns) {
print "$_";
  }
  print "\n";
  foreach my $row (@$data) {
print "";
foreach (@$row) {
  print "$_";
}
print "\n";
  }
  print <<'  EOF';



  EOF
}
The code is called like:

my $columns = ["Col1", "Col2", "Col3", "Col4"];
my @data;
while(...) {
  # Get data somehow
  push @data, ["$data1", "$data2", "$data3", "$data4"];
}
generate_report_html("report title", $columns, [EMAIL PROTECTED]);
I want to be able to call it like:

my $columns = [{width => 150, text => 'Col1', total => 0},
   {width => 100, text => 'Col2', total => 1},
   {width => 200, text => 'Col3', total => 1},
   {width => 100, text => 'Col4', total => 0}];
my @data;
while(...) {
  # Get data somehow
  push @data, ["$data1", "$data2", "$data3", "$data4"];
}
generate_report_html("report title", $columns, [EMAIL PROTECTED]);
Can anyone offer any suggestions?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



determining reference type

2004-04-06 Thread Andrew Gaffney
How do you determine what type of data a reference points to? I have a function (one in 
previous post) that can take either an array of scalars or an array of hash references. I 
want to execute different code based on which one it was. How can I do that?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: determining reference type

2004-04-06 Thread Andrew Gaffney
WC -Sx- Jones wrote:
Andrew Gaffney wrote:

How do you determine what type of data a reference points to? I have a 
function (one in previous post) that can take either an array of 
scalars or an array of hash references. I want to execute different 
code based on which one it was. How can I do that?

use the ref() function -
perldoc -f ref
sub marshall {
 my($thing) = @_;
 $type = ref($thing);
 if ($type eq "ARRAY") {
  return(encode_list($thing));
 }
 elsif ($type eq "HASH") {
  return(encode_hash($thing));
 }
 elsif (!$type) {
  return(encode_scalar($thing));
 }
 else { die("Can't handle $type\n"); }
}
http://www.usenix.org/publications/perl/perl12.html
That did the trick. Thanks.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



determining size of array through reference

2004-04-06 Thread Andrew Gaffney
I've got an array reference and I'm trying to figure out how many elements are in it. I've 
tried '$#arrayref', '[EMAIL PROTECTED]', '$(@($arrayref))', and probably a few others that I've 
forgotten. What is the correct way to do this?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: determining size of array through reference

2004-04-06 Thread Andrew Gaffney
david wrote:
Andrew Gaffney wrote:


I've got an array reference and I'm trying to figure out how many elements
are in it. I've tried '$#arrayref', '[EMAIL PROTECTED]', '$(@($arrayref))', and
probably a few others that I've forgotten. What is the correct way to do
this?


you can try @{EXP} or $#{EXP}+1 where EXP is your array reference:

[panda]# perl -le 'print $#{[1,3,5,7]}+1'
4
[panda]# perl -le 'print @{[1,3,5,7]}+0'
4
[panda]#
the '{}' is sometimes optional depends on EXP, i usually use it for personal 
perference.
'$#{$arrayref}+1' worked for me. Thanks. Once again, I don't know what I'd do without the 
people on this list.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



parsing Apache2 access log

2004-04-09 Thread Andrew Gaffney
I maintain the Perl CGI/mod_perl side of a website, and someone else maintains the static 
HTML side. Well, the htdocs dir has gotten very messy. Because of things I've done with 
CGI/mod_perl/Mason, there are many static pages that are no longer used.

I want to write a Perl script that will parse the Apache access log and keep track of the 
most recent access of each file referenced. I then want to compare this list to the 
contents of the htdocs directory. If a file exists in htdocs that was not referenced in 
the Apache access log after a certain cutoff date (or not referenced at all), I want to 
print the filename.

In effect, this will generate a list of "safe to delete" files which I will then inspect 
by hand before deleting. Is there already something like this out there or has anyone else 
done something like this? If not, is there a module that will help me parse the Apache 
access log?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: parsing Apache2 access log

2004-04-10 Thread Andrew Gaffney
Andrew Gaffney wrote:
I maintain the Perl CGI/mod_perl side of a website, and someone else 
maintains the static HTML side. Well, the htdocs dir has gotten very 
messy. Because of things I've done with CGI/mod_perl/Mason, there are 
many static pages that are no longer used.

I want to write a Perl script that will parse the Apache access log and 
keep track of the most recent access of each file referenced. I then 
want to compare this list to the contents of the htdocs directory. If a 
file exists in htdocs that was not referenced in the Apache access log 
after a certain cutoff date (or not referenced at all), I want to print 
the filename.

In effect, this will generate a list of "safe to delete" files which I 
will then inspect by hand before deleting. Is there already something 
like this out there or has anyone else done something like this? If not, 
is there a module that will help me parse the Apache access log?
I whipped up the following program myself that mostly does what I want. It still has a few 
problems. For example, it will display directories that are in /var/www/htdocs unless 
someone had specifically requested that directory without a trailing slash. It is also 
slow. It takes about 5 minutes to run this on a 200MB access_log. I realize I shouldn't be 
complaining about that, but the machine is a dual Athlon MP 2200+ w/ 1GB RAM.

#!/usr/bin/perl

use strict;
use warnings;
use CGI();
my %files;

open LOG, "< /var/log/apache/access_log";

while() {
  my $line = $_;
  $line =~ /^(\d+\.\d+\.\d+\.\d+) (.+) (.+) \[(.+)\] \"(.+) (.+) (.+)\" (\d+) (\d+) 
\"(.+)\" \"(.+)\"$/;
  my ($ip, $date, $request, $requestcode, $bytesreturned, $browser) = ($1, $4, $6, $8, 
$9, $11);

  next if($request =~ m|^/cgi-bin/|);
  $request =~ s/^\/(.+)\??/$1/;
#  $date =~ m|^(\d+)/(.+)/(\d+):|;
  $request = CGI::unescape($request);
  $files{$request} = 1;
}
close LOG;

opendir HTDOCS, "/var/www/htdocs";
my @htdocsfiles = readdir HTDOCS;
my @newhtdocsfiles;
foreach my $htdocsfile (@htdocsfiles) {
  unless(exists $files{$htdocsfile}) {
push @newhtdocsfiles, $htdocsfile;
  }
}
foreach(@newhtdocsfiles) {
  print "$_\n";
}
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



  1   2   3   4   5   6   >