Re: CGI.pm internals question

2005-07-14 Thread Scott R. Godin

Bob Showalter wrote:

Scott R. Godin wrote:


under what circumstances is the CGI.pm's STORE autoloaded method
called? 


is it used only when you assign values to the object, or is it only
used when receiving values (or multi-values) from the webserver query?



It is part of the tied hash interface returned by the $q-Vars method. It is
only invoked if you assign parameters through the tied hash.

All it does is call $q-param to assign the parameter value.


So if I were to say, override it thusly:

package CGI;

sub STORE {
my $self = shift;
my $tag  = shift;
my $vals = shift;
#my @vals = index($vals,\0)!=-1 ? split(\0,$vals) : $vals;
my @vals = @{$vals};
$self-param(-name=$tag,-value=[EMAIL PROTECTED]);
}

It wouldn't affect the webserver's ability to insert params from the 
query, correct?


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




RE: CGI.pm internals question

2005-07-14 Thread Bob Showalter
Scott R. Godin wrote:
[snip]
 So if I were to say, override it thusly:
 
 package CGI;
 
 sub STORE {
  my $self = shift;
  my $tag  = shift;
  my $vals = shift;
  #my @vals = index($vals,\0)!=-1 ? split(\0,$vals) : $vals;
  my @vals = @{$vals};
  $self-param(-name=$tag,-value=[EMAIL PROTECTED]);
 }
 
 It wouldn't affect the webserver's ability to insert params from the
 query, correct?

If I understand the question correctly, the answer is no, this method has no
effect on parsing the query parameters.

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




Re: 0; and 1;

2005-07-14 Thread Chris Devers
On Thu, 14 Jul 2005, Beast wrote:

 I coudn't find any reference (yet) the meaning of 0; or 1; in the end 
 of perl program.

In the absense of an explicit return statement, a block of Perl code 
will return the value of the last statement to any calling code.

For an ordinary script, this doesn't really matter -- it will return 
what it will return. For code that you expect to be called though, like 
a package or module, you have to keep the return value -- and more to 
the point, the truth of the return value -- in mind.

The simplest way to do this is the 1; end-of-module idiom. I've also 
seen people use random strings like 'true'; or 'pony pony pony'; -- 
but either way has the same result: as long as the truth status of the 
final statement is guaranteed to unconditionally be true, then the 
module can be used without throwing any errors (or at least, not errors 
because of the return status). 
 
The important bit to keep in mind is the truth value of the last line. 
Using '1;' is a short, simple, guaranteed way to get this truth value.


-- 
Chris Devers

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




call other program

2005-07-14 Thread Ken Killer
If I run the application A  from the command line, it will write some
output to screen  and continue running on the foreground.
Now, in my perl tool program,  I will call the application A and
collect some output of that application A. my perl program will be
used on Unix/Linux/Win32 system.

My program like this,  I don't close the filehandle FH, because I want
the appA to run at the background for ever.

open FH,appA |;
my @result =FH;   
   
foreach (@result) { 
print $_ if  m/patten/;
} 

But I don't get the expect as what I want,  my perl program never
exit, because  the appA is running.

how to fix my perl program?

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




mixin object method

2005-07-14 Thread Todd W
I've been trying to undersand what mixins are and at the same time figuring 
out how to make them easy to use. I just belched out this piece of code, but 
I dont know if its doing anything special:

use warnings;
use strict;

package MyMixins;

sub SomeMethod {
  my $obj = shift;
  print( 'a ', ref( $obj ), ' goes: ', $obj-{slot}, \n );
}

package MyClient;

sub new {
  my $class = shift;
  my $self = bless( { }, $class );
  $self-{slot} = shift || 'moo';
  return $self;
}

package main;

my $client = MyClient-new;
$client-MyMixins::SomeMethod;

print(done!\n);

C:\waveright\home\trwww\miscperl mixintest.pl
a MyClient goes: moo
done!





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




flock and open files

2005-07-14 Thread bclark1

Hi list

My colleaque and I have just had a small disagreement with each other 
about file locking and reading / ammending a txt file.


To up date a CSV file (it must be quick and / or effient), my colleaque
likes to either read the whole file in memory (I dont like this) or
open the file and use seek etc.

I like to open the file, open a tem, use a while, print the line to the 
temp file, and on the line im looking for do what I need then print to 
the temp file and then close the file and then unlink the original and 
then rename the file.


The other one is file locking. My colleaque says the flocking does not 
work on Linux, where as I say the flock works for both Linux as well as 
win32. I read the perldocs and I have not seen anything proving him 
right, but as the same time I have not seen anything that proves him wrong.


So if anyone share their experiences or tips is would be most appreciated.

Please bare with me on this, still new to perl / programming.

Kind Regards
Brent Clark

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




Limit memory used by perl

2005-07-14 Thread Beast

Hi all,


Is it possible to limit memory used by perl? I don't want perl program 
to eat all memory causing OS to freeze.



--

--beast


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




Re: Limit memory used by perl

2005-07-14 Thread Brent Clark

Beast wrote:

Hi all,


Is it possible to limit memory used by perl? I don't want perl program 
to eat all memory causing OS to freeze.





Hi

Maybe you should relook / think yout app and see where you can make it 
more effienct


Kind Regards
Brent Clark

P.s. How much memory is the machine using?

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




Re: Limit memory used by perl

2005-07-14 Thread Ing. Branislav Gerzo
Beast [B], on Thursday, July 14, 2005 at 18:23 (+0700) typed the
following:

B Is it possible to limit memory used by perl? I don't want perl program
B to eat all memory causing OS to freeze.

I think, one way how to limit memory usage by perl is measure its
memory, you didn't write you OS, so here are some:

for win:
use Win32;
...
my $osname = Win32::GetOSName();
if ($osname eq 'WinXP/.Net' or $osname eq 'Win2003') {
   print memory usage: $1 RAM. if `tasklist /FO list /v /FI PID eq $$` 
=~ /Mem\s+Usage:\s+(.+)/;
} else {
   print memory usage: $1 RAM. if `tlist $$` =~ 
/WorkingSetSize:\s+(\d+\s+\w+)/;
}

for *nix:
http://www.perlmonks.org/index.pl?node_id=336856
or something like that :)

I had similar problems (too big data structure for speed...),
so I limit hash keys to certain value...

-- 

How do you protect mail on web? I use http://www.2pu.net

[:^[-B  Girlfriend's mad at me.]



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




Re: Limit memory used by perl

2005-07-14 Thread Beast

Brent Clark wrote:

Beast wrote:


Hi all,


Is it possible to limit memory used by perl? I don't want perl program 
to eat all memory causing OS to freeze.





Hi

Maybe you should relook / think yout app and see where you can make it 
more effienct




Yes maybe :-p
I have prototype that should parse big log files (680MB) converted into 
nice GUI apps. It's not nice if the machine totaly freeze during testing.

(linux 512MB/2GB swap).

--

--beast


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




Re: 0; and 1;

2005-07-14 Thread Adriano Ferreira
On 7/14/05, Beast [EMAIL PROTECTED] wrote:
 
 I coudn't find any reference (yet) the meaning of 0; or 1; in the end of
 perl program.

In the examples in perldoc perlmod you will find

 1;  # don't forget to return a true value from the file

This is needed when you do a 'require' over a Perl module (which is a
Perl package in a file). The same applies to 'use' which does a
'require' as its first step. Perl programs or packages within the same
file don't need this. Or else a program simple as 'print(Hello,
World); undef would not work, but it does. As Chris Devers has said
it has to do with the return value of the last statement. This is
interpreted by 'require' as meaning everything was fine during the
initialization of the Perl module. Most of the time, we finish the
module just with 1;, but more deeper things could be done. An
example is a Perl module attached to a configuration file: it that
configuration could not be read, it is better to die than to continue.
(This is not the perfect example: something sensible could be done
with defaults rather than blowing in user's face).

For references, take a look at perldoc -f require.


 It means exit or return value? when I explicitly type return 0; it
 gives error, 

You return only from a sub.

 but when I give exit 100; the value of $$ isn't 100 anyway.

'exit' finishes the program immediately. $? (if in shell) catches the exit code:
$ perl -e exit(100)
$ echo $?
100

Regards,
Adriano.

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




Re: Limit memory used by perl

2005-07-14 Thread Robin
On Thursday 14 July 2005 23:23, Beast wrote:
 Is it possible to limit memory used by perl? I don't want perl program
 to eat all memory causing OS to freeze.
If you're on a UNIX or Linux, look into 'ulimit'. It allows you to set per 
account (and maybe per-process, I haven't really gotten into it) limits 
on things like memory and CPU.

-- 
Robin [EMAIL PROTECTED] JabberID: [EMAIL PROTECTED]

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0xA99CEB6D = 5957 6D23 8B16 EFAB FEF8  7175 14D3 6485 A99C EB6D


pgpSKVlrQwuTU.pgp
Description: PGP signature


Re: mixin object method

2005-07-14 Thread Jeff 'japhy' Pinyan

On Jul 13, Todd W said:


I've been trying to undersand what mixins are and at the same time figuring
out how to make them easy to use. I just belched out this piece of code, but
I dont know if its doing anything special:


Perl allows you to call an object from any class to call a method from any 
class.  Typically, $object-method searches through $object's class and 
inheritance tree.  If you give a fully-qualified method name, such as 
OtherClass::method, then Perl calls that very specific method, which is 
what you've done below.



package MyMixins;

sub SomeMethod {...}

package MyClient;

sub new {...}

package main;

my $client = MyClient-new;
$client-MyMixins::SomeMethod;


Yeah, that looks about right.  Thrilling, wasn't it?

--
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

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




HaMakor Prize

2005-07-14 Thread Offer Kaye
http://www.hamakor.org.il/prize.html

There are five finalists nominated for the prize, one of them is our
very own Gabor Szabo.

Congratulations Gabor and good luck!

If you are already a member/friend of HaMakor, you should have
received an email from them urging you to vote. So go do it :)
If you aren't a member/friend, you need to register in order to vote.
What are you waiting for? ;-)

-- 
Offer Kaye

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




Re: flock and open files

2005-07-14 Thread mgoland


- Original Message -
From: bclark1 [EMAIL PROTECTED]
Date: Thursday, July 14, 2005 6:48 am
Subject: flock and open files

 Hi list
Hello,
 
 My colleaque and I have just had a small disagreement with each 
 other 
 about file locking and reading / ammending a txt file.
 
 To up date a CSV file (it must be quick and / or effient), my 
 colleaquelikes to either read the whole file in memory (I dont 
 like this) or
 open the file and use seek etc.
 
 I like to open the file, open a tem, use a while, print the line 
 to the 
 temp file, and on the line im looking for do what I need then 
 print to 
 the temp file and then close the file and then unlink the original 
 and 
 then rename the file.
This is just a choise of preferance, as long as you can be certain that no 
other processes are modifying the file while you are at it, techniqe makes no 
differance [ surly one will be faster and more secure then other ].

 
 The other one is file locking. My colleaque says the flocking does 
 not 
 work on Linux, where as I say the flock works for both Linux as 
 well as 
 win32. I read the perldocs and I have not seen anything proving 
 him 
 right, but as the same time I have not seen anything that proves 
 him wrong.
reading perldoc -f flock...

 Calls flock(2), or an emulation of it, on FILEHANDLE. Returns
 true for success, false on failure. Produces a fatal error if
 used on a machine that doesn't implement flock(2), fcntl(2)
 locking, or lockf(3). flock is Perl's portable file locking
 interface, although it locks only entire files, not records.

Sounds like any OS that supports these system calls, will work. Surely most [ I 
have never herd of one] linux systems will support these system calls. you 
should also know that Cflock will not actualy lock the file, just set locking 
bit on.
 
 So if anyone share their experiences or tips is would be most 
 appreciated.
 Please bare with me on this, still new to perl / programming.
 
 Kind Regards
 Brent Clark
Cheers,
mark G.
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 

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




LWP

2005-07-14 Thread David Foley


attachment: blue-nod.jpg


Re: LWP

2005-07-14 Thread Ing. Branislav Gerzo
David Foley [DF], on Thursday, July 14, 2005 at 15:41 (+0100) has on
mind:

[we don't know]...

David, we all get (I think) only 3 pictures in your mail; if you
could, stop sending this (pictures). But main problem is we don't get
any text, any question in your mail, so we can't answer.
Try to fix that, but don't test that on this mail-list :)

-- 

How do you protect mail on web? I use http://www.2pu.net

[Make her sound like a kazoo - Joel on alien lab tests]



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




[Fwd: LWP]

2005-07-14 Thread David Foley
Guys can some read the below code and tell me what I'm doing wrong? I 
just want to post some values to a php script.


# Setup a user agent for LWP
use LWP::UserAgent;
my $LWPua = LWP::UserAgent-new;
$LWPua-agent(firefox);

#LWP - HTTP request 1
my $LWPreq1a = HTTP::Request-new(POST 
=http://www.scoilweb.net/construction/dev/dev102r.php;);

$LWPreq1a-content(recipient = [EMAIL PROTECTED]);
$LWPreq1a-content(subject = OnLineExped\-ORDER);
$LWPreq1a-content(followup-page = 
http:\/\/www.eset.sk\/order\/index.html);

$LWPreq1a-content(Reseller_Id = KILO865421);
$LWPreq1a-content(PurchaseOption  = NFR);
$LWPreq1a-content(TypeOfPlatform = NOD32 for 
Win9x\/Me\/NT\/2000\/XP\/2003\+DOS);

$LWPreq1a-content(TypeOf_License = 1);
$LWPreq1a-content(Clients_name = $FirstName $SecondName);
$LWPreq1a-content(Clients_email = [EMAIL PROTECTED]);
$LWPreq1a-content(Clients_phone = $RefNo);
$LWPreq1a-content(Expiration = 08\/14\/2006);
$LWPreq1a-content(Price = 39);
$LWPreq1a-content(Servers = 0);
$LWPreq1a-content(Note = This order was automatically submited by TMA1);

#Pass HTTP request 1 to user agent
my $LWPreq1 = $LWPua-request($LWPreq1a);

#Check response and add to info.txt
if ($LWPreq1-is_success) {print success} else {print fail};

Thanks
David

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




Re: Object persistence

2005-07-14 Thread Jeff 'japhy' Pinyan

On Jul 13, Scott R. Godin said:


http://www.webdragon.net/miscel/DB.pm


I'll check it out.

All Subscriber::DB objects would share the DBI object -- there's no need for 
a billion database handles. 


ok, so possibly one should do it differently than I have, in my example.


Well, look at it this way:  either the Subscriber::DB object holds the 
database, or it holds a subscriber.  Choose.


If it holds the database, then it needs a method to lookup, create, and 
return a Subscriber object from the database.


If it holds the subscriber, it needs to CALL the database to populate 
itself.


But what I had thought of doing would be to populate the object via the 
database and fill it entire, thus being able to call any of the Subscriber 
methods on it without generating multiple calls to the database for each one.


Ah, so by object persistence you mean that you want to create the 
objects from the state they had in the database, and then when you're done 
with them, save them back to the database?  That seems reasonable, if 
you're not going to have multiple processes accessing and changing this 
information.


The way I envisioned it was very similar to a tie() mechanism.  Every 
access or setting of a value triggers a database action.  Your method is 
certainly less of a strain on the database.


One problem-space I'm still trying to wrap into the picture is the need to be 
able to grab data from the database based on different criterion..  for 
example everyone who has requested info by e-mail only, or the opposite -- 
people who want their info snail-mailed to them.


That's just SQL.

  SELECT *
  FROM subscribers
  WHERE email IS NOT NULL

Something like that would get all the records that had email addresses 
filled in.


Here is my new take on what you want Subscriber::DB to do:

1. you create a connection to the database
2. you get all the records from the database (in the form of Subscriber
   objects) which match a certain criteria
3. you fiddle with them
4. if you make changes, they get reflected in database when you're done

Does that sound appropriate?

  use Subscriber::DB;

  my $email_dbh = Subscriber::DB-new;   # makes a new connection
  $email_dbh-filter('email IS NOT NULL');   # sets up criteria
  my @email_subs = $email_dbh-subscribers;  # gets matches

  my $snail_dbh = Subscriber::DB-new;   # makes a new connection
  $snail_dbh-filter('email IS NULL');   # sets up criteria
  my @snail_subs = $email_dbh-subscribers;  # gets matches

Is that what you envision?  The storage of the Subscriber objects 
somewhere in the Subscriber::DB object?  I would change it to needing only 
ONE S::DB object:


  my $dbh = Subscriber::DB-new;
  my @email_subs = $dbh-filter('email IS NOT NULL');  # runs the search
  my @snail_subs = $dbh-filter('email IS NULL');  # ditto

The other idea I have is to return not Subscriber objects, but objects 
that inherit from Subscriber, for this reason:  you can override their 
DESTROY handler to update the database when they die!


  package Subscriber::DB;

  sub filter {
my ($dbh, @how) = @_;
my @results = ...;  # DBI magic here
my @obj;

for my $rec (@results) {
  # the object needs to know the DBI handle it came from
  my $s = Subscriber::Updater-new($dbh, $rec);
  push @obj, $s;
}

return @obj;
  }

  package Subscriber::Updater;

  use base 'Subscriber';

  sub new {
my ($class, $dbh, $data) = @_;
# fill it in...
  }

  DESTROY {
my ($self) = @_;
my $db = $self-{_dbh};  # or however you'd prefer
# do some updating of the DB based on the contents of the object
  }

How's that sound?

--
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

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




how to use command line parameters

2005-07-14 Thread Manish Uskaikar
command line:
 
$perl man.pl manish
 
 
 
perl script
 
#!/usr/bin/perl;
($inputfile) = @ARGS;
 
Could anyone tell me how to accept the commandline parametes this does not seem 
to work.
 
Regards,
Manish U


Re: how to use command line parameters

2005-07-14 Thread Remo Sanges

Manish Uskaikar wrote:


command line:

$perl man.pl manish



perl script

#!/usr/bin/perl;
($inputfile) = @ARGS;

Could anyone tell me how to accept the commandline parametes this does not seem 
to work.


@ARGV and not @ARGS is an array
so you have to use it by element.
In your case the name of the input file (manish)
seems to be  the first argument.

So youshould use this code:

($inputfile) = @ARGV[0];



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




Re: how to use command line parameters

2005-07-14 Thread Remo Sanges

Manish Uskaikar wrote:


command line:

$perl man.pl manish



perl script

#!/usr/bin/perl;
($inputfile) = @ARGS;

Could anyone tell me how to accept the commandline parametes this does not seem 
to work.


@ARGV and not @ARGS is an array
so you have to use it by element.
In your case the name of the input file (manish)
seems to be  the first argument.

So youshould use this code:

($inputfile) = @ARGV[0];


HTH

Remo

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




Re: how to use command line parameters

2005-07-14 Thread Remo Sanges

Remo Sanges wrote:


Manish Uskaikar wrote:


command line:

$perl man.pl manish



perl script

#!/usr/bin/perl;
($inputfile) = @ARGS;

Could anyone tell me how to accept the commandline parametes this 
does not seem to work.



@ARGV and not @ARGS is an array
so you have to use it by element.
In your case the name of the input file (manish)
seems to be  the first argument.

So youshould use this code:

($inputfile) = @ARGV[0];


HTH

Remo


Sorry...
Too hot here in Naples ;-)
The rigth code is

($inputfile) = $ARGV[0];

Remo

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




update file

2005-07-14 Thread Rafael Morales
Hi list.

I have two files which I compare:
first file:
813|42006|34913|373376|SALAZAR/BERLANGA/JUAN FRANCISCO
K00|42004|99|489545|FAUSTO/PERALTA/PORFIRIO
900|72059|2031|237648|CAZARES/GUTIERREZ/ALEJANDRO
211|42005|34913|86258|GUZMAN/DIAZ/CARLOS NOE

second file:
000|42006|34913|373376|SALAZAR/BERLANGA/JUAN FRANCISCO
111|42004|99|489545|FAUSTO/PERALTA/PORFIRIO
222|72059|2031|237648|CAZARES/GUTIERREZ/ALEJANDRO
333|42005|34913|86258|GUZMAN/DIAZ/CARLOS NOE|20050609

As you can see the first column is different so I need to update the second 
file for both files have the same values, how could I do it ???
Note: My comparison works fine, I just need update it.

Thanks and regards !!!

-- 
___
Get your free email from http://mymail.bsdmail.com

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




Re: how to use command line parameters

2005-07-14 Thread John Doe
Manish Uskaikar am Donnerstag, 14. Juli 2005 18.21:
 command line:
 $perl man.pl manish

 perl script:
 #!/usr/bin/perl;
 ($inputfile) = @ARGS;

 Could anyone tell me how to accept the commandline parametes this does not
 seem to work.

please put the following lines into every script/module you write, since it 
gives you error messages and hints about what could be/going wrong:

use strict;  
use warnings;

joe

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




Re: update file

2005-07-14 Thread Rafael Morales
This the code I use for compare, and works, but I don't know how to update the 
file2, I hope you understand me

#!/usr/bin/perl
use strict;

   my file1 = path to file;
   my file2 = path to file;

   open(FILE1, $file1) || die;  # just read
   open(FILE2, +$file2) || die; # for update it

   foreach $nomina (FILE1)
   {
   my $match = 0;
   my @nomina = split /|/, $nomina;

   foreach $bucareli (FILE2)
   {
 @bucareli = split /\|/, $bucareli;
   
 if ( $nomina[3] == $bucareli[3] )
 { 
 if ( $nomina[0] == $bucareli[0] )
 {
 $match = 1; 
 }
 } 
   }

   if ( $match == 1 )
   {
print FILE2 $nomina[0]\n;
   }  
}


- Original Message -
From: Wiggins d'Anconia [EMAIL PROTECTED]
To: Rafael Morales [EMAIL PROTECTED]
Subject: Re: update file
Date: Thu, 14 Jul 2005 10:56:54 -0600

 
 Rafael Morales wrote:
  Hi list.
 
  I have two files which I compare:
  first file:
  813|42006|34913|373376|SALAZAR/BERLANGA/JUAN FRANCISCO
  K00|42004|99|489545|FAUSTO/PERALTA/PORFIRIO
  900|72059|2031|237648|CAZARES/GUTIERREZ/ALEJANDRO
  211|42005|34913|86258|GUZMAN/DIAZ/CARLOS NOE
 
  second file:
  000|42006|34913|373376|SALAZAR/BERLANGA/JUAN FRANCISCO
  111|42004|99|489545|FAUSTO/PERALTA/PORFIRIO
  222|72059|2031|237648|CAZARES/GUTIERREZ/ALEJANDRO
  333|42005|34913|86258|GUZMAN/DIAZ/CARLOS NOE|20050609
 
  As you can see the first column is different so I need to update 
  the second file for both files have the same values, how could I 
  do it ???
  Note: My comparison works fine, I just need update it.
 
  Thanks and regards !!!
 
 
 What have you tried? Where did it fail? Show us some code.
 
 perldoc perlopentut
 perldoc Tie::File
 perldoc DBD::CSV
 
 http://danconia.org
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response


-- 
___
Get your free email from http://mymail.bsdmail.com

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




Re: update file

2005-07-14 Thread Wiggins d'Anconia
Because it's up-side down.
Why is that?
It makes replies harder to read.
Why not?
Please don't top-post. - Sherm Pendley, Mac OS X list


Rafael Morales wrote:
 This the code I use for compare, and works, but I don't know how to update 
 the file2, I hope you understand me
 
 #!/usr/bin/perl
 use strict;

Do you really have 'use strict' in your file? If so there are problems
below that you haven't corrected and your script won't run. If this is a
chunk of a larger script you should tell us so that we don't think this
is complete.

 
my file1 = path to file;
my file2 = path to file;
 

The above two lines are missing their sigils.

my $file1 = ...;
my $file2 = ...;

open(FILE1, $file1) || die;  # just read
open(FILE2, +$file2) || die; # for update it
 

It usually helps to include an error message when calling die, and when
that message is caused by an internal function usually you should
include the special variable $! to indicate *why* it died.

open(FILE1, $file1) || die Can't open field for reading: $!\n;

foreach $nomina (FILE1)

You did not declare $nomina which is why I have the question about use
strict.

In general it is usually better to use a while loop instead of a foreach
when reading files line by line. The foreach loop causes the whole file
to be read in immediately and stored to memory. Using a while loop will
read only a line at a time.

{
my $match = 0;
my @nomina = split /|/, $nomina;
 

You did not backslash the | here. Consistency.

foreach $bucareli (FILE2)

You did not declare $bucareli. See above comment about foreach.

{
  @bucareli = split /\|/, $bucareli;

Missing declaration.


  if ( $nomina[3] == $bucareli[3] )
  { 
  if ( $nomina[0] == $bucareli[0] )
  {

The above two checks can be condensed, and no real need to set a
temporary variable. Just perform your match stuff right in the if block,

if ($nomina[3] == $bucareli[3] and $nomina[0] == $bucareli[0]) {
print FILE2 .;

Since you haven't stated clearly what the real problem is, I assume this
is part of it. You are only printing the one column of the record back
to the file. You need to re-join the elements of the line and print them
back, updating the ones that have changed.

For instance,

print FILE2 join '|', $nomina[0], @bucareli[1..$#bucareli];

perldoc -f join

Of course if you are really trying to make the files identical then
there is certainly a much shorter way.

http://danconia.org

  $match = 1; 
  }
  } 
}
 
if ( $match == 1 )
{
 print FILE2 $nomina[0]\n;
}  
 }
 
[snip]

I have two files which I compare:
first file:
813|42006|34913|373376|SALAZAR/BERLANGA/JUAN FRANCISCO
K00|42004|99|489545|FAUSTO/PERALTA/PORFIRIO
900|72059|2031|237648|CAZARES/GUTIERREZ/ALEJANDRO
211|42005|34913|86258|GUZMAN/DIAZ/CARLOS NOE

second file:
000|42006|34913|373376|SALAZAR/BERLANGA/JUAN FRANCISCO
111|42004|99|489545|FAUSTO/PERALTA/PORFIRIO
222|72059|2031|237648|CAZARES/GUTIERREZ/ALEJANDRO
333|42005|34913|86258|GUZMAN/DIAZ/CARLOS NOE|20050609


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




Re: how to use command line parameters

2005-07-14 Thread Todd W

Manish Uskaikar [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
command line:

$perl man.pl manish

perl script

#!/usr/bin/perl;
($inputfile) = @ARGS;

Could anyone tell me how to accept the commandline parametes this does not 
seem to work.

for simple arguments this works great. If you want to parse complex command 
line arguments, use Getopt::Long.This module comes with perl. Heres an 
example:

my $opts = { };
GetOptions( $opts = qw/directory=s loglevel=s/);

my $missing = [ ];
foreach my $option ( qw/directory loglevel/ ) {
  push( @{ $missing }, $option ) unless ( $opts-{ $option } );
}

usage( $missing ) if ( @{ $missing } );

sub usage {
  my $args = shift; my $usage;

  $usage = join(, map(missing required parameter: '$_'\n, @{ $args }), 
\n );

  $usage .= 'Usage: $ ' . $0 . ' \\' . \n;
  $usage .= '  --directory=/path/to/zip/files \\' . \n;
  $usage .= '  --loglevel=[DEBUG|INFO|WARN|ERROR|FATAL]' . \n\n;

  die( $usage );
}

Enjoy,

Todd W.



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