Re: how to execute a perl file in cgi?

2004-10-10 Thread Bill Jones

--- Gunnar Hjalmarsson [EMAIL PROTECTED] wrote:

 Bill Jones wrote:
  The third way - `` (back-ticks) is highly discouraged.
 
 Discouraged? Why? I thought that was depending on what exactly it is
 you want to do, e.g. whether you want to capture the output from the
 script you run.


Well, it is definitely a matter of taste, true.  There are cleaner ways
to capture the external program's output.

Personally I have seen, in my short time programming in Perl, that some
versions of Perl have at times executed `` (back-ticks) as if they were
contained inside a BEGIN block -- that is prior to executing my code in
correct sequence.

Don't misundertsnad me, I have used back-ticks a lot.  I just feel
there are better (read: clearer) ways to start an external program from
Perl.

:)
-Sx-


=
-Sx-
seeking employment: http://youve-reached-the.endoftheinternet.org/



__
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

-- 
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 execute a perl file in cgi?

2004-10-10 Thread Bill Jones

--- Xiangli Zhang [EMAIL PROTECTED] wrote:

 Since I want to analyse a complicated problem involved with one
 file.pl, I am suspect the .pl file was not executed. I tried with
 very simple file.pl only printing one line, but it does not work. The
 following is the code:
  
 the cgi file
  
  
 #!/usr/bin/perl
 use lib '/srv/www/cgi-bin/phrap';
 
 print Content-type: text/html\n\n;
 print htmlheadtitlePerl CGI Example # 2;
 print /title/headbodyh1;
 print Alignment Result /h1p;
 print pre;
 
 system(perl, /srv/www/cgi-bin/phrap/testL.pl);
 print /pre;
 print /p;
 print /body/html;
 
 the .pl file testL.pl
  
 #!/usr/bin/perl
 print %%\n\n;
 


A series of Percent signs is significant to the resulting web browser;
please try to use a sim ple, plain old, ASCII text - maybe just Hi, I
am the testL programs output ???

  
 testL.pl is in the folder '/srv/www/cgi-bin/phrap', both of the files
 have maximum permissions
  
 I am suspecting the problem is related to configuration of Apache web
 server. Is it possible? Since, the exact files work fine in one
 server, but not in the other. 
  
 I am not so familiar with Apache configuration, just know some basic
 things.
  
 Any suggestions?


How do you know that the use lib is working?  Can you prove the
programs both work for the command line first - before you try them as
CGIs?

As far as apache is concerned I suggest:

http://httpd.apache.org/docs-2.0/howto/cgi.html

:)
-Sx-



=
-Sx-
seeking employment: http://youve-reached-the.endoftheinternet.org/

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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




I'm confused: where are the commas for map and sort

2004-10-10 Thread Siegfried Heintze

The map and the sort statements are strange. Why don't they require a comma
between the first and second arguments?

 Thanks,
Siegfried


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




Re: Variable name substitution (probably a question on references)

2004-10-10 Thread Peter Rabbitson
Ok, I guess I need to bring more context to the stage. The script itself is
a credit card batch parser, which guesses the card type by the first digit,
and proceeds by calculating totals, transaction counts, transaction fees,
and bunch of other relevant things. So ebverything in the script revolves
around hashes with the same keys (3,4,5,6). However at the end after all
calculations, because of a certain processing specifics, I need to produce a
visa + master grand total, if the user requests it (web for input). So I
dropped this snippet which simply creates an additional key vm, and adds
everything together. In this light I hope you understand that doing
this:$data{vm}{cardtot} = $data{4}{cardtot} + $data{5}{cardtot};
would complicate code even more than just plain adding them together.
Actually it is not that big of a deal since I am replacing 5 lines with 3,
not that much of a speed increase. However for aesthetical reasons I wanted
to know how to reference a variable, nevertheless in this case it is
completely justified. Granted the code will instantly break if some
doofus changes the names of the variables (the foreach list will be invalid
thereafter) but hey - who asked him to mess with the names?

As a matter of fact this probably was a bad example, I have another
application for this that is way more elaborate to write line by line.
Consider a cgi form that has a number of properties for a number of cards.
For example transaction fee, fee assessment, discount rate for all visa,
master, discover, amex. Say we name the Input types accordingly:

6_pct - discover discount rate
6_tfee - discover transaction fee
6_fa - discover fee assessment
5_pct - master card discount rate

you get the idea. Now I want to read them in the script:

$pct{6} = $form-param('6_pct');
$tfee{6} = $form-param('6_tfee');
$fa{6} = $form-param('6_fa');
$pct{5} = $form-param('5_pct');

Wow... what if I had 10 kinds of cards and 20 properties for each?

However if I could define:
%cards = (4,Visa, 5,MasterCard, 6,Discover, 3,AmEx);
@props = (pct, tfee, fa);

and than do:
foreach $c (keys (%cards)) {
foreach $p (@props) {
$($p){$c} = $form-param('($c)._.($p)');
}
}

(or at least something along the lines, since this is obviously more
pseudo-langague than perl itself)

Disregard how stupid it is to use a variable as a variable name - I don't
see why it wouldn't be suitable above. Nevertheless I still don't know how
to do it, although Mr. Dominus says it is fairly easy.

So help me or shoot me :)


P.S. I personally think use strict complains just way too much, to a point
where you lose all the elegance that coding in perl calls for.

Peter

P.P.S. Sorry for the double message, did not reply to list. 

On Sun, Oct 10, 2004 at 09:34:13PM +0200, Jenda Krynicky wrote:
 From: Peter Rabbitson [EMAIL PROTECTED]
  Hello list, 
  I have the following code:
  
  $cardtot{vm} = $cardtot{4} + $cardtot{5};
  $trans{vm} = $trans{4} + $trans{5};
  $dsc_amt{vm} = $dsc_amt{4} + $dsc_amt{5};
  $trf_amt{vm} = $trf_amt{4} + $trf_amt{5};
  $cardtot{vm} = $cardtot{4} + $cardtot{5};
  $as_tot{vm} = $as_tot{4} + $as_tot{5};
 
 You should use a hash like this:
 
   $data{vm}{cardtot} = $data{4}{cardtot} + $data{5}{cardtot};
   $data{vm}{trans} = $data{4}{trans} + $data{5}{trans};
   ...
  
  How can it be rewritten in a way similar to this?:
  
  foreach $var (cardtot, trans, dsc_amt, trf_amt, cardtot,
  as_tot) { $$var{vm} = $$var{4} + $$var{5}; }
 
 Then it would be either:
 
 foreach my $var (cardtot, trans, dsc_amt, trf_amt, 
   cardtot, as_tot) {
   $data{vm}{$var} = $data{4}{$var} + $data{5}{$var};
 }
 
 or (if you were sure you want to do this for all keys in 
 $data{something} you could use just:
 
 foreach my $var (keys %{$data{4}}) {
   $data{vm}{$var} = $data{4}{$var} + $data{5}{$var};
 }
 
  
  It does not work the way I wrote it, so I guess I am missing something
  really really minor...
 
 There are two things you are missing. 
 1) What does $$var{key} mean? Is it the same as ${$var}{key} or 
 ${$var{key}}? That is should I first dereference and then look for a 
 key or the other way around? To tell the truth I don't remember 
 myself which one takes precedence so I would always use the {} to 
 make sure it means what I wanted.
 
 2) You are trying to use so called soft references. While it is 
 possible (without use strict) it's not a good idea. Please read:
 
 Why it's stupid to `use a variable as a variable name' - by M-J. 
 Dominus 
 http://www.plover.com/~mjd/perl/varvarname.html
 
 HTH, Jenda
 = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
 When it comes to wine, women and song, wizards are allowed 
 to get drunk and croon as much as they like.
   -- Terry Pratchett in Sourcery
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 

-- 

Re: Variable name substitution (probably a question on references)

2004-10-10 Thread Gunnar Hjalmarsson
[ Please type your reply below the quoted part of the message you are
replying to. Please only quote what's needed to give context. ]
Peter Rabbitson wrote:
However for aesthetical reasons I wanted to know how to reference a
variable, nevertheless in this case it is completely justified.
I disagree. Nothing you have said makes me understand why the advice
Jenda gave you isn't applicable to your problem.
snip
Disregard how stupid it is to use a variable as a variable name -
I don't see why it wouldn't be suitable above.
I'm sure it would be possible, but it's considered bad coding practice
when you easily can apply another technique.
Nevertheless I still don't know how to do it, although Mr. Dominus
says it is fairly easy.
So help me or shoot me :)
P.S. I personally think use strict complains just way too much, to
a point where you lose all the elegance that coding in perl calls
for.
Since you
1) are not very convincing in explaining why it would be necessary to
use soft references, and
2) argue against enabling strictures, and with that make Perl help you
get your code right,
you'll find that few people here are inclined to help you.
(You can always read about soft references in perldoc perlref.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



IDE for web pages produces by Perl/MySql

2004-10-10 Thread Mike K
G'day...

I'm wanting to use Perl with MySQL to produce web pages, and then
process the results.

Are there any IDEs (like PageMill, Dreamweaver, etc) that understand
Perl or can write templates that Perl can understand using a particular
package?

All help appreciated.

Thanks

Mike
(Please reply-to-all to hit my work email as well.)


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




Re: Variable name substitution (probably a question on references)

2004-10-10 Thread Jenda Krynicky
From: Peter Rabbitson [EMAIL PROTECTED]
 For example transaction fee, fee assessment, discount rate for
 all visa, master, discover, amex. Say we name the Input types
 accordingly:
 
 6_pct - discover discount rate
 6_tfee - discover transaction fee
 6_fa - discover fee assessment
 5_pct - master card discount rate
  
 you get the idea. Now I want to read them in the script:
 
 $pct{6} = $form-param('6_pct');
 $tfee{6} = $form-param('6_tfee');
 $fa{6} = $form-param('6_fa');
 $pct{5} = $form-param('5_pct');
 
 Wow... what if I had 10 kinds of cards and 20 properties for each?
 
 However if I could define: 
 %cards = (4,Visa, 5,MasterCard, 6,Discover, 3,AmEx);
 @props = (pct, tfee, fa);
 and than do:
 foreach $c (keys (%cards)) {
  foreach $p (@props) {
   $($p){$c} = $form-param('($c)._.($p)');

Change that to
${$p}{$c} = $form-param($c._.$p);
and it will be runnable (albait not perfect) code.

  }
 }

It would still IMHO be much better to do something like:

%cards = (
4 = {name = 'Visa'},
5 = {name = 'MasterCard'},
6 = {name = 'Discover'},
3 = {name = 'AmEx'},
);

foreach my $cardid (keys %cards) {
  foreach my $property (@props) {
$data{$cardid}{$property} = $form-param($cardid._.$property);
  }
}

This way you have just one variable holding all the data, not several 
separate variables. So you can pass the whole data between functions 
easily, you can keep several separate data structures holding 
different data ...

It's probably not worth the effort to go rewrite the whole script, 
but believe me GLOBAL VARIABLES ARE BAD. And soft references are even 
worse.

You may be able to keep track of everything if you are writing a 
single small script, but once you start on something bigger globals 
and soft references will surely bite you. 

You say the code will instantly break if some
doofus changes the names of the variables, yes that's quite 
possible. And the doofus may easily be you two months later, after 
you've forgotten the details of the implementation of this stuff.

Jenda


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


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




Wanted: Help understanding files, file handles and typeglobs

2004-10-10 Thread Siegfried Heintze
I'm looking at the camel book again and feeling confused. This seems to
happen whenever I look at the camel book. The camel book (3rd edition) page
78 says:

 

Perl uses an special type called a typeglob to hold an entire symbol table
entry.

 

A. OK, if  Larry says so. I don't understand why I would ever want a
typeglob.

 

It continues.

One of the uses of typelgobs, (or references thereto) is for passing or
storing filehandles. If you want to store a file handle, do it this way: 

 

$fh = *STDOUT;

 

I'm lost!

 

What does the * mean? I guess the * syntax is intended to suggest wild
card hinting that $fh contains { SCALAR=$STDOUT, HASH=%STDOUT,
ARRAY=@STDOUT}? Correct?  

 

Continuing with the camel book on the top of page 79:

 

Sub newopen {

 my $path = shift;

 local *FH;

.

Why local and not my here?

Just what exactly is FH now? Is it an array that contains six empty values,
one for each: $FH, @FH, %FH and FH?

. continuing

 

   open(FH, $path) or return undef;

 

So FH is a file handle. Are file handles the only type of value is that is
not preceded by a  or $ or % or @? But FH was declared with a *.
What is the rule for knowing when to use a * and when not to use a *?

 

}

$fh = newopen('/etc/password');

 

. 

So now I skip to page 296 and  try the following experiment:

perl -e ' package pkg; $x = abc; @x=(1,3,3); %x=(a=b,c=d); print
${*pkg::x{SCALAR}}.\n.join(,, keys %{*pkg::x{HASH}}).\n.
join(,,@{*pkg::x{ARRAY}}).\n ;'

 

It works! Ah hah! Now I understand typeglobs.

 

perl -e ' local *x; $x = abc; @x=(1,3,3); %x=(a=b,c=d); print
${*x{SCALAR}}.\n.join(,, keys %{*x{HASH}}).\n.
join(,,@{*x{ARRAY}}).\n ;'

 

This works too! 

 

Now Larry (or Tom, or John) says

This syntax is primarily used to get at the internal file handle or
directory handle reference, because the other internal references are
already accessible in other ways.

 

Ah hah! Here is the root of my confusion: Why, when inventing the perl
language, did Larry define a special punctuation character for each type
(scalar, array, hash) except IO? 

 

That is s confusing! So the real reason to use typeglobs is because
there is no special punctuation character for *x{IO}. That is so
inconsistent! Why is there no special prefix character for file handles like
there is for hashes, arrays and scalars?

 

Thanks,

  Siegfried



Variable scope in wanted function

2004-10-10 Thread Ron Goral
Greetings All -

I am having some difficulty with a module that is using File::Find.  The
method is below.

The idea is to enter this method feeding it a file name and beginning
directory and then looking for all occasions of $file_name and push those
addresses into @a_files.  This works fine until I need to use FindPath again
during the same session.  What I'm finding is that while @a_files looses
scope within FindPath itself, it does not in ProcessFile.  In other words,
when I exit FindPath and come back into it later, @a_files is an uninitiated
array.  However when ProcessFile is called, @a_files has retained the values
it had from the last call to FindPath.

Am I making sense?


sub FindPath
{
#- Var Declaration And Initialization
my ($hr_self, $file_name, $file_path) = @_;
# Array to fill with file paths
my @a_files = ();

# Search file_path for the file
find(\ProcessFile, $file_path);

#- The Subroutine To Process Files And Directories
sub ProcessFile
{if ($_ eq $file_name){push (@a_files, $File::Find::name);}}

# Return the paths found
return @a_files;
}   # end FindPath

Peace -
Ron Goral



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




Re: Variable name substitution (probably a question on references)

2004-10-10 Thread Peter Rabbitson
 It would still IMHO be much better to do something like:
 
 %cards = (
   4 = {name = 'Visa'},
   5 = {name = 'MasterCard'},
   6 = {name = 'Discover'},
   3 = {name = 'AmEx'},
 );
 
 foreach my $cardid (keys %cards) {
   foreach my $property (@props) {
   $data{$cardid}{$property} = $form-param($cardid._.$property);
   }
 }

Now this is something I like :) As a matter of fact instead of using $data I 
can re-use $cards, so I have a single unified structure, hodling names, 
properties, totals and other things, all addressable by the primary hash key 
$cardid. I really like it :) 

Thanks

Peter





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




Re: Variable name substitution (probably a question on references)

2004-10-10 Thread Peter Rabbitson
 Since you
 
 1) are not very convincing in explaining why it would be necessary to
 use soft references, and
 
 2) argue against enabling strictures, and with that make Perl help you
 get your code right,
 
 you'll find that few people here are inclined to help you.
 
 (You can always read about soft references in perldoc perlref.)
 
 -- 
 Gunnar Hjalmarsson
 Email: http://www.gunnar.cc/cgi-bin/contact.pl
 

If soft references were so evil as you claim, probably they would not be a 
part of Perl to begin with... imho of course. 

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




Re: Variable name substitution (probably a question on references)

2004-10-10 Thread Gunnar Hjalmarsson
Peter Rabbitson wrote:
Since you
1) are not very convincing in explaining why it would be
necessary to use soft references, and
2) argue against enabling strictures, and with that make Perl
help you get your code right,
you'll find that few people here are inclined to help you.
(You can always read about soft references in perldoc perlref.)
If soft references were so evil as you claim, probably they would
not be a part of Perl to begin with... imho of course.
Actually, I didn't say anything about their degree of evilness. Others
can elaborate on that much better than I would be able to.
I just said that soft references
1) are considered something that typically should be avoided,
2) can almost always be easily replaced with a solution involving a
hash, and
3) you did not show why there would be a need to use soft references
in this case.
Seems as if Jenda has convinced you now, btw.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Variable scope in wanted function

2004-10-10 Thread Gunnar Hjalmarsson
Ron Goral wrote:
I am having some difficulty with a module that is using File::Find.
The method is below.
The idea is to enter this method feeding it a file name and
beginning directory and then looking for all occasions of
$file_name and push those addresses into @a_files.  This works fine
until I need to use FindPath again during the same session.  What
I'm finding is that while @a_files looses scope within FindPath
itself, it does not in ProcessFile.  In other words, when I exit
FindPath and come back into it later, @a_files is an uninitiated 
array.  However when ProcessFile is called, @a_files has retained
the values it had from the last call to FindPath.

Am I making sense?
Yes. But you are apparently running the code without warnings enabled,
or else Perl would have indicated the reason for this problem.
sub FindPath
{
#- Var Declaration And Initialization
my ($hr_self, $file_name, $file_path) = @_;
# Array to fill with file paths
my @a_files = ();
# Search file_path for the file
find(\ProcessFile, $file_path);
#- The Subroutine To Process Files And Directories
sub ProcessFile
{if ($_ eq $file_name){push (@a_files, $File::Find::name);}}
# Return the paths found
return @a_files;
}   # end FindPath
One possible solution is to move the ProcessFile() function out from
FindPath(), so the former is no longer a nested sub:
sub ProcessFile {
my ($a_files, $file_name) = @_;
push @$a_files, $File::Find::name if $_ eq $file_name;
}
and call ProcessFile() from FindPath() with arguments:
find( \ProcessFile( [EMAIL PROTECTED], $file_name ), $file_path );
And last but not least:
use warnings;
;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
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 add comma for thousands seperators for Currency types?

2004-10-10 Thread Siegfried Heintze
I'm reading some currency values from a database and I need to display them
in a vertical column using an HTML table. These values need a leading $.
They also need a comma for the thousands separator. So what is the
business/accounting convention for displaying currency values in the US? I
believe 100, 23432.32 and -53.23 are display as

 

$ 100.00

$23,432.32

$ (53.23)

 

 

I'm not sure if the $ goes outside or inside the parentheses.

 

Anyway, is there an elegant and slick way to do this in perl? Perhaps there
is a special package on CPAN to do this?

 

I'm wondering if you could do something like this:

 

perl -e ' $v = 100.23; $v =~ s/([0-9][0-9][0-9])([0-9])/\1,\2/g; print
$v\n; '

 

This does not quite work, however, because the commas are added starting
from the left, not the right. Is there a way to start matching from the
right instead of the left?

 

  Thanks,

Siegfried

 



Re: How to add comma for thousands seperators for Currency types?

2004-10-10 Thread Chris Devers
On Sun, 10 Oct 2004, Siegfried Heintze wrote:

 So what is the business/accounting convention for displaying currency 
 values in the US? I believe 100, 23432.32 and -53.23 are display as
 
 $ 100.00
 
 $23,432.32
 
 $ (53.23)
 
 I'm not sure if the $ goes outside or inside the parentheses.
 
Outside, I think, but I'm not an accountant or bookkeeper...
 
 Anyway, is there an elegant and slick way to do this in perl? Perhaps 
 there is a special package on CPAN to do this?

Do you have the _Perl Cookbook_? Recipe 2.17 goes over this, at least in 
part:

sub commify {
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}
 
This may have to be extended for what you're doing, but it's a good 
start. The big insight here is that it's easier to do this on a reversed 
version of the number, then flip it back around once you're done. 
 

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




Re: Map out a directory heirarchy

2004-10-10 Thread Harry Putnam
Harry wrote:
 This new coding although easier to look at and probably more
 efficient, isn't really any faster or at least not appreciably.  It
 still goes to each and every numbered file.

John replied:
 In most file systems the file names are not stored in any particular
 order so in order to find every file of a certain type you have to
 look at every file in a directory to determine if it is the type you
 want.

So I guess there just isn't any tricky fast way to get just the
directory names then eh?  This is on ext3 fs but about the only real
change I could make there would be to reiserfs or something and I'll
assume that wouldn't really change the problem.

 [...] snipped new code 

 Also changing the file name regex from
 /^\d+$/ to /^\d/ will cause problems in some directories where
 there may be such things as 780~ or even 123.bak

 Your original example used /^\d+/ not /^\d+$/ and /^\d/ does the
 same thing as /^\d+/.

Oh .. now I see where you got it.  Because the actual program used
/^\d+$/ for the reasons I listed.  Must have been a foible or typo
during conversion to mail message.  I might not have cut and pasted
all of it or changed the program after posting... or something.

[...]

 sub something { ... }
 find( \something, @directories );

 And

 find( sub { ... }, @directories );

 Do the same thing but the first uses a reference to a named
 subroutine and the second uses a reference to an anonymous
 subroutine.

OK, thanks for clearing that up...Is one better than the other in some
way?

 use File::Spec;
 use File::Find;

[...]

 my @top_dir = map File::Spec-rel2abs($_), splice @ARGV;
 my $file = './uniq_dir_under_news';

Is using File::Spec in this way, faster or more efficient than using
Cwd like in the original?  Or are you just showing another approach?

Thanks for that too, I hadn't run into File::Spec as yet and now have
a handy reference to its use when I need it.

Those perldoc pages are terrrible about showing enough examples.  But
mainly because I lack the expertise to understand the ones they do
give.

Well thanks for your usual patience and explanations...


-- 
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 reinvent grep with perl? (OT: Cygwin grep)

2004-10-10 Thread Harry Putnam
Bakken, Luke [EMAIL PROTECTED] writes:

 Voila. That's most likely your problem - a mismatch between line endings
 and Cygwin mount point type.

And in case you hadn't seen them before... there are at least a few
sets of unix tools for dos/windows.  Cygwin maybe the best known but
I've used Uwin myself for sometime  and never had a problem with its
grep.

http://www.research.att.com/sw/tools/uwin/


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




Can do in 1 while loop?

2004-10-10 Thread loan tran
Hello Perl Gurus,

I wrote a script to search for log suspends and
bloking processes in a text file and send me email if
it find either of them. My codes below work but it's
not efficent. As you can see I open the file and go to
while loop twice. Can someone suggest a better way?
Thanks.
(attached is the text file i open to search.)
Below is my codes:

#!/bin/perl -w
require /home/sybase/tranl/pl/global.pl;

## Search for blocking process

open (FILE,$whodo_out) or die (Cannot open file:
$!);
while (my $line =FILE){
chomp($line);
$line =~ s/^\s+//;
next if ($line =~ /^\D/);
my $blk = substr($line,40,3);
print  $blk \n;
if ($blk != 0){
print 'Alert! Blocking processes';
system(/usr/bin/mailx -s 'Alert Blocking
Process' $receipients  $whodo_out);
}
print \n $suspend \n;
#exit ;
}#end while

close (FILE);

# Search for LOG SUSPEND process

open (FILE,$whodo_out) or die (Cannot open file:
$!);
while (my $line =FILE){
chomp($line);
$line =~ s/^\s+//;
next if ($line =~ /^\D/);
my $log_suspend = substr($line,70,11);
print  $log_suspend \n;
if ($log_suspend eq 'LOG SUSPEND'){
print 'Alert! LOG SUSPEND processes';
system(/usr/bin/mailx -s 'Alert LOG SUSPEND
Process' $receipients  $whodo_out);
}

}#end while

close FILE;

##



__
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 
 spid   status   loginame hostname   blk  program  dbname  cmd 
 cpuio   
 --   --   --- 
 --  
  2 sleeping NULL0 master  NETWORK 
HANDLER  0  0
  3 sleeping NULL0 master  DEADLOCK 
TUNE0  0
  4 sleeping NULL0 master  MIRROR 
HANDLER   0  0
  5 sleeping NULL0astc master  ASTC HANDLER 0
  0
  6 sleeping NULL0 master  CHECKPOINT 
SLEEP 0  1502134  
  7 sleeping NULL0 master  HOUSEKEEPER 
 0  886596   
  8 sleeping NULL18master  NETWORK 
HANDLER  0  0
 13 sleeping loader  0 Mills   INSERT  
 2031   9872 
 16 recv sleep   sa   ASDECS04   0Rapid SQLMills   AWAITING 
COMMAND 1  0
 18 running  sa   titania.ab 0isql Mills   SELECT  
 2180
 21 sleeping loader  0 Mills   LOG SUSPEND 
 1930   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 reinvent grep with perl? (OT: Cygwin grep)

2004-10-10 Thread Bakken, Luke
  Voila. That's most likely your problem - a mismatch between 
 line endings
  and Cygwin mount point type.
 
 And in case you hadn't seen them before... there are at least a few
 sets of unix tools for dos/windows.  Cygwin maybe the best known but
 I've used Uwin myself for sometime  and never had a problem with its
 grep.
 
 http://www.research.att.com/sw/tools/uwin/

And another suggestion:

http://gnuwin32.sourceforge.net

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




Receve and forward email

2004-10-10 Thread marcos . rebelo
Hi all

This is my first question.

One part of my job is to read one e-mail from Pop3 and do a forward of that
e-mail with SMTP to +- 1000 users, just changing the from and the to.

There is something that can eseally do this?
How to do this?

Probably there is some modules that can do this work ease, but where to start?

thanks
Marcos







O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt

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