Re: OOP: a class using a class that is descended from it?

2017-08-04 Thread Shawn H Corey
On Fri, 4 Aug 2017 17:51:01 +0200
hw <h...@gc-24.de> wrote:

> Huh? How many package statements is a module supposed to contain?
> And doesn´t a package statement turn a module into a package?

Convention is:

* One package per module.

* One module per package.

But if come across bad code, you may see more than one-to-one. :(



A module is a file that has a *.pm extension. Example: Foo.pm

A package is a name space that keeps its contents separate from other
packages.


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: OOP: a class using a class that is descended from it?

2017-08-04 Thread Shawn H Corey
On Fri, 4 Aug 2017 15:23:21 +0200
hw <h...@gc-24.de> wrote:

> Now I´m confused as to what is a module and a package.  Both are
> files.
> 
> In any case, it is my intention to keep everything that one class
> requires within one file which starts with 'package FOO'.  Due to
> increasing complexity, I´m using POD sections or I wouldn´t know
> anymore what I´m doing ...
> 

A package is a name space. A file may have more than one package:

package Foo;
# thingies for Foo

package Bar;
# thingies for Bar

package main;
# thingies for main (default package)

__END__


In Perl, a class is a thingy blessed to a package. In other words,
classes are subset of packages but a package need not be a class.

package Foo;
$object = bless $thingy, Foo;

__END__


A module is a file which has the extension `*.pm` It can be loaded by
the `use` keyword.

use Foo; # load the module Foo.pm

__END__

As seen above, a module need not be restricted to one package. In fact,
the module need not have the package for its name.

# File: Foo.pm

package Bar;
# thingies for Bar

__END__

And a module can have one (or more) class(es).

# File: Foo.pm

package Foo;

sub new {
return bless { @_ };
}

__END__


Packages may be distributed among many files.

# File: Foo.pm

package Foo;
# thingies for Foo

__END__

# File: Bar.pm

package Foo;
# more thingies for Foo

__END__



This is very confusing so the convention is that one module has one
package. I'm telling you this because the terms module and package are
not interchangeable.

To summarize:

* A module is a file with the extension *.pm

* A module may have zero, one or many packages but please stick to one
  package per module.

* Packages may be distributed among many files but please stick to one
  module for each package.

* A package may be a class. If it has the keyword `bless`in it, it is a
  class.



> > The way I would do it would be to separate out what is common in
> > both Foo and Bar and put them in a separate module. Then Foo and
> > Bar can `use` it as their parent.  
> 
> I think that might be the best solution.  I could make a metaclass
> that contains the methods common to both FOO and BAR and have both of
> them descend from it.
> 
> However, that feels like using inheritance in an upside down manner.
> But perhaps it´s supposed to be used like that?

Yes, they are called virtual classes. Aka generics in Java and
interfaces in general.
http://www.cs.utah.edu/~germain/PPS/Topics/interfaces.html


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: OOP: a class using a class that is descended from it?

2017-08-03 Thread Shawn H Corey
On Thu, 3 Aug 2017 20:44:45 +0200
hw <h...@gc-24.de> wrote:

> 
> Hi,
> 
> suppose I have a class FOO and a class BAR.  The parent of BAR is FOO.
> 
> I would like FOO to /use/ BAR because BAR has some methods needed by
> FOO. BAR is /decended/ from FOO because FOO has many methods needed
> by BAR.
> 
> Is this possible, or does it lead to some endless recursion when
> compiling?
> 

Files and packages are two different things in Perl. `use Foo;` mean
load the module from the file Foo.pm and execute it. Perl keeps a list
of all the modules (files) it loads so that no it never loads a module
twice.

`package Foo;` means what follows is in the name-space Foo. Their
fully-qualified names would start with `Foo::`

The convention is that there should be only one package per
module-file. But Perl doesn't care. You can mixed packages and modules
any which way you can imagine. You can have a package spread out in
several modules and you can have a module contains many packages, or
any combination of the two. But to keep you code understandable, please
keep to one and only one package per module.

The way I would do it would be to separate out what is common in both
Foo and Bar and put them in a separate module. Then Foo and Bar can
`use` it as their parent.


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Trap undefined barewords in subroutines

2017-08-02 Thread Shawn H Corey
On Wed, 2 Aug 2017 18:48:43 +
"Dyer, Dustin E. (KSC-VAH10)" <dustin.e.d...@nasa.gov> wrote:

> So is there something different I can do to cause an error when
> provided files contain undefined barewords?

Do you mean something like this?

my $someVar = '[map {$_ - 250 * FT2M} 1,2,3,]';  #FT2M is undef
eval $someVar;
if( $@ ){
if( $@ =~ /^Bareword / ){
# process bare word error
}else{
# some other error
}
}else{
# no errors.
}


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Filehandle within foreach loop

2017-07-16 Thread Shawn H Corey
On Sun, 16 Jul 2017 07:36:39 -0400
David Mertens <dcmertens.p...@gmail.com> wrote:

> Also note that lexical filehandles close when they go out of scope

True but you should always explicitly close your files. This gives you
a chance to report any errors it had, have rather than silently
ignoring them.


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: Filehandle within foreach loop

2017-07-12 Thread Shawn H Corey
On Thu, 13 Jul 2017 00:50:42 +0530
perl kamal <kamal.p...@gmail.com> wrote:

> open (my $FH, $file) or die "could not open file\n";

A quick note: output the file name and error message to have a better
idea of what went wrong.

open (my $FH, $file) or die "could not open file $file: $!\n";


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Perl invocations

2017-07-02 Thread Shawn H Corey
On Sun, 2 Jul 2017 14:29:25 +0200
Eric de Hont <eric-pml...@hobiho.nl> wrote:

> What it boils down to: use warnings as well as -w works, but -w is 
> considered old fashioned.

The problem with -w is that it can't be turned off. Sometimes a module
has to do something dangerous and having a warning appear is annoying
at best and can cause worry and stress in a programmer. `use
warnings;` can be turned off:

{
no warnings;
# do something dangerous
}
# end of scope restores warnings to the previous value `use` or `no`

> 
> A space in the perlbang (shebang) line is not perls problem but your 
> shell's. I would NOT use a space.
> If your shell doesn't choke on such a space: lucky you.

A space after the shebang tells the C-shell csh(1) not to interpret the
script as a C-shell script. Other shells, like bash(1) and the POSIX
sh(1) ignore the space but the Bourne shell may not.


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'

2017-07-01 Thread Shawn H Corey
On Sat, 1 Jul 2017 17:27:02 +0200
hw <h...@gc-24.de> wrote:

> 
> Hi,
> 
> can someone please explain this:
> 
> 
> perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
> i:
> 
> 
> Particularly:
> 
> 
> + Why doesn´t it print 1?

Because !!$i is zero

> 
> + How is this not a bug?

Nope, no bug.

> 
> + What is being printed here?

!!$i which is !(!(0)) which is !(1) which is 0

> 
> + How do you do what I intended in perl?
> 

How do we know what you intend?


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: is this reasonably save?

2017-05-14 Thread Shawn H Corey
On Sun, 14 May 2017 18:16:50 +0100
lee <l...@yagibdah.de> wrote:

> Ok, do you see a way to do what I'm doing here by evaluating a block?
> 

Simply remove it.

$sth_cmds->bind_columns(@params);


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: is this reasonably save?

2017-05-14 Thread Shawn H Corey
On Sun, 14 May 2017 02:08:11 +0100
lee <l...@yagibdah.de> wrote:

> I haven't used 'eval' before, and this seems inherently dangerous.

eval EXPR;
eval;

These are dangerous.

eval BLOCK

This is not.

See:

`perldoc -f eval`  http://perldoc.perl.org/functions/eval.html

`perldoc perlrun` and search for /-T/
http://perldoc.perl.org/perlrun.html


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: postderef with subroutines

2017-05-11 Thread Shawn H Corey
On Thu, 11 May 2017 13:10:03 +0200
Luca Ferrari <fluca1...@infinito.it> wrote:

> Hi all,
> according to the documentation the postderef for code blocks $ref->&*
> and $ref->() have different meanings
> <https://perldoc.perl.org/perlref.html#Postfix-Dereference-Syntax>
> 
> While I can use the following:
> 
> my $sub_ref = sub { say "Hello world: @_ !" };
> $sub_ref->( 'and the camels go' );
> &{ $sub_ref }( 'and the camels go' );
> $sub_ref->&* ;
> 
> is it possible to pass argument to the function via postderef?
> Something like the not working code:
> 
> $sub_ref->& ( 'and the camels go' );
> 
> Any idea?
> 

{
    local @_ = ( 'and the camels go' );
$sub_ref->&*;
}


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: How to delete multiple indices from array

2017-04-12 Thread Shawn H Corey
On Wed, 12 Apr 2017 19:34:22 -0400
Uri Guttman <u...@stemsystems.com> wrote:

> it is so odd to be filtering an array by the indexes. i smell an XY 
> problem here. i wonder what the real goal is vs how to solve it this
> way.
> 
> thanx,
> 
> uri

I was thinking that too.


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: How to delete multiple indices from array

2017-04-12 Thread Shawn H Corey
On Wed, 12 Apr 2017 18:16:56 -0400
Uri Guttman <u...@stemsystems.com> wrote:

> On 04/12/2017 05:42 PM, Shawn H Corey wrote:
> > On Wed, 12 Apr 2017 16:19:32 -0400
> > Uri Guttman <u...@stemsystems.com> wrote:
> >
> >
> > my @array;
> >
> > for my $index (reverse sort @indices) {
> >> sort defaults to a lexical sort which won't work well on integers
> >> with more than 2 digits.
> >>
> >> and why are you sorting and reversing the indexes? i don't think
> >> that will help make the splice more efficient if any of the
> >> indexes are not at the end of the array.
> > If you're going to splice, do it from the highest index to the
> > lowest. Otherwise the splice will shift the end of the array down,
> > which messes up the indexing.
> but if the splice is not at the end of the array it doesn't save
> much. you still have to shift down multiple elements on each call to
> splice. maybe you shift down fewer as there are now fewer elements up
> top. anyhow, i was somewhat surprised to see splice was the fastest
> method. i feel there is something odd and maybe with a larger data
> set, that wouldn't be the case.
> 
> uri
> 

It's not about saving time. It's about removing a bug. In the code
below, notice that there are two different outputs depending on the
order that splice is applied. It's only by using descending indexing do
you get the correct deletions.

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

say "ascending indexing";
my @a = 'a' .. 'z';
say "@a";

splice( @a, 3, 1 );
say "@a";

splice( @a, 9, 1 );
say "@a";

say "descending indexing";
@a = 'a' .. 'z';
say "@a";

splice( @a, 9, 1 );
say "@a";

splice( @a, 3, 1 );
say "@a";

__END__

ascending indexing
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c e f g h i j k l m n o p q r s t u v w x y z
a b c e f g h i j l m n o p q r s t u v w x y z
descending indexing
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i k l m n o p q r s t u v w x y z
a b c e f g h i k l m n o p q r s t u v w x y z


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: How to delete multiple indices from array

2017-04-12 Thread Shawn H Corey
On Wed, 12 Apr 2017 16:19:32 -0400
Uri Guttman <u...@stemsystems.com> wrote:

> On 04/12/2017 04:08 PM, Илья Рассадин wrote:
> > Hi!
> >
> > You can use splice to delete elements from array.
> >
> > To delete multiple elements you need to do splice in a loop
> >
> > my @indices = qw/2 4 5 7/;
> 
> why are you using qw which makes strings and not a list of integers?

Because you don't have to type all those commas. ;)

> 
> >
> > my @array;
> >
> > for my $index (reverse sort @indices) {
> sort defaults to a lexical sort which won't work well on integers
> with more than 2 digits.
> 
> and why are you sorting and reversing the indexes? i don't think that 
> will help make the splice more efficient if any of the indexes are
> not at the end of the array.

If you're going to splice, do it from the highest index to the lowest.
Otherwise the splice will shift the end of the array down, which messes
up the indexing.

> 
> > splice @array, $index, 0;
> >
> >
> you need a length of 1 to remove the element. that line is a no-op.
> 
> uri
> 



-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: how to recursion

2017-03-29 Thread Shawn H Corey
On Wed, 29 Mar 2017 09:25:06 +0800
PYH <p...@vodafonemail.de> wrote:

> sub my_recursion {
>  my $self = shift;
>  
>  if (...) {
>  $self->my_recursion;

# you don't need $self. subroutine lookup starts
# in the same package. Just the sub by itself
# is good enough.
my_recursion();

>  }
> }

More thoughts on recursion:
https://lookatperl.blogspot.ca/2012/11/a-look-at-recursion.html


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Changing date format using carpout

2017-03-26 Thread Shawn H Corey
On Sun, 26 Mar 2017 11:28:44 -0700
SSC_perl <p...@surfshopcart.com> wrote:

> > On Mar 25, 2017, at 8:58 PM, Jim Gibson <jimsgib...@gmail.com>
> > wrote:
> > 
> > You could also try overriding the supplied function of the imported
> > module with your own version (not sure exactly how that is done).  
> 
>   Hmm… me neither, but it’s a good idea.  I’ll contact the
> maintainer of CGI::Carp to see if that could be added as a feature.

In Perl, anything is possible. I haven't tried anything like this but
it would mean replacing the subroutine after the module was loaded.

This is untested.

use CGI::Carp;
{
no warnings;
local *CGI::Carp::stamp = sub {
# new code
    }
}


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Using PerlPod creatively

2017-03-24 Thread Shawn H Corey
On Fri, 24 Mar 2017 00:17:33 -0700
Sami Joseph <sami.jos...@gmail.com> wrote:

> He would comment out the
> control codes (thus rendering the text interpretable) on the parts
> meant to run, which would differ between machines.

There are better ways to do this, at least in Perl.

You can use the $^O to determine the operating system. See
http://perldoc.perl.org/perlvar.html#%24OSNAME

You can use the environment variable to do conditional compiling.
# --
# Diagnostics

# conditional compile DEBUGging statements
# See

#http://lookatperl.blogspot.ca/2013/07/a-look-at-conditional-compiling-of.html
use constant DEBUG => $ENV{DEBUG};

To use it:
print "something\n" if DEBUG;


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Installing Net::SFTP

2017-03-15 Thread Shawn H Corey
On Wed, 15 Mar 2017 15:41:57 +0800
community tech <commun...@dnsbed.com> wrote:

> before that you may want to install SSLeay etc.
> 
> cpanm Net::SSLeay
> cpanm Crypt::SSLeay

I don't know about Crypt::SSLeary but Net::SSLeary needs two
libraries: `zlib1g` and `libssl`

I don't run RHEL but IIRC, the command is:

yum install zlib1g libssl


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: Uninitialized Value, but It Isn't, so Why?

2017-03-02 Thread Shawn H Corey
On Thu, 2 Mar 2017 16:35:17 -0600
Andy Bach <afb...@gmail.com> wrote:

> if ( not defined $interdest5 ) ...
> 
> defined() is the built in function. "undef" is a value ...  not sure
> why you don't get a syntax error there but, most likely, the if quits
> at seeing "undef" as it's "false"
> 
>  perl -we 'if (undef $interdest5) {$interdest5 = "";} print
> "$interdest5\n"' Use of uninitialized value $interdest5 in
> concatenation (.) or string at -e line 1.
> 
> $ perl -we 'if (undef $interdest5) {$interdest5 = "";} print "i:
> $interdest5\n"'
> Use of uninitialized value $interdest5 in concatenation (.) or string
> at -e line 1.
> i:
> $ perl -we 'if (undef eq $interdest5) {$interdest5 = "";} print "i:
> $interdest5\n"'
> Use of uninitialized value in string eq at -e line 1.
> Use of uninitialized value $interdest5 in string eq at -e line 1.
> i:
> $ perl -we 'if (undef == $interdest5) {$interdest5 = "";} print "i:
> $interdest5\n"'
> Use of uninitialized value $interdest5 in numeric eq (==) at -e line
> 1. Use of uninitialized value in numeric eq (==) at -e line 1.
> i:
> 
> Hah! "undef" is an uninitialized value !

$ perl -we 'if (not $interdest5) {$interdest5 = "";} print
"|$interdest5|\n"'
||
$ perl -we 'if (! $interdest5) {$interdest5 = "";} print
"|$interdest5|\n"'
||


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Uninitialized Value, but It Isn't, so Why?

2017-03-02 Thread Shawn H Corey
On Thu, 2 Mar 2017 12:29:42 -0600
Danny Spell <ddsp...@gmail.com> wrote:

> Line 57 is "last if ($interdest5 ne "");".
> 
> Why does Perl say it is uninitialized ?
> I thought I took care of that in two places. Once when it was
> declared and and again within the loop.

Because you assign it a value in this statement:

($interdest5) = $sth_mex->fetchrow_array();

Change your if statement to:

last if ! defined $interdest5;



-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: Converting string to float

2017-03-02 Thread Shawn H Corey
On Thu, 2 Mar 2017 16:50:32 + (UTC)
mailing lists via beginners <beginners@perl.org> wrote:

> $VAR1 = {
> 'work_hours_to_float_try3' => '5.2',
> 'work_hours_to_float_try2' => '4.1',
> 'work_hours' => '4.1',
> 'work_hours_to_float_try1' => '4.10'
> };
> {"work_hours_to_float_try3":"5.2","work_hours_to_float_try2":"4.1","work_hours":"4.1","work_hours_to_float_try1":"4.10"}
> 
> 
> As you can see, the values are strings (note the double quotes around
> the numeric values) and not floats. So the real question is how to
> output float numbers in this case.

Perl automatically converts from number to string and back.

When I try it, I get the following, which seems to be correct.

$VAR1 = {
  'work_hours' => '4.1',
  'work_hours_to_float_try1' => '4.10',
  'work_hours_to_float_try2' => '4.1',
  'work_hours_to_float_try3' => '5.2'
};
{"work_hours_to_float_try3":5.2,"work_hours_to_float_try1":"4.10","work_hours_to_float_try2":4.1,"work_hours":"4.1"}


-- 
Don't stop where the ink does.

Shawn H Corey

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




Free Books

2017-02-24 Thread Shawn H Corey
A short list of free Perl books.

https://www.ossblog.org/grasp-perl-open-source-books/


-- 
Don't stop where the ink does.

Shawn H Corey

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




Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?

2017-01-15 Thread Shawn H Corey
On Sun, 15 Jan 2017 12:09:53 -0800
al...@myfastmail.com wrote:

> What's wrong with the way I'm unpacking the arguments passed to the
> subroutine,
> 
>   my %args = %{ shift @_ };
> 
> Is there a different, recommended way?

Nothing's wrong. perlcritic does not this valid method, that's all.

TIMTOWTDI (There Is More Than One Way To Do It.)


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: Perl file exists check

2016-11-10 Thread Shawn H Corey
On Thu, 10 Nov 2016 12:15:48 +0100
jaceke <jac...@op.pl> wrote:

> sub escMe($) {

Don't use sub prototypes. There are not the same as in C. They do
something completely different. They are best not used until you know
what they really do. :)


-- 
Don't stop where the ink does.

    Shawn H Corey

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




Re: Regex for matching files that don't have type extensions

2016-11-05 Thread Shawn H Corey
On Sat, 05 Nov 2016 21:30:12 +
Aaron Wells  wrote:

> True. It could get hairy. Unicode is a pretty vast landscape, and I
> think if you only want ASCII word characters to count as things that
> could be in a filename, your original [A-Za-z0-9_] is your best bet.
> Thanks to the others for their comments. As Ken says: there are
> probably more ways to code this.

TIMTOWTDI
https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it

;)

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




Re: Re-exec in perl

2016-10-04 Thread Shawn H Corey
On Tue, 04 Oct 2016 19:32:44 +
"Chas. Owens" <chas.ow...@gmail.com> wrote:

> It looks like the problem exists at the C level as well.  This code
> doesn't work past the first alarm:

Doesn't it say the alarm has to be reset by the code in the
documentation? After all, you don't want a second alarm to go off
before the first handler is finished. If it did, there's a chance of an
infinite number of alarms to stack up, fill memory, and kill the
process.


-- 
Don't stop where the ink does.

Shawn H Corey
mailto:shawnhco...@nili.ca

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




Re: Email Sender timeout with more than two paragraphs of text in body

2016-10-03 Thread Shawn H Corey
On Mon, 3 Oct 2016 16:25:22 -0400
Uri Guttman <u...@stemsystems.com> wrote:

> > $text ="  
> use here documents for long multiline strings like that. it is hard
> to find a close quote after so many lines.

You can also use the qq operator

$text = qq{
...
};

If your editor have matching-brace abilities, you can use them with it.
See
http://perldoc.perl.org/5.8.9/perlop.html#Quote-and-Quote-like-Operators


-- 
Don't stop where the ink does.

Shawn H Corey
mailto:shawnhco...@nili.ca

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




Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
On Tue, 6 Sep 2016 22:08:40 +0200
David Emanuel da Costa Santiago <deman...@gmail.com> wrote:

> 
> 
> Thanks :-)
> 
> A little bug:
> 
> > my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 );
> my %HexCodes = map { chr($_) => sprintf '%02X', $_ } ( 0 .. 128 );
> 
> 
> 
> 

Oops. :)


-- 
Don't stop where the ink does.

Shawn H Corey
mailto:shawnhco...@nili.ca

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




Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
On Tue, 6 Sep 2016 17:01:52 -0400
Uri Guttman <u...@stemsystems.com> wrote:

> On 09/06/2016 04:42 PM, X Dungeness wrote:
> > It's kinda hard to see but I included the /x switch because
> > I inserted blanks on the pattern as well as the replacement
> > side. Without /x, the match will fail.
> >
> > $str =~ s{  ([^[:print:]])  }{ sprintf( "(%#2X)", ord $1) }gex;
> >   ^  ^  
> you are correct. /x affects whitespace in the pattern. i was stuck 
> thinking about the replacement part. in fact now that i am thinking 
> about it more clearly, /x doesn't affect the replacement at all.

True but /e does. ;)


-- 
Don't stop where the ink does.

Shawn H Corey
mailto:shawnhco...@nili.ca

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




Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
A little refinement.

On Tue, 6 Sep 2016 21:04:04 +0200
David Emanuel da Costa Santiago <deman...@gmail.com> wrote:

> If you want to replace all non printable characters you can do
> something like:
> 
> ### START
> 
> #Change the value to the maximum you want
> my %HEXCODES = map{$_ => sprintf("%03X", $_)} (0..128); 

my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 );

> 
> my $s="This is my string! \r\n the end";
> 
> say "String before: $s";
> 
> #Change the character class you want
> $s =~ s/([^[:print:]])/$HEXCODES{ord($1)}/g;

$s =~ s/([^[:print:]])/$HexCodes{$1}/g;

> 
> say "String after: $s";
> 
> END

__END__


-- 
Don't stop where the ink does.

Shawn H Corey
mailto:shawnhco...@nili.ca

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




Some Perl Links

2016-05-30 Thread Shawn H Corey
Here is a list of Perl links:

Official site http://www.perl.org/
Beginners' help   http://learn.perl.org/faq/beginners.html
Advance help  http://perlmonks.org/
News  http://perlsphere.net/
Documentation http://perldoc.perl.org/
Online Books  http://www.perl.org/books/library.html
Real World Books  http://learn.perl.org/books/
Repositoryhttp://metacpan.org/
Blog  http://blogs.perl.org/
Regional groups   http://www.pm.org/
Videoshttp://perltv.org/


-- 
Don't stop where the ink does.
Shawn

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




Re: Start a New Thread for a New Question (WAS: This is one of the things ...)

2016-05-13 Thread Shawn H Corey
On Fri, 13 May 2016 13:20:15 +
"Walker, Michael E"  wrote:

> Hi,
> 
> What framework are you all using for database development? When
> tracking this thread back to the original message, I thought, "Nice
> syntax." I am overall new to Perl, but am learning it for ETL at work.
> 
> Thanks,
> Mike

Hi Mike,

FYI: To get as many responses as possible, you should start a new thread
for a new question. If you tack onto a existing thread, some people will
read just the subject and skip it as not interesting. Starting a new
thread will get more people to read it. :)


-- 
Don't stop where the ink does.
Shawn

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




Re: This is one of the things ...

2016-05-13 Thread Shawn H Corey
On Fri, 13 May 2016 00:11:57 -0400
Uri Guttman  wrote:

> i stick to using fat comma ( => ) only for key/value pairs. it has
> the side effect of quoting a bareword to the left which makes those
> pairs easier to read. so i never use it just for a comma though i
> have seen it used like that. this is definitely a matter of taste and
> i know mine is better than most! :)
> 
> as for q{} i stick to using it when there are quote chars in the
> string. i haven't had trouble reading '' (vs "" vs q{}) as the null
> string. pick a better font if you have trouble! :) also context (not
> perl but code in general) should make it easier to know when a null
> string is being used.

Another method is to use `constant` since it creates constant subs
which perl replaces with the literal.

$ cat quotes.pl 
#!/usr/bin/env perl

use constant {
qSPACE=> q{ },
qCOMMA=> q{,},
qQUESTION => q{?},
};

my $holders = join qCOMMA, (qQUESTION) x @cgi_params;

$ perl -MO=Deparse ./quotes.pl 
use constant ({'qSPACE', ' ', 'qCOMMA', ',', 'qQUESTION', '?'});
my $holders = join(',', ('?') x @cgi_params);
./quotes.pl syntax OK


Notice in the join that qCOMMA and qQUESTION were replaced with the
literal.


-- 
Don't stop where the ink does.
Shawn

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




Re: This is one of the things ...

2016-05-12 Thread Shawn H Corey
On Thu, 12 May 2016 21:35:02 -0400
Uri Guttman  wrote:

>  my $holders = join ',', ('?') x @cgi_params ;
> 
> and i like here docs for sql so i can see the sql and not need all
> those quotes and noise.

PBP recommends that you put short strings that are all punctuation in
q{}, so they will be easier to read.

my $holders = join q{,}, (q{?}) x @cgi_params ;


-- 
Don't stop where the ink does.
Shawn

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




Re: Are there (non-obvious) differences in string quoting methods?

2016-04-07 Thread Shawn H Corey
On Thu, 7 Apr 2016 16:28:36 +1200
Kent Fredric  wrote:

> On 7 April 2016 at 07:20, Jonathon Fernyhough 
> wrote:
> >
> > qq{} obviously wins when there would otherwise be a lot of
> > escaping, but are there any downsides of using this method more
> > generally (other than double-quotes being two characters shorter)?
> > For example, is it "faster" for Perl to parse a double-quoted
> > string or does the compiler optimise this out so the methods are
> > fundamentally equivalent?
> 
> 
> In that regards you can get a reasonable look at how perl interprets
> your string with B::Deparse, partly because
> the deparse reversal shows it more "natively"
> 
> perl -MO=Deparse -e' print q[Helloo]'
> print 'Helloo';
> 
> perl -MO=Deparse -e' print qw[Helloo world]'
> print 'Helloo', 'world';
> 
> perl -MO=Deparse -e' print qq[Helloo world]'
> print 'Helloo world';
> 
>  perl -MO=Deparse -e' print q[Helloo world $var]'
> print 'Helloo world $var';
> 
> perl -MO=Deparse -e' print qq[Helloo world $var]'
> print "Helloo world $var";  <-- note double quotes
> 
>  perl -MO=Deparse -e' print qq[Helloo \Qwo)\E]'
> print 'Helloo wo\\)';
> 
> 
> 
> 

Not exactly. Perl converts the source code into an internal
representation. Since it does this only once, it is hard to determine
which is faster.

What Deparse does is scan the internal representation and convert it to
something readable. Its output is not the internal representation.


-- 
Don't stop where the ink does.
Shawn

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




Re: Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Shawn H Corey
On Wed, 6 Apr 2016 15:29:26 -0400
Uri Guttman  wrote:

> my rule is for the reader and not the computer. i try to use '' when
> i know there is no interpolation and "" when there is. i am telling
> the reader to either not look or to look inside the string.

PBP recommends that yo use q{} for single, non-alphanumerics, like
spaces.

eg:
my $SPACE = q{ };


-- 
Don't stop where the ink does.
Shawn

-- 
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 Shawn H Corey
On Fri, 18 Mar 2016 19:07:10 +0530
Prashant Thorat  wrote:

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

What have you tried so far?


-- 
Don't stop where the ink does.
Shawn

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




Re: reading directories using perl in windows

2016-03-13 Thread Shawn H Corey
On Sun, 13 Mar 2016 09:48:20 -0500
Mike Flannigan  wrote:

> 
> FYI, there is no error.  If the directory
> path has no spaces it works fine, if the directory
> path has spaces it prints the path up to the 1st space
> and just goes back to a cursor line.
> 
> 
> Mike

Yup. The default glob() function s based on the C-shell and spaces are
separators. If your file names have spaces, use the BSD glob. This will
replace glob() with one that allows spaces in the file names.

use File::Glob qw( :bsd_glob );

> 
> 
> On 3/6/2016 5:04 AM, beginners-digest-h...@perl.org wrote:
> > Subject:
> > Re: reading directories using perl in windows
> > From:
> > Akshay Mohit 
> > Date:
> > 3/1/2016 4:49 AM
> >
> > To:
> > Arghya Das 
> > CC:
> > Perl Beginners 
> >
> >
> > Could you please send the exact error which you are getting as I 
> > Copy/Pasted the exact code which you had given and it is working 
> > properly for me. I have only given the directory which is present
> > in my system.
> >
> > use strict;
> > use warnings;
> >
> > my $dir = "C:/Python_Exercise/*";
> > my @files = glob( $dir );
> >
> > foreach (@files ){
> >print $_ . "\n";
> > }
> 



-- 
Don't stop where the ink does.
Shawn

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




Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Shawn H Corey
On Tue, 8 Mar 2016 13:29:40 -0800
Kenneth Wolcott  wrote:

>   How do I call the built-in Perl sort function on an array of strings
> where the string is composed of one or more digits, followed by a tab
> which is followed by a string and I want the results to be sorted in
> reverse numeric order?

The best thing to do is write a sortkey function to extract the keys:

sub sortkey {
  my $value = shift @_;

  return split /\t/, $value, 2;
}

my @sorted = map { $_->[0] }
 sort { $b->[1] <=> $a->[1] || $a->[2] cmp $b->[2] }
 map { [ $_. sortkey( $_ ) ] }
 @list;


-- 
Don't stop where the ink does.
Shawn

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




Re: reading directories using perl in windows

2016-03-01 Thread Shawn H Corey
On Tue, 1 Mar 2016 15:53:15 +0530
Arghya Das  wrote:

> use warnings;
> 
> $dir = "c:/folder/*";my @files = glob( $dir );
> foreach (@files ){
>print $_ . "\n";}
> 
> 
> i am trying to read windows directory using above code but it gives
> errors in recognising tthe directory path. please help.

Does the directory path have spaces in its names? If so, glob() does
not work correctly. Use the BSD glob() instead.

   use File::Glob qw( :bsd_glob );

See `perldoc File::Glob` for details.
http://perldoc.perl.org/File/Glob.html


-- 
Don't stop where the ink does.
Shawn

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




Re: coding help

2016-03-01 Thread Shawn H Corey
On Tue, 1 Mar 2016 12:05:14 +0530
Arghya Das  wrote:

> $num = 1234;
> $sum = 0;
> 
> while ( $num != 0)
> {
> $rem = $num % 10;
> $sum = ( $sum * 10 ) + $rem;
> $num = $num / 10;

$num = int( $num / 10 );

> }
> 
> print $sum;
> 
> 
> 
> please tell what is wrong with the reverse number code .
> It prints Infinity.

See `perldoc -f int` for details.
http://perldoc.perl.org/functions/int.html


-- 
Don't stop where the ink does.
Shawn

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




Re: use of bless

2016-02-28 Thread Shawn H Corey
On Sun, 28 Feb 2016 08:59:20 +
rakesh sharma  wrote:

> 
> HI all
> 
> I am using object oriented perl and saw return self as well as bless
> being used According to docs bless returns the reference to self. Why
> should we use both statements in the new method
> 
> Sent from Mail for
> Windows 10
> 

Because the variable $self has no special meaning. You could use $this
instead. Or any other name. Or don't use one at all:

sub new {
  my $class = shift @_;

  return bless {}, $class;
}

See
http://perldoc.perl.org/perlobj.html#An-Object-is-Simply-a-Data-Structure


-- 
Don't stop where the ink does.
Shawn

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




Re: preventing concurrency between five different perl scripts

2016-02-24 Thread Shawn H Corey
On Wed, 24 Feb 2016 18:47:09 +0200
Shlomi Fish  wrote:

> Hello Kenneth,
> 
> On Tue, 23 Feb 2016 18:34:54 -0800
> Kenneth Wolcott  wrote:
> 
> > Hi;
> > 
> >   This seems like a very simple concept, but I'm not getting it, so
> > I'd like some help.
> > 
> >   So part of this is perl (not understanding readdir and/or glob
> > well enough) and part of it is not getting the logic right.
> > 
> >   I have five perl scripts.
> > 
> >   I do not want any of them running concurrently as they will use a
> > common resource which will cause corruption in the resource and will
> > probably consume too much CPU and/or RAM/ and/or I/O.
> 
> Why not just use flock - see
> http://perldoc.perl.org/functions/flock.html ?
> 

Some examples:

http://perltricks.com/article/2/2015/11/4/Run-only-one-instance-of-a-program-at-a-time/

http://www.perlmonks.org/?node_id=590619


-- 
Don't stop where the ink does.
Shawn

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




Re: Counter Help

2016-02-12 Thread Shawn H Corey
On Fri, 12 Feb 2016 12:08:07 -0500
Uri Guttman  wrote:

> hashes are very easy to learn. and once you get the hang of them you 
> will wonder why you waited so long.

If keeping the data ordering is important, use an array. Otherwise, use
a hash. :)


-- 
Don't stop where the ink does.
Shawn

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




Re: Regex to match "bad" characters in a parameter

2016-01-25 Thread Shawn H Corey
On Mon, 25 Jan 2016 16:16:40 -0800
SSC_perl  wrote:

>   I'm trying to find a way to trap bad item numbers.  I want to
> parse the parameter "itemid=" and then everything up to either an "&"
> or end-of-string.  A good item number will contain only ASCII
> letters, numbers, dashes, and underscores and may terminate with a
> "&" or it may not (see samples below).   The following string should
> test negative in the regex below:
> 
> my $QUERY_STRING = 'itemid=AT18C_AT18C=1';
> 
> but a string containing "itemid=AT18/C" should test positive, since
> it has a slash.
> 
>   I can catch a single bad character and get it to work, e.g.
> 
> if ( $QUERY_STRING =~ m| itemid= .*? [/]+? .*? &? |x ) {
> 
> but I'd like to do something like this instead to catch others:
> 
> if ( $QUERY_STRING =~ m| itemid= (?: .*? [^a-zA-Z0_-]+ .*? ) &? |x )
> { ...
> 
>   Unfortunately, I can't get it to work.  I've read perlretut,
> but can't see the answer.  What am I doing wrong?
> 
> Thanks,
> Frank
> 
> Here are a couple of test strings:
> 
> 'itemid=AT18C_AT18C=1=main.htm=1=1=detail.htm=asc'
> 
> 'c=detail.htm=AT18C'
> 
> 
> 
> 

Use the negative match operator !~

  if( $QUERY_STRING !~ m{ itemid = [-0-9A-Za-z_]+? (?: \& | \z ) }msx ){
print "bad: $QUERY_STRING\n";
  }


-- 
Don't stop where the ink does.
Shawn

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




Re: Is perl user specific

2016-01-06 Thread Shawn H Corey
On Wed, 6 Jan 2016 21:04:39 +0530
Ankita Rath  wrote:

> I am trying to execute some perl scripts. I am getting following
> error. But other user in the same server are not getting the error.
> So can anybody help me understanding this problem. And why other user
> are not getting the error.
> 
> Perl 5.008003 required--this is only version 5.00503, stopped at
> ../Modules/Modules_64/5.8.5/x86_64-linux-thread-multi/YAML/XS.pm line
> 26. BEGIN failed--compilation aborted at
> ../Modules/Modules_64/5.8.5/x86_64-linux-thread-multi/YAML/XS.pm line
> 26.

Type the following on a command line:

perl --version

It will say something like:

This is perl 5, version 5,...

The version number must be 8 or higher to use XAML::Xs


-- 
Don't stop where the ink does.
Shawn

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




Re: scp_put failing when there are too many files

2015-12-11 Thread Shawn H Corey
On Fri, 11 Dec 2015 16:28:39 +0100
Ori Raz  wrote:

> Hi,
> Did anyone encounter the scenario where scp_put is failing (too many
> arguments) when the directory contains too many files?
> We have 36K files in the directory and it is failing... (with lower
> amount it works fine)
> 
> This is how we use it:
> $dr_node->scp_put( { recursive => 1,
> glob => 1,
> copy_user_attrs => 1 } ,
> "$ib_backup_path/*",$ib_backup_path );
> 
> And we get the error:
> Can't exec "rsync": Argument list too long at
> /perl/lib/perl5/site_perl/5.16.0/Net/OpenSSH.pm line 1433
> 
> Appreciate any advise :)
> 
> Thanks.

rsync(1) is a UNIX utility http://linux.die.net/man/1/rsync Because of
this, the only solution I can think of is to do one file at a time. Set
up a loop to read their names and send them on at a time.


-- 
Don't stop where the ink does.
Shawn

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




Re: scp_put failing when there are too many files

2015-12-11 Thread Shawn H Corey
On Fri, 11 Dec 2015 19:55:15 +0200
Shlomi Fish  wrote:

> Of note here is Rob Pike's note about the argument list being limited
> in size on UNIX-systems here:

Yeah but usually it's a high number like 32767. :)


-- 
Don't stop where the ink does.
Shawn

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




Re: regex problem?

2015-11-25 Thread Shawn H Corey
On Wed, 25 Nov 2015 17:22:04 +
Andrew Solomon  wrote:

> The only problem I can see is that you want UPPERCASE-1234 and your
> regex has lowercase. Try
> 
> (\A[A-Z]+)   # match and capture leading alphabetics

Please put the anchor outside the capture. And you could use the POSIX
conventions:

m{ \A ([[:upper:]]+) }msx;

This will work with non-English characters. :)


-- 
Don't stop where the ink does.
Shawn

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




Re: passwords in Perl

2015-10-27 Thread Shawn H Corey
On Tue, 27 Oct 2015 12:25:38 -0400
shawn wilson  wrote:

> Oh, and this is one place where you *don't* give lots of details of
> what went wrong. Don't say "invalid user", don't say "bad password",
> say "Bad username or password". and exit 1 if your failure is at a cli
> - that's it

Print the error message and then sleep for 5 seconds. This is to slow
down automated guessers.


-- 
Don't stop where the ink does.
Shawn

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




Re: Multi line file handling

2015-10-19 Thread Shawn H Corey
On Mon, 19 Oct 2015 19:48:06 +0530
Prashant Thorat  wrote:

> Hi All,
> 
> I have a file with multiple lines ,I want to assign all content to
> variable & then want to work on it.
> Like want to match pattern /window/ from it.
> how can it is possible ?
> for example -
> 
> open ( F1 ,"file.txt") || die "$!";
> 
> $a=;
> 
> if (/window/i){print
> "it is present\n";
> }

use autodie;  # dies when I/O error occurs

my $file = 'file.txt';  # write literals once so they are easy
# to find and change
my $contents = '';  # holds contents of $file

# use a block to isolate the INPUT_RECORD_SEPARATOR
{
local $/; # file slurp mode
open my $fh, '<', $file;  # three-argument open
$contents = <$fh>;# slurps the whole file into $contents
close $fh;# in case of input error,
  # give it a chance to report
}

if( $contents =~ /window/i ){
print "it is present\n";
}

# see `perldoc perlvar` and search for /INPUT_RECORD_SEPARATOR
# http://perldoc.perl.org/perlvar.html


-- 
Don't stop where the ink does.
Shawn

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




Re: access hash in specific sequence

2015-09-03 Thread Shawn H Corey
On Thu, 3 Sep 2015 17:42:48 +0100
Gary Stainburn  wrote:

> I have a hash of hashes which I converted to an array of hashes
> because I needed to access them in a specific sequence.  It now looks
> like
> 
> my @pagetypes=(
>   {'pagetype'=>'Delivery  Note','weight'=>2,.
>   {'pagetype'=>'Sales Invoice','weight'=>2,.
>   {'pagetype'=>'Purchase Invoice','weight'=>2,.  
> ..
> 
> I then access the array using
> 
> foreach my $pt (@pagetypes) {

Each item of the array is a reference to a hash. It helps if you add
the suffix `_href` for hash references (and `_aref` for array
references).


foreach my $pt_href ( @pagetypes ){
my $pagetype = $pt_href->{pagetype};


-- 
Don't stop where the ink does.
Shawn

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




Re: Perl beginner

2015-07-30 Thread Shawn H Corey

FYI: some useful Perl links.

• Official site http://www.perl.org/
• Beginners' help http://learn.perl.org/faq/beginners.html
• Advance help http://perlmonks.org/
• News http://perlsphere.net/
• Documentation http://perldoc.perl.org/
• Online Books http://www.perl.org/books/library.html
• Real World Books http://learn.perl.org/books/
• Repository http://metacpan.org/
• Blog http://blogs.perl.org/
• Regional groups http://www.pm.org/
• Videos http://perltv.org/


-- 
Don't stop where the ink does.
Shawn

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




Re: convert linear array to nested structure

2015-07-21 Thread Shawn H Corey
On Tue, 21 Jul 2015 13:35:37 -0700
Jim Gibson j...@gibson.org wrote:

 The data structure you have shown is not very efficient in tems of
 data storage. Is this the actual data structure, or is it part of
 something more complicated. For exampe, a more efficient use of space
 would be this, which uses nested arrays instead of hashes:
 
 [ 
  [0, “string1],
  [1, “string2],
  [2, “string3],
  [2, “string4]
 ]

my @data = (
[ string1 ],
[ string2 ],
[ string3, string4 ],
);

Each string is pushed onto the anonymous array at its level.

my @data = ();
for my $pair ( @$original ){
push @{ $data[ $pair-{level} ]}, $pair-{value};
}


-- 
Don't stop where the ink does.
Shawn

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




Re: Display a hash in the order of an array

2015-07-17 Thread Shawn H Corey
On Fri, 17 Jul 2015 15:11:13 +0200
Vincent Lequertier s...@riseup.net wrote:

 Hi,
 
 I have the following structure :
 
 $hash{$date} = {
  'ip' = $ip,
  'action'   = $action,
  };
 
 witch produce data like :
 
 $VAR1 = '[15/Jul/2015:10:30:03 +0200]';
 $VAR2 = {
'ip' = 'xxx.xxx.xxx.xxx',
'action' = 'GET xxx'
  };
 
 and an array of ip addresses, say @ip
 
 My question is how can I display the content of %hash in the order of 
 @ip, assuming %hash has the same length as @ip ?
 
 Thank you
 

UNTESTED:

sub ip_cmp {
  my @ip_a = split /\./, $a;
  my @ip_b = split /\./, $b;

  for my $i ( 0 .. 3 ){
my $cmp = ( $ip_a[$i] || 0 ) = ( $ip_b[$1] || 0 );
return $cmp if $cmp != 0;
 }
  return 0;
}

for my $hash_ref ( sort ip_cmp keys %hash ){
# display $hash_ref-{$date}
}


-- 
Don't stop where the ink does.
Shawn

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




Re: Debugging and passing constant value at run time

2015-07-07 Thread Shawn H Corey
On Tue, 7 Jul 2015 11:40:35 +
Sharanbasappa Raghapur, ERS, HCLTech shar...@hcl.com wrote:

 I am using constant mainly to enable printing of debugging messages
 (e.g. use constant DEBUGGING_L1 = 0;) Normally, the value is '0' and
 when I need to see debug messages, I make this 1 and run the script.
 
 Is there a way to allocate value to constants at run time so that I
 can avoid editing the script again and again? Also, is there a better
 way to handle debugging?

Yup, see
http://lookatperl.blogspot.ca/2013/07/a-look-at-conditional-compiling-of.html


-- 
Don't stop where the ink does.
Shawn

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




Re: Debugging and passing constant value at run time

2015-07-07 Thread Shawn H Corey
On Tue, 7 Jul 2015 07:27:49 -0700 (PDT)
Ron Bergin r...@i.frys.com wrote:

 Using a DEBUG constant and assigning its value via an environment
 variable are both common, but has a drawback and would not be my
 choice of approach. I prefer to use a lexical var (with file scope)
 and assign it via command line option. 

Using a variable has the drawback that the debug code is compiled.
Using a constant sub means the debug code is not compiled.


-- 
Don't stop where the ink does.
Shawn

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




Re: Customized Module Concept

2015-07-03 Thread Shawn H Corey
On Fri, 3 Jul 2015 12:48:22 +0530
ayush kabra ayush.kab...@gmail.com wrote:

 Hi Team,
 
 I want to make customized module on perl but i don't know how to make
 it. i have checked on google but it's little bit confusing. i am not
 able to understand what is the meaning of EXPORTER_OK ,IMPORT and
 there is lot of thinh which i am not able to understand. Can you
 please send me some examples of cusotmized module and explain it's
 functionality. what is the work of @ISA, and @INA path?.
 
 Please help me on this.
 
 Thanks in Advance...!!
 
 
 Regards,
 Ayush Kabra

Here's the code I use:

# --
# Exports
use  Exporter  qw( import );
our @EXPORT  = qw( );
our @EXPORT_OK   = qw( );
our %EXPORT_TAGS = (
  all  = [ @EXPORT, @EXPORT_OK ],
);

# --

@EXPORT is the list of default exports. @EXPORT_OK is the list of
everything that can be exported.


-- 
Don't stop where the ink does.
Shawn

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




Re: Getting 2/8 as output

2015-06-17 Thread Shawn H Corey
On Wed, 17 Jun 2015 08:29:10 -0500
Mike Flannigan mikef...@att.net wrote:

 If I am not mistaken there is no $, variable in Perl.
 Correct me if I am wrong.

http://perldoc.perl.org/perlvar.html and search
for /\$OUTPUT_FIELD_SEPARATOR/


-- 
Don't stop where the ink does.
Shawn

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




Re: Strange

2015-06-12 Thread Shawn H Corey
On Fri, 12 Jun 2015 07:43:59 +0200
Jerry Rocteur mac...@rocteur.cc wrote:

 What happened to the list ? Where has everybody gone to ?

stackoverflow.com


-- 
Don't stop where the ink does.
Shawn

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




Re: When is qw used

2015-06-10 Thread Shawn H Corey
On Wed, 10 Jun 2015 17:49:44 +0530
rakesh sharma rakeshsharm...@hotmail.com wrote:

 I have seen perl syntax like use Carp qw(some list items)so when do
 we need to write like this and why is not the items of the module
 getting imported

As others have said, to import a selected set of functions or to import
functions not in the default import.

Also:

use Carp qw( :all );

Will import everything. Most modules (standard modules and CPAN ones)
will have the tag `:all` to import everything.

If you don't want to import any:

use Carp ();

To use a function in Carp, you would use the fully-qualified name:

Carp::croak ribbit;


-- 
Don't stop where the ink does.
Shawn

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




Re: Compilation fails with Padre (a Perl IDE) on RHEL-based distros (CentOS, etc.)

2015-05-26 Thread Shawn H Corey
On Tue, 26 May 2015 11:53:55 -0400
someone called someonecal...@safe-mail.net wrote:

 I tried but failed (wxWidgets is a requirement of Padre) as root:

Wx requires some development libaries: libgconf*-dev libgtk*-dev
libgstreamer*dev libgstreamer-plugins-base*-dev

where * is to be replace with the version number, if any. Without the
*.h files for these libraries, you will not be able to compile
WxWidgets.

 
 yum install cpan perl-ExtUtils-Embed make gcc g++ wxGTK-devel.x86_64
 # done, OK cpan YAML # done, OK
 
 and the problem:
 
 [root@notebook ~]# cpan Alien::wxWidgets
 Sorry, we have to rerun the configuration dialog for CPAN.pm due to
 some missing parameters...
 ...
 Building Alien-wxWidgets
 
 ATTENTION: It apperars 'g++' is not a working compiler, please make
 sure all necessary packages are installed.

This may be a problem with g++ or it may be missing *.h files. Missing
*.h files can give strange, unrelated error messages.


-- 
Don't stop where the ink does.
Shawn

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




Re: Can u suggest me the best ide for perl

2015-05-21 Thread Shawn H Corey
On Thu, 21 May 2015 10:21:07 +0200
Li Xue me.li...@gmail.com wrote:

 Just realized that I replied only to Gary. Here is how to use vim as
 perl IDE. VIM-based perl IDE is my favoriate because it saved me lots
 of time in debugging and in tidying up my code. I used eclipse before
 and the perl plugin is too buggy and too slow.
 
 Two things you need to do to configure vim for perl:
 
 1.  https://www.youtube.com/watch?v=DrzAuLsxgwU
 2. perl-support: http://www.vim.org/scripts/script.php?script_id=556
 
 Li
 

There is also Padre http://padre.perlide.org/, an IDE written in Perl
(and WxWidgets) for Perl (and other languages).


-- 
Don't stop where the ink does.
Shawn

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




Re: Removing text

2015-05-18 Thread Shawn H Corey
On Mon, 18 May 2015 17:32:03 +0200
Richard Taubo o...@bergersen.no wrote:

 Hi!
 
 Trying to remove the literal text %st from the command line return
 value: 0.0%st as in:
 [$] printf 0.0%st | perl -pe 's/\%st//'
 
 I have also tried: 
 
 [$] printf 0.0%st | perl -pe 's/\Q%st\E//'
 
 Neither works.
 
 Would be happy if someone had any input here! :-)
 
 Thanks!
 
 Richard Taubo

I'm not sure what you're trying to do but if you want a percent sign in
a printf specification, use two of them.

printf Sale: %d%% off, $percentage_off;

See `perldoc -f sprintf`
http://perldoc.perl.org/functions/sprintf.html


-- 
Don't stop where the ink does.
Shawn

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




Re: Perl array question

2015-05-06 Thread Shawn H Corey
On Wed, 6 May 2015 12:49:53 +0530
Anirban Adhikary anirban.adhik...@gmail.com wrote:

 Hi List
 I have the following array ---
 ('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
 There are two part for each element separated by a dash.
 first one known as earfcn and second one is pcid .
 The requirement is  For the same “earfcn”, concatenate the “pcid”
 values using  separator between values.
 so the output will be like this
 EARFCN=1900,PCID=0124;
 EARFCN=1902,PCID=5678;
 
 I am not able to generate any idea how to adress this isuue. Please
 give me some starting point.
 
 Best Regards
 Anirban.

Unlike everyone else, I would used nested hashes. Why? Because then the
code can hand duplicates.

#!/usr/bin/env perl

use strict;
use warnings;

my @data =
('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
my %hash = ();

# load the data structure
for my $item ( @data ){
  if( my ( $earfcn, $pcid ) = $item =~ m{ \A ( \d+ ) \- ( \d+ ) \z }msx ){ 
  $hash{$earfcn}{$pcid} ++;
  }
}

# output the data
for my $earfcn ( sort { $a = $b } keys %hash ){
  my @pcids = ();
  for my $pcid ( sort { $a = $b } keys %{ $hash{$earfcn} } ){
for my $count ( 1 .. $hash{$earfcn}{$pcid} ){
  push @pcids, $pcid;
}
  }
  print EARFCN=$earfcn,PCID=, join( q{}, @pcids ), \n;
}


-- 
Don't stop where the ink does.
Shawn

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




Re: Need explanation of code

2015-04-12 Thread Shawn H Corey
On Sat, 11 Apr 2015 21:20:22 -0700
SSC_perl p...@surfshopcart.com wrote:

   Could someone please explain the difference between:
 
 %{$self-{'DATA'}} = () }

  %{ $self-{'DATA'} } = ();

 
 and
 
 $self-{'DATA'} = {}
 
   I was told that they are equivalent, but they're not.  One
 works and the other doesn't, so they must be different.  Here's the
 context:

No, they are not the exact same, as this snippet of code shows:

  my $self = { DATA = 1 };
  %{ $self-{'DATA'} } = ();

If $self-{DATA} does not exist, then they are the same because Perl
does autovivification. To get the first one to behave like the second,
you should delete $self-{DATA}

  delete( $self-{DATA} );
  %{ $self-{'DATA'} } = ();



-- 
Don't stop where the ink does.
Shawn

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




Re: How to handle null elements inside an array

2015-04-02 Thread Shawn H Corey
On Thu, 2 Apr 2015 08:34:37 -0700
SSC_perl p...@surfshopcart.com wrote:

 On Apr 2, 2015, at 7:43 AM, Anirban Adhikary wrote:
  When I am trying to split the line based on whitespace
  @elements = split(/\s+/,$line);
 
   It will be interesting if someone can come up with a solution
 to this, but I don't see one.  If your separator is whitespace, then
 the split has nothing to work with if some values are blank.  You'd
 need to add some kind of separator between your values, like a tab,
 or a comma, or something else unique that you can split it on.
 
   What kind of a file is this information in?  If it's in
 something like Excel, then, of course, you could just re-export it
 with another separator.  However, if it's in a simple text file, you
 may have to add them by hand.  I copied your data into a text file
 and it looks like you have an arbitrary number of spaces between your
 data (though that could just be the formatting from the email).  I
 thought that if the spacing was consistent, then you could count the
 number of spaces, but it doesn't look like that will work, either.
 
   Am I missing something?
 

From what the OP posted, I think these are fixed-field records. The
best way to handle fixed-field records is using `substr` or `unpack`.

See:
perldoc -f substr  http://perldoc.perl.org/functions/substr.html
perldoc -f unpack  http://perldoc.perl.org/functions/unpack.html
perldoc -f packhttp://perldoc.perl.org/functions/pack.html



-- 
Don't stop where the ink does.
Shawn

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




Re: Good books to study perl interpreter

2015-03-30 Thread Shawn H Corey
On Mon, 30 Mar 2015 22:12:51 +0530
rakesh sharma rakeshsharm...@hotmail.com wrote:

 Hi all
 
 Please suggest nice books to know perl interpreter. In depth books is
 that i am looking for.
 
 Thanks
 Rakesh

FYI: some useful Perl links.
• Official site http://www.perl.org/
• Beginners' help http://learn.perl.org/faq/beginners.html
• Advance help http://perlmonks.org/
• News http://perlsphere.net/
• Documentation http://perldoc.perl.org/
• Online Books http://www.perl.org/books/library.html
• Real World Books http://learn.perl.org/books/
• Repository http://metacpan.org/
• Blog http://blogs.perl.org/
• Regional groups http://www.pm.org/
• Videos http://perltv.org/


-- 
Don't stop where the ink does.
Shawn

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




Re: Regular Expression Help.

2015-03-25 Thread Shawn H Corey
On Wed, 25 Mar 2015 10:31:40 +0530
Frank Vino vinofra...@gmail.com wrote:

 Hi Team,
 
 How to understand Regular Expression in a easy way?
 
 Thanks,
 Frank

Sorry Frank but there's no easy way. ☹

Some things to remember:

Some punctuation marks have special meaning, like periods, question
marks, and asterisks. But if there is a backslash before them, then
they match themselves. This is true for all punctuation marks.

And the opposite is true for ASCII letters and numbers. A backslash
before them may give them special meaning but if there is none, then
they match themselves.


-- 
Don't stop where the ink does.
Shawn

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




Re: $CONFIG_FILE

2015-02-20 Thread Shawn H Corey
On Fri, 20 Feb 2015 13:38:42 +0100
nicolas  nicolas...@mail.com wrote:

 jupiter@jupiter-OptiPlex-755:~/Documents/base-0.50#36; ./base.pl -i
 words Global symbol #36;CONFIG_FILE requires explicit package name
 at vowCons2.pm line 18. 

Go to line 18 of vowCons2.pm and change: #36;CONFIG_FILE
to: $CONFIG_FILE


-- 
Don't stop where the ink does.
Shawn

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




Re: Finding my localtime

2015-02-04 Thread Shawn H Corey
On Wed, 4 Feb 2015 11:21:32 -0800
SSC_perl p...@surfshopcart.com wrote:

 I'm trying to break out a timestamp into it's appropriate fields,
 like so:
 
 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
 localtime($my_time);
 
 but no matter if I use localtime or gmtime, $my_time gets analyzed as
 either in the server's timezone or in UTC.  I need to break apart the
 timestamp in $my_time without it being changed.  In other words, I'm
 trying to get $hour, $min, $sec, etc, in _my_ timezone, not the
 server's nor in UTC.

Have you read `perldoc perllocale` especially the `setlocale` function?
http://perldoc.perl.org/perllocale.html#The-setlocale-function


-- 
Don't stop where the ink does.
Shawn

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




Re: Debug when script WILL NOT RUN

2015-02-02 Thread Shawn H Corey
On Mon, 02 Feb 2015 11:54:12 -0500
Harry Putnam rea...@newsguy.com wrote:

 Are we even talking about the same program... Perl::Critic/perlcritic?
 
 For me, it just blows up with piles of help information when I use
 `-c':

Use the -c option with `perl`, not `perlcritic`.

Perl::Critic is the Perl module that you can use in a Perl script to
give it the same functionality.

`perlcritic` is a Perl script that is install when you install
Perl::Critic and it uses the module to examine other Perl scripts.

Hope that helps. :)


-- 
Don't stop where the ink does.
Shawn

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




Re: Debug when script WILL NOT RUN

2015-02-01 Thread Shawn H Corey
On Sun, 1 Feb 2015 14:08:24 + (UTC)
ThankGod Ebenezer thankgod1...@yahoo.co.uk wrote:

 Please can you remove me from this list?

No. But see the link below; the one marked unsubscribe. :)


-- 
Don't stop where the ink does.
Shawn

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




Re: Debug when script WILL NOT RUN

2015-02-01 Thread Shawn H Corey
On Sun, 1 Feb 2015 00:10:30 -0800
Charles DeRykus dery...@gmail.com wrote:

 One good sleuthing tool is perltidy (perltidy.sourceforge.net) which
 is good at unraveling a rat's nest of errors to  tease out the
 culprit:

You can also download and install with `cpan`:

cpan Perl::Tidy

Another good tool to have is is `perlcritic`. It can also be downloaded
and install with `cpan`:

cpan Perl::Critic

See:
http://metacpan.org/pod/distribution/Perl-Tidy/lib/Perl/Tidy.pod
http://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy
http://metacpan.org/pod/Perl::Critic
http://metacpan.org/pod/distribution/Perl-Critic/bin/perlcritic


-- 
Don't stop where the ink does.
Shawn

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




Re: Debug when script WILL NOT RUN

2015-02-01 Thread Shawn H Corey
On Sun, 01 Feb 2015 11:12:46 -0500
Harry Putnam rea...@newsguy.com wrote:

 Shawn H Corey shawnhco...@gmail.com writes:
 
  http://metacpan.org/pod/Perl::Critic  
 
 Feeding my sorry script to the advertised webpage like by using the
 posted method of testing Perl::Critic with no installation.

I have installed Perl::Critic on my machine. To use it, I just run
perlcritic:

perlcritic file


-- 
Don't stop where the ink does.
Shawn

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




Re: Debug when script WILL NOT RUN

2015-02-01 Thread Shawn H Corey
On Sun, 01 Feb 2015 18:07:18 -0500
Harry Putnam rea...@newsguy.com wrote:

 Shawn H Corey shawnhco...@gmail.com writes:
 
  On Sun, 01 Feb 2015 11:12:46 -0500
  Harry Putnam rea...@newsguy.com wrote:
 
  Shawn H Corey shawnhco...@gmail.com writes:
  
   http://metacpan.org/pod/Perl::Critic  
  
  Feeding my sorry script to the advertised webpage like by using the
  posted method of testing Perl::Critic with no installation.
 
  I have installed Perl::Critic on my machine. To use it, I just run
  perlcritic:
 
  perlcritic file
 
 Does it have to be fed a *.pm type file or will any perlscript work.
 
 Does the script have to run beyond compilatiom phase, to get helpful
 output?
 
 

It works with any file, even those that aren't Perl scripts (expect a
lot of errors).

As Paul Johnson says, try it with the -c option first but note:

-c   causes Perl to check the syntax of the program and then exit
without executing it. Actually, it will execute and BEGIN,
UNITCHECK, or CHECK blocks and any use statements: these are
considered as occurring outside the execution of your program.
INIT and END blocks, however, will be skipped.

All of perl's command-line options can be found in `perldoc perlrun`
http://perldoc.perl.org/perlrun.html#Command-Switches


-- 
Don't stop where the ink does.
Shawn

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




Re: question of what can respond to die [...]

2015-01-27 Thread Shawn H Corey
On Tue, 27 Jan 2015 10:48:43 -0500
Brandon McCaig bamcc...@gmail.com wrote:

 It would not be very pleasant if most things die() on error because
 errors are normal and usually we don't want robust programs to crash
 when something innocent fails, nor do we want to have to wrap every
 error that we can recover from with eval blocks (i.e., similar to
 try...catch in other languages) to handle errors.

`die` is Perl's way to throw exceptions. Avoiding `die` is avoid
exceptions.


-- 
Don't stop where the ink does.
Shawn

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




Re: question of what can respond to die [...]

2015-01-27 Thread Shawn H Corey
On Tue, 27 Jan 2015 09:37:15 -0500
Harry Putnam rea...@newsguy.com wrote:

 #!/usr/local/src/test/bin/perl
 
 use strict;
 use warnings;
 use Cwd 'abs_path';
 
 my $tdir = shift;
 

You can use `-e` to determine if the path exists and `-d` to determine
if it's a directory. See `perldoc -f -X` and search for /-e/ and /-d/,
http://perldoc.perl.org/functions/-X.html


 $tdir = abs_path($tdir)  or die Can't find  $tdir: $!;
 
 chdir $tdir or die Can't chdir $tdir: $!;
 
 print Hello from $tdir\n;


-- 
Don't stop where the ink does.
Shawn

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




Re: Looping regexes against a list

2015-01-20 Thread Shawn H Corey


What the OP should do is put the regexes in a Perl module and unroll
the loop. That way, he can group them so that groups of tests are
skipped:

# strings containing foo
if( /foo/ ){
return food if /food/;
return fool if /fool/;
return foot if /foot/;
return foo;
}


-- 
Don't stop where the ink does.
Shawn

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




Re: Looping regexes against a list

2015-01-20 Thread Shawn H Corey
On Tue, 20 Jan 2015 10:23:42 -0500
Brandon McCaig bamcc...@gmail.com wrote:

 On Tue, Jan 20, 2015 at 10:21 AM, Brandon McCaig bamcc...@gmail.com
 wrote:
  perldoc -f qr//
 
 I was sure that worked in my up-to-date perlbrew environments, but it
 isn't working in Cygwin running perl 5.14.2 so in the event that it
 doesn't work for you look at `perldoc -f qr' and `perldoc perlop'
 (then search for qr/STRING or something to that effect).
 
 Regards,
 
 

Try leaving the slashes off: perldoc -f qr


-- 
Don't stop where the ink does.
Shawn

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




Re: Looping regexes against a list

2015-01-20 Thread Shawn H Corey
On Tue, 20 Jan 2015 17:47:58 +
Mike Martin m...@redtux.org.uk wrote:

 Take a load of Job Vacancy posts (xml files - loads of)
 Parse the Information, getting rid of as much garbage as possible
 Push a distinct list into a lookup hash

If you're running Linux (or any POSIX), see `man sort` and search
for /-u/

Since sort(1) is fully compiled, it should be faster than a Perl hash,
especially for long lists.

 Do replace to this list against a long list of regexes

This will create a cross-product table. That means each pair has to be
tested. Nobody has found a way to reduce this.

 Spit out nicely formatted Clean Job Titles


-- 
Don't stop where the ink does.
Shawn

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




Re: Looping regexes against a list

2015-01-19 Thread Shawn H Corey
On Mon, 19 Jan 2015 15:57:35 +
Andrew Solomon and...@geekuni.com wrote:

 On Mon, Jan 19, 2015 at 2:50 PM, Mike Martin m...@redtux.org.uk
 wrote:
  The lookup hash is like this
  %clean=(
  HeatingEngineer =  (?:Heating.*?Engineer)\b.*?
  HGV  
  Driver=(?=\A(?:(?!tech|mech).)*$)(?:HGV|LGV|Class.?1|Class.?2).?(?:1|2|3|)(?:.+Driver|).*?

  HGV Mechanic=
  (?:(?:HGV|LGV|Lorry).+(?:Mech?anics?|technicians?))\b.*? Highway
  Engineer= (?:(?:Highway.?) (?:Engineer.?))\b.*? Highway Technician
  = (?:Highway.?) (?:Technician.?)\b.*? )
 

Please tell me that this is _not_ in a text file.

The idea of placing configuration options in a file was for compiled
programs. Since the end user may not have the source, being able to
change the configurations via a text file is a good method.

But since this has regular expressions, it can only be changed by a
programmer, which means, it should be in a Perl module.


-- 
Don't stop where the ink does.
Shawn

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




Re: Looping regexes against a list

2015-01-19 Thread Shawn H Corey
On Mon, 19 Jan 2015 11:18:01 -0500
bill pemberton wape...@gmail.com wrote:

 I fail to see why a regex can only be changed by a programmer.  please
 expand upon this.

Regex is a programming language in its own right. Why should an
average user have any knowledge of it?


-- 
Don't stop where the ink does.
Shawn

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




Re: Looping regexes against a list

2015-01-19 Thread Shawn H Corey
On Mon, 19 Jan 2015 11:43:41 -0500
John Mason john.mason...@gmail.com wrote:

 On Mon, Jan 19, 2015 at 11:36 AM, Shawn H Corey
 shawnhco...@gmail.com wrote:
 
  On Mon, 19 Jan 2015 11:18:01 -0500
  bill pemberton wape...@gmail.com wrote:
 
   I fail to see why a regex can only be changed by a programmer.
   please expand upon this.
 
  You shouldn't blindly trust input from a user, there should be
 checking/limits on what input is allowed .
 
 John

Why would the average user have access to something he is not trained
to understand?


-- 
Don't stop where the ink does.
Shawn

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




Re: Parsing multi column files

2015-01-18 Thread Shawn H Corey
On Sun, 18 Jan 2015 19:00:05 -0500
Mike ekimduna...@gmail.com wrote:

 sub gen_ins {
  open(FH, '', 'insults2.txt') or die [-] ERROR: Can't find
 insult list.;
  my @cols = split ( , FH);
  print $cols[0];
  close FH;
 }
 
 gen_ins();
 
 When currently run, gen_ins() will print out the first word of the
 given column: $cols[0], $cols[1], or $cols[2]. How can I access the
 rest of the words below the first?

You would need an array for each column:

my $MAX = 10;

my @first = ();
my @second = ();
my @third = ();

sub get_columns {
my $file = shift @_;

open my $fh, '', $file or die could not open $file: $!\n;
while( $fh ){
my @items = split;
push @first, $items[0];
push @second, $items[0];
push @third, $items[0];
}
close $fh or die could not close $file: $!\n;
}

get_columns( 'insults2.txt' );

for ( 1 .. $MAX ){
my @line = (
 @first[rand(@first)],
 @second[rand(@second)],
 @third[rand(@third)],
   );
print @line\n;
}


-- 
Don't stop where the ink does.
Shawn

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




Re: Using regular expressions to populate a variable?

2015-01-18 Thread Shawn H Corey
On Sun, 18 Jan 2015 11:49:11 -0500
Mike ekimduna...@gmail.com wrote:

 Hey everyone, I'm trying to find information on how I can use regular 
 expressions to populate a variable.
 
 I want to pull text between one set of characters and another set of 
 characters and use that to populate my variable. Can anyone point me
 in the right direction?
 
 Thanks.
 

Use parentheses to select the part of the match you want in your
variables: 

my ( $var1, $var2, @rest ) =~ /some characters(populates $var1)more
characters(populates $var2) more (populates @rest) more (populates
@rest) /;


See `perdoc perlre` and search for /Capture groups/
http://perldoc.perl.org/perlre.html#Capture-groups


For more info:
perldoc perlretuthttp://perldoc.perl.org/perlretut.html
perldoc perlrequick  http://perldoc.perl.org/perlrequick.html
perldoc perlre   http://perldoc.perl.org/perlre.html


-- 
Don't stop where the ink does.
Shawn

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




Re: How does opendir/readdir process files

2015-01-15 Thread Shawn H Corey
On Thu, 15 Jan 2015 17:27:03 -0500
Harry Putnam rea...@newsguy.com wrote:

 When Brandan said that to me... other than the RTFM it sailed right
 over my head... so what does  tl;dr mean?

tl;dr == too long; didn't read


-- 
Don't stop where the ink does.
Shawn

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




Re: How does opendir/readdir process files

2015-01-14 Thread Shawn H Corey
On Tue, 13 Jan 2015 22:40:46 -0500
Brandon McCaig bamcc...@gmail.com wrote:

 my @files = map { $_-[0] }
sort { $a cmp $b }

 sort { $a-[1] = $b-[1] }

map {[$_, (stat($dir/$_))[9] ] }
grep { ! /^\./  -f $dir/$_ } readdir($dh);

$a and $b are ARRAY references. The `stat` is the second element, at
index 1.

You could also sort by name when the mtimes are the same:

sort { $a-[1] = $b-[1]
   || lc( $a-[0] ) cmp lc( $b-[0] ) }


-- 
Don't stop where the ink does.
Shawn

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




Re: Back to work on perl + gui + hebrew...

2015-01-12 Thread Shawn H Corey
On Mon, 12 Jan 2015 15:23:53 +0200
Shlomi Fish shlo...@shlomifish.org wrote:

 Actually, Perl/Qt and Perl/KDE should also support Hebrew,
 Bidirectionality, and internationalisation well. Maybe wxPerl too
 (not sure). See:
 
 http://perl-begin.org/uses/GUI/

I think wxWidgets supports UTF by default. See:
http://docs.wxwidgets.org/trunk/overview_unicode.html


-- 
Don't stop where the ink does.
Shawn

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




Re: Multi-line `find` commands

2015-01-01 Thread Shawn H Corey
On Thu, 1 Jan 2015 15:11:36 -0800
SSC_perl p...@surfshopcart.com wrote:

   Thanks, guys.  I appreciate the responses.  I couldn't get
 either of those solutions to work so I'll switch over to using
 File::Find.  I don't know why I didn't think of that before - I use
 it in other scripts. :\  I guess I was just trying to see if I could
 tweak the script and get it to work since it's super fast.

File::Find::Rule is easier to use.
https://metacpan.org/pod/File::Find::Rule


-- 
Don't stop where the ink does.
Shawn

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




Re: Is There a Way to Make Uninitialized Warnings Fatal?

2014-12-11 Thread Shawn H Corey
On Wed, 10 Dec 2014 17:04:42 -0500
Uri Guttman u...@stemsystems.com wrote:

 it is called magic goto for that reason. it isn't really a sub call
 but a replacement of the current sub with the called one. no stack
 work is done and @_ is passed as is. it is very valuable when used
 like that but rarely needed. when you see newbies making calls like
 foo; and not know why that is dangerous, you have to teach them about
 it.

It's based on the idea of continuations, for those you want to know the
theory behind it. A continuation is passing a code reference to a sub
for it to return to rather than using the call stack. It works well
with exceptions: the first parameter to every sub is the normal
execution and the second is the exception handler. (The rest of the
parameters would be the regular parameters of the sub call.)

https://en.wikipedia.org/wiki/Continuation


-- 
Don't stop where the ink does.
Shawn

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




Re: Is There a Way to Make Uninitialized Warnings Fatal?

2014-12-10 Thread Shawn H Corey
On Wed, 10 Dec 2014 11:32:16 -0600
Martin G. McCormick mar...@server1.shellworld.net wrote:

 it made me wonder if there is a way to cause a perl program
 to die if that condition exists?

See `perldoc warnings` and search for /Fatal Warnings/
http://perldoc.perl.org/warnings.html#Fatal-Warnings


-- 
Don't stop where the ink does.
Shawn

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




Re: Substitution operator is not working in perl - Windows OS

2014-12-04 Thread Shawn H Corey
On Thu, 4 Dec 2014 16:06:26 +0530
Jitendra Barik jbarik...@gmail.com wrote:

 My code is:
 
 $version1 = JITENDRA;
 tie @array,Tie::File,$rtf1 or die($!);
 
 for(@array){
 #print Hi;
  s/\%VERSIONS\%/$version1/g;
 
 
 }
 untie(@array);
 
 FILE:
 ***
 
 *Version *%VERSION%, Hello,HI

In the substitution, you have VERSIONS but in the file, you have VERSION

If the S is optional, use: s/\%VERSIONS?\%/$version1/g;


-- 
Don't stop where the ink does.
Shawn

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




Re: reading a hash of arrays

2014-11-19 Thread Shawn H Corey
On Wed, 19 Nov 2014 17:03:40 -0600
Frank K. fklei...@gmail.com wrote:

 I can't do @array1 = @hash{one};

@array1 = @{ $hash{one} };

$hash{one} contains a reference to an array. By dereferencing it with
@{ ... }, you get the array.


-- 
Don't stop where the ink does.
Shawn

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




Re: using string as module

2014-11-08 Thread Shawn H Corey
On Sat, 8 Nov 2014 17:48:31 +0200
Shlomi Fish shlo...@shlomifish.org wrote:

 The correct syntax is simply (untested):
 
   my $foo = MyFoo::${pgm}Bar-new;

FYI: That is called a symbolic reference. For more information, see
`perldoc perlref` and search for /Symbolic references/

BTW, symbolic references are not considered good practice. But if you
need them, you need them.


-- 
Don't stop where the ink does.
Shawn

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




Re: share a variable between files

2014-10-09 Thread Shawn H Corey
On Wed, 8 Oct 2014 21:36:06 +0200
Hans Ginzel h...@matfyz.cz wrote:

 I want to use one global hash variable for options or configuration
 variables like verbose, debug.  I don't want to pass them to each
 function or to almost each object.

package main;
our %Opts = (
  verbose = 0,
  debug   = 0.
);

# you can use %::Opts anywhere.
# See `perldoc -f our`


-- 
Don't stop where the ink does.
Shawn

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




Re: map vs foreach

2014-09-30 Thread Shawn H Corey
On Tue, 30 Sep 2014 14:08:14 -0700
SSC_perl p...@surfshopcart.com wrote:

   Is the output of these two lines equivalent?
 
 map { $hash-{$_} = shift @record } @{$self-{'FIELDNAMES'}};
 
 $hash-{$_} = shift @record foreach @{$self-{'FIELDNAMES'}};
 
   They appear to be in my testing, but I'd like to make sure.
 
   Is one more appropriate than the other in a situation like
 this, or is it simply a styling difference?

Fancy tricks are fine...if you understand them. But do yourself a
favour: code like you will have to read it after an all-night party
(some day, you will).

foreach my $field_name ( @{ $self-{FIELDNAMES} } ){
  $hash-{ $field_name } = shift @record;
}

In other words, keep is simple.


-- 
Don't stop where the ink does.
Shawn

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




Re: map vs foreach

2014-09-30 Thread Shawn H Corey
On Tue, 30 Sep 2014 16:38:24 -0700
SSC_perl p...@surfshopcart.com wrote:

 On Sep 30, 2014, at 4:08 PM, Shawn H Corey wrote:
  code like you will have to read it after an all-night party
  (some day, you will).  
 
   Those days are over, but point taken! ;)

They're never over but they do get farther apart. ;)


-- 
Don't stop where the ink does.
Shawn

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




Re: Any project like Ipython/Bpython in Perl.

2014-09-15 Thread Shawn H Corey
On Mon, 15 Sep 2014 08:45:14 +0530
Santosh Kumar rhce@gmail.com wrote:

 I have seen some quick help option in some of the interpreters in
 python like Ipython and bpython. Do we have similar kind of projects
 or interpreter tools which i can start using in perl.

I don't know what Python is doing buy have you checked the Perl IDE,
Padre? http://padre.perlide.org/


-- 
Don't stop where the ink does.
Shawn

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




Re: Books or links or knowledge base

2014-09-13 Thread Shawn H Corey
On Sat, 13 Sep 2014 13:24:45 +0530
Santosh Kumar rhce@gmail.com wrote:

 Any good pointers or links on learning perl . Also any good pointer
 on OOPS concepts.

Some useful Perl links.

*   Official site http://www.perl.org/

*   Beginners' help http://learn.perl.org/faq/beginners.html

*   Advance help http://perlmonks.org/

*   Documentation http://perldoc.perl.org/

*   News http://perlsphere.net/

*   Repository http://metacpan.org/

*   Blog http://blogs.perl.org/

*   Regional groups http://www.pm.org/

*   Videos http://perltv.org/


-- 
Don't stop where the ink does.
Shawn

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