Re: Scalar References - oxymoron?

2017-04-04 Thread Peter Scott
On Mon, 03 Apr 2017 15:52:59 -0700, SSC_perl wrote:

> Reading http://perldoc.perl.org/perlreftut.html I see it’s possible to
> create a scalar reference.  What situation would require someone to
> create a reference to a scalar?  I thought refs were only useful for
> passing complex data structures.  Is it just because Perl lets you, or
> is there a reason I’m not aware of?  It seems like it would just be
> redundant.

They can make handy objects, whivh have to be references, but if you're 
making an inside-out object which doesn't contain its own attributes, you 
want something light and immutable.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=9780133036268

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: grep - block with start & end text

2016-03-19 Thread Scott Hall
Thanks Andrew.

Your article explained what I did not have the words for.  It was very well
written.

Scott

On Fri, Mar 18, 2016 at 1:23 PM Andrew Solomon  wrote:

> And to understand Scott's easy to write, hard to understand approach:
>
> http://blog.geekuni.com/2016/03/perl-flip-flop.html
>
> Andrew
>
> On Fri, Mar 18, 2016 at 3:50 PM, Scott Hall  wrote:
>
>>
>>
>> On Fri, Mar 18, 2016 at 9:40 AM Prashant Thorat <
>> thorat.prash...@gmail.com> wrote:
>>
>>> Hi All,
>>>
>>> Can you please help me to grep below 'block of text' from my file ? this
>>> blocks occurs number of time & I want to grep all in between lines of this
>>> block -
>>>
>>> first line is having - retr_test asm1
>>> & 4th line is having only - END
>>>
>>> so I want to grep all four lines with above match .
>>>
>>>
>> If you are looking for a command line that works like grep:
>>
>> perl -lne 'print if /retr_test asm1/ .. /END/;' input_file
>>
>> http://perldoc.perl.org/perlop.html#Range-Operators
>>
>> Best Regards,
>>
>> Scott
>>
>>
>>> Thanks in advance,
>>> Prashant
>>>
>>>
>>>
>
>
> --
> Andrew Solomon
>
> Mentor@Geekuni http://geekuni.com/
> http://www.linkedin.com/in/asolomon
>


Re: grep - block with start & end text

2016-03-18 Thread Scott Hall
On Fri, Mar 18, 2016 at 9:40 AM Prashant Thorat 
wrote:

> Hi All,
>
> Can you please help me to grep below 'block of text' from my file ? this
> blocks occurs number of time & I want to grep all in between lines of this
> block -
>
> first line is having - retr_test asm1
> & 4th line is having only - END
>
> so I want to grep all four lines with above match .
>
>
If you are looking for a command line that works like grep:

perl -lne 'print if /retr_test asm1/ .. /END/;' input_file

http://perldoc.perl.org/perlop.html#Range-Operators

Best Regards,

Scott


> Thanks in advance,
> Prashant
>
>
>


Re: Forking as another user

2016-03-13 Thread Peter Scott
On Sat, 12 Mar 2016 18:44:18 +0200, Lars Noodén wrote:
> The snippet below works to fork as a specific user, if run as root.
> However, it generates zombies.  The functions wait() or waitpid() seem
> to be available to use to stop that, but if I insert either of them in
> the outer while loop, only one client can connect at a time.
> 
> What modification can prevent zombies yet allow multiple concurrent
> clients to attach?

You need the WNOHANG option on your wait() to make it nonblocking.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=9780133036268

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Operand evaluation order

2014-03-17 Thread Peter Scott
On Fri, 14 Mar 2014 13:03:58 -0400, Ralph Grove wrote:
> I'm trying to determine how Perl evaluates operands for expressions. I
> expected the following code to output 3, 4, and 5, as it would if
> executed as a C++ or Java program. The actual output that I get
> (v5.16.2), however, is 4, 4, and 5. This leads me to believe that
> operand evaluation is either non-deterministic and compiler-dependent,
> or it's simply broken.

Kudos for the curiosity.  Did you have any other reason for wanting to 
know how this worked in Perl?

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.oreillyschool.com/certificates/perl-programming.php
http://www.informit.com/store/product.aspx?isbn=9780133036268

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: question about perl 6 sigils

2013-09-29 Thread Peter Scott
On Tue, 24 Sep 2013 18:48:40 +0200, Luca Ferrari wrote:
> I read both the book and the exegenis, it is only that it requires me to
> think about the correct usage of sigils because it is not as much
> intuitive for me as it is in v5.
> I was just trying to explain to my brain why having immutable sigils is
> smarter than the v5 ones. I know Perl is built in a way everything has a
> strong sense, I cannot see what is in this case.

When you learn a language - Perl 5 in this case - its syntax becomes 
'intuitive'.  From then on, any deviation from it is unintuitive.  It 
takes a special kind of genius to be both familiar with that language and 
step outside of it to determine what will be more intuitive to someone 
who has not encountered the language at all yet, and that's what we have 
in Larry and Damian.

In my classes, people invariably wanted to put @ on the beginning of an 
array element to begin with.  After enough correction, they learned to 
use $, and adopted the rationalization for it.  But most people's first 
instinct is @.  That's why the Llama book doesn't introduce the @ sign 
for arrays until after its shown the use of $ for scalar elements.  
Damian and Larry determined that they could remove this small speed bump 
without any damage to the language.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.oreillyschool.com/certificates/perl-programming.php
http://www.informit.com/store/product.aspx?isbn=9780133036268


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Who instantiated an object

2013-05-31 Thread Peter Scott
On Fri, 31 May 2013 13:13:29 +, Weidner, Ron wrote:
>my ( $proto, $common, $name, $options ) = @_; 
>my $class = ref($proto) || $proto;

That is a common bit of cargo-culting that you might want to rethink.  I 
know it's posted all over the place but it's generally considered a bad 
practice now.  See 
http://search.cpan.org/~petdance/Perl-Critic-Bangs-1.08/lib/Perl/Critic/
Policy/Bangs/ProhibitRefProtoOrProto.pm  and near the end of http://
www.stonehenge.com/merlyn/UnixReview/col52.html.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.oreillyschool.com/certificates/perl-programming.php
http://www.informit.com/store/product.aspx?isbn=9780133036268
http://www.oscon.com/oscon2013/public/schedule/detail/28923

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: hash issue

2013-04-19 Thread Peter Scott
On Wed, 17 Apr 2013 11:47:49 -0700, Jim Gibson wrote:
> 1. You should not modify a hash while you are iterating through it with
> the each() function. The each() function uses an internal data structure
> that persists from one call of each to the next. That internal data
> structure can be modified if you add or delete elements (as you are
> doing). 

So the documentation has warned.  Yet it should probably be updated, since 
that behavior has been demonstrated to be safe: https://groups.google.com/
forum/?hl=en&fromgroups#!topic/comp.lang.perl.misc/53Lfj8IM0JQ and there 
is specific code in the internals to make it safe: https://
groups.google.com/forum/?hl=en&fromgroups=#!topic/comp.lang.perl.moderated/
_J9aO8pdAVc

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Proposed correction for my long script

2012-09-16 Thread Peter Scott
On Sun, 16 Sep 2012 12:46:08 -0700, jmrhide-perl wrote:
> Does it look OK?

This is a prime example of something that a test harness would be very 
useful for, then we'd all know the answer.

There may be some entirely different reason why your provider thinks this 
script is consuming excessive resources.  They may be wrong.  Having some 
idea of how long it takes to execute would be good:

END {
  my $elapsed = time - $^T;
  send_mail "We took $elapsed seconds to run at " . localtime . "!"
if $elapsed > $MAX_PERMISSIBLE_RUN_TIME;
}

If all else fails, install your own timeout:

alarm $MAX_PERMISSIBLE_RUN_TIME;
$SIG{ALRM} = sub { die "Exceeded $MAX_PERMISSIBLE_RUN_TIME timeout" };

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: My script is OUT OF CONTROL!

2012-09-13 Thread Peter Scott
Set up some test harnesses to run from the command line so you can see 
how your script behaves without having to run it through a web server.  
Since it gets its input from a cookie, set the environment variable 
HTTP_COOKIE to each test value in turn and execute the script.  (You'll 
get a mess of HTML back that'll be tedious to validate.  This is the 
point at which you learn about separation of responsibilities and the 
Model-View-Controller pattern if you want to improve how you do this in 
the future.)

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Using different libraries dynamically

2012-09-12 Thread Peter Scott
On Wed, 12 Sep 2012 10:18:49 -0400, Mark Haney wrote:

> I've got what I hope is an easy question to answer.  I've got a perl web
> app that I've setup with a 'live' version (more like a beta actually)
> and a dev version for me to make changes to that might break the other
> site.
> 
> The way I inherited it was as a single site using 'use lib' with the
> library files to a working site being used as the dev version.  I've
> moved the files around to match the first paragraph setup.  Two
> different sets of files, one live the other development.
> 
> For the time being I've manually change the 'use lib' statement before
> uploading the changed/fixed code to the live site, but this is getting a
> bit silly, not to mention completely not standard practice.
> 
> My question is, what IS standard practice for this?  Honestly, I've
> never built a web app in this manner despite writing a lot of perl code.
>   So?  What should I do?  Any suggestions are appreciated.

If the dev site and live site are on different filesystems and each 
doesn't share the other's path, then just put both directories in the use 
lib argument.  That's a bit fragile, though, because one day they might 
both exist on the same system.

What I do is have a module that figures out whether I'm in dev or prod; I 
use it before the use lib and get a value back that I can use to switch 
which path to fetch.  Something like (pseudo code, untested):

use MyEnv;  # Sets $MyEnv::Env_Type
BEGIN {
  require lib;
  lib->import( $MyEnv::Env eq 'dev' ? '/path/to/dev' : '/path/to/prod' );
}

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parsing multiple logins logs (create a unique hash name for every user)

2012-09-10 Thread Peter Scott
On Mon, 10 Sep 2012 20:52:41 +0800, andrew sison wrote:
> I don't get how you can actually print the contents of the subhash.

Generic hash-of-hashes iteration example:

for my $outer_key ( keys %hash )
{
  print "Outer key: $outer_key:\n";
  for my $inner_key ( sort keys %{ $hash{$outer_key} } )
  {
print "\t$inner_key: $hash{$outer_key}{$inner_key}\n";
  }
}

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Code

2012-08-31 Thread Peter Scott
On Sat, 01 Sep 2012 04:05:31 +, Peter Scott wrote:

> On 2012-08-29, at 12:46 PM, Ashwin Rao T  wrote:
>> 1)Check if IP address is in the range 172.125.1.0 and 172.125.25.0
>> using only return functions & regular expressions in Perl.
> 
> /\b172\.125\.(\d+)\.((?>\d+))(??{(1<=$1 && $1<=24 && 0<=$2 && $2<=255)||
> ($1==25 && $2==0) ? "" : "(*FAIL)"})/ and say "Strictly correct answer
> that shows instructor didn't think about the question"
> 
> Do let us know what grade that gets you :-)

Forgot the /a...

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Code

2012-08-31 Thread Peter Scott
On 2012-08-29, at 12:46 PM, Ashwin Rao T  wrote:
> 1)Check if IP address is in the range 172.125.1.0 and 172.125.25.0
> using only return functions & regular expressions in Perl.

/\b172\.125\.(\d+)\.((?>\d+))(??{(1<=$1 && $1<=24 && 0<=$2 && $2<=255)||
($1==25 && $2==0) ? "" : "(*FAIL)"})/ and say "Strictly correct answer 
that shows instructor didn't think about the question"

Do let us know what grade that gets you :-)

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Unblessed reference problem

2012-05-20 Thread Peter Scott
On Sun, 20 May 2012 18:28:10 +0300, Shlomi Fish wrote:
> Note that I think I saw a way to return the flattened array in Moose,
> but I don't remember the specifics.

auto_deref => 1

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How Can I find all kinds of methods a Object support?

2012-04-12 Thread Peter Scott
On Wed, 11 Apr 2012 16:12:22 +0800, Zapp wrote:
> How Can I find all kinds of methods a Object support? For example:
> 
> my $fh = IO::File->new("/path/to/file");
> 
> how manny kinds of methods does the $fh have ?
> 
> I try perldoc IO::File , but didn't find what I want.

I suspect that what you want is documentation, because a literal answer 
to your question will only give a list of method names, which is rarely 
useful (I've used it on occasion for very specialized classes where that 
list constituted metadata of a sort.)

As Lesley said, if you don't find the methods you're looking for in the 
class itself, try superclasses.  This is one case where the structured 
nature of documentation in more rigid languages has an edge over Perl.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Using the ternary operator to concat a string not working like I think?

2012-04-07 Thread Peter Scott
On Wed, 04 Apr 2012 03:04:42 -0400, Uri Guttman wrote:
> On 04/03/2012 06:55 PM, timothy adigun wrote:
> that is the wrong way to fix this even if it works.
> 
> the ternary operator is meant to return a single value from a choice of
> two expressions. it is not meant for side effects like assignment or sub
> calls that do things. use if/else for that. the correct answer here is
> to use if/else as the assignments go to different places.
> 
> if( $test{one} eq 'first' ) {
>   $test{one} .= " is the worst\n" ;
> else {
>   $test{two} .= " is the best\n";
> }
> 
> that code is not a good use of ?: at all so use if/else.

Right.  And if you want the single statement succinctness, use and/or:

% perl -le '%test = qw(one first two second); $test{one} eq "first" and 
$test{one} .= " is the worst" or $test{two} .= " is the best"; print for 
values %test'
first is the worst
second

% perl -le '%test = qw(one third two second); $test{one} eq "first" and 
$test{one} .= " is the worst" or $test{two} .= " is the best"; print for 
values %test'
third
second is the best


-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Why do I get a warning?

2012-03-25 Thread Peter Scott
On Thu, 22 Mar 2012 20:06:35 -0400, Uri Guttman wrote:
>  no one uses braces for single scalar handles in general.

I do.  Ever since Damian recommended it (Perl Best Practices, page 217).  
One of those numerous times I didn't agree with him until I tried it, 
then found he was right.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Transitioning from BASH to Perl

2012-03-18 Thread Peter Scott
On Sat, 17 Mar 2012 02:43:02 +0530, Deepak Malhotra wrote:
> You might have got similar questions in past too but could I request to
> demystify it again on how to swiftly and quickly make transition to Perl
> from Bash. Although I am no expert of Bash and awk but I can do the
> stuff which suffice my needs.
> 
> What I am really looking for is the text processing  (grep , awk, tr),
> conditional statements and control structures, to automate my work and
> create scripts (Garbage-in Garbage-out types)
> 
> Please guide on how to learn minimal perl quickly. Any tutorials/books
> which deals with this kind of approach?

Tim Maher's "Minimal Perl" was designed for your kind of requirement: 
http://www.amazon.com/Minimal-Perl-UNIX-Linux-People/dp/1932394508 .

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: run command from perl

2012-03-03 Thread Peter Scott
On Fri, 02 Mar 2012 21:31:50 +0100, Manfred Lotz wrote:
> Another question I have: Where do I find what '-|' means? I mean the
> minus before the pipe char.

perldoc -f open


-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: run command from perl

2012-03-01 Thread Peter Scott
On Sun, 26 Feb 2012 20:30:56 +0100, Manfred Lotz wrote:
> I want to run a shell command with the following constraints:
> 
> a. I like to get the return code of the command b. Furthermore I want to
> combine stdout and stderr so that the output comes in a natural sequence
> like in the shell. c. I don't want to capture the output in a variable
> (because the output could be really large and I don't want to wait for
> the first line of output)
> 
> I did this:
> 
> use IPC::Open3;
> 
> sub run_cmd {
>   my $cmd = shift @_;
> 
>   my $pid = open3(undef, *CMD_OUT, *CMD_OUT,$cmd);
> 
>   while ( ) { print "$_"; }
>   waitpid($pid,0);
>   my $rc = $? >>8;
>   return $rc;
> }
> 
> 
> I tested the code and it I can say it worked fine under fair weather
> conditions.
> 
> Question: Is the code ok, or could it be improved, or has it even flaws?

It doesn't have flaws.  You could do it without the module with a piped 
open:

sub run_cmd
{
  my $cmd = shift;

  open my $fh, '-|', "$cmd 2>&1" or die "open: $!";
  print while <$fh>;
  close $fh;
  return $? >> 8;
}

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to compile just the current perl module, ignoring all the other included modules

2012-01-25 Thread Peter Scott
On Mon, 23 Jan 2012 12:38:44 -0500, Nemana, Satya wrote:
> 
> I tried perl -c also with the same results. It takes 4-5 minutes to know
> that I missed a " some where. It is very painful.

4-5 minutes?!  Either you have an unbearably slow computer or something 
is not right.  Please post details.  It sounds like some module is doing 
ridiculous computations in its main code instead of being encapsulated in 
subroutines.  It should be tracked down and shot^Wrefactored.  That's 
likely to cause all kinds of problems, so working around it like you're 
trying isn't really the answer.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Difference between <> and grep EXPR, <>

2012-01-19 Thread Peter Scott
On Fri, 20 Jan 2012 10:08:31 +0600, Andrey P wrote:
> I don't understand why I need to use a list assignment for
> 
>   say  scalar(()=<$fh>);
> 
> but not for
> 
>   say  scalar(grep /./, <$fh>);
> 
> From perlop:
> 
> If a  is used in a context that is looking for a list, *a
> list* comprising all input lines *is returned*, one line per list
> element.
> 
> From perlfunc:
> 
> grep EXPR, LIST
> 
> Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_
> to each element) and *returns the list value*...

Because grep is defined to return the number of elements in scalar 
context.  Keep reading perldoc -f grep one more sentence:

 In scalar context, returns the number of times the expression was true.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex : Extract data between { } spanning in multplie lines

2011-12-26 Thread Peter Scott
On Fri, 23 Dec 2011 01:56:40 -0800, iand wrote:
> Ex file.txt:
> A1 {@ a d e \n a b c}
> A2 {@ 1 {2 3} \n a b c \n d e f}
> 
> I need to extract these separately :
> {@ a d e a b c }
> {@ 1 {2 3} \n a b c \n d e f}
> 
> perl -lne 'print $1 if '~/^[A-Z0-9]+\s\{.*$/m' file.txt I can extract
> data by grouping after \{ in regex but how to span over multiple lines
> and make this work. Need pointers.

May I suggest http://search.cpan.org/dist/Text-Balanced/ for this type of 
endeavor.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: FW: Perl to python converter

2011-12-26 Thread Peter Scott
On Fri, 23 Dec 2011 17:38:35 +, fudmer rieley 
 wrote:

> I would love to work on this type of project, but I am a beginning perl
> programmer.

You'll find more assistance outside of a beginning Perl group.  If you 
want to pursue this, your best bet is to pair up with an experienced Perl 
programmer that you find on somewhere like Perlmonks, and advertise that 
you have XML/XSLT experience to bring to the party.  On this list, your 
options are more or less limited to asking how you can become a better 
Perl programmer.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: ipc question

2011-12-15 Thread Peter Scott
On Wed, 14 Dec 2011 20:42:10 -0300, Tessio Fechine wrote:
> I have a cgi application that has a two way communication with a ldap
> application via open2:
> 
> I need to keep communicating with the same ldap.pl process as other cgi
> scripts are launched:

Sounds like you want a named pipe.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: File health check on *nix system using stat

2011-12-12 Thread Peter Scott
On Sun, 11 Dec 2011 10:40:24 -0400, frank cui wrote:
> Ok, to make this question more specific, the author of this book is
> making a program to check if the files can be read off from the disk.
> And he does so by checking two steps, first is making sure the meta data
> of this file looks fine, and secondly by reading byte by byte from this
> file to actually check the file's content readability.

As a "toy" example demonstrating the use of filetest operators and sysread
(), this is okay.  It's hard to come up with decent short examples.  Just 
as long as you don't come away thinking that this is really how you would 
test to see if you could read a file.  I see people using access checks 
all the time when they should simply be testing that they can open() the 
file instead.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: File health check on *nix system using stat

2011-12-10 Thread Peter Scott
On Sat, 10 Dec 2011 11:11:15 -0400, frank cui wrote:
> # attempt to read the directory entry for this file my @stat =
> stat($name);
> if ( !$stat[4] && !$stat[5] && !$stat[6] && !$stat[7] && !$stat[8] ) {
> return 0;# according to the code context, here
> it is saying the file is NOT ok

What is the program trying to accomplish?  What does "ok" mean for a file 
in the context of this exercise?  The empirical derivation from the code 
doesn't seem useful.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Simulate `sh -x'

2011-12-03 Thread Peter Scott
On Jun 24 2002, 4:44 am, davidtg-perl-beginn...@justpickone.org (David T-
G) wrote:
> ...and then Peter Scott said...
> % >% Would you like tracing that goes off when you go into a function? 
Suppose
> % >% if you gave a numeric argument to 't' it would trace up to that 
depth
> % >% in subroutine calls beneath the current level but not beneath? That
> % >% might be doable (as a patch to the debugger).
> % >
> % >Hmmm...  That's a pretty attractive idea, actually.
> %
> % I'll see if I can whack it out.  'Course, it won't show up in an 
actual
> % release until 5.8.1, since 5.8.0 is on the verge of release.

No, that's not a typo, I really am following up a thread from 2002.  I 
finally got around to implementing this patch.  If I'd known how easy it 
was going to be I'd have done it earlier.  Okay, so I'm a bit slow :-)

It's in the blead version of perl and will be in subsequent releases.  
Enjoy.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Make a script to run multiple scripts

2011-12-03 Thread Peter Scott
On Thu, 01 Dec 2011 12:38:56 -0500, Ryan.Barracuda wrote:
> I have 7 perl scripts that I want to run simultaneously from the command
> line with the possibility of growing this number. I'm pretty new to
> perl, so thought in the mean time it would be a good idea to create a
> perl script to run multiple scripts. I could just add to this file as
> needed if more scripts are created. What is the best way to do this?

Consider spawning code rather than programs and using 
Parallel::ForkManager:

http://search.cpan.org/~dlux/Parallel-ForkManager-0.7.9/lib/Parallel/
ForkManager.pm

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: passing arguments to perl function with - in the string

2011-11-29 Thread Peter Scott
On Tue, 29 Nov 2011 18:19:59 -0500, Nemana, Satya wrote:
> P.S : unfortunately, I cant provide more details due to the IP
> restrictions, sorry about that, hope you understand, otherwise would
> have posted the code in the first go.

This is a common constraint.  You can always post a version of the code 
that exhibits the same problem but has been cleansed of all IP 
restrictions.  I and many others have had to do exactly this.  It has the 
advantage that in the process you are likely to catch any simple errors 
and thus solve your problem faster and without the need for external help.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl module for Gmail

2011-11-29 Thread Peter Scott
On Sun, 20 Nov 2011 12:27:31 -0800, samjesse wrote:
> I need a Perl script which will connect to my gmail and download the
> unread emails from a certain folder. But not all the unread emails, only
> those with a certain subjects and from a certain sender. after that mark
> them as read and leave them on the server.
> 
> those emails must be stored "appended" in a file on the local hard
> drive.

I do this with Net::IMAP::Client.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Fwd: RE: overriding a custom compiled perl binary

2011-11-16 Thread Peter Scott
On Wed, 16 Nov 2011 02:25:18 -0500, shawn wilson wrote:
> Yes, it was 5.6.1. I wish I had the perl source code to compile. That
> would be the simplest solution. The perl binaries where provided by a
> vendor and the product only works with the customized version of perl
> they compiled for us. The vendor doesn’t exist any more.

You have a bigger problem in that you are living on borrowed time with a  
10 year-old version of perl that even if it were not custom, is no longer 
supported. At any moment something could cause this to stop working. You 
can't just freeze your whole environment, as evidenced by the fact that 
you are trying to make a change to @INC already.

Tell us more about what you mean by "only works with the customized 
version of perl" as in, what "not working" looks like.

Activestate used to distribute perl binaries that had @INC compiled in as 
long placeholder strings that their installation tool then modified for 
the local installation.  So theoretically you could edit the binary to 
replace the paths with anything the same length or shorter.  As if you 
weren't out on a long enough limb already.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Taint mode CGI problem

2011-11-11 Thread Peter Scott
On Fri, 11 Nov 2011 19:08:18 -0300, Tessio Fechine wrote:
> #!/usr/bin/perl -T -w
> 
> use strict;
> use CGI;
> 
> $ENV{PATH} = '/var/www/cgi-bin/';
> my $exec = 'search.pl';
> 
> 
> my $c = CGI->new();
> print $c->header(), $c->start_html(-title => "It's alive!\n"), "\n";
> 
> my $search = $c->param('search') || 'nobody'; !system $exec, "(cn=".
> $search ." *)" or die "$exec: $!\n";
> 
> print $c->end_html(), "\n";
> ---//---
> 
> When I run it from command line (./crap.pl), it works just fine. But
> when I try to run it from apache, as a CGI script, I get this error in
> error_log:
> 
> "Insecure dependency in system while running with -T switch at
> /var/www/cgi-bin/crap.pl line 14., referer: http://frodo/crap.html";

perldoc perlsec.  You haven't untainted $search.

Consider embedding the LDAP search functionality in your CGI, or better 
yet, abstracting it to a common module used by both search.pl and your, 
er, crap.pl.  Code duplication is so enervating.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: bootstrap.pl for setting up my machine

2011-11-01 Thread Peter Scott
On Sat, 29 Oct 2011 23:24:10 +0200, Sime Ramov wrote:

> * Shlomi Fish  [2011-10-29T19:03+0200]:
>> Since you're not interested in the output of the pkg_add command, you
>> should do:
>>
>> system("pkg_add", $_);
> 
> Actually, I am. I want to be able to interface with the program. E.g. if
> there are multiple flavors for some package, `pkg_add` might prompt me
> which one to install.

system() will still let *you* interface with pkg_add.  Do you want your 
program to be able to interface with pkg_add instead?

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help with Getopt::Std

2011-10-22 Thread Peter Scott
On Sat, 22 Oct 2011 11:58:38 +1300, newbie01 perl wrote:
> Am just trying to port 1:1. Quite painful trying to figure out how to
> get awk-like behavior in Perl especially when trying to do some
> calculation on some specific fields.

Awk is Perl's closest ancestor on the evolutionary tree, from one point 
of view anyway.  There's even a program a2p that comes with perl (http://
perldoc.perl.org/a2p.html) for making transitioning automatic, if not 
easier.  Post what you're having trouble with here and we can help.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Updating Perl without admin

2011-10-13 Thread Peter Scott
On Wed, 12 Oct 2011 20:18:20 -0500, Chris Stinemetz wrote:
> To use perlbrew, it is required to install curl or wget first. perlbrew
> depends on one of this two external commmands to be there in order to
> fetch files from the internet.
> 
> My unix OS doesn't have curl or wget. Is there a work around?

Install one or both to a directory you can write to and put it in your 
path.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to put an AND in a regex?

2011-10-13 Thread Peter Scott
On Thu, 13 Oct 2011 10:33:17 +, Hamann, T.D. (Thomas) wrote:
> I am trying to write a regex that should only match when certain
> patterns are not present, e.g. when a line does not start with either a
> digit or ALL-CAPS text. I figured I could use negative look-aheads for
> this.
> 
> I can write it as:
> 
> if (/^(?![[:upper:]][[:upper:]])/) {
> if (/^(?!\d)/) {
> s/^//;
> }
> else {
> }
> }
> else {
> }
> 
> However, I was wondering whether there was a way of writing this as a
> single if loop, because there are much more than two situations that
> should not be matched.
> 
> I tried to write it as:
> 
> if (/^(?![[:upper:]][[:upper:]])|^(?!\d)/) { s/^//;
> }
> else {
> }
> 
> but this means if one option is not matched the other one is matched,
> which is not what I want. So I need something that does the equivalent
> of "Don't match this AND don't match this". Is this possible in a if
> loop, or should I use something else?

Am I missing something about why this approach won't work for you:

  if ( ! /\A[[:upper:]][[:upper:]]/ && ! /\A[[:digit:]]/ ) 

Seems easier to understand.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to get the multiselect select box or checkbox element values WITHOUT using CGI module

2011-10-01 Thread Peter Scott
On Sat, 01 Oct 2011 01:00:47 -0700, Rajeev Prasad wrote:
> I thought it would be overkill (RAM, CPU etc.) to use CGI.pm when all i
> need is to get values out of form-variables. but i am going to settle
> for CGI::Simple

Do you have any figures on how the trivial use of RAM/CPU by CGI.pm 
impacts your application noticeably?  Because programmer time is, in the 
absence of proof of anything else, the most precious resource, and so 
anything that takes longer than typing

use CGI;

is overkill.  Especially if it requires downloading something not in core.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: running perl script from inside another script & collecting output in array

2011-09-15 Thread Peter Scott
On Wed, 14 Sep 2011 21:07:31 -0700, Rajeev Prasad wrote: 
> thecalledscript.pl needs a filename as argument.
> 
> here is how i am calling it from a thecalling_script:
> 
> 
> 
> {
>     local @ARGV;
>     @ARGV = ("$filename");
>     require "thecalledscript.pl";
> }
> 
> issue is, the called script prints some filenames after completion to
> STDOUT. how can i collect them into an array variable?


You would be better off calling it with backticks.  Otherwise you have to 
try fragile techniques such as tying filehandles.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to calculate the uncover region

2011-09-13 Thread Peter Scott
On Tue, 13 Sep 2011 04:54:40 -0700, Lemon wrote:

> I have some segments start and end position on a reference sequence, I
> want to calculate the uncoverage region for the reference;
> 
> for example: reference sequence length= 100,
> 
> name [start,end]
> segment 1 [1,20]
> segment 2 [2,28]
> segment 3 [50,100]
> segment 4 [5,38]
> 
> so uncover region = [38,49]
> 
> 
> now I already have %pos{start}=end structure for those segment position,
> could somebody give a good method?

By the usual definition the uncovered region is [39,49].  Here's an 
approach:

$ cat differ
#!/usr/local/bin/perl
use strict;
use warnings;

use Set::IntSpan;  # http://search.cpan.org/perldoc?Set%3A%3AIntSpan

my ($diff, @sets) = map { Set::IntSpan->new( $_ ) }
qw(1-100 1-20 2-28 50-100 5-38);
$diff -= $_ for @sets;
print "$diff\n";

$ ./differ
39-49

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Accessing IMap accounts messages via Perl.

2011-09-03 Thread Peter Scott
On Sat, 03 Sep 2011 13:39:47 +0200, werner wrote:

> Am 03.09.11 13:31, schrieb Sean Murphy:
>> All.
>> 
>> How can I access my IMap messages from Google via Perll. I wish to
>> extract the message body only.
> how about Mail::IMAPClient?

Or Net::IMAP::Client...

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: unit test case for this perl code

2011-09-03 Thread Peter Scott
On Fri, 02 Sep 2011 14:16:30 +0530, anirban adhikary wrote:

> Hi I have write the following code and Now I have been asked to write a
> unit test case for this code. But neither I have  any idea how to write
> a unit test case nor I have ever experience with it. So in this case I
> am asking your help.

[Snip program that deletes old records from a database]

If someone used the words "unit test" in a request to you then they 
likely have an existing testing environment and expectations of how tests 
should behave and what scope they have.  Or is this the first unit test 
that the person asking you will have?  So find out what "unit test" means 
to them, because there are many possibilities.  Assuming they used the 
term in its usual sense, this test would be one unit out of many others, 
so what do those other tests do, what protocols do they follow, where do 
they send their results?  Without knowing those things any well-meaning 
answers you could get here would probably lead you in the wrong 
direction.  Tell us what you find out.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex negative looking up a backtrace

2011-08-26 Thread Peter Scott
On Wed, 24 Aug 2011 20:24:00 +0530, Ramprasad Prasad wrote:

> Assume I have to find the first unique character in a string
> 
> $string = "abtable";
> 
> # t is the first unique string
> 
> I tried using a negative backtrace lookup to get the answer in a single
> regex ... But something is missing.
> 
> /(.).(?!\1)/ && print $1;
> 
> it seems fine ... But doesn't work

The easier way would be with code instead of a regex:

use strict;
use warnings;
use 5.10.0;

@ARGV or @ARGV = (qw(abtable zzabtable abcabc zbbb abcdefabcdefg q qqq));

OUTER: for ( @ARGV )
{
  my @c = split //;
  my %n;
  $n{$_}++ for @c;
  for ( @c )
  {
next if $n{$_} > 1;
say;
next OUTER;
  }
  say "FAIL: $_";
}

% ./proggie
t
t
FAIL: abcabc
z
g
q
FAIL: qqq

But if you really want a regular expression to do the job:

use strict;
use warnings;
use 5.10.0;

@ARGV or @ARGV = (qw(abtable zzabtable abcabc zbbb abcdefabcdefg q qqq));

for ( @ARGV )
{
  say
  /\A   # Starts with
(.*?)   # Minimal string, possibly null, then
(.) # Candidate character
(??{# Evaluate code
 index($1,$2) >= 0  #  If first capture contains candidate
 ? '(*FAIL)'#   Assert match failure
 : '(*ACCEPT)'  #   Else success
   })   # Followed by
(?!.*\2.*)  # Chars not containing candidate
  /x ? "$1\[$2\]${^POSTMATCH}" : "FAIL: $_";
}

%proggie
ab[t]able
zzab[t]able
FAIL: abcabc
[z]bbb
abcdefabcdef[g]
[q]
FAIL: qqq

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/certificates/perl-programming.php

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to grab last element of array from split with no temporary variables?

2011-08-14 Thread Peter Scott
On Thu, 11 Aug 2011 23:30:32 -0700, John W. Krahn wrote:
> Peter Scott wrote:
>> On Thu, 11 Aug 2011 16:17:51 -0700, siegfried wrote:
>>> Is there a way to do it with less typing? How can I do it without
>>> creating a temporary variable "@p"? Thanks, siegfried
>>>
>>> find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split "/"; rename $_,
>>> "./$p[$#p].txt" } '
>>
>> Try this:
>>
>> find /xyz -type f -print0 | perl -F/ -0lane 'rename $_,"$F[-1].txt" or
>> warn $!'
> 
> That won't work as that reads the contents of the files and not the file
> names.

No, STDIN is the list of filenames; Perl's not taking that as @ARGV.  
Observe:

$ ls -lR /tmp/xxx
/tmp/xxx:
total 4
-rw-rw-r-- 1 peter peter0 Aug 14 11:04 a
drwxrwxr-x 2 peter peter 4096 Aug 14 11:04 yyy

/tmp/xxx/yyy:
total 0
-rw-rw-r-- 1 peter peter 0 Aug 14 11:04 b
$ pwd
/tmp/zzz
$ find /tmp/xxx -type f -print0 | perl -F/ -0lane 'rename $_,"$F[-1].txt" 
or warn $!'
$ ls -l
total 0
-rw-rw-r-- 1 peter peter 0 Aug 14 11:04 a.txt
-rw-rw-r-- 1 peter peter 0 Aug 14 11:04 b.txt
$ ls -lR /tmp/xxx
/tmp/xxx:
total 4
drwxrwxr-x 2 peter peter 4096 Aug 14 11:05 yyy

/tmp/xxx/yyy:
total 0

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl4/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to grab last element of array from split with no temporary variables?

2011-08-11 Thread Peter Scott
On Thu, 11 Aug 2011 16:17:51 -0700, siegfried wrote:
> This works! 

Really?  I get "find: missing argument to `-exec'"

I think your command also renames directories.  You want that?

> Is there a way to do it with less typing? How can I do it
> without creating a temporary variable "@p"? Thanks,
> siegfried
> 
> find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split "/"; rename $_,
> "./$p[$#p].txt" } '

Try this:

find /xyz -type f -print0 | perl -F/ -0lane 'rename $_,"$F[-1].txt" or 
warn $!'

That should give you a good excuse to read perlrun :-)

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl4/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Choosing between look up tables

2011-07-09 Thread Peter Scott
On Fri, 08 Jul 2011 09:53:05 -0700, Steven Surgnier wrote:

> Hi everyone,
> 
> I could use both suggestions and answers on the follow topic.  The
> problem I'm trying to solve is quite simple: I must parse through a
> large csv file.
>  A field within the csv will signify which product type the included
>  data is
> associated with.  Once the product type is known then a field within the
> same csv (a 64 byte long hex string) must be parsed out.  The hex string
> is converted to binary where each binary bit represents pass/fail for a
> particular functional test.  Each functional test is unique and the
> index of said test in the 512 bit string may differ by product type. 
> Everything described so far I'm comfortable tackling.  Now to the real
> question.  My initial direction with this problem was to have a separate
> functable.pl file with unique arrays for each lookup table (the value of
> the each array location was simply a scalar of the test name).  Then
> "use functable.pl" in the main parsing script and reference the desired
> lookup table.  If I knew every lookup table ahead of time, I would of
> course just include them in the parsing script.  However, new product
> types will always be around the corner.  So is this a reasonable
> solution or a rookie mistake?  Or should I simply have a .txt file that
> might look like the following: ###
> # begin: product1
> testA,0
> testB,8
> testC,16
> testD,32
> # end
> 
> # begin: product2
> testA,2
> testB,4
> testC,8
> testD,16
> # end
> ###
> 
> Then simply read in the .txt file and build the array from within the
> main parsing script as opposed to referencing an array in a separate
> file?

It seems as though you are talking about data rather than code; hard to 
say because you don't describe how the functional tests may vary. But if 
all the variations can be captured in data then store it as data, either 
in a single file if there's not much of it, multiple files if you want to 
partition responsibility for updating new product types, or a database if 
it's really dynamic.  Don't create reams of code that initializes arrays 
to literal lists, it's excruciating to read.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl4/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: discover all packages subclassing some other package

2011-06-11 Thread Peter Scott
On Sat, 11 Jun 2011 08:25:15 +0200, marcos rebelo wrote:

> I need to discover all the packages (not files, the symbolic tables)
> that are child of my package, something like:
> 
> my @child = map { $_->isa('My::Class') } ->ALL_PACKAGES<-
> 
> How do I create the ->ALL_PACKAGES<- list?

Class::Inspector->subclasses.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: timestamp with milisecond

2011-06-03 Thread Peter Scott
On Fri, 03 Jun 2011 19:47:53 -0400, Uri Guttman wrote:
> regardless of the need for millisecond info, use the POSIX::strftime
> function as it does all of that formatting timestamps for you. and since
> you pass it a string you can just interpolate the millisecond part into
> that string.

Like so:

$ perl -MPOSIX=strftime -MTime::HiRes=time -le '$t = time; $s=sprintf "%
06.3f", $t-int($t/60)*60; print strftime "%H:%M:$s %d:%m:%Y", localtime 
$t'
20:38:44.551 03:06:2011

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to do absolute redirect in perl

2011-06-02 Thread Peter Scott
On Thu, 02 Jun 2011 02:45:25 -0700, anujbhambhani wrote:

> $Request->redirect( url => $Std->url("/gp/errors/404"),type =>
> "permanent");
> works for me
> but
>  $Request->redirect( url => $Std->url("http://www.google.com";,
> {absolute => 1});
> does not work someone please help

Please provide a complete script of under 20 lines that we can run, tell 
us what output you see from running it, and what output you think you 
should see instead.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Ten Years of Considerate Help

2011-05-31 Thread Peter Scott
On Tue, 31 May 2011 18:13:20 +0100, Dermot wrote:
> I'd like to put an idea out to see what the list thinks, what if Casey
> asked for a moderator to take on the role for one year and then the list
> hold an electon[1] in 12 months time for another moderator.

That's as reasonable an idea as any.  I could quibble, but I'd sooner see 
action taken than endless debate.

The actual power of any moderator at this point is limited, I think, to 
requesting an end to certain threads.  You can't remove anyone as far as 
I know; you could have someone removed from the mailing list but it is 
possible to post to this group via NNTP; that's how I do it.  I don't 
think the means to prevent someone from coming in that way exists.

Ultimately we are simply talking about an agreement to respect the 
requests of one or more people.  So that when they request a thread be 
closed, there isn't a response of, "So who put you in charge... oh yeah."

This doesn't have to be difficult. 

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Remove all HTML tags

2011-05-21 Thread Peter Scott
On Wed, 18 May 2011 09:13:20 -0400, Shawn H Corey wrote:
> On 11-05-18 09:02 AM, Mike Blezien wrote:
>> Is there a perl module available, or a regex method, that will prase an
>> HTML formatted file then remove ALL the HTML elements so you end up
>> with just the text content of the file?
> 
> HTML::TreeBuilder loads HTML::Element which has a method as_text().  Use
> HTML::Element::look_down() to find the body, than use as_text()
> 
> http://search.cpan.org/~jfearn/HTML-Tree-4.2/lib/HTML/TreeBuilder.pm
> http://search.cpan.org/~jfearn/HTML-Tree-4.2/lib/HTML/Element.pm

That's the answer I would give, I would just add to the OP that what you 
think the text content of a page ought to be may not match what this 
returns.  Text without formatting runs together and for the majority of 
pages produces a useless mess.  Usually more complex parsing is called 
for based on specific knowledge of the page.  Although if all you want 
the text content for is further machine processing like checksums, 
concordance, or indexing, then this is fine.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: [OT] Good Perl ISP's

2011-05-21 Thread Peter Scott
On Wed, 11 May 2011 11:13:51 +0100, Rob Dixon wrote:
> I wonder what you urgently need that isn't in 5.8.8? Yes, 5.10/5.12 has
> a few nice things in it, but nothing life-changing.

Some modules won't build with the version of ExtUtils::MakeMaker that 
comes with 5.8.8.  Fairly major modules too, although I'm not sure 
exactly which ones right now.  And cpan ExtUtils::MakeMaker won't help 
since core comes before site in @INC.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Rounding Date/Time

2011-05-06 Thread Peter Scott
On Mon, 02 May 2011 11:46:42 -0500, Matt wrote:

> Have a date:
> 
> 2011-05-02-16:40:51
[...]
> 
> I need to round it to nearest 5 minute point.
> 
> 2011-05-02-16:40:51

If you care about things like daylight savings time adjustments, calendar 
changes, or leap seconds, the answer requires considerably more thought 
(use DateTime and do only one arithmetic operation to adjust the time).  
People who spend much time learning about time peculiarities tend to 
think of those considerations constantly.  They only matter to you if you 
don't want to accidentally generate a time that didn't exist in your 
locale, e.g. 2am on a day that the clocks advanced.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: special method name start with "_"

2011-04-28 Thread Peter Scott
On Thu, 28 Apr 2011 13:21:56 +0800, Jeff Pang wrote:
> I may think Perl OO (not moose) doesn't have private or protected
> methods as other languages like Java/Ruby. _method can be accessed from
> anywhere.

In your example, yes.  But Moose *is* Perl's O-O, it's just a wrapper
around it.  Perl provides enough flexibility to do all kinds of things. 
See  http://search.cpan.org/perldoc?MooseX::Privacy.  (That's Moose-X, 
not Moo-Sex.)  Class::Std can do this too.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Fwd: how to parse complex table

2011-04-24 Thread Peter Scott
On Sun, 24 Apr 2011 18:14:52 -0400, galeb abu-ali wrote:
> I revised the code to the following:
[...]
> for my $file( @ARGV ) {
> open( my $IN, "<", $file ) or die "Failed to open: $!\n";
> 
> my( %cog_cat, %cog_id, @cogs, $oid, $locus, $source, $cluster_info
> );
> 
> while( my $line = <$IN> ) {
> chomp $line;
> 
> if( $line=~ /COG_category/ ) {
> ( $oid, $locus, $source, $cluster_info ) = split /\t/,
> $line;
> 
> push @{ $cog_cat{ $locus } }, $cluster_info if(
> $cluster_info );
> 
> } elsif ( $line=~ /COG\d+/ ) {
> ( $oid, $locus, $source, $cluster_info ) = split /\t/,
> $line; push @{ $cog_id{ $locus } }, $source if( $source );
> push @{ $cog_id{ $locus } }, $cluster_info if( $cluster_info
> );
> }
> }

Be ruthless about removing duplication.  The more unnecessary code you 
can prune, the more what's left reveals its true intention, like 
chiseling away everything that is not David from a block of marble :-)  
So in the above, you can take the line

( $oid, $locus, $source, $cluster_info ) = split /\t/, $line;

from both clauses and put it before the if statement.  Also, Perl's topic 
variable allows you to eliminate the use of certain variables that 
otherwise serve no purpose, like $line in your code is only there to get 
at its contents.  So instead you can say

while (<$IN>) {
chomp;
if ( /COG_CATEGORY/ ) {
my ( $oid, $locus, $source, $cluster_info ) = split /\t/;

See also how I declared those four variables right there?  Remove their
declaration from before the while loop now and you've gotten rid of some 
more duplication and unnecessarily wide scoping.

> Many thanks again! Must've spent ~ 4 days on this. I've been flirting
> with Perl less than a year, it's so seductive I find myself debating
> whether to go back to school.

Heh, camels can be like that :-)

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Ten Years of Considerate Help

2011-04-23 Thread Peter Scott
On Fri, 22 Apr 2011 13:39:15 -0400, Casey West wrote:
> Shortly after this mailing list got off the ground I wrote an article
> trying to instigate the Perl community to embrace the idea of a safe
> place for newcomers, both to Perl and programming. It's been pointed out
> I was marginally hyperbolic, but only a little. My abuse of the comma,
> however, has no justification. I quoted from the preface of a popular
> Perl book at the time, closing my argument thusly:
> 
>   "But, paradoxically, the way in which Perl helps you the most has
>almost nothing to do with Perl, and everything to do with the people
>who use Perl. Perl folks are, frankly, some of the most helpful folks
>on earth. If there's a religious quality to the Perl movement, then
>this is at the heart of it. Larry wanted the Perl community to
>function like a little bit of heaven, and he seems to have gotten his
>wish, so far. Please do your part to keep it that way."
>  -- Preface, Programming Perl 2nd Edition
> http://www.perl.com/pub/2001/05/29/tides.html

Thanks, Casey, for coming back and demonstrating that intelligence and 
politeness are not mutually exclusive. I encourage people who haven't 
read your article linked above to do so; it contains some excellent and 
concise explanations of the rationale for civil treatment of beginners.

One more explanation that might help was given to me by the founder of 
the O'Reilly School of Technology, who I am creating courses for.  He is 
very enthusiastic and inspiring about education, and wants to make sure 
all the OST courses follow his vision, and he recognizes that expertise 
is not the same thing as teaching ability, so he impressed upon his 
authors the following model.  

He breaks down students into a bell curve.  On the right tail are the 
early adopters like Randal, me, Uri, Casey, and other experts we could 
all name.  These people will learn something, anything, and everything 
without any external prodding; they just go off and hunt down the 
resources, read the manual, experiment.  They're completely self-starting.

The middle of the bell curve - where the most students are - contains 
people who learn better with varying levels of help and encouragement, 
ranging from a point in the right direction to more directed help from a 
mentor.  OST courses (and Stonehenge, etc, courses) are for them.  They'd 
be a waste of time for the people on the right tail.

People out on the right tail are particularly prone to thinking that the 
best or only way to learn is the same way they did - self-motivated 
figuring things out from the manual and experimentation - and that any 
other approach is inferior or wrong.  But it's simply not going to work 
for the folk in the middle of the curve, who learn a different way.  Some 
folk on the right tail think that if they beat up the people in the 
middle enough, they'll migrate to the right tail - where the "right" 
people are.  Any instances of this actually working are so rare as to be 
the exceptions that prove the rule.

Note that this is a bell curve of learning types, *not* intelligence or 
ability.  And as other posters have pointed out, someone can be in the 
right tail in one discipline, like bioinformatics, and in the middle in 
another - like Perl.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Creating web pages using Perl.

2011-04-23 Thread Peter Scott
On Sat, 23 Apr 2011 18:14:46 +1000, Sean Murphy wrote:
> 
> I am starting another project and I wish to know the best method of
> creating a web page via Perl. I don't want to reinvent the wheel here.
> The perl script must generate plain 4.0 HTML code. I am not after any
> bells or whistles on the page.
> 
> The Perl script will go through all my Audio books and group them by
> author, title and titles in series. I was thinking a table with the
> below columns:
> 
> Author, Series, Title, stream, category  and rating. Rating is Adult,
> Junior, etc. Category is SiFi, thriller, etc.
> 
> If the person clicks on the title, a brief description would pop-up.
> This would be a text file that it would show. Stream it would send the
> audio directly to the browser.

I find HTML::Template a good solution for the beginner who knows HTML. 
The Template Toolkit is awesome in its power but takes longer to learn 
for basic jobs like what you describe.  If and when you learn the 
Template Toolkit for some other reason then you're likely to use it for 
everything including tasks like this one.

The CGI.pm module can generate HTML via functions or methods with the 
same names as the elements.  It was very popular at one time although 
templating makes a lot more sense.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: sample distribution

2011-04-19 Thread Peter Scott
On Tue, 19 Apr 2011 16:29:16 -0700, ai nguyen wrote:

> A population of 20 cows, each one has age and weight (known). Device
> this population into 2 group, each group has 10 cows.
> 
> Questions:
> How to pick a cow on each group so that a distribution of AGE and WEIGHT
> on each group is similar. Show your strategy or/and implement it in
> PERL.

Is this a question on a quiz or test you're taking?  Do the people giving 
the test have the expectation that your answer is a measure of your 
abilities or those of people you've asked for help?

How far have you gotten with a solution?

Or if you're just posing a question as a challenge for people to exercise 
their brains, this would be better off in the Perl Quiz-of-the-Week list 
(which hasn't seen any traffic in aeons).

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Nature of this list

2011-04-19 Thread Peter Scott
I remember when Casey West and Kevin Meltzer started this list.  Casey 
was very specific on-line and in person about it being a place where 
newcomers could ask questions without being flamed.  The FAQ bears this 
out:

: 2.1 - What is the list for?
:
:  A list for beginning Perl programmers to ask questions in a friendly
:  atmosphere.

That is also the complete description of this group at http://
lists.perl.org/list/beginners.html.

The FAQ goes on:

: 2.3 - Are there any rules?
:
: Yes. As with most communities, there are rules. Not many, and ones that
: shouldn't need to be mentioned, but they are.
:
:   * Be nice
:   * No flaming
:   * Have fun
:[...]
: * If you think what you are writing may be taken in a way you didn't
: intend, please add a smiley :-) Many flame wars are stopped by a simple
: smiley!
: * No flames. If your fingers are burning as you are typing the email, it
:  would likely be best not to send it.

If anything is clear from that FAQ it is that the intention is to avoid 
flames on this list.  Casey and Kevin appear to have stopped monitoring 
this group some time ago, though.

There is no shortage of lists, groups, or forums where people can get 
flamed for not following the rules, and people who want to flame them 
have an outlet for doing so.  I've already stopped reading most of them 
because it's not worth my time when most of the content is arguments 
about conduct.  I don't know whether communities inevitably fall into 
that mode after a while but this one at least had a good run and I'll be 
sorry if I end up leaving it too.  

Andy Lester had a good article about this: http://perlbuzz.com/2010/11/
think-for-perls-sake.html.  But judging from the responses it seems he 
and I may be in a minority.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: format output from system command

2011-04-16 Thread Peter Scott
On Fri, 15 Apr 2011 08:53:12 -0700, sono-io wrote:

> On Apr 15, 2011, at 8:37 AM, Alan Haggai Alavi wrote:
> 
>>> open ('FILEOUT', '>>', 'cmdout') ||die "cant open cmdout: $! \n";
>>> 
>>> Is that O.K.?
>> 
>> You are still using a bareword filehandle.
> 
>   Putting single quotes around the filehandle allows it to pass Perl
>   Critic, so I was just curious about the difference.

If you're concerned about following the recommendations of Perl Best 
Practices (which PerlCritic is based on), I'd hope you'd follow the one 
that says to not create bareword filehandles.

I adopted the PBP recommendation to always wrap the lexical filehandle in 
curlies when using it as the indirect object, and I like the result a lot.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Alternative to goto

2011-04-16 Thread Peter Scott
On Fri, 15 Apr 2011 08:48:10 -0400, shawn wilson wrote:
> but, sense it is jumping to a different place in the stack, isn't it
> more efficient than doing the above mentioned
> 
> my $done = 0;
> while( !$done ){
>$done = 1 if( contition );
>do_work;
> }
> 
> vs
> 
> for(;;) {
>goto DONE if( contition );
>do_work;
> }
> label DONE;
> 
> i'd think the later would be faster not only because you are jumping to
> a memory location and because you're not assessing a value every time.

Exactly why would you care about what would be at best milliseconds of 
execution speed more than maintainability?  Seems like you'd be better 
off programming in assembler if that's your priority.  Execution speed 
hasn't been a primary concern since the '70s, if it was even one then.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Alternative to goto

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 10:47:17 -0700, sono-io wrote:

> On Apr 14, 2011, at 10:15 AM, Uri Guttman wrote:
> 
>> goto just shouldn't be in your vocabulary. there is no reason for it at
>> all in any decent language, especially perl.
> 
>   I've been following this thread and I'm just curious.  If goto is 
so
>   bad, why did they add it to Perl?

Perl's goto is pretty old.  Larry was feeling permissive and in a frame 
of mind to make BASIC programmers happy.  He regrets it.  The perldoc for 
goto says he has never found a reason to use it.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Alternative to goto

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 20:44:57 +0100, Rob Dixon wrote:
> [ Good arguments about goto ]
> A final note, perldoc perlsyn says
> 
>   A loop's LABEL is not actually a valid target for a goto; it's just
>   the name of the loop.
> 
> and I am left wondering what this means, as I have had no problem
> writing a 'goto' targetting such labels. I wonder if this is a mistake
> in the documentation, or it is simply saying that such a goto is
> deprecated?

Mistake by the look of it.  To the discoverer go the rights of perlbug :)

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Calling subroutines with the & sigil

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 08:49:45 -0700, sono-io wrote:
>   The only one I was concerned with was a sub called "if", 

Sounds like a great device for an obfuscated Perl contest entry.  That's 
the only place I want to see it, though.

>but it 
doesn't
>   look like it's a built-in function.  However, just so it makes more
>   sense to me and to be on the safe side, I've renamed it 
"if_routine".

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Alternative to goto

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 14:05:54 +0300, Shlomi Fish wrote:

> Hi Uri and Peter,
>> 
> Regarding the "Goto statement considered harmful" myth, see what I wrote
> about it here:

"Myth" is generally used to descibe something widely thought to be true 
that is in fact false.  The assertion that goto is harmful has hardly been 
proven false.

> The entire "GOTO statement considered harmful" is quite a myth. Granted,
> Dijkstra wrote an article with this title, and many people agreed with
> him. But, on the other hand, some people have demonstrated that it is
> possible to do structured programming with goto statements, and
> sometimes even better with them than without them.

Of course you *can* replace control structures with GOTOs, they all 
compile to machine code that uses either GOTO or program counter stacks 
anyway.  The reason we even have GOTO in languages is because the first 
ones were assembler code that reflected the machine code.  Ancient history.

> For example, Don Knuth wrote an article "Structured Programming Using
> Goto Statements" (rumouredly sub-titled "'Goto Statement Considered
> Harmful' Considered Harmful") in which he deomnstrated exactly that. And
> I take this view as well.

Knuth's article is at http://citeseerx.ist.psu.edu/viewdoc/download?
doi=10.1.1.103.6084&rep=rep1&type=pdf .  He doesn't call Dijkstra's 
statement harmful.  He spends half the paper discussing how to remove 
GOTOs and then brings up some cases where using them would make certain 
code run faster, which in 1974 was often more important than programmer 
time but almost always isn't now.  Knuth also had spent time developing 
languages like MIX that needed GOTO; MIX was a hypothetical machine code 
(sort of an early Parrot).  It included card punch devices and drum 
units.  So he was used to writing programs that had to use GOTO.  Only 
assembly programmers these days still need it.

Like I said: I've never seen code that was clearer with a GOTO than 
without it.  Shorter, maybe; faster, maybe, but not clearer.  Even if I 
ever did, it would be the exception that proved an unusually universal 
rule.  Any possible justification for a GOTO would be so arcane that it is 
counterproductive to suggest it at all in a beginner's group. 

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Calling subroutines with the & sigil

2011-04-13 Thread Peter Scott
On Wed, 13 Apr 2011 16:07:47 -0700, sono-io wrote:

> Hello,
> 
>   I read somewhere that it's bad practice anymore to call a 
subroutine
>   like this:
> 
> &subroutine();
> 
>   I've also read where it's faster to call a sub like this:
> &subroutine;
> 
> than it is to call like this:
> subroutine();
> 
>   Is this true?  I searched but I can't find a good recent 
discussion of
>   this.  What is the best (preferred) way to call subroutines today?

It is better to call them as subroutine() provided that you don't define a 
subroutine with the same name as a Perl builtin.  It's better to learn the 
names of the Perl builtins than to give up and always use &subroutine.  
The builtins are all listed in perlfunc.  It's actually not that hard to 
get them.  The only one that people habitually collide with is log().

If you're worried about the speed overhead of one vs the other then either 
you are worried about the wrong thing or you have bigger problems.  Worry 
about speed only when (a) you've determined that your code is too slow, 
and then (b) you've profiled it to find out where the bottleneck is (hint: 
it's not likely to be in subroutine call overhead).

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Alternative to goto

2011-04-13 Thread Peter Scott
On Wed, 13 Apr 2011 21:57:53 -0700, Mariano Loza Coll wrote:

> Hi all,
> 
>>  OC> I never bothered to learn how
>>  OC> to use goto because it's deprecated (or on it's way?), but it OC>
>>  seems like this would be a good place to use it.  At the same OC>
>>  time, I understand that use of goto is akin to sleeping with your OC>
>>  sister among most programmers in the Perl programming community.
> 
> Like Owen, I've come across many a recommendation AGAINST using goto in
> Perl. And (like Owen?), I have yet to find one that explains clearly the
> reasons arguing against its use. If nothing else, it has made me very
> curious... Can any of the more experienced programmers (ie. nearly
> everyone else on this list by my standards) point to a good explanation
> as to why one should avoid goto in Perl (or coding in general)? I looked
> around in perl-begin.org but couldn't find anything obvious. Once again,
> I make my request from the purest desire of learning Perl the best way I
> can.

Here is the definitive explanation: http://www.cs.utexas.edu/users/EWD/
ewd02xx/EWD215.PDF .

I have never, ever, seen a situation where the use of goto would have 
resulted in clearer code.  Considering it has always indicated to me that 
the person considering it has not understood the problem properly or 
modeled its solution well.  Goto simply is not part of the vocabulary of 
clear coding.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: perl dd

2011-04-02 Thread Peter Scott
On Fri, 01 Apr 2011 10:51:58 +0300, Shlomi Fish wrote:
> 2. The problem with 1E9 is that I think it's a floating point number
> (though Perl 5 may have some intelligence there). Not sure it matterns a
> lot for Perl but if you do something like 1.27E9 you may get weird
> side-effects due to:

Yup, anything in scientific notation becomes floating point, but I doubt 
it's going to matter in the case of 1E9:

$ perl -MDevel::Peek -e 'Dump($_) for 1E9, 10, 1E2'
SV = NV(0x8a4aee8) at 0x8a367b8
  REFCNT = 2
  FLAGS = (NOK,READONLY,pNOK)
  NV = 10
SV = IV(0x8a367c4) at 0x8a367c8
  REFCNT = 2
  FLAGS = (IOK,READONLY,pIOK)
  IV = 10
SV = NV(0x8a4aef0) at 0x8a367d8
  REFCNT = 2
  FLAGS = (NOK,READONLY,pNOK)
  NV = 100


-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: perl dd

2011-03-31 Thread Peter Scott
On Thu, 31 Mar 2011 12:07:41 +0200, Shlomi Fish wrote:
> Also, Larry Wall has allowed Perl 5 numeric constants to contain
> underscore so you can write 10**9 as 1_000_000_000 instead of 10
> which is much less readable and also more error-prone. (Larry Wall)++ .

1E9 seems to capture your intention even better :-)

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: shift oo

2011-03-23 Thread Peter Scott
On Tue, 22 Mar 2011 13:41:59 -0700, Randal L. Schwartz wrote:

>>>>>> "Peter" == Peter Scott  writes:
> 
>>> my $s = Streamer->new;
>>> my $app = sub {
>>> return sub {
>>> $s->open_fh;
>>> my $writer = shift->(
>>> [ 200, [ "Content-type" => "text/plain" ], $s ] );
>>> };
>>> };
> 
> Peter> As it stands, this doesn't make sense because nothing happens to
> $writer; Peter> so why create it?
> 
> I presume you're objecting to the explicit $writer.  Certainly, the
> value of $writer is also the return value of the inner subroutine, so
> that *is* something that could be noted:

Right, the superfluous naming of $writer leads to a lot of head-
scratching.  Best guess (if this is an accurate post of the code), that 
there was originally some debugging/logging code in there before a 
"return $writer" that got taken out.  Although I supposed that the paste 
was incomplete.  Either way, a giant red herring.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: sub routine

2011-03-19 Thread Peter Scott
On Thu, 17 Mar 2011 19:25:02 -0600, Chris Stinemetz wrote:

> Take the value of $data[261] and return the solution of:
> $data[261]+13)/6.6/8/2*10)/10

Your expression there is missing left parentheses.  If we guess at where 
to put them we end up with  

(($data[261]+13)/6.6/8/2*10)/10

which doesn't make sense because why multiply by 10 only to divide by 10?

The code you posted is an odd mix of sophistication levels.  Did you 
write it all, and if not, do you understand it?  You seem to be in need 
more of a beginner's lesson to Perl if you need to know how to construct 
expressions like that and yet are working with code containing 
Schwartzian transforms.

In general, posting a lengthy program and asking how to enhance it to 
meet some new requirement is not what this list/group is about; that 
falls under "doing your homework".  We're here to teach you how to solve 
problems, not solve them for you.  You might still get solutions - like 
you did here - but things will go better when you ask for learning 
instead.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: shift oo

2011-03-19 Thread Peter Scott
On Fri, 18 Mar 2011 17:34:00 -0400, shawn wilson wrote:
> here's the whole function (i didn't think i needed to post it because i
> get the rest of this code):

Your problem is less to do with Perl than it is with explaining what you 
need clearly.  Clear thinking and clear communication lead to clear code 
so this is an important thing to work on. This thread resembled a bad 
rewrite of the Abbott & Costello "Who's on First?" skit.

> my $s = Streamer->new;
> my $app = sub {
> return sub {
> $s->open_fh;
> my $writer = shift->(
> [ 200, [ "Content-type" => "text/plain" ], $s ]
> );
> };
> };

That is a fancy piece of code somewhat beyond the usual definition of 
"beginner".  Context is important; you haven't provided all of the 
context we need to understand this so there is going to be some guesswork 
in the explanation.

This code creates a "Streamer" object in $s.  Then it populates $app with 
a reference to a subroutine that when called, will return a reference to 
a subroutine that first calls the open_fh() method of $s, then creates in 
$writer the result of calling the first argument (to the inner 
subroutine) as a code reference, passing it a reference to an array 
containing 200, another array ref, and the $s object.

As it stands, this doesn't make sense because nothing happens to $writer; 
so why create it?  The code certainly does something but either there is 
code that you haven't shown us or the writer of this code wasn't thinking 
clearly in putting $writer in there.

There are two code refs created and another one passed in these few 
lines; it is very compact.  Use of this code would go something like this:

  $other_ref = sub {
my $ar = shift;
my ($status, $header_ref, $streamer) = @$ar;
my @headers = @$header_ref;
# Do something with those variables...
  };
  $coderef = $app->();
  $coderef->( $other_ref );

$other_ref must be a reference to a subroutine for this code to work.  It 
is not therefore an object (technically, it could be - it could be 
blessed - but that is beside the point, nothing in this code expects it 
to be an object).

You need to be very conversant with code references and functional 
programming to be comfortable with this code.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: MRF-ERROR: Is a directory

2011-03-17 Thread Peter Scott
On Thu, 17 Mar 2011 02:26:06 +0700, indrag wrote:

> this is the code:
> 
> #!/usr/bin/perl
> 
> use NetCDF;

The error is coming out of NetCDF.pm.  Check all of the calls you make to 
functions from that module against its documentation.

Did you write the program you posted or did someone else?  Do you 
understand it?

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How does the function loading works in Perl

2011-03-02 Thread Peter Scott
On Wed, 02 Mar 2011 17:02:30 -0500, Shawn H Corey wrote:

> On 11-03-02 04:15 PM, Parag Kalra wrote:
>> A Perl script may have many functions. When we execute the script via
>> Perl Interpreter, does all the functions are loaded into memory?
>>
>>
> All the functions are compiled and loaded.
> 
>> Sometimes we just like to keep the coded functions in the script with
>> the idea that we may need them in future. Will removing an un-called
>> functions improve the execution time?
> 
> Yes but on modern machines, you will need an awful lot of subs to get a
> noticeable slow down.

Right.

> The AUTOLOAD feature can be used to delay the compilation and loading of
> a sub 

I think you mean AutoLoader.  Or SelfLoader.  They may use AUTOLOAD under 
the hood but that's not the direction to point the user in.

> but I have never seen it used in practice.  

There are a fair number of modules on CPAN using it.  And in the core: 
POSIX, for instance.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: x,y axis graph

2011-02-16 Thread Scott Hall
On Tue, Feb 15, 2011 at 9:35 PM, Chris Stinemetz <
cstinem...@cricketcommunications.com> wrote:

> I am interested in creating a cgi perl script that I can publish on the web
> that will tie into a mysql database and create a x,y axis graph based on
> data selection. Any suggestions are greatly appreciated.
>
> Thank you,
> Chris Stinemetz
>
>
I use GD::Graph with cgi to create graphs on the fly.

There are some examples on http://gdgraph.com/

Regards,

Scott


Re: x,y axis graph

2011-02-16 Thread Peter Scott
On Tue, 15 Feb 2011 19:35:03 -0700, Chris Stinemetz wrote:
> I am interested in creating a cgi perl script that I can publish on the
> web that will tie into a mysql database and create a x,y axis graph
> based on data selection. Any suggestions are greatly appreciated.

Suggestion: 

http://search.cpan.org/~dmaki/Google-Chart-0.05014/lib/Google/Chart.pm

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: understanding the ||= operator

2011-02-13 Thread Peter Scott
On Sat, 12 Feb 2011 12:13:13 +0100, Dr.Ruud wrote:
> On 2011-02-11 11:26, Alan Haggai Alavi wrote:
> 
>> $variable_1 ||= $variable_2 is equivalent to $variable_1 = $variable_1
>> || $variable_2.
> 
> Hmm, I don't buy that, I would say that $x ||= $y is equivalent to
> 
>$x = $y unless $x;
> 
> alternatively:
> 
>$x or $x = $y;
> 
> because the setting of $x only needs to happen if $x is false.
> 
> Realize that C<$variable_1 = $variable_1;> can only be optimized away if
> no magic is involved.

No, the optimization seems to happen either way:

$ perl -E 'tie $x, "F"; tie $y, "F"; say "Orcish:"; $x ||= $y; say 
"Unwrapped:"; $x = $x || $y; say "Done"; sub F::TIESCALAR{ bless [], 
"F" }; sub F::AUTOLOAD{ say $F::AUTOLOAD } '
Orcish:
F::FETCH
Unwrapped:
F::FETCH
Done
F::DESTROY
F::DESTROY


-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Dereference Links

2011-01-23 Thread Peter Scott
On Fri, 21 Jan 2011 08:01:03 -0600, Mike Flannigan wrote:
> I'm trying to dereference the @{$links} produced by WWW::SimpleRobot and
> am having a heck of a time getting it done.  Can anybody help? You can
> see some of the things I have tried below.

That module hasn't been updated since 2001.  You'll have a much easier 
time using WWW::Mechanize and many more people will be in a position to 
help you.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Function to print Object properties

2011-01-06 Thread Peter Scott
On Thu, 06 Jan 2011 21:31:11 -0500, Shawn H Corey wrote:
> On 11-01-06 09:25 PM, Parag Kalra wrote:
>> For example if I have a package say Foo::Bar. Now assume that there is
>> a object called $fob and pretend that I don't know that its an instance
>> of Foo::Bar
> 
> print ref( $fob ), "\n";
> 
> See `perldoc -f ref`.

The officially blessed :-) way to do this is with Scalar::Util:

use Scalar::Util qw(blessed);

say blessed( $fob );


since this can discriminate between a reference and a blessed reference.  
Consider the cases of

$fob = {};
$fob = bless {}, "HASH";

for instance.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: advangtes of Perl on various languages

2011-01-06 Thread Peter Scott
On Thu, 06 Jan 2011 09:32:31 +0530, Sunita Rani Pradhan wrote:
>>>> This is a good question .I am asking for my own career growth . I
> work as a automation engineer . I used to be in manual testing and moved
> to automation just been 1.5yr.

What does an automation engineer do, and what industry are you in or want 
to be in?  Are you programming embedded devices or microcontrollers?  In 
the video game business or financial services?  Are you doing industrial 
process monitoring, educational software, mobile phone applications, CAD/
CAM, or engineering documentation library interfaces?  All of those 
possibilities and more would have radically different answers and you 
have not provided any information to differentiate between them. 

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: advangtes of Perl on various languages

2011-01-03 Thread Peter Scott
On Tue, 04 Jan 2011 12:42:28 +0530, Sunita Rani Pradhan wrote:
> I would like to know answers of following questions  :
>  
> - What all advantages Perl has on top of other scripting languages like
> Python , shell , Java ?
>  
> - What is the career growth, road map in Perl programming ?

These questions are more of a Rohrshach test for the reader than anything 
else.  Without any idea of what goal you are trying to satisfy any answer 
is essentially useless.  It is like the old saw that a recession is when 
the other guy is out of work and a depression is when you are out of work: 
aggregate statistics--and industry trends--are of very little importance 
compared to your personal priorities.

If you want a language with a large install base, learn COBOL.  If you 
want cool IDEs, learn Java.  Me, I don't care whether there's more money 
in Java, it wouldn't be enough for me.  And if money's the top priority, 
become a lawyer.

So I can't see any answers to those questions being of use unless you tell 
us why you want to know.  Are they an assignment for a term paper?  Are 
you writing a trade magazine article?  Or something else?  If you're 
asking in regard to your own career path then we'd need to know a lot more 
about what your priorities and background are.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: 1st line of perl script

2011-01-03 Thread Peter Scott
On Tue, 04 Jan 2011 01:09:56 -0500, George Worroll wrote:
> On Windows, that line is just a comment.  Neither the operating system
> nor the interpreter does anything with it. 

Not quite.  Any options on the line (e.g., -T) will be activated.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: perl training material and excercises for freshers

2011-01-03 Thread Peter Scott
On Mon, 03 Jan 2011 13:26:49 +0530, Sunita Rani Pradhan wrote:
> I am planning to give Perl training to my juniors in my
> team. They are new to Perl. Could anyone please send me any Perl
> training materials with exercises, or links, which I can refer to?
> 
> Please send me good suggestions also for training.

Web-based training with instructor feedback at the O'Reilly School of 
Technology:

http://www.oreillyschool.com/courses/perl1/

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Strategy for diagnosing context-sensitive bug

2010-12-07 Thread Peter Scott
On Tue, 07 Dec 2010 10:33:08 -0800, Jonathan Pool wrote:
>> Every CGI program should be testable from the command line.  But if
>> that doesn't work, there is a way to remotely invoke the debugger in
>> this situation. http://
>> www.foo.be/docs/tpj/issues/vol4_3/tpj0403-0008.html .
> 
> Thanks. The applicability of this approach is unclear to me. The
> document says "The ptkdb window will appear". But this script is being
> run by httpd to generate a reply to a request from a web browser's form
> submission. I don't understand where a window could appear.

On whatever workstation you designate through the DISPLAY environment 
variable.  You have to have a basic understanding of X Windows and its 
client/server model to make this work.

> As for the command line, yes, but I would be simulating a
> multipart/form-data http form submission with a file-upload part and
> hoping that Perl is seeing the same thing. 

True, it won't be easy, but if you can come up with a test for whatever 
bug you are experiencing, it will be invaluable for saving time later.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Strategy for diagnosing context-sensitive bug

2010-12-07 Thread Peter Scott
On Tue, 07 Dec 2010 01:24:57 -0800, Jonathan Pool wrote:
>> Are you familiar with the perl debugger?
> 
> Thanks much for your reply. I haven't used the debugger, partly because
> its documentation describes it as an interactive tool and it's not clear
> to me how that works in my context. The script is executed by httpd in
> response to a browser form submission, which includes a file upload.

Every CGI program should be testable from the command line (and CGI.pm 
can read arguments from there).  But if that doesn't work, there is a way 
to remotely invoke the debugger in this situation.  Rather than retype 
it, I googled and found it in a Perl Journal article saved at http://
www.foo.be/docs/tpj/issues/vol4_3/tpj0403-0008.html .

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Monitoring ssh connectivity to a server using perl !

2010-11-23 Thread Peter Scott
On Tue, 23 Nov 2010 21:59:19 +0530, Amit Saxena wrote:

> Hi all,
> 
> What's the best way to monitor ssh connectivity, and not just ssh port
> availability, to a server using perl assuming following constraints ?
> 
> I tried for Net::SSH but public private key is not allowed.
> 
> I tried for Net::SSH::Perl etc but these are not built in perl
> distribution (active perl on windows or part of perl distribution of
> linux / solaris).
> 
> Can we do it via "IO::Socket::INET" ?

If it's enough to check that something's listening to port 22:

perl -MNet::Ping -le '$p=Net::Ping->new; $p->port_number(22); $p->ping
(localhost) or warn "SSH down"'

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Email Filter Script

2010-10-22 Thread Peter Scott
On Fri, 22 Oct 2010 03:35:19 -0400, Mark wrote:
>  I have a college e-mail account. The college uses Outlook webmail.
> I hate Outlook webmail.

You are among friends :)

> I have multiple e-mail accounts and use one IMAP
> e-mail client (Tbird) to manage them all; can't be chasing down
> individual webmail accounts. However, the college Outlook account in
> question is not accessible via IMAP. So I set up the Outlook account to
> automatically forward all messages to one of my personal accounts.
>  The college's Outlook server does forward all messages, but in the
> process it severely alters the messages in the following ways:

Can you create a redirection rule instead?

http://office.microsoft.com/en-us/outlook-help/automatically-forward-
messages-to-another-e-mail-account-HA001150201.aspx

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: perl for systemadministration

2010-10-20 Thread Peter Scott
On Wed, 20 Oct 2010 17:09:17 +0530, Jyoti wrote:
> I need your help. Please tell me a good book for perl for system
> administration.

"Perl for System Administration"

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: PERL MYSQL query "IF EXISTS then UPDATE else INSERT"

2010-10-20 Thread Peter Scott
On Wed, 20 Oct 2010 12:07:03 +0530, S Pratap Singh wrote:
> I want to update my database if the key value is already there then it
> will update the required field else it will insert the new row in the
> same table.
> 
> Insert query works fine but I am not able to figure out how to achieve
> this "IF EXISTS then UPDATE else INSERT"  using a one liner MYSQL
> statement . If someone can give me an example to write such query and
> execute it from perl then it would be really appreciated.

This isn't a Perl question, you're asking in the wrong place.  This is 
analogous to asking your auto mechanic what the feeding habits of emus 
are because you used your car to drive to the zoo.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I open a remote ssh session with perl

2010-08-28 Thread Peter Scott
On Sat, 28 Aug 2010 11:55:01 +0530, S Pratap Singh wrote:
> Is there any way I can get these interactive output via my script or I
> am missing something? .. Thanks for your continued help.
> 
> I need to get those interactive outputs to my script or is there any way
> to open a psuedo terminal.  I do not want to execute command on server
> it should be examined via my script and then it should get executed . 
> Let me know if this is possible using perl or I have to use any other
> scripting language like python.

Yes, the documentation for Net::SSH::Perl explains how.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I open a remote ssh session with perl

2010-08-27 Thread Peter Scott
On Fri, 27 Aug 2010 09:17:22 +0530, S Pratap Singh wrote:

> Hello Peter ,
> 
> Did you try executing command "top -cd2", "iostat 1", vmstat 1 10" etc ?
> Did you get the output of those command ? 

vmstat 1 10 works for me; pstree works; but of course you're not going to 
run top -cd2 this way, that's an interactive program that won't terminate 
without user input. Neither will iostat 1 terminate; but iostat 1 10 
works fine, just got to wait 10 seconds. 

I don't see anything in your pstree output that looks truncated.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I open a remote ssh session with perl

2010-08-26 Thread Peter Scott
On Thu, 26 Aug 2010 11:22:29 +0530, S Pratap Singh wrote:
> Here is my code which logs in and performs some task but it does not
> show the output of top and pstree command what would i do to get the
> output of these commands along with vmstat and iostat
> 
> #!/usr/bin/perl -w
> use Net::SSH::Perl
> $host = '192.168.3.36';
> $username = 'root';
> $login_passwd = 'password';
> #$session -> close;
> 
> #my $cmd = "ls -l";
> my $ssh = Net::SSH::Perl->new($host); $ssh->login($username,
> $login_passwd); #my $arg= join '',@ARGV;
> #while ($arg) {
> while(<>) {
> $cmd = $_;
> my($stdout,$sterr, $stderr) = $ssh->cmd("$cmd"); print
> "\n$stdout\n$stderr   ";
> print "quiting from the server " if eof; }

I just tried this code with a server and credentials of my own and it 
worked fine with several commands including pstree.  So you have some 
problem specific to your configuration that needs debugging.  Either the 
module isn't built right, you have the wrong credentials, you aren't 
connecting, or the remote end doesn't have the right environment, 
something like that.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I open a remote ssh session with perl

2010-08-24 Thread Peter Scott
On Tue, 24 Aug 2010 14:25:01 +0530, S Pratap Singh wrote:
 
> I know how to run command on remote shell using script , but I want to
> open remote shell using perl and want to run the command manually and
> terminate the session when I am done as we normally do with shell .

CPAN: Net::SSH::Perl .

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl obfuscator

2010-08-23 Thread Peter Scott
On Sun, 22 Aug 2010 03:40:33 -0400, Chas. Owens wrote:
>> But the names (variables, subroutines) can be rendered meaningless.
>> Since picking good names is one of the most important contributions a
>> good programmer can make, trying to understand and change a large body
>> of code that has the worst names possible may not be impossible, but
>> still is excruciating.
> snip
> 
> If you do that in Perl 5, you run the risk of breaking the code.
> Anything that used a symbolic reference would break.  [snip] This
> is why all Perl 5 obfuscators, that I know of, work by encoding the text
> somehow, not by modifying what perl sees. 

http://www.stunnix.com/prod/po/overview.shtml :

Now, I haven't used it.  But it does claim to be an exception to your 
rule.  The users manual has a section on what to do about symbolic name 
construction.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl obfuscator

2010-08-21 Thread Peter Scott
On Fri, 20 Aug 2010 14:27:29 -0400, Chas. Owens wrote:
> There are no good obfuscators.  A user can always get the source back
> out.  

But the names (variables, subroutines) can be rendered meaningless.  
Since picking good names is one of the most important contributions a 
good programmer can make, trying to understand and change a large body of 
code that has the worst names possible may not be impossible, but still 
is excruciating.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Real newbie question

2010-07-22 Thread Scott Hall
On Thu, Jul 22, 2010 at 2:34 AM, Dr.Ruud

> wrote:

> Jim Gibson wrote:
>
>>  scribbled:
>>
>
>  I have a multi line text file laid out as below.
>>>
>>> 10.10.10.45 bobs
>>> 10.10.10.34 jims
>>> 10.10.10.27 jacks
>>>
>>> I would like to that the 10.10.10.??? and move it to the end of the same
>>> line so the output will look like.
>>>
>>> bobs 10.10.10.45
>>> jims 10.10.10.34
>>> jacks 10.10.10.27
>>>
>>
>> perl -ane 'print join(" ",reverse(@F)),"\n"' file
>>
>
>  perl -anle 'print "@F[1,0]"' file
>
>
perl -plae '$_="@F[1,0]"' file


> --
> Ruud


Scott
-- 
pri...@{[q%@%x5**2^q"
534`!./4(%2`0%2,`(!#+%2l"]};


Re: How to become a perl architect !

2010-07-02 Thread Peter Scott
On Fri, 02 Jul 2010 23:00:48 +0530, Amit Saxena wrote:

> On Fri, Jul 2, 2010 at 9:41 PM, Peter Scott  wrote:
> 
>> On Fri, 02 Jul 2010 09:34:05 +, Amit Saxena wrote:
>> > I have around 6+ years of IT experience as a software development
>> > mailing in scripting technologies using perl.
>> >
>> > I want to become technical architect in perl. Please help me /
>> > suggest me / guide me on how should I start. Also please tell me any
>> > resources which could help me.
>>
>> I have been developing in Perl for 20 years and doing enterprise
>> architecture for 10 years.  But I have no idea what a "Perl architect"
>> is.  Please explain in more detail.
>>
>> --
>> Peter Scott
>> http://www.perlmedic.com/ http://www.perldebugged.com/
>> http://www.informit.com/store/product.aspx?isbn=0137001274
>> http://www.oreillyschool.com/courses/perl1/
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional
>> commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
>>
>>
>>
> Hi Peter,
> 
> Perl is my main skill and I wanted to learn how to design and develop
> enterprise applications in Perl. Development is OK but how to design is
> something I want to know. So far, I am only developing small application
> components in Perl but now I want to learn how to design the "whole
> system" and subsequently develop in Perl.
> 
> I might have incorrectly stated the term "Perl architect" but I hope you
> now have got the idea of what I want to now learn. If yes, then please
> suggest.

To develop large-scale applications in Perl, you may need to use a 
framework such as POE or Catalyst depending on the type of application.  
You should certainly understand Moose and how to develop modules.  Design 
patterns help, but read the Perl Design Patterns Wiki rather than the 
turgid book, since many of the archetypal design patterns exist solely to 
solve problems of strongly-typed languages that don't exist in Perl.

Inter-application interfaces should not be language-specific. If you are 
developing a service-oriented architecture, for instance, you might 
specify a type of enterprise service bus, but the way applications talk 
to each other should be based on standard protocols and formats. 

Principles of system architecture are higher level than application 
language.  Ditto for enterprise architecture.  I prefer the Zachman 
framework for the latter.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to become a perl architect !

2010-07-02 Thread Peter Scott
On Fri, 02 Jul 2010 09:34:05 +, Amit Saxena wrote:
> I have around 6+ years of IT experience as a software development
> mailing in scripting technologies using perl.
> 
> I want to become technical architect in perl. Please help me / suggest
> me / guide me on how should I start. Also please tell me any resources
> which could help me.

I have been developing in Perl for 20 years and doing enterprise 
architecture for 10 years.  But I have no idea what a "Perl architect" 
is.  Please explain in more detail. 

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Conditionally use

2010-06-14 Thread Peter Scott
On Mon, 14 Jun 2010 11:23:34 -0700, kenTk wrote:
> How can I conditionally use a module? 
 
perldoc if

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




  1   2   3   4   5   6   7   8   9   10   >