Re: Upgrade from Debian 11 to Debian 12 Broke Perl.

2024-03-11 Thread John SJ Anderson
> Can't locate warnings/unused.pm in @INC (you may need to install the 
> warnings::unused module) (@INC contains: /etc/perl 
> /usr/local/lib/x86_64-linux-gnu/perl/5.36.0 /usr/local/share/perl/5.36.0 
> /usr/lib/x86_64-linux-gnu/perl5/5.36 /usr/share/perl5 
> /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.36 
> /usr/share/perl/5.36 /usr/local/lib/site_perl) at /home/martin/etc/p2 line 3.
> BEGIN failed--compilation aborted at /home/martin/etc/p2 line 3.
> 
> So, if I try to use cpanp and re-add that module, I get:
> 
> 1wb5agz martin tmp $ cpanp -i Warnings::Unused
> ERROR] 'Warnings::Unused' does not contain an author part
> 
> [ERROR] Cannot find 'Warnings::Unused' in the module tree

“Warnings::Unused” != “warnings::unused”

Try `cpanp warnings::unused`.

j.


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




Re: Knowledge for a basic programmer and advanced programmer

2024-01-05 Thread John SJ Anderson
> If you are coding you should be backing up every
> 10 minutes or more often.  And you should store 
> a "historical" full copy of the code every 30 minutes
> or more often and save them for days.

No, you shouldn’t, because it is no longer 1985. 

You should learn how to use version control; the de facto standard at this 
point is Git. 

j.



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




Re: Modules

2023-10-24 Thread John Harris Gmail
What modules and/or libraries are you using? Before you code do you block
diagram and flowchart your programs?

On Tue, Oct 24, 2023, 12:06 PM Levi Elias Nystad-Johansen via beginners <
beginners@perl.org> wrote:

> I use modules for complex things that I might get wrong. To re-use other
> people's code is often better than to re-invent their solutions.
>
> https://metacpan.org/pod/WWW::Mechanize::Examples has some good examples
> of useful scripts that are short and simple.
> Imagine how hard it would be to write the same scripts without the module.
>
> When I have an issue that I think others must also have faced, I look for
> a module to solve the issue.
>
> But I am critical to modules that are outdated/abandoned, heavy with many
> dependencies, or unproven with few downloads etc.
>
> I also remove modules when I no longer need them. I find this easier with
> App::cpanminus
>
> - L
>
>
>
>
>
>
>  Original Message 
> On 24. okt. 2023, 17:31, William Torrez Corea < willitc9...@gmail.com>
> wrote:
>
>
> When I must use modules and when I don't must use?
>
> I am working without modules, only i use:
>
>1. Subroutines
>2. Control flow
>
> My programs are short and simple, they do not exceed 15 lines. I think
> that I need more practice and learn more about Perl. I have limited
> knowledge in Perl.
>
> --
>
> With kindest regards, William.
>
> ⢀⣴⠾⠻⢶⣦⠀
> ⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
> ⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
> ⠈⠳⣄
>
>
>


Re: Tool for develop in Perl

2023-10-23 Thread John Tebbe

I use this, it an old one but it meets my needs:

https://sourceforge.net/projects/open-perl-ide/

On 10/23/2023 6:55 AM, Ruprecht Helms wrote:


An Alternative for VIM or Emacs is the Nano-Editor.


Maybe the IDE Eclipse is able to assist you in developing perl-code. 
But like to use Eclipse for PHP-Developing, Handling SQL, ... you have 
to install a plugin to add this oppertunity. By default Eclipse is a 
IDE for Java-Developing.


Regards,
Ruprecht

On 22.10.23 21:46, Francisco Valladolid H. wrote:
The only thing that you need for develop  in perl is vi/vim and Unix 
like terminal.


Regards

On Sun 22 Oct 2023 at 1:38 p.m. Vlado Keselj  wrote:


I use Emacs.

On Fri, 20 Oct 2023, William Torrez Corea wrote:

> What tool can I use for development in Perl?
>
> I use VIM for coding and executing programs with the Perl
Command Line from GNU/Linux. In addition I have installed Eclipse
> but the IDE is abandoned.
>
> My theory: I can make full development from VIM but few
developers use VIM for development. They use Eclipse, Netbeans,
> Visual Studio or some other code editor like Visual Studio
Code, Sublime Text, Atom and Notepad++.
>
> The IDE is complete but large files while the code editor is light.
> --
>
> With kindest regards, William.
>
> ⢀⣴⠾⠻⢶⣦⠀
> ⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
> ⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
> ⠈⠳⣄
>
>
>
>
-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org

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


Re: escape character in regex

2022-10-10 Thread John W. Krahn

On 2022-10-10 18:12, Henrik Park wrote:


I know "/" is a special character for regex, which should be escaped.

But if I put "/" in a variable and use the variable in regex, then it 
doesn't need the explicit escape. Like this one:


$ perl -le '$delimiter="/"; $str="hello/world/buddy"; 
@list=split/$delimiter/,$str;print "@list"'

hello world buddy


Am I right? thank you.




"/" is NOT a special charater in a regular expression.  It is just that 
in Perl the default delimiter for some operators is "/" (i.e. m//, s///, 
tr///, etc.).


John

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




Re: Benchmark for Scala, Ruby and Perl

2022-01-15 Thread John W. Krahn

On 2022-01-15 00:04, Jon Smart wrote:


Hello Paul

Do you mean by undef $/ and with <$fh> we can read the file into memory 
at one time?


$/ is the input record separator, newline by default.
If undefined that means that the whole file is treated as one single record.


Yes that would be faster b/c we don't need to read file by each line, 
which increases the disk IO.


Another questions:
1. what's the "truss" command?


truss is a "unix" command.  Search for "truss unix".



2. what's the syntax "<:mmap"?


mmap enables a memory mapped file.  I treats the file as if it were a 
chunk of memory instead of a file.


Depending on the size of the file and the amount of memory available it 
may not make a difference.  Benchmark to confirm.




On 15.01.2022 15:45, Paul Procacci wrote:


-
use strict;

$/ = undef;


That is usually written as:

local $/;

because $/ is a global variable and you want to limit the scope of any 
change.




my %stopwords = do {
    open my $fh, '<:mmap', 'stopwords.txt' or die $!;
    map { $_ => 1; } split /\n/, <$fh>;
};

my %count = do {
    my %res;
    open my $fh, '<:mmap', 'words.txt' or die $!;
    map { $res{$_}++ unless $stopwords{$_}; } split /\n/, <$fh>;
    %res;
};

my $i=0;
for (sort {$count{$b} <=> $count{$a}} keys %count) {
    if ($i < 20) {
    print "$_ -> $count{$_}\n"
    } else {
   last;
    }
    $i ++;
}




John

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




Re: A Philosophical Point To Be Made: The Truth

2021-10-26 Thread John SJ Anderson
This is off-topic for this mailing list; please take this discussion elsewhere. 

thanks,
john,
list mom. 


> On Oct 26, 2021, at 03:06, Shlomi Fish  wrote:
> 
> Hi Brandon!
> 
>> On Sun, 17 Oct 2021 01:15:13 -0400
>> Brandon McCaig  wrote:
>> 
>> Hello All,
>> 
>> It has been a while. I haven't been active on the list in years.
>> Something much bigger has been stealing my focus. And now I think
>> I might be ready to share it with the world.
>> 
>> Do be warned, I make best efforts to be inclusive of all, but I
>> only know what I know. But if I'm right I have the answer to all
>> of this for all of us.
>> 
>> https://castopulence.org/
>> 
>> To summarize, I think I know what the "correction" to
>> insensitivity is. A better social network. Based upon the truth.
>> 
>> I wonder too if the Perl developers themselves might be
>> interested in this discussion because of its relationship to
>> linguistics and software. Though I dare not try to send it their
>> way directly without a push (and maybe a direction).
>> 
>> Feedback, constructive or otherwise, is welcomed and encouraged.
>> 
> 
> After reading that page, I still don't understand how the issue manifests
> itself as well as how the proposed solution will be implemented. Perhaps try
> giving concrete examples.
> 
>> Regards,
>> 
>> 
>> 
>> Brandon McCaig   <
>> bamb...@castopulence.org>  
>> Castopulence Software <https://www.castopulence.org/>
>> Blog <https://www.bambams.ca/ <http://www.bambams.ca/>>
>> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
>> q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
>> tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
> 
> 
> 
> -- 
> 
> Shlomi Fish   https://www.shlomifish.org/
> Beginners Site for the Vim text editor - https://vim.begin-site.org/
> 
> Buddha has the Chuck Norris nature.
>— https://www.shlomifish.org/humour/bits/facts/Chuck-Norris/
> 
> Please reply to list if it's a mailing list post - https://shlom.in/reply .
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 


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




Re: memory mapped file example

2020-10-03 Thread John W. Krahn

On 2020-10-03 5:41 a.m., stefano cerbioni wrote:

hi guys i try to read a memory mapped file created with c++ , this is a c++
code that i have
[code]


[snip code]



[/code]

how can read a  memory mapped created ?
thankz at all



A memory mapped file should be just like any other file.  Just find out 
what the file name is and determine what format the data is stored in 
that file.


John

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




Re: Wide character in print at HTML::TreeBuilder::XPath function

2020-01-26 Thread John SJ Anderson
> That, I am very grateful to report, solved that question.  I guess the
> scope of "use utf8;" is more narrow than I had thought.

When you have a bit of time, sitting down and reading through 
https://github.com/rgs/p5-intelligible-unicode 
<https://github.com/rgs/p5-intelligible-unicode> is a really good investment in 
reducing future frustrations when working with Unicode in Perl.

chrs,
john.





Re: question about perl script

2019-10-30 Thread John W. Krahn

On 2019-10-29 7:48 p.m., 刘东 wrote:

Dear every one:


Hello.


I try to write a perl script to delet the content of file carp01_1_both.txt as 
same as from another file carp-carp01_TKD181002053-1_1_sg.txt, so to get a new 
file from file carp-carp01_TKD181002053-1_1_sg.txt but excluding file 
carp01_1_both.txt. However, when I run this scrip, it does not work, and 
display the information as follows:
...

Semicolon seems to be missing at carp01_1_both.txt line 44993.




syntax error at carp01_1_both.txt line 1, near "979:"


These messages say that perl is trying to interpret your data file as if 
it were a Perl program.




perl script:
#!/usr/bin/perl -w
open(NAME,"<$ARGV[0]")|| die;
open(SECON,"<$ARGV[1]")|| die;
open(SELEC,">$ARGV[2]")|| die;
$name = "";
%pair = ();

while(){
  chomp;
  my @line = split("\t",$_);
 $name = $line[0];
 $pair{$name} = 1;
}

while(my $li = ){
 chomp($li);
 my  @line = split("\t",$li);
 $name = $line[0];
 my  $cont = $li;
if (exists $hash{$name}) { # if current read appeared before
 next;
 } else { # if it haven't been read before
 print SELEC "$cont\n";
  }
}

close NAME;
close SECON;
close SELEC;


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

open my $NAME, '<', $ARGV[ 0 ] or die "Cannot open '$ARGV[0]' because: $!";
open my $SECON, '<', $ARGV[ 1 ] or die "Cannot open '$ARGV[1]' because: $!";
open my $SELEC, '>', $ARGV[ 2 ] or die "Cannot open '$ARGV[2]' because: $!";

my %pair;

while ( <$NAME> ) {
my ( $name ) = split /\t/;
$pair{ $name }++;
}

while ( <$SECON> ) {
my ( $name ) = split /\t/;
print { $SELEC } $_ unless exists $pair{ $name };
}

close $NAME;
close $SECON;
close $SELEC;

__END__


John

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




Re: Help me with a regex problem

2019-10-25 Thread John W. Krahn

On 2019-10-25 3:23 a.m., Maggie Q Roth wrote:

  Hello


Hello.


There are two primary types of lines in the log:


What are those two types?  How do you define them?



60.191.38.xx/
42.120.161.xx   /archives/1005


From my point of view those two lines have two fields, the first looks 
like an IP address and the second looks like a file path.  In other 
words I can't distinguish the difference between these two "types".




I know how to write regex to match each line, but don't get the good result
with one regex to match both lines.

Can you help?


Perhaps if you could describe the problem better?


John

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




Re: perl script question

2019-10-10 Thread John W. Krahn

On 2019-10-09 7:21 p.m., 刘东 wrote:

hellow:
I have written a script, but it does not work, can you tell me what wrong with 
me?


#! /usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

my ($dir, $files, $file_name, $file_format, $file_dir, $file_main);

GetOptions ('dr=s'  =>\$dir);

open INF,"<",'sine.fa' or die "can't read open sine";

foreach $files (glob("$dir/*.fa")) {
open FASEQ, "<", $files or die "can not read open $!";
   ($file_dir, $file_main) = split (/\/\//,$files);
   ($file_name,$file_format) =split(/\./,$file_main);
open OUTFILE, '>', $file_name.".txt";
`./usearch -ublast FASEQ -db INF -evalue 1e-5 -userout OUTFILE -strand both 
-userfields query+qlo+qhi+ql+qs+qstrand+target+tlo+thi+tl`;
}

close FASEQ;
close OUTFILE;
close INF;


(Sorry, correction added.)
Perhaps it may work better like this:

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

GetOptions( 'dr=s' => \my $dir );

opendir my $DH, $dir or die "Cannot open '$dir' because: $!";

while ( my $file = readdir $DH ) {

my $file_name = $file =~ s/\.fa\z/.txt/r or next;

0 == system './usearch',
'-ublast', "$dir/$file",
'-db', 'sine.fa',
'-evalue', '1e-5',
'-userout', $file_name,
'-strand', 'both',
'-userfields', 'query+qlo+qhi+ql+qs+qstrand+target+tlo+thi+tl'
or die "system ./usearch failed: $?";
}


John

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




Re: perl script question

2019-10-10 Thread John W. Krahn

On 2019-10-09 7:21 p.m., 刘东 wrote:

hellow:
I have written a script, but it does not work, can you tell me what wrong with 
me?


#! /usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

my ($dir, $files, $file_name, $file_format, $file_dir, $file_main);

GetOptions ('dr=s'  =>\$dir);

open INF,"<",'sine.fa' or die "can't read open sine";

foreach $files (glob("$dir/*.fa")) {
open FASEQ, "<", $files or die "can not read open $!";
   ($file_dir, $file_main) = split (/\/\//,$files);
   ($file_name,$file_format) =split(/\./,$file_main);
open OUTFILE, '>', $file_name.".txt";
`./usearch -ublast FASEQ -db INF -evalue 1e-5 -userout OUTFILE -strand both 
-userfields query+qlo+qhi+ql+qs+qstrand+target+tlo+thi+tl`;
}

close FASEQ;
close OUTFILE;
close INF;



Perhaps it may work better like this:

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

GetOptions( 'dr=s' => \my $dir );

opendir my $DH, $dir or "Cannot open '$dir' because: $!";

while ( my $file = readdir $DH ) {

my $file_name = $file =~ s/\.fa\z/.txt/r or next;

0 == system './usearch',
'-ublast', "$dir/$file",
'-db', 'sine.fa',
'-evalue', '1e-5',
'-userout', $file_name,
'-strand', 'both',
'-userfields', 'query+qlo+qhi+ql+qs+qstrand+target+tlo+thi+tl'
or die "system ./usearch failed: $?";
}


John

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




Re: symlink to "pack"

2019-09-09 Thread John W. Krahn

On 2019-09-08 12:20 p.m., Jorge Almeida wrote:

On Sun, Sep 8, 2019 at 8:08 PM John W. Krahn  wrote:


On 2019-09-07 1:25 p.m., Jorge Almeida wrote:

On Unix/Linux a character in a file name can be any character except a
slash '/' character because that is used to separate path elements, or a
null "\0" character because that is what the C language uses to signify
the end of a string.


Yes, but does a symlink target counts as a "file name"? Probably, but
it's not very clear. (I didn't want to dereference the symlink, only
readlink() it...)

Jorge


So your Perl string "\0\f" is read by C as a zero length string.



The operating system is written in C.  The symlink(2) function is part 
of the operating system and is written in C.  Therefore, when perl calls 
symlink(2) it has to send a valid C type string.  Because your string 
starts with a NULL character it is a C string with zero characters.



John

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




Re: symlink to "pack"

2019-09-08 Thread John W. Krahn

On 2019-09-07 1:25 p.m., Jorge Almeida wrote:

Sorry about the title, it's the best I can do...

#!/usr/bin/perl
use strict;
use warnings;
my $num=12;
my $target=pack('n', $num);
symlink($target, "foo") || die $!;

It dies with "No such file or directory"
No symlink is created. What I want is a symlink named "foo" pointing
to a 2-byte string. Yes, it would be a broken symlink. (Yes, this is
how I want it).

Symlink() can create broken links, the problem is the target. What to
do? (And why doesn't it work?)



$ perl -le'
use warnings;
use strict;
use Data::Dumper;
$Data::Dumper::Useqq = 1;

my $num = 12;
my $target = pack "n", $num;
print Dumper $target;
'
$VAR1 = "\0\f";


On Unix/Linux a character in a file name can be any character except a 
slash '/' character because that is used to separate path elements, or a 
null "\0" character because that is what the C language uses to signify 
the end of a string.


So your Perl string "\0\f" is read by C as a zero length string.


John

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




Re: ActiveState unauthorized license claims?

2019-05-31 Thread John SJ Anderson
> probably that's the wrong list for that question but I didn't find a better 
> one - hints are welcome.

Yes, this is very much not the right list for this. 

I would suggest posting this to the Perl 5 Porters list; it’s probably the best 
venue to get an answer to your question. 

https://lists.perl.org/list/perl5-porters.html 
<https://lists.perl.org/list/perl5-porters.html>

chrs,
john.




Re: What are the environmental variables used by Perl?

2019-05-30 Thread John SJ Anderson
> 
> Do you know if there is a list of environmental variables anywhere?

I think maybe this is what you’re looking for?  
https://perldoc.pl/perlrun#ENVIRONMENT 


Re: Syntax "||" before sub

2018-11-22 Thread John W. Krahn

On 2018-11-22 8:08 a.m., David Precious wrote:



You'll often see these operators used to provide default values.

e.g.

   sub hello {
   my $name = shift;
   $name ||= 'Anonymous Person';


Which is usually written as:

   sub hello {
   my $name = shift || 'Anonymous Person';



I do notice that there isn't actually a very useful section on ||=
and //= - I may try to raise a pull requests to add more documentation
on them.


$var ||= 'VALUE';

Is just shorthand for:

$var = $var || 'VALUE';

The syntax is borrowed from the C programming language and it is 
slightly more efficient when compiled to machine code.




John

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




Re: Code Assistance Pls

2018-11-21 Thread John W. Krahn

On 2018-11-21 3:08 a.m., Amanda Paziuk wrote:


I'm hoping someone can assist as I'm having difficulty with parsing a
section of the following configuration:

This is the code I have:

 push @list, $datum; # should only contain '1', and '3'

>
> ...
>

 foreach my $i (@list){ # loops through dynamically-learned file IDs
 open (IN, $file);
 while () {
 chomp;
 if (/^file-id $i/) {


If $i contains 1 then this will match "file-id 10" or "file-id 1234" or 
any number whose first digit is 1.

You need to either use anchors:

 if ( /^file-id \b$i\b/ ) {

Or capture the number and do numerical comparison:

 if ( /^file-id (\d+)/ && $1 == $i ) {




John

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




RE: XML::LibXML and comments

2018-09-11 Thread John Cortland Morgan
Hi Lawrence,

  Works great, thanks! Never thought of appending the comment directly to the 
$doc, just assumed I
Needed to set the root first.

Regards,

John

From: Lawrence Statton 
Sent: Monday, September 10, 2018 9:44 PM
To: beginners@perl.org
Subject: Re: XML::LibXML and comments




On Sep 10, 2018, at 6:33 AM, John Cortland Morgan 
mailto:johncortland.mor...@ericsson.com>> 
wrote:

Hi,

 I'm trying to place a comment directly after the XML declaration using 
XML::LibXML,
But cannot seem to manage, always receiving error:

setDocumentElement: ELEMENT node required at .../LibXML.pm line 1393

What I would like:




 testing


My relevant code thus far:

My $dom = XML::LibXML::Document->new( "1.0", "UTF-8");
My $root =  XML::LibXML::Comment->new( "test comment" );
$dom->setDocumentElement($root);


Any help would be greatly appreciated. I'm kinda stuck with using XML::LibXML 
though.

John

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


The root of a document cannot be a comment, however you can add a comment with

$dom->addChild($dom->createComment(‘test comment’))

#!/usr/bin/perl

use strict;
use warnings;
use XML::LibXML;

my $doc = XML::LibXML::Document->new(qw/1.0 utf-8/);

$doc->appendChild($doc->createComment('test comment'));
$doc->setDocumentElement(my $e_products = $doc->createElement('products'));
$e_products->appendTextChild(field => 'testing');

print $doc->toString(1);




XML::LibXML and comments

2018-09-10 Thread John Cortland Morgan
Hi,

  I'm trying to place a comment directly after the XML declaration using 
XML::LibXML,
But cannot seem to manage, always receiving error: 

setDocumentElement: ELEMENT node required at .../LibXML.pm line 1393

What I would like:




  testing


My relevant code thus far:

My $dom = XML::LibXML::Document->new( "1.0", "UTF-8");
My $root =  XML::LibXML::Comment->new( "test comment" );
$dom->setDocumentElement($root);


Any help would be greatly appreciated. I'm kinda stuck with using XML::LibXML 
though.

John

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




RE: Eclipse/Epic/PadWalker for Perl

2018-07-31 Thread John Cortland Morgan
Padwalker needs to be installed befor EPIC, so EPIC knows that it is there.
Try to remove EPIC and reinstall.

Regards

From: Lauren C. 
Sent: Tuesday, July 31, 2018 3:27 AM
To: James Kerwin ; beginners@perl.org
Subject: Re: Eclipse/Epic/PadWalker for Perl

[OT] maybe you want to change IDE to vi/vim since you are using Perl. :)


发件人: James Kerwin
日期: 2018年7月30日 星期一 下午9:19
至: mailto:beginners@perl.org>>
主题: Eclipse/Epic/PadWalker for Perl

Hi all,

I appreciate this isn't a place for the Eclipse IDE, but maybe some of you may 
have an answer.

I installed Eclipse Photon, EPIC and then PadWalker. Unfortunately I can't seem 
to see variables and their values in eclipse. I can't seem to find a diagnosis 
or solution.

Would anybody be able to shed some light onto this?

I should add that my scripts run in eclipse as expected. The debugging just 
doesn't seem to be behaving itself.

Thanks,
James


Re: help with a stat script

2018-07-12 Thread John W. Krahn
On Thu, 2018-07-12 at 19:35 +0800, Lauren C. wrote:
> 
> My web is powered by Apache and PHP,its access log seems as blow,
> 
> xx.xx.xx.xx - - [12/Jul/2018:19:29:43 +0800] "GET 
> /2018/07/06/antique-internet/ HTTP/1.1" 200 5489 "https://miscnote.ne
> t/" 
> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 
> (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
> 
> A perl script for stat purpose of this log:
> 
> tail -f /var/log/apache2/access.log|perl -nle 'next unless m{^(\S+) -
> - 
> \[(\S+).*\] \"GET (.*?/)\s+}; printf "%-20s%-40s%-40s\n",$1,$3,$2'
> 
> I was totally confused about it.
>   what does m{...} and its content stand for?



m{^

Start with the (^) beginning of line anchor, the following pattern must
match at the beginning of the line.

(\S+)

Match one or more non-whitespace characters and store the match in the
$1 variable.  This matches the "xx.xx.xx.xx" portion of your string.

' - - \['

Match the literal characters SPACE HYPHEN SPACE HYPHEN SPACE LEFT-
BRACKET.

(\S+)

Match one or more non-whitespace characters and store the match in the
$2 variable.  This matches the "12/Jul/2018:19:29:43" portion of your
string.

'.*\] \"GET '

Match zero or more non-newline characters followed by the literal
string '] "GET '.

(.*?/)

Match as few as possible non-newline characters followed by a '/'
character and store the match in the $3 variable.  This matches the
"/2018/07/06/antique-internet/" portion of your string.

\s+}

And finally, match one or more whitespace characters so that the
previous non-greedy pattern will match correctly.  The modifier is
redundant so it could simply be:

\s}



John

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




Re: Removing a Pattern using a Regular Expression

2018-06-14 Thread John W. Krahn
On Wed, 2018-06-13 at 21:21 -0500, Martin McCormick wrote:
> I wrote a small perl program to more quickly read all the
> subjects in an email list.  One of the things the script does is
> to remove the mailing list name which repeats for every message
> and consists of a [, some English text and finally a ].
> 
>   I was able to write a RE that identifies that text and
> cause the script to save that string in a variable called
> $remove.  That part works and looks like:
> 
> foreach my $field (@fields) {#Assemble the new subject.
> if($field =~ m/\[(.*?)\]/) 

if you want to remove this string then why not just remove it here:

if ( $field =~ s/\[(.*?)\]// )


> { #$field is the blocked field.
> $remove = $field;
> } #field is the blocked field.
> else
> { #$field is not the blocked string.
> $newest = $newest . $field;
> } #$field is not the blocked string.
> }#Assemble the new subject.
> 
> if ( $newest eq $previous ) {#Skip this iteration.
> $newest = "";
> next;
> }#Skip this iteration.
> else
> { #they are different.
> 
>   This is where things don't quite work yet.  At this
> point, I have $remove which contains that bracketted list name
> such as
> 
> [BLIND-HAMS] or any number of other names enclosed in brackets.
> So, the next thing I do is to attempt to remove just that part of
> the subject line, keeping everything else that was there.
> 
>    $subject =~ s/'$remove'//;

After string interpolation you have:

$subject =~  s/'[BLIND-HAMS]'//;

Which is a string of three characters consisting of the "'" character
followed by a character class followed by the "'" character.

The character class says to match one character that is either 'A' or
'B' or 'D' or 'E' or 'F' or 'G' or 'H' or 'I' or 'L' or 'M' or 'N' or
'S'.

You probably need to use quotemeta:

$subject =~  s/'\Q$remove\E'//;



John

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




Re: project euler #8

2018-06-07 Thread John SJ Anderson
Hi Shlomi. 

A reminder that sometimes when somebody does something, you can just ignore the 
email and _not_ reply to it. 

Thanks,
John the list mom. 

-- 
John Anderson // j...@genehack.org 

> On Jun 7, 2018, at 08:58, Shlomi Fish  wrote:
> 
> Hi,
> 
> why did you resurrect a one year old's thread for which there were proper
> replies here -
> https://www.nntp.perl.org/group/perl.beginners/2017/05/msg126502.html and here
> - https://github.com/shlomif/project-euler/tree/master/project-euler/8 . just
> let sleeping dogs rest. Some comments on your code:
> 
> On Wed, 06 Jun 2018 19:23:11 -0700
> "John W. Krahn"  wrote:
> 
>> On Tue, 2017-05-16 at 14:01 +0800, derr...@thecopes.me wrote:
>> 
>> 
>> I am working on problem #8 of the euler project. see below.
>>> 
>>> 
>>> 
>>> The four adjacent digits in the 1000-digit number that have the
>>> greatest product are 9 × 9 × 8 × 9 = 5832.
>>> 
>>> 73167176531330624919225119674426574742355349194934
>>> 96983520312774506326239578318016984801869478851843
>>> 85861560789112949495459501737958331952853208805511
>>> 12540698747158523863050715693290963295227443043557
>>> 66896648950445244523161731856403098711121722383113
>>> 6222989342338030813533627661428280686645238749
>>> 30358907296290491560440772390713810515859307960866
>>> 70172427121883998797908792274921901699720888093776
>>> 65727333001053367881220235421809751254540594752243
>>> 52584907711670556013604839586446706324415722155397
>>> 53697817977846174064955149290862569321978468622482
>>> 83972241375657056057490261407972968652414535100474
>>> 82166370484403199890008895243450658541227588666881
>>> 16427171479924442928230863465674813919123162824586
>>> 17866458359124566529476545682848912883142607690042
>>> 2421902267105562632109370544217506941658960408
>>> 07198403850962455444362981230987879927244284909188
>>> 84580156166097919133875499200524063689912560717606
>>> 05886116467109405077541002256983155200055935729725
>>> 71636269561882670428252483600823257530420752963450
>>> 
>>> Find the thirteen adjacent digits in the 1000-digit number that have
>>> the greatest product. What is the value of this product?  
>> 
>> 
>> 
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> 
>> ( my $x = < 
> Please use a more meaninful var name.
> 
>> 73167176531330624919225119674426574742355349194934
>> 96983520312774506326239578318016984801869478851843
>> 85861560789112949495459501737958331952853208805511
>> 12540698747158523863050715693290963295227443043557
>> 66896648950445244523161731856403098711121722383113
>> 6222989342338030813533627661428280686645238749
>> 30358907296290491560440772390713810515859307960866
>> 70172427121883998797908792274921901699720888093776
>> 65727333001053367881220235421809751254540594752243
>> 52584907711670556013604839586446706324415722155397
>> 53697817977846174064955149290862569321978468622482
>> 83972241375657056057490261407972968652414535100474
>> 82166370484403199890008895243450658541227588666881
>> 16427171479924442928230863465674813919123162824586
>> 17866458359124566529476545682848912883142607690042
>> 2421902267105562632109370544217506941658960408
>> 07198403850962455444362981230987879927244284909188
>> 84580156166097919133875499200524063689912560717606
>> 05886116467109405077541002256983155200055935729725
>> 71636269561882670428252483600823257530420752963450
>> STUFF
>> 
>> my @z = ( 0 ) x 5;
> 
> why 5?
>> while ( $x =~ / ( . ) (?= ( . ) ( . ) ( . ) ( . ) ( . ) ( . ) ( . ) ( .
>> ) ( . ) ( . ) ( . ) ( . ) ) /xg ) {
>> my $y = $1 * $2 * $3 * $4 * $5 * $6 * $7 * $8 * $9 * $10 * $11 *
>> $12 * $13;
>> @z = ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $y )
>> if $z[ -1 ] < $y;
>> }
>> 
> 
> this code is full of duplicate functionality and you are abusing the capture
> vars as arrays.
> 
> The ?= trick is nice, though.
> 
>> print "@z\n";
>> 
>> 
>> __END__
>> 
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 

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




Re: project euler #8

2018-06-06 Thread John W. Krahn
On Tue, 2017-05-16 at 14:01 +0800, derr...@thecopes.me wrote:


I am working on problem #8 of the euler project. see below.
> 
> 
> 
> The four adjacent digits in the 1000-digit number that have the
> greatest product are 9 × 9 × 8 × 9 = 5832.
> 
> 73167176531330624919225119674426574742355349194934
> 96983520312774506326239578318016984801869478851843
> 85861560789112949495459501737958331952853208805511
> 12540698747158523863050715693290963295227443043557
> 66896648950445244523161731856403098711121722383113
> 6222989342338030813533627661428280686645238749
> 30358907296290491560440772390713810515859307960866
> 70172427121883998797908792274921901699720888093776
> 65727333001053367881220235421809751254540594752243
> 52584907711670556013604839586446706324415722155397
> 53697817977846174064955149290862569321978468622482
> 83972241375657056057490261407972968652414535100474
> 82166370484403199890008895243450658541227588666881
> 16427171479924442928230863465674813919123162824586
> 17866458359124566529476545682848912883142607690042
> 2421902267105562632109370544217506941658960408
> 07198403850962455444362981230987879927244284909188
> 84580156166097919133875499200524063689912560717606
> 05886116467109405077541002256983155200055935729725
> 71636269561882670428252483600823257530420752963450
> 
> Find the thirteen adjacent digits in the 1000-digit number that have
> the greatest product. What is the value of this product?



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

( my $x = 

Re: CPAN will shutdown

2018-05-22 Thread John SJ Anderson

> On 22May2018, at 20:41, Practical Perl  wrote:
> 
> search.cpan.org is shutting down
> For details read Perl NOC. After June 25th this page will redirect to 
> MetaCPAN.org 

1) Please don’t cross-post between this list and other lists. It’s rude. 

2) It’s not “shutting down” so much as it is being replaced by the existing 
MetaCPAN search site. This is positive news about the future of Perl: an older, 
less capable tool has been replaced, and is being shutdown and transitioned to 
its replacement in an orderly fashion. This is what a healthy programming 
language community looks like. 

chrs,
john.

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




Re: regex with HEX ascii chars

2018-04-13 Thread John W. Krahn
On Thu, 2018-04-12 at 17:26 +0100, Gary Stainburn wrote:
> I have a text file (created by  pdftotext) that I've imported into my
> script.
> 
> It contains ASCII characters 251 for crosses and 252 for ticks.

ASCII defines 128 characters so those characters are not ASCII.


John

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




Re: [^/]* Is Not Working

2018-03-17 Thread John SJ Anderson


> But this one in its place does not work:
> if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work

You still need to escape the `/` inside the character class.

This works in my testing: `m/\/([^\/]*)$/`.

IMO this is a case where an alternative delimiter for `m//` — such as the `#` 
in your working example — is a better approach. 



chrs,
john.

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




Re: compute depth of word in line

2018-03-10 Thread John W. Krahn
On Sat, 2018-03-10 at 00:14 +0100, hw wrote:
> 
> Not really, the words I get from the ReadLine functions are not
> organized in an array.
> 
> I´ve come up with this function to compute the "depth" of a word:
> 
> 
> sub get_depth {
>   my $string = shift;
> 
>   $string =~ s/\s/ /g;
>   $string =~ s/\s+/ /g;
>   $string =~ s/^\s*//;
>   $string =~ s/\s*$//;
> 
>   my $depth = 0;
>   my $position = 0;
>   while((my $start = index($string, ' ', $position)) != -1) {
> $position = $start + 1;
> $depth++;
>   }
> 
>   return $depth;
> }

That function could be simplified to:

sub get_depth {
my $string = shift;

$string =~ s/^\s+//;
    $string =~ s/\s+$//;
my $depth = $string =~ s/\s+/ /g;

return $depth;
}


John

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




Re: Find::Perl find not returning

2017-12-13 Thread John W. Krahn
On Wed, 2017-12-13 at 11:28 +, Mike Martin wrote:
> Hi
> I have the following code
> 
> use strict;
> use File::Find;
> my @vsbe;
> my $top='P:\PT-6\PT-60\PT-603\Shared\Data Store\Files Dump Folder';
> my $max_depth=9;
> my $cnt1=0;
> 
> find({wanted=>\&wanted1,preprocess=>\&preprocess1},$top) ;
> 
> sub wanted1 {
> 
> if ($cnt1 <=1000){
> my $file = $File::Find::name;
> if (grep {/vsb$/} $file){

grep works on lists so you don't need grep there:

if ( $file =~ /vsb$/ ) {


> push @vsbe, $file if $cnt1 <=1000 ;
> $cnt1++;
> print $cnt1,"\n" ;
> }
> else {return}
> 
> return if $cnt1 >=1000
> }
> return
> 
> }
> sub preprocess1 {
> my $depth = $File::Find::dir =~ tr[\\][];
> #print 'depth',"\t",$depth,"\t",$File::Find::dir,"\n";
> return  @_ if $depth < $max_depth;
> return grep { not -d } @_ if $depth == $max_depth;
> return;
> }
> 
> Unfortunately the wanted function never returns, it (at best) stays
> stuck
> on print the last value of $cnt1 (1000)
> 
> Any ideas what is happening here

The wanted function does return, but it does not return to your
process.  It is called inside a loop in the File::Find code and when it
returns the loop continues until all the files are found.


John

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




Re: Using Pack and Unpack

2017-12-06 Thread John W. Krahn
On Wed, 2017-12-06 at 21:53 -0600, Martin McCormick wrote:
> A perl program needs to send binary data to an external device
> such that 0xff looks like 


$ perl -le'my $x = sprintf q/%b/, 0xff; print $x'




>   I have a line in the program as follows:
> 
> my $txstart = pack("h*","fefe5a95");
> 
> Are those 4 bytes usable as the binary data 
> 
> fe fe 5a 95?
> 
>   Is there a good way when running perl -d to view the
> contents of the string to make sure it is what it should be?


use Data::Dumper;
$Data::Dumper::Useqq = 1;

my $txstart = pack 'h*', 'fefe5a95';

print Dumper $txstart;



John

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




Re: Use of uninitialized value for perl

2017-11-05 Thread John W. Krahn
On Sun, 2017-11-05 at 00:43 +, Dong Liu wrote:
> I try used perl script to get characters from data:
> 
> #!/usr/bin/perl -w
> use v5.14;
> while (){
> chomp;
> my $line = '';
> $line = (split //,@_)[5];

At no point in your script do you or perl assign a value to the array
@_ so the array will have 0 elements, and an array in scalar context
will return the number of elements in the array, so that statement is
the same as:

$line = ( split //, '0' )[ 5 ];

Which will create the list ( '0' ).  So every element other than zero
(the first element) will be undef.  So that statement is the same as:

$line = undef;


> print "it is $line.\n";
> }
> 
> __DATA__
> Danio rerio strain Tuebingen chromosome 1 GRCz11 Primary Assembly
> Danio rerio strain Tuebingen chromosome 2 GRCz11 Primary Assembly
> 
> the results is :
> Use of uninitialized value $line in concatenation (.) or string at
> foundins.pl line 9,  line 1.
> it is .
> Use of uninitialized value $line in concatenation (.) or string at
> foundins.pl line 9,  line 2.
> it is .
> 
> the aim for the work is to get the number for each line such as:
> 1 for first line and
> 2 for second lin

When using a while ( <> ) loop the current line number can be found in
the $. variable:

$ perldoc -v $.




John

-- 
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-10-29 Thread John W. Krahn
On Sun, 2017-07-02 at 11:16 -0400, Shawn H Corey wrote:
> On Sun, 2 Jul 2017 14:29:25 +0200
> Eric de Hont  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.

$ perl -le'
use warnings;
my $x;
{   no warnings;
print $x;
}
print $x;
'

Use of uninitialized value $x in print at -e line 7.

$ perl -wle'
my $x;
{   local $^W = 0;
print $x;
}
print $x;
'

Use of uninitialized value $x in print at -e line 6.

-- 
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 John Harris
What are these emails really about?

On Jul 1, 2017 2:42 PM, "Chas. Owens"  wrote:

>
>
> On Sat, Jul 1, 2017, 12:44 Shlomi Fish  wrote:
>
>> Hi Shawn!
>>
>> On Sat, 1 Jul 2017 11:32:30 -0400
>> Shawn H Corey  wrote:
>>
>> > !!$i which is !(!(0)) which is !(1) which is 0
>> >
>>
>> I suspect !1 returns an empty string in scalar context.
>>
>
> !1 returns PL_sv_no (an internal scalar variable). It is a dualvar that
> contains the empty string, the int 0 and the double 0.0. depending on the
> context the value is used in, it will be one of those values.
>
> Many people think it is an empty string because the print function forces
> string context.
>
>>


Re: dangerous perl (Re: is this reasonably save?)

2017-05-26 Thread John SJ Anderson
Take. It. Off. The. List. 

I've asked nicely. Now I'm telling you. Take it off the list. 

John 
List moderator. 

-- 
John Anderson // j...@genehack.org 

> On May 26, 2017, at 19:09, Kent Fredric  wrote:
> 
>> On 27 May 2017 at 00:01, lee  wrote:
>> You have a variable.
> 
> Even in C, you'd have a variable as well.  It would be a variable that
> contains a *pointer* to a data structure.
> 
> The variable may be *typed*, but *types* don't impact anything about
> the data storage in memory.
> 
> *types* in C are mechanisms that direct the compiler how to handle the
> memory the variable deals with.
> 
>> 
>>> Because as far as I'm concerned, I have both data structures and
>>> references in play.
>> 
>> As far as I'm concerned, you seem to have assigned a reference to the
>> variable, and what it might be referring to is difficult to figure out.
>> 
>> Some sort of construction that resembles a hash seems involved.  As far
>> as I'm concerned, hashes are key/value pairs.  I don't consider them as
>> data structures any more than, for example, an integer.  They are a
>> given element of the language which can be useful when you have a bunch
>> of values you want to refer to by names.
>> 
>> So I'm not sure what you have there.
> 
> It is a variable that references a hash, whos values in turn reference hashes.
> 
> Accessing the value "total" is as simple as:
> 
> $var->{memory}->{total}
> 
> This is not entirely unlike C where you look up a struct member of a
> struct which has a nested struct within.
> 
> var.memory.total
> 
> ( I think )
> 
> The real distinctions being that structs are compile-time semantics
> that boil expressions down to memory offsets in the block, whereas the
> Perl equivalent is not quite so bounded, and the memory addresses are
> computed at runtime.
> 
> They're rather different at the machine level in how the actual data
> is laid out, but from a users perspective, multi-level structs and
> multi-level hash references are equally convenient.
> 
> How you define a "Data structure" and how the C version being "a data
> structure" and the Perl version "not a data structure" is a little
> confusing to me, because to me, a data structure is supposed to be an
> abstract idea for laying out your data in a way convenient to coding,
> and the implementation details of how that data structure works under
> the hood are not too important, as long as the user visible promises
> remain the same.
> 
>>> References are not a low level mechanic that only the Perl VM needs to
>>> care about.
>>> 
>>> References are a mechansim to allow data structures to be passed
>>> *without copying*
>> 
>> Yes, that works nicely in C.
>> 
>>> my $x = 5;
>>> my $y = $x;   # x is a copy of y
>>> 
>>> However, if I do:
>>> 
>>> my $x = 5;
>>> $y  = \$x
>>> 
>>> 
>>> Y is now a reference to X
>> 
>> $y = 5;
>> 
>> Now $y is 5.  That is what's evil.
> 
> All you're saying here is there's no strong typing.
> 
> That's pretty much just par for dynamic languages.
> 
> That is, it doens't mean there are no data structures, it means there
> are no compile time constraints that prevent storing bits classes as
> one type of data in a container that previously held another.
> 
>> 
>>> If I now do:
>>> 
>>>  ${$y}  = 10
>>> 
>>> X changes.
>> 
>> Yes, and that's a horrible notation.
> 
> That's a matter of preference really. Pointer notation in C is worse
> because it uses the same syntax for multiple different purposes.
> 
>> 
>>> Its a useful tool, that programmers have uses for.
>>> 
>>> If you think they're evil, then you're probably thinking too much in C.
>> 
>> They are evil in perl because the notation is unwieldy, especially when
>> you need to de-reference a reference.  That they are indistinguishable
>> from non-references doesn't help.
> 
> They're not entirely indistinguishable, the Perl VM can tell, that's
> what the "ref" built-in is for.
> 
> They're not *visually* indistinguishable, but C is no different if the
> scope where the variable was defined is not currently in your screen.
> 
>   fun( foo, bar );
> 
> ^ Tell me what foo and bar are, _and_ tell me what types fun() takes
> in C from that statement alone.
> 
> 
> 
>> 
>>

Re: dangerous perl (Re: is this reasonably save?)

2017-05-25 Thread John SJ Anderson
Folks, this has passed the event horizon of what’s appropriate for the 
Beginners list a good while back. If y’all wanna continue this conversation, 
please kindly do so outside the bounds of this mailing list. 

thanks,
john,
the resident list mom. 



> On 25May2017, at 10:52, Uri Guttman  wrote:
> 
> On 05/25/2017 01:33 PM, lee wrote:
>> Uri Guttman  writes:
>> 
>>> >> this private IMO>
>>> 
>>> 
>>> On 05/24/2017 08:20 PM, lee wrote:
>>>> Uri Guttman  writes:
>>>> 
>>>> 
>>>> you can get an array of hashes, where each hash is one row.
>>>> 
>>>> learning dereferencing will do you much more good than using eval
>>>> EXPR. references are key to deeper data structures in perl and are
>>>> used all over the place. it is a core skill you should focus on as it
>>>> will solve your current problem and many to come.
>>>> Since when are there any data structures in perl?  Variables are even
>>>> virtually typeless.
>>> since when is a variable a data structure? :)
>> It is when it has a type.
>> 
>> 
>> typedef struct {
>>   unsigned long MemTotal;
>>   unsigned long MemFree;
>>   unsigned long Buffers;
>> } meminfo;
>> 
>> 
>> meminfo test;
>> meminfo foo[20];
>> 
>> int bar;
>> int baz[20];
>> 
>> 
>> The difference between 'int' and 'meminfo' is that 'int' is pre-defined
>> while 'meminfo' is defined by the programmer.  Both are data types of
>> which you can declare variables.  The variables you declare are
>> instances of the data structures that correspond to the type of the
>> variable.  For practical purposes, the variables 'test', 'foo[]', 'bar',
>> 'baz[]' are all data structures.
> 
> that is c, not perl. why do you keep bringing up c? languages are different 
> for various reasons. perl doesn't do strong typing so if you want to use and 
> learn perl, you can't say it should be like c. that isn't the way to learn 
> anything.
> 
> and those are trivial data structures in c. perl has hashes for simple data 
> structures. and YES, hashes are data structures, no matter what you say in 
> opposition.
>> 
>> Perl doesn't have data structures, so variables in perl are not data
>> structures.  That is unfortunate.
> wrong. i won't argue this again. you haven't the experience in programming to 
> defend that point.
>>> the key is again references which still seems to confuse you. a scalar
>>> can hold only one thing.
>> A scalar can hold many different things, like an integer, a float, a
>> double, a string, and at least three different types of references.  You
>> never really know what it happens to be.
> you code so you know what it can be.
>> Why would I need a reference to put a hash into an array or into a hash? 
>> Perl may need that internally, which isn't relevant to the programmer in the 
>> first place. 
> 
> huh??? that is how you build complex data structures in perl. you haven't 
> learned that yet. please learn references before you rant about them.
>>>>> if you need help with references, this list is the place to ask.
>>>> Why is it so awfully difficult to dereference a reference to an array
>>>> that contains references to arrays, and why does DBI, for example,
>>>> provide a function that returns such a reference?  It involves holding
>>>> the data in memory, so what is the supposed advantage of using cascaded
>>>> references?
>>> how will you organize the data without references?
>> I put it into a database.
> and when you get it out of the database what do you do with it? what about 
> complex cross connected tables? how do you manage that in memory. you haven't 
> dealt with complex data yet if you think that is a solution.
>> 
>>> they are the branches in the tree of data. returning a single
>>> reference is much more efficient than returning the whole array or
>>> hash. that would involve copying the array/hash onto the stack and
>>> then copying it again to a variable in the caller. that is very slow.
>> Programming is even slower when you have to mess around with nested
>> references, trying to figure out how to de-reference them correctly.  I
>> did spent hours with that ...
> hours? i spent years. decades even. experience helps. :)
>>> you say cascaded references. i call that a data tree.
>> Arrays do not look like trees to me, 

Re: WWW::Mechanize requires wget

2017-04-04 Thread John SJ Anderson

> On 4Apr2017, at 11:13, SSC_perl  wrote:
> 
>> On Apr 4, 2017, at 10:59 AM, John SJ Anderson  wrote:
>> 
>> I’m not sure what was behind the resolution of your problem, but I can 
>> assure you I’m typing this on a Macintosh without wget installed, and 
>> WWW::Mechanize works just fine.
> 
>   Weird.  Which OS are you running?  I’m on 10.11.6.
> 
>   Perhaps something else got installed along with wget, but whatever it 
> was, that install solved my problem.

It’s whatever is current, but I’ve used WWW::Mechanize on MacOS for the last 
*mumble* versions, never having wget installed, without any problem. 

I also just checked, and the string ‘wget’ does not appear in the 
WWW::Mechanize dist at all. ¯\_(ツ)_/¯ 


j.

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




Re: WWW::Mechanize requires wget

2017-04-04 Thread John SJ Anderson

> On 4Apr2017, at 10:43, SSC_perl  wrote:
> 
>   This is a heads up for anyone wanting to use WWW::Mechanize on OS X.  
[snip]

Apple ships ‘curl’ instead of ‘wget’. Always has; not sure why.

‘wget’ is *NOT* required for WWW::Mechanize on MacOS, however. I’m not sure 
what was behind the resolution of your problem, but I can assure you I’m typing 
this on a Macintosh without wget installed, and WWW::Mechanize works just fine.

chrs,
john.

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




Re: search and replace

2016-06-29 Thread John SJ Anderson

> On Jun 29, 2016, at 09:20, Uri Guttman  wrote:
> 
> since you are correct about modules being already there, why do you write 
> your own versions of 
> slurp_file and write_file? the module File::Slurp has those functions which 
> are stable, fast and debugged.

Please don’t use File::Slurp. See 
http://blogs.perl.org/users/leon_timmermans/2015/08/fileslurp-is-broken-and-wrong.html
 for some reasons why. 

File::Slurper or Path::Tiny are both good alternatives; Path::Tiny in 
particular has a very convenient API and makes working with files, directories, 
and paths in a cross-platform way super easy. 

thanks,
john.


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




Re: how to install WWW::Salesforce::Simple on a Mac? cpanm refuses to install Crypt::SSLeay

2016-04-15 Thread John SJ Anderson
>  Apparently the Crypt::SSLeay module won't install for my protection
> (HeartBleed?), but it is still a required prerequisite for
> WWW::Salesforce.

Apple stopped distributing the OpenSSH headers recently. Those are required to 
build Crypt::SSLeay. 

You can get the source for OpenSSH and install it to /usr/local (it’s the 
standard './configure && make && sudo make install' dance, and it will end up 
under /usr/local. Once you’ve done that, Crypt::SSLeay will install without 
issue.

I haven’t looked at all, but I imagine the Crypt::SSLeay dependency is because 
the Salesforce module needs to talk HTTPS, which needs Crypt::SSLeay. 

chrs,
john.


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




Re: Storing Output file.

2016-02-01 Thread John SJ Anderson

> On Feb 1, 2016, at 05:34, Thomas J Hughes  wrote:
[ snip ]

This is *completely* inappropriate for the perl-beginners list, or as an 
off-list reply to a message received from the list.

If you don't want to get email related to people trying to learn the Perl 
language, I suggest you make use of this unsubscribe link immediately. 

> To unsubscribe, e-mail: beginners-unsubscr...@perl.org

Failing that, if you intend to remain on this list, you need to moderate both 
your language and your tone. Any further instances of this type of behavior 
will be grounds for your removal from this mailing list. 

john,
perl-beginners list mom. 




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




Re: converting Genbank format in gff format

2015-08-18 Thread John SJ Anderson
On Mon, Aug 17, 2015 at 3:58 PM, Uri Guttman  wrote:

> On 08/17/2015 03:57 AM, atteyet-alla.yas...@ukb.uni-bonn.de wrote:
>
> hi all,
>
> is there a possibilty to convert Genbank format in gff format using perl?
> I installed perl5 in my linux.
>
>
Atteyet-Alla -- there's a 'genbank2gff' script in the Bioperl dist, perhaps
that at least gives you some hints on where to start? Code is here:

https://metacpan.org/source/CJFIELDS/BioPerl-1.6.924/scripts/Bio-DB-GFF/bp_genbank2gff.pl


You'll need to install the Bioperl module.

> the answer is yes, perl can convert anything into anything. that is true
> for most if not all languages. do you have more questions?
>
>
Wow, Uri, do you suppose Perl could convert your smug condescending answer
into something useful? Geez.


john.

-- 
*John Anderson* • j...@genehack.org • *@genehack* • www.genehack.org
Suck it up, buttercup.


Re: reading from socket

2015-08-11 Thread John SJ Anderson
On Tue, Aug 11, 2015 at 5:24 AM, Chris Knipe  wrote:

>
>
> my $numBytesToRead = 512;
>
> my $buffer;
>
> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
>
>   if ($buffer =~ m/\r\n\.\r\n$/) {
>
> print $buffer;
>
> last;
>
>   }
>
> }
>
>
>
> I’m obviously doing this wrong :(  Can anyone perhaps show me the light?
>
>
Don't you need to put $bytesRead into $buffer at some point?

j.


-- 
*John Anderson* • j...@genehack.org • *@genehack* • www.genehack.org
Suck it up, buttercup.


Re: reading from socket

2015-08-11 Thread John SJ Anderson
On Tue, Aug 11, 2015 at 6:58 AM, John SJ Anderson  wrote:

> On Tue, Aug 11, 2015 at 5:24 AM, Chris Knipe  wrote:
>
>>
>>
>> my $numBytesToRead = 512;
>>
>> my $buffer;
>>
>> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
>>
>>   if ($buffer =~ m/\r\n\.\r\n$/) {
>>
>> print $buffer;
>>
>> last;
>>
>>   }
>>
>> }
>>
>>
>>
>> I’m obviously doing this wrong :(  Can anyone perhaps show me the light?
>>
>>
> Don't you need to put $bytesRead into $buffer at some point?
>

Wow, and this is why we don't review the code before the coffee... 8^/

j.


-- 
*John Anderson* • j...@genehack.org • *@genehack* • www.genehack.org
Suck it up, buttercup.


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

2015-05-26 Thread John SJ Anderson
On Tue, May 26, 2015 at 8:53 AM, someone called  wrote:


> ATTENTION: It apperars 'g++' is not a working compiler, please make
> sure all necessary packages are installed.
>
>  that is your problem. For whatever reason, g++ (the GNU C++ compiler)
is not installed properly, or is not being found in your path, or
_something_.

Try seeing what running 'g++' tells you.

j.


Re: Perlists groupware service

2015-04-15 Thread John SJ Anderson
I don't see any indication that web site is at all affiliated with this
mailing list. What leads you to think we can answer your question?

On Wed, Apr 15, 2015 at 2:59 AM, Masayoshi Fujimoto <
m.fujim...@rocketmail.com> wrote:

> Hi.
> How should I delete my email address from the following website?
>
> https://groups.perlists.pm/sympa/home
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Doubt

2015-03-29 Thread John SJ Anderson
Please show exactly what commands you ran and what output you got. In what
you're reporting, there's a typo, and it's not clear if that's a copy-paste
error or a problem in the actual command.

chrs,
john.


On Mon, Mar 30, 2015 at 1:16 AM, Frank Vino  wrote:

> When i try to install Alias.pm file from environment i was getting an
> error message as cannot locate alimas.pm file, then i checked in cpan it
> was showing, In case how to fix this and update the Alias.pm file.
>
> Frank
>


Re: Why doesn't this script error?

2015-03-14 Thread John SJ Anderson
Try again with 'use strict' and 'use warnings' turned on.

On Sat, Mar 14, 2015 at 1:40 PM, Sherman Willden 
wrote:

> I am new to Eclipse and Epic so I wrote the below script which I thought
> would error but it runs. Why?
>
> #!/usr/bin/perl
>
> use 5.18.2;
>
> print "Hello World \n";
>
> print this
>
> 1
>
> Thank you;
>
> Sherman
>


Re: Re[2]: Need something like macro

2015-03-09 Thread John SJ Anderson
On Mon, Mar 9, 2015 at 12:48 PM, Артём Варнайский 
wrote:

Execution time of inline variant approximately 17.6ms, subroutine solution
> slower about 26%. My script is captcha generator. Random sign used very
> often during execution. I think 26% is a lot enough in this case.
>
>
And the average latency of the network connection you're serving this
captcha over is... ?

j.


Re: Looping regexes against a list

2015-01-19 Thread John Mason
On Mon, Jan 19, 2015 at 11:36 AM, Shawn H Corey 
wrote:

> On Mon, 19 Jan 2015 11:18:01 -0500
> bill pemberton  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


Re: How does opendir/readdir process files

2015-01-14 Thread John SJ Anderson
On Tue, Jan 13, 2015 at 7:40 PM, Brandon McCaig  wrote:
> Harry:
>
> (Expect typographical errors in such a long post...)
>
> tl;dr? RTFM.

Please don't tell people that. It's not helpful, it's not a helpful
attitude, and it's really not welcome here.

The rest of your post may be excellent, but I couldn't say, as I
stopped reading immediately after reading that.

john.

-- 
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-08 Thread John SJ Anderson
On Thu, Jan 8, 2015 at 5:52 PM, Harry Putnam  wrote:
> Opening a directory and readdir with a grep in there to find specific
> filenames, how does that process collect the files?

See http://www.perlmonks.org/?node_id=533744

tl;dr: it depends on your OS.


> I mean will the generated @ar of files be oldest first or someother
> reliable order?

and tl;dr: no, most likely not.

j.

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




Re: Unable to install Net::IP

2014-12-02 Thread John SJ Anderson
Whenever you have a module installation fail, your first step should
be to ask: is it failing for other people?

Results of CPAN Testers (which is basically a distributed testing
network) are available on the dist's MetaCPAN page. For Net::IP,
that's here: https://metacpan.org/pod/Net::IP

(Spoiler: it has a tiny number of fails but a _huge_ number of passes.
It works for almost everybody.)

Based on those results, the good news is, it seems like the module
itself (probably) isn't broken, but instead, there's something about
your machine that isn't working for it.

Based on the output you have shown, my first question would be: do you
actually have make installed?

If you do have make installed, the next step would be to download the
dist tarball yourself (there's a download link on that MetaCPAN page),
expand it, cd into it, and run 'perl Makefile.PL && make', and see
what the output of that is. I suspect make is giving an error that's
getting eaten by the cpan client, for whatever reason.

(Aside: doing the make as root is not the best idea. (Least privilege)++)

chrs,
john.


On Tue, Dec 2, 2014 at 2:17 PM,   wrote:
> Hi,
>
> I'm unable to find information on this issue.  Whenever I try to install
> Net::IP (to do a simple DHCP configuration file that will make IP address
> reservations DNS files that will do forward and reverse lookups) it gives me
> the following results:
>
> root@SERVER:~# cpan -i Net::IP
> Reading '/root/.cpan/Metadata'
>   Database was generated on Tue, 02 Dec 2014 10:53:28 GMT
> Running install for module 'Net::IP'
> Running make for M/MA/MANU/Net-IP-1.26.tar.gz
> Checksum for /root/.cpan/sources/authors/id/M/MA/MANU/Net-IP-1.26.tar.gz ok
>
>   CPAN.pm: Building M/MA/MANU/Net-IP-1.26.tar.gz
>
> Checking if your kit is complete...
> Looks good
> Writing Makefile for Net::IP
> Writing MYMETA.yml and MYMETA.json
>   MANU/Net-IP-1.26.tar.gz
>   make -- NOT OK
> Running make test
>   Can't test without successful make
> Running make install
>   Make had returned bad status, install seems impossible
>
>
> I'm running Ubuntu server:
> root@SERVER:~# cat /etc/os-release
> NAME="Ubuntu"
> VERSION="14.04.1 LTS, Trusty Tahr"
> ID=ubuntu
> ID_LIKE=debian
> PRETTY_NAME="Ubuntu 14.04.1 LTS"
> VERSION_ID="14.04"
> HOME_URL="http://www.ubuntu.com/";
> SUPPORT_URL="http://help.ubuntu.com/";
> BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/";
>
> Perl 5.18:
> root@SERVER:~# perl -v
>
> This is perl 5, version 18, subversion 2 (v5.18.2) built for
> x86_64-linux-gnu-thread-multi
> (with 41 registered patches, see perl -V for more detail)
>
> Copyright 1987-2013, Larry Wall
>
> Perl may be copied only under the terms of either the Artistic License or
> the
> GNU General Public License, which may be found in the Perl 5 source kit.
>
> Complete documentation for Perl, including FAQ lists, should be found on
> this system using "man perl" or "perldoc perl".  If you have access to the
> Internet, point your browser at http://www.perl.org/, the Perl Home Page.
>
> I'm running always as root for everything.  It makes my server management
> much easier by saving me from typing "sudo" for everything I do.
>
> Any help would be greatly appreciated!
>
> Zac
> Power Switch of Tulsa, LLC
>
> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional
> commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

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




Re: At wits end CG::unescape

2014-11-25 Thread John SJ Anderson
What version of CGI::Application do you have installed?

Assuming the most recent one
(https://metacpan.org/source/MARKSTOS/CGI-Application-4.50/lib/CGI/Application.pm),
line 1951 is:

if ( $p{path_info} && $self->query->path_info() ) {

$self->query calls the 'query' method, defined at line 493. I'm
guessing code flow goes into the 'else' half of the branch there, and
ends up calling $self->cgiapp_get_query() (on line 503).

That method is defined at line 250, and ultimately returns the result
of calling CGI->new().

I would suggest either putting in some debug print() statements into
that cgiapp_get_query() routine, or using the debugger to stop
execution inside there and looking at what that call from CGI->new()
is actually returning.

chrs,
john.








On Tue, Nov 25, 2014 at 7:56 AM, Patton, Billy N  wrote:
> OS : mac 10.10.1 Yosemite
> Perl version : 5.16.0 (perlbrew)
> I have file cp.cgi that is the top level
> It uses CP.pm
> which inherits Base.pm
> which inherits CGI::Application
> CGI::Application Requires CGI.pm
> CGI.pm has a use CGI::Util qw(… unescape …);
>
> When I try and run cp.cgi I get a timeout.
> The erro log only tells me that I get a timeout
> [Tue Nov 25 09:13:53.677383 2014] [cgi:warn] [pid 461] [client ::1:63053] 
> AH01220: Timeout waiting for output from CGI script 
> /Library/WebServer/Documents/cportal/html/cp.cgi, referer: 
> http://localhost/index.html
>
> when I try and run it from the command line : perl cp.cgi
> I get
> Software error:
> Undefined subroutine CGI::unescape
>  at 
> /Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application.pm
>  line 1951.
> 
> 
> For help, please send mail to this site's webmaster, giving this error message
> and the time and date of the error.
>
> 
> [Tue Nov 25 09:34:59 2014] cp.cgi: Undefined subroutine CGI::unescape
> [Tue Nov 25 09:34:59 2014] cp.cgi:  at 
> /Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application.pm
>  line 1951.
>
> unescape exists in CGI::Util.pm and is exported.
>
> When I put a Dumper \%INC I get: Making sure that I wasn’t mixing too many 
> version
>
> 'CGI/Application.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application.pm’,
> 'CGI/Application/Plugin/Redirect.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/Redirect.pm',
> 'CGI/Application/Plugin/TT.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/TT.pm’,
> 'CGI/Application/Plugin/ValidateRM.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/ValidateRM.pm’,
> 'CGI/Application/Plugin/LogDispatch.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/LogDispatch.pm',
> 'CGI/Carp.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Carp.pm’,
> 'CGI/Application/Plugin/Config/YAML.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/Config/YAML.pm',
> 'CGI/Application/Plugin/DBH.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/DBH.pm’,
> 'CGI/Util.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Util.pm’,
> 'CGI/Application/Plugin/Forward.pm'  => 
> '/Users/bpatto/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/CGI/Application/Plugin/Forward.pm’,
>
> unescape does not exist in Application, even though it tells me line 1951
> %INC shows me that it is including the right file.
> Util.pm is exporting
> package CGI::Util;
> use base 'Exporter';
> require 5.008001;
> use strict;
> use if $] >= 5.019, 'deprecate';
> our @EXPORT_OK = qw(rearrange rearrange_header make_attributes unescape escape
> expires ebcdic2ascii ascii2ebcdic);
>
> our $VERSION = '4.09’;

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




Re: CGI::Application::Plugin::TT

2014-11-12 Thread John SJ Anderson
On Wed, Nov 12, 2014 at 4:54 AM, Patton, Billy N  wrote:
> I’ve , mistakenly, updated to Mac OS 10.10 Yosemite.
> That completely caused my app to fail in Apache 2.4.
> Looks like it might be a version problem for TT.pm

TT.pm is really 'Template.pm'. Are you sure the Perl you're using has
it installed?

What does 'perl -MTemplate -e 1' tell you if you run it in a terminal?

On my Yosemite install, the system perl (at /usr/bin/perl) does not
have Template.pm installed. I'm not sure whether installed modules
were propagated across the update process (because I don't rely on the
system perl for anything), but I would strongly suspect they were
_not_.

You should consider -- *strongly* consider -- using perlbrew or plenv
to set up a Perl installation that is not under the control of your
operating system vendor. That helps reduce the occurrence of these
issues.

> I’ve tried to install a new TT.pm from cpan but it tells me that it is up to 
> date.
> I’ve tried changing the Template->new to HTML::Template-> new with bad 
> results.
> I’ve tried changing use Template to use HTML::Template with bad results
> I’ve tried changing the use Template 2.0; to use Template. results are still 
> it fails;

One more note. This ^^ is what thrashing looks like. Don't start
randomly changing around pieces of your code hoping things will
magically work. Look at the actual error message that you're getting,
from the code that used to work. What does that say?

j.

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




Re: (Possibly a terrible lamer) is `open' format wrong

2014-11-03 Thread John SJ Anderson
On Mon, Nov 3, 2014 at 9:57 AM, Harry Putnam  wrote:
> Ken Slater  writes:

 that attribution is wrong. Ken didn't say this, Shlomi did.

>> It is a good idea to avoid using $_ in production code:

This is an opinion. I think it's ... I hesitate to use the word
"controversial", but it's not universally shared, let us say.

> But why is this important?

It's not. (Somebody is going to reply to this and talk about
maintainability, and maybe clarity or something like that, and all of
that may be valid, but for something this trivial, if the code works
and you're happy, don't worry about it.)

chrs,
john.

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




Re: Interactive perl based application who works as per schedule

2014-10-09 Thread John SJ Anderson
On Thu, Oct 9, 2014 at 2:19 AM, Benjamin Fernandis  wrote:
> Hi,

Hi!

[ snip ]

> Please suggest me for this.

I suggest you don't try to re-invent cron. Cron works. Cron is a known
quantity. You don't need to re-invent cron.

What you need is a way to let other people edit crontab files, with a
better UI. So make a Perl web application. Require authentication --
tie it into your AD or LDAP or whatever -- and provide a UI that
writes out a crontab file based on the users input.

Then have a cronjob that runs every minute that looks at those crontab
files, detects when one has been changed, and reloads it.

chrs,
john.

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




Re: Problem with regex

2014-10-06 Thread John Delacour

> On 6 Oct 2014, at 18:57, punit jain  wrote:
> 
> Thanks Paul. However I think I couldnot explain the problem.
> 
> The issue is when I have mailid's as well as a part of input stream.
> 
>  Input stream ---> $str="ldap:///uid=user1,ou=People,o=test.com 
> ,a...@test.com ,t...@test.com 
> ,r...@test.com 
> ,ldap:///uid=user2,ou=People,o=test.com 
> ,ldap:///uid=user3,ou=People,o=test.com "

Suddenly you've switched to double quotes.  That won't do unless you escape the 
@s.

> expected output
> 
> first=uid=user1,ou=People,o=test.com 
> first=a...@test.com 
> first=t...@test.com 
> first=r...@test.com 
> first = uid=user2,ou=People,o=test.com 
> first = uid=user3,ou=People,o=test.com 

Try this.

#!/usr/bin/perl
use strict;
my $str 
='ldap:///uid=user1,ou=People,o=test.com,a...@test.com,t...@test.com,r...@test.com,ldap:///uid=user2,ou=People,o=test.com,ldap:///uid=user3,ou=People,o=test.com';
my @ldap = split 'ldap:///', $str;
my $concat;
for (@ldap){
  for (split /,/) {
if (/\@/) {
  $concat .= "\nfirst=$_"
} elsif (/uid/) {
  $concat .= "\nfirst=$_,"
} else {
  $concat .= "$_,"
}
  }
}
my @printlist = split /\n/, $concat;
for (@printlist) {
  unless (/^$/){ # skip empty lines
s~,$~~g; # remove trailing commas
print "$_\n";
  }
}


#JD





Re: [ANN] SurfShop 1.6.1 Shopping Cart Released

2014-09-21 Thread John W. Krahn
:1301:  $main::global->{'config'}->{'prunecart'} = 7 if (! 
$main::global->{'config'}->{'prunecart'});  # default time 7 days
useradmin.cgi:39:$main::global->{'form'}->{'storeid'} = '1' unless 
($main::global->{'form'}->{'storeid'});  # defaults to '1'
useradmin.cgi:53:$main::global->{'config'}->{'ssl_port'} = 443 unless 
($main::global->{'config'}->{'ssl_port'});
ss_files/SSLib.pm:153:  $main::global->{'omsg'}->{'0'} = 'class="text-small">' if (! $main::global->{'omsg'}->{'0'});
ss_files/SSLib.pm:520:  $in_sortby = $main::global->{'form'}->{'sortby'} 
if not $in_sortby;
ss_files/SSLib.pm:521:  $database  = $main::global->{'form'}->{'b'} if 
not $database;
ss_files/SSLib.pm:549:  $main::global->{'form'}->{'scount'} = 1 if 
(!$main::global->{'form'}->{'scount'});

ss_files/SSLib.pm:1453: $label = $opt if (! $label);
ss_files/SSLib.pm:1468: $label = $field if (!$label);
ss_files/SSLib.pm:1683: $form->{'QBacct_coupon'}= 
$out->{'coupontype'} ? "$out->{'coupontype'} Discounts" : 'Coupon 
Discounts' unless ($form->{'QBacct_coupon'});
ss_files/SSLib.pm:1684: $form->{'QBinvitem_coupon'} = 
$out->{'coupontype'} ? $out->{'coupontype'} : 'Coupon' unless 
($form->{'QBinvitem_coupon'});
ss_files/SSLib.pm:1758: $form->{'shiptype'} = $calc if not 
$form->{'shiptype'};

ss_files/SSLib.pm:2005: $template = 'main.htm' unless ($template);
ss_files/SSLib.pm:2044: 
$main::global->{'form'}->{'Ecom_BillTo_Postal_StateProv'} = 
$main::global->{'form'}->{'defaultstate'} unless 
$main::global->{'form'}->{'Ecom_BillTo_Postal_StateProv'};
ss_files/SSLib.pm:2045: 
$main::global->{'form'}->{'Ecom_ShipTo_Postal_StateProv'} = 
$main::global->{'form'}->{'defaultstate'} unless 
$main::global->{'form'}->{'Ecom_ShipTo_Postal_StateProv'};
ss_files/SSLib.pm:2081: $content_type   = 'text/plain' unless 
($content_type);

ss_files/SSLib.pm:2087: $count = 1 unless ($count);
ss_files/SSLib.pm:2119: $count = 1 unless ($count);
ss_files/SSLib.pm:2447: $item->{'unitprice'} = 
$price unless $item->{'unitprice'};
ss_files/SSLib.pm:2486: $item->{'optionprice'} = 
$addtl unless ($item->{'optionprice'});

ss_files/SurfDB.pm:315: $show = 10 unless ($show);
ss_files/SurfDB.pm:317: $cursor = 1 unless ($cursor);
ss_files/SurfDB.pm:323: $key = $sort unless ($key);  # 
in case Wildcards are used

ss_files/SurfDB.pm:429: $result = 'BAD PASSWORD' unless ($result);
ss_files/SurfDB.pm:635: $length = 1 unless ($length);
ss_files/SurfDB.pm:830: $replace = {} unless ($replace);
ss_files/SurfDB.pm:1168:$cursor = 1 unless ($cursor);
ss_files/SurfDB.pm:1169:$show = 10 unless ($show);

The idiom:

$variable = 'value' unless $variable;
$variable = 'value' if ! $variable;
$variable = 'value' if not $variable;

Could be written as:

$variable ||= 'value';


admin.cgi:154:  $main::global->{'form'}->{'show_cart_on_add'} = 
1 if not defined $main::global->{'form'}->{'show_cart_on_add'};
admin.cgi:155:  $main::global->{'form'}->{'offline_mode'} = 0 if 
not defined $main::global->{'form'}->{'offline_mode'};
admin.cgi:832:  $main::global->{'form'}->{$checkbox} = '' if (! 
defined($main::global->{'form'}->{$checkbox}) );
forceorder.cgi:369:$out->{'minibasket'} = $data->{'minibasket'} 
unless (defined($out->{'minibasket'}));
shop.cgi:192:   $main::global->{'form'}->{"modify_$cartitem"} = 
$test[1] unless (defined ($main::global->{'form'}->{"modify_$cartitem"}));
shop.cgi:760:   $main::global->{'form'}->{$checkbox} = '' if (! 
defined($main::global->{'form'}->{$checkbox}) );
shop.cgi:793: $main::global->{'form'}->{"modify_$cartitem"} = $test[1] 
unless (defined ($main::global->{'form'}->{"modify_$cartitem"}));
shop.cgi:798: $main::global->{'form'}->{"modify_$cartitem"} = $test[1] 
unless (defined ($main::global->{'form'}->{"modify_$cartitem"}));
ss_files/SSLib.pm:1540: $form->{$field} = $out->{$field} unless 
(defined ($form->{$field}));

ss_files/Surf.pm:153:   $eol = "\n" unless defined $eol;

The idiom:

$variable = 'value' unless defined $variable;
$variable = 'value' if ! defined $variable;
$variable = 'value' if not defined $variable;

Could be written as:

$variable //= 'value';

ss_files/SSLib.pm:2812: $this_date = $this_date || $dt;  ## WHAT DOES 
THIS DO?


The same as:

$this_date = $dt unless $this_date;

See above.


ss_files/Multipart.pm:25:else {
ss_files/Multipart.pm:26:   my($old);
ss_files/Multipart.pm:27:   ($old, $/) = ($/,$crlf);
ss_files/Multipart.pm:31:   $/ = $old;
ss_files/Multipart.pm:32:}

ss_files/SSLib.pm:1939: my $temp = $/;
ss_files/SSLib.pm:1940: $/ = undef;
ss_files/SSLib.pm:1948: $/ = $temp;

ss_files/SSLib.pm:1994: if (-f $from_page) {
ss_files/SSLib.pm:1995: my $temp = $/;
ss_files/SSLib.pm:1996: $/ = undef;
ss_files/SSLib.pm:2001: $/ = $temp;
ss_files/SSLib.pm:2002: }

ss_files/SurfDB.pm:90:  my $temp = $/;
ss_files/SurfDB.pm:91:  $/ = undef;
ss_files/SurfDB.pm:93:  $/ = $temp;

ss_files/SurfDB.pm:497: my $temp = $/;
ss_files/SurfDB.pm:498: $/ = "\n";
ss_files/SurfDB.pm:573: $/ = $temp;

This idiom can be replaced with:

local $/;  # $/ is now undef

Or:

local $/ = $crlf;


There is a problem in the following subroutine.  If you know how hashes 
work you should be able to figure it out.


admin.cgi:922:sub new_field {
admin.cgi:923:  my ($names, $cols, $html, $current, $action) = @_;
admin.cgi:924:  my ($cell, $totalcells, $count, $counter, %cell) = ();
admin.cgi:925:  while ($current =~ m|(.*?)|sig) {

admin.cgi:926:  $cell{$2} = $1;
admin.cgi:927:  $totalcells++;
admin.cgi:928:  }
admin.cgi:929:  if ($action eq 'del') {
admin.cgi:930:  foreach my $name (split (/, */ , $names)) {
admin.cgi:931:  delete ($cell{$name});
admin.cgi:932:  $totalcells--;
admin.cgi:933:  }
admin.cgi:934:  }
admin.cgi:935:  else {
admin.cgi:936:  foreach my $name (split (/, */ , $names)) {
admin.cgi:937:  next unless ($name =~ /\w/);
admin.cgi:938:  my $sortstr = substr("00$totalcells", 
-2);  # Pads $totalcells with 2 leading zeroes for non-HTML emails.
admin.cgi:939:  $html =~ s~\na new line between admin.cgi:940:  $cell{"$sortstr$name"} = 
"\n$html\n";
admin.cgi:941:  $cell{"$sortstr$name"} =~ 
s/\[NAME\]/$name/sig;

admin.cgi:942:  $totalcells++;
admin.cgi:943:  }
admin.cgi:944:  }
admin.cgi:945:  ($counter, $count) = 0;
admin.cgi:946:  $current = "\n";  # start off with a new line so HTML 
looks cleaner

admin.cgi:947:  foreach my $cell (sort keys (%cell)) {
admin.cgi:948:  my $cell_name = substr ($cell, 2);  # removes the 2 
digit number from the beginning of $cell and leaves only the calc name

admin.cgi:949: next unless ($cell);
admin.cgi:950: $current .= "\n\n" unless 
($count);  # adds an IF statement around custom calcs so they don't show 
if = $0.00

admin.cgi:951: $current .= "$cell{$cell}\n";
admin.cgi:952: $count++;
admin.cgi:953: $counter++;
admin.cgi:954: if ($count >= $cols || $counter == $totalcells) {
admin.cgi:955: $count = 0;
admin.cgi:956: $current .= "\n";
admin.cgi:957:  }
admin.cgi:958:  }
admin.cgi:959:  $html =~ s|\nbetween admin.cgi:960:  return 
"$current";

admin.cgi:961:}





John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
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 John SJ Anderson
On Mon, Sep 15, 2014 at 5:19 AM, Sam  wrote:

> If you are just looking for a REPL, look at:
> https://metacpan.org/pod/Devel::REPL

IMO, Reply is a little nicer -
https://metacpan.org/pod/distribution/Reply/bin/reply

j.

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




Re: returning arrays

2014-09-09 Thread John SJ Anderson
On Tue, Sep 9, 2014 at 2:57 PM, Shawn H Corey  wrote:

> Lists are sequences used by Perl. They are very short lived, seldom
> longer than one statement.

The way I've always liked to explain this is that arrays are the
containers you use to store a list.

As Shawn says, a list is usually pretty ephemeral -- but if you want
it to stick around, you can put it in an array variable.

chrs,
john.

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




Re: [ANN] SurfShop 1.6.1 Shopping Cart Released

2014-09-07 Thread John SJ Anderson
Hi -

This is a list for people starting to learn Perl, or with Perl questions.

It's not a list for announcing software written in Perl, so your post
here is off topic.

thanks,
john.


On Sat, Sep 6, 2014 at 5:55 PM, SSC_perl  wrote:
> Sorry for a repost so soon, but if you downloaded SurfShop 1.6.0, you 
> were greeted with a 500 error upon installation.  Somehow, during the upload, 
> GitHub for Mac corrupted some of the files with extraneous text which 
> rendered SurfShop unusable.  Unfortunately, it wasn't caught for a few days.
>
> I apologize profusely if you were bitten by this.  I have found and 
> cleaned all the miscreant files, and version 1.6.1 was uploaded to GitHub on 
> Friday.  After that fiasco, I wanted to sit on the fix awhile and run more 
> tests before letting everyone know that it was fixed.  I'm pleased to say 
> that version 1.6.1 fixes those problems.
>
> So, if you're interested in an open source Perl/MySQL shopping cart, 
> check out our forum for more information:
>
> http://www.surfshopcart.com/forrumm/viewtopic.php?f=2
>
> Again, let us know what you think!  Your feedback, as always, is 
> appreciated.
>
> Regards,
> Frank Jance
>
> http://www.surfshopcart.com/
> Setting up shop has never been easier!
>
> Follow us on GitHub!
> https://github.com/surfshopcart/surfshop
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>

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




Re: cygwin64 perl blead YAML and JSON backend chicken and egg.

2014-09-07 Thread John SJ Anderson
Hi Dave -

I really don't think Perl beginners is the best place to be asking
this question. Have you considered trying something like
http://code.activestate.com/lists/perl-win32-users/ ? That seems like
a more likely place to connect with somebody who can help you.

chrs,
john.


On Mon, Sep 1, 2014 at 6:46 AM, Dave Horner  wrote:
> continuing to play with the cygwin64 perl blead that I built on Aug-12th.  I
> mentioned the strange infinite loop in the questioning of gpg tool; haven't
> had time to research why that happened, yet.  I'm trying to get basic
> reporting facilities up, as I have yet to report a single cygwin report.
> All of my testing is failing within configure so force does not help and of
> course they don't get reported.
>
> As I mentioned before I have to be cognizant of the environment variables
> shared with my windows strawberry perl.
> This means at first I was tried all these options with PERL_YAML_BACKEND and
> PERL_JSON_BACKEND set...which didn't work.  So I've also tried unsetting
> them, ensuring they were not in env/set output, and trying to install again.
>
> It appears that PERL_YAML_BACKEND defaults to YAML when no value is set.
>
> the issue it seems resides within: /usr/local/lib/perl5/5.21.3/CPAN/Meta.pm
> $backend = Parse::CPAN::Meta->yaml_backend();
> $data = eval { no strict 'refs'; &{"$backend\::Dump"}($struct) };
> if ( $@ ) {
>   croak $backend->can('errstr') ? $backend->errstr : $@
> }
>
> # running Build.PL
> Could not load PERL_YAML_BACKEND 'YAML'
>  at /usr/local/lib/perl5/5.21.3/CPAN/Meta.pm line 613.
>
> I've tried forcing installing YAML::XS, YAML, YAML::Tiny, YAML::Old,
> JSON::XS, JSON
>
> They all give me a similar error about the backend not being there;  what am
> I missing?  Do I need to be bootstrapping these files manually?  Shouldn't a
> basic backend support for YAML/JSON come out of the box with perl blead?
>
> I appreciate any help/guidance.
>
> Thanks,
> --dave
> https://questhub.io/realm/perl/quest/53d39f40b587a43011000143
> http://wiki.cpantesters.org/wiki/YACSmokePOE - built perl using instructions
> found here.

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




Re: return the list content

2014-08-18 Thread John SJ Anderson
On Mon, Aug 18, 2014 at 1:38 AM, Paul Johnson  wrote:
> On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote:

>> which one is the better way to return the list content? And if the
>> method is an instance method?
>
> Functionally, the two are identical.  The first is returning a reference
> to the array you have created.  The second is returning a reference to a
> new array created from a (shallow) copy of the array you have created.

[ snip ]

To expand further (because you asked about "list context"), note that
both are returning a _scalar_, because references are always scalars.
If you want to return a list, you should just do

return @x;

If you wanted the return value to depend on the calling context, you
could use 'wantarray' like so:

return wantarray ? @x : \@x;

That said, APIs that have contextually dependent return values are
usually fairly confusing to use, so consider not doing this.

chrs,
john.

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




Re: Suddenly.... Part 2

2014-07-31 Thread John W. Krahn

Peter Holsberg wrote:

I think I've isolated the section that is not doing what I want.

open (FHIN, "$recapfile") or die $!;


That would be better as:

open my $FHIN, '<', $recapfile or die "Cannot open '$recapfile' because: 
$!";




my $indexb; ## for the recapfile array
my $ofile;


You never use this variable, it should be:

my @ofile;



# Create new array containing all the lines of recapfile up to
# the string RESULTS OF BOARD 1

XYZZY:
while ()
{
last XYZZY if  / RESULTS OF BOARD 1/;
chomp;
$ofile[$indexb++] .= $_;


That would be better as:

push @ofile, $_;



 }
close FHIN;

To see what was put into ofile, a line at a time, I used

foreach (@ofile) {
   print "$_\n";
}

Is that correct?


That is correct.


John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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




Re: Why Does the Following Not Work?

2014-07-30 Thread John SJ Anderson
> die("***YOU MUST HAVE A DESTINATION ADDRESS/NETWORK address.\n")
> if (@destinations);

Don't you mean 'if !@destinations' or 'unless @destinations' here?
That test is for whether @destinations has any entries.

% perl -E 'my @x=(); say "lives" if (@x)'

%  perl -E 'my @x=(1); say "dies" if (@x)'
dies

j.

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




Re: Apologetic request for simple one-off script

2014-07-14 Thread John SJ Anderson
You were asked to take this off list once.

I'm now telling you, in my official capacity as list moderator:
further discussion of this is off-topic and does not belong on this
list.

Let it go.

thanks,
john.



On Mon, Jul 14, 2014 at 7:18 AM, John Delacour  wrote:
>
> On 14 Jul 2014, at 14:11, Shlomi Fish  wrote:
>
>>> perldoc -f open
>
>> This is irrelevant. Two-args open is dangerous - always use three-args open:
>>
>> * http://perl-begin.org/tutorials/bad-elements/#open-function-style
>
> Who wrote that?  Ah...a certain Shlomi Fish.
>
> open my $fh, "< $path"; # with or without the space _does_ contain three 
> arguments to all intents and purposes.
>
> Now tell us exactly how this is “dangerous”.  Give examples.
>
> JD
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>

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




Re: Apologetic request for simple one-off script

2014-07-14 Thread John Delacour

On 14 Jul 2014, at 14:11, Shlomi Fish  wrote:

>> perldoc -f open

> This is irrelevant. Two-args open is dangerous - always use three-args open:
> 
> * http://perl-begin.org/tutorials/bad-elements/#open-function-style

Who wrote that?  Ah...a certain Shlomi Fish.

open my $fh, "< $path"; # with or without the space _does_ contain three 
arguments to all intents and purposes.

Now tell us exactly how this is “dangerous”.  Give examples.

JD


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




Re: Apologetic request for simple one-off script

2014-07-14 Thread John SJ Anderson
Hi. List Mom here.

Please take this off list, it's not on-topic.

John: Thank you for answering the OP's question. However, Shlomi is
right, the two argument form of open() is something that the general
Perl community considers to be a deprecated style that should not be
used with new code. This list is not the place to argue that, that
ship has sailed.

Shlomi: line-by-line teardowns of scripts people post in response to
questions are generally not helpful, particularly when the script
_will_ work as written. It makes people feel attacked and leads to
defensive responses that make the list appear to be an unfriendly
place. If you think you can write a better or more correct script,
just provide it; this type of critique ends up being an overall
negative contribution.


thanks,
john,
perl-beginners list mom

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




Re: Apologetic request for simple one-off script

2014-07-14 Thread John Delacour

On 14 Jul 2014, at 05:39, Shlomi Fish  wrote:

> don't use two-args open

perldoc -f open

In the one- and two-argument forms of the call, the mode and
filename should be concatenated (in that order), preferably
separated by white space. You can--but shouldn't--omit the mode
in these forms when that mode is "<". It is always safe to use
the two-argument form of "open" if the filename argument is a
known literal.

JD

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




Re: Apologetic request for simple one-off script

2014-07-13 Thread John Delacour

On 13 Jul 2014, at 23:48, ESChamp  wrote:

> John Delacour has written on 7/13/2014 5:31 PM:
>> 
>> On 13 Jul 2014, at 21:43, ESChamp  wrote:
>> 
>>> ...lastname firstname other other other ... emailaddress
>>> 
>>> I wish to write a new file that contains only the emailaddress field
>>> contents.
>> 
>> Here’s an easily-understood way of doing it:
>> 
>> #!/usr/bin/perl
>> use strict;
>> while (){
>>  chomp;
>>  @_ = split / /;
>>  print $_[-1] . $/;
>> }
>> __DATA__
>> x x x a@b
>> x x x x c@d
>> x x e@f
> 
> That's great! How do I get it to read the data from a file?

Like this:

#!/usr/bin/perl
use strict;
my $filepath = "$ENV{HOME}/temp/a.txt";
open my $fh, "<$filepath" or die $!; 
while (<$fh>) {
 chomp;
 @_ = split / /;
 print $_[-1] . $/;
}


# JD


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




Re: Apologetic request for simple one-off script

2014-07-13 Thread John Delacour

On 13 Jul 2014, at 21:43, ESChamp  wrote:

> ...lastname firstname other other other ... emailaddress
> 
> I wish to write a new file that contains only the emailaddress field
> contents.

Here’s an easily-understood way of doing it:

#!/usr/bin/perl
use strict;
while (){
  chomp;
  @_ = split / /;
  print $_[-1] . $/;
}
__DATA__
x x x a@b
x x x x c@d
x x e@f




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




Re: Creating a hash of arrays from

2014-07-09 Thread John SJ Anderson
On Wed, Jul 9, 2014 at 6:59 PM, SSC_perl  wrote:
> If someone could explain what I'm doing wrong, I'd appreciate it.  I 
> just can't see it.

You're looping over the entries in the array, not the entries in the hash.

> foreach my $state (sort keys %entries) {
> say "The Zip Codes of $state are";
> foreach (@{$entries{$state}}) {

This foreach loop is looping over the five zip codes in the array...

> print Dumper (@{$entries{$state}});

And printing out the same array each time.

Try something like

foreach my $state ( sort keys %entries) {
  say "The ZIP codes of $state are: ";
  foreach my $zip ( @{ $entries{$state} } ) {
say "\t$zip";
  }
}


j.

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




Re: want to write to file in different format

2014-07-07 Thread John Delacour

On 7 Jul 2014, at 09:18, Sunita Pradhan  wrote:

> I have a file of contents:
> ---
> 1 6
> 2 7
> 3 8
> 4 9
> 5 10
> --
> I want a file with content:
> 
> 1 2 3 4 5
> 6 7 8 9 10

Try this:


#!/usr/local/bin/perl
use strict;
my (@col1, @col2);
while () {
  chomp;
  my @words = split / /;
  push @col1, $words[0];
  push @col2, $words[1];
}
print join " ", @col1;
print "\n";
print join " ", @col2;
__DATA__
1 6
2 7
3 8
4 9
5 10

#JD




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




Re: one line script for word count

2014-06-30 Thread John Delacour

On 30 Jun 2014, at 20:05, Jim Gibson  wrote:

> Try this:
> 
> $c = () = $line =~ /\b$w\b/g;

Or, slightly less obscure:

#!/usr/bin/perl
use strict;
my $line = "one potato two potato three potato four";
my @hits = $line =~ /potato/g;
print scalar @hits; # => 3
 

#JD

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




Re: CGI script produces blank screen

2014-06-27 Thread John SJ Anderson
On Fri, Jun 27, 2014 at 7:34 PM, SSC_perl  wrote:
> Any input would be greatly appreciated!

Look in the web server error log.

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




Re: uninitialized error for hash printing

2014-06-22 Thread John Delacour

On 22 Jun 2014, at 21:01, Sunita Pradhan  
wrote:

> I have following code for printing a simple hash.
> 
> #!/usr/bin/perl -w
> %hash = ("abc" => 123, "dfg" => 456, "xsd" => 34);
> foreach $k (keys %hash){
>  print "key $k:: value $hash{$k}\n";
>  }
> --
> Use of uninitialized value $k:: in concatenation (.) or string at 
> hash_test2.pl

Try this:

#!/usr/bin/perl -w
use strict;
my %hash = (
"abc" => 123,
"dfg" => 456,
"xsd" => 34
);
foreach my $k (keys %hash){
print "key $k\:: value $hash{$k}\n";
}

#JD



Re: Install Alien SVN::Core

2014-06-15 Thread John SJ Anderson
On Sun, Jun 15, 2014 at 11:36 AM, Tim Dunphy  wrote:
> Ok! Well if I do a which on that program:
>
> [root@uszmpaplp005lc apr-util-1.5.3]# which apu-1-config
> /usr/bin/apu-1-config
>
> It's found. Yay!

That's finding the system one, not the one you just installed under
/usr/local/apr/bin.

> But just for good measure I try adding that directory to my PATH.
>
> [root@host1 apr-util-1.5.3]# echo $PATH
> /opt/python27/bin:/opt/php-5.3.28/bin:/opt/csvquerytool-0.0.3/bin:/opt/python27/bin:/opt/php-5.3.28/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/opt/csvquerytool-0.0.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/apache2/bin:/root/bin:/opt/apache2/bin:/usr/local/apr/bin

Because you added it to the end of the PATH, the system will still
find the one under /usr/bin first.

> So I ran the perl Build.PL process again and got much further along than I
> had before! However no luck as of yet, as it's now giving me this error:

I'm pretty deep into SWAG territory here, but my guess is that the
version installed with the system is not the required 1.5.3 (or
whatever it was), and that explains those C compiler errors you're
getting.

j.

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




Re: perlbrew error

2014-06-15 Thread John SJ Anderson
On Sun, Jun 15, 2014 at 10:31 AM, Subinoy Biswas  wrote:
> Hi,
> I am having a trouble installing any module with cpanm in perlbrew
> perl-5.20.0 in an test1 local lib. Below I am pasting the verbose. Please
> help me to solve this issue

So, you need to install Tie::Hash::Indexed:

> Can't locate Tie/Hash/Indexed.pm in @INC (you may need to install the
> Tie::Hash::Indexed module)

Which you tried to do:

> subinoybiswas@sunymacs:~/work_ubc/seq$ cpanm Tie::Hash::Indexed
[ snip ]

Which failed:

> ! Installing Tie::Hash::Indexed failed. See
> /Users/subinoybiswas/.cpanm/build.log for details.

So the contents of that file might be helpful.

Additionally:

> cannot unlink file for
> /Users/subinoybiswas/.cpanm/work/1383165137.7601/build.log: Permission
> denied at /loader/0x7fd8d10320a0/App/cpanminus/script.pm line 1.
> cannot restore permissions to 0100644 for
> /Users/subinoybiswas/.cpanm/work/1383165137.7601/build.log: Permission
> denied at /loader/0x7fd8d10320a0/App/cpanminus/script.pm line 1.
> cannot remove directory for
> /Users/subinoybiswas/.cpanm/work/1383165137.7601: Directory not empty at
> /loader/0x7fd8d10320a0/App/cpanminus/script.pm line 1.

Those errors suggest something is messed up in your ~/.cpanm directory
hierarchy. If I had to bet, I'd bet that you ran something as root,
once upon a time, and the above errors are from root-owned files that
got produced at that point.

You should just be able to 'rm -rfv ~/.cpanm' without issue.


j.

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




Re: Install Alien SVN::Core

2014-06-15 Thread John SJ Anderson
On Sun, Jun 15, 2014 at 10:39 AM, Tim Dunphy  wrote:
> Hi John,
>
> --
> /usr/bin/install -c -m 644 aprutil.exp /usr/local/apr/lib
> /usr/bin/install -c -m 755 apu-config.out /usr/local/apr/bin/apu-1-config
>
> However when I do a 'which apr-util' I get nothing back.

Sorry, I forgot apr-utils isn't the name of the command you need.

It's apu-1-config -- see the last 'install' command in the 'make
install' output above.

> [root@host1 apr-util-1.5.3]# which apr-util
> /usr/bin/which: no apr-util in
> (/opt/python27/bin:/opt/php-5.3.28/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/opt/csvquerytool-0.0.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/apache2/bin:/root/bin)

You don't have /usr/local/apr/bin in that PATH. Try adding it.

j.

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




Re: Install Alien SVN::Core

2014-06-15 Thread John SJ Anderson
On Fri, Jun 13, 2014 at 3:45 PM, Tim Dunphy  wrote:

> How can I specify apr-util to this perl module when apr-util 1.5.1 is
> already installed.

Can you confirm that 'which apr-util' shows that the command is
actually in your $PATH?

j.

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




Re: Running module using cpan.

2014-06-10 Thread John SJ Anderson
On Tue, Jun 10, 2014 at 9:47 PM, Priyal Jain  wrote:
> Hello,
>
> I uploaded my module in CPAN on 02June,2014 
> http://search.cpan.org/search?mode=all&query=Net%3A%3ANetconf but while 
> installing my module using cpan i.e. "cpan Net::Netconf" its giving warning

Have you seen https://rt.cpan.org/Public/Bug/Display.html?id=95038 ?

It looks like the distribution you uploaded is not set up correctly in
at least a few ways. In addition to the missing META.yml file, the POD
markup is rendering wrong on search.cpan.org, and the module doesn't
seem to be indexed at all on MetaCPAN, which is generally indicative
of problems.

My advice would be to contact the person who submitted that ticket,
and take them up on their offer to help you.

chrs,
john.

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




Re: how to create a text progress status line that updates on the same line in Perl?

2014-06-10 Thread John SJ Anderson
On Tue, Jun 10, 2014 at 2:59 PM, Kenneth Wolcott
 wrote:
> Hi All;
>
> how to create a text progress status line that updates on the same line in 
> Perl?

You mean something like https://metacpan.org/pod/Text::ProgressBar::Bar ?

Maybe reading that source code would be informative. 8^)

chrs,
john.

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




Re: regular expression

2014-05-06 Thread John SJ Anderson
On Tue, May 6, 2014 at 10:30 PM, Danny Wong (dannwong)
 wrote:
> Both string are possible outputs, so I want to be able to grep for the
> username only.

Well, if the username will always be either the only thing between
'by' and 'on', or in parens if it's not...

#! /usr/bin/env perl

use strict;
use warnings;
use 5.010;

my @strings = (
  "^Modifications made by Danny Wong (danwong) on 2014/05/06 18:27:48
from database brms" ,
  "^Modifications made by danwong on 2014/05/06 18:27:48 from database brms²",
);

foreach my $string ( @strings ) {
  my( $match ) = $string =~ /by (.*?) on/;
  if ( $match and $match =~ /\(([^)]+)\)/ ) {
$match = $1;
  }
  say "Matched '$1' in '$string'"
if $match;
}

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




Re: regular expression

2014-05-06 Thread John SJ Anderson
On Tue, May 6, 2014 at 10:19 PM, Danny Wong (dannwong)
 wrote:

> What is a regular expression where I can extract ³danwong² from either
> string (one string have () parentheses and the other doesn¹t have
> parentheses)?

I'm not entirely sure what you're trying to accomplish, but perhaps
something like:

#! /usr/bin/env perl

use strict;
use warnings;
use 5.010;

my @strings = (
  "^Modifications made by Danny Wong (danwong) on 2014/05/06 18:27:48
from database brms" ,
  "^Modifications made by danwong on 2014/05/06 18:27:48 from database brms²",
);

foreach my $string ( @strings ) {
  say "Matched '$1' in '$string'"
if $string =~ /(danwong)/;
}

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




Re: small puzzle

2014-04-25 Thread John SJ Anderson
*puts on List Mom hat*

Okay, we're done here. The original question was asked and answered (a
couple times). Let's move on and get back to dealing with Perl
questions, not personalities.

thanks,
john.

*takes List Mom hat back off*

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




Re: small puzzle

2014-04-25 Thread John SJ Anderson
On Fri, Apr 25, 2014 at 12:18 PM, Harry Putnam  wrote:

> About just using 'shift':  How I happened to be using that weird
> looking notation at all was because I thought it was a way to avoid
> the extra step of compiling the rgx in qr// after shifting.

My advice to you on this point would be that when you're trying to do
two things, it's perfectly okay to use two lines of code to do it.
(It's even okay sometimes when you're only trying to do one thing!)

Perl doesn't charge you by the lines of code you use, so doing this:

   my $re = shift;
   $re = qr/$re/;

is just fine.


chrs,
john.

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




Re: small puzzle

2014-04-24 Thread John SJ Anderson
On Thu, Apr 24, 2014 at 8:40 PM, Harry Putnam  wrote:
> my $dir2sr  = @{[shift]};

This shifts an element off @ARGV, makes an array reference containing
a single element (the value that was just shifted off), then
deferences that arrayref to create an array (which still contains a
single element, the value that was just shifted off), then assigns the
result of evaluating that array in a scalar context (which is the
number of elements in the array, i.e., 1) to $dir2sr.

(The same thing happens earlier, when you're pulling the first value
off @ARGV, but there the evaluation of the array is happening inside
qr//, which I guess imparts a list context so it DWyouM.)

In general, anywhere you're doing '@{[shift]}', unless you REALLY know
what's going on and why you'd want to do that ... instead just do
'shift'.

j.

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




Re: Where's this documented?

2014-03-20 Thread John W. Krahn

shawn wilson wrote:


Oh, I guess I was thinking that using the file name repeats the stat
(which it does). Since I was complaining about the ugliness of '_'.
However, you're right - that works as well as (-f _)<-- that doesn't
look weird as shit? I've got issues moving my fingers into typing
that Whatever, y'all answered my question and I learned something
(though damn them for not just making another perlvar or something
else to do this) - I appreciate the help/info.


_ is a perlvar.  It is part of the typeglob that includes $_, @_, %_ and &_.

perldoc perldata
perldoc perlmod
perldoc perlref



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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




Re: Where's this documented?

2014-03-18 Thread John W. Krahn

Shaji Kalidasan wrote:


You can use more than one file test on the same file to create a
complex logical condition.
Suppose you only want to operate on files that are both readable and
writable; you check each attribute and combine them with and:

if (-r $file and -w $file) {
...
}

Each time you perform a file test


or use stat() or lstat()


, Perl asks the filesystem for all of
the information about the file (Perl’s actually doing a stat each time,
which we talk about in the next section). Although you already got that
information when you tested -r, Perl asks for the same information
again so it can test -w. What a waste! This can be a significant
performance problem if you’re testing many attributes on many files.

The virtual filehandle _ (just the underscore) uses the information
from the last file lookup that a file test operator


or stat() or lstat()


performed. Perl
only has to look up the file information once now:




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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




Re: Turn part of a string into a single newline

2014-02-14 Thread John W. Krahn

Parysatis Sachs wrote:

Hi everyone!


Hello,



I'm new to this mailing list as well as to programming and Perl in general.
So there is a chance I might ask relatively stupid questions with very
obvious answers... Please bear with me!

So, here it goes:

I have a very long string with lots of Ns in it, like this:
agctagccgagctaNNatggctaNNNatgtgaNNatg

So, I want to get rid of the Ns and get ONE SINGLE newline for each group
of Ns

So far I've managed to do this:

if ($joinedDNA =~ s/N+/\n/g) {

$joinedDNA =~ s/\R//g;

}


That should be just:

$joinedDNA =~ s/N+/\n/g;

Or just:

$joinedDNA =~ tr/N/\n/s;


The statement:

$joinedDNA =~ s/\R//g;

removes all newlines.




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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




Re: Test::More is_deeply failed data

2014-02-11 Thread John SJ Anderson
On Tue, Feb 11, 2014 at 10:17 AM, shawn wilson  wrote:
> Is there a way to see the data difference when is_deeply fails?

So, with this code:

#! perl

use Test::More;

my $a = { foo => {bar => { baz => 'bargle' }}};
my $b = { foo => {baz => { bar => 'bargle' }}};

is_deeply( $a , $b );

done_testing;

I get this output:

% prove deeply.t
deeply.t .. 1/?
#   Failed test at deeply.t line 8.
# Structures begin differing at:
#  $got->{foo}{baz} = Does not exist
# $expected->{foo}{baz} = HASH(0x7fdb798283f0)
# Looks like you failed 1 test of 1.
deeply.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests

Test Summary Report
---
deeply.t (Wstat: 256 Tests: 1 Failed: 1)
  Failed test:  1
  Non-zero exit status: 1
Files=1, Tests=1,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.02 cusr
0.00 csys =  0.06 CPU)
Result: FAIL

What do you get?

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




Re: constant in object

2014-02-10 Thread John SJ Anderson
On Mon, Feb 10, 2014 at 10:07 PM, shawn wilson  wrote:

>  which I still don't see why this is bad?

In "classic" object-oriented programming, object constructors -- which
is what new() is in your class -- are always class methods. Calling
'new()' as an object method doesn't make any sense. Further, as Uri
points out, the semantics can get confused when you call a 'new()'
method on an object. Are you asking for a new, fresh instance of an
object of the class that the existing object is a member of, or are
you asking for a a new instance that's a copy of the object you're
calling the method on?

(Aside: that confusion is the reason why Uri is suggesting an object
method called 'clone()'. I can only assume he's intending for it to
return a copy of the object it is called on, not a completely fresh
instance of the object defined by the class of the object that it is
called on.)

TL;DR - if you can't offer a positive reason why you're doing this --
and "it doesn't seem to hurt anything" is *not* a positive reason --
then you shouldn't do it.

j.

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




Re: Package version numbers

2014-01-14 Thread John SJ Anderson
> Thanks for the test, John.  In the book's example, they have:
>
> use v5.10;
>
> so I thought I was new enough, but maybe not.

http://use.perl.org/use.perl.org/articles/10/04/13/1953252.shtml also
notes it as a new feature in 5.12. I'm sure the authors regret the
typo. ;^)



j.

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




Re: Package version numbers

2014-01-14 Thread John SJ Anderson
On Tue, Jan 14, 2014 at 2:50 PM, SSC_perl  wrote:
> I'm trying to number packages the way it's written about on page 406 
> of Programming Perl, 4th ed., e.g.
>
> package Emailer 1.01;
>
> However, when I do that, I get the following error:
>
> syntax error at ss_files/Emailer.pm line 1, near "package Emailer 1.01"
> Compilation failed in require at admin.cgi line 38.
> BEGIN failed--compilation aborted at admin.cgi line 38.
>
> I'm running Perl 5.10.1 on my laptop so that should be new enough to 
> handle this.  What am I doing wrong?

I'm not sure exactly when that syntax was added, but for what it's
worth, it fails with 5.10.1 here too. Perl 5.12.5, on the other hand,
works.

You may just need to upgrade.

chrs,
john.

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




Re: Recursive Validation Function

2014-01-02 Thread John Aten
Hello again,

I wasn't able to continue with the project I was working on way back in 
September, but I wanted to send a quick note to thank everyone (Andy Bach, Jim 
Gibson, Rob Dixon and Mike Flannigan) for their help. I apologize for not 
following up sooner. Hopefully I'll have some time to get back to it some day 
soon; I was a little optimistic in my planning.  Thanks again!

On Sep 4, 2013, at 10:55 PM, beginners-digest-h...@perl.org wrote:

> 
> beginners Digest 5 Sep 2013 03:55:27 - Issue 4576
> 
> Topics (messages 123410 through 123433):
> 
> Re: Recursive Validation Function
>   123410 by: Andy Bach
>   123411 by: Jim Gibson
>   123412 by: Rob Dixon
>   123413 by: Rob Dixon
>   123427 by: Mike Flannigan
> 
> 
> --
> 
> From: Andy Bach 
> Date: September 2, 2013 8:43:59 PM CDT
> To: John Aten 
> Cc: "beginners@perl.org" 
> Subject: Re: Recursive Validation Function
> 
> 
> 
> 
> On Monday, September 2, 2013, John Aten wrote:
> my $valid_token = validate_tokens($token);
> 
> 
> Too bad it doesn't work! Even if I put in valid tokens on the first shot, 
> there are errors:
> 
> You're passing the token as a parameter to the sub but the is using $_ for 
> the match. You need to assign the parameter in the sub. They arrive on the 
> global @_ array; one idiom is
> sub validate_token {
>   my ($test_token) = @_;
>   
> This assigns the first passed parameter to test_token. The advantage being of 
> you add more params you can just insert a new var. in the LHS list:
>   my ($test_token, $empty_allowed, $cleanup) = @_;
> 
> Now use $test_token instead of $_
> 
>  
> 
> I am writing a script to rename files. The script prompts the user to enter 
> tokens which will comprise part of the file name. These are made of letters 
> and numbers separated by a dot, ie: R.3. The letters can be R, I or C, upper 
> or lowercase. The first number can be one through eight, and if it is a six 
> there can be an additional dot followed by a one or two. To make sure that I 
> don't make any mistakes when putting in these tokens, I have tried to write a 
> function to make sure that they are valid:
> 
> sub validate_tokens {
> if ($_ !~ /^[ric]\.[1234578]$/i) {
> if ($_ !~ /^[ric]\.6(\.[1|2])?$/i) {
> print "Enter valid tokens: ";
> my $new_token = ;
> chomp $new_token;
> validate_tokens($new_token);
> }
> }
> return $_;
> }
> 
> 
> I'm calling it like this:
> 
> print "Enter Tokens: ";
> my $token = ;
> chomp $token;
> my $valid_token = validate_tokens($token);
> 
> 
> Too bad it doesn't work! Even if I put in valid tokens on the first shot, 
> there are errors:
> 
> Use of uninitialized value $_ in pattern match (m//) at bulk.pl line 65, 
>  line 3.
> Use of uninitialized value $_ in pattern match (m//) at bulk.pl line 66, 
>  line 3.
> 
> Lines 65 and 66 are the ones with the two if statements, lines 2 and 3 of the 
> first code snippet above. Each time I run it, the  line number in the 
> error message increases by one. The script goes into an infinite loop, 
> prompting for valid tokens, but even if valid ones are entered it continues. 
> What am I missing?
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 
> 
> -- 
> 
> a
> 
> Andy Bach,
> afb...@gmail.com
> 608 658-1890 cell
> 608 261-5738 wk
> 
> 
> 
> From: Jim Gibson 
> Date: September 3, 2013 12:56:16 AM CDT
> To: "begin >> Perl Beginners" 
> Subject: Re: Recursive Validation Function
> 
> 
> 
> On Sep 2, 2013, at 6:23 PM, John Aten wrote:
> 
>> Hello all,
>> 
>> I am writing a script to rename files. The script prompts the user to enter 
>> tokens which will comprise part of the file name. These are made of letters 
>> and numbers separated by a dot, ie: R.3. The letters can be R, I or C, upper 
>> or lowercase. The first number can be one through eight, and if it is a six 
>> there can be an additional dot followed by a one or two. To make sure that I 
>> don't make any mistakes when putting in these tokens, I have tried to write 
>> a function to make sure that they are valid:
> 
> Use $_[0] instead of $_ or the other suggestions from Andy.
> 
>> 
>> sub validate

Re: DBD::Pg::st execute failed: execute called with an unbound placeholder

2013-12-11 Thread John SJ Anderson
On Wed, Dec 11, 2013 at 1:56 AM, Lars Noodén  wrote:
>  my $sth = $dbh->prepare("delete from sessions where \
>  current_timestamp - time > interval ?");
>
>  $sth->execute( $interval );
>
>
> What mistake is there causing the error?  I can use a similar line with
> a placeholder for a SELECT sql statement without error.

The DBI docs say (here =
http://search.cpan.org/~timb/DBI/DBI.pm#Placeholders_and_Bind_Values):

"With most drivers, placeholders can't be used for any element of a
statement that would prevent the database server from validating the
statement and creating a query execution plan for it."

I suspect you're running afoul of that...

j.

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




Re: [OT] SurfShopPRO Perl shopping cart system is now open source

2013-11-19 Thread John W. Krahn

SSC_perl wrote:

Hi John,


Hello,



Thanks for getting back to me with your findings.  I really
appreciate it.  I've gone through everything, made the changes that I
could, and I have some questions to some of your remarks.


You are using the value from readdir() without prepending the path to
the file name.


Unless I'm mistaken, I believe the full paths are being set in
the variables, before being used by opendir.


Yes, the full path of a directory.


 Am I misunderstanding  something?


readdir() returns just the file names, without the path.



autoconfig.cgi:883:   print "[dir] $dir/$file  - .htaccess 
installed\n";
The variable $file is not assigned a value.


I'm not seeing this.  I thought it was set earlier in the
security sub, but maybe I've just been staring at it for too long.


All instances of $file in the subroutine Security():

745 my (@dirs, @files, $dir, $file) = ();

$file is created at the beginning of the subroutine.

832 foreach $file (@datfiles) {
833 Surf::cl("$path/$file") 
=~ /(.*)/;


$file is used in a foreach loop and therefore:

perldoc perlsyn
the variable is implicitly local to the loop and regains its former
value upon exiting the loop.

Where its former value is undef.

874 foreach $file (@files) {
875 push @dirs, 
"$dir/$file" if (-d "$dir/$file" && $file !~ /^\./);


Same as above.

883 print "color=\"33\">[dir] $dir/$file - .htaccess installed\n";


At this point $file has no value.



I also ran perl -c, as well as PerlCritic, on all the files and
have uploaded a "cleaned up" version (1.5.1) to our site.  Here's a
direct link:

http://www.surfshopcart.com/download-zip.php


I started looking through it and found this mistake.  In the old version 
you had:


Email.pm:97:   open (my $mail_fh, "|$path -t -oi -oem") || 
error("Can't open $main::global->{form}->{'mailprog'}!\n");


And:

ipn.pl:90:open (MAIL, "|$main::global->{config}->{'mailprog'} -t -oi 
-oem") || error("IPNemail: Can't open 
$main::global->{config}->{'mailprog'}!\n");


Which you changed to:

Email.pm:91:open (my $mail_fh, '<', "|$path -t -oi -oem") || 
error("Can't open $main::global->{'form'}->{'mailprog'}!\n");


And:

ipn.pl:90:open (my $mail, '<', 
"|$main::global->{config}->{'mailprog'} -t -oi -oem") || 
error("ipn_email: Can't open $main::global->{config}->{'mailprog'}!\n");



You've changed them from opening an OUTPUT pipe to a mail program to 
opening a file named "|$path -t -oi -oem" for INPUT!


They were correct in the first place.

Or maybe better as:

Email.pm:91:open my $mail_fh, '|-', $path, '-t', '-oi', 
'-oem' or error( "Can't open $path!\n" );


And:

ipn.pl:90:open my $mail, '|-', $::global->{ config }{ mailprog }, 
'-t', '-oi', '-oem' or error( "ipn_email: Can't open 
$::global->{config}{mailprog}!\n" );




Antway, I found some mistakes in your code; to wit:


You were being kind. ;)  Thank you again!

Can I reference your name as a contributor,


Sure, if you would like to.


or would you prefer
to keep your name off the project?  Also, would you consider joining us?


I'll think about it.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

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

2013-11-18 Thread John SJ Anderson
On Mon, Nov 18, 2013 at 12:34 PM, John W. Krahn  wrote:

>> Also, is there something in the perl man pages about it?
>
>
> Yes.  You probably want perlop?

Specifically, http://perldoc.perl.org/perlop.html#Conditional-Operator

'?:' is otherwise known as the 'ternary conditional operator' -- if
you don't know that bit of esoterica, finding the right documentation
is a lot harder. 8^)

chrs,
john.

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