How to check the file is modified or not?

2007-10-29 Thread sivasakthi
Hi All,

How to check the file is modified or not? 


Thanks,
Siva



Re: Modifing Text Files

2007-10-29 Thread Chas. Owens
On 10/28/07, Telemachus Odysseos [EMAIL PROTECTED] wrote:
 On 10/25/07, Chas. Owens [EMAIL PROTECTED] wrote:
  From the sound of it what you want is in-place-editing:
 
  #!/usr/bin/perl -i
 
  use strict;
  use warnings;
 
  while () {
   s/this/that/
  }
 
  The code above will read in any number of files modifying this to
  that in each one.

 Doesn't that code empty out a file?  That is, isn't there a key line
 missing:

 #!/usr/bin/perl -i
 use strict;
 use warnings;

 while () {
  s/this/that/;
  print;
 }

 I apologize if print; was so obvious that it didn't even need to be
 mentioned, but to be honest, I tried it without that line and emptied a few
 test files before I got it right.


Doh!, that was supposed to be -pi on the command line version and a
print in the full code.

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




Hash Variables

2007-10-29 Thread Kaushal Shriyan
Hi,

I have a sample code



#!/usr/bin/perl -w

%states = ( California,Sacramento, Wisconsin,Madison, New York,
Albany);

print Capital of California is  . $states{California} . \n\n;



I did not understand the statement $states{California} in the above print
statement of the code

I know the the dot is a concatenation operator and \n is a newline character

Thanks in Advance.

Thanks and Regards

Kaushal


Re: Parsing Bounced Emails

2007-10-29 Thread Nigel Peck

Dr.Ruud wrote:

Consider MailTools: http://search.cpan.org/~markov/MailTools/


Thanks Dr.Rudd, looks useful to me.

Cheers,
Nigel

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




Re: How to check the file is modified or not?

2007-10-29 Thread Yogesh Sawant
On Oct 29, 4:09 pm, [EMAIL PROTECTED] (Sivasakthi) wrote:
 Hi All,

 How to check the file is modified or not?

 Thanks,
 Siva

1. get the file's modify time using stat function
2. then compare that time with whatever time-date you have

lookout stat in `perldoc perlfunc` or here's the link:
http://perldoc.perl.org/functions/stat.html

cheers
yogesh


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




Re: Hash Variables

2007-10-29 Thread sivasakthi
On Mon, 2007-10-29 at 17:06 +0530, Kaushal Shriyan wrote:


 
 
 #!/usr/bin/perl -w
 
 %states = ( California,Sacramento, Wisconsin,Madison, New York,
 Albany);
 
 print Capital of California is  . $states{California} . \n\n;
 
 
 
 I did not understand the statement $states{California} in the above print
 statement of the code
 
 I know the the dot is a concatenation operator and \n is a newline character



Hi  Kaushal,

%states is a hash array
California  is a key value

$states{California}  means the value of hash($states)  key(California)
is Sacramento


More information : # perldoc -q hash



Regs,
Siva











fork

2007-10-29 Thread Ryan Dillinger

Hello,
 I have this script here:
 
#!/usr/bin/perluse warnings;use strict;
 
print PID=$$\n;
my $child = fork();die Can't fork: $! unless defined $child;
if ($child  0) {  # parent process  print Parent process: PID=$$, 
child=$child\n;} else {  # child process  my $ppid = getppid();  print Child 
process: PID=$$, parent=$ppid\n;}
 
after I run it I get:
PID=3472
The getppid function is unimplemented at...
The getppid function is unimplemented at...
Can someone explain what is wrong here?
   Thanks
 
_
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews

Re: fork

2007-10-29 Thread Jeff Pang
On 10/29/07, Ryan Dillinger [EMAIL PROTECTED] wrote:

 #!/usr/bin/perluse warnings;use strict;

 print PID=$$\n;
 my $child = fork();die Can't fork: $! unless defined $child;
 if ($child  0) {  # parent process  print Parent process: PID=$$, 
 child=$child\n;} else {  # child process  my $ppid = getppid();  print 
 Child process: PID=$$, parent=$ppid\n;}


Hi,

I think you want to see the parent id and child id when forking.
The modification version of your code is below,

#!/usr/bin/perl
use warnings;
use strict;

my $pid = $$;
print process id before forking is ,$pid,\n;

#print PID=$$\n; # don use something like this,what is it?

my $child = fork();
die Can't fork: $! unless defined $child;

if ($child  0) {  # parent process
print parent id is ,$$,\n;

}else {  # child process
my $ppid = getppid();
print Child id is $$, parent id is $ppid\n;
}

__END__

HTH.

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




Re: Array Manipulation newbie

2007-10-29 Thread Greg
Thank you, Tom, that is exactly what I was looking for!!
Thanks again!
-Greg



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




array within array

2007-10-29 Thread Mike Tran
Hey all,

 

I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My script
below is incomplete and I'm doing an array within an array which is
incorrect. Please help.  

 

Here's what I want to do; I have to flat files (pipe delimited, export
from a database) that I want to parse through and assign variables for
each column. Basically, I want to parse through exclude_bases.txt and
do: if base_no in exclude_bases.txt equals to base_no in base.txt then
search in the description field of base.txt for the string listed in
the keyword field in exclude_bases.tx and replace with new_keyword
in exclude_bases.txt and write the out put into a new file called
new_bases.txt.

 

Any suggestions on how I could accomplish the above task is greatly
appreciated. Thanks all. 

 

Flat Files:

 

base.txt:

base_no|name|description

1|test|test desc

10001|test2|test desc 2

10002|test3|test desc 3

 

exclude_bases.txt:

base_no|keyword|new_keyword|

1|test desc|testdesc|0

10001|test desc 2|testdesc2|0

10002|test desc 3|testdesc3|1

 

 

 

#!/usr/bin/perl

 

use strict;

use warnings;

 

my $exclude_bases = exclude_bases.txt;

my $current_base = base.txt;

my $output = new_bases.txt;

 

my %exclude_bases;

my $exclude_text;

my $exbase_no;

my $keyword;

my $new_keyword;

 

open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);

%exclude_bases=EXCLUDE;

close(EXCLUDE);

 

my $base_no =;

my $name=;

my $description=;

my $current_base=;

my $base_text=;

my %bases;

 

open(BASE,base.txt)|| die(Could not open file!);

%bases=BASE;

close(BASE);

 

#choping lines and assign variables to base.txt

foreach $base_text (%bases)

{

  chop($base_text);

  ($base_no,$name,$description)=split(/\|/,$base_text);

 

#choping lines and assign variables to exclude_bases.txt

foreach $exclude_text (%exclude_bases)

{

  chop($exclude_text);

  ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);

  

  if ($exbase_no=$base_no) {

  $keyword =~ s/$keyword/$new_keyword/g;}

}

}

~

 

 

 

 

 



Quotes and apostrophes assistance

2007-10-29 Thread Beginner
Hi,

I am trying to insert a lots file paths into an SQLite table and am 
having trouble with filenames with apostrophes in.

Below is the snippet I have been using. I have experimented with 
sprintf,  qq and a combination of both but can't get a quoting system 
that will get DBI to accept paths like q(/path/to/Camellia japonica 
'Mercury'2.tif).

I don't want to transform the path. I want to maintain the true path 
without having to do substitiutions everytime the data gets read from 
or inserted into the table. It would be a maintenance headache 
otherwise.

Is there a technique for this anyone or any advice anyone can offer 
(apart from shooting the users how uploaded the files in the first 
place).

TIA,
Dp.

sub Check_if_exists {
 my $name = shift;
 my $str = qq($name);
 my $statement = sprintf(SELECT id FROM files where 
path='%s',$str);
# my $statement = qq(SELECT id FROM files where path=$str);
 my $rows = $dbh-selectrow_array($statement) or die Can't 
selectrow_array statement=$statement: ,$DBI::errstr,\n;
 return $rows;
}


DBD::SQLite::db selectrow_array failed: near Mercury: syntax 
error(1) at dbdimp.c line 271 at myfile.pm line 158.
Can't selectrow_array statement=SELECT id FROM images where 
tiffpath='/data/finished/GB 10484/Camellia japonica 
'Mercury'2.NEF.tif': near Mercury: syntax error(1) at dbdimp.c line 
271


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




Re: array within array

2007-10-29 Thread Beginner
On 29 Oct 2007 at 8:42, Mike Tran wrote:

 Hey all,
 
  
 
 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My script
 below is incomplete and I'm doing an array within an array which is
 incorrect. Please help.  
 
  
 
 Here's what I want to do; I have to flat files (pipe delimited, export
 from a database) that I want to parse through and assign variables for
 each column. Basically, I want to parse through exclude_bases.txt and
 do: if base_no in exclude_bases.txt equals to base_no in base.txt then
 search in the description field of base.txt for the string listed in
 the keyword field in exclude_bases.tx and replace with new_keyword
 in exclude_bases.txt and write the out put into a new file called
 new_bases.txt.
 
  
 
 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all. 
 
  
 
 Flat Files:
 
  
 
 base.txt:
 
 base_no|name|description
 
 1|test|test desc
 
 10001|test2|test desc 2
 
 10002|test3|test desc 3
 
  
 
 exclude_bases.txt:
 
 base_no|keyword|new_keyword|
 
 1|test desc|testdesc|0
 
 10001|test desc 2|testdesc2|0
 
 10002|test desc 3|testdesc3|1
 
  
 
  
 
  
 
 #!/usr/bin/perl
 
  
 
 use strict;
 
 use warnings;
 
  
 
 my $exclude_bases = exclude_bases.txt;
 
 my $current_base = base.txt;
 
 my $output = new_bases.txt;
 
  
 
 my %exclude_bases;
 
 my $exclude_text;
 
 my $exbase_no;
 
 my $keyword;
 
 my $new_keyword;
 
  
 
 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);
 
 %exclude_bases=EXCLUDE;
 
 close(EXCLUDE);
 
  
 
 my $base_no =;
 
 my $name=;
 
 my $description=;
 
 my $current_base=;
 
 my $base_text=;
 
 my %bases;
 
  
 
 open(BASE,base.txt)|| die(Could not open file!);
 
 %bases=BASE;
 
 close(BASE);
 
  
 
 #choping lines and assign variables to base.txt
 
 foreach $base_text (%bases)
 
 {
 
   chop($base_text);
 
   ($base_no,$name,$description)=split(/\|/,$base_text);
 
  
 
 #choping lines and assign variables to exclude_bases.txt
 
 foreach $exclude_text (%exclude_bases)
 
 {
 
   chop($exclude_text);
 
   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);
 
   
 
   if ($exbase_no=$base_no) {
 
   $keyword =~ s/$keyword/$new_keyword/g;}
 

Well here my effort. It should help you get closer to what your after 
but it's not complete. I would use hashes not arrays, you'll find 
them extremely useful for de-duping data 

I haven't run the script below, please do a perl -c first. 

Check out exists

perldoc -f exists



#!/usr/bin/perl

use strict; # Well done
use warnings; # ditto.

my $exclude_bases = exclude_bases.txt;
 
open(EXCLUDE,excludes.txt )|| die(Could not open file!);
while (EXCLUDE) {
chomp;
my @fields = split(/|/,$_);
$exclude_bases{$F[0]} = 0; # $f[0] contains base_no
}
close(EXCLUDE);

open(BASE,base.txt)|| die(Could not open file!);
while (BASE) {
chomp;
my @fields = split(/|/,$_);
if (! exists($exlude_bases{$_}) ) {
print $f[2]\n;
}
}
close(BASE);


HTH,
Dp.



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




RE: array within array

2007-10-29 Thread Andrew Curry
be very careful with exists, it auto creates the structure 

i.e.
use Data::Dumper;
my %hash;

if (exists $hash{a}{b}) {

}

print Dumper(\%hash)

then the next time you use exists it is there.

defined is much safer as it doesnt do this.

-Original Message-
From: Beginner [mailto:[EMAIL PROTECTED]
Sent: 29 October 2007 15:30
To: beginners @ perl. org
Subject: Re: array within array


On 29 Oct 2007 at 8:42, Mike Tran wrote:

 Hey all,
 
  
 
 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My script
 below is incomplete and I'm doing an array within an array which is
 incorrect. Please help.  
 
  
 
 Here's what I want to do; I have to flat files (pipe delimited, export
 from a database) that I want to parse through and assign variables for
 each column. Basically, I want to parse through exclude_bases.txt and
 do: if base_no in exclude_bases.txt equals to base_no in base.txt then
 search in the description field of base.txt for the string listed in
 the keyword field in exclude_bases.tx and replace with new_keyword
 in exclude_bases.txt and write the out put into a new file called
 new_bases.txt.
 
  
 
 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all. 
 
  
 
 Flat Files:
 
  
 
 base.txt:
 
 base_no|name|description
 
 1|test|test desc
 
 10001|test2|test desc 2
 
 10002|test3|test desc 3
 
  
 
 exclude_bases.txt:
 
 base_no|keyword|new_keyword|
 
 1|test desc|testdesc|0
 
 10001|test desc 2|testdesc2|0
 
 10002|test desc 3|testdesc3|1
 
  
 
  
 
  
 
 #!/usr/bin/perl
 
  
 
 use strict;
 
 use warnings;
 
  
 
 my $exclude_bases = exclude_bases.txt;
 
 my $current_base = base.txt;
 
 my $output = new_bases.txt;
 
  
 
 my %exclude_bases;
 
 my $exclude_text;
 
 my $exbase_no;
 
 my $keyword;
 
 my $new_keyword;
 
  
 
 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);
 
 %exclude_bases=EXCLUDE;
 
 close(EXCLUDE);
 
  
 
 my $base_no =;
 
 my $name=;
 
 my $description=;
 
 my $current_base=;
 
 my $base_text=;
 
 my %bases;
 
  
 
 open(BASE,base.txt)|| die(Could not open file!);
 
 %bases=BASE;
 
 close(BASE);
 
  
 
 #choping lines and assign variables to base.txt
 
 foreach $base_text (%bases)
 
 {
 
   chop($base_text);
 
   ($base_no,$name,$description)=split(/\|/,$base_text);
 
  
 
 #choping lines and assign variables to exclude_bases.txt
 
 foreach $exclude_text (%exclude_bases)
 
 {
 
   chop($exclude_text);
 
   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);
 
   
 
   if ($exbase_no=$base_no) {
 
   $keyword =~ s/$keyword/$new_keyword/g;}
 

Well here my effort. It should help you get closer to what your after 
but it's not complete. I would use hashes not arrays, you'll find 
them extremely useful for de-duping data 

I haven't run the script below, please do a perl -c first. 

Check out exists

perldoc -f exists



#!/usr/bin/perl

use strict; # Well done
use warnings; # ditto.

my $exclude_bases = exclude_bases.txt;
 
open(EXCLUDE,excludes.txt )|| die(Could not open file!);
while (EXCLUDE) {
chomp;
my @fields = split(/|/,$_);
$exclude_bases{$F[0]} = 0; # $f[0] contains base_no
}
close(EXCLUDE);

open(BASE,base.txt)|| die(Could not open file!);
while (BASE) {
chomp;
my @fields = split(/|/,$_);
if (! exists($exlude_bases{$_}) ) {
print $f[2]\n;
}
}
close(BASE);


HTH,
Dp.



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



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

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

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





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




Re: Quotes and apostrophes assistance

2007-10-29 Thread anders
On 29 Okt, 16:14, [EMAIL PROTECTED] (Beginner) wrote:
 Hi,

 I am trying to insert a lots file paths into an SQLite table and am
 having trouble with filenames with apostrophes in.

 Below is the snippet I have been using. I have experimented with
 sprintf,  qq and a combination of both but can't get a quoting system
 that will get DBI to accept paths like q(/path/to/Camellia japonica
 'Mercury'2.tif).

 I don't want to transform the path. I want to maintain the true path
 without having to do substitiutions everytime the data gets read from
 or inserted into the table. It would be a maintenance headache
 otherwise.

 Is there a technique for this anyone or any advice anyone can offer
 (apart from shooting the users how uploaded the files in the first
 place).

 TIA,
 Dp.

 sub Check_if_exists {
  my $name = shift;
  my $str = qq($name);
  my $statement = sprintf(SELECT id FROM files where
 path='%s',$str);
 # my $statement = qq(SELECT id FROM files where path=$str);
  my $rows = $dbh-selectrow_array($statement) or die Can't
 selectrow_array statement=$statement: ,$DBI::errstr,\n;
  return $rows;

 }

 DBD::SQLite::db selectrow_array failed: near Mercury: syntax
 error(1) at dbdimp.c line 271 at myfile.pm line 158.
 Can't selectrow_array statement=SELECT id FROM images where
 tiffpath='/data/finished/GB 10484/Camellia japonica
 'Mercury'2.NEF.tif': near Mercury: syntax error(1) at dbdimp.c line
 271

I have the same problem but with C and SQLITE it is becurse the
database don't like single '
(and some other characters) you have to transform them,  to dubble
example
' transforms to '' ( ' x 2 not the char )
I don't have tro transform back just for saving..

// Anders


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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Rob Coops
Since I never worked with an SQLite DB I am not sure how well this will work
but you might want to have a look at the following command in the DBI:
$dbh-quote($value);

This should make the whole thing SQL approved with escaped special
characters and everything... Now as I said I have no idea how this will work
on SQLite but it is worth a try.

See: http://search.cpan.org/~timb/DBI-1.601/DBI.pm#quote for more
information

Regards,

Rob



On 10/29/07, Beginner [EMAIL PROTECTED] wrote:

 Hi,

 I am trying to insert a lots file paths into an SQLite table and am
 having trouble with filenames with apostrophes in.

 Below is the snippet I have been using. I have experimented with
 sprintf,  qq and a combination of both but can't get a quoting system
 that will get DBI to accept paths like q(/path/to/Camellia japonica
 'Mercury'2.tif).

 I don't want to transform the path. I want to maintain the true path
 without having to do substitiutions everytime the data gets read from
 or inserted into the table. It would be a maintenance headache
 otherwise.

 Is there a technique for this anyone or any advice anyone can offer
 (apart from shooting the users how uploaded the files in the first
 place).

 TIA,
 Dp.

 sub Check_if_exists {
 my $name = shift;
 my $str = qq($name);
 my $statement = sprintf(SELECT id FROM files where
 path='%s',$str);
 # my $statement = qq(SELECT id FROM files where path=$str);
 my $rows = $dbh-selectrow_array($statement) or die Can't
 selectrow_array statement=$statement: ,$DBI::errstr,\n;
 return $rows;
 }


 DBD::SQLite::db selectrow_array failed: near Mercury: syntax
 error(1) at dbdimp.c line 271 at myfile.pm line 158.
 Can't selectrow_array statement=SELECT id FROM images where
 tiffpath='/data/finished/GB 10484/Camellia japonica
 'Mercury'2.NEF.tif': near Mercury: syntax error(1) at dbdimp.c line
 271


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





Re: array within array

2007-10-29 Thread John W . Krahn
On Monday 29 October 2007 07:29, Beginner wrote:

 while (EXCLUDE) {
   chomp;
   my @fields = split(/|/,$_);
   ^^^


   $exclude_bases{$F[0]} = 0; # $f[0] contains base_no
 }
 close(EXCLUDE);

 open(BASE,base.txt)|| die(Could not open file!);
 while (BASE) {
   chomp;
   my @fields = split(/|/,$_);
   ^^^

The '|' character has a special meaning in a regular expression so you 
have to escape it if you want to match a literal '|' character.



John
-- 
use Perl;
program
fulfillment


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




Re: array within array

2007-10-29 Thread Dr.Ruud
Andrew Curry schreef:

 be very careful with exists, it auto creates the structure
 use Data::Dumper;
 my %hash;
 if (exists $hash{a}{b}) {}
 print Dumper(\%hash)
 then the next time you use exists it is there.
 defined is much safer as it doesnt do this.

No, the difference here is not between exists() and defined().

To be able to check the definedness (or the existence) of $h{foo}{bar},
$h{foo} is created first (auto-vivification).

Neither exists() nor defined() short-cuts hash-levels.


perl -MData::Dumper -wle'
my %hash;
if ( defined $hash{foo}{bar} ) {};
print Dumper \%hash;
'
$VAR1 = {
  'foo' = {}
};

(same with exists())


Solution: test $h{foo} first:

if ( exists( $hash{foo}  ) and
 exists( $hash{foo}{bar} ) )
{ ... }

-- 
Affijn, Ruud

Gewoon is een tijger.


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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Dr.Ruud
Beginner schreef:

 I am trying to insert a lots file paths into an SQLite table and am
 having trouble with filenames with apostrophes in.

Use placeholders, so prepare/execute. 

-- 
Affijn, Ruud

Gewoon is een tijger.

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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Dr.Ruud
Rob Coops schreef:

 See: http://search.cpan.org/~timb/DBI-1.601/DBI.pm#quote for more
 information

Read
http://search.cpan.org/~timb/DBI-1.601/DBI.pm#Placeholders_and_Bind_Values
first.

-- 
Affijn, Ruud

Gewoon is een tijger.


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




Re: How to check the file is modified or not?

2007-10-29 Thread Tom Phoenix
On 10/29/07, sivasakthi [EMAIL PROTECTED] wrote:

 How to check the file is modified or not?

If the file exists at all, it's been modified at least once. But you
seem to want to know something more.

If you want to know whether the file has been modified since a certain
time, you probably want some form of the mtime, the timestamp that you
see when you use the 'ls -l' command, or your system's equivalent. You
can use Perl's stat() function to get the mtime, or you can use the -M
operator to measure the file's modification age in days. Both -M and
stat are documented in the perlfunc manpage.

If you want to know whether the file has the same contents as it once
had, but you don't want to save a copy of the contents for comparison,
you probably want to calculate a digest of the contents, and save
that. (A digest is a short string produced by a cryptographic hash
algorithm.) There are modules on CPAN that can help you to make a
digest for your file; when the digest doesn't match, you know that the
file has been modified.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: fork

2007-10-29 Thread Tom Phoenix
On 10/29/07, Ryan Dillinger [EMAIL PROTECTED] wrote:

 #!/usr/bin/perluse warnings;use strict;

 print PID=$$\n;
 my $child = fork();die Can't fork: $! unless defined $child;
 if ($child  0) {  # parent process  print Parent process: PID=$$, 
 child=$child\n;} else {  # child process  my $ppid = getppid();  print 
 Child process: PID=$$, parent=$ppid\n;}

Yoicks! I don't know what happened to your program's formatting, so I
tried to untangle it:

#!/usr/bin/perl

use warnings;
use strict;

print PID=$$\n;
my $child = fork();
die Can't fork: $! unless defined $child;

if ($child  0) {  # parent process
print Parent process: PID=$$, child=$child\n;
} else {  # child process
my $ppid = getppid();
print Child process: PID=$$, parent=$ppid\n;
}

 after I run it I get:
 PID=3472
 The getppid function is unimplemented at...
 The getppid function is unimplemented at...
 Can someone explain what is wrong here?

It looks as if your perl executable doesn't understand getppid, which
surprises me because I had thought that getppid was implemented
everywhere that fork is. Seeing the message twice, but no error
message about the fork, implies that the fork succeeded, but both
processes (?!) got a return value of zero. (Or a negative number. Hm.
Does anybody's fork return negative PIDs? Why have you changed part of
the error message to ...? Why aren't you showing us your program's
real output? Were there other error messages in the output? Is this
perhaps the output from a different version of your program?)

If your system does implement getppid (check your docs), that means
that your perl binary should be recompiled to use it. If your system
doesn't support getppid, which OS is it? Maybe people who use that OS
have a workaround.

In this case, because you're using fork, there is a simple workaround:
Save the PID before forking. But that doesn't obviate the need for
getppid in general.

For what it's worth, your code (after reformatting) works as expected
for me, on Mac OS X (Darwin) perl 5.8.6:

PID=1715
Child process: PID=1716, parent=1715
Parent process: PID=1715, child=1716

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Beginner
On 29 Oct 2007 at 10:55, Paul Lalli wrote:

 On Oct 29, 12:31 pm, [EMAIL PROTECTED] (Dr.Ruud) wrote:
  Beginner schreef:
 
   I am trying to insert a lots file paths into an SQLite table and am
   having trouble with filenames with apostrophes in.
 
  Use placeholders,
 
 Good advice.
 
  so prepare/execute.
 
 irrelevant advice, nothing to do with the problem at hand.  There is
 no reason to alter the OP's method of using selectrow_array.
 
 my ($val) = $dbh-selectrow_array(SELECT foo FROM bar WHERE id = ?,
 undef, q{stuff'with'quotes'});
 
 http://search.cpan.org/~timb/DBI-1.601/DBI.pm#selectrow_array
 
Being new to DBI (and not much of expert in perl anyway) so I can't 
add much to the debate. 

What I can say is that this always dies

my $statement = sprintf(SELECT foo FROM bar where path=%s,$dbh-
quote($name));
my $rows = $dbh-selectrow_array($statement) or 
die Can't selectrow_array statement=$statement: ,$DBI::errstr, 
NO:,$DBI::err,$DBI::state\n;


or this:

my ($rows) = $dbh-selectrow_array(SELECT foo FROM bar where 
path=?,undef,q($name)) or die snip


whereas if I am do 

my $statement = sprintf(SELECT foo FROM bar where path=%s,
$dbh-quote($name));
my $sth = $dbh-prepare($statement) or 
die PREPARE:statement=$statement: ,$DBI::errstr,\n;
 $sth-execute or die EXECUTE: statement=$statement: 
,$DBI::errstr, NO:,$DBI::err,\n;
 my @rows;
 while (defined(my $i = $sth-fetchrow_array)) {
push(@rows,$i);
 }


It will process. What I want is to check if a fully qualified file 
path exists before attempting to insert a new record so I opted for 
the shorthand notation.

I didn't understand the 2 argument list in Paul's selectrow_array 
either.

I am currently fighting with 
$dbh-last_insert_id(undef,undef,undef,undef)

which constantly returns 0 so I can't get any further with my 
original query except to say the first one always returns a code to 
indicate a problem whereas the more verbose latter method will work.

BTW: SQLite 3.5.1 
DBI: 1.6.1.

Any further advice appreciated.
Dp.


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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Paul Lalli
On Oct 29, 12:31 pm, [EMAIL PROTECTED] (Dr.Ruud) wrote:
 Beginner schreef:

  I am trying to insert a lots file paths into an SQLite table and am
  having trouble with filenames with apostrophes in.

 Use placeholders,

Good advice.

 so prepare/execute.

irrelevant advice, nothing to do with the problem at hand.  There is
no reason to alter the OP's method of using selectrow_array.

my ($val) = $dbh-selectrow_array(SELECT foo FROM bar WHERE id = ?,
undef, q{stuff'with'quotes'});

http://search.cpan.org/~timb/DBI-1.601/DBI.pm#selectrow_array

Paul Lalli


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




Re: array within array

2007-10-29 Thread John W . Krahn
On Monday 29 October 2007 06:42, Mike Tran wrote:
 Hey all,

Hello,

 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My
 script below is incomplete and I'm doing an array within an array
 which is incorrect. Please help.

You are not using arrays you are using hashes.

 Here's what I want to do; I have to flat files (pipe delimited,
 export from a database) that I want to parse through and assign
 variables for each column. Basically, I want to parse through
 exclude_bases.txt and do: if base_no in exclude_bases.txt equals to
 base_no in base.txt then search in the description field of
 base.txt for the string listed in the keyword field in
 exclude_bases.tx and replace with new_keyword in exclude_bases.txt
 and write the out put into a new file called new_bases.txt.

 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all.

 Flat Files:

 base.txt:
 base_no|name|description
 1|test|test desc
 10001|test2|test desc 2
 10002|test3|test desc 3

 exclude_bases.txt:
 base_no|keyword|new_keyword|
 1|test desc|testdesc|0
 10001|test desc 2|testdesc2|0
 10002|test desc 3|testdesc3|1


 #!/usr/bin/perl
 use strict;
 use warnings;

 my $exclude_bases = exclude_bases.txt;
 my $current_base = base.txt;
 my $output = new_bases.txt;

 my %exclude_bases;
 my $exclude_text;
 my $exbase_no;
 my $keyword;
 my $new_keyword;

You should define variables in the smallest possible scope.


 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);

You have stored the file name in the $exclude_bases variable above so 
why do you not use the variable instead?  You should include the $! 
variable in the error message so you know *why* it failed.


 %exclude_bases=EXCLUDE;

You are assigning the list from the file to a hash.  The list elements 
are defined by the value of the $/ variable so here each element of the 
list is a line from the file.  Because you are assigning to a hash the 
first element is a key and the second element is the value for that 
key.  if any of the keys (odd elements) are the same as a previous key 
then the old value will be overwritten by the new value and you will 
lose lines from the file.


 close(EXCLUDE);

 my $base_no =;
 my $name=;
 my $description=;
 my $current_base=;
 my $base_text=;
 my %bases;

 open(BASE,base.txt)|| die(Could not open file!);

Same as above.

 %bases=BASE;

Same as above.

 close(BASE);

 #choping lines and assign variables to base.txt
 foreach $base_text (%bases)
 {
   chop($base_text);

You should use chomp() instead of chop().


   ($base_no,$name,$description)=split(/\|/,$base_text);

 #choping lines and assign variables to exclude_bases.txt
 foreach $exclude_text (%exclude_bases)
 {
   chop($exclude_text);

Same as above.


   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);

   if ($exbase_no=$base_no) {

You are assigning the value of $base_no to the variable $exbase_no.  If 
the value of $base_no is true then the expression is true.  You 
want to use a comparison operator like '==' or 'eq'.


   $keyword =~ s/$keyword/$new_keyword/g;}

Your description said that you wanted to modify 'the description 
field of base.txt' so that sould be:

   $description =~ s/$keyword/$new_keyword/g;}


 }
 }


It looks like you may want something like this:

#!/usr/bin/perl
use strict;
use warnings;

my $exclude_bases = 'exclude_bases.txt';
my $current_base  = 'base.txt';
my $output= 'new_bases.txt';

open EXCLUDE, '', $exclude_bases or die Could not open 
'$exclude_bases' $!;

my %exclude_bases;
while ( EXCLUDE ) {
next if $. == 1;  # exclude header
chomp;
my ( $exbase_no, $keyword, $new_keyword ) = split /\|/;
$exclude_bases{ $exbase_no } = { from = qr/\Q$keyword/, to = 
$new_keyword };
}

close EXCLUDE;


open BASE, '', $current_base  or die Could not open '$current_base' 
$!;
open OUT,  '', $outputor die Could not open '$output' $!;

while ( BASE ) {
my ( $base_no, $name, $description ) = split /\|/;
if ( exists $exclude_bases{ $base_no } ) {
$description =~ 
s/$exclude_bases{$base_no}{from}/$exclude_bases{$base_no}{to}/g;
$_ = join '|', $base_no, $name, $description;
}
print OUT;
}

__END__



John
-- 
use Perl;
program
fulfillment

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




Re: Hash of array

2007-10-29 Thread Rob Dixon

Kevin Viel wrote:

I have a dataset of values for variables for subjects.  Some subject have
multiple records, requiring an average:

ID  Var1 Var2
1   1.0  2.0
1   2.0  1.5

-
1   1.5  1.75

If I collect the variables into an array, I can average the contents after I
have processed the entire file.  It would seem that I want something like:

my %subjects ;

$subjects{ $ID }{ $var }[ 0 ] = $var1 ;
$subjects{ $ID }{ $var }[ 0 ] = $var2 ;

It does not seem like I could PUSH values onto the array:

push $subject{ $ID }{ $var } , $var1 ;

My first inclination is to use EXISTS and a create a variable intended to
INDEX the array:

my $index ;
if ( ~ exists $subjects{ $ID }{ $var } ) {
  $index = 0 ;
} else { $index = $subjects{ $ID }{ $var } ) 


  $subjects{ $ID }{ $var }[ $index ] = $var1 ;


I would appreciate any comments or suggestions concerning this approach.


Hi Kevin

You can indeed push onto your array, and what is more Perl will
automatically create an empty array if it doesn't already exist:

 push @{$subject{$ID}{$var}}, $var1;

You may also want to look at the built-in module List::Util to save
you writing code to calculate the total of the array's values.

HTH,

Rob

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




Hash of array

2007-10-29 Thread Kevin Viel
I have a dataset of values for variables for subjects.  Some subject have
multiple records, requiring an average:

ID  Var1 Var2
1   1.0  2.0
1   2.0  1.5

-
1   1.5  1.75

If I collect the variables into an array, I can average the contents after I
have processed the entire file.  It would seem that I want something like:

my %subjects ;

$subjects{ $ID }{ $var }[ 0 ] = $var1 ;
$subjects{ $ID }{ $var }[ 0 ] = $var2 ;

It does not seem like I could PUSH values onto the array:

push $subject{ $ID }{ $var } , $var1 ;

My first inclination is to use EXISTS and a create a variable intended to
INDEX the array:

my $index ;
if ( ~ exists $subjects{ $ID }{ $var } ) {
  $index = 0 ;
} else { $index = $subjects{ $ID }{ $var } ) 

  $subjects{ $ID }{ $var }[ $index ] = $var1 ;


I would appreciate any comments or suggestions concerning this approach.

Thank you,

Kevin


Kevin Viel, PhD
Post-doctoral fellow
Department of Genetics
Southwest Foundation for Biomedical Research
San Antonio, TX 78227  


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




Re: Quotes and apostrophes assistance

2007-10-29 Thread Dr.Ruud
Beginner schreef:

 my ($rows) = $dbh-selectrow_array(SELECT foo FROM bar where
 path=?,undef,q($name)) or die snip

Your q($name) creates the literal string $name.

  my ($rows) =
  $dbh-selectrow_array(
  SELECT foo FROM bar where path=?,
  undef,
  $name,
  );

No need for die() if you set up the $dbh with 'RaiseError' on, 
see perldoc DBI. Also look for 'trace'. 

-- 
Affijn, Ruud

Gewoon is een tijger.

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




Re: array within array

2007-10-29 Thread Ron Bergin
On Oct 29, 6:42 am, [EMAIL PROTECTED] (Mike Tran) wrote:
 Hey all,

 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My script
 below is incomplete and I'm doing an array within an array which is
 incorrect. Please help.

 Here's what I want to do; I have to flat files (pipe delimited, export
 from a database) that I want to parse through and assign variables for
 each column. Basically, I want to parse through exclude_bases.txt and
 do: if base_no in exclude_bases.txt equals to base_no in base.txt then
 search in the description field of base.txt for the string listed in
 the keyword field in exclude_bases.tx and replace with new_keyword
 in exclude_bases.txt and write the out put into a new file called
 new_bases.txt.

 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all.
This sounds like a homework assignment, so I won't provide a complete
solution, but I will give a few pointers and maybe a little code.

 Flat Files:

 base.txt:

 base_no|name|description

 1|test|test desc

 10001|test2|test desc 2

 10002|test3|test desc 3

 exclude_bases.txt:

 base_no|keyword|new_keyword|

 1|test desc|testdesc|0

 10001|test desc 2|testdesc2|0

 10002|test desc 3|testdesc3|1
Your description of your required output doesn't say what you want to
do with the 4th field in the exclude_bases.txt.

 #!/usr/bin/perl

 use strict;

 use warnings;

 my $exclude_bases = exclude_bases.txt;

 my $current_base = base.txt;

 my $output = new_bases.txt;

 my %exclude_bases;

 my $exclude_text;

 my $exbase_no;

 my $keyword;

 my $new_keyword;
You don't really need most of those and the following global vars.
You should define the vars in the smallest scope that they require.

 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);
Why didn't you use the $exclude_bases var that you previously defined?
You should use the 3 arg form of open and include $! in the die
statement which will tell you why it failed.

 %exclude_bases=EXCLUDE;
Why are you slurping the data into a hash?  If you use the
Data::Dumper module to output that hash, I think you'll find that it's
not in the format that you wanted.

 close(EXCLUDE);

 my $base_no =;

 my $name=;

 my $description=;

 my $current_base=;

 my $base_text=;

 my %bases;

 open(BASE,base.txt)|| die(Could not open file!);

 %bases=BASE;

 close(BASE);
See my previous comments.

 #choping lines and assign variables to base.txt

 foreach $base_text (%bases)

 {

   chop($base_text);
use chomp instead of chop

   ($base_no,$name,$description)=split(/\|/,$base_text);

 #choping lines and assign variables to exclude_bases.txt

 foreach $exclude_text (%exclude_bases)

 {

   chop($exclude_text);

   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);

   if ($exbase_no=$base_no) {

   $keyword =~ s/$keyword/$new_keyword/g;}

 }
 }

 ~

Here's how I'd load the hash.

my %base;

open (my $base, '', 'base.txt') || die base.txt $!;
while ($base) {
  next if /^\s*$/;
  chomp;
  my @fields = split /\|/;
  $base{$fields[0]} = [EMAIL PROTECTED];
}
close $base;


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




SoapLite Error

2007-10-29 Thread Mike Blezien

Hello,

we're trying to put together a SOAP::Lite application but keep getting this
error message:
===
soaptest.cgi: Element 'XMLRequest' can't be allowed in valid XML message. Died.
at /usr/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm
===

this is a snip of code being used, the line
 SOAP::Data-name(XMLRequest=$xmllines), 

seems to be causing the error.
===
my $soap = SOAP::Lite
   - uri('https://www.edentifyservices.com/')
   - proxy('https://www.edentifyservices.com/XMLGateway/Request.asmx')
   - on_action( sub { return 'http://tempuri.org/ProcessRequest' });

# Format the SOAP envelope
my $method = SOAP::Data-name('ProcessRequest')-attr({xmlns
='http://tempuri.org/'});

# Format the SOAP body
my $query = SOAP::Data-name(ProcessRequest = SOAP::Data-value(
SOAP::Data-name(ServiceName='idalert'),
SOAP::Data-name(XMLRequest=$xmllines),
SOAP::Data-name(Userid=$conf{edentify}-{Userid}),
SOAP::Data-name(password=$conf{edentify}-{Password}),
SOAP::Data-name(Options=''))
);

# Query the web service
my $result = $soap-call($method = $query);
=

This is the way it suppose to be setup according to documentation provided by
the service provider, Edentify. The $xmllines is a XML request formatted file
sent in the request. The $xmllines looks like this and passed to the 
'XMLRequest= :

=

idalertusernameTotalPayroll/usernamecandidatescandidate
firstnameKaren/firstnamemiR/milastnameJones/lastname
suffix/suffixssn339448854/ssndob6/25/1965/doblocatorDD-987654321/locator
addressaddress18585 N. Center Ave./address1address2/address2
cityJonestown/citystateNE/statezip66654/zip/address
/candidate/candidates/idalert

=

Any help would be much appreciated. This is my first crack using SoapLite :)

Thx's
Mike(mickalo)Blezien
===
Thunder Rain Internet Publishing
Providing Internet Solution that Work
===


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




RE: array within array

2007-10-29 Thread Mike Tran
John, 

That is exactly what I wanted. Thanks for pointing out all those errors
for me and your help with the script. Appreciate the prompt respond.  


Cheers,
 
Mike  

-Original Message-
From: John W.Krahn [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 29, 2007 1:10 PM
To: Perl beginners
Subject: Re: array within array

On Monday 29 October 2007 06:42, Mike Tran wrote:
 Hey all,

Hello,

 I'm new with Perl and need help with this simple script. I'm still
 playing around with the script below to get a feel for Perl. My
 script below is incomplete and I'm doing an array within an array
 which is incorrect. Please help.

You are not using arrays you are using hashes.

 Here's what I want to do; I have to flat files (pipe delimited,
 export from a database) that I want to parse through and assign
 variables for each column. Basically, I want to parse through
 exclude_bases.txt and do: if base_no in exclude_bases.txt equals to
 base_no in base.txt then search in the description field of
 base.txt for the string listed in the keyword field in
 exclude_bases.tx and replace with new_keyword in exclude_bases.txt
 and write the out put into a new file called new_bases.txt.

 Any suggestions on how I could accomplish the above task is greatly
 appreciated. Thanks all.

 Flat Files:

 base.txt:
 base_no|name|description
 1|test|test desc
 10001|test2|test desc 2
 10002|test3|test desc 3

 exclude_bases.txt:
 base_no|keyword|new_keyword|
 1|test desc|testdesc|0
 10001|test desc 2|testdesc2|0
 10002|test desc 3|testdesc3|1


 #!/usr/bin/perl
 use strict;
 use warnings;

 my $exclude_bases = exclude_bases.txt;
 my $current_base = base.txt;
 my $output = new_bases.txt;

 my %exclude_bases;
 my $exclude_text;
 my $exbase_no;
 my $keyword;
 my $new_keyword;

You should define variables in the smallest possible scope.


 open(EXCLUDE,exclude_bases.txt )|| die(Could not open file!);

You have stored the file name in the $exclude_bases variable above so 
why do you not use the variable instead?  You should include the $! 
variable in the error message so you know *why* it failed.


 %exclude_bases=EXCLUDE;

You are assigning the list from the file to a hash.  The list elements 
are defined by the value of the $/ variable so here each element of the 
list is a line from the file.  Because you are assigning to a hash the 
first element is a key and the second element is the value for that 
key.  if any of the keys (odd elements) are the same as a previous key 
then the old value will be overwritten by the new value and you will 
lose lines from the file.


 close(EXCLUDE);

 my $base_no =;
 my $name=;
 my $description=;
 my $current_base=;
 my $base_text=;
 my %bases;

 open(BASE,base.txt)|| die(Could not open file!);

Same as above.

 %bases=BASE;

Same as above.

 close(BASE);

 #choping lines and assign variables to base.txt
 foreach $base_text (%bases)
 {
   chop($base_text);

You should use chomp() instead of chop().


   ($base_no,$name,$description)=split(/\|/,$base_text);

 #choping lines and assign variables to exclude_bases.txt
 foreach $exclude_text (%exclude_bases)
 {
   chop($exclude_text);

Same as above.


   ($exbase_no,$keyword,$new_keyword)=split(/\|/,$base_text);

   if ($exbase_no=$base_no) {

You are assigning the value of $base_no to the variable $exbase_no.  If 
the value of $base_no is true then the expression is true.  You 
want to use a comparison operator like '==' or 'eq'.


   $keyword =~ s/$keyword/$new_keyword/g;}

Your description said that you wanted to modify 'the description 
field of base.txt' so that sould be:

   $description =~ s/$keyword/$new_keyword/g;}


 }
 }


It looks like you may want something like this:

#!/usr/bin/perl
use strict;
use warnings;

my $exclude_bases = 'exclude_bases.txt';
my $current_base  = 'base.txt';
my $output= 'new_bases.txt';

open EXCLUDE, '', $exclude_bases or die Could not open 
'$exclude_bases' $!;

my %exclude_bases;
while ( EXCLUDE ) {
next if $. == 1;  # exclude header
chomp;
my ( $exbase_no, $keyword, $new_keyword ) = split /\|/;
$exclude_bases{ $exbase_no } = { from = qr/\Q$keyword/, to = 
$new_keyword };
}

close EXCLUDE;


open BASE, '', $current_base  or die Could not open '$current_base' 
$!;
open OUT,  '', $outputor die Could not open '$output' $!;

while ( BASE ) {
my ( $base_no, $name, $description ) = split /\|/;
if ( exists $exclude_bases{ $base_no } ) {
$description =~ 
s/$exclude_bases{$base_no}{from}/$exclude_bases{$base_no}{to}/g;
$_ = join '|', $base_no, $name, $description;
}
print OUT;
}

__END__



John
-- 
use Perl;
program
fulfillment

-- 
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: Hash of array

2007-10-29 Thread John W . Krahn
On Monday 29 October 2007 09:15, Kevin Viel wrote:
 I have a dataset of values for variables for subjects.  Some subject
 have multiple records, requiring an average:

 ID  Var1 Var2
 1   1.0  2.0
 1   2.0  1.5

 -
 1   1.5  1.75

 If I collect the variables into an array, I can average the contents
 after I have processed the entire file.  It would seem that I want
 something like:

 my %subjects ;

 $subjects{ $ID }{ $var }[ 0 ] = $var1 ;
 $subjects{ $ID }{ $var }[ 0 ] = $var2 ;

 It does not seem like I could PUSH values onto the array:

 push $subject{ $ID }{ $var } , $var1 ;

 My first inclination is to use EXISTS and a create a variable
 intended to INDEX the array:

 my $index ;
 if ( ~ exists $subjects{ $ID }{ $var } ) {
   $index = 0 ;
 } else { $index = $subjects{ $ID }{ $var } )

   $subjects{ $ID }{ $var }[ $index ] = $var1 ;


 I would appreciate any comments or suggestions concerning this
 approach.

It looks like you could do something like this:


my %subjects;

while ( FILE ) {
next unless /^\d/;
my ( $ID, @vars ) = split;
$subjects{ $ID }{ count }++;
for my $index ( 0 .. $#vars ) {
$subjects{ $ID }{ sum }[ $index ] += $vars[ $index ];
}
}

# post-processing averages
for my $ID ( sort { $a = $b } keys %subjects ) {
for my $var ( @{ $subjects{ $ID }{ sum } } ) {
$var /= $subjects{ $ID }{ count };
}
print join \t, $ID, @{ $subjects{ $ID }{ sum } };
}




John
-- 
use Perl;
program
fulfillment


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




dereferencing

2007-10-29 Thread Aaron Priven

I can do this:

my $hashref = \%hash;

But as near as I can tell, there is no way to do the reverse  
operation: making a my %hash that is an alias for a hash reference.


It's possible with a package variable:

#/usr/bin/perl
our %hash;
my $hashref = { a = 5 , b = 8 };
*hash = $hashref;
print $hash{a};

that prints 5. But there's no way to do this with a lexical (my)  
variable.


is this right?

--
Aaron Priven, [EMAIL PROTECTED],com, http://www.priven.com/aaron



Re: Hash Variables

2007-10-29 Thread Matthew Whipple
sivasakthi wrote:
 On Mon, 2007-10-29 at 17:06 +0530, Kaushal Shriyan wrote:


   
 

 #!/usr/bin/perl -w

 %states = ( California,Sacramento, Wisconsin,Madison, New York,
 Albany);

 print Capital of California is  . $states{California} . \n\n;

 

 I did not understand the statement $states{California} in the above print
 statement of the code

 I know the the dot is a concatenation operator and \n is a newline character
 



 Hi  Kaushal,

 %states is a hash array
 California  is a key value

 $states{California}  means the value of hash($states)  key(California)
 is Sacramento


 More information : # perldoc -q hash

   
I'd recommend `perldoc perldata`.  For this particular instance in a
nutshell...you can initialize a hash as a list of keys followed by their
values (which is I believe how they are stored...the answer to that is
likely in the above reference topic).  Therefore, each *even* indexed
hash item (starting with 0) becomes a key, and accessing that key by
name (such as as $states{California}) will return the following item.


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




Re: dereferencing

2007-10-29 Thread Jeremy Kister

On 10/29/2007 7:23 PM, Aaron Priven wrote:

my $hashref = \%hash;

But as near as I can tell, there is no way to do the reverse  
operation: making a my %hash that is an alias for a hash reference.


my %newhash = %{$hashref};



--

Jeremy Kister
http://jeremy.kister.net./

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




Re: help on ip addr

2007-10-29 Thread Matthew Whipple
lists user wrote:
 Hello,

 I want to do the things below:

 a) get all binded IPs on a redhat linux os.there are maybe more than
 one IP,like eth0,eth1,eth0:1 etc.

 b) for each IP,I need to know if it's a private network address (like
 192.168.0.1) or a public network address.

 for the first problem I can read something from
 /etc/sysconfig/network-script/ifcfg-eth*, or code with @ips =
 `/sbin/ifconfig` and use regex to capture the IPs.But I don't think
 these are the best ways.

 I don't like to use any CPAN module,b/c I'm not admin user,don't have
 privileges to install those modules.
   
To save you from re-inventing wheels...
You don't need admin access to install most modules, just put them
somewhere where you can script can access them and use lib.

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




Re: dereferencing

2007-10-29 Thread Tom Phoenix
On 10/29/07, Aaron Priven [EMAIL PROTECTED] wrote:

 I can do this:

 my $hashref = \%hash;

 But as near as I can tell, there is no way to do the reverse
 operation: making a my %hash that is an alias for a hash reference.

You mean, given a reference to a hash, create a named lexical hash
that that reference refers to? No, that's not possible. Why would you
even want to do that? Is it just a matter of convenience, so you can
avoid dereferencing?

As you found, you can manipulate the symbol table so that a name
refers to a hash from a reference, but lexical variables aren't in the
symbol table.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: dereferencing

2007-10-29 Thread Tom Phoenix
On 10/29/07, Jeremy Kister [EMAIL PROTECTED] wrote:
 On 10/29/2007 7:23 PM, Aaron Priven wrote:
  my $hashref = \%hash;
 
  But as near as I can tell, there is no way to do the reverse
  operation: making a my %hash that is an alias for a hash reference.

 my %newhash = %{$hashref};

You have made a copy of the hash. I do not believe that that is what
the original poster wished, which I think would be a new hash that the
old reference points to. I don't think that what the original poster
wants is even possible, but I can't see any reason to need it, either.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: dereferencing

2007-10-29 Thread Paul Johnson
On Mon, Oct 29, 2007 at 05:21:52PM -0700, Tom Phoenix wrote:

 On 10/29/07, Jeremy Kister [EMAIL PROTECTED] wrote:
  On 10/29/2007 7:23 PM, Aaron Priven wrote:
   my $hashref = \%hash;
  
   But as near as I can tell, there is no way to do the reverse
   operation: making a my %hash that is an alias for a hash reference.
 
  my %newhash = %{$hashref};
 
 You have made a copy of the hash. I do not believe that that is what
 the original poster wished, which I think would be a new hash that the
 old reference points to. I don't think that what the original poster
 wants is even possible, but I can't see any reason to need it, either.

Perhaps something like Data::Alias, for example, might do the trick.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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




Re: dereferencing

2007-10-29 Thread John W . Krahn
On Monday 29 October 2007 15:23, Aaron Priven wrote:
 I can do this:

 my $hashref = \%hash;

 But as near as I can tell, there is no way to do the reverse
 operation: making a my %hash that is an alias for a hash reference.

Correct.  You can alias a package variable but not a lexical variable.


 It's possible with a package variable:

 #/usr/bin/perl
 our %hash;
 my $hashref = { a = 5 , b = 8 };
 *hash = $hashref;

You are not assigning to %hash you are assigning to the typeglob *hash. 
Because $hashref contains a reference to a hash only the *hash{ HASH } 
entry in the symbol table is affected.


 print $hash{a};

 that prints 5. But there's no way to do this with a lexical (my)
 variable.

 is this right?

Correct.  Lexical variables are not part of the symbol table.



John
-- 
use Perl;
program
fulfillment


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




Re: dereferencing

2007-10-29 Thread Jeremy Kister

On 10/29/2007 8:21 PM, Tom Phoenix wrote:

my %newhash = %{$hashref};


You have made a copy of the hash. I do not believe that that is what
the original poster wished, which I think would be a new hash that the
old reference points to. I don't think that what the original poster
wants is even possible, but I can't see any reason to need it, either.


Oops.  I knew I was making a new hash (hence the variable name).  I read 
his message (and subject) to imply that all he wanted was dereferencing. 
 My fault.


--

Jeremy Kister
http://jeremy.kister.net./

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




Re: dereferencing

2007-10-29 Thread Aaron Priven

On Oct 29, 2007, at 5:21 PM, Tom Phoenix wrote:

 I don't think that what the original poster
wants is even possible, but I can't see any reason to need it, either.


It's probably not necessary per se, as you can always do anything  
using reference syntax, but it's awkward and requires lots of extra  
dereferencing by the interpreter.


If %hash has a few thousand entries,

routine (%hash);

sub routine {
   my %myhash = @_;
...
}

is wasteful and timeconsuming, and I don't want to have to type lots  
of extra arrows just because I passed the hash to a subroutine. And  
now I don't have to. Yay.


--
Aaron Priven, [EMAIL PROTECTED], http://www.priven.com/aaron



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




how to get source of of web page which is hosted on the server (which I dont have access).

2007-10-29 Thread Siva Prasad
 

HI Gurus,

 

 

I am opening a web page using win32::IEAutomation and clicking each link on
the page and reading data.(This page has 177 links).

 

The above processes occupy more memory, After some time the page is unable
to load and the script gives me READY STATE error.

 

I have used WaitforDone(); but still no luck.

 

I tried LWP::Simple and LWP::UserAgent to read the content, But the it
throws me unable to get the source of the page.

 

I don't have access to the server on which pages are hosted.

 

Is there any other way to read the source of the page from the server on
which I don't have a account?

 

 

 

 

Thanks,

PP

 

 

image001.gif

Re: Hash Variables

2007-10-29 Thread Kaushal Shriyan
Hi

I am referring to perldoc perlintro
my %fruit_color = (apple, red, banana, yellow);

You can use whitespace and the = operator to lay them out more nicely:

   my %fruit_color = (
   apple  = red,
   banana = yellow,
   );

I know to use the Fat Comma Operator, How can one use the whitespace to lay
the Hash Key/Values Pair. Please explain me with the above example.

Thanks and Regards

Kaushal




On 10/29/07, Kaushal Shriyan [EMAIL PROTECTED] wrote:

 Hi,

 I have a sample code

 

 #!/usr/bin/perl -w

 %states = ( California,Sacramento, Wisconsin,Madison, New York,
 Albany);

 print Capital of California is  . $states{California} . \n\n;

 

 I did not understand the statement $states{California} in the above
 print statement of the code

 I know the the dot is a concatenation operator and \n is a newline
 character

 Thanks in Advance.

 Thanks and Regards

 Kaushal




Re: dereferencing

2007-10-29 Thread Aaron Priven

Playing around with this, indeed, proves it can be done:

#!/usr/bin/perl
use strict;
use warnings;
use Data::Alias;
my $hashref = { a = 5, b = 8};
alias my %hash = %{$hashref};
print $hash{a} , \n;

prints 5. (And \%hash == $hashref evaluates true.)

I knew that Data::Alias existed -- it's mentioned in Perl Best  
Practices -- but at least to me, the documentation seemed to imply  
that it couldn't do this, or that it would act like many scalar  
assignments in parallel.


Thanks!

On Oct 29, 2007, at 5:33 PM, Paul Johnson wrote:

Perhaps something like Data::Alias, for example, might do the trick.


--
Aaron Priven, [EMAIL PROTECTED], http://www.priven.com/aaron



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