Re: how to know the object type

2007-04-04 Thread Ovid
--- Jeff Pang [EMAIL PROTECTED] wrote:

 
 If I'm not mistaken, all Perl objects are references to a hash.
 
 
 Not correct at all.
 Perl objects can be anything that's the blessed references.

This is correct. It's another reason why you don't want to care about
what data structure is being used.  The class author needs the freedom
to choose the data structure he or she needs.  If you find that you
can't get the information/behavior you want without knowing the data
structure, then supply the author with a patch which fixes the broken
class or use a class which isn't broken.

DO NOT pay attention to what type of reference it is.  There are many,
many years of collective wisdom in that*

Cheers,
Ovid

* Yes, there are time you may need to know what the reference is, but
this is usually with black magic type wizardry.  With all due respect,
if you have to ask how to figure out what the reference is, then you
won't know what those times are.

--

Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/

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




Using case in Perl

2007-04-04 Thread Rodrigo Tavares
Hello,

I'm changing the script postgresq-init.sh for
postgresql-init.pl. I made all perl scripts for store
the database names. But my doubt is the case.

In bash i have:

#case $1 in
#  start)
#   $ECHO_N Starting PostgreSQL: $ECHO_C
#   su - $PGUSER -c $DAEMON -D '$PGDATA' 
$PGLOG 21
#   echo ok
#   ;;

In perl, How I to build it ?

I saw :

SWITCH: {
 if (/^abc/) { $abc = 1; last SWITCH; }
 if (/^def/) { $def = 1; last SWITCH; }
 if (/^xyz/) { $xyz = 1; last SWITCH; }
 $nothing = 1;
   }

I don't imagine with use the switch for start the
postgres. Do I have system command ?

Best regards.

Faria


 

__
Fale com seus amigos  de graça com o novo Yahoo! Messenger 
http://br.messenger.yahoo.com/ 

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




Re: Using case in Perl

2007-04-04 Thread Jeff Pang

In bash i have:

#case $1 in
#  start)
#   $ECHO_N Starting PostgreSQL: $ECHO_C
#   su - $PGUSER -c $DAEMON -D '$PGDATA' 
$PGLOG 21
#   echo ok
#   ;;

In perl, How I to build it ?


How about this?

if ($ARGV[0] eq 'start') {
print Starting PostgreSQL:\n;
unless (fork) {
exec su - $PGUSER -c \$DAEMON -D \'$PGDATA\' ;
}else {
 print ok\n;
 exit;
}

} elsif ($ARGV[0] eq 'stop') {

}

Perl doesn't have the switch control statement.
But you can get it by looking at CPAN:
http://search.cpan.org/~rgarcia/Switch-2.13/Switch.pm

--
mailto: [EMAIL PROTECTED]
http://home.arcor.de/jeffpang/

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




Re: Using case in Perl

2007-04-04 Thread Igor Sutton Lopes


On 2007/04/04, at 14:58, Jeff Pang wrote:



How about this?

if ($ARGV[0] eq 'start') {
print Starting PostgreSQL:\n;
unless (fork) {
exec su - $PGUSER -c \$DAEMON -D \'$PGDATA\' ;
}else {
 print ok\n;
 exit;
}

} elsif ($ARGV[0] eq 'stop') {

}


Or maybe this:

code
sub start {
print Starting PostgreSQL: , $/;
unless (fork) {
exec qq{su - $PGUSER -c $DAEMON -D '$PGDATA'};
}
else {
print OK, $/;
exit;
}
}

sub stop {
...
}

my %functions = (
start = \start,
stop = \stop,
...
);

$functions{$ARGV[0]}-();
/code

This approach is called 'dispatch table' and is very common on Perl  
code.


Good luck!

--
Igor Sutton
[EMAIL PROTECTED]





PGP.sig
Description: This is a digitally signed message part


Re: Using case in Perl

2007-04-04 Thread Chas Owens

On 4/4/07, Igor Sutton Lopes [EMAIL PROTECTED] wrote:
snip

unless (fork) {

snip

The fork function has three returns: undef, zero, and non-zero.  It
returns 0 to the child and a pid that is non-zero to the parent on
success or undef to the parent on failure.  It is important to catch
this error:

my $pid = fork;
die fork failed unless defined $pid;
unless ($pid) {

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




removing special characters

2007-04-04 Thread Michael Gargiullo
I have a log file I’m parsing that has special characters at the end of each 
row.  In vi it appears to be  ^@  I’ve already tried chomp and s/\^\@//  
Neither work.   Does any one have any ideas?

-Mike

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.25/744 - Release Date: 4/3/2007 5:32 
AM
 

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




Re: removing special characters

2007-04-04 Thread Jeff Pang

I have a log file I’m parsing that has special characters at the end of each 
row.  In vi it appears to be  ^@  I’ve already tried chomp and s/\^\@//  
Neither work.   Does any one have any ideas?


For the fast resolving,you can use the unix shell command dos2unix to 
translate it.
$ dos2unix doc.txt

--
mailto: [EMAIL PROTECTED]
http://home.arcor.de/jeffpang/

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




Re: removing special characters

2007-04-04 Thread Chas Owens

On 4/4/07, Michael Gargiullo [EMAIL PROTECTED] wrote:

I have a log file I'm parsing that has special characters at the end of each 
row.  In vi it appears to be  ^@  I've already tried chomp and s/\^\@//  
Neither work.   Does any one have any ideas?

snip

^@ is one character not two.  It is a control character.  If I
remember correctly it is the nul character (ascii 0).  You could try
s/\000//.  If that doesn't work then run the following command to find
out what character it is

perl -ne 'for (split //) { $a = ord; printf %o\n, $a unless $a =  32 }' file

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




Can I map this

2007-04-04 Thread Beginner
Hi All,

I have a list of names all in uppercase that I would like to 
capitaIise. I can't help but think that map could make short work of 
this loop but I am not sure how. Is it possible to use map here 
instead of a for loop? I can see there are going to be issues with 
double-barrelled names but I'll cross that bridge later.


Thanx,
Dp,.

while (DATA) {

 my @words = split(/\s+/,$_);
 my $str;
 foreach my $w (@words) {
my $s = lc($w);
$s = ucfirst($s);
$str .= $s.' ';
 }
 print STR=$str\n;
}

__DATA__ 
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME


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




Re: removing special characters

2007-04-04 Thread Tom Phoenix

On 4/4/07, Michael Gargiullo [EMAIL PROTECTED] wrote:


I have a log file I'm parsing that has special characters at the end of each
row.  In vi it appears to be  ^@


You can use a hex-dump utility to see what characters are actually in
the file. On unix, I often use od. But if I've got the data in a Perl
string, I'll just use Perl:

   print , unpack(H*, $data), \n;  # debug hex dump


I've already tried chomp and s/\^\@//  Neither work.


You tried chomp? Did you also try sqrt? :-)

Even though that character looks like ^@ in a program such as vi,
that's not one of the ways Perl uses for writing special characters. I
suspect that this one is the NUL character, and vi is calling it
control-@ (which makes some sense from the ASCII chart). If that's
it, it's character zero, which can look as simple as \0.

   s/\0+//g;# strip NUL characters

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Can I map this

2007-04-04 Thread Igor Sutton Lopes


On 2007/04/04, at 16:28, Beginner wrote:


while (DATA) {

 my @words = split(/\s+/,$_);
 my $str;
 foreach my $w (@words) {
my $s = lc($w);
$s = ucfirst($s);
$str .= $s.' ';
 }
 print STR=$str\n;
}

__DATA__
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME


This was discussed sometime ago on Lisbon.pm :-)

code
while (DATA) {

my $str = join(  , map { s/\B(\w+)/\L\1/; $_ } split( /\s+/,  
$_ ) );

print str = $str\n;

}

__DATA__
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME
/code

--
Igor Sutton
[EMAIL PROTECTED]





PGP.sig
Description: This is a digitally signed message part


Re: Can I map this

2007-04-04 Thread Jason Roth

my $str = join  , map { ucfirst lc } @words;

should do what your for loop is doing.

-Jason

On 4/4/07, Beginner [EMAIL PROTECTED] wrote:

Hi All,

I have a list of names all in uppercase that I would like to
capitaIise. I can't help but think that map could make short work of
this loop but I am not sure how. Is it possible to use map here
instead of a for loop? I can see there are going to be issues with
double-barrelled names but I'll cross that bridge later.


Thanx,
Dp,.

while (DATA) {

 my @words = split(/\s+/,$_);
 my $str;
 foreach my $w (@words) {
my $s = lc($w);
$s = ucfirst($s);
$str .= $s.' ';
 }
 print STR=$str\n;
}

__DATA__
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME


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





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




Re: perl 5.10 questions

2007-04-04 Thread oryann9


 But this is all fairly complicated stuff and
 probably a little advanced
 for a beginners list.  You might find more joy
 asking on
 comp.lang.perl.moderated, or perlmonks.
 
 -- 
 Paul Johnson - [EMAIL PROTECTED]


yes but there are a lot of advanced members on the
list. ok thanks for responding!


 

Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

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




Re: Can I map this

2007-04-04 Thread John W. Krahn
Beginner wrote:
 Hi All,

Hello,

 I have a list of names all in uppercase that I would like to 
 capitaIise. I can't help but think that map could make short work of 
 this loop but I am not sure how. Is it possible to use map here 
 instead of a for loop? I can see there are going to be issues with 
 double-barrelled names but I'll cross that bridge later.
 
 
 Thanx,
 Dp,.
 
 while (DATA) {
 
  my @words = split(/\s+/,$_);
  my $str;
  foreach my $w (@words) {
   my $s = lc($w);
   $s = ucfirst($s);
   $str .= $s.' ';
  }
  print STR=$str\n;
 }
 
 __DATA__ 
 SOME NAME
 SOMEONE WITH FOUR NAMES
 ONE WITH THREE
 A-HYPENED NAME


Try it like this:

while ( DATA ) {
s/([[:alpha:]]+)/\L\u$1/g;
print STR=$_;
}

__DATA__
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Re: Can I map this

2007-04-04 Thread Randal L. Schwartz
 Igor == Igor Sutton Lopes [EMAIL PROTECTED] writes:

Igor my $str = join(  , map { s/\B(\w+)/\L\1/; $_ } split( /\s+/,  $_ ) 
);

It's bad style to modify $_ in a map, because that also modifies the incoming
data.  The simplest workaround is adding local:

@out = map { local $_ = $_; s/.../.../; $_ } @in

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: Can I map this

2007-04-04 Thread John W. Krahn
Beginner wrote:
 Hi All,

Hello,

 I have a list of names all in uppercase that I would like to 
 capitaIise. I can't help but think that map could make short work of 
 this loop but I am not sure how. Is it possible to use map here 
 instead of a for loop? I can see there are going to be issues with 
 double-barrelled names but I'll cross that bridge later.
 
 
 Thanx,
 Dp,.
 
 while (DATA) {
 
  my @words = split(/\s+/,$_);
  my $str;
  foreach my $w (@words) {
   my $s = lc($w);
   $s = ucfirst($s);
   $str .= $s.' ';
  }
  print STR=$str\n;
 }
 
 __DATA__ 
 SOME NAME
 SOMEONE WITH FOUR NAMES
 ONE WITH THREE
 A-HYPENED NAME


Try it like this:

while ( DATA ) {
s/([[:alpha:]]+)/\L\u$1/g;
print STR=$_;
}

__DATA__
SOME NAME
SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Re: Using case in Perl

2007-04-04 Thread oryann9
---
 
 Perl doesn't have the switch control statement.
 But you can get it by looking at CPAN:

http://search.cpan.org/~rgarcia/Switch-2.13/Switch.pm
 

To share some information in the up-incoming Perl 5.10
there will be a replacement for the switch clause.

The given-when is the Perl answer to the switch
(or case) keyword in other programming languages.
It replaces Switch.pm, which was a pre-Perl 5.10
source filter that did the same thing but didn't
always
work correctly.

#!/usr/bin/perl
use feature qw(say switch);
chomp( my $var = STDIN );
   given( $var ) {
  when( /\D/ ){ 
 say Needs a number!}
 when( $_ == 1 ) { 
 say Got 1! 
 }
 when( $_ == 2 ) { 
 say Got 2!
 }
 default { 
 say You said $_ 
 }
} ## END given


 

Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/

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




Japanese characters in utf8 and DBD::MySQL

2007-04-04 Thread Jb Van Puyvelde
Hello,

I would like to insert japanese characters into a MySql table, but it 
just produces stange symbols.

In a nutshell, I would like to cut up a japanese html page in little 
chunks and insert them into a database. I've no problem for reading the 
page and printing the japanese characters on screen with the Encode 
module, I just can't insert them properly.

Of course, the table uses the utf8 charset and utf8_unicode_ci coallition.
I've heard about patchs but they only works for reading.

Does anyone have a solution ?

Thanks in advance,

Jb


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




run system command in the background using CGI

2007-04-04 Thread Brian Volk
Hello,

 

I have web page that downloads and extracts images based on file
selection. The thank you page will not be displayed until the download
is complete... (Understandable).  One of the download files is quite big
and the web server is timing out. I would like to thank you page to be
displayed instantly while the download continues to run in the
background; kind of like the '' does at the end of a bash command. Is
this possible?

 

I thought for sure if I used a print Location: $search_results\n\n;
and then used the system command to launch the download script, it
would've worked... I was mistaken! :-)  

 

How can I get the $search_results page to come up and still run the
download program in the background?

 

-

 

#!/usr/bin/perl

 

use strict;

use warnings;

use CGI qw(:standard);

my $query = param(vendor);

my $search_results = http://www.example.com/res_jmt_thx.htm;;

my $no_search_results = http://www.example.com/res_nomsds.htm;;

 

my $zip_file = BigZipFile.zip; 

 

 if ($query eq $zip_file)  {

  print Location: $search_results\n\n;

 };



system /usr/bin/perl /var/www/cgi-bin/jmt_launch3.pl;

 

#print Location: $no_search_results\n\n;

 

--

 

Thanks for any suggestions!

 

Brian 

   

 



Beginner question about XML::Simple

2007-04-04 Thread Gerben Wierda

I've got a XML file that contains the following snippet

TPM:Requires
  TPM:Package name=adobeuro/
  TPM:Package name=avantgar/
  TPM:Package name=bookman/
  TPM:Package name=charter/
  TPM:Package name=cmextra/
  TPM:Package name=courier/
  TPM:Package name=euro/
  TPM:Package name=euro-ce/
  TPM:Package name=eurofont/
  TPM:Package name=eurosans/
  TPM:Package name=eurosym/
  TPM:Package name=fpl/
  TPM:Package name=helvetic/
  TPM:Package name=marvosym/
  TPM:Package name=mathpazo/
  TPM:Package name=ncntrsbk/
  TPM:Package name=palatino/
  TPM:Package name=psnfssx/
  TPM:Package name=pxfonts/
  TPM:Package name=rsfs/
  TPM:Package name=symbol/
  TPM:Package name=tex-gyre/
  TPM:Package name=times/
  TPM:Package name=timesnew/
  TPM:Package name=tipa/
  TPM:Package name=txfonts/
  TPM:Package name=utopia/
  TPM:Package name=wasy/
  TPM:Package name=wasysym/
  TPM:Package name=zapfchan/
  TPM:Package name=zapfding/
  TPM:TLCore name=collection-basic/
/TPM:Requires

Reading this with XML::Simple and Dumping it gives me

 'TPM:Requires' = {
   'TPM:TLCore' = {

'name' = 'collection-basic'

 },
   'TPM:Package' = {
 
'cmextra' = {},
 
'wasysym' = {},
 
'eurosym' = {},


Basically, when there is only one item, (as with TPM:TLCore above) I  
get a hash with one item with key 'name' and value whatever is in  
there, while with multiple entries I get something different, the  
values have become keys for the   hash. Is this not illogical and is  
there a way to get it in a sipler way? I tried ForceArray = 1, but  
that gives me arrays instead of hashes. I'd like to get it purely in  
hashes.


G

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




Merge CSV Data Files - Ideas on how to do this.

2007-04-04 Thread Bill
Hi all.  I have bunch of CSV files that have the same data.  This data is sent 
to clients.  Then the data is returned back with the Active/Remove field 
filled.  This field is only filled by 1 client.  All the files are returned 
back. Once they are returned back I need a script that will go through each of 
the CSV merge the data.  For example, below files are idential accept the 
active/remove field is filled in some files and not in other.  I had done this 
through putting all the files into a hash and looking at that way.  But it 
consumes alot of memory, which limits me with what i can do with a hash.  I 
just wanted to run this by the group and find out a more efficient way to do 
this. The program runs on Win32 system.  

Below are the files


File 1: 
LAST NAME, FIRST NAME, STATUS, ACTIVE/REMOVE
smith, john, 1, active
Robinson, Cindy, 5,,

File 2: 
LAST NAME, FIRST NAME, STATUS, ACTIVE/REMOVE
smith, john, 1,
Robinson, Cindy, 5,remove

File 3: 
LAST NAME, FIRST NAME, STATUS, ACTIVE/REMOVE
smith, john, 1, 
Robinson, Cindy, 5,

File 4: 
LAST NAME, FIRST NAME, STATUS, ACTIVE/REMOVE
smith, john, 1,
Robinson, Cindy, 5


 

Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

Re: Merge CSV Data Files - Ideas on how to do this.

2007-04-04 Thread Chas Owens

On 4/4/07, Bill [EMAIL PROTECTED] wrote:
snip

I just wanted to run this by the group and find out a more efficient way to do
this.

snip

If you are worried about memory try a hash tied to a db file.

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




Re: Merge CSV Data Files - Ideas on how to do this.

2007-04-04 Thread Bill
Chase, 

Thanks for the quick reply.  I am not familiar with how to go about doing this. 
 Do i need a module to do this? could you point me to some documentation or 
something that i can look at? 

Thanks - Bill


- Original Message 
From: Chas Owens [EMAIL PROTECTED]
To: Bill [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Wednesday, April 4, 2007 4:44:07 PM
Subject: Re: Merge CSV Data Files - Ideas on how to do this.


On 4/4/07, Bill [EMAIL PROTECTED] wrote:
snip
 I just wanted to run this by the group and find out a more efficient way to do
 this.
snip

If you are worried about memory try a hash tied to a db file.

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


 

It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

Re: Merge CSV Data Files - Ideas on how to do this.

2007-04-04 Thread Chas Owens

On 4/4/07, Bill [EMAIL PROTECTED] wrote:


Chase,

Thanks for the quick reply.  I am not familiar with how to go about doing
this.  Do i need a module to do this? could you point me to some
documentation or something that i can look at?

Thanks - Bill

snip

Old school functions:
perldoc -f dbmopen
perldoc -f dbmclose

New/Better modules:
http://search.cpan.org/~nwclark/perl-5.8.8/lib/AnyDBM_File.pm
http://search.cpan.org/~pmqs/DB_File-1.815/DB_File.pm

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




Re: Merge CSV Data Files - Ideas on how to do this.

2007-04-04 Thread Mumia W.

On 04/04/2007 02:56 PM, Bill wrote:
Hi all.  I have bunch of CSV files that have the same data.  This data is sent to clients.  Then the data is returned back with the Active/Remove field filled.  This field is only filled by 1 client.  All the files are returned back. Once they are returned back I need a script that will go through each of the CSV merge the data.  For example, below files are idential accept the active/remove field is filled in some files and not in other.  I had done this through putting all the files into a hash and looking at that way.  But it consumes alot of memory, which limits me with what i can do with a hash.  I just wanted to run this by the group and find out a more efficient way to do this. The program runs on Win32 system.  


Below are the files
[...]


Go through the files twice. The first time, only remember which users 
are either active or removed. The second time you go through the files, 
incorporate the information about active and removed users before you 
send the files.


Here is an example that uses your sample data files (not included):

#!/usr/bin/perl
use strict;
use warnings;
use Fcntl;
use DB_File;
use Text::CSV_XS;
use File::Spec::Functions;
use IO::File;
use Data::Dumper;

use constant SCAN = 0;
use constant WRITE = 1;

my $filesdir = 'dfiles';
my @files = glob(catdir($filesdir, '*.txt'));
my %users;
my $csv = Text::CSV_XS-new();

load_file($_, SCAN) for @files;
load_file($_, WRITE) for @files;


undef $csv;
exit;

#

sub load_file {
my ($filename, $mode) = @_;
my $fh = IO::File-new($filename,'r') or die(open failure: $!);
my $header = 0;
local $_;

if ($mode eq SCAN) {
while ($_ = $fh-getline) {
next unless $header++;
next unless $csv-parse($_);
my @fields = $csv-fields;
next unless @fields  2;
my $uname = $fields[0],$fields[1];

$users{$uname} = $fields[3]
if ($fields[3]  !$users{$uname});
}
}

if ($mode eq WRITE) {
print FILENAME: $filename\n;
while ($_ = $fh-getline) {
next unless $csv-parse($_);
my @fields = $csv-fields;
next unless @fields  2;
my $uname = $fields[0],$fields[1];

$fields[3] = $users{$uname} if ($users{$uname});
s/^\s+//, s/\s+$// for @fields;
$csv-print(\*STDOUT, [EMAIL PROTECTED]);
print \n;
}
}

print \n;
$fh-close or die (close failure: $!);
}


__HTH__


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




Re: create gui

2007-04-04 Thread Daniel Kasak

xavier mas wrote:


Hi list,

I want to create an interface with Per,l like a form for a database. Searching 
in cpan.org I found many Qtk and Tk modules, but I really don't know what I 
need in order to create Perl programs that can be handled through an 
interface. 


Can you advise me on that?

Greetings,
  



I've been working on a set of Gtk2-Perl modules for database stuff ( 
think replacing MS Access ) for a couple of years now. Check it out at:

http://entropy.homelinux.org/axis

I'm on the verge of another round of releases, and will next be 
concentrating on wrapping everything together with a nice GUI and XML 
import / export thing.


Some quick points re: the Axis modules:

- open-source
- cross-platform ( in heavy use on Linux and Windows 2000 )
- gtk+ looks really nice compared to Tk
- very low system requirements
- optimised for slow network connections ( eg dial-up )
- report builder exports direct to PDF
- big plans for the next 12 months :)

See the screenshots / examples on my webpage for more details ...

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

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




Re: Can I map this

2007-04-04 Thread Igor Sutton Lopes


On 2007/04/04, at 18:12, Randal L. Schwartz wrote:


Igor == Igor Sutton Lopes [EMAIL PROTECTED] writes:


Igor my $str = join(  , map { s/\B(\w+)/\L\1/; $_ } split( / 
\s+/,  $_ ) );


It's bad style to modify $_ in a map, because that also modifies  
the incoming

data.  The simplest workaround is adding local:

@out = map { local $_ = $_; s/.../.../; $_ } @in


Thanks pointing that.

--
Igor Sutton
[EMAIL PROTECTED]





PGP.sig
Description: This is a digitally signed message part


Re: Can I map this

2007-04-04 Thread Rob Dixon

Beginner wrote:


I have a list of names all in uppercase that I would like to 
capitaIise. I can't help but think that map could make short work of 
this loop but I am not sure how. Is it possible to use map here 
instead of a for loop? I can see there are going to be issues with 
double-barrelled names but I'll cross that bridge later.



Thanx,
Dp,.

while (DATA) {

 my @words = split(/\s+/,$_);
 my $str;
 foreach my $w (@words) {
my $s = lc($w);
$s = ucfirst($s);
$str .= $s.' ';
 }
 print STR=$str\n;
}

__DATA__ 
SOME NAME

SOMEONE WITH FOUR NAMES
ONE WITH THREE
A-HYPENED NAME


Hi Dermot.

I don't like this sort of thing - it's grossly unreadable.
But you asked for it :)

while (DATA) {
 chomp;
 my $str = join '', map ucfirst lc, split /([^a-z]+)/i;
 print STR=$str\n;
}

Rob

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




Re: run system command in the background using CGI

2007-04-04 Thread Jeff Pang

I have web page that downloads and extracts images based on file
selection. The thank you page will not be displayed until the download
is complete... (Understandable).  One of the download files is quite big
and the web server is timing out. I would like to thank you page to be
displayed instantly while the download continues to run in the
background; kind of like the '' does at the end of a bash command. Is
this possible?

Hello,

If I'm you,I'll try both of the two ways.
1) Fork a child process and call exec to execute that system command.Surely 
if you run the system command in parent process,the webpage should get timeout 
(so if you really want to do it in CGI processes,you need to set timeout using 
perl's eval{} and $SIG{ALRM}).
2) CGI doesn't execute that big download,but just set a label in somewhere like 
database.Then another program read that label periodicly (by crontab) and do 
the actual download.

Maybe I'm not correct too,but hope this some helps.:)

--
mailto: [EMAIL PROTECTED]
http://home.arcor.de/jeffpang/

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




Re: Beginner question about XML::Simple

2007-04-04 Thread Rob Dixon

Gerben Wierda wrote:


I've got a XML file that contains the following snippet

TPM:Requires
  TPM:Package name=adobeuro/
  TPM:Package name=avantgar/
  TPM:Package name=bookman/
  TPM:Package name=charter/
  TPM:Package name=cmextra/
  TPM:Package name=courier/
  TPM:Package name=euro/
  TPM:Package name=euro-ce/
  TPM:Package name=eurofont/
  TPM:Package name=eurosans/
  TPM:Package name=eurosym/
  TPM:Package name=fpl/
  TPM:Package name=helvetic/
  TPM:Package name=marvosym/
  TPM:Package name=mathpazo/
  TPM:Package name=ncntrsbk/
  TPM:Package name=palatino/
  TPM:Package name=psnfssx/
  TPM:Package name=pxfonts/
  TPM:Package name=rsfs/
  TPM:Package name=symbol/
  TPM:Package name=tex-gyre/
  TPM:Package name=times/
  TPM:Package name=timesnew/
  TPM:Package name=tipa/
  TPM:Package name=txfonts/
  TPM:Package name=utopia/
  TPM:Package name=wasy/
  TPM:Package name=wasysym/
  TPM:Package name=zapfchan/
  TPM:Package name=zapfding/
  TPM:TLCore name=collection-basic/
/TPM:Requires

Reading this with XML::Simple and Dumping it gives me

  'TPM:Requires' = {
'TPM:TLCore' = {
  'name' = 'collection-basic'
},
'TPM:Package' = {
  'cmextra' = {},
  'wasysym' = {},
  'eurosym' = {},

Basically, when there is only one item, (as with TPM:TLCore above) I get 
a hash with one item with key 'name' and value whatever is in there, 
while with multiple entries I get something different, the values have 
become keys for the   hash. Is this not illogical and is there a way to 
get it in a sipler way? I tried ForceArray = 1, but that gives me 
arrays instead of hashes. I'd like to get it purely in hashes.


I'm afraid I don't like XML::Simple, because the representation it uses is
both awkward and inaccurate. You should take a look at XML::Twig or XML::LibXML
if you're doing much XML work or if you have anything other than trivial data.

Unfortunately you can't do what you want. Because a hash has unique keys, if a
tag or attribute name in the XML is repeated, this must represented by 
XML::Simple
as a single hash entry with an array as it's value. However by default 
XML::Simple
economises on data nesting by using an array only when the name is repeated and
leaving the value as a simple scalar or hash if it is unique.

In addition, it will do what the documentation calls 'array folding' where if a
value is labelled 'name' 'id' or 'key' then the value is used as the hash key
instead. This is what you have here where 'name' has been thrown away and the
hash keys become the XML attribute values.

To get XML::Simple to store things consistently you must always use

 XMLin($xml, ForceArray = 1, KeyAttr = [])

So that every hash value is an array and all element or attribute names are
mentioned even if they happen to be special words. Your data will then
look like:

'TPM:Requires' = [
 {
   'TPM:TLCore' = [
 {
   'name' = 'collection-basic'
 }
   ],
   'TPM:Package' = [
 {
   'name' = 'adobeuro'
 },
 {
   'name' = 'avantgar'
 },
 {
   'name' = 'bookman'
 },
 :
 :

I hope this helps.

Rob



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




Re: removing special characters

2007-04-04 Thread Dave Gray

On 4/4/07, Michael Gargiullo [EMAIL PROTECTED] wrote:

I have a log file I'm parsing that has special characters at the end of each 
row.  In vi it appears to be  ^@  I've already tried chomp and s/\^\@//  
Neither work.   Does any one have any ideas?


You can match what vi(m) displays as '^@' by typing ctrl-v
ctrl-shift-2 in your substitution regex.

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




wait time

2007-04-04 Thread Brandino Andreas
Hi all,

is there any function i can use to add some seconds of delay in my
program??


Thanks



 ---  ---  ---  
Brandino Andreas
[EMAIL PROTECTED]
 ---  ---  ---  


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