Re: Newbie help

2003-07-17 Thread Paul D. Kraus
"Keith Olmstead" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> Been searching though this list for awhile now, and now I am needing some
help.  I am not asking for someone to do my code for me,  I am trying to
learn perl and the only way for me to do that is to dive staight into it.
>
> My problem is with the theory of the script that I am trying to write.  I
am needing something to backup logs for me from a central log server.  They
layout of these files are as follows.
>
> /host/ip/year/month/day/log1, log2, etc
>
> Every file and dir under dir1 is created dynamically by the logging
program, syslog-ng.
>
> What I am wanting to do is create a script that will tar and gzip the day
dirs at the end of the day and remove the dir after it has been backed up.
After the month is finished, I would like the same done for it.
>
> Currently there are 20ish host dirs, one of each server that is logging to
this box.  There will be more and when they get pointed to this server, the
ip dir will be created for that host and each dir under that will also be
created for the corresponding date.  The logs need to be kept for 2-3
months, and then deleted.
>
> I am needing help thinking this script out, maybe get ideas of how to set
it up.  From reading using File::Find, might be useful.
>
> I was thinking about writing a script that runs in cron each night that
tars and gzp the log dirs.  Currently I have a script that is getting a list
of the dir, but I don't really know  where to go from there.  I need to get
it to dive into the dir to the day lvl and archive the previous days logs.
>
> Here are 2 scripts that I have been playing with.  I don't even know if I
am going in the right direction.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $dir = '/opt/log/hosts/';
>
> opendir(DIR, $dir) or die "Cannot open Directory";
>
> # read the dir contents into a list, and grep out the . and .. dir entries
> my @entries = grep (!/^\.\.?$/ , readdir (DIR));
> closedir(DIR);
> foreach (@entries)
> {
>   print "$_\n";
> }
>
> and
>
> #!/usr/bin/perl
>
> use File::Find;
> use strict;
> use warnings;
> my $startdir = $ARGV[0];
> my @dirlist;
> find(
> sub {
> return if -d and /^\.\.?$/;
> push @dirlist, $_ if -d;
> }, $startdir);
>
> #my $file_list = join '', @dirlist;
> my $file_list = @dirlist;
> print $file_list;
>
> Like I said before, I am not asking for someone to do my work just some
guidiance in the right direction.
>
> TIA,
>
> Keith Olmstead
>
>
>

File Find is a good place to start. Also do a search on search.cpan.org for
Zip. Assuming the script is running on the server with the logs you should
be able to do everything you want with these two modules.

Paul Kraus



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



Assigning a singe value to a list

2003-07-17 Thread Paul D. Kraus
Is there a way to assign a single value to a list? other then doing the
obvious and spelling out each list assignment or running through a loop.

For instance...

my ( $var1, $var2, $var3, ... ) = "Paul"
assigning paul to all variables in the list.

or a more useful example

my  ($passed1, $passed2, ... ) = shift

Paul Kraus



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



Re: Script's Name

2003-07-17 Thread Kristofer Hoch

--- Nigel Peck - MIS Web Design <[EMAIL PROTECTED]> wrote:
> Can someone please remind a forgetful idiot how to get the name of
> the script being run (the file itself)?
> 
> Cheers,
> Nigel
> 
> MIS Web Design
> http://www.miswebdesign.com/
> 
print "Full File name: $0\n";

Forgetfulness does not automagically confer idiotism.

Kristofer


=
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GIT d s+:++ a C++ UL++ US+ P+++ L++ 
W+++ w PS PE t++ b+ G e r+++ z
--END GEEK CODE BLOCK--

__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



Re: custom return value from entire script

2003-07-17 Thread david
Mark Henry wrote:

> Hi All,
> 
> Anyone know if it's possible for the return/exit value of a script, in the
> event of success, to be something other than 0?
> 
> I want to call, from a shell script, a perl script that determines a
> certain
> record ID from a database.  When the ID has been obtained, the script
> would exit, and the calling shell script would receive the returned value.
> 
> The 'return' command doesn't allow this - I've thought of setting an env
> variable - not sure how to export it from perl so the environment sees it.
> Would like to get plan A to work first though..
> 

exit with the status you want or set $? inside END. for example:

#!/usr/bin/perl -w

use strict;

#--
#-- x.pl - does absolutely nothing except handling 10 to the shell
#--
exit 10;

#--
#-- or you could:
#--
=item samething:
END{$?=10}
=cut

__END__

and then in another script:

#!/usr/bin/perl -w

use strict;

#--
#-- y.pl - see what x.pl returns
#--
print system('x.pl') >> 8,"\n";

__END__

prints:

10

the '>> 8' portion removes the lower 8 bits of the returned 16 bit word. 
since most os use 16 bit word, your exit value should be 255 or less so if 
you do:

exit 12345;

you might not get back what you expect. your os might have larger word size 
but Perl might decided to use 16 so it's better to keep it down. 

david

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



RE: custom return value from entire script

2003-07-17 Thread wiggins


On Thu, 17 Jul 2003 17:29:49 -0400, "HENRY,MARK (HP-Roseville,ex1)" <[EMAIL 
PROTECTED]> wrote:

> Hi All,
> 
> Anyone know if it's possible for the return/exit value of a script, in the
> event of success, to be something other than 0?
> 
> I want to call, from a shell script, a perl script that determines a certain
> record ID from a database.  When the ID has been obtained, the script would
> exit, and the calling shell script would receive the returned value.
> 
> The 'return' command doesn't allow this - I've thought of setting an env
> variable - not sure how to export it from perl so the environment sees it.
> Would like to get plan A to work first though..
> 

perldoc -f exit
perldoc -f die

Should provide the answers.  Essentially you can call either with any value you want 
(though there may be a limitation on the size depending on the OS, shell, etc.).

http://danconia.org

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



custom return value from entire script

2003-07-17 Thread HENRY,MARK (HP-Roseville,ex1)
Hi All,

Anyone know if it's possible for the return/exit value of a script, in the
event of success, to be something other than 0?

I want to call, from a shell script, a perl script that determines a certain
record ID from a database.  When the ID has been obtained, the script would
exit, and the calling shell script would receive the returned value.

The 'return' command doesn't allow this - I've thought of setting an env
variable - not sure how to export it from perl so the environment sees it.
Would like to get plan A to work first though..

Many thanks,

Mark

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



Re: Script's Name

2003-07-17 Thread Jenda Krynicky
From:   "Nigel Peck - MIS Web Design" <[EMAIL PROTECTED]>
> Can someone please remind a forgetful idiot how to get the name of the
> script being run (the file itself)?

$0

See 
perldoc perlvar

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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



RE: Script's Name

2003-07-17 Thread Tony Esposito
If I understand you're question correctly, you can get the basename of the
script that you are running ( i.e., minus the extension ) with the code:

my ($basename) = fileparse($0, '\..*');

> Anthony (Tony) Esposito
> Senior Technical Consultant 
> Inovis(tm)
> 2425 N. Central Expressway, Suite 900 
> Richardson, TX  75080 
> (972) 643-3115 
> [EMAIL PROTECTED] 
> 


-Original Message-
From: Nigel Peck - MIS Web Design [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 17, 2003 4:13 PM
To: Kristofer Hoch; [EMAIL PROTECTED]
Subject: Script's Name


Can someone please remind a forgetful idiot how to get the name of the
script being run (the file itself)?

Cheers,
Nigel

MIS Web Design
http://www.miswebdesign.com/


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

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



Script's Name

2003-07-17 Thread Nigel Peck - MIS Web Design
Can someone please remind a forgetful idiot how to get the name of the script being 
run (the file itself)?

Cheers,
Nigel

MIS Web Design
http://www.miswebdesign.com/


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



RE: trying out examples in Oreilly's Perl Graphics Programming

2003-07-17 Thread Joel Lopez
I finally got the script to work!!  Thanks for all your help and
suggestions.
http://shawn.apocabilly.org/PGP/examples/example2-1.txt

I had to add the line:
binmode STDOUT;

right before the last line:
print $image->png;

A friend of mine was able to get it to work without adding that line.  Is
there some setting that I didn't set or is this normal for a default install
of perl on RH 8?

Thanks again,
Joel

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 16, 2003 1:59 PM
To: Joel Lopez; [EMAIL PROTECTED]
Subject: RE: trying out examples in Oreilly's Perl Graphics Programming


Please don't top post...


On Wed, 16 Jul 2003 13:11:57 -0700, "Joel Lopez"
<[EMAIL PROTECTED]> wrote:

> Hi,
>
> using this seems to get rid of the garbled stuff:
>   ./helloworld2 > output.png
>
> Is output.png supposed to be an existing image or is it one that is
created
> on the fly?
>

It is created on the fly.

> The code refers to the book authors home directory:
>
> my ($x1, $y1, $x2, $y2,
> $x3, $y3, $x4, $y4) = $image->stringFT($black,
> "/home/shawn/arial.ttf", 48, 0, 40, 120, "Hello World");
>

arial.ttf is the font that will be used for the words "Hello World" probably
you need to replace that location with the path to a similar (Truetype) font
on your local computer.

> Is this where the image is read from or created to?  The book site doesn't
> give an image to work with.
>

Neither. The image is essentially just a set of properties stored in a Perl
object. Then when you have finished manipulating the object you call the
'png' method on the object to magically transform your Perl object into
image data (a PNG) that can then be used in some way, specifically in the
example it is printed to STDOUT.

That is why I had you redirect the output into a file, namely output.png
which is your newly generated image. If it were a CGI for example, you would
want to print the proper MIME header, and then just print the data to
STDOUT, but from a terminal window that is not terribly helpful.

> thanks for helping a lost man,

You will get there, somewhat complicated at first but once the samples make
sense it is pretty much boundless what you can accomplish.

http://danconia.org

>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 16, 2003 12:22 PM
> To: Joel Lopez; [EMAIL PROTECTED]
> Subject: RE: trying out examples in Oreilly's Perl Graphics Programming
>
>
>
> 
> On 16 Jul 2003 11:28:31 -0700, Joel Lopez
<[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
> >
> > I have been trying to get this perl script to work, but I'm can't seem
> > to figure out why it's not working.  You can see it here:
> >
> > http://shawn.apocabilly.org/PGP/examples/example2-1.txt
> >
> > When I run it I get this on my screen:
> >
> > [EMAIL PROTECTED] imagemagick]# ./helloworld2
> > Use of uninitialized value in subtraction (-) at ./helloworld2 line 31.
> > Use of uninitialized value in addition (+) at ./helloworld2 line 31.
> > Use of uninitialized value in addition (+) at ./helloworld2 line 31.
> > Use of uninitialized value in subtraction (-) at ./helloworld2 line 31.
> > ‰PNG
>
> 
>
> >
> > I first typed it in, but then after I couldn't get it to work I copied
> > and pasted it into a file.
> >
> > I'm using Red Hat 8 and have updated the libgd C library to version
> > 1.8.4 and then used cpan to install GD.
> >
> > I ran the demo for libgd and it made the graphic it was supposed to so I
> > think it's working ok.  Is there anyway to find out if everything is
> > installed correctly?
> >
>
> What makes you think it didn't work correctly? The script just prints the
> image data to the screen, which is basically what that garbled mess was in
> your e-mail.  Try opening a file to write the image to, then print it to
the
> handle, then open the image in a image viewer
>
> As an option first try to capture the output of the script to a file and
> open that in the image viewer:
>
> ./helloworld2 > output.png
>
> The other messages are just warnings that we can help you get rid of
later.
>
> http://danconia.org
>
>

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


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



Re: Substiuting portions of a string with elements from a hash ...

2003-07-17 Thread David Storrs
Hi Jamie,

On Thu, Jul 17, 2003 at 11:46:08AM -0400, Jamie Risk wrote:
> I'm trying to add HTML anchors to a lines of text.  Quick example would be
> to take the line:
>"Search the internet using an engine like Google."
> and turn it into:
>"Search the internet using an engine like  href="www.google.com">Google."

> I can do this in a hacking sort of manner but it'll be slow and inelegant.
> I apologize for asking for design template/suggestions rather than
> help, 

Don't sweat it--those qualify as help too.  Personally, I think it
shows you're thinking.


As always, TIMTOWDI.  The best way depends on other constraints--where
are you planning on running this?  What kind of load will it see?  How
cross-platform does it need to be?  etc.


One solution is to tokenize your files yourself, then Reduce To
Problem Already Solved. (*) You can do a rough version of that with
something as simple as:

my $delims = qr/[^-\w']+/;
my @tokens = split /$delims/o, $text_of_file;

Or you can check CPAN (there is a Parse::Tokens module, but I haven't
used it; there are probably others too).  


Another way is to do a  s/$token/$replacement/eg on the text of your
file...it may not work perfectly, but it should go a long way.


A heavier-weight solution would be to use a real templating system
like Mason, The Template Toolkit, or Text::Template (to name a few...I
think CPAN has over 20).  Mason and TTT both come very highly
recommended to me.


--Dks

(*) Note that tokenizing English is hard--how do you handle hyphens vs
em-dashes (this sentence offering examples of each)?  You can't forget
the 'apostrophes vs single-quotes' issue either, and remember that
some possessive words' apostrophes are at the end.  How about
abbreviations with embedded punctuation (e.g. i.e.)?

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



Re: Variable "$q" will not stay shared at

2003-07-17 Thread Kristofer Hoch
B,
  Please post the entire code base of envir.pl.  Feel free to obfuscate
any data that it requires.  I cannot get the code you posted to fail. 
There is something amiss, and we need to see the code to help.

Kristofer.
--- "B. Fongo" <[EMAIL PROTECTED]> wrote:
> 
> 
> Hello,
> 
> I'm working on my first Perl project. Most of my cgi programs work
> ok,
> but a look at the apache error log reveals this warning which is
> clear
> to me:
> 
> Variable "$xy" will not stay shared at /data/www/cgi-perl/envir.pl
> line
> 19. [Wed Jul 16 11:44:57 2003] [error] Undefined subroutine
> &Apache::ROOT::cgi_2dperl::environ_2epl::start_html called at
> /data/www/cgi-
> perl/envir.pl line 20.
> 
> For instance: This code will trigger such warning.  
> 
> #!/usr/bin/perl -w
> use strict;
> use CGI;
> my $xy = new CGI;
> print $xy->header();
> print $xy->start_html();
> print $xy->p(" Perl-CGI");
> print $xy->end_html;
> 
> #
> 
> I tried several alternatives, like invoking print() only once at
> header.
> But I can't feature out what that warning actually means. My apache
> is
> configure with mod_perl.
> 
> Besides that, my project will consist of 1 main Perl script and
> several
> modules in a subdirectory which will be performing various functions.
> Now; what I intend to do is always send the main script a parameter
> through the URL, which will then indicate which of the modules should
> be
> called.  Each of my modules will contains subroutines for various
> functions:
> My question is: How do I send a parameter to my script through a link
> on
> my web page? I tried something like this, but did not work.  
> 
> A cup of
> coffee
> 
> 
>   What I'm trying to do here is to send the string "cup_of_coffee" to
> the main program.
> 
> The main program will have something like this to store the parameter
> from the url:
> @forwarded_by_url = ??? # Am not sure here.
> 
> 
> Can someone tell me how to implement it? That will be great!
> 
> Thanks
> 
> Babs
> 
> 
>   
> 
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


=
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GIT d s+:++ a C++ UL++ US+ P+++ L++ 
W+++ w PS PE t++ b+ G e r+++ z
--END GEEK CODE BLOCK--

__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



Newbie help

2003-07-17 Thread Keith Olmstead
Hello,

Been searching though this list for awhile now, and now I am needing some help.  I am 
not asking for someone to do my code for me,  I am trying to learn perl and the only 
way for me to do that is to dive staight into it.

My problem is with the theory of the script that I am trying to write.  I am needing 
something to backup logs for me from a central log server.  They layout of these files 
are as follows.

/host/ip/year/month/day/log1, log2, etc

Every file and dir under dir1 is created dynamically by the logging program, syslog-ng.

What I am wanting to do is create a script that will tar and gzip the day dirs at the 
end of the day and remove the dir after it has been backed up.  After the month is 
finished, I would like the same done for it.

Currently there are 20ish host dirs, one of each server that is logging to this box.  
There will be more and when they get pointed to this server, the ip dir will be 
created for that host and each dir under that will also be created for the 
corresponding date.  The logs need to be kept for 2-3 months, and then deleted.

I am needing help thinking this script out, maybe get ideas of how to set it up.  From 
reading using File::Find, might be useful.  

I was thinking about writing a script that runs in cron each night that tars and gzp 
the log dirs.  Currently I have a script that is getting a list of the dir, but I 
don't really know  where to go from there.  I need to get it to dive into the dir to 
the day lvl and archive the previous days logs.

Here are 2 scripts that I have been playing with.  I don't even know if I am going in 
the right direction.

#!/usr/bin/perl
use strict;
use warnings;
 
my $dir = '/opt/log/hosts/';
 
opendir(DIR, $dir) or die "Cannot open Directory";
 
# read the dir contents into a list, and grep out the . and .. dir entries
my @entries = grep (!/^\.\.?$/ , readdir (DIR));
closedir(DIR);
foreach (@entries)
{
  print "$_\n";
}

and

#!/usr/bin/perl
 
use File::Find;
use strict;
use warnings;
my $startdir = $ARGV[0];
my @dirlist;
find(
sub {
return if -d and /^\.\.?$/;
push @dirlist, $_ if -d;
}, $startdir);
 
#my $file_list = join '', @dirlist;
my $file_list = @dirlist;
print $file_list;

Like I said before, I am not asking for someone to do my work just some guidiance in 
the right direction.

TIA,

Keith Olmstead




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



DDL:Oracle / DDL:Pg?

2003-07-17 Thread Johnson, Shaunn
Howdy:

I am running PostgreSQL 7.2.1 on RedHat Linux.

I would like to get information from my
tables that include index, primary keys, sequences,
etc. I see that there is a module DDL:Oracle that
does this, but is there one for PostgreSQL?  (I'm 
using DBI-1.37 for most of my work).

Thanks!

-X


Re: trying to delete a file if >= 1 day old

2003-07-17 Thread John W. Krahn
Jenda Krynicky wrote:
> 
> From: "John W. Krahn" <[EMAIL PROTECTED]>
> > perldoc -f -C
> >-M  Age of file in days when script started.
> >-A  Same for access time.
> >-C  Same for inode change time.
> >
> >
> > In *nix files do not have a creation time.  You probably want to use
> > -M instead.
> 
> When does the inode change? (after the file creation ...:)


man 2 stat
[snip]
   The field st_atime is changed by file  accesses,  e.g.  by
   exec(2),  mknod(2), pipe(2), utime(2) and read(2) (of more
   than zero bytes). Other routines, like mmap(2), may or may
   not update st_atime.

   The  field st_mtime is changed by file modifications, e.g.
   by mknod(2), truncate(2), utime(2) and write(2)  (of  more
   than  zero  bytes).   Moreover, st_mtime of a directory is
   changed by the creation  or  deletion  of  files  in  that
   directory.   The st_mtime field is not changed for changes
   in owner, group, hard link count, or mode.

   The field st_ctime is changed by  writing  or  by  setting
   inode  information  (i.e., owner, group, link count, mode,
   etc.).


John
-- 
use Perl;
program
fulfillment

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



Threading / Shared Variable Assertion

2003-07-17 Thread Phil Schaechter
Hello all,

I'm having some threading issues with perl 5.8 on solaris 9 x86.  This problem 
does not appear on linux.  If anyone can provide any hints, I would be 
eternally thankful.

Here's some background:

SunOS load5.**.com 5.9 Generic_112234-05 i86pc i386 i86pc

bash-2.05# perl --version

This is perl, v5.8.0 built for i86pc-solaris-thread-multi

And here's the output:

line 503 at /auto/tools/dust/dust.pl line 858,  line 13.
thread failed to start: Assertion ((shared)->sv) failed: file "shared.xs", 
line 503 at /auto/tools/dust/dust.pl line 858,  line 13.
thread failed to start: Assertion ((shared)->sv) failed: file "shared.xs", 
line 503 at /auto/tools/dust/dust.pl line 858,  line 13.
thread failed to start: Assertion ((shared)->sv) failed: file "shared.xs", 
line 503 at /auto/tools/dust/dust.pl line 858,  line 28.
0 00:15:41 dustck start, mode 0
Assertion ((shared)->sv) failed: file "shared.xs", line 503 at 
/auto/tools/dust/dust.pl line 1216.

And here's an example line of failure.

if ( $flags{$ind_thread} ne "RUN" ) { next threadcheck; }

That variable is defined as:

my %flags : shared; # Thread & System flags

And is being accessed in a different thread than the definition.

Any clues?  Do I need to provide more information?  Thanks

-Phil

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



Re: trying to delete a file if >= 1 day old

2003-07-17 Thread Jenda Krynicky
From: "John W. Krahn" <[EMAIL PROTECTED]>
> perldoc -f -C
>-M  Age of file in days when script started.
>-A  Same for access time.
>-C  Same for inode change time.
> 
> 
> In *nix files do not have a creation time.  You probably want to use
> -M instead.

When does the inode change? (after the file creation ...:)

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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



chomp'ing EOL

2003-07-17 Thread Jamie Risk
I've no control over the EOL of text files that I'm processing; is there a
conveniant method using chomp() and the INPUT_RECORD_SEPERATOR ($/) to
handle DOS/UNIX/MAC generated text files automatically?




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



Re: help me out please ..

2003-07-17 Thread zentara
On 17 Jul 2003 08:23:54 -, [EMAIL PROTECTED] (Vemulakonda
Uday Bhaskar) wrote:

>i am tring to tranfer files between two linux systems through 
>sftop
>
>i have installed the following modules :
>
>1. Download Net::FTP and Install
>2. Download Net::SFTP .
>
>and the error displayed after running the perl file with the above 
>code is :
>
>"Request for subsystem 'sftp' failed on channel '1' at
>/usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 66."
>
>please help in this regard.
>
>i have sent a mail earlier with the same problem , but i got reply 
>fort sending the original code. the code above is the original 
>code .
>
>please help me rectify my problem

I told you this before, can you connect with the sftp program itself?
"sftp  -v yourhost.com"

Not all hosts are setup properly to accept sftp, especially those
running ssh1.

Until you can make that connection, you are wasting your time trying to
connect with perl.

When you do connect with perl, use the debug feature, and post the
output of your connection.

$sftp = Net::SFTP->new("myhost.com",
user=>"zz",
password=>"zfoo",
debug => 1,
);



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



Re: secure socket connection

2003-07-17 Thread zentara
On Thu, 17 Jul 2003 05:12:16 +, [EMAIL PROTECTED] (Mario Kulka)
wrote:

>I'm trying to set up credit card processing and one of the first steps is to 
>establish a "secure socket connection" - how can i do it? (My host does 
>support it)

You are not clear which part of the credit card processing you are
talking about?

To take cc info from a customer:
Just run your cgi script on a secure server, ie https not http.
https://somehost.com/my.cgi

To connect to a bank's verification service:
use  LWP which handles ssl.  The best way to do this, is
setup a simple html form which can connect to your
service's test server. Get some test transactions going thru
html, and then take the html_form_fields and plug them into
LWP like shown below.

$card_no= &z($card_no);  #decrypt card number, encrypted on hard drive
 my $ua = LWP::UserAgent->new(timeout=>45); 
 my $req = POST
'https://zentara.zentara.net/~zentara/cgi-bin/store/respgen.pl', 
  [IOC_merchant_id => '4301330018817403', 
  IOC_order_total_amount => "$grand_total", 
  IOC_merchant_shopper_id => 'susehost', 
#  IOC_merchant_order_id => "$order_id", 
  IOC_merchant_order_id => "$unique_id", 
  ecom_billto_postal_street_line1 => "$street1", 
  ecom_billto_postal_postalcode => "$zip", 
  ecom_billto_postal_countrycode => "$country", 
  ecom_billto_online_email => "$email", 
  ecom_payment_card_name => "$first $last", 
  ecom_payment_card_number => "$card_no", 
  ecom_payment_card_expdate_month => "$exp_mon", 
  ecom_payment_card_expdate_year => "$exp_yr", 
  url => 'https://192.168.0.1/~zentara/cgi-bin/shop/boacc.pl', 
 ]; 

The url is the url that you want the results returned to, typically it
will be true or false and maybe a reason or error code.





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



RE: trying to delete a file if >= 1 day old

2003-07-17 Thread Tony Esposito
Thank you for your input.  I have found a resolution to this issue.

> Anthony (Tony) Esposito
> Senior Technical Consultant 
> Inovis(tm)
> 2425 N. Central Expressway, Suite 900 
> Richardson, TX  75080 
> (972) 643-3115 
> [EMAIL PROTECTED] 
> 


-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 17, 2003 11:54 AM
To: [EMAIL PROTECTED]
Subject: Re: trying to delete a file if >= 1 day old


Tony Esposito wrote:
> 
> Fellow Perl neophytes ( and non-neophytes),

Hello,

> I need a little clarification.  I am trying to remove files that
are
> greater that 24 hours old.  The code snippet below is in a 'while' loop
that
> steps through a directory, yet it seems not to work - no files are removed
> no matter what their 'age' ( i.e., their creation time ).  I have stepped
> through the code via the Perl debugger and know the code is being
executed.
> 
> unlink $file unless -C $file < 1;
> 
> Another question - is the creation time of a file 'updated'
whenever
> a 'write' to the file is performed or does the creation time remain
static?
> I need a way to delete files based on the file creation time and that time
> needs to be static.

perldoc -f -C
   -M  Age of file in days when script started.
   -A  Same for access time.
   -C  Same for inode change time.


In *nix files do not have a creation time.  You probably want to use -M
instead.


John
-- 
use Perl;
program
fulfillment

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

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



Re: trying to delete a file if >= 1 day old

2003-07-17 Thread John W. Krahn
Tony Esposito wrote:
> 
> Fellow Perl neophytes ( and non-neophytes),

Hello,

> I need a little clarification.  I am trying to remove files that are
> greater that 24 hours old.  The code snippet below is in a 'while' loop that
> steps through a directory, yet it seems not to work - no files are removed
> no matter what their 'age' ( i.e., their creation time ).  I have stepped
> through the code via the Perl debugger and know the code is being executed.
> 
> unlink $file unless -C $file < 1;
> 
> Another question - is the creation time of a file 'updated' whenever
> a 'write' to the file is performed or does the creation time remain static?
> I need a way to delete files based on the file creation time and that time
> needs to be static.

perldoc -f -C
   -M  Age of file in days when script started.
   -A  Same for access time.
   -C  Same for inode change time.


In *nix files do not have a creation time.  You probably want to use -M
instead.


John
-- 
use Perl;
program
fulfillment

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



RE: fast match count of char in string

2003-07-17 Thread Charles K. Clarkson
Juerg Oehler [mailto:[EMAIL PROTECTED] wrote:

: Sent: Thursday, July 17, 2003 11:09 AM
: To: [EMAIL PROTECTED]
: Subject: fast match count of char in string
: 
: 
: hi,
: 
: how do efficent count char 'a' in string "abdaatela" ?

Plagiarizing from perlfaq4:

  "How can I count the number of occurrences of a
   substring within a string?"

There are a number of ways, with varying efficiency:
If you want a count of a certain single character (a)
within a string, you can use the tr/// function like so:

$string = "abdaatela";

$count = ($string =~ tr/a//);

print "There are $count a characters in the string";



HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



fast match count of char in string

2003-07-17 Thread Juerg Oehler
hi,

how do efficent count char 'a' in string "abdaatela" ?

i guess there are better solutions than:

$tmpstr =~ s/[^a]//g ;
$cnt = length ($tmpstr) ;
print ("found <$cnt> a's <$tmpstr>\n");

thanx
george




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



RE: trying to delete a file if >= 1 day old

2003-07-17 Thread Tony Esposito
Good points - thanks for your feedback.

> Anthony (Tony) Esposito
> Senior Technical Consultant 
> Inovis(tm)
> 2425 N. Central Expressway, Suite 900 
> Richardson, TX  75080 
> (972) 643-3115 
> [EMAIL PROTECTED] 
> 


-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED]
Sent: Thursday, July 17, 2003 11:32 AM
To: Tony Esposito; [EMAIL PROTECTED]
Subject: RE: trying to delete a file if >= 1 day old


Tony Esposito wrote:
> Fellow Perl neophytes ( and non-neophytes),
>   I need a little clarification.  I am trying to remove files that are
> greater that 24 hours old.  The code snippet below is in a 'while'
> loop that steps through a directory, yet it seems not to work - no
> files are removed no matter what their 'age' ( i.e., their creation
> time ).  I have stepped through the code via the Perl debugger and
> know the code is being executed. 
> 
>   unlink $file unless -C $file < 1;
-C is not for creation, but for inode-change time

use -M which is last file modification time.

If you use as a daemon, then you will need set $^T otherwise this is
set to the startup of the script. Happened to me and couldn't understand why
nothing we ever deleted.

Wags ;)
> 
>> Anthony (Tony) Esposito
>> Senior Technical Consultant
>> Inovis(tm)
>> 2425 N. Central Expressway, Suite 900
>> Richardson, TX  75080
>> (972) 643-3115
>> [EMAIL PROTECTED]



**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.


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



RE: trying to delete a file if >= 1 day old

2003-07-17 Thread Tony Esposito
Thank you, Bob.  Very helpful information on all fronts.

> Anthony (Tony) Esposito
> Senior Technical Consultant 
> Inovis(tm)
> 2425 N. Central Expressway, Suite 900 
> Richardson, TX  75080 
> (972) 643-3115 
> [EMAIL PROTECTED] 
> 


-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 17, 2003 11:31 AM
To: Tony Esposito; [EMAIL PROTECTED]
Subject: RE: trying to delete a file if >= 1 day old


Tony Esposito wrote:
> Fellow Perl neophytes ( and non-neophytes),
>   I need a little clarification.  I am trying to remove files that are
> greater that 24 hours old.  The code snippet below is in a 'while'
> loop that steps through a directory, yet it seems not to work - no
> files are removed no matter what their 'age' ( i.e., their creation
> time ).

See below...

> I have stepped through the code via the Perl debugger and
> know the code is being executed. 
> 
>   unlink $file unless -C $file < 1;

-C is expressed in "days ago, since start of program". So -C < 1 means "less
than 1 day ago".

> 
>   Another question - is the creation time of a file
> 'updated' whenever
> a 'write' to the file is performed or does the creation time remain
> static? 

Neither. There is no such thing as "creation" time (on Unices anyway). -C
gives you days since last inode change. Typically, you use -M, which is days
since last modification of the file contents.

> I need a way to delete files based on the file creation time
> and that time needs to be static.

No can do, since file creation time isn't kept anywhere.

See http://www.faqs.org/faqs/unix-faq/faq/part3/section-1.html

>   One last - unrelated - query:  Does anyone know of a Oracle PL/SQL
> mailing list ( e.g., [EMAIL PROTECTED] )?

I dunno.

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



RE: trying to delete a file if >= 1 day old

2003-07-17 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Tony Esposito wrote:
> Fellow Perl neophytes ( and non-neophytes),
>   I need a little clarification.  I am trying to remove files that are
> greater that 24 hours old.  The code snippet below is in a 'while'
> loop that steps through a directory, yet it seems not to work - no
> files are removed no matter what their 'age' ( i.e., their creation
> time ).  I have stepped through the code via the Perl debugger and
> know the code is being executed. 
> 
>   unlink $file unless -C $file < 1;
-C is not for creation, but for inode-change time

use -M which is last file modification time.

If you use as a daemon, then you will need set $^T otherwise this is set to 
the startup of the script. Happened to me and couldn't understand why nothing we ever 
deleted.

Wags ;)
> 
>> Anthony (Tony) Esposito
>> Senior Technical Consultant
>> Inovis(tm)
>> 2425 N. Central Expressway, Suite 900
>> Richardson, TX  75080
>> (972) 643-3115
>> [EMAIL PROTECTED]



**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



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



RE: Padding a record with zero's in a file

2003-07-17 Thread Charles K. Clarkson
James Parsons <[EMAIL PROTECTED]> wrote:

: I have a following in a file 
: 
: Raw data   =   
: 18822 188.22
: 133  1.33
: 230023.00
: 222003  `2220.03 
: 
: 
: And when I run the following perl script the
: total is extremely out of wacky, total should
: be 2432.58  not  7734.23 

I get four errors and a correct total:

Argument "18822 188.22\n" isn't numeric in addition (+) at ff.pl
line 5,  line 1.
$2432.58
Argument "133  1.33\n" isn't numeric in addition (+) at
ff.pl line 5,  line 2.
Argument "230023.00\n" isn't numeric in addition (+) at
ff.pl line 5,  line 3.
Argument "222003  `2220.03 \n" isn't numeric in addition (+) at
ff.pl line 5,  line 4.

It would be better to not rely on perl to
find the values you want in the file. Here's
a more precise algorithm:

my @amounts;
while (  ) {
push @amounts, (split ' ')[0];
}

my $total = 0;
$total += $_ foreach @amounts;

printf "\$ %s\n", $total/100;

__END__
18822   188.22
1331.33
2300  23.00
222003  `2220.03 

Assuming that each line in the file is valid.

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328




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



RE: trying to delete a file if >= 1 day old

2003-07-17 Thread Bob Showalter
Tony Esposito wrote:
> Fellow Perl neophytes ( and non-neophytes),
>   I need a little clarification.  I am trying to remove files that are
> greater that 24 hours old.  The code snippet below is in a 'while'
> loop that steps through a directory, yet it seems not to work - no
> files are removed no matter what their 'age' ( i.e., their creation
> time ).

See below...

> I have stepped through the code via the Perl debugger and
> know the code is being executed. 
> 
>   unlink $file unless -C $file < 1;

-C is expressed in "days ago, since start of program". So -C < 1 means "less
than 1 day ago".

> 
>   Another question - is the creation time of a file
> 'updated' whenever
> a 'write' to the file is performed or does the creation time remain
> static? 

Neither. There is no such thing as "creation" time (on Unices anyway). -C
gives you days since last inode change. Typically, you use -M, which is days
since last modification of the file contents.

> I need a way to delete files based on the file creation time
> and that time needs to be static.

No can do, since file creation time isn't kept anywhere.

See http://www.faqs.org/faqs/unix-faq/faq/part3/section-1.html

>   One last - unrelated - query:  Does anyone know of a Oracle PL/SQL
> mailing list ( e.g., [EMAIL PROTECTED] )?

I dunno.

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



Re: Problems With SFTP Subsytem Errors (was: help me out please)

2003-07-17 Thread Rob Dixon
[EMAIL PROTECTED] wrote:
> 
> On 17 Jul 2003 08:23:54 -, "vemulakonda uday bhaskar"
> <[EMAIL PROTECTED]> wrote:
>
> >
> > hi all,
> >
> > i am tring to tranfer files between two linux systems through
> > sftop
>
> Please use a more descriptive subject line, "help me out please" is
> not terribly to the point.

Hi Wiggins.

Please use a more descriptive subject line, "Re: help me out please" is
not terribly to the point.

Touché, mon ami ;D

Rob




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



Re: newbie : obtain gid of the current user

2003-07-17 Thread John W. Krahn
Sylvain masnada wrote:
> 
> Hi again and thx John for you help.
> >
> > You could run id inside your perl program.
> >
> > my $id_output = qx/id/;
> I didn't know how to execute a shell command into a perl script, thx.

There are many ways to execute a "shell command" in a perl program, that
is just one way.


> > > My script is :
> > >
> > > while(<>)
> > > {
> > > if(/^uid=\d+.\w+.\sgid=(\d+)/)
> > > {
> > > $gid=$1;
> > > print "gid:$gid\n";
> > > }
> > > }
> >
> > Perl supplies the User ID in $<, the Effective User ID in $>, the Group
> > ID in $( and the Effective Group ID in $).
> 
> What's the difference between effective and non-effective,

It is the difference between the effective and the real uid/gid.


> the answer are the same for : print
> "$>, $<\n" and idem for group
> Moreover when I do this
> print "gid: $)\n";
> I get (a : gid: 0 10 6 4 3 2 1 0
> not just 0. How to get just the true gid?

perldoc perlvar
[snip]
$REAL_GROUP_ID
$GID
$(  The real gid of this process. If you are on a machine that
supports membership in multiple groups simultaneously, gives
a
space separated list of groups you are in. The first number
is
the one returned by getgid(), and the subsequent ones by
getgroups(), one of which may be the same as the first
number.

However, a value assigned to `$(' must be a single number
used
to set the real gid. So the value given by `$(' should *not*
be
assigned back to `$(' without being forced numeric, such as
by
adding zero.

(Mnemonic: parentheses are used to *group* things. The real
gid
is the group you *left*, if you're running setgid.)

$EFFECTIVE_GROUP_ID
$EGID
$)  The effective gid of this process. If you are on a machine
that
supports membership in multiple groups simultaneously, gives
a
space separated list of groups you are in. The first number
is
the one returned by getegid(), and the subsequent ones by
getgroups(), one of which may be the same as the first
number.

Similarly, a value assigned to `$)' must also be a
space-separated list of numbers. The first number sets the
effective gid, and the rest (if any) are passed to
setgroups().
To get the effect of an empty list for setgroups(), just
repeat
the new effective gid; that is, to force an effective gid of
5
and an effectively empty setgroups() list, say ` $) = "5 5"
'.

(Mnemonic: parentheses are used to *group* things. The
effective
gid is the group that's *right* for you, if you're running
setgid.)

`$<', `$>', `$(' and `$)' can be set only on machines that
support the corresponding *set[re][ug]id()* routine. `$('
and
`$)' can be swapped only on machines supporting setregid().


> > print "gid: $(\n";
> >
> >
> > To find the name assigned to $(:
> >
> > my $group = getgrgid $(;
> > print "Group: $group\n";
> >
> >
> > To get all groups that $( belongs to:
> >
> > my @groups;
> > my $name = getpwuid $<;
> > while ( my @ent = getgrent ) {
> > push @groups, $ent[ 0 ] if $ent[ -1 ] =~ /\b$name\b/;
> > }
> > print "@groups\n"
> >
> >
> > > My aim is to change the ip address following the gid.
> >
> > The id program does not output an ip address.
> Yes I know. My first goal was to get the gid. Now I want to attribute ip address by 
> gid, maybe
> thanks to :
> 
> if ($( == 1000)
> {
> qx/ifconfig eth0 x.x.x.x up/;
> }
> 
> elseif ($( == 1001)
> {
> qx/ifconfig eth0 x.x.x.y up/;
> }

You should use system() instead of qx// for that.

my %gid2ip = (
1000 => 'x.x.x.x',
1001 => 'x.x.x.y',
);
my @ifconfig = ( 'ifconfig', 'eth0', '', 'up' );

if ( exists $gid2ip{ $( + 0 } ) {
$ifconfig[ 2 ] = $gid2ip{ $( + 0 };
system( @ifconfig ) == 0 or die "system @ifconfig failed: $?"
}

perldoc -f system


John
-- 
use Perl;
program
fulfillment

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



trying to delete a file if >= 1 day old

2003-07-17 Thread Tony Esposito
Fellow Perl neophytes ( and non-neophytes),
I need a little clarification.  I am trying to remove files that are
greater that 24 hours old.  The code snippet below is in a 'while' loop that
steps through a directory, yet it seems not to work - no files are removed
no matter what their 'age' ( i.e., their creation time ).  I have stepped
through the code via the Perl debugger and know the code is being executed.

unlink $file unless -C $file < 1;

Another question - is the creation time of a file 'updated' whenever
a 'write' to the file is performed or does the creation time remain static?
I need a way to delete files based on the file creation time and that time
needs to be static.
One last - unrelated - query:  Does anyone know of a Oracle PL/SQL
mailing list ( e.g., [EMAIL PROTECTED] )?
Thanks to all in advance and cheers to our friends across the pond!

> Anthony (Tony) Esposito
> Senior Technical Consultant 
> Inovis(tm)
> 2425 N. Central Expressway, Suite 900 
> Richardson, TX  75080 
> (972) 643-3115 
> [EMAIL PROTECTED] 
> 
> 

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



Re: Creating html source ...

2003-07-17 Thread Rob Dixon
Jamie Risk wrote:
> er, sorry.
>
> Is there a module to produce html formatted output? If so, would I
> be directed to some documentation?
>
> > > I have to assume that any of the simple HTML-izing I want to do
> > > with simple text files has already been done.  I'm guessing
> > > modules, particularly "CGI" but would appreciate a directed
> > > pointer to docs.

Thanks Jamie, but I still can't help very much. It sounds like you
need to explore

  perldoc CGI

a little more. What can help a lot if you're writing CGI stuff is
HTML::QuickTable which lets you do things like

  use HTML::QuickTable;
  my $qt = HTML::QuickTable->new(font_face => 'sans-serif');
  print $qt->render(\%ENV);

is there anything more specific we could help you with?

Rob




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



RE: Padding a record with zero's in a file

2003-07-17 Thread Wagner, David --- Senior Programmer Analyst --- WGO
James Parsons wrote:
> Hi everyone..
> 
> I'm still a Newbie so be gently
> 
> 
> I have a following in a file
> 
> Raw data   =
> 18822 188.22
> 133  1.33
> 230023.00
> 222003  `2220.03
> 
> 
> And when I run the following perl script the total is extremely out of
> wacky, total should be 2432.58  not  7734.23
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $total = 0;
> 
> open(FILE,"//usr/local/logs/eigen/temp/day_amt") || die $!;
> 
> $total += $_ while();
> 
> close(FILE);
> 
> my $value = 100;
> 
> $total = $total/$value;
> 
> #print  "\$$total\n",;
> 
> 
> 
> 
> 
> printf ("%7.2f\n",$total);
> 
> 
> Any help would be great.
> 
> Thanks
> James Parsons

Then I run it I end up with the total you state you should get.  It was 
unclear whether the decimal point data was there or not. Running with or without the 
decimal point data, it gives the right total.

Running AS 5.6.0 Build 623.

Wags ;)


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



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



RE: Is there a simple way to include source code I've written in other files?

2003-07-17 Thread Charles K. Clarkson
Jamie Risk wrote:
: 
: Until now, I've avoided writing modules by inlining the 
: deisred code in the new files. Messy.  I'm avoiding
: modules for two reasons, laziness and naive conception
: that for what I'm trying to do it's overkill.

Neat! Your first reason is why I use modules.


Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


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



Padding a record with zero's in a file

2003-07-17 Thread James Parsons
Hi everyone..

I'm still a Newbie so be gently 


I have a following in a file 

Raw data   =   
18822   188.22
1331.33
2300  23.00
222003  `2220.03 


And when I run the following perl script the total is extremely out of
wacky, total should be 2432.58  not  7734.23 

#!/usr/bin/perl -w

use strict;

my $total = 0;

open(FILE,"//usr/local/logs/eigen/temp/day_amt") || die $!;

$total += $_ while();

close(FILE);

my $value = 100;

$total = $total/$value;

#print  "\$$total\n",;

 

 

printf ("%7.2f\n",$total);


Any help would be great.

Thanks 
James Parsons  





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



Substiuting portions of a string with elements from a hash ...

2003-07-17 Thread Jamie Risk
I'm trying to add HTML anchors to a lines of text.  Quick example would be
to take the line:
   "Search the internet using an engine like Google."
and turn it into:
   "Search the internet using an engine like Google."

In the past, I've contructed hash tables from text files having delimited
key-value pairs (in the above "Google" would be the key).  This has worked
for me so far because I've been able to look at tokenized string phrases
when determining if they exist as keys in the hash.  Eg.
  if (defined $html_anchor{$token})  { print "$token";   }

My problem now is that my text isn't tokenized, and my keys are still
phrases.  I'm not bound to using a hash, just my text file which has the
delimited key-value pairs.

I can do this in a hacking sort of manner but it'll be slow and inelegant.
I apologize for asking for design template/suggestions rather than help, but
since it's summer, my promise that it's not homework should add credibility
(and I've not been to school for some time).  Also, since it's summer, I've
got time to read (and I don't mind schooling, having been removed from it
for some time), so documentation pointers are just as useful.

- Jamie

p.s. This sort of ties into a previous post I did yesterday "Creating html
source ...".




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



Re: Comparing two strings for first difference

2003-07-17 Thread Rob Anderson

"Paul Archer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thanks a lot! This is just what I was looking for in your first example.
> (The second example won't do me as much good, as I need to consider
> characters that haven't changed inside of a string of characters that
> have--but it's still a good reference.)
>
> Thanks again,

No prob, glad to be of help.

Rob

>
> paul
>
>
> 10:11am, Rob Anderson wrote:
>
> > > If anyone can offer general improvements to that approach, that'd be
> > > great--but what I'm really interested in is finding the first element
that
> > > differs, and maybe the last as well. If there were any easy way to
find
> > > that, say, the first character that differs is at position 120, and
the
> > last
> > > character that differs is at position 135, then I only have to loop
> > through
> > > 15 characters, not 160.
> >
> > Probably the quickest way to do this in perl is as follows
> >
> > 
> > #!/perl -w
> > use strict;
> > my $string1 = "The quick brown fox.";
> > my $string2 = "The Kuick brUwn fox.";
> >
> > my $string_xor = ("$string1" ^ "$string2");
> >
> > $string_xor =~ /^(\0*)/;
> > print "Number of equal bytes at the front of the string = " . length($1)
.
> > "\n";
> > $string_xor =~ /(\0*)$/;
> > print "Number of equal bytes at the end of the string = " . length($1) .
> > "\n";
> > 
> >
> > the xor op (^) will return a string, every matching byte of which will
be
> > null, every mismatching byte will have some bit (literaly) set.
> >
> > so the all first regex does is match the all the null bytes it can find
from
> > the front of the string, the length of the string is equivalent to the
> > number of identical chars at the front.
> > The second regex is the same, just working from the end.
> >
> > You could extend this and translate all the non-null values to something
you
> > could then search for that value with index. This would give you the
> > positions of all the bytes that were different...
> >
> > my $string_xor = ("$string1" ^ "$string2");
> > my $pos = 0;
> > while ( ($pos = index($string_xor, 'X', $pos)) != -1) {
> >print "==> $pos\n";
> >$pos++;
> > }
> >
> > Hope this helps,
> >
> > Rob
> >
> > >
> > > TIA,
> > >
> > > paul
> > >
> > >
> > > -
> > > On the side of the software box, in the "System Requirements" section,
> > > it said "Requires Windows 95 or better".  So I installed Linux.
> > > -
> >
> >
> >
>
> -
> "Somebody did say Swedish porn, there--
> but someone always does..."
> --Clive Anderson, host of "Whose Line Is It, Anyway",
> after asking the audience for movie suggestions
> -



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



Re: Comparing two strings for first difference

2003-07-17 Thread Paul Archer
Thanks a lot! This is just what I was looking for in your first example.
(The second example won't do me as much good, as I need to consider
characters that haven't changed inside of a string of characters that
have--but it's still a good reference.)

Thanks again,

paul


10:11am, Rob Anderson wrote:

> > If anyone can offer general improvements to that approach, that'd be
> > great--but what I'm really interested in is finding the first element that
> > differs, and maybe the last as well. If there were any easy way to find
> > that, say, the first character that differs is at position 120, and the
> last
> > character that differs is at position 135, then I only have to loop
> through
> > 15 characters, not 160.
>
> Probably the quickest way to do this in perl is as follows
>
> 
> #!/perl -w
> use strict;
> my $string1 = "The quick brown fox.";
> my $string2 = "The Kuick brUwn fox.";
>
> my $string_xor = ("$string1" ^ "$string2");
>
> $string_xor =~ /^(\0*)/;
> print "Number of equal bytes at the front of the string = " . length($1) .
> "\n";
> $string_xor =~ /(\0*)$/;
> print "Number of equal bytes at the end of the string = " . length($1) .
> "\n";
> 
>
> the xor op (^) will return a string, every matching byte of which will be
> null, every mismatching byte will have some bit (literaly) set.
>
> so the all first regex does is match the all the null bytes it can find from
> the front of the string, the length of the string is equivalent to the
> number of identical chars at the front.
> The second regex is the same, just working from the end.
>
> You could extend this and translate all the non-null values to something you
> could then search for that value with index. This would give you the
> positions of all the bytes that were different...
>
> my $string_xor = ("$string1" ^ "$string2");
> my $pos = 0;
> while ( ($pos = index($string_xor, 'X', $pos)) != -1) {
>print "==> $pos\n";
>$pos++;
> }
>
> Hope this helps,
>
> Rob
>
> >
> > TIA,
> >
> > paul
> >
> >
> > -
> > On the side of the software box, in the "System Requirements" section,
> > it said "Requires Windows 95 or better".  So I installed Linux.
> > -
>
>
>

-
"Somebody did say Swedish porn, there--
but someone always does..."
--Clive Anderson, host of "Whose Line Is It, Anyway",
after asking the audience for movie suggestions
-

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



Re: Porting perl scripts on windows

2003-07-17 Thread Michele Ouellet
   "Sharad Gupta" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
   Any good books on how to learn perl on windows??.

Learning Perl on Win32 Systems ( O'Reilly ) is pretty good.

Good Luck,

Michèle.



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



Re: file changed??

2003-07-17 Thread Jose M.Herrera
> From: "Jose M.Herrera" <[EMAIL PROTECTED]>
> > I need to make a perl program which print "Changed!" when a file
> > xx.txt is changed. please, any idea??
> 
> Since you are using Outlook I assume you want this under Windows, 
> right? Take a look at Win32::ChangeNotify module.

No... with RedHat Linux 7.3.

Thanks 



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



MIME::Lite

2003-07-17 Thread Yacketta, Ronald
Hello all!

I have a rather simple question that has me stumped (for about 2 hours now)

I am using the MIME:Lite package
(http://theoryx5.uwinnipeg.ca/CPAN/data/MIME-Lite/MIME/Lite.html) to
Send reports via email from a *nix box.

What I am looking to-do is send the text of a report in the body of the
email as well as an attachment, but keep coming up short.

Here is what I have so far

$g_mail = MIME::Lite->new ( From=>
"[EMAIL PROTECTED]",
To  => $g_mail_to,
Subject => $g_mail_subject,
Type=> 'multipart/mixed'
   );

$g_mail->attach(Type => 'TEXT', 
Data => $g_mail_file ); # Here is where I am
trying to put the text of the report in the body of the email

$g_mail->attach(Type=> 'TEXT',
Path=> $g_mail_file,
Filename=> $g_mail_file,
Disposition => 'attachment' );  #
Here is where I attach the file

$g_mail->send("sendmail");


-Ron

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



Re: quota's

2003-07-17 Thread Joe Stuart
Yeah, I tried that it works fine. I dont know it's probably something
stupid. Even though it throws that error it will adjust the first person
in the passwd files quota, but no one after that. I've even changed the
script to just deal with one person at a time and I get the same error
but it's successful. 

Thanks

>>> Ramprasad <[EMAIL PROTECTED]> 07/17/03 09:44AM >>>
Joe Stuart wrote:
> I'm trying to implement quota's using the quota interface for perl.
The
> problem I'm having is when I execute this code. 
> 
> #!/usr/bin/perl
> 
> use Getopt::Std;
> use Quota;
> 
> getopt("f:s:h:");
> die "Usage: $0 -f  -s  -h \n"
> if(!$opt_f || !$opt_s || !$opt_h);
> 
> open(PASS, "/etc/passwd") or die "Unable to open users file\n";
> @array = ;
> close(PASS);
> 
> $dev = Quota::getqcarg($opt_f) or die "Unable to translate path
$opt_f:
> $!\n";
> 
> foreach $i (@array) {
> $i =~ /(\w+):x:(\d+)/;
> 
> unless($2 <= 500) {
> 
> ($block_curr, $block_soft, $block_hard,
> $block_timelimit, $inode_curr,
> $inode_soft, $inode_hard, $inode_timelimit)
=
> Quota::query($dev ,$2);
> 
> Quota::setqlim($dev, $2, $opt_s, $opt_h,
> $inode_soft, $inode_hard, 1) or
> die "Unable to set quota's: $!\n";
> 
> 
> I get this error message.
> Unable to set quota's: No such file or directory
> 
> I'm out of ideas. 
> thanks

Please reduce your indent size, I can hardly read your code

Well on the face of it I am not able to see any problem, Can you just 
try setting the quota using edquota on command line and see If the
quota 
  error is not because of the system

Ram


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


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



Re: Please help !! Socket

2003-07-17 Thread Ramprasad
Pandey Rajeev-A19514 wrote:
Hi,

I want to create differnent Socket Handles in a function and the function creates the created Socket Handle..
my $sock = gensym(); 

I am getting the same instance of Handle "S".

Please some one tell me how to create different instances of sockets in perl.

Regards
Rajeev
I think the problem is with line 17 of your code

Ram

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


Re: Is there a simple way to include source code I've written inother files?

2003-07-17 Thread Ramprasad
Jamie Risk wrote:
Until now, I've avoided writing modules by inlining the deisred code in the
new files. Messy.  I'm avoiding modules for two reasons, laziness and naive
conception that for what I'm trying to do it's overkill.
Thats a dangerous idea.

Is there a method to reference code in other files, like, a simple
"include"?
Yes "use or require"
perldoc -f use
Ram

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


RE: Is there a simple way to include source code I've written in other files?

2003-07-17 Thread wiggins


On Thu, 17 Jul 2003 10:39:56 -0400, "Jamie Risk" <[EMAIL PROTECTED]> wrote:

> Until now, I've avoided writing modules by inlining the deisred code in the
> new files. Messy.  I'm avoiding modules for two reasons, laziness and naive
> conception that for what I'm trying to do it's overkill.
> 
> Is there a method to reference code in other files, like, a simple
> "include"?
> 

A module can be as complex or not as you want and your application dictates. 
Essentially a module is just an 'include' with specific semantics.  Though if you 
prefer you may want to have a look at the docs for 'require'.

perldoc -f require
perldoc -f use

http://danconia.org

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



Re: quota's

2003-07-17 Thread Ramprasad
Joe Stuart wrote:
I'm trying to implement quota's using the quota interface for perl. The
problem I'm having is when I execute this code. 

#!/usr/bin/perl

use Getopt::Std;
use Quota;
getopt("f:s:h:");
die "Usage: $0 -f  -s  -h \n"
if(!$opt_f || !$opt_s || !$opt_h);
open(PASS, "/etc/passwd") or die "Unable to open users file\n";
@array = ;
close(PASS);
$dev = Quota::getqcarg($opt_f) or die "Unable to translate path $opt_f:
$!\n";
foreach $i (@array) {
$i =~ /(\w+):x:(\d+)/;
unless($2 <= 500) {

($block_curr, $block_soft, $block_hard,
$block_timelimit, $inode_curr,
$inode_soft, $inode_hard, $inode_timelimit) =
Quota::query($dev ,$2);
Quota::setqlim($dev, $2, $opt_s, $opt_h,
$inode_soft, $inode_hard, 1) or
die "Unable to set quota's: $!\n";
I get this error message.
Unable to set quota's: No such file or directory
I'm out of ideas. 
thanks
Please reduce your indent size, I can hardly read your code

Well on the face of it I am not able to see any problem, Can you just 
try setting the quota using edquota on command line and see If the quota 
 error is not because of the system

Ram

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


RE: file changed??

2003-07-17 Thread wiggins

On Wed, 16 Jul 2003 21:33:56 -0400, "Jose M.Herrera" <[EMAIL PROTECTED]> wrote:

> I need to make a perl program which print "Changed!" when a file xx.txt is
> changed.
> please, any idea??
> 
> Thanks for all..
>

Usually two-three options with this type of task on varying levels. 

1. Is your program going to run out of a scheduler (aka cron, etc.)? Or will it be 
continually running?  In the latter case, is it ok for it to sleep/block between 
intervals or must it be non-blocking?

2. What kind of change are you trying to detect?  Checking the mtime against the 
system time will tell you whether the file was modified, but not necessarily that it's 
contents changed.  To detect changes in contents you are probably best off using some 
type of hashing module, such as Digest::MD5 or Digest::SHA1, which will provide a 
unique 'hash' that changing the contents of the file, then rehashing you can match 
against.

3. In the case of the scheduler you will need some way to save the last checked state 
(outside of main memory, to a file, database, etc.), aka the modified time, the hash, 
etc. between sessions.

4. Are you checking multiple files on each pass or only a single one? Is it a large 
list? Are the files always the same and specifically determined, or do you have to 
'find' them?

Depending on how precise, etc. you need to be these may not cut it, but are the right 
questions to be asking first.

You should start by redefining the problem into smaller more manageable chunks until 
the implementation becomes obvious, then we can help you with some of the details of 
that implementation.

http://danconia.org

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



Is there a simple way to include source code I've written in other files?

2003-07-17 Thread Jamie Risk
Until now, I've avoided writing modules by inlining the deisred code in the
new files. Messy.  I'm avoiding modules for two reasons, laziness and naive
conception that for what I'm trying to do it's overkill.

Is there a method to reference code in other files, like, a simple
"include"?




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



Re: DBI execute problem

2003-07-17 Thread Jenda Krynicky
From: Ramprasad <[EMAIL PROTECTED]>
> You are right it is weird. But just a test script to learn DBI. What I
> really want is how Can I use prepare and execute which I think is
> better than doing a do every time If my table name keeps changing
> 
> Is a prepare statement always specific to a table in a database ?

No and yes.
I think that maybe DBD::AnyData does allow prepare with a placeholder 
for the table name, but no "real" database does.

The query execution plan (the way the database will search for the 
rows that match all the requirements, what indexes will be used, what 
types of table merges, etc.) depends heavily on the table(s) used. 
Therefore it would not really make sense to prepare something you 
can't generate an execution plan for.

The best you can get is to create several statement handles and 
prepare the statement for each table separately.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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



Re: Simple process controll question

2003-07-17 Thread Ramprasad
Gabor Urban wrote:
Hi,

I think the question at hand may be quite simple, though I could not
figure the asnwer out :-))
MyScript.pl runs an other script (foo.pl) with the system call:

system foo.pl arg1 arg2 ;

I would like to have a status report (error flag) from foo.pl, which
does some exit's and die's at error occurences. How can I catch these
in MyScript.pl? What does die deliver as error code?
REgards,

Gabaux
If your error conditions are going to be simple enough you may consider 
catching the output of the program
like
pipeopen or backticks
$OUTPUT=`foo.pl args... 2>&1`  ;  This wont work on Micro$oft systems

else
Instead in your main program call
do "foo.pl args..."
And in foo.pl set some scope defined variable like

#foo.pl
$dbh=connect()
unless($dbh){
  $GLOBAL::ERRORSTR="Couldnot connect to database $@";
   exit 1
}
And in the main program you can check

if($GLOBAL::ERRORSTR) {
  # Hmm something went wrong
...
}

But personally I consider this as dirty work though it works. Let me 
know If you get a better way

Ram



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


RE: DBI execute problem

2003-07-17 Thread Balint, Jess
When you prepare a statement and use placeholders (?), they can only be used
for parameters such as "insert into sometable values ( ?, ?, ? )" or "where
somevar = ?". The parameters are bind to the statement when it is executed,
which means it must successfully being prepared already.

The do method is better in your case because your are not using parameters,
but using a perl variable in the name of the table. Since "create table
tableno? (  )" is not valid, you would need to prepare and execute every
time or just do().

-- Jess

> -Original Message-
> From: Ramprasad [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 17, 2003 10:22 AM
> To: [EMAIL PROTECTED]; Rob Dixon
> Cc: [EMAIL PROTECTED]
> Subject: Re: DBI execute problem
> 
> 
> > Hi Ram.
> > 
> > If all you're doing is to create a number of tables then I'd
> > get Perl to write the whole SQL statement for you and just
> > 
> >   $dbh-do($sql)
> > 
> > Even so, what you've written is weird. You're creating a 
> set of thirty
> > tables, each with two character columns with a maximum length equal
> > to the table number. Is this just an example?
> 
> You are right it is weird. But just a test script to learn 
> DBI. What I 
> really want is how Can I use prepare and execute which I 
> think is better 
> than doing a do every time If my table name keeps changing
> 
> Is a prepare statement always specific to a table in a database ?
> 
> I mean Cant I do
> .
> $sth=$dbh->prepare("insert into ? (word,wkey) values ( ? , ?)")
> foreach $word ( @list) {
> my $tablename = "w" . length($word);
> $sth->execute($tablename,$word,foo($word)) || die $dbh->errstr;
>   # $tablename gets quoted here and gives error
> }
> 
> 
> I have been using perl  with Mysql module and now I want to 
> shift to DBI
> 
> 
> Thanks
> Ram
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

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



Re: file changed??

2003-07-17 Thread Jenda Krynicky
From: "Jose M.Herrera" <[EMAIL PROTECTED]>
> I need to make a perl program which print "Changed!" when a file
> xx.txt is changed. please, any idea??

Since you are using Outlook I assume you want this under Windows, 
right? Take a look at Win32::ChangeNotify module.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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



RE: help me out please ..

2003-07-17 Thread wiggins

On 17 Jul 2003 08:23:54 -, "vemulakonda uday bhaskar" <[EMAIL PROTECTED]> wrote:

> 
> hi all,
> 
> i am tring to tranfer files between two linux systems through 
> sftop

Please use a more descriptive subject line, "help me out please" is not terribly to 
the point.

> 
> i have installed the following modules :
> 



> 
> 
> and my original code is :
> 
> 
> #!/usr/bin/perl
> 
> use Net::SFTP:
> 
> use strict;
> use warnings;
> 
> my $host="192.168.255.214";
> my $user="shuban";
> my $password="shuban";
> my $proto="sftp";
> 
> my
> $hp=Net::SFTP->new("$host",user=>"$user",password=>"$password",proto=>"$proto")
> or die "not connected";
> 

>From the Net::SFTP and Net::SSH::Perl docs there does not appear to be a 'proto' 
>argument.  And if you are referring to the 'protocol' argument, it would need to be 
>some combination of 1 and 2, though for Net::SFTP I believe it forces 2.

> and the error displayed after running the perl file with the above 
> code is :
> 
> "Request for subsystem 'sftp' failed on channel '1' at
> /usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 66."
> 
> please help in this regard.
> 
> i have sent a mail earlier with the same problem , but i got reply 
> fort sending the original code. the code above is the original 
> code .
> 

Right and asking that you turn the debug flag on and provide the output from the 
session which your message still did not include, and that is probably going to be the 
most helpful information you can provide.

http://danconia.org

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



Re: DBI execute problem

2003-07-17 Thread Ramprasad
Hi Ram.

If all you're doing is to create a number of tables then I'd
get Perl to write the whole SQL statement for you and just
  $dbh-do($sql)

Even so, what you've written is weird. You're creating a set of thirty
tables, each with two character columns with a maximum length equal
to the table number. Is this just an example?
You are right it is weird. But just a test script to learn DBI. What I 
really want is how Can I use prepare and execute which I think is better 
than doing a do every time If my table name keeps changing

Is a prepare statement always specific to a table in a database ?

I mean Cant I do
.
$sth=$dbh->prepare("insert into ? (word,wkey) values ( ? , ?)")
foreach $word ( @list) {
   my $tablename = "w" . length($word);
   $sth->execute($tablename,$word,foo($word)) || die $dbh->errstr;
 # $tablename gets quoted here and gives error
}

I have been using perl  with Mysql module and now I want to shift to DBI

Thanks
Ram








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


Re: Creating html source ...

2003-07-17 Thread Jamie Risk
er, sorry.

Is there a module to produce html formatted output? If so, would I be
directed to some documentation?

> > I have to assume that any of the simple HTML-izing I want to do
> > with simple text files has already been done.  I'm guessing
> > modules, particularly "CGI" but would appreciate a directed pointer
> > to docs.
> >
>
> The question is?
>
> Rob




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



RE: Is there anyway to modify my bios clock by perl ?

2003-07-17 Thread wiggins
---
On Thu, 17 Jul 2003 09:20:20 +0800, "LI NGOK LAM" <[EMAIL PROTECTED]> wrote:

> Is there anyway to modify my BIOS clock by Perl ?
> and more, is there anyway to adjust my BIOS clock, so
> to sync. with other time servers ?
> 

1) This is a very OS/hardware/BIOS specific question.  While it should be the last 
resort, there is a good chance you will hit last resort territory on this issue, you 
can always shell out to a utility that will do it for you. For instance 'hwclock' 
available on most Linuxes and maybe other *nixes, will set the bios clock.

2) Presumably your system clock is set to the bios clock, and there should be a way to 
hook into the time daemon that is doing the setting of the system clock to find out 
when it has done an update, then just run whatever method you have for #1.  Some of 
the time servers may have this capability built-in, but then that really isn't a Perl 
question...

http://danconia.org

This should be sufficient for most applications, though we aren't talking real time 
clock support or anything that precise.

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



RE: Porting perl scripts on windows

2003-07-17 Thread Janek Schleicher
Sharad Gupta wrote at Wed, 16 Jul 2003 21:03:49 -0700:

> Ok, Let me try to put it the other way.
> 
> Any good books on how to learn perl on windows??.

What about
"Learning Perl on Win32 Systems"
by Randal L. Schwartz, Tom Christiansen, Erik Olsen
from O'Reilly


Greetings,
Janek

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



Please help !! Socket

2003-07-17 Thread Pandey Rajeev-A19514
Hi,

I want to create differnent Socket Handles in a function and the function creates the 
created Socket Handle..
my $sock = gensym(); 

I am getting the same instance of Handle "S".

Please some one tell me how to create different instances of sockets in perl.

Regards
Rajeev

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



RE: Pattern matching

2003-07-17 Thread Ruben Montes
thanks it's solved

-Mensaje original-
De: Sparrow, Dave [mailto:[EMAIL PROTECTED]
Enviado el: jueves, 17 de julio de 2003 15:38
Para: Ruben Montes; '[EMAIL PROTECTED]'
Asunto: RE: Pattern matching


How about this:

$_ = "<45>13: 16:18:46: %SYS-5-CONFIG_I";
print "$1\n" if /(%.*)$/;

or, if you're reading lots of lines like this from a file:

while(<>) {
  print "$1\n" if /(%.*)$/;
}

Cheers,
Dave


-Original Message-
From: Ruben Montes [mailto:[EMAIL PROTECTED]
Sent: 17 July 2003 10:21
To: '[EMAIL PROTECTED]'
Subject: Pattern matching


Hello,

I have this string: 

<45>13: 16:18:46: %SYS-5-CONFIG_I

and I only want to print all the characters behind %:

%SYS-5-CONFIG_I

How can I make this?

Regards
 

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

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



RE: Pattern matching

2003-07-17 Thread Sparrow, Dave
How about this:

$_ = "<45>13: 16:18:46: %SYS-5-CONFIG_I";
print "$1\n" if /(%.*)$/;

or, if you're reading lots of lines like this from a file:

while(<>) {
  print "$1\n" if /(%.*)$/;
}

Cheers,
Dave


-Original Message-
From: Ruben Montes [mailto:[EMAIL PROTECTED]
Sent: 17 July 2003 10:21
To: '[EMAIL PROTECTED]'
Subject: Pattern matching


Hello,

I have this string: 

<45>13: 16:18:46: %SYS-5-CONFIG_I

and I only want to print all the characters behind %:

%SYS-5-CONFIG_I

How can I make this?

Regards
 

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



Re: DBI execute problem

2003-07-17 Thread Rob Dixon
Ramprasad wrote:
> Hello all,
>
> I have a mysql database and I want to create tables
> w1 w2 w3 w4 ... w30
>
> Can I use the prepare and execute methods of DBI
> I am getting an error because DBI is quoting the table name and
> Mysql is not accepting it
>
> This is my code
>
> #!/usr/bin/perl
> use DBI;
> use strict;
>
> my $dbh = DBI->connect( 'DBI:mysql:database=words;host=;port=3306',
>  "", "" ) or die "Can't connect to Mysql database:
> $DBI::errstr\n";
>
> my $sql="CREATE TABLE ? (word VARCHAR( ? ) DEFAULT 'a' NOT NULL
> ,'wkey' VARCHAR( ? ) DEFAULT 'a' NOT NULL ,PRIMARY KEY ( word ))";
> my $sth = $dbh->prepare( $sql ) || die $dbh->errstr;
>
> my($i);
> foreach $i ( 1..30){
>$sth->execute("w$i",($i+1),($i+1)) || die $dbh->errstr;
>print "Created w$i\n";
> }
>
>
> Error
>
> DBD::mysql::st execute failed: You have an error in your SQL syntax.
> Check the manual that corresponds to your MySQL server version for
> the right syntax to use near ''w1' (word VARCHAR( 2 ) DEFAULT 'a'
> NOT NULL ,'wkey' VARCHAR( 2 at ./createsql.pl line 13.
>
>
>
> The problem is with the execute statement
> I know I can use the do statement and put the entire sql in the
> loop but
> Is there a way I can so it using prepare and execute

Hi Ram.

If all you're doing is to create a number of tables then I'd
get Perl to write the whole SQL statement for you and just

  $dbh-do($sql)

Even so, what you've written is weird. You're creating a set of thirty
tables, each with two character columns with a maximum length equal
to the table number. Is this just an example?

To show you what I mean, here's a sample. It prints out
each SQL statement instead of executing 'do' on the string.

HTH,

Rob


  use strict;
  use warnings;

  foreach my $n ( 1 .. 30 ) {
my $sql = 

Simple process controll question

2003-07-17 Thread Gabor Urban
Hi,

I think the question at hand may be quite simple, though I could not
figure the asnwer out :-))

MyScript.pl runs an other script (foo.pl) with the system call:

system foo.pl arg1 arg2 ;

I would like to have a status report (error flag) from foo.pl, which
does some exit's and die's at error occurences. How can I catch these
in MyScript.pl? What does die deliver as error code?

REgards,

Gabaux

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



RE: Sockets

2003-07-17 Thread Kipp, James
 
> 
> In the documentation of socket appears the fllowing:
> $sockaddr = 'S n a4 x8'
> 
> What means this???

it is a template for packing the generic C socket adr structure. readup on
sockets for deeper explanation. the adt string is packed into structure of:
a signed short, followed by an integer in network order, four unsigned
bytes, and eight NULL characters.

YOUR MUCH better off using sockaddr_in() to handle this for you.



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



Re: newbie : obtain gid of the current user

2003-07-17 Thread Sylvain Masnada
Hi again and thx John for you help.
> > Hi all,
> 
> Hello,
> 
> > I'd like to get a script which allows me to get the gid of the
> > user which is connected currently.
> > I've done this "script" which is not very useful for me because
> > I have to run it like this :
> > id | myscript.pl
> 
> You could run id inside your perl program.
> 
> my $id_output = qx/id/;
I didn't know how to execute a shell command into a perl script, thx.

> > My script is :
> > 
> > while(<>)
> > {
> > if(/^uid=\d+.\w+.\sgid=(\d+)/)
> > {
> > $gid=$1;
> > print "gid:$gid\n";
> > }
> > }
> 
> Perl supplies the User ID in $<, the Effective User ID in $>, the Group
> ID in $( and the Effective Group ID in $).

What's the difference between effective and non-effective, the answer are the same for 
: print
"$>, $<\n" and idem for group
Moreover when I do this 
print "gid: $)\n"; 
I get (as root) : gid: 0 10 6 4 3 2 1 0
not just 0. How to get just the true gid?


> 
> print "gid: $(\n";
> 
> 
> To find the name assigned to $(:
> 
> my $group = getgrgid $(;
> print "Group: $group\n";
> 
> 
> To get all groups that $( belongs to:
> 
> my @groups;
> my $name = getpwuid $<;
> while ( my @ent = getgrent ) {
> push @groups, $ent[ 0 ] if $ent[ -1 ] =~ /\b$name\b/;
> }
> print "@groups\n"
> 
> 
> > My aim is to change the ip address following the gid.
> 
> The id program does not output an ip address.
Yes I know. My first goal was to get the gid. Now I want to attribute ip address by 
gid, maybe
thanks to :

if ($( == 1000)
{
qx/ifconfig eth0 x.x.x.x up/;
}

elseif ($( == 1001)
{
qx/ifconfig eth0 x.x.x.y up/;
}
 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  

___
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

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



RE: secure socket connection

2003-07-17 Thread Kipp, James
> 
> 
> I'm trying to set up credit card processing and one of the 
> first steps is to 
> establish a "secure socket connection" - how can i do it? (My 
> host does 
> support it)
> 

there are som modules for this:
IO::Socket::SSL 
Net::Daemon::SSL 


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



Re: newbie : obtain gid of the current user

2003-07-17 Thread Sylvain Masnada
Hi again and thx John for you help.
> > Hi all,
> 
> Hello,
> 
> > I'd like to get a script which allows me to get the gid of the
> > user which is connected currently.
> > I've done this "script" which is not very useful for me because
> > I have to run it like this :
> > id | myscript.pl
> 
> You could run id inside your perl program.
> 
> my $id_output = qx/id/;
I didn't know how to execute a shell command into a perl script, thx.

> > My script is :
> > 
> > while(<>)
> > {
> > if(/^uid=\d+.\w+.\sgid=(\d+)/)
> > {
> > $gid=$1;
> > print "gid:$gid\n";
> > }
> > }
> 
> Perl supplies the User ID in $<, the Effective User ID in $>, the Group
> ID in $( and the Effective Group ID in $).

What's the difference between effective and non-effective, the answer are the same for 
: print
"$>, $<\n" and idem for group
Moreover when I do this 
print "gid: $)\n"; 
I get (a : gid: 0 10 6 4 3 2 1 0
not just 0. How to get just the true gid?


> 
> print "gid: $(\n";
> 
> 
> To find the name assigned to $(:
> 
> my $group = getgrgid $(;
> print "Group: $group\n";
> 
> 
> To get all groups that $( belongs to:
> 
> my @groups;
> my $name = getpwuid $<;
> while ( my @ent = getgrent ) {
> push @groups, $ent[ 0 ] if $ent[ -1 ] =~ /\b$name\b/;
> }
> print "@groups\n"
> 
> 
> > My aim is to change the ip address following the gid.
> 
> The id program does not output an ip address.
Yes I know. My first goal was to get the gid. Now I want to attribute ip address by 
gid, maybe
thanks to :

if ($( == 1000)
{
qx/ifconfig eth0 x.x.x.x up/;
}

elseif ($( == 1001)
{
qx/ifconfig eth0 x.x.x.y up/;
}


> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  

___
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

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



RE: Porting perl scripts on windows

2003-07-17 Thread Kipp, James
here is a nice tutorial to start with:
http://www.sthomas.net/roberts-perl-tutorial.htm

> -Original Message-
> From: Gupta, Sharad [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 17, 2003 12:04 AM
> To: Gupta, Sharad; [EMAIL PROTECTED]
> Subject: RE: Porting perl scripts on windows
> 
> 
> Ok, Let me try to put it the other way.
> 
> Any good books on how to learn perl on windows??.
> 
> Thanx,
> -Sharad
> 
> -Original Message-
> From: Gupta, Sharad 
> Sent: Wednesday, July 16, 2003 12:41 PM
> To: [EMAIL PROTECTED]
> Subject: Porting perl scripts on windows
> 
> 
> 
> Hello Friends,
> 
> I have always been on Unix and perl. Now i wanted to port 
> some of my scripts to Windows.
> Any pointers to web/books for understanding the implications 
> is appreciated??
> 
> TIA,
> -Sharad
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


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



RE: Variable "$q" will not stay shared at

2003-07-17 Thread Bob Showalter
B. Fongo wrote:
> Hello,
> 
> I'm working on my first Perl project. Most of my cgi programs work ok,
> but a look at the apache error log reveals this warning which is
> clear to me: 
> 
> Variable "$xy" will not stay shared at
> /data/www/cgi-perl/envir.pl line
> 19. [Wed Jul 16 11:44:57 2003] [error] Undefined subroutine
> &Apache::ROOT::cgi_2dperl::environ_2epl::start_html called at
> /data/www/cgi- perl/envir.pl line 20.
> 
> For instance: This code will trigger such warning.
> 
> #!/usr/bin/perl -w
> use strict;
> use CGI;
> my $xy = new CGI;
> print $xy->header();
> print $xy->start_html();
> print $xy->p(" Perl-CGI");
> print $xy->end_html;
> 
> #
> 
> I tried several alternatives, like invoking print() only once at
> header. But I can't feature out what that warning actually means. My
> apache is configure with mod_perl. 

The problem is caused by the way Apache::Registry handles your script. 
For the gory details see:


The solution I always use is to change all file-scoped lexicals to globals
and protect them with "local" so you get fresh copies with each request.

Instead of:

   my $xy = new CGI;

Do:

   our $xy;
   local $xy = new CGI;

> 
> Besides that, my project will consist of 1 main Perl script and
> several modules in a subdirectory which will be performing various
> functions. Now; what I intend to do is always send the main script a
> parameter through the URL, which will then indicate which of the
> modules should be called.  Each of my modules will contains
> subroutines for various functions: My question is: How do I send a
> parameter to my script through a link on my web page? I tried
> something like this, but did not work. 

What did it do?

> 
> A cup of
> coffee  

That looks OK, except that the URL is relative, so you need to make
sure you know where you are.

> 
>   What I'm trying to do here is to send the string "cup_of_coffee" to
> the main program. 
> 
> The main program will have something like this to store the parameter
> from the url: @forwarded_by_url = ??? # Am not sure here.

Assuming $xy is the CGI object:

   $action = $xy->param('action');   # sets $action to 'cup_of_coffee'

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



DBI execute problem

2003-07-17 Thread Ramprasad
Hello all,

I have a mysql database and I want to create tables
w1 w2 w3 w4 ... w30
Can I use the prepare and execute methods of DBI
I am getting an error because DBI is quoting the table name and Mysql is 
not accepting it

This is my code

#!/usr/bin/perl
use DBI;
use strict;
my $dbh = DBI->connect( 'DBI:mysql:database=words;host=;port=3306', "", "" )
or die "Can't connect to Mysql database: $DBI::errstr\n";
my $sql="CREATE TABLE ? (word VARCHAR( ? ) DEFAULT 'a' NOT NULL ,'wkey' 
VARCHAR( ? ) DEFAULT 'a' NOT NULL ,PRIMARY KEY ( word ))";
my $sth = $dbh->prepare( $sql ) || die $dbh->errstr;

my($i);
foreach $i ( 1..30){
  $sth->execute("w$i",($i+1),($i+1)) || die $dbh->errstr;
  print "Created w$i\n";
}
Error

DBD::mysql::st execute failed: You have an error in your SQL syntax. 
Check the manual that corresponds to your MySQL server version for the 
right syntax to use near ''w1' (word VARCHAR( 2 ) DEFAULT 'a' NOT NULL 
,'wkey' VARCHAR( 2 at ./createsql.pl line 13.



The problem is with the execute statement
I know I can use the do statement and put the entire sql in the loop but 
Is there a way I can so it using prepare and execute

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


RE: Pattern matching

2003-07-17 Thread Boon Chong Ang
while(<>){
@arr =split(" ",$_);
$arr[2] =~s/\%//g; ## I am not sure whether % is a meta
## character or not. If it is not a meta character, just remove the "\"
}

I am also a perl beginner. 

Thank you & best regards,
ABC

-Original Message-
From: Ruben Montes [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 17, 2003 5:21 PM
To: '[EMAIL PROTECTED]'
Subject: Pattern matching

Hello,

I have this string: 

<45>13: 16:18:46: %SYS-5-CONFIG_I

and I only want to print all the characters behind %:

%SYS-5-CONFIG_I

How can I make this?

Regards
 

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

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



Re: Comparing two strings for first difference

2003-07-17 Thread Rob Anderson
Hi Paul

"Rob Anderson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> "Paul Archer" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> [snip]
>
> >
> > If anyone can offer general improvements to that approach, that'd be
> > great--but what I'm really interested in is finding the first element
that
> > differs, and maybe the last as well. If there were any easy way to find
> > that, say, the first character that differs is at position 120, and the
> last
> > character that differs is at position 135, then I only have to loop
> through
> > 15 characters, not 160.
>
> Probably the quickest way to do this in perl is as follows
>
> 
> #!/perl -w
> use strict;
> my $string1 = "The quick brown fox.";
> my $string2 = "The Kuick brUwn fox.";
>
> my $string_xor = ("$string1" ^ "$string2");
>
> $string_xor =~ /^(\0*)/;
> print "Number of equal bytes at the front of the string = " . length($1) .
> "\n";
> $string_xor =~ /(\0*)$/;
> print "Number of equal bytes at the end of the string = " . length($1) .
> "\n";
> 
>
> the xor op (^) will return a string, every matching byte of which will be
> null, every mismatching byte will have some bit (literaly) set.
>
> so the all first regex does is match the all the null bytes it can find
from
> the front of the string, the length of the string is equivalent to the
> number of identical chars at the front.
> The second regex is the same, just working from the end.
>
> You could extend this and translate all the non-null values to something
you
> could then search for that value with index. This would give you the
> positions of all the bytes that were different...
>
> my $string_xor = ("$string1" ^ "$string2");

missed the actual traslation...  :-$
$string_xor =~ s/[^\0]/X/g;

> my $pos = 0;
> while ( ($pos = index($string_xor, 'X', $pos)) != -1) {
>print "==> $pos\n";
>$pos++;
> }
>
> Hope this helps,
>
> Rob
>
> >
> > TIA,
> >
> > paul
> >
> >
> > -
> > On the side of the software box, in the "System Requirements" section,
> > it said "Requires Windows 95 or better".  So I installed Linux.
> > -
>
>



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



Pattern matching

2003-07-17 Thread Ruben Montes
Hello,

I have this string: 

<45>13: 16:18:46: %SYS-5-CONFIG_I

and I only want to print all the characters behind %:

%SYS-5-CONFIG_I

How can I make this?

Regards
 

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



Re: Comparing two strings for first difference

2003-07-17 Thread Rob Anderson

"Paul Archer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

[snip]

>
> If anyone can offer general improvements to that approach, that'd be
> great--but what I'm really interested in is finding the first element that
> differs, and maybe the last as well. If there were any easy way to find
> that, say, the first character that differs is at position 120, and the
last
> character that differs is at position 135, then I only have to loop
through
> 15 characters, not 160.

Probably the quickest way to do this in perl is as follows


#!/perl -w
use strict;
my $string1 = "The quick brown fox.";
my $string2 = "The Kuick brUwn fox.";

my $string_xor = ("$string1" ^ "$string2");

$string_xor =~ /^(\0*)/;
print "Number of equal bytes at the front of the string = " . length($1) .
"\n";
$string_xor =~ /(\0*)$/;
print "Number of equal bytes at the end of the string = " . length($1) .
"\n";


the xor op (^) will return a string, every matching byte of which will be
null, every mismatching byte will have some bit (literaly) set.

so the all first regex does is match the all the null bytes it can find from
the front of the string, the length of the string is equivalent to the
number of identical chars at the front.
The second regex is the same, just working from the end.

You could extend this and translate all the non-null values to something you
could then search for that value with index. This would give you the
positions of all the bytes that were different...

my $string_xor = ("$string1" ^ "$string2");
my $pos = 0;
while ( ($pos = index($string_xor, 'X', $pos)) != -1) {
   print "==> $pos\n";
   $pos++;
}

Hope this helps,

Rob

>
> TIA,
>
> paul
>
>
> -
> On the side of the software box, in the "System Requirements" section,
> it said "Requires Windows 95 or better".  So I installed Linux.
> -



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



Re: Regular Expression (fwd)

2003-07-17 Thread Sudarshan Raghavan
trensett wrote:

-- Forwarded message --
Date: Wed, 16 Jul 2003 18:23:35 -0500 (EST)
From: trensett <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: Regular Expression


On Wed, 16 Jul 2003, Janek Schleicher wrote:

 

Nick Diel wrote at Tue, 15 Jul 2003 11:12:18 -0600:

   

I am having a hard time getting a regular expression to work the way i want
it to.  Take the following text: bla bla bla (la la) bla bla (di da)
I want to extract the la la to one variable  and di da to antoher variable.
What I have tried so far is using match variables, but so far I am only able
to match either just la la or la la) bla bla (di da.
 

It would be better if you show us not only a description of your code, but
your real code.
The next will work:
my @variable = $string =~ /\((.*?)\)/g;
   

what's the exact implication of ".*?"?
Why wouldn't just .* in parenthesis work for this case?
The regex engine is greedy by nature, it will get the longest possible 
match for the given regex. In this case that will be 'la la) bla bla (di 
da'. The regex says get the match between a '(' and a ')' . The '? after 
the pattern makes it to fetch the smallest possible match i.e. disable 
the greediness. Try the example out with and without the '?' and check 
the output.

my $str = 'bla bla bla (la la) bla bla (di da)';
if ($str =~ /\((.*?)\)/) {
   print $1, "\n";
}
if ($str =~ /\((.*)\)/) {
   print $1, "\n";
}


 

Now $variable[0] contains 'la la' and
   $variable[1]  ' di da'.
Greetings,
Janek


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


help me out please ..

2003-07-17 Thread vemulakonda uday bhaskar
hi all,

i am tring to tranfer files between two linux systems through 
sftop

i have installed the following modules :

1.  Download Net::FTP and Install
2.  Download Net::SFTP .
1.  PreRequisite for Install  Net::SFTP is  Net::SSH::Perl
2.  PreRequisite for Net::SSH::Perl is
2.1 Protocol 1:
2.1.1   Math::GMP
2.1.2   String::CRC32
2.1.3   Digest::MD5
2.1.4   IO::Socket
2.2 Protocol 2:
2.2.1   Crypt::DSA   (version 0.03 or Greater)
2.2.2   Crypt::DH (version 0.01 or Greater)
2.2.3   Math::Pari (version 2.001804 or Greater)
2.2.4   MIME::Base64
2.2.5   Digest::MD5
2.2.6   Convert::PEM(version 0.05 or Greater)
2.2.7   IO::Socket
3.  PreRequisite  for Crypt::DSA
3.1  Digest::SHA1
3.2  Math::Pari (version 2.001800 or Greater)
3.3  Crypt::Random  (version 0.33 or Greater)
PreRequisite for Crypt::Random
3.3.1   Class::Loader
4.  PreRequisite for Crypt::DH
4.1Math::Pari  (version 2.001804 or Greater).
4.2 Crypt::Random  (version 0.33 or Greater).
5.  PreRequisite for Convert::PEM
5.1  MIME::Base64
5.2  Convert::ASN1(version 0.10 or Greater)
5.3  Digest::MD5
5.4  Crypt::DES_EDE3
PreRequisite for  Crypt::DES_EDE3
5.4.1   Crypt::DES
PreRequisite for Crypt::DES
5.4.1.1 Crypt::CBC
PreRequisite for Crypt::CBC
5.4.1.1.1   Crypt::Rijndael
6.  PreRequisite for Math::GMP
6.1 gmp-4.1.2
and also Net-SSH-0.07

and my original code is :

#!/usr/bin/perl

use Net::SFTP:

use strict;
use warnings;
my $host="192.168.255.214";
my $user="shuban";
my $password="shuban";
my $proto="sftp";
my
$hp=Net::SFTP->new("$host",user=>"$user",password=>"$password",proto=>"$proto")
or die "not connected";
and the error displayed after running the perl file with the above 
code is :

"Request for subsystem 'sftp' failed on channel '1' at
/usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 66."
please help in this regard.

i have sent a mail earlier with the same problem , but i got reply 
fort sending the original code. the code above is the original 
code .

please help me rectify my problem

with regards
uday
___
Download the hottest & happening ringtones here!
OR SMS: Top tone to 7333
Click here now: 
http://sms.rediff.com/cgi-bin/ringtone/ringhome.pl



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


RE: Regular Expression (fwd)

2003-07-17 Thread Nigel Peck - MIS Web Design
? means minimal matching not maximal, so without the question mark it would match up 
to the second closing paren in the following line.

( test data )   ( more test data )

which is not what you want, it would match up to the last closing paren in the data 
you gave it, forgetting about newlines, with the question mark it matches up to the 
first, which is what you want (I assume).

no ? = greedy
? = on a diet

Cheers,
Nigel

> -Original Message-
> From: trensett [mailto:[EMAIL PROTECTED]
> Sent: 17 July 2003 00:30
> To: [EMAIL PROTECTED]
> Subject: Re: Regular Expression (fwd)
> 
> 
> 
> 
> -- Forwarded message --
> Date: Wed, 16 Jul 2003 18:23:35 -0500 (EST)
> From: trensett <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: Regular Expression
> 
> 
> 
> On Wed, 16 Jul 2003, Janek Schleicher wrote:
> 
> > Nick Diel wrote at Tue, 15 Jul 2003 11:12:18 -0600:
> >
> > > I am having a hard time getting a regular expression to work 
> the way i want
> > > it to.  Take the following text: bla bla bla (la la) bla bla (di da)
> > >
> > > I want to extract the la la to one variable  and di da to 
> antoher variable.
> > > What I have tried so far is using match variables, but so far 
> I am only able
> > > to match either just la la or la la) bla bla (di da.
> >
> > It would be better if you show us not only a description of 
> your code, but
> > your real code.
> >
> > The next will work:
> > my @variable = $string =~ /\((.*?)\)/g;
> 
> what's the exact implication of ".*?"?
> Why wouldn't just .* in parenthesis work for this case?
> 
> 
> >
> > Now $variable[0] contains 'la la' and
> > $variable[1]  ' di da'.
> >
> >
> > Greetings,
> > Janek
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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



Re: Regular Expression (fwd)

2003-07-17 Thread trensett


-- Forwarded message --
Date: Wed, 16 Jul 2003 18:23:35 -0500 (EST)
From: trensett <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: Regular Expression



On Wed, 16 Jul 2003, Janek Schleicher wrote:

> Nick Diel wrote at Tue, 15 Jul 2003 11:12:18 -0600:
>
> > I am having a hard time getting a regular expression to work the way i want
> > it to.  Take the following text: bla bla bla (la la) bla bla (di da)
> >
> > I want to extract the la la to one variable  and di da to antoher variable.
> > What I have tried so far is using match variables, but so far I am only able
> > to match either just la la or la la) bla bla (di da.
>
> It would be better if you show us not only a description of your code, but
> your real code.
>
> The next will work:
> my @variable = $string =~ /\((.*?)\)/g;

what's the exact implication of ".*?"?
Why wouldn't just .* in parenthesis work for this case?


>
> Now $variable[0] contains 'la la' and
> $variable[1]  ' di da'.
>
>
> Greetings,
> Janek
>
>
>
> --
> 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]



Comparing two strings for first difference

2003-07-17 Thread Paul Archer
I'm working on a bit of code to update a serial LCD display. The display is
4 lines by 40 characters, and each character can be addressed individually.

First, the pseudocode I have is:

compare each element of the new string and the old string
# each string is 160 characters, and represents what is on the
# display or what is going on the display

(if the characters differ) {
(if the state flag is not set) {
 set it and concatenate the direct-positioning characters
to a temp string, along with the new character
} else {
just concatenate the current element of the new string to
the temp string
};
} else {
(if the state flag is not set) {
go to next element
} else {
(if one of the next three characters has changed) {
keep state flag set, add character to temp string
# idea here is it's cheaper to just print a character
# that hasn't changed than a new set of positioning
# characters if another character right after it has changed
} else {
unset flag
}
}
}

If anyone can offer general improvements to that approach, that'd be
great--but what I'm really interested in is finding the first element that
differs, and maybe the last as well. If there were any easy way to find
that, say, the first character that differs is at position 120, and the last
character that differs is at position 135, then I only have to loop through
15 characters, not 160.

TIA,

paul


-
On the side of the software box, in the "System Requirements" section,
it said "Requires Windows 95 or better".  So I installed Linux.
-

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